-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathutilities.lua
More file actions
567 lines (540 loc) · 14.7 KB
/
utilities.lua
File metadata and controls
567 lines (540 loc) · 14.7 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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
function Card:has_stickers()
for i, v in pairs(SMODS.Sticker.obj_table) do
if self.ability[i] then
return true
end
end
end
function Card:remove_random_sticker(seed)
local s = {}
for i, v in pairs(SMODS.Sticker.obj_table) do
if not v.hidden and i ~= "cry_absolute" and self.ability[i] then
s[#s + 1] = i
end
end
if #s > 0 then
local sticker = pseudorandom_element(s, pseudoseed(seed))
self.ability[sticker] = nil
if sticker == "perishable" then
self.ability.perish_tally = nil
end
end
end
function Cryptid.table_merge(t1, t2)
local tbl = {}
for i, v in pairs(t1) do
tbl[#tbl + 1] = v
end
for i, v in pairs(t2) do
tbl[#tbl + 1] = v
end
return tbl
end
function Cryptid.get_highlighted_cards(areas, ignore, min, max, blacklist, seed)
ignore.checked = true
blacklist = blacklist or function()
return true
end
local cards = {}
for i, area in pairs(areas) do
if area.cards then
for i2, card in pairs(area.cards) do
if
card ~= ignore
and blacklist(card)
and (card.highlighted or G.cry_force_use)
and not card.checked
then
cards[#cards + 1] = card
card.checked = true
end
end
end
end
for i, v in ipairs(cards) do
v.checked = nil
end
if (#cards >= min and #cards <= max) or not G.cry_force_use then
ignore.checked = nil
return cards
else
for i, v in pairs(cards) do
v.f_use_order = i
end
pseudoshuffle(cards, pseudoseed("forcehighlight" or seed))
local actual = {}
for i = 1, max do
if cards[i] and not cards[i].checked and actual ~= ignore then
actual[#actual + 1] = cards[i]
end
end
table.sort(actual, function(a, b)
return a.f_use_order < b.f_use_order
end)
for i, v in pairs(cards) do
v.f_use_order = nil
end
ignore.checked = nil
return actual
end
return {}
end
function Card:is_food()
--you cant really check if vanilla jokers are in a pool because its hardcoded
--so i have to hardcode it here too for the starfruit unlock
local food = {
j_gros_michel = true,
j_egg = true,
j_ice_cream = true,
j_cavendish = true,
j_turtle_bean = true,
j_diet_cola = true,
j_popcorn = true,
j_ramen = true,
j_selzer = true,
}
if food[self.config.center.key] or Cryptid.safe_get(self.config.center, "pools", "Food") then
return true
end
end
function Cryptid.cry_rankname_to_id(rankname)
for i, v in pairs(SMODS.Rank.obj_buffer) do
if rankname == v then
return i
end
end
return nil
end
--Utility function to check things without erroring
---@param t table
---@param ... any
---@return table|false
function Cryptid.safe_get(t, ...)
local current = t
for _, k in ipairs({ ... }) do
if not current or current[k] == nil then
return false
end
current = current[k]
end
return current
end
function Cryptid.is_card_big(joker)
if not Talisman then
return false
end
local center = joker.config and joker.config.center
if not center then
return false
end
if center.immutable and center.immutable == true then
return false
end
-- im making bignums not work with Cryptid. since i dont see the point
-- could be changed but i dont feel like making 2 blacklists or making this mod use the cryptid table either
if center.mod and not (Cryptid or {}).mod_whitelist[center.mod.name] then
return false
end
local in_blacklist = ((Cryptid or {}).big_num_blacklist or {})[center.key or "Nope!"] or false
return not in_blacklist --[[or
(center.mod and center.mod.id == "Cryptid" and not center.no_break_infinity) or center.break_infinity--]]
end
-- Check G.GAME as well as joker info for banned keys
function Card:no(m, no_no)
if no_no then
-- Infinifusion Compat
if self.infinifusion then
for i = 1, #self.infinifusion do
if
G.P_CENTERS[self.infinifusion[i].key][m]
or (G.GAME and G.GAME[m] and G.GAME[m][self.infinifusion[i].key])
then
return true
end
end
return false
end
if not self.config then
--assume this is from one component of infinifusion
return G.P_CENTERS[self.key][m] or (G.GAME and G.GAME[m] and G.GAME[m][self.key])
end
return self.config.center[m] or (G.GAME and G.GAME[m] and G.GAME[m][self.config.center_key]) or false
end
return Card.no(self, "no_" .. m, true)
end
function Cryptid.no(center, m, key, no_no)
if no_no then
return center[m] or (G.GAME and G.GAME[m] and G.GAME[m][key]) or false
end
return Cryptid.no(center, "no_" .. m, key, true)
end
function Cryptid.deck_effects(card, func)
if not card.added_to_deck then
return func(card)
else
card.from_quantum = true
card:remove_from_deck(true)
local ret = func(card)
card:add_to_deck(true)
card.from_quantum = nil
return ret
end
end
function Cryptid.deep_copy(obj, seen)
if type(obj) ~= "table" then
return obj
end
if seen and seen[obj] then
return seen[obj]
end
local s = seen or {}
local res = setmetatable({}, getmetatable(obj))
s[obj] = res
for k, v in pairs(obj) do
res[Cryptid.deep_copy(k, s)] = Cryptid.deep_copy(v, s)
end
return res
end
-- generate a random edition (e.g. Antimatter Deck)
function Cryptid.poll_random_edition()
local random_edition = pseudorandom_element(G.P_CENTER_POOLS.Edition, pseudoseed("cry_ant_edition"))
while random_edition.key == "e_base" do
random_edition = pseudorandom_element(G.P_CENTER_POOLS.Edition, pseudoseed("cry_ant_edition"))
end
ed_table = { [random_edition.key:sub(3)] = true }
return ed_table
end
-- gets a random, valid consumeable (used for Hammerspace, CCD Deck, Blessing, etc.)
function Cryptid.random_consumable(seed, excluded_flags, banned_card, pool, no_undiscovered)
-- set up excluded flags - these are the kinds of consumables we DON'T want to have generating
excluded_flags = excluded_flags or { "hidden", "no_doe", "no_grc" }
local selection = "n/a"
local passes = 0
local tries = 500
while true do
tries = tries - 1
passes = 0
-- create a random consumable naively
local key = pseudorandom_element(pool or G.P_CENTER_POOLS.Consumeables, pseudoseed(seed or "grc")).key
selection = G.P_CENTERS[key]
-- check if it is valid
if selection.discovered or not no_undiscovered then
for k, v in pairs(excluded_flags) do
if not Cryptid.no(selection, v, key, true) then
--Makes the consumable invalid if it's a specific card unless it's set to
--I use this so cards don't create copies of themselves (eg potential inf Blessing chain, Hammerspace from Hammerspace...)
if not banned_card or (banned_card and banned_card ~= key) then
passes = passes + 1
end
end
end
end
-- use it if it's valid or we've run out of attempts
if passes >= #excluded_flags or tries <= 0 then
if tries <= 0 and no_undiscovered then
return G.P_CENTERS["c_strength"]
else
return selection
end
end
end
end
-- simple plural s function for localisation
function Cryptid.pluralize(str, vars)
local inside = str:match("<(.-)>") -- finds args
local _table = {}
if inside then
for v in inside:gmatch("[^,]+") do -- adds args to array
table.insert(_table, v)
end
local num = vars[tonumber(string.match(str, ">(%d+)"))] -- gets reference variable
if type(num) == "string" then
num = (Big and to_number(to_big(num))) or num
end
if not num then
num = 1
end
local plural = _table[1] -- default
local checks = { [1] = "=" } -- checks 1 by default
local checks1mod = false -- tracks if 1 was modified
if #_table > 1 then
for i = 2, #_table do
local isnum = tonumber(_table[i])
if isnum then
if not checks1mod then
checks[1] = nil
end -- dumb stuff
checks[isnum] = "<" .. (_table[i + 1] or "") -- do less than for custom values
if isnum == 1 then
checks1mod = true
end
i = i + 1
elseif i == 2 then
checks[1] = "=" .. _table[i]
end
end
end
local function fch(str, c)
return string.sub(str, 1, 1) == c -- gets first char and returns boolean
end
local keys = {}
for k in pairs(checks) do
table.insert(keys, k)
end
table.sort(keys, function(a, b)
return a < b
end)
if not (tonumber(num) or is_number(num)) then
num = 1
end
for _, k in ipairs(keys) do
if fch(checks[k], "=") then
if to_big(math.abs(num - k)) < to_big(0.001) then
return string.sub(checks[k], 2, -1)
end
elseif fch(checks[k], "<") then
if to_big(num) < to_big(k - 0.001) then
return string.sub(checks[k], 2, -1)
end
end
end
return plural
end
end
function Cryptid.advanced_find_joker(name, rarity, edition, ability, non_debuff, area)
local jokers = {}
if not G.jokers or not G.jokers.cards then
return {}
end
local filter = 0
if name then
filter = filter + 1
end
if edition then
filter = filter + 1
end
if type(rarity) ~= "table" then
if type(rarity) == "string" then
rarity = { rarity }
else
rarity = nil
end
end
if rarity then
filter = filter + 1
end
if type(ability) ~= "table" then
if type(ability) == "string" then
ability = { ability }
else
ability = nil
end
end
if ability then
filter = filter + 1
end
-- return nothing if function is called with no useful arguments
if filter == 0 then
return {}
end
if not area or area == "j" then
for k, v in pairs(G.jokers.cards) do
if v and type(v) == "table" and (non_debuff or not v.debuff) then
local check = 0
if name and v.ability.name == name then
check = check + 1
end
if
edition
and (v.edition and v.edition.key == edition) --[[ make this use Cryptid.safe_get later? if it's possible anyways]]
then
check = check + 1
end
if rarity then
--Passes as valid if rarity matches ANY of the values in the rarity table
for _, a in ipairs(rarity) do
if v.config.center.rarity == a then
check = check + 1
break
end
end
end
if ability then
--Only passes if the joker has everything in the ability table
local abilitycheck = true
for _, b in ipairs(ability) do
if not v.ability[b] then
abilitycheck = false
break
end
end
if abilitycheck then
check = check + 1
end
end
if check == filter then
table.insert(jokers, v)
end
end
end
end
if not area or area == "c" then
for k, v in pairs(G.consumeables.cards) do
if v and type(v) == "table" and (non_debuff or not v.debuff) then
local check = 0
if name and v.ability.name == name then
check = check + 1
end
if
edition
and (v.edition and v.edition.key == edition) --[[ make this use Cryptid.safe_get later? if it's possible anyways]]
then
check = check + 1
end
if ability then
--Only passes if the joker has everything in the ability table
local abilitycheck = true
for _, b in ipairs(ability) do
if not v.ability[b] then
abilitycheck = false
break
end
end
if abilitycheck then
check = check + 1
end
end
--Consumables don't have a rarity, so this should ignore it in that case (untested lmfao)
if check == filter then
table.insert(jokers, v)
end
end
end
end
return jokers
end
-- backwards compat, not needed when smods updates, also doesnt do anything here really
-- mostly just to stop crashes
function cry_prob(owned, den, rigged)
prob = G.GAME and G.GAME.probabilities.normal or 1
if rigged then
return to_number(math.min(den, 1e300))
else
if owned then return to_number(math.min(prob*owned, 1e300)) else return to_number(math.min(prob, 1e300)) end
end
end
function Cryptid.with_deck_effects(card, func)
if not card.added_to_deck then
return func(card)
else
card.from_quantum = true
card:remove_from_deck(true)
local ret = func(card)
card:add_to_deck(true)
card.from_quantum = nil
return ret
end
end
if not (SMODS.Mods["Cryptid"] or {}).can_load then
local set_spritesref = Card.set_sprites
function Card:set_sprites(_center, _front)
set_spritesref(self, _center, _front)
if _center and _center.soul_pos and _center.soul_pos.extra then
self.children.floating_sprite2 = Sprite(
self.T.x,
self.T.y,
self.T.w,
self.T.h,
G.ASSET_ATLAS[_center.atlas or _center.set],
_center.soul_pos.extra
)
self.children.floating_sprite2.role.draw_major = self
self.children.floating_sprite2.states.hover.can = false
self.children.floating_sprite2.states.click.can = false
end
end
SMODS.DrawStep({
key = "floating_sprite2",
order = 59,
func = function(self)
if
self.config.center.soul_pos
and self.config.center.soul_pos.extra
and (self.config.center.discovered or self.bypass_discovery_center)
then
local scale_mod = 0.07 -- + 0.02*math.cos(1.8*G.TIMERS.REAL) + 0.00*math.cos((G.TIMERS.REAL - math.floor(G.TIMERS.REAL))*math.pi*14)*(1 - (G.TIMERS.REAL - math.floor(G.TIMERS.REAL)))^3
local rotate_mod = 0 --0.05*math.cos(1.219*G.TIMERS.REAL) + 0.00*math.cos((G.TIMERS.REAL)*math.pi*5)*(1 - (G.TIMERS.REAL - math.floor(G.TIMERS.REAL)))^2
if self.children.floating_sprite2 then
self.children.floating_sprite2:draw_shader(
"dissolve",
0,
nil,
nil,
self.children.center,
scale_mod,
rotate_mod,
nil,
0.1 --[[ + 0.03*math.cos(1.8*G.TIMERS.REAL)--]],
nil,
0.6
)
self.children.floating_sprite2:draw_shader(
"dissolve",
nil,
nil,
nil,
self.children.center,
scale_mod,
rotate_mod
)
else
local center = self.config.center
if _center and _center.soul_pos and _center.soul_pos.extra then
self.children.floating_sprite2 = Sprite(
self.T.x,
self.T.y,
self.T.w,
self.T.h,
G.ASSET_ATLAS[_center.atlas or _center.set],
_center.soul_pos.extra
)
self.children.floating_sprite2.role.draw_major = self
self.children.floating_sprite2.states.hover.can = false
self.children.floating_sprite2.states.click.can = false
end
end
end
end,
conditions = { vortex = false, facing = "front" },
})
SMODS.draw_ignore_keys.floating_sprite2 = true
end
local inj = SMODS.injectItems
function SMODS.injectItems(...)
inj(...)
local keys = {}
local a_keys = {}
for i, v in pairs(SMODS.scoring_parameter_keys) do
if not keys[v] then
a_keys[#a_keys+1] = v
end
keys[v] = true
end
SMODS.scoring_parameter_keys = a_keys
end
function Cryptid.pulse_flame(duration, intensity) -- duration is in seconds, intensity is in idfk honestly, but it increases pretty quickly
G.cry_flame_override = G.cry_flame_override or {}
G.cry_flame_override["duration"] = duration or 0.01
G.cry_flame_override["intensity"] = intensity or 2
end
function Cryptid.get_next_tag()
end
function Cryptid.is_number(x)
return type(x) == "number" or (type(x) == "table" and is_number(x)) or (is_big and is_big(x))
end
function Cryptid.is_big(x)
return (type(x) == "table" and is_number(x)) or (is_big and is_big(x))
end
function Cryptid.clamp(x, min, max)
return math.max(min, math.min(x, max))
end