-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathrandomizer.lua
More file actions
2884 lines (2505 loc) · 97.3 KB
/
randomizer.lua
File metadata and controls
2884 lines (2505 loc) · 97.3 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
--- STEAMODDED HEADER
--- MOD_NAME: Archipelago Randomizer
--- MOD_ID: Rando
--- MOD_AUTHOR: [Burndi, SpaD_Overolls, Myst, Silvris]
--- MOD_DESCRIPTION: Archipelago Client for Balatro
--- PRIORITY: 8000
--- PREFIX: rand
--- BADGE_COLOR: 4E8BE6
--- DISPLAY_NAME: Archipelago
--- VERSION: 0.1.9f-indev-2
--- DEPENDENCIES: [Steamodded>=1.0.0~BETA-0614a]
----------------------------------------------
------------MOD CODE -------------------------
G.AP = {
APAddress = "archipelago.gg",
APPort = 38281,
APSlot = "Player1",
APPassword = "",
id_offset = 5606000
}
G.AP.stake_unlock_modes = {
["unlocked"] = 0,
["vanilla"] = 1,
["linear"] = 2,
["stake_as_item"] = 3,
["stake_as_item_per_deck"] = 4
}
G.AP.location_id_to_item_name = {}
G.AP.game_over_by_deathlink = false
G.AP.this_mod = SMODS.current_mod
G.AP.this_mod.process_loc_text = function()
G.localization.misc.labels.rand_ap_borrowed = 'Borrowed'
G.localization.descriptions.Other.debuffed_default_b = {}
G.localization.descriptions.Other.debuffed_default_b.name = G.localization.descriptions.Other.debuffed_default.name
G.localization.descriptions.Other.debuffed_default_b.text = {}
for k, v in ipairs(G.localization.descriptions.Other.debuffed_default.text) do
G.localization.descriptions.Other.debuffed_default_b.text[k] = v
end
end
NFS.load(G.AP.this_mod.path .. "ap_connection.lua")()
NFS.load(G.AP.this_mod.path .. "utils.lua")()
NFS.load(G.AP.this_mod.path .. "misc.lua")()
NFS.load(G.AP.this_mod.path .. "stake.lua")()
NFS.load(G.AP.this_mod.path .. "UIdefinitions.lua")()
NFS.load(G.AP.this_mod.path .. "atlas.lua")()
NFS.load(G.AP.this_mod.path .. "modsupport.lua")()
function G.AP.prepare_dll()
local workdir = NFS.getWorkingDirectory()
local dll_loc = G.AP.this_mod.path .. "lua-apclientpp"
NFS.setWorkingDirectory(dll_loc)
AP = require('lua-apclientpp')
NFS.setWorkingDirectory(workdir)
end
json = NFS.load(G.AP.this_mod.path .. "json.lua")()
G.AP.prepare_dll()
local isInProfileTabCreation = false
local isInRunInfoTabCreation = false
local isInProfileOptionCreation = false
local unloadAPProfile = false
local ap_profile_delete = false
local standard_deck = nil
local deck_list = {}
deck_list[0] = 'Red Deck'
deck_list[1] = 'Blue Deck'
deck_list[2] = 'Yellow Deck'
deck_list[3] = 'Green Deck'
deck_list[4] = 'Black Deck'
deck_list[5] = 'Magic Deck'
deck_list[6] = 'Nebula Deck'
deck_list[7] = 'Ghost Deck'
deck_list[8] = 'Abandoned Deck'
deck_list[9] = 'Checkered Deck'
deck_list[10] = 'Zodiac Deck'
deck_list[11] = 'Painted Deck'
deck_list[12] = 'Anaglyph Deck'
deck_list[13] = 'Plasma Deck'
deck_list[14] = 'Erratic Deck'
G.AP.profile_Id = -1
G.AP.GameObjectInit = false
G.AP.StakesInit = false
G.AP.UnlockConsCache = {}
G.AP.ChallengeCache = {}
G.AP.Spectral = {
item = nil,
active = false,
item_detected = false
}
-- stake cursor used for AP logic
G.viewed_stake_act = {}
G.viewed_stake_act[1] = 1
G.viewed_stake_act[2] = 1
-- true if the profile was selected and loaded
function isAPProfileLoaded()
return G.SETTINGS and G.AP and G.SETTINGS.profile == G.AP.profile_Id
end
-- true if the profile is selected in profile selection, does not have to be loaded yet
function isAPProfileSelected()
return G.focused_profile == G.AP.profile_Id
end
G.AP.create_ap_profile = function()
if G.AP.profile_Id == -1 then
G.AP.profile_Id = #G.PROFILES + 1
G.PROFILES[G.AP.profile_Id] = {}
G.AP.log("Created AP Profile in Slot " .. tostring(G.AP.profile_Id))
-- load data to avoid resetting the text inputs
local APSettings = NFS.read('APSettings.json')
if APSettings ~= nil then
APSettings = json.decode(APSettings)
if APSettings ~= nil then
G.AP.APSlot = APSettings['APSlot'] or G.AP.APSlot
G.AP.APAddress = APSettings['APAddress'] or G.AP.APAddress
G.AP.APPort = APSettings['APPort'] or G.AP.APPort
G.AP.APPassword = APSettings['APPassword'] or G.AP.APPassword
end
end
end
end
G.FUNCS.can_APConnect = function(e)
if (G.APClient) then
e.config.button = nil
e.config.colour = G.C.UI.BACKGROUND_INACTIVE
else
e.config.button = 'APConnect'
e.config.colour = G.C.RED
end
end
-- gets called when connection wants to be established. Also saves Connection info in json
G.FUNCS.APConnect = function(e)
local APInfo = json.encode({
APAddress = G.AP.APAddress,
APPort = G.AP.APPort,
APSlot = G.AP.APSlot,
APPassword = G.AP.APPassword
})
NFS.write('APSettings.json', APInfo)
APConnect()
end
-- gets called when connection wants to be ended (for example when selecting non AP profile)
G.FUNCS.APDisconnect = function(sanity_check)
G.APClient = nil
collectgarbage("collect")
unloadAPProfile = true
standard_deck = nil
G.E_MANAGER.queues.ap_hints = nil
G.AP.GameObjectInit = false
G.PROFILES[G.AP.profile_Id] = {}
G.AP.hints = nil
G.AP.hint_locations = nil
G.AP.player_names = nil
G.AP.hint_priotiy = nil
G.AP.Spectral = {
item = nil,
active = false,
item_detected = false
}
if sanity_check then
if G.SETTINGS.profile == G.AP.profile_Id then G.SETTINGS.profile = 1 end
end
end
-- Initialize AP Buffs
local init_game_objectRef = Game.init_game_object
function Game:init_game_object()
local init_game_object = init_game_objectRef(self)
if isAPProfileLoaded() then
init_game_object.starting_params.hands = init_game_object.starting_params.hands +
(G.PROFILES[G.AP.profile_Id]["bonushands"] or 0)
init_game_object.starting_params.discards = init_game_object.starting_params.discards +
(G.PROFILES[G.AP.profile_Id]["bonusdiscards"] or 0)
init_game_object.starting_params.dollars = init_game_object.starting_params.dollars +
(G.PROFILES[G.AP.profile_Id]["bonusstartingmoney"] or 0)
init_game_object.starting_params.hand_size = init_game_object.starting_params.hand_size +
(G.PROFILES[G.AP.profile_Id]["bonushandsize"] or 0)
local ap_interest = G.PROFILES[G.AP.profile_Id]["maxinterest"] or 0
init_game_object.interest_cap = init_game_object.interest_cap +
(ap_interest * 5 or 0)
init_game_object.starting_params.joker_slots = init_game_object.starting_params.joker_slots +
(G.PROFILES[G.AP.profile_Id]["bonusjoker"] or 0)
init_game_object.starting_params.consumable_slots = init_game_object.starting_params.consumable_slots +
(G.PROFILES[G.AP.profile_Id]["bonusconsumable"] or 0)
init_game_object.ap_seed = G.APClient:get_seed()
init_game_object.ap_jokers_removed = AreJokersRemoved()
init_game_object.ap_consums_removed = AreConsumablesRemoved()
init_game_object.ap_modded_items = G.AP.this_mod.config.modded
end
return init_game_object
end
-- DeathLink
G.FUNCS.die = function()
if G.STAGE == G.STAGES.RUN and G.AP.slot_data and IsDeathlinkOn() then
-- G.SETTINGS.screenshake = 300
G.STATE = G.STATES.GAME_OVER
if not G.GAME.won and not G.GAME.seeded and not G.GAME.challenge then
G.PROFILES[G.SETTINGS.profile].high_scores.current_streak.amt = 0
end
G:save_settings()
G.FILE_HANDLER.force = true
G.STATE_COMPLETE = false
end
end
-- jimbo yaps about deathlink cause
local speech_bubbleref = G.UIDEF.speech_bubble
function G.UIDEF.speech_bubble(text_key, loc_vars)
if isAPProfileLoaded() and
(G.AP.death_link_cause and G.AP.death_link_cause ~= "unknown" and loc_vars and
loc_vars.quip) then
-- split cause into chunks
local lines = split_text_to_lines(G.AP.death_link_cause)
G.localization.quips_parsed.ap_death = {
multi_line = true
}
for k, v in ipairs(lines) do
G.localization.quips_parsed.ap_death[k] = loc_parse_string(v)
end
local text = {}
localize {
type = 'quips',
key = 'ap_death',
vars = {},
nodes = text
}
local row = {}
for k, v in ipairs(text) do
row[#row + 1] = {
n = G.UIT.R,
config = {
align = "cl"
},
nodes = v
}
end
local t = {
n = G.UIT.ROOT,
config = {
align = "cm",
minh = 1,
r = 0.3,
padding = 0.07,
minw = 1,
colour = G.C.JOKER_GREY,
shadow = true
},
nodes = {{
n = G.UIT.C,
config = {
align = "cm",
minh = 1,
r = 0.2,
padding = 0.1,
minw = 1,
colour = G.C.WHITE
},
nodes = {{
n = G.UIT.C,
config = {
align = "cm",
minh = 1,
r = 0.2,
padding = 0.03,
minw = 1,
colour = G.C.WHITE
},
nodes = row
}}
}}
}
G.AP.death_link_cause = nil
G.AP.death_link_source = nil
return t
end
return speech_bubbleref(text_key, loc_vars)
end
-- send out deathlink
function sendDeathLinkBounce(cause, source)
G.AP.log("sendDeathLinkBounce started")
cause = cause or "Balatro"
source = source or G.AP.APSlot or "BalatroPlayer"
local time = G.APClient:get_server_time()
G.AP.LAST_DEATH_LINK_TIME = time
G.AP.log("AP:sendDeathLinkBounce " .. tostring(time) .. " " .. cause .. " " .. source)
local res = G.APClient:Bounce({
time = time,
cause = cause,
source = source
}, {}, {}, {"DeathLink"})
end
local update_game_overRef = Game.update_game_over
function Game:update_game_over(dt)
-- only sends deathlink if run ended before and during ante 8
-- also checks if run is over because of deathlink coming in (not sure if necessary)
if isAPProfileLoaded() and not G.STATE_COMPLETE and G.AP.slot_data and IsDeathlinkOn() and
G.GAME.round_resets.ante <= G.GAME.win_ante and not G.AP.game_over_by_deathlink then
sendDeathLinkBounce("Run ended at ante " .. G.GAME.round_resets.ante)
end
G.AP.game_over_by_deathlink = false
return update_game_overRef(self, dt)
end
-- game changes
local game_updateRef = Game.update
function Game:update(dt)
local game_update = game_updateRef(self, dt)
if G.APClient ~= nil then
G.APClient:poll()
elseif isAPProfileLoaded() then
G.FUNCS.APDisconnect()
G.focused_profile = 1
G.SETTINGS.profile = 1
G.FUNCS.load_profile()
end
return game_update
end
-- hook to make bypass_lock consumables usable
G.FUNCS.can_use_consumeableRef = G.FUNCS.can_use_consumeable
G.FUNCS.can_use_consumeable = function(e)
local unlocked = nil
if isAPProfileLoaded() and e.config.ref_table.bypass_lock then
unlocked = e.config.ref_table.config.center.unlocked
e.config.ref_table.config.center.unlocked = true
end
local ret = G.FUNCS.can_use_consumeableRef(e)
if isAPProfileLoaded() and e.config.ref_table.bypass_lock then
e.config.ref_table.config.center.unlocked = unlocked
end
return ret
end
local game_drawRef = Game.draw
function Game:draw()
local game_draw = game_drawRef(self)
if G and G.STAGES and G.STAGE == G.STAGES.MAIN_MENU and G.AP.status_text then
local status = G.AP.status_text:get_UIE_by_ID('status_text')
local status_string = ""
local goal = G.AP.status_text:get_UIE_by_ID('goal_text')
local goal_string = ""
if G.APClient ~= nil then
if G.APClient:get_state() == AP.State.SLOT_CONNECTED then
status_string = string.gsub(G.AP.this_mod.config.connection_status ~= 3 and localize("k_ap_connected") or
localize('k_ap_connected_no_ip'),'#3#', tostring(G.AP.APSlot))
if G.AP.this_mod.config.connection_status ~= 3 then
status_string = string.gsub(status_string, '#2#', tostring(G.AP.APPort))
status_string = string.gsub(status_string, "#1#", tostring(G.AP.APAddress))
end
if G.AP.goal and G.AP.GameObjectInit then
local goal_loc = localize('ap_goal_text')
if goal_loc and type(goal_loc) == "table" then
goal_string = localize("k_ap_goal") .. ": "..goal_loc[G.AP.goal+1]
end
-- beat # of decks
if G.AP.goal == 0 then
goal_string = string.gsub(goal_string, "#1#", tostring(G.AP.slot_data.decks_win_goal))
goal_string = string.gsub(goal_string, "#2#", tostring(G.PROFILES[G.AP.profile_Id].ap_progress))
-- unlock # of jokers
elseif G.AP.goal == 1 then
local unlocked_jokers = get_unlocked_jokers()
goal_string = string.gsub(goal_string, "#1#", tostring(G.AP.slot_data.jokers_unlock_goal))
goal_string = string.gsub(goal_string, "#2#", tostring(unlocked_jokers))
-- beat specific ante
elseif G.AP.goal == 2 then
goal_string = string.gsub(goal_string, "#1#", tostring(G.AP.slot_data.ante_win_goal))
-- beat # decks on at least # stake
elseif G.AP.goal == 3 then
goal_string = string.gsub(goal_string, "#1#", tostring(G.AP.slot_data.decks_win_goal))
goal_string = string.gsub(goal_string, "#2#", tostring(G.PROFILES[G.AP.profile_Id].ap_progress))
if G.AP.StakesInit then
for i = 1, 8, 1 do
if G.P_CENTER_POOLS.Stake[i].stake_level == tonumber(G.AP.slot_data.required_stake) then
goal_string = string.gsub(goal_string, "#3#", localize({
type = "name_text",
key = G.P_CENTER_POOLS.Stake[i].key,
set = "Stake"
}))
break
end
end
else
goal_string = string.gsub(goal_string, "#3#",
localize("b_stake") .. " " .. tostring(G.AP.slot_data.required_stake))
end
-- win with # jokers on at least # stake
elseif G.AP.goal == 4 then
goal_string = string.gsub(goal_string, "#1#", tostring(G.AP.slot_data.jokers_unlock_goal))
goal_string = string.gsub(goal_string, "#2#", tostring(G.PROFILES[G.AP.profile_Id].ap_progress))
if G.AP.StakesInit then
for i = 1, 8, 1 do
if G.P_CENTER_POOLS.Stake[i].stake_level == tonumber(G.AP.slot_data.required_stake) then
goal_string = string.gsub(goal_string, "#3#", localize({
type = "name_text",
key = G.P_CENTER_POOLS.Stake[i].key,
set = "Stake"
}))
break
end
end
else
goal_string = string.gsub(goal_string, "#3#",
localize("b_stake") .. " " .. tostring(G.AP.slot_data.required_stake))
end
-- win with # of unique combinations of deck and stake
elseif G.AP.goal == 5 then
goal_string = string.gsub(goal_string, "#1#", tostring(G.AP.slot_data.unique_deck_win_goal))
goal_string = string.gsub(goal_string, "#2#", tostring(G.PROFILES[G.AP.profile_Id].ap_progress))
end
end
else
status_string = string.gsub(localize("k_ap_connecting"), "#1#", tostring(G.AP.APAddress))
status_string = string.gsub(status_string, "#2#", tostring(G.AP.APPort))
end
else
status_string = localize("k_ap_not_connected")
end
if status then
status.config.text = status_string
status.config.text_drawable:set(status.config.text)
end
if goal then
goal.config.text = goal_string
goal.config.text_drawable:set(goal.config.text)
end
G.AP.status_text:recalculate()
end
return game_draw
end
-- load APSettings when opening Profile Select
-- also create new profile when first loading (might have to move this somewhere more fitting)
local game_load_profileRef = Game.load_profile
function Game:load_profile(_profile)
-- print(tostring(_profile).." "..tostring(isAPProfileLoaded()).." "..tostring(G.AP.GameObjectInit))
if unloadAPProfile then
_profile = _profile == G.AP.profile_Id and 1 or _profile
unloadAPProfile = false
end
ap_profile_delete = false
G.AP.create_ap_profile()
if _profile ~= G.AP.profile_Id then
local game_load_profile = game_load_profileRef(self, _profile)
elseif _profile == G.AP.profile_Id and not G.AP.GameObjectInit then
G.SETTINGS.profile = _profile
G.AP.load_profile()
elseif _profile == G.AP.profile_Id and G.AP.GameObjectInit then
G.SETTINGS.profile = G.AP.profile_Id
end
return game_load_profile
end
local back_initRef = Back.init
function Back:init(selected_back)
if isAPProfileLoaded() and not selected_back then
selected_back = G.P_CENTERS[standard_deck or 'b_red']
end
return back_initRef(self, selected_back)
end
-- unlock Items based on APItems
G.FUNCS.AP_unlock_item = function(item, notify)
--G:save_notify(item)
table.sort(G.P_CENTER_POOLS["Back"], function(a, b)
return (a.order - (a.unlocked and 100 or 0)) < (b.order - (b.unlocked and 100 or 0))
end)
--G:save_progress()
if item.set == 'Back' then
discover_card(item)
end
if item.set == 'Joker' and G.DISCOVER_TALLIES and G.DISCOVER_TALLIES.jokers and G.DISCOVER_TALLIES.jokers.tally then
G.DISCOVER_TALLIES.jokers.tally = G.DISCOVER_TALLIES.jokers.tally + 1
end
G.FILE_HANDLER.force = true
-- prevent duplicate notification on stake_unlock_mode 4
if not (item.set == 'Back' and tonumber(G.AP.slot_data.stake_unlock_mode) ==
G.AP.stake_unlock_modes.stake_as_item_per_deck) then
if notify then notify_alert(item.key, item.set) end
end
end
local game_init_item_prototypesRef = Game.init_item_prototypes
function Game:init_item_prototypes()
local game_init_item_prototypes = game_init_item_prototypesRef(self)
if isAPProfileLoaded() then
-- load serverside data
G.AP.server_load()
G.PROFILES[G.AP.profile_Id].name = G.AP['APSlot']
G.PROFILES[G.AP.profile_Id].Archipelago = true
-- AP lock sticker
if not G.AP.locked_stickers then
G.AP.locked_stickers = {}
G.AP.locked_stickers[1] = Sprite(0, 0, G.CARD_W, G.CARD_H, G.ASSET_ATLAS["rand_ap_lock"], {x = 0, y = 0})
G.AP.locked_stickers[2] = Sprite(0, 0, G.CARD_W, G.CARD_H, G.ASSET_ATLAS["rand_ap_lock"], {x = 1, y = 0})
end
-- borrowed sticker
SMODS.Stickers.rand_ap_borrowed.no_collection = nil
if tableContains(G.AP.slot_data.included_decks, 'b_red') then
standard_deck = 'b_red'
end
-- Locked text | Decks require description setup similar to the old system here
-- everything else uses "Other.wip_locked" and overwrites it with their text (not here)
for k, v in pairs(G.localization.descriptions.Back) do
v.unlock_parsed = {}
local loc_target = k == 'b_challenge' and G.localization.descriptions.Other.ap_locked_Deck_c.text_parsed or
G.localization.descriptions.Other.ap_locked_Back.text_parsed
for _line, _string in pairs(loc_target) do
v.unlock_parsed[_line] = _string
end
local _name = loc_parse_string("{C:inactive,s:0.8}(" .. v.name .. ")")
v.unlock_parsed[#v.unlock_parsed + 1] = _name
G.localization.descriptions.Back[k] = v
end
--safeguard bcos crashes on seed mismatch
G.PROFILES[G.AP.profile_Id]["jokers"] = G.PROFILES[G.AP.profile_Id]["jokers"] or {}
G.PROFILES[G.AP.profile_Id]["backs"] = G.PROFILES[G.AP.profile_Id]["backs"] or {}
G.PROFILES[G.AP.profile_Id]["vouchers"] = G.PROFILES[G.AP.profile_Id]["vouchers"] or {}
G.PROFILES[G.AP.profile_Id]["packs"] = G.PROFILES[G.AP.profile_Id]["packs"] or {}
G.PROFILES[G.AP.profile_Id]["consumables"] = G.PROFILES[G.AP.profile_Id]["consumables"] or {}
for k, v in pairs(G.AP.JokerQueue) do
G.PROFILES[G.AP.profile_Id]["jokers"][k] = true
end
for k, v in pairs(G.AP.BackQueue) do
G.PROFILES[G.AP.profile_Id]["backs"][k] = true
end
for k, v in pairs(G.AP.VoucherQueue) do
G.PROFILES[G.AP.profile_Id]["vouchers"][k] = true
end
for k, v in pairs(G.AP.PackQueue) do
G.PROFILES[G.AP.profile_Id]["packs"][k] = true
end
for k, v in pairs(G.AP.ConsumableQueue) do
G.PROFILES[G.AP.profile_Id]["consumables"][k] = true
end
self.P_LOCKED = {}
for k, v in pairs(self.P_CENTERS) do
-- for jokers
if string.find(k, '^j_') then
v.alerted = true
if AreJokersRemoved() then
v.wip = true
v.unlocked = false
v.discovered = false
v.hidden = true
v.ap_unlocked = false
else
v.unlocked = true
v.discovered = true
v.hidden = false
v.ap_unlocked = false
end
if G.PROFILES[G.AP.profile_Id]["jokers"][v.key] ~= nil then
if AreJokersRemoved() then
v.wip = nil
v.unlocked = true
v.discovered = true
v.hidden = false
v.ap_unlocked = true
else
v.ap_unlocked = true
end
if (G.AP.JokerQueue[v] == true) then
G.FUNCS.AP_unlock_item(v)
end
end
-- for backs (decks)
elseif string.find(k, '^b_') then
v.alerted = true
v.unlocked = false
G.AP.UnlockConsCache[k] = v.unlock_condition
v.unlock_condition = nil
if G.PROFILES[G.AP.profile_Id]["backs"][v.key] ~= nil then
v.unlocked = true
v.discovered = true
v.hidden = false
if (G.AP.BackQueue[v] == true) then
G.FUNCS.AP_unlock_item(v)
end
end
if not tableContains(G.AP.slot_data.included_decks, k) and k ~= 'b_challenge' then
SMODS.Back:take_ownership(k, {}):delete()
elseif not standard_deck and k ~= 'b_challenge' then
standard_deck = k
end
-- create (or fix) deck_usage (for stake unlocks)
if not G.PROFILES[G.AP.profile_Id].deck_usage or type(G.PROFILES[G.AP.profile_Id].deck_usage) ~= 'table' then
G.PROFILES[G.AP.profile_Id].deck_usage = {}
end
if not G.PROFILES[G.AP.profile_Id].deck_usage[k] then
G.PROFILES[G.AP.profile_Id].deck_usage[k] = {}
end
if not G.PROFILES[G.AP.profile_Id].deck_usage[k].count then
G.PROFILES[G.AP.profile_Id].deck_usage[k].count = 0
end
if not G.PROFILES[G.AP.profile_Id].deck_usage[k].wins then
G.PROFILES[G.AP.profile_Id].deck_usage[k].wins = {}
end
if not G.PROFILES[G.AP.profile_Id].deck_usage[k].losses then
G.PROFILES[G.AP.profile_Id].deck_usage[k].losses = {}
end
if not G.PROFILES[G.AP.profile_Id].deck_stake then
G.PROFILES[G.AP.profile_Id].deck_stake = {}
end
if not G.PROFILES[G.AP.profile_Id].deck_stake[k] then
G.PROFILES[G.AP.profile_Id].deck_stake[k] = {}
for i = 1, 8, 1 do
G.PROFILES[G.AP.profile_Id].deck_stake[k][i] = false
end
end
-- for vouchers
elseif string.find(k, '^v_') and not string.find(k, '^v_rand_ap_item') then
v.wip = true
v.unlocked = false
v.ap_unlocked = false
v.alerted = true
if G.PROFILES[G.AP.profile_Id]["vouchers"][v.key] ~= nil then
-- progressive vouchers
if v.requires then
if (not G.P_CENTERS[v.requires[1]].unlocked) then
G.P_CENTERS[v.requires[1]].nextVoucher = v
v = G.P_CENTERS[v.requires[1]]
end
elseif v.nextVoucher then
v = v.nextVoucher
end
v.wip = nil
v.unlocked = true
v.discovered = true
v.hidden = false
v.ap_unlocked = true
if (G.AP.VoucherQueue[v] == true) then
G.FUNCS.AP_unlock_item(v)
end
end
elseif k == 'v_rand_ap_item' then
v.alerted = true
-- for packs
elseif string.find(k, '^p_') then
v.unlocked = false
v.discovered = false
v.wip = true
v.alerted = true
v.ap_unlocked = false
for pack_key, pack_center in pairs(G.PROFILES[G.AP.profile_Id]["packs"]) do
if string.find(k, pack_key) and pack_center ~= nil then
--if G.PROFILES[G.AP.profile_Id]["packs"][v.key] ~= nil then
v.wip = nil
v.unlocked = true
v.discovered = true
v.hidden = false
v.ap_unlocked = true
if (G.AP.PackQueue[v] == true) then
G.FUNCS.AP_unlock_item(v)
end
break
end
end
-- for consumables
elseif string.find(k, '^c_') and not string.find(k, '^c_base') then --and
--not tableContains({'c_rand_ap_tarot', 'c_rand_ap_planet', 'c_rand_ap_spectral'}, k) then
v.discovered = true
v.alerted = true
if AreConsumablesRemoved() then
v.wip = true
v.unlocked = false
v.ap_unlocked = false
else
v.unlocked = true
v.ap_unlocked = false
end
if G.PROFILES[G.AP.profile_Id]["consumables"][v.key] ~= nil then
if AreConsumablesRemoved() then
v.wip = nil
v.unlocked = true
v.discovered = true
v.hidden = false
v.ap_unlocked = true
else
v.ap_unlocked = true
v.discovered = true
end
if (G.AP.ConsumableQueue[v] == true) then
G.FUNCS.AP_unlock_item(v)
end
end
end
-- back up unlock_condition
if v.unlock_condition and not G.AP.UnlockConsCache[k] then
G.AP.UnlockConsCache[k] = v.unlock_condition
end
v.unlock_condition = v.unlock_condition or {}
-- modded item overrides (backs excluded)
if G.AP.this_mod.config.modded ~= 1 and not string.find(k, '^b_') then
if not IsVanillaItem(k) then
v.modded = true
v.alerted = true
if G.AP.this_mod.config.modded == 2 then
v.ap_unlocked = false
v.wip = true
v.unlocked = false
v.discovered = false
v.hidden = false
else
v.ap_unlocked = true
v.wip = nil
v.unlocked = true
v.discovered = true
v.hidden = false
end
end
end
-- Grab IDs for local vanilla items
if not v.modded then
for _id, _key in pairs(G.APItems) do
if _key == v.key or (string.find(v.key, _key)) then
v.ap_id = _id
break
end
end
end
end
-- Handle global stake unlock save data
if not G.PROFILES[G.AP.profile_Id].stake_unlocks then
G.PROFILES[G.AP.profile_Id].stake_unlocks = {}
for i = 1, 8, 1 do
G.PROFILES[G.AP.profile_Id].stake_unlocks[i] = false
end
-- G.PROFILES[G.AP.profile_Id].stake_unlocks[1] = true
-- ^ uncomment to force the first stake to be always open
end
-- AP goal progress
if not G.PROFILES[G.AP.profile_Id].ap_progress then
G.PROFILES[G.AP.profile_Id].ap_progress = G.AP.check_progress() or 0
end
-- Pick the hardest stake as the required one if AP.slot_data lacks one
if G.AP.slot_data.required_stake == nil then
G.AP.slot_data.required_stake = 1
for i = 1, #G.AP.slot_data.included_stakes, 1 do
G.AP.slot_data.required_stake = math.max(G.AP.slot_data.required_stake,
G.AP.slot_data.included_stakes[i])
end
end
-- Handle Queued Bonus stuff
for k, v in pairs(G.AP.BonusQueue) do
if (not G.PROFILES[G.AP.profile_Id]["received_indeces"][v.idx]) then
if (v.type == "bonusdiscards") then
G.PROFILES[G.AP.profile_Id]["bonusdiscards"] =
(G.PROFILES[G.AP.profile_Id]["bonusdiscards"] or 0) + 1
elseif (v.type == "bonusstartingmoney") then
G.PROFILES[G.AP.profile_Id]["bonusstartingmoney"] =
(G.PROFILES[G.AP.profile_Id]["bonusstartingmoney"] or 0) + 1
elseif (v.type == "bonushands") then
G.PROFILES[G.AP.profile_Id]["bonushands"] = (G.PROFILES[G.AP.profile_Id]["bonushands"] or 0) + 1
elseif (v.type == "bonushandsize") then
G.PROFILES[G.AP.profile_Id]["bonushandsize"] =
(G.PROFILES[G.AP.profile_Id]["bonushandsize"] or 0) + 1
elseif (v.type == "maxinterest") then
G.PROFILES[G.AP.profile_Id]["maxinterest"] = (G.PROFILES[G.AP.profile_Id]["maxinterest"] or 0) + 1
elseif (v.type == "bonusjoker") then
G.PROFILES[G.AP.profile_Id]["bonusjoker"] = (G.PROFILES[G.AP.profile_Id]["bonusjoker"] or 0) + 1
elseif (v.type == "bonusconsumable") then
G.PROFILES[G.AP.profile_Id]["bonusconsumable"] =
(G.PROFILES[G.AP.profile_Id]["bonusconsumable"] or 0) + 1
end
G.PROFILES[G.AP.profile_Id]["received_indeces"][v.idx] = true
end
end
-- remove queued items
G.AP.BonusQueue = {}
G.AP.BackQueue = {}
G.AP.VoucherQueue = {}
G.AP.JokerQueue = {}
G.AP.PackQueue = {}
G.AP.ConsumableQueue = {}
G.AP.GameObjectInit = true
G.FUNCS.initialize_shop_items()
self.P_CENTERS['b_red'] = self.P_CENTERS[standard_deck]
-- handle challenges
local ci = 1
G.PROFILES[G.SETTINGS.profile].challenge_unlocks = G.PROFILES[G.SETTINGS.profile].challenge_unlocks or {}
while ci <= #G.CHALLENGES do
-- remove modded challenges
if not IsVanillaItem(G.CHALLENGES[ci].key) then
G.AP.ChallengeCache[#G.AP.ChallengeCache + 1] = G.CHALLENGES[ci]
table.remove(G.CHALLENGES, ci)
else -- prepare vanilla challenges
-- init save data
G.PROFILES[G.SETTINGS.profile].challenge_unlocks[G.CHALLENGES[ci].key] =
G.PROFILES[G.SETTINGS.profile].challenge_unlocks[G.CHALLENGES[ci].key] or false
-- wrape the unlock checking function to check ap values in ap mode
if G.CHALLENGES[ci].unlockedRefAP == nil then
G.CHALLENGES[ci].unlockedRefAP = G.CHALLENGES[ci].unlocked
G.CHALLENGES[ci].unlocked = function(self)
if isAPProfileLoaded() then
return G.PROFILES[G.SETTINGS.profile].challenge_unlocks[self.key] and
G.PROFILES[G.SETTINGS.profile].challenge_unlocks[self.key]
else
return self.unlockedRefAP
end
end
end
ci = ci + 1
end
end
init_AP_stakes()
G.AP.team_id = G.APClient:get_team_number()
G.AP.player_id = G.APClient:get_player_number()
G.APClient:Get({"_read_hints_"..tostring(G.AP.team_id).."_"..tostring(G.AP.player_id)})
if not G.AP.hint_event then
G.AP.hint_event = Event {
blockable = false,
blocking = false,
pause_force = true,
no_delete = true,
trigger = 'after',
delay = 10,
func = function()
if isAPProfileLoaded() then
G.AP.hint_event.start_timer = false
--G.AP.log("autoscout hints")
G.APClient:Get({"_read_hints_"..tostring(G.AP.team_id).."_"..tostring(G.AP.player_id)})
else G.AP.hint_event = nil end
return not isAPProfileLoaded()
end
}
G.E_MANAGER:add_event(G.AP.hint_event, 'other')
end
-- fix decks not being sorted on initial load
table.sort(G.P_CENTER_POOLS["Back"], function (a, b) return (a.order - (a.unlocked and 100 or 0)) < (b.order - (b.unlocked and 100 or 0)) end)
else
-- restore unlock conditions
for k, v in pairs(G.AP.UnlockConsCache) do
if self.P_CENTERS[k] then
self.P_CENTERS[k].unlock_condition = v
end
end
G.AP.UnlockConsCache = {}
-- remove wip tag
for k, v in pairs(self.P_CENTERS) do
if v.wip then
self.P_CENTERS[k].wip = nil
end
end
-- borrowed sticker
SMODS.Stickers.rand_ap_borrowed.no_collection = true
-- fix some custom implementation of the Challenge Deck
G.P_CENTERS['b_challenge'].name = "Challenge Deck"
G.P_CENTERS['b_challenge'].unlocked = true
-- remove it from the pool if its there somehow
for k, v in ipairs(G.P_CENTER_POOLS.Back) do
if v == G.P_CENTERS['b_challenge'] then
table.remove(G.P_CENTER_POOLS.Back, k)
break
end
end
-- restore challenges removed by ap
if #G.AP.ChallengeCache > 0 then
for _, v in pairs(G.AP.ChallengeCache) do
G.CHALLENGES[#G.CHALLENGES + 1] = v
end
G.AP.ChallengeCache = {}
end
-- reload metadata just in case because it doesnt want to work properly
if not love.filesystem.getInfo(G.SETTINGS.profile..'') then love.filesystem.createDirectory( G.SETTINGS.profile..'' ) end
if not love.filesystem.getInfo(G.SETTINGS.profile..'/'..'meta.jkr') then love.filesystem.append( G.SETTINGS.profile..'/'..'meta.jkr', 'return {}') end
convert_save_to_meta()