-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUnstableEX.lua
More file actions
2156 lines (1778 loc) · 63.9 KB
/
UnstableEX.lua
File metadata and controls
2156 lines (1778 loc) · 63.9 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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local unstbex = SMODS.current_mod
local filesystem = NFS or love.filesystem
local path = unstbex.path
local unstbex_config = unstbex.config
--Global Table
unstbex_global = {}
unstbex_global.config = unstbex.config
unstbex_lib = {}
--Library
SMODS.load_file("/lib/suit_compat.lua")()
--Localization Messages
--local loc = filesystem.load(path..'localization.lua')()
-- Debug message
local function print(message)
sendDebugMessage('[UnstableEX] - '..(tostring(message) or '???'))
end
print("Starting UnstableEX")
--Compat List
unstbex_global.compat = {
Bunco = (SMODS.Mods["Bunco"] or {}).can_load,
Familiar = (SMODS.Mods["familiar"] or {}).can_load,
Ortalab = (SMODS.Mods["ortalab"] or {}).can_load,
Six_Suit = (SMODS.Mods["SixSuits"] or {}).can_load,
Inks_Color = (SMODS.Mods["InkAndColor"] or {}).can_load,
Cryptid = (SMODS.Mods["Cryptid"] or {}).can_load,
CustomCards = (SMODS.Mods["CustomCards"] or {}).can_load,
Pokermon = (SMODS.Mods["Pokermon"] or {}).can_load,
KCVanilla = (SMODS.Mods["kcvanilla"] or {}).can_load,
DnDJ = (SMODS.Mods["dndj"] or {}).can_load,
MtJ = (SMODS.Mods["magic_the_jokering"] or {}).can_load,
Minty = (SMODS.Mods["MintysSillyMod"] or {}).can_load,
Cardsauce = (SMODS.Mods["Cardsauce"] or {}).can_load,
Showdown = (SMODS.Mods["showdown"] or {}).can_load,
Paperback = (SMODS.Mods["paperback"] or {}).can_load,
}
local function check_mod_active(mod_id)
return unstbex_global.compat[mod_id]
end
--Config Stuff
function unstbex.save_config(self)
SMODS.save_mod_config(self)
end
local unstbex_config_tab = function()
--Dynamically Building Config Based on loaded mods
--I'll figure out how to make paginations later
local mod_config_ui_tables = {}
local function create_mod_config(mod_name, conf_list)
if not check_mod_active(mod_name.key) then return end
local ui_nodes = {}
ui_nodes[1] = {n=G.UIT.R, config={align = "cm"}, nodes={{n = G.UIT.T, config = {text = mod_name.name or mod_name.key, colour = G.C.ORANGE, scale = 0.5}}}}
for k,v in pairs(conf_list) do
ui_nodes[#ui_nodes+1] = create_toggle({label = v.label, ref_table = unstbex.config[v.ref_table], ref_value = k, callback = function() unstbex:save_config() end})
end
mod_config_ui_tables[#mod_config_ui_tables+1] = {n=G.UIT.R, config={align = "cl"}, nodes = ui_nodes }
end
local function mod_config_ui_init()
--List of ALL possible mod config
create_mod_config({key= "DnDJ", name = "DnDJ"}, {
keep_sprite = {label = "Keep Rank Sprites", ref_table = "dndj"},
})
create_mod_config({key= "Showdown", name = "Showdown"}, {
use_decimal = {label = "Use Decimal Mechanics", ref_table = "showdown"},
replace_zero = {label = "Replace Rank 0", ref_table = "showdown"},
})
end
mod_config_ui_init();
--Rendering
local render_table = {}
local restart_header = nil
if #mod_config_ui_tables > 0 then
for i=1, #mod_config_ui_tables do
render_table[#render_table+1] = mod_config_ui_tables[i]
end
restart_header = {n=G.UIT.R, config={align = "cm"}, nodes={{n = G.UIT.T, config = {text = localize("unstb_config_requires_restart"), colour = G.C.RED, scale = 0.4}}}}
else
render_table = {{n=G.UIT.R, config={align = "cl"}, nodes={
{n=G.UIT.R, config={align = "cm"}, nodes={{n = G.UIT.T, config = {text = "No configurable options found for the current modlist", scale = 0.5}}}},
}}}
end
return{
{
label = "Config",
chosen = true,
tab_definition_function = function()
return {
n = G.UIT.ROOT,
config = {
emboss = 0.05,
minh = 6,
r = 0.1,
minw = 10,
align = "cm",
padding = 0.2,
colour = G.C.BLACK,
},
nodes = {
{n=G.UIT.R, config={align = "cm"}, nodes= {restart_header} },
{n=G.UIT.R, config={align = "cm"}, nodes={ --Base Box containing everything
-- Left Side Column
{n=G.UIT.C, config={align = "cl", padding = 0.2}, nodes = render_table },
-- Right Side Column
--{n=G.UIT.C, config={align = "cl"}, nodes = render_table},
}}
},
}
end
},
--[[{ --Reserved Tab, in case the settings are expended in the future
label = localize("unstb_config_header_joker_settings"),
tab_definition_function = function()
return {
n = G.UIT.ROOT,
config = {
emboss = 0.05,
minh = 6,
r = 0.1,
minw = 10,
align = "cm",
padding = 0.2,
colour = G.C.BLACK,
},
nodes = {
},
}
end
}]]
}
end
unstbex.extra_tabs = unstbex_config_tab
--Just so the gear icon shows up
unstbex.config_tab = true
--Map config value with a single string keyword
local config_value = {
--["rank_21"] = unstb_config.rank.rank_21,
}
--Utility
--Auto event scheduler, based on Bunco
local function event(config)
local e = Event(config)
G.E_MANAGER:add_event(e)
return e
end
local function big_juice(card)
card:juice_up(0.7)
end
local function extra_juice(card)
card:juice_up(0.6, 0.1)
end
local function play_nope_sound()
--Copied from Wheel of Fortune lol
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)
end
local function forced_message(message, card, color, delay, juice)
if delay == true then
delay = 0.7 * 1.25
elseif delay == nil then
delay = 0
end
event({trigger = 'before', delay = delay, func = function()
if juice then big_juice(juice) end
card_eval_status_text(
card,
'extra',
nil, nil, nil,
{message = message, colour = color, instant = true}
)
return true
end})
end
-- Index-based coordinates generation
local function get_coordinates(position, width)
if width == nil then width = 10 end -- 10 is default for Jokers
return {x = (position) % width, y = math.floor((position) / width)}
end
--Mod Icon
SMODS.Atlas {
-- Key for code to find it with
key = "modicon",
-- The name of the file, for the code to pull the atlas from
path = "modicon.png",
-- Width of each sprite in 1x size
px = 32,
-- Height of each sprite in 1x size
py = 32
}
--Creates an atlas for cards to use
--[[SMODS.Atlas {
-- Key for code to find it with
key = "unstbEX_jokers",
-- The name of the file, for the code to pull the atlas from
path = "unstbEX_jokers.png",
-- Width of each sprite in 1x size
px = 71,
-- Height of each sprite in 1x size
py = 95
}]]
--Updated Enhancement atli to include modded suits
SMODS.Atlas {
key = "enh_slop",
path = "enh_slop.png",
px = 71,
py = 95
}
SMODS.Atlas {
key = "enh_slop_hc",
path = "enh_slop_hc.png",
px = 71,
py = 95
}
SMODS.Atlas {
key = "enh_res",
path = "enh_res.png",
px = 71,
py = 95
}
--Fallback atlas for extra ranks
SMODS.Atlas {
key = "rank_ex_default",
path = "rank_ex/default/rank_ex.png",
px = 71,
py = 95
}
SMODS.Atlas {
key = "rank_ex2_default",
path = "rank_ex/default/rank_ex2.png",
px = 71,
py = 95
}
--Bunco's resprites suit colours
SMODS.Atlas {
key = "rank_ex_hc_b",
path = "rank_ex/bunco/rank_ex_hc_b.png",
px = 71,
py = 95
}
SMODS.Atlas {
key = "rank_ex2_hc_b",
path = "rank_ex/bunco/rank_ex2_hc_b.png",
px = 71,
py = 95
}
SMODS.Atlas {
key = "enh_slop_hc_b",
path = "enh_slop_hc_b.png",
px = 71,
py = 95
}
--Cardsauce Skin
local use_cardsauce_skin = false
if check_mod_active("Cardsauce") then
use_cardsauce_skin = csau_enabled['enableSkins']
SMODS.Atlas {
key = "rank_ex_cs",
path = "rank_ex/cardsauce/rank_ex_cs.png",
px = 71,
py = 95
}
SMODS.Atlas {
key = "rank_ex2_cs",
path = "rank_ex/cardsauce/rank_ex2_cs.png",
px = 71,
py = 95
}
end
--Familiar's Multi-Suit Cards Fallback
--(I don't think it is possible to make all combinations by myself, especially to account for modded suits)
SMODS.Atlas {
key = "rank_ex_multi",
path = "rank_ex_multi.png",
px = 71,
py = 95
}
SMODS.Atlas {
key = "rank_ex2_multi",
path = "rank_ex2_multi.png",
px = 71,
py = 95
}
--Map new atlas to the rank - new ranks now used more than 1 atlas (split off for maintenance reason)
local rank_atlas_map = {['unstb_0'] = 1,
['unstb_0.5'] = 1,
['unstb_1'] = 1,
['unstb_r2'] = 1,
['unstb_e'] = 1,
['unstb_Pi'] = 1,
['unstb_21'] = 1,
['unstb_???'] = 1,
['unstb_11'] = 2,
['unstb_12'] = 2,
['unstb_13'] = 2,
['unstb_25'] = 2,
['unstb_161'] = 2,}
local rank_atlas_name = {'unstbex_rank_ex', 'unstbex_rank_ex2'}
local rank_atlas_name_base = {'unstb_rank_ex', 'unstb_rank_ex2'}
--Swap the hc atli with bunco resprites version to match suit colours
local using_bunco_resprites = false
if check_mod_active("Bunco") then
if BUNCOMOD and BUNCOMOD.content and BUNCOMOD.content.config then
using_bunco_resprites = BUNCOMOD.content.config.fixed_sprites
end
end
local vanilla_suits = {Hearts = true,
Clubs = true,
Diamonds = true,
Spades = true,
}
unstbex_lib.extra_suits = {}
--Init extra suits information based on loaded mod
if check_mod_active("Bunco") then
unstbex_lib.init_suit_compat('bunc_Fleurons', 'bunco')
unstbex_lib.init_suit_compat('bunc_Halberds', 'bunco')
end
if check_mod_active("Six_Suit") then
unstbex_lib.init_suit_compat('six_Stars', 'sixsuits', true)
unstbex_lib.init_suit_compat('six_Moons', 'sixsuits', true)
end
if check_mod_active("Inks_Color") then
unstbex_lib.init_suit_compat('ink_Inks', 'inkscolor')
unstbex_lib.init_suit_compat('ink_Colors', 'inkscolor')
end
if check_mod_active("MtJ") then
unstbex_lib.init_suit_compat('mtg_Clovers', 'mtj')
unstbex_lib.init_suit_compat('mtg_Suitless', 'mtj')
end
if check_mod_active("Minty") then
unstbex_lib.init_suit_compat('minty_3s', 'minty', true)
end
if check_mod_active("Paperback") then
unstbex_lib.init_suit_compat('paperback_Stars', 'paperback')
unstbex_lib.init_suit_compat('paperback_Crowns', 'paperback')
end
--Suit injection code based on Showdown by Mistyk__
local function inject_p_card_suit_compat(suit, rank)
local card = {
name = rank.key .. ' of ' .. suit.key,
value = rank.key,
suit = suit.key,
pos = { x = rank.pos.x, y = rank.suit_map[suit.key] or suit.pos.y },
lc_atlas = rank.suit_map[suit.key] and rank.lc_atlas or suit.lc_atlas,
hc_atlas = rank.suit_map[suit.key] and rank.hc_atlas or suit.hc_atlas,
}
if not vanilla_suits[card.suit] then
if not unstbex_lib.extra_suits[card.suit] then
print("Warning: Unknown suit for "..card.name)
card.lc_atlas = rank_atlas_name[rank_atlas_map[rank.key]]..'_default'
card.hc_atlas = rank_atlas_name[rank_atlas_map[rank.key]]..'_default'
card.pos.y = 0
else
card.lc_atlas = unstbex_lib.extra_suits[card.suit].lc_atlas[rank_atlas_map[rank.key]]
card.hc_atlas = unstbex_lib.extra_suits[card.suit].hc_atlas[rank_atlas_map[rank.key]]
end
end
G.P_CARDS[suit.card_key .. '_' .. rank.card_key] = card
end
local function rank_injection(self)
print("Performing extra rank injection")
for _, suit in pairs(SMODS.Suits) do
inject_p_card_suit_compat(suit, self)
end
end
--Injected Rank List, will loop over all possible ranks
--table: key = rank_key, pos_x = rank's x position
local inject_rank_list = {}
local function inject_rank_atlas(prefix)
for k,v in pairs(SMODS.Ranks) do
if k:find(prefix) then
local rank = SMODS.Ranks[k]
rank.inject = rank_injection
--[[if use_cardsauce_skin then
rank.lc_atlas = rank_atlas_name[rank_atlas_map[k] ]..'_cs'
rank.hc_atlas = rank_atlas_name[rank_atlas_map[k] ]..'_cs'
end
if using_bunco_resprites then
rank.hc_atlas = rank_atlas_name[rank_atlas_map[k] ]..'_hc_b'
end]]
inject_rank_list[#inject_rank_list+1] = {key = k, pos_x = rank.pos.x}
--[[rank.lc_atlas = rank_atlas_map[k]
rank.hc_atlas = using_bunco_resprites and rank_atlas_map[k]..'_hc_b' or rank_atlas_map[k]..'_hc'
rank.suit_map = unstbex_global.rank_suit_map]]
print("Injecting the graphic for rank "..rank.key)
end
end
end
inject_rank_atlas('unstb_')
--Default DeckSkin Injection for all base suits
local target_palette = {'lc', 'hc'}
for target_suit, _ in pairs(unstbex_lib.extra_suits) do
local deckSkin = SMODS.DeckSkins['default_'..target_suit]
if deckSkin then
for _, i in ipairs(target_palette) do
if deckSkin.palette_map[i] then
--ds_halberd.palette[p]
local pos_style = {fallback_style = 'deck'}
for _,rank in ipairs(inject_rank_list) do
table.insert(deckSkin.palette_map[i].ranks, rank.key)
end
--ds_halberd.palettes[i].ranks
local suit_y = SMODS.Suits[target_suit].pos.y
for _,rank in ipairs(inject_rank_list) do
local atlas = i == 'hc' and unstbex_lib.extra_suits[target_suit].hc_atlas[rank_atlas_map[rank.key]] or unstbex_lib.extra_suits[target_suit].lc_atlas[rank_atlas_map[rank.key]]
pos_style[rank.key] = {atlas = atlas, pos = { x = rank.pos_x, y = suit_y } }
end
deckSkin.palette_map[i].pos_style = pos_style
deckSkin.pos_style = pos_style
--Adds hc_default property to the hc pallete by default (for some reason SMODS didnt)
if i == 'hc' then
deckSkin.palette_map[i].hc_default = true
end
end
end
end
end
--Inject Bunco Recast Contrast
if check_mod_active("Bunco") then
for k, _ in pairs(vanilla_suits) do
local deckSkin = SMODS.DeckSkins['default_'..k]
if deckSkin then
local palette = deckSkin.palette_map['recast_contrast']
local pos_style = {fallback_style = 'deck'}
for _,rank in ipairs(inject_rank_list) do
table.insert(palette.ranks, rank.key)
end
local suit_y = SMODS.Suits[k].pos.y
for _,rank in ipairs(inject_rank_list) do
local atlas = rank_atlas_name[rank_atlas_map[rank.key] ]..'_hc_b'
pos_style[rank.key] = {atlas = atlas, pos = { x = rank.pos_x, y = suit_y } }
end
palette.pos_style = pos_style
end
end
end
--Inject All CardSauce Palletes
--This is a complete Spaghetti I apologize
if check_mod_active("Cardsauce") then
for deck_key, deck_skin in pairs(SMODS.DeckSkins) do
--Skip if there is no pallete
if deck_skin.palette_map then
for k, p in pairs(deck_skin.palette_map) do
if p.atlas == 'csau_default' then
--print('inject skin '..deck_key..' '..k)
if p.pos_style and type(p.pos_style) ~= 'table' then
p.pos_style = {fallback_style = 'deck'}
end
pos_style = p.pos_style
for _,rank in ipairs(inject_rank_list) do
table.insert(p.ranks, rank.key)
end
local suit_y = SMODS.Suits[deck_skin.suit].pos.y
for _,rank in ipairs(inject_rank_list) do
local atlas = rank_atlas_name[rank_atlas_map[rank.key] ]..'_cs'
pos_style[rank.key] = {atlas = atlas, pos = { x = rank.pos_x, y = suit_y } }
end
elseif p.atlas == 'cards_1' and k:find('csau_') then --Standard Game Low Contrast
--print('inject skin '..deck_key..' '..k)
if p.pos_style and type(p.pos_style) ~= 'table' then
p.pos_style = {fallback_style = 'deck'}
end
pos_style = p.pos_style
for _,rank in ipairs(inject_rank_list) do
table.insert(p.ranks, rank.key)
end
local suit_y = SMODS.Suits[deck_skin.suit].pos.y
for _,rank in ipairs(inject_rank_list) do
local atlas = rank_atlas_name_base[rank_atlas_map[rank.key] ]
pos_style[rank.key] = {atlas = atlas, pos = { x = rank.pos_x, y = suit_y } }
end
elseif p.atlas == 'cards_2' and k:find('csau_') then --Standard Game High Contrast
--print('inject skin '..deck_key..' '..k)
if p.pos_style and type(p.pos_style) ~= 'table' then
p.pos_style = {fallback_style = 'deck'}
end
pos_style = p.pos_style
for _,rank in ipairs(inject_rank_list) do
table.insert(p.ranks, rank.key)
end
local suit_y = SMODS.Suits[deck_skin.suit].pos.y
for _,rank in ipairs(inject_rank_list) do
local atlas = rank_atlas_name_base[rank_atlas_map[rank.key] ]..'_hc'
pos_style[rank.key] = {atlas = atlas, pos = { x = rank.pos_x, y = suit_y } }
end
end
end
end
end
end
--Register Suits for UnStable suit system
--Modded Suits Code in UnStableEX
--Bunco
--[[register_suit_group("suit_black", "bunc_Halberds")
register_suit_group("suit_red", "bunc_Fleurons")
register_suit_group("suit_black", "six_Moons")
register_suit_group("suit_red", "six_Stars")
register_suit_group("no_smear", "Inks_Inks")
register_suit_group("no_smear", "Inks_Color")]]
--Update extended atlas for Slop and Resource Cards
--Separated from rank suit map now
local enhancement_suit_map = {
Hearts = 0,
Clubs = 1,
Diamonds = 2,
Spades = 3,
bunc_Fleurons = 4,
bunc_Halberds = 5,
six_Stars = 6,
six_Moons = 7,
ink_Inks = 8,
ink_Colors = 9,
}
local center_unstb_slop = SMODS.Centers['m_unstb_slop'] or {}
center_unstb_slop.suit_map = enhancement_suit_map
center_unstb_slop.atlas = 'unstbex_enh_slop'
center_unstb_slop.lc_atlas = 'unstbex_enh_slop'
center_unstb_slop.hc_atlas = using_bunco_resprites and 'unstbex_enh_slop_hc_b' or 'unstbex_enh_slop_hc'
local center_unstb_resource = SMODS.Centers['m_unstb_resource'] or {}
center_unstb_resource.suit_map = enhancement_suit_map
center_unstb_resource.atlas = 'unstbex_enh_res'
--Generic Rank Replacement Utility
--A map of orignal mod's rank, to new rank, and the mod's tag to check if the config is enabled or not
local replace_rank_map = {}
function register_rank_replacement(originalrank, newrank, keepsprite)
replace_rank_map[originalrank] = {new_rank = newrank, keep_sprite = keepsprite}
end
local ref_card_set_base = Card.set_base
function Card:set_base(card, initial)
card = card or {}
ref_card_set_base(self, card, initial)
--Only run this piece of codes when inside the run (so, menu animations aren't interrupted)
if G.GAME and G.GAME.blind then
if self.base and self.base.value and replace_rank_map[self.base.value] then
local replace_rank_data = replace_rank_map[self.base.value]
if replace_rank_data.keep_sprite and vanilla_suits[self.base.suit] then
--Re-assign the rank to UnStable's equivalent
--Doing it this way should keep the sprites unchanged
--Automatically replaced it completely if the suit isn't vanilla for stable reasons
self.base.value = replace_rank_data.new_rank
local rank = SMODS.Ranks[self.base.value] or {}
self.base.nominal = rank.nominal or 0
self.base.face_nominal = rank.face_nominal or 0
self.base.id = rank.id
else
SMODS.change_base(self, nil, replace_rank_map[self.base.value].new_rank)
end
end
end
end
--Blacklist "top" ranks for many jokers
local top_rank_blacklist = {
['Ace'] = true,
['unstb_21'] = true,
['unstb_25'] = true,
['unstb_161'] = true,
['unstb_???'] = true,
}
if check_mod_active("Bunco") then
print("Inject Bunco Jokers")
local bunc_pawn = SMODS.Centers['j_bunc_pawn'] or {}
--Blacklist ranks for Pawn
bunc_pawn.loc_vars = function(self, info_queue, card)
if G.playing_cards and #G.playing_cards > 0 then
local rank = math.huge
local target_rank = 'unstb_???';
for _, deck_card in ipairs(G.playing_cards) do
local newrank = deck_card.base.nominal + (deck_card.base.face_nominal or 0)
if newrank < rank and (not deck_card.config.center.no_rank or deck_card.config.center ~= G.P_CENTERS.m_stone) then
rank = newrank
target_rank = deck_card.base.value
end
end
return {vars = {localize(target_rank, 'ranks')}}
end
return {vars = {localize('2', 'ranks')}}
end
bunc_pawn.calculate = function(self, card, context)
if context.after and context.scoring_hand and not context.blueprint then
for i = 1, #context.scoring_hand do
local condition = false
local other_card = context.scoring_hand[i]
local rank = math.huge
local target_rank = 'unstb_???';
for _, deck_card in ipairs(G.playing_cards) do
local newrank = deck_card.base.nominal + (deck_card.base.face_nominal or 0)
if newrank < rank and (not deck_card.config.center.no_rank or deck_card.config.center ~= G.P_CENTERS.m_stone) then
rank = newrank
target_rank = deck_card.base.value
end
end
if other_card.base.value == target_rank and not top_rank_blacklist[other_card.base.value] then
condition = true
event({trigger = 'after', delay = 0.15, func = function() other_card:flip(); play_sound('card1', 1); other_card:juice_up(0.3, 0.3); return true end })
event({
trigger = 'after',
delay = 0.1,
func = function()
local new_rank = get_next_x_rank(other_card.base.value, 1)
assert(SMODS.change_base(other_card, nil, new_rank))
return true
end
})
event({trigger = 'after', delay = 0.15, func = function() other_card:flip(); play_sound('tarot2', 1, 0.6); big_juice(card); other_card:juice_up(0.3, 0.3); return true end })
end
if condition then delay(0.7 * 1.25) end
end
end
end
local bunc_zero_shapiro = SMODS.Centers['j_bunc_zero_shapiro'] or {}
local zeroshapiro_zerorank = {
['unstb_0'] = true,
['unstb_???'] = true,
['Jack'] = true,
['Queen'] = true,
['King'] = true,
['showdown_Butler'] = true,
['showdown_Princess'] = true,
['showdown_Lord'] = true,
['showdown_Zero'] = true,
}
bunc_zero_shapiro.calculate = function(self, card, context)
if context.individual and context.cardarea == G.play then
if context.other_card.config.center.no_rank or zeroshapiro_zerorank[context.other_card.base.value] then
if pseudorandom('zero_shapiro'..G.SEED) < G.GAME.probabilities.normal / card.ability.extra.odds then
return {
extra = {message = '+'..localize{type = 'name_text', key = 'tag_d_six', set = 'Tag'}, colour = G.C.GREEN},
card = card,
func = function()
event({func = function()
add_tag(Tag('tag_d_six'))
return true
end})
end
}
end
end
end
end
local bunc_crop_circles = SMODS.Centers['j_bunc_crop_circles'] or {}
local crop_circles_rank_mult = {
['unstb_0'] = 1,
['unstb_0.5'] = 1,
['6'] = 1,
['8'] = 2,
['9'] = 1,
['10'] = 1,
['Queen'] = 1,
['unstb_161'] = 1,
['showdown_8.5'] = 2,
--['showdown_Butler'] = 2,
--['showdown_Princess'] = 1,
['showdown_Zero'] = 1,
}
--Implemented differently than in Bunco, but should yield the same result
bunc_crop_circles.calculate = function(self, card, context)
if context.individual and context.cardarea == G.play then
local other_card = context.other_card
local total_mult = 0
--Check suit
if not other_card.config.center.no_suit then
if other_card.base.suit == 'bunc_Fleurons' then
total_mult = total_mult + 4
elseif other_card.base.suit == 'Clubs' then
total_mult = total_mult + 3
elseif other_card.base.suit == 'mtg_Clovers' then
total_mult = total_mult + 4
end
end
--Check rank
if not other_card.config.center.no_rank then
if crop_circles_rank_mult[other_card.base.value] then
total_mult = total_mult + crop_circles_rank_mult[other_card.base.value]
end
end
--If the amount is greater than 0, grant the bonus w/ animation
if total_mult > 0 then
return {
mult = total_mult,
card = card
}
end
end
end
end
--Hook to Familiar's set_sprite_suits to account for new ranks
local unstb_ranks_pos = {['unstb_0'] = 6,
['unstb_0.5'] = 2,
['unstb_1'] = 5,
['unstb_r2'] = 7,
['unstb_e'] = 3,
['unstb_Pi'] = 4,
['unstb_21'] = 0,
['unstb_???'] = 1,
['unstb_11'] = 0,
['unstb_12'] = 1,
['unstb_13'] = 2,
['unstb_25'] = 3,
['unstb_161'] = 4,}
if check_mod_active("Familiar") then
print('Inject Familiar set_sprite_suits')
local ref_set_sprite_suits = set_sprite_suits
function set_sprite_suits(card, juice)
ref_set_sprite_suits(card, juice)
--If the rank is one of the UnStable Rank, and has one of the ability
if unstb_ranks_pos[card.base.value] and (card.ability.is_spade or card.ability.is_heart or card.ability.is_club or card.ability.is_diamond or card.ability.suitless) then
--print('UnstbEX Set Sprite Suit Hook Active')
local suit_check = {card.base.suit == 'Spades' or card.ability.is_spade or false,
card.base.suit == 'Hearts' or card.ability.is_heart or false,
card.base.suit == 'Clubs' or card.ability.is_club or false,
card.base.suit == 'Diamonds' or card.ability.is_diamond or false}
local suit_count = 0
for i=1, #suit_check do
if suit_check[i] then
suit_count = suit_count+1
end
end
--Suitless, or has more than 1 suits
if card.ability.suitless or suit_count>1 then
--Technically, if anyone wants to make it works properly, this would be where to check
--Unfortunately, I don't think I can write them all because there's a lot of combination + lots of graphic to make
--Hopefully there is a more elegant solution found in the future.
card.children.front.atlas = G.ASSET_ATLAS[rank_atlas_name[rank_atlas_map[card.base.value]]..'_multi']
card.children.front:set_sprite_pos({x = unstb_ranks_pos[card.base.value], y = 0})
end
end
end
print("Inject Familiar Vigor Fortune Card")
local familiar_vigor = SMODS.Centers['c_fam_vigor'] or {}
--Reimplemented Familiar Vigor Fortune Card to use get_next_x_rank instead
familiar_vigor.use = function(self, card)
for i = 1, #G.hand.highlighted do
for j = 1, 3 do
G.E_MANAGER:add_event(Event({trigger = 'after',delay = 0.1,func = function()
local card = G.hand.highlighted[i]
local new_rank = get_next_x_rank(card.base.value, 1)
assert(SMODS.change_base(card, nil, new_rank))
card:juice_up(0.3, 0.5)
return true end }))
end
end
end
end
--Re-implementation of Ortalab's Index Card functions to support UNSTB Ranks
--Notice: this rank changes the behavior from vanilla slightly, where rank 0 and 1 is immediately available
local main_rankList = {'unstb_0', 'unstb_1', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King', 'Ace'}
--Special UNSTB Rank is pre-defined
local rankMap = { ['unstb_0.5'] = {UP = 'unstb_1', MID = 'unstb_0.5' , DOWN = 'unstb_0'},
['unstb_r2'] = {UP = '2', MID = 'unstb_r2' , DOWN = 'unstb_1'},
unstb_e = {UP = '3', MID = 'unstb_e' , DOWN = '2'},
unstb_Pi = {UP = '4', MID = 'unstb_Pi' , DOWN = '3'},
unstb_21 = {UP = 'unstb_21', MID = 'unstb_21' , DOWN = 'unstb_21'},
unstb_11 = {UP = 'unstb_12', MID = 'unstb_11' , DOWN = '10'},
unstb_12 = {UP = 'unstb_13', MID = 'unstb_12' , DOWN = 'unstb_11'},
unstb_13 = {UP = 'Ace', MID = 'unstb_13' , DOWN = 'unstb_12'},
unstb_25 = {UP = 'unstb_25', MID = 'unstb_25' , DOWN = 'unstb_25'},
unstb_161 = {UP = 'unstb_161', MID = 'unstb_161' , DOWN = 'unstb_161'},
['unstb_???'] = {UP = 'unstb_???', MID = 'unstb_???' , DOWN = 'unstb_???'},
['showdown_2.5'] = {UP = '3', MID = 'showdown_2.5' , DOWN = '2'},
['showdown_5.5'] = {UP = '6', MID = 'showdown_5.5' , DOWN = '5'},
['showdown_8.5'] = {UP = '9', MID = 'showdown_8.5' , DOWN = '8'},
['showdown_Butler'] = {UP = 'Queen', MID = 'showdown_Butler' , DOWN = 'Jack'},
['showdown_Princess'] = {UP = 'King', MID = 'showdown_Princess' , DOWN = 'Queen'},
['showdown_Lord'] = {UP = 'Ace', MID = 'showdown_Lord' , DOWN = 'King'},
['showdown_Zero'] = {UP = 'unstb_1', MID = 'showdown_Zero' , DOWN = 'Ace'},
}
for i=1, #main_rankList do
rankMap[main_rankList[i]] = {UP = main_rankList[i+1] or main_rankList[1], MID = main_rankList[i], DOWN = main_rankList[i-1] or main_rankList[#main_rankList]}
end
--print(inspectDepth(rankMap))
if check_mod_active("Ortalab") then
print('Inject Ortalab Index Card')
--Inject new property into Ortalab index card
local ortalab_index = SMODS.Centers['m_ortalab_index'] or {}
ortalab_index.set_ability = function(self, card, initial, delay_sprites)
print('call set ability')
if card.base and card.ability and card.ability.extra and type(card.ability.extra) == 'table' then
if card.ability.extra.index_state == 'MID' then
card.ability.extra.mainrank = card.base.value
elseif card.ability.extra.index_state == 'UP' then
card.ability.extra.mainrank = rankMap[card.base.value]['DOWN']
elseif card.ability.extra.index_state == 'DOWN' then
card.ability.extra.mainrank = rankMap[card.base.value]['UP']
end
end
end
ortalab_index.set_sprites = function(self, card, front)
if card.ability and card.ability.extra and type(card.ability.extra) == 'table' then
if card.ability.extra.index_state == 'MID' then
card.children.center:set_sprite_pos({x = 2, y = 0})
elseif card.ability.extra.index_state == 'UP' then
--card.ability.extra.mainrank = rankMap[card.base.value]['DOWN']
card.children.center:set_sprite_pos({x = 1, y = 2})
elseif card.ability.extra.index_state == 'DOWN' then
card.children.center:set_sprite_pos({x = 0, y = 2})
end
--print('main card value is '.. card.ability.extra.mainrank)
end
end