-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.lua
More file actions
322 lines (296 loc) · 9.34 KB
/
Copy pathfunctions.lua
File metadata and controls
322 lines (296 loc) · 9.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
-- Plays the given sound if the "legendary_joker_sounds" config option is true.
-- Otherwise, plays the "otherwise" sound.
-- "sound" will automatically have "wafflemod_" appended to the front.
function WaffleMod.legendary_sound(sound, otherwise)
if WaffleMod.config.legendary_joker_sounds then
play_sound("wafflemod_" .. sound)
else
play_sound(otherwise or "generic")
end
end
-- Flip a table of cards and perform a function on each one.
-- This is similar to how cards such as Sigil do it.
-- Each card is passed as the first argument of applyFunc.
function WaffleMod.flipFunctionCards(cards, applyFunc)
G.E_MANAGER:add_event(Event({
trigger = 'after',
delay = 0.4,
func = function()
play_sound('tarot1')
return true
end
}))
for i = 1, #cards do
local percent = math.max(1.15 - (i - 0.999) / (#cards - 0.998) * 0.3, 0)
G.E_MANAGER:add_event(Event({
trigger = 'after',
delay = 0.15,
func = function()
cards[i]:flip()
play_sound('card1', percent)
cards[i]:juice_up(0.3, 0.3)
return true
end
}))
end
delay(0.15)
for i = 1, #cards do
G.E_MANAGER:add_event(Event({
func = function()
applyFunc(cards[i])
return true
end
}))
end
delay(0.2)
for i = 1, #cards do
local percent = math.max(1.15 - (i - 0.999) / (#cards - 0.998) * 0.3, 0)
G.E_MANAGER:add_event(Event({
trigger = 'after',
delay = 0.15,
func = function()
cards[i]:flip()
play_sound('tarot2', percent, 0.6)
cards[i]:juice_up(0.3, 0.3)
return true
end
}))
end
end
function WaffleMod.addLocColor(name, color)
G.C[name] = color
local ref_loc_colour = loc_colour
function loc_colour(_c, _default)
ref_loc_colour(_c, _default)
G.ARGS.LOC_COLOURS[name] = G.C[name]
return G.ARGS.LOC_COLOURS[_c] or _default or G.C.UI.TEXT_DARK
end
end
-- Respects Credit Card's debt ability
function WaffleMod.canAfford(price)
return G.GAME.dollars - price > G.GAME.bankrupt_at
end
-- Juices up the blind and plays the light "ba-dunk" sound when a boss blind is triggered.
function WaffleMod.juiceBlindWithSound()
G.E_MANAGER:add_event(Event({
trigger = 'immediate',
func = (function()
SMODS.juice_up_blind()
G.E_MANAGER:add_event(Event({
trigger = 'after',
delay = 0.06 * G.SETTINGS.GAMESPEED,
blockable = false,
blocking = false,
func = function()
play_sound('tarot2', 0.76, 0.4); return true
end
}))
play_sound('tarot2', 1, 0.4)
return true
end)
}))
end
-- If checkConfig evaluates to false (or nil), adds the "disabled" tooltip to the passed info_queue.
function WaffleMod.addDisabledTooltip(info_queue, checkConfig)
if not checkConfig then
info_queue[#info_queue + 1] = { key = 'wafflemod_disabled_tooltip', set = 'Other', config = {} }
end
end
-- Will only get visible poker hands (i.e. will not get secret hands that have not yet been played)
function WaffleMod.getRandomHand(pseudorandom_seed)
local _poker_hands = {}
for handname, _ in pairs(G.GAME.hands) do
if SMODS.is_poker_hand_visible(handname) then
_poker_hands[#_poker_hands + 1] = handname
end
end
return pseudorandom_element(_poker_hands, pseudorandom_seed)
end
-- Returns the name of the most played hand, as well as the amount of times it has been played.
function WaffleMod.getMostPlayedHand()
local _handname, _played = 'High Card', 0
for hand_key, hand in pairs(G.GAME.hands) do
if hand.played > _played then
_played = hand.played
_handname = hand_key
end
end
return _handname, _played
end
-- Returns the key of the current deck.
function WaffleMod.getCurrentBack()
return G.GAME.selected_back.effect.center.key
end
-- Returns true if key matches the key of the current deck.
function WaffleMod.usingBack(key)
return G.GAME and G.GAME.selected_back and G.GAME.selected_back.effect and G.GAME.selected_back.effect.center and
G.GAME.selected_back.effect.center.key == key
end
-- Returns true if at least one card with the given enhancement exists in the deck.
function WaffleMod.isEnhancementInDeck(enhancement_key)
for _, playing_card in ipairs(G.playing_cards or {}) do
if SMODS.has_enhancement(playing_card, enhancement_key) then
return true
end
end
return false
end
-- Returns true if at least one card with the given enhancement is held in hand.
function WaffleMod.isEnhancementInHand(enhancement_key)
for _, playing_card in ipairs(G.hand or {}) do
if SMODS.has_enhancement(playing_card, enhancement_key) then
return true
end
end
return false
end
-- As in whether it's in the collection *UI*, i.e. when you're viewing a card in the collection
function WaffleMod.isCardInCollection(card)
if G.your_collection then
for i, v in pairs(G.your_collection) do
if v.cards then
for _, w in pairs(v.cards) do
if w == card then
return true
end
end
end
end
end
end
-- Returns true if the given voucher is owned
function WaffleMod.hasVoucher(key)
if G.GAME.used_vouchers[key] then
return true
end
end
-- Returns a random number that is determined by the given seed.
-- Made this as an analog for pseudorandom that does not progress the seed used
local letterToNumber = {
q = 1,
w = 2,
e = 3,
r = 4,
t = 5,
y = 6,
u = 7,
i = 8,
o = 9,
p = 10,
a = 11,
s = 12,
d = 13,
f = 14,
g = 15,
h = 16,
j = 17,
k = 18,
l = 19,
z = 20,
x = 21,
c = 22,
v = 23,
b = 24,
n = 25,
m = 26,
}
function WaffleMod.frozenRandom(seed)
for letter, number in pairs(letterToNumber) do
seed = seed:gsub(string.upper(letter), tostring(number))
end
seed = tonumber(seed) or 0
return seed
end
-- Gets the number of suits. Useful if other mods add more than the normal 4.
function WaffleMod.getSuitCount()
local count = 0
for _, v in pairs(SMODS.Suits) do
count = count + 1
end
return count
end
-- Checks if the context is the main end of round context (and not game_over)
function WaffleMod.endOfRoundContext(context)
return context.end_of_round and context.main_eval and context.game_over == false
end
-- Makes a joker perishable. Used for Blighted Deck's effect
function WaffleMod.blightedMakePerishable(card)
if card.ability.set == "Joker" then
card.ability.eternal = false
if not card.ability.perishable then
card:add_sticker("perishable", true)
end
end
end
function WaffleMod.selectRandomTag()
local tag_pool = get_current_pool('Tag')
local selected_tag = pseudorandom_element(tag_pool, 'modprefix_seed')
local it = 1
while selected_tag == 'UNAVAILABLE' do
it = it + 1
selected_tag = pseudorandom_element(tag_pool, 'modprefix_seed_resample'..it)
end
return selected_tag
end
-- Adds a tooltip to a card that appears if the player has Fuzzy Pickle, localized in the wafflemod_reference set.
function WaffleMod.addReferenceTooltip(info_queue, key)
if next(SMODS.find_card("j_wafflemod_fuzzy_pickle", true)) then
info_queue[#info_queue+1] = {key = key, set = "Other"}
end
end
-- Gets the joker to the right of a given Joker, or nil if there is none.
function WaffleMod.getJokerToRight(joker)
local other_joker
for i = 1, #G.jokers.cards do
if G.jokers.cards[i] == joker then other_joker = G.jokers.cards[i + 1] end
end
return other_joker
end
function WaffleMod.getNumFaceCardsInDeck()
local numFaceCards = 0
if G.playing_cards then
for i = 1, #(G.playing_cards or {}) do
if G.playing_cards[i]:is_face() then
numFaceCards = numFaceCards + 1
end
end
else
numFaceCards = 12
end
return numFaceCards
end
WaffleMod.calculateFunctions = {}
function WaffleMod.bindToModCalculate(func, name)
if name then
WaffleMod.calculateFunctions[name] = func
else
table.insert(WaffleMod.calculateFunctions, func)
end
end
function SMODS.current_mod.calculate(self, context)
local retTable
local curExtra
for _, func in pairs(WaffleMod.calculateFunctions) do
local returnEffect = func(context)
if returnEffect then
if not retTable then -- First return table
retTable = returnEffect
elseif not curExtra then -- Second return table
retTable.extra = returnEffect
curExtra = returnEffect
else -- Further return tables
curExtra.extra = returnEffect
curExtra = returnEffect
end
end
end
return retTable
end
-- i am far too used to luau and its capabilities
table.find = function(tab, findThis)
for i, v in pairs(tab) do
if findThis == v then
return i
end
end
end