forked from nicolasberube/Arzette_Randomizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArzetteRandomizer.py
More file actions
1728 lines (1508 loc) · 81.2 KB
/
Copy pathArzetteRandomizer.py
File metadata and controls
1728 lines (1508 loc) · 81.2 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
import copy
import random
import yaml
import csv
from itertools import combinations
starting_locations = ["Default Beacon"]
rock_locations = ["Orange Rock", "Brown Rock", "Gray Rock", "Blue Rock"]
level_locations = {
"Faramore": [
"Faramore Key (Well)",
"Faramore Key (Tavern)",
"Faramore Bonus",
"Faramore Candle (Empty House)",
"Faramore Candle (Cypress House)",
"Faramore Coin"
],
"Forest": [
"Bombs",
"Forest Bag (First Room 1)",
"Forest Bag (First Room 2)",
"Forest Key",
"Forest Bonus",
"Forest Candle (Tree)",
"Forest Candle (Cypress)",
"Forest Coin",
"Forest Bag (Sword Wave)",
"Sword Wave",
"Golden Fly",
"Forest Bag (Last Room)",
"Forest Beacon",
"Forest Jewel",
"Magic Armor"
],
"Caves": [
"Silver Cricket",
"Rope Ladder",
"Caves Bag (Rope Ladder)",
"Caves Candle (First Dark Room)",
"Caves Coin",
"Caves Candle (Second Dark Room)",
"Caves Bonus",
"Caves Bag (Last Room)",
"Shield Ring",
],
"Desert": [
"Desert Coin",
"Desert Bag (First Room 1)",
"Desert Bag (First Room 2)",
"Compass",
"Desert Candle (Pit)",
"Desert Bonus",
"Desert Key",
"Desert Candle (Last Room)",
"Desert Life-Up",
"Desert Bag (Last Room)",
"Desert Beacon"
],
"Canyon": [
"Canyon Bonus",
"Canyon Bag (Before Checkpoint)",
"Canyon Bag (After Checkpoint 1)",
"Canyon Bag (After Checkpoint 2)",
"Canyon Bag (After Checkpoint 3)",
"Canyon Bag (First Room End)",
"Canyon Candle (First Room End)",
"Canyon Jewel",
"Canyon Key",
"Canyon Bag (After Zipline 1)",
"Canyon Bag (After Zipline 2)",
"Canyon Bag (After Zipline 3)",
"Canyon Coin",
"Canyon Bag (Motte House)",
"Canyon Candle (Motte House)"
],
"Swamp": [
"Swamp Candle (First Room)",
"Swamp Bag (First Room)",
"Swamp Coin",
"Swamp Key (Frich House)",
"Swamp Candle (Frich House)",
"Swamp Key (Griffin Boots)",
"Griffin Boots",
"Swamp Plant",
"Swamp Bonus",
"Swamp Beacon"
],
"Peak": [
"Peak Candle (First Cave)",
"Peak Bag (First Cave 1)",
"Peak Bag (First Cave 2)",
"Peak Bonus",
"Peak Coin",
"Peak Key",
"Peak Candle (Ciclena Cave)",
"Peak Bag (Before Apatu)",
"Peak Jewel",
"Peak Bag (After Apatu)"
],
"Crypts": [
"Crypts Life-Up",
"Bell",
"Crypts Bonus",
"Crypts Key",
"Crypts Bag (Crypt)",
"Crypts Candle (After Crypt)",
"Crypts Coin",
"Crypts Candle (Skelvis)",
"Crypts Bag (Skelvis)"
],
"Volcano": [
"Volcano Bonus",
"Volcano Candle (First Room)",
"Volcano Coin",
"Volcano Candle (Last Room)",
"Crystal of Refraction"
],
"Beach": [
"Beach Bag (First Room)",
"Beach Key (First House)",
"Beach Coin",
"Beach Key (Tork Cabin)",
"Beach Candle (Tork Cabin)",
"Beach Plant",
"Beach Bonus",
"Beach Candle (Cave)",
"Fatal Flute",
"Beach Beacon"
],
"River": [
"River Key (Francine)",
"River Bonus",
"River Candle (Boat)",
"River Key (Submarine)",
"River Coin",
"Blue Magic",
"River Bag (Last Room)",
"River Candle (Last Room)",
"River Life-Up"
],
"Hills": [
"Hills Candle (Cave)",
"Lightning Sword",
"Hills Coin",
"Hills Bonus",
"Hills Bag (Barn)",
"Hills Key",
"Hills Bag (Music Shrine)",
"Hills Candle (Music Shrine)",
"Hills Plant",
"Hills Beacon"
],
"Fort": [
"Fort Bag (Dungeon 1)",
"Fort Bag (Dungeon 2)",
"Fort Bag (Dungeon 3)",
"Fort Bag (Dungeon 4)",
"Sacred Oil",
"Fort Key (First Room)",
"Fort Candle (Dark Room)",
"Fort Bag (Dark Room)",
"Enchanted Shoes",
"Fort Coin",
"Fort Key (Top Room)",
"Fort Bag (Top Room 1)",
"Fort Bag (Top Room 2)",
"Fort Bag (Top Room 3)",
"Fort Candle (Last Room)",
"Fort Bag (Last Room)",
"Reflector Ring",
"Fort Jewel",
"Fort Bonus"
],
"Castle": [
"Castle Bag (Entrance)",
"Castle Candle (Right Room)",
"Castle Key (Nodelki)",
"Castle Candle (Top Room)",
"Castle Bag (Top Room)",
"Winged Belt",
"Castle Coin",
"Castle Key (Left Room)",
"Castle Bag (Bonus)",
"Castle Bonus",
"Castle Jewel"
],
"Lair": [
"Lair Candle (Tree Trunk)",
"Lair Candle (Tree Top)",
"Lair Bonus",
"Lair Bag (First Room)",
"Lair Coin",
"Lair Bag (Lava Room)",
"Lair Bag (Final Room 1)",
"Lair Bag (Final Room 2)",
"Lair Bag (Final Room 3)",
"Daimur"
]
}
bonus_locations = [f"{level} Bonus Reward" for level in level_locations]
default_level_order = {
"Default": ["Faramore", "Forest"],
"Forest": ["Caves", "Desert", "Canyon"],
"Desert": ["Swamp", "Peak", "Crypts"],
"Swamp": ["Volcano", "Beach", "River"],
"Beach": ["Hills", "Fort"],
"Hills": ["Castle", "Lair"]
}
default_npc_fool = [
"Faramore Boru", # blacksmith help
"Faramore Kari", # bell quest dude
"Faramore Univor", # guard
"Faramore Salvik", # drunk dude
"Faramore Maki", # baker
"Faramore Payop", # librarian
"Volcano Joe", # radical
"River Barnabuss" # sailor
]
default_npc_locations = {
"Purple Magic": "Faramore Yukeen",
"Citizenship Papers": "Faramore Covenplate",
"Power Stone Upgrade": "Faramore Kari Quest",
"Dungeon Key": "Faramore Alven",
"Chainsword": "Faramore Alven",
"Canteen": "Faramore Brinda",
"Wallet Upgrade": "Faramore Frich",
"Infinite Soulfire": "Faramore Rudy",
"Bomb Upgrade": "Faramore Barnabuss",
"Calendar": "Faramore Denny",
"200 Rupees": "Faramore Dewey",
"Lamp Oil Upgrade": "Faramore Cypress",
"Rope Upgrade": "Faramore Munhum",
"Forest Race 100 Rupees": "Faramore Rudy",
"Peak Race 100 Rupees": "Faramore Rudy",
"Hills Race 100 Rupees": "Faramore Rudy",
"Lantern": "Forest Cypress",
"Rope": "Caves Munhum",
"Snail Salt": "Caves Ellido",
"Fairy Dust": "Desert Fairy",
"Backstep": "Canyon Crowdee",
"Smart Gun": "Canyon Motte",
"Star Earrings": "Canyon Odie",
"Ogre Hair": "Swamp Glubbert",
"Power Pendant": "Peak Ciclena",
"Bomb Gauntlet": "Crypts Skelvis",
"Speedy Shoes": "Beach Fleetus",
"Magic Cloak": "Beach Tork",
"Cleaver Shovel": "River Francine",
"Oil and Chains": "River Morgh",
"Double Wave": "Hills Milbert",
"Funky Fungus": "Lair Zazie",
"Soul Upgrade": "Lair Zazie"
}
default_npc_locked = [
"Faramore Mortar", "Swamp Frich", "Forest Rudy (Start)", "Forest Rudy (End)",
"Peak Rudy (Start)", "Peak Rudy (End)", "Hills Rudy (Start)", "Hills Rudy (End)"]
trading_locations = [
"Sacred Oil", "Funky Fungus", "Snail Salt",
"Cleaver Shovel", "Ogre Hair", "Oil and Chains", "Chainsword"]
default_barrier_types = {typ: typ for typ in ["Red", "Blue", "Purple", "Gauntlet", "Flute"]}
all_locations = starting_locations + [
location for locations in level_locations.values() for location in locations] + \
[location for location in (
list(default_npc_locations) + rock_locations + bonus_locations)]
non_quest_locations = [
location for location in all_locations
if location not in list(default_npc_locations) + rock_locations + bonus_locations
and "Jewel" not in location.split()
and location not in {"Desert Candle (Last Room)", "Swamp Plant", "River Key (Submarine)"}]
all_npcs = (list(set(default_npc_locations.values())) + default_npc_locked + default_npc_fool)
level_names = {
"Faramore": "Faramore Town",
"Forest": "Durridin Forest",
"Caves": "Cogwyn Caves",
"Desert": "Anju Desert",
"Canyon": "Creece Canyon",
"Swamp": "Norin Swamp",
"Peak": "Chillinax Peaks",
"Crypts": "Boanjale Crypts",
"Volcano": "Sprigum Volcano",
"Beach": "Badonc Beach",
"River": "Ryha River",
"Hills": "Lichen Hills",
"Fort": "Fort Findula",
"Castle": "Dennys Castle",
"Lair": "Daimurs Lair"
}
def add_rule(spot, rule, combine="and"):
old_rule = spot.access_rule
if combine == "and":
spot.access_rule = lambda state: rule(state) and old_rule(state)
else:
spot.access_rule = lambda state: rule(state) or old_rule(state)
class ArzetteLocation():
access_rule = staticmethod(lambda state: True)
item = None
def can_reach(self, state) -> bool:
return self.access_rule(state)
class ArzetteWorld():
level_locations = level_locations
all_locations = all_locations
n_tries = 0
item_name_groups = {
"magic": {"Sword Wave", "Smart Gun"},
"bombs": {"Bombs", "Bomb Gauntlet"},
"blue": {"Blue Magic", "Purple Magic"},
"candles": {location for location in all_locations if "Candle" in location.split()},
"coins": {location for location in all_locations if "Coin" in location.split()},
"jewels": {location for location in all_locations if "Jewel" in location.split()},
"plants": {location for location in all_locations if "Plant" in location.split()},
"races": {location for location in all_locations if "Race" in location.split()},
"rocks": {location for location in all_locations if "Rock" in location.split()},
"bags": {location for location in all_locations if "Bag" in location.split()},
}
def __init__(self, config_path="./config.yml"):
with open(config_path, "r") as file:
self.config = yaml.safe_load(file)
def fill(self):
seed = self.config["seed"]
# It is crucial to fill in order
# self.level_beacons -> self.set_rules_barrier() + self.barrier_types ->
# self.set_rules() -> assign all quest NPCs in self.location_cache + self.npc_locations ->
# self.set_rules_quests() + rest of self.location_cache
if seed == "vanilla":
self.seed = seed
self.level_order = default_level_order
self.level_beacons = {
level: f"{beacon} Beacon" for beacon, levels in self.level_order.items()
for level in levels}
self.barrier_cache = {
name: ArzetteLocation() for name in default_barrier_types}
self.set_rules_barrier()
self.barrier_types = default_barrier_types
self.location_cache = {
name: ArzetteLocation() for name in all_npcs+all_locations}
for name in self.location_cache:
self.location_cache[name].item = name
self.npc_locations = default_npc_locations
return
if seed is None:
self.seed = random.randint(0, 4294967295)
else:
self.seed = seed
random.seed(self.seed)
# Level order randomisation
# This function causes some seed generation failures when your
# starting level is Beach or Hills.
level_type = self.config["level_order"].lower()
if level_type in {"random", "faramore"}:
level_list = [level for levels in default_level_order.values()
for level in levels]
if level_type == "faramore":
level_list = [
level for level in level_list if level != "Faramore"]
random.shuffle(level_list)
level_order = {}
beacons = ["Default"]
if self.config["item_pool"]["beacons"]:
beacons = list(default_level_order)
while len(beacons):
beacon = beacons.pop(0)
if not self.config["item_pool"]["beacons"]:
for i_l, level in enumerate(level_list):
if level in default_level_order and level != beacon:
beacons.append(level)
break
level_order[beacon] = [level_list.pop(i_l)]
else:
level_order[beacon] = []
if level_type == "faramore" and beacon == "Default":
level_order[beacon].append("Faramore")
n_unlocks = 0
else:
n_unlocks = len(default_level_order[beacon])-1
if self.config["item_pool"]["beacons"]:
n_unlocks += 1
for _ in range(n_unlocks):
if (level_list[0] in default_level_order and
not self.config["item_pool"]["beacons"]):
beacons.append(level_list[0])
level_order[beacon].append(level_list.pop(0))
self.level_order = level_order
elif level_type == "vanilla":
self.level_order = default_level_order
else:
raise Exception(f"Config level_type {level_type} not recognised.")
self.level_beacons = {
level: f"{beacon} Beacon" for beacon, levels in self.level_order.items()
for level in levels}
# Barrier types randomisation
self.barrier_cache = {name: ArzetteLocation() for name in default_barrier_types}
self.set_rules_barrier()
if self.config["barrier_types"]:
barrier_list = list(default_barrier_types)
random.shuffle(barrier_list)
barrier_types = {}
for barrier in default_barrier_types:
barrier_types[barrier] = barrier_list.pop(0)
self.barrier_types = barrier_types
else:
self.barrier_types = default_barrier_types
# Set-up item pool based on settings
self.location_cache = {
name: ArzetteLocation() for name in all_npcs+all_locations}
item_locked = ["Default Beacon", "Daimur"]
item_locked += ["Faramore Bonus Reward",
"Volcano Bonus Reward",
"Castle Bonus Reward"]
item_list = []
sub_item_lists = {
"bags": [item for item in all_locations if "Bag" in item.split()],
"keys": [item for item in all_locations if "Key" in item.split()
and item not in {"Dungeon Key", "Hills Key"}],
"hills_key": ["Hills Key"],
"candles": [item for item in all_locations if "Candle" in item.split()],
"coins": [item for item in all_locations if "Coin" in item.split()],
"plants": [item for item in all_locations if "Plant" in item.split()],
"rocks": [item for item in all_locations if "Rock" in item.split()],
"upgrades": ([item for item in all_locations if "Upgrade" in item.split()] +
["Infinite Soulfire"]),
"life_ups": [item for item in all_locations if "Life-Up" in item.split()],
"bonus_rewards": [item for item in all_locations if "Bonus" in item.split() and
"Reward" in item.split() and
not any(level in item for level in ["Faramore", "Volcano", "Castle"])],
"race_rewards": [item for item in all_locations if "Race" in item.split()],
"beacons": [item for item in all_locations if "Beacon" in item.split()
and item != "Default Beacon"],
"jewels": [item for item in all_locations if "Jewel" in item.split()],
}
for option, sub_item_list in sub_item_lists.items():
if self.config["item_pool"][option]:
item_list += sub_item_list
else:
item_locked += sub_item_list
trading_type = self.config["item_pool"]["trading_sequence"].lower()
if trading_type not in {"included", "excluded", "vanilla"}:
raise Exception(f"config file trading_type {trading_type} not recognised.")
if trading_type == "included":
item_list += trading_locations
# Locking items in location before trading_sequence
for item in item_locked:
self.get_location(item).item = item
if trading_type == "vanilla":
# Assuming you want to start later in the sequence
# start_position = random.randint(0, len(trading_locations)-2)
start_position = 0
elif trading_type == "excluded":
start_position = len(trading_locations)-2
if trading_type != "included":
if start_position != 0:
item_locked.append(trading_locations[0])
self.get_location(trading_locations[start_position]).item = \
trading_locations[0]
for i_s, item in enumerate(trading_locations):
if i_s in {0, start_position}:
continue
item_locked.append(item)
self.get_location(item).item = item
item_list.append(trading_locations[start_position])
# NPC + Bonus scrolls randomisation
scroll_locations = [item for item in all_locations if "Bonus" in item.split()
and "Reward" not in item.split()]
npc_list = []
if self.config["item_pool"]["npc"]:
npc_list += list(set(default_npc_locations.values())) + default_npc_fool
npc_locked = default_npc_locked
for npc in npc_locked:
self.get_npc(npc).item = npc
else:
for name in all_npcs:
self.get_location(name).item = name
self.npc_locations = default_npc_locations
if self.config["item_pool"]["bonus_scrolls"]:
npc_list += scroll_locations
else:
for item in scroll_locations:
self.get_location(item).item = item
if len(npc_list) > 0:
npc_locs = [location for location in non_quest_locations
if self.get_location(location).item is None]
random.shuffle(npc_locs)
npc_locs = npc_locs[:len(npc_list)]
for location, npc in zip(npc_locs, npc_list):
if self.get_location(location).item is not None:
raise Exception(f"Location {location} already filled.")
self.get_location(location).item = npc
self.npc_locations = {}
npc_to_location = {self.get_location(name).item: name for name in npc_locs}
for item, npc in default_npc_locations.items():
self.npc_locations[item] = npc_to_location[npc]
# Item randomisation
self.set_rules()
self.set_rules_quests()
core_items = [name for name in all_locations
if name not in item_list+item_locked+scroll_locations]
item_list += core_items
location_list = [name for name, location in self.location_cache.items()
if location.item is None]
if len(item_list) != len(location_list):
raise Exception(
f"{len(item_list)} items and {len(location_list)} available locations.")
# Randomise item pool
# This function is not based on the Archipelago Fill.py functions. It is a homemade algorithm, but it works.
random.shuffle(item_list)
random.shuffle(location_list)
# For debugging
all_spheres = []
all_expanders = []
n_spheres = -1
while True:
state = self.sweep()
if "Daimur" in state.prog_items:
n_spheres = len(all_spheres)
current_sphere = [location for location in location_list
if self.get_location(location).can_reach(state)]
all_spheres.append(current_sphere[:])
current_expanders = {}
for n_items in range(1, 3):
for test_items in combinations(item_list, n_items):
test_state = self.sweep(extra_items=test_items)
test_sphere = [location for location in location_list
if self.get_location(location).can_reach(test_state)]
delta = len(test_sphere) - len(current_sphere)
if delta > 0:
if delta not in current_expanders:
current_expanders[delta] = []
current_expanders[delta].append(list(test_items))
if len([delta for delta in current_expanders if delta > 1]):
break
if n_items > len(current_sphere) or len(current_expanders) == 0:
if state.prog_items["Daimur"]:
break
if seed is None:
self.n_tries += 1
if self.n_tries < 10:
print(f"Seed generation failed {self.n_tries} time(s). Trying again")
self.fill()
return
print(self.level_order)
print(all_spheres)
print(all_expanders)
raise Exception("Seed generation failed.")
expand_value = random.choice(list(current_expanders))
all_expanders.append((expand_value, current_expanders))
current_expander = current_expanders[expand_value][0][:]
while len(current_sphere):
location = current_sphere.pop(0)
location = location_list.pop(location_list.index(location))
if len(current_expander):
item = current_expander.pop(0)
item = item_list.pop(item_list.index(item))
else:
item = item_list.pop(0)
self.get_location(location).item = item
if len(item_list) == 0:
break
print(f"{len(item_list)} unplaced items, but game is beatable.")
print("Locations:\n\t" + "\n\t".join(location_list))
print("Items:\n\t" + "\n\t".join(item_list))
while len(item_list):
item = item_list.pop(0)
location = location_list.pop(0)
self.get_location(location).item = item
print("All items and locations have been filled. "
f"Game is beatable in {n_spheres} spheres.")
def get_location(self, location_name):
return self.location_cache[location_name]
def get_npc(self, location_name):
return self.location_cache[location_name]
def get_barrier(self, location_name):
return self.barrier_cache[location_name]
def set_rules_barrier(self):
add_rule(self.get_barrier("Red"), lambda state:
state.has_group("magic"))
add_rule(self.get_barrier("Blue"), lambda state:
state.has_group("magic") and state.has_group("blue"))
add_rule(self.get_barrier("Purple"), lambda state:
state.has_group("magic") and state.has("Purple Magic"))
add_rule(self.get_barrier("Gauntlet"), lambda state:
state.has("Bomb Gauntlet") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"])))
add_rule(self.get_barrier("Flute"), lambda state:
state.has("Fatal Flute") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"])))
def set_rules(self):
# NPC LOCATIONS
# Level Access Rules
for npc in all_npcs:
level = npc.split()[0]
add_rule(self.get_npc(npc), lambda state, level=level:
state.has(self.level_beacons[level]))
if level in ["Crypts", "Fort", "Castle", "Lair"]:
add_rule(self.get_npc(npc), lambda state:
state.has("Power Pendant"))
for level, locations in self.level_locations.items():
for item in locations:
add_rule(self.get_location(item), lambda state, level=level:
state.has(self.level_beacons[level]))
if level in ["Crypts", "Fort", "Castle", "Lair"]:
add_rule(self.get_location(item), lambda state:
state.has("Power Pendant"))
# Faramore Rules
add_rule(self.get_location("Faramore Key (Well)"), lambda state:
state.has("Faramore Key (Well)") or state.has("Faramore Key (Tavern)") or
state.has("Griffin Boots"))
for item in ["Faramore Bonus", "Faramore Candle (Empty House)", "Faramore Maki"]:
add_rule(self.get_location(item), lambda state:
((state.has("Faramore Key (Well)") or state.has("Faramore Key (Tavern)")) and
(self.get_barrier(self.barrier_types["Blue"]).access_rule(state) or
(state.has("Winged Belt") and self.config["logic"]["tricky_jumps"]))) or
state.has("Griffin Boots"))
for npc in ["Faramore Kari Quest", "Faramore Barnabuss"]:
add_rule(self.get_npc(npc), lambda state:
state.has("Faramore Key (Well)") or state.has("Faramore Key (Tavern)") or
state.has("Griffin Boots"))
add_rule(self.get_npc("Faramore Payop"), lambda state:
((state.has("Faramore Key (Well)") or state.has("Faramore Key (Tavern)")) and
self.get_barrier(self.barrier_types["Red"]).access_rule(state)) or
state.has("Griffin Boots"))
for item in ["Faramore Dewey", "Faramore Coin"]:
add_rule(self.get_location(item), lambda state:
state.has("Griffin Boots") and
self.get_barrier(self.barrier_types["Purple"]).access_rule(state))
# Purple Magic requirement for Dewey has been deactivated in the mod.
add_rule(self.get_location("Faramore Candle (Cypress House)"), lambda state:
state.has("Griffin Boots") and
self.get_barrier(self.barrier_types["Red"]).access_rule(state) and
self.get_barrier(self.barrier_types["Blue"]).access_rule(state))
for npc in ["Faramore Denny", "Faramore Cypress"]:
add_rule(self.get_npc(npc), lambda state: state.has("Griffin Boots"))
add_rule(self.get_npc("Faramore Rudy"), lambda state:
state.has_group("bombs"))
# Forest Rules
for item in ["Forest Coin", "Forest Bag (Sword Wave)", "Golden Fly", "Sword Wave",
"Forest Bag (Last Room)", "Forest Beacon", "Forest Jewel", "Magic Armor",
"Forest Cypress"]:
add_rule(self.get_location(item), lambda state:
state.has("Forest Key") or state.has("Griffin Boots"))
add_rule(self.get_location("Forest Rudy (End)"), lambda state:
state.has("Forest Key") or
(state.has("Griffin Boots") and self.config["logic"]["tricky_jumps"]))
add_rule(self.get_location("Golden Fly"), lambda state:
state.has_group("bombs") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"])) and
self.get_barrier(self.barrier_types["Red"]).access_rule(state))
add_rule(self.get_location("Forest Jewel"), lambda state:
state.has_group("candles", 17))
add_rule(self.get_location("Magic Armor"), lambda state:
state.has_group("candles", 20) and
self.get_barrier(self.barrier_types["Gauntlet"]).access_rule(state))
for item in ["Sword Wave", "Forest Bag (Sword Wave)"]:
add_rule(self.get_location(item), lambda state:
((state.has("Lantern") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"]))) or
self.config["logic"]["no_lantern"]))
add_rule(self.get_location("Forest Candle (Tree)"), lambda state:
self.get_barrier(self.barrier_types["Red"]).access_rule(state))
add_rule(self.get_location("Forest Candle (Cypress)"), lambda state:
state.has("Griffin Boots"))
# Caves Rules
for item in ["Silver Cricket", "Rope Ladder", "Caves Bag (Rope Ladder)",
"Caves Candle (First Dark Room)", "Caves Coin",
"Caves Candle (Second Dark Room)", "Caves Bonus", "Shield Ring",
"Caves Bag (Last Room)", "Caves Ellido"]:
add_rule(self.get_location(item), lambda state:
state.has("Bombs") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"])))
for item in ["Caves Candle (First Dark Room)", "Caves Coin",
"Caves Candle (Second Dark Room)", "Caves Bonus", "Shield Ring",
"Caves Bag (Last Room)", "Caves Ellido"]:
add_rule(self.get_location(item), lambda state:
((state.has("Lantern") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"]))) or
self.config["logic"]["no_lantern"]))
for item in ["Silver Cricket", "Rope Ladder",
"Caves Bag (Rope Ladder)", "Caves Ellido"]:
add_rule(self.get_location(item), lambda state:
self.get_barrier(self.barrier_types["Blue"]).access_rule(state))
for item in ["Rope Ladder", "Caves Bag (Rope Ladder)"]:
add_rule(self.get_location(item), lambda state:
self.get_barrier(self.barrier_types["Purple"]).access_rule(state))
add_rule(self.get_location("Caves Candle (First Dark Room)"), lambda state:
self.get_barrier(self.barrier_types["Red"]).access_rule(state))
add_rule(self.get_location("Caves Coin"), lambda state:
state.has("Griffin Boots") or state.has("Winged Belt"))
# Desert Rules
add_rule(self.get_location("Desert Key"), lambda state:
(state.has_group("bombs") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"]))) or
(((state.has("Griffin Boots")) or
(state.has("Winged Belt") and state.has("Speedy Shoes"))) and
self.get_barrier(self.barrier_types["Red"]).access_rule(state) and
self.config["logic"]["tricky_jumps"]))
for item in ["Desert Key", "Desert Candle (Last Room)", "Desert Life-Up",
"Desert Bag (Last Room)", "Desert Beacon", "Desert Fairy"]:
add_rule(self.get_location(item), lambda state:
((state.has("Lantern") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"]))) or
self.config["logic"]["no_lantern"]))
for item in ["Desert Candle (Last Room)", "Desert Life-Up",
"Desert Bag (Last Room)", "Desert Beacon", "Desert Fairy"]:
add_rule(self.get_location(item), lambda state: state.has("Desert Key"))
add_rule(self.get_location("Desert Candle (Last Room)"), lambda state:
self.get_barrier(self.barrier_types["Red"]).access_rule(state) and
self.get_barrier(self.barrier_types["Blue"]).access_rule(state))
add_rule(self.get_location("Desert Life-Up"), lambda state:
state.has_group("candles", 20))
add_rule(self.get_location("Desert Beacon"), lambda state:
self.get_barrier(self.barrier_types["Red"]).access_rule(state) or
(state.has("Griffin Boots") and self.config["logic"]["tricky_jumps"]))
# Canyon Rules
add_rule(self.get_location("Canyon Bonus"), lambda state:
self.get_barrier(self.barrier_types["Red"]).access_rule(state))
add_rule(self.get_location("Canyon Candle (First Room End)"), lambda state:
(state.has("Speedy Shoes") and state.has("Winged Belt")) or
state.has("Griffin Boots"))
for item in ["Canyon Jewel", "Canyon Crowdee"]:
add_rule(self.get_location(item), lambda state:
state.has_group("candles", 20) and
(state.has_group("magic") or state.has("Griffin Boots") or
state.has("Reflector Ring") or (state.has("Magic Cloak") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"]))) or
self.config["logic"]["damage_boost"]))
for item in ["Canyon Key", "Canyon Bag (After Zipline 1)",
"Canyon Bag (After Zipline 2)", "Canyon Bag (After Zipline 3)",
"Canyon Coin", "Canyon Bag (Motte House)", "Canyon Candle (Motte House)",
"Canyon Motte", "Canyon Odie"]:
add_rule(self.get_location(item), lambda state:
state.has_group("bombs") and
(state.has("Lantern") or self.config["logic"]["no_lantern"]) and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"])))
for item in ["Canyon Candle (Motte House)", "Canyon Motte", "Canyon Odie"]:
add_rule(self.get_location(item), lambda state: state.has("Canyon Key"))
for item in ["Canyon Candle (Motte House)", "Canyon Odie"]:
add_rule(self.get_location(item), lambda state:
(self.get_barrier(self.barrier_types["Red"]).access_rule(state) or
state.has("Griffin Boots")))
add_rule(self.get_location("Canyon Candle (Motte House)"), lambda state:
self.get_barrier(self.barrier_types["Blue"]).access_rule(state))
# Swamp Rules
for item in ["Swamp Candle (First Room)", "Swamp Bag (First Room)", "Swamp Coin",
"Swamp Key (Frich House)", "Swamp Candle (Frich House)",
"Swamp Frich", "Swamp Glubbert"]:
add_rule(self.get_location(item), lambda state:
state.has_group("magic") or state.has("Griffin Boots") or
state.has("Reflector Ring") or (state.has("Magic Cloak") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"]))) or
self.config["logic"]["damage_boost"])
for item in ["Swamp Key (Griffin Boots)", "Griffin Boots", "Swamp Plant",
"Swamp Bonus", "Swamp Beacon"]:
add_rule(self.get_location(item), lambda state:
(state.has_group("magic") or
((state.has("Fatal Flute") or state.has("Magic Cloak")) and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"]))) or
self.config["logic"]["damage_boost"]))
for item in ["Swamp Candle (First Room)", "Swamp Bag (First Room)",
"Swamp Candle (Frich House)"]:
add_rule(self.get_location(item), lambda state:
state.has("Griffin Boots"))
for item in ["Swamp Coin", "Swamp Key (Frich House)", "Swamp Candle (Frich House)",
"Swamp Key (Griffin Boots)", "Griffin Boots", "Swamp Plant",
"Swamp Bonus", "Swamp Beacon", "Swamp Glubbert"]:
add_rule(self.get_location(item), lambda state:
state.has("Golden Fly")) # This is only because Frich is locked for now
for item in ["Swamp Candle (Frich House)", "Swamp Key (Griffin Boots)",
"Griffin Boots", "Swamp Plant", "Swamp Bonus", "Swamp Beacon",
"Swamp Glubbert"]:
add_rule(self.get_location(item), lambda state:
state.has("Swamp Key (Frich House)"))
add_rule(self.get_location("Swamp Key (Griffin Boots)"), lambda state:
self.get_barrier(self.barrier_types["Blue"]).access_rule(state))
for item in ["Griffin Boots", "Swamp Plant", "Swamp Bonus"]:
add_rule(self.get_location(item), lambda state:
state.has("Swamp Key (Griffin Boots)") or
self.get_barrier(self.barrier_types["Red"]).access_rule(state))
add_rule(self.get_location("Swamp Beacon"), lambda state:
state.has_group("bombs") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"])))
# Peak Rules
add_rule(self.get_location("Peak Candle (First Cave)"), lambda state:
self.get_barrier(self.barrier_types["Red"]).access_rule(state))
for item in ["Peak Bag (First Cave 1)",
"Peak Bag (First Cave 2)", "Peak Bonus", "Peak Coin"]:
add_rule(self.get_location(item), lambda state:
self.get_barrier(self.barrier_types["Red"]).access_rule(state) and
(state.has_group("magic") or state.has("Griffin Boots") or
state.has("Reflector Ring") or (state.has("Magic Cloak") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"]))) or
self.config["logic"]["damage_boost"]))
for item in ["Peak Rudy (End)", "Peak Key",
"Peak Candle (Ciclena Cave)", "Peak Bag (Before Apatu)",
"Peak Jewel", "Peak Bag (After Apatu)", "Peak Ciclena"]:
add_rule(self.get_location(item), lambda state:
self.get_barrier(self.barrier_types["Red"]).access_rule(state) and
(state.has_group("magic") or
(state.has("Magic Cloak") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"]))) or
(state.has("Fatal Flute") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"])) and
state.has("Griffin Boots")) or
self.config["logic"]["damage_boost"]))
for item in ["Peak Rudy (End)", "Peak Coin", "Peak Key",
"Peak Candle (Ciclena Cave)", "Peak Bag (Before Apatu)",
"Peak Jewel", "Peak Bag (After Apatu)", "Peak Ciclena"]:
add_rule(self.get_location(item), lambda state:
((state.has("Lantern") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"]))) or
self.config["logic"]["no_lantern"]))
add_rule(self.get_location("Peak Candle (First Cave)"), lambda state:
self.get_barrier(self.barrier_types["Blue"]).access_rule(state))
add_rule(self.get_location("Peak Coin"), lambda state:
self.get_barrier(self.barrier_types["Purple"]).access_rule(state))
add_rule(self.get_location("Peak Ciclena"), lambda state:
state.has("Peak Key"))
add_rule(self.get_location("Peak Candle (Ciclena Cave)"), lambda state:
state.has("Peak Key") and state.has("Griffin Boots"))
for item in ["Peak Jewel", "Peak Bag (After Apatu)"]:
add_rule(self.get_location(item), lambda state:
state.has_group("candles", 20))
add_rule(self.get_location("Peak Bag (After Apatu)"), lambda state:
state.has("Peak Jewel"))
# Crypts Rules
for item in ["Crypts Life-Up", "Bell", "Crypts Bonus", "Crypts Key",
"Crypts Bag (Crypt)", "Crypts Candle (After Crypt)", "Crypts Coin",
"Crypts Candle (Skelvis)", "Crypts Bag (Skelvis)",
"Crypts Skelvis"]:
add_rule(self.get_location(item), lambda state:
state.has_group("magic") or state.has("Griffin Boots") or
state.has("Reflector Ring") or (state.has("Magic Cloak") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"]))) or
self.config["logic"]["damage_boost"])
add_rule(self.get_location("Crypts Life-Up"), lambda state:
state.has_group("bombs") and state.has_group("candles", 20) and
state.has("Griffin Boots") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"])))
add_rule(self.get_location("Bell"), lambda state:
state.has_group("bombs") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"])) and
(self.get_barrier(self.barrier_types["Blue"]).access_rule(state) or
(state.has_group("candles", 20) and state.has("Griffin Boots"))))
for item in ["Crypts Bonus", "Crypts Key", "Crypts Bag (Crypt)",
"Crypts Candle (After Crypt)", "Crypts Coin",
"Crypts Candle (Skelvis)", "Crypts Bag (Skelvis)", "Crypts Skelvis"]:
add_rule(self.get_location(item), lambda state:
((state.has("Lantern") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"]))) or
self.config["logic"]["no_lantern"]))
for item in ["Crypts Candle (After Crypt)", "Crypts Coin",
"Crypts Candle (Skelvis)", "Crypts Bag (Skelvis)", "Crypts Skelvis"]:
add_rule(self.get_location(item), lambda state:
state.has("Crypts Key"))
add_rule(self.get_location("Crypts Candle (After Crypt)"), lambda state:
state.has("Griffin Boots") or state.has("Winged Belt"))
add_rule(self.get_location("Crypts Coin"), lambda state:
self.get_barrier(self.barrier_types["Flute"]).access_rule(state) and
self.barrier_types["Flute"] == "Flute")
for item in ["Crypts Candle (Skelvis)", "Crypts Bag (Skelvis)", "Crypts Skelvis"]:
add_rule(self.get_location(item), lambda state:
state.has_group("bombs") and
(state.has_group("bags") or state.has(self.level_beacons["Faramore"])))
add_rule(self.get_location("Crypts Candle (Skelvis)"), lambda state:
self.get_barrier(self.barrier_types["Blue"]).access_rule(state))
add_rule(self.get_location("Crypts Bag (Skelvis)"), lambda state:
self.get_barrier(self.barrier_types["Gauntlet"]).access_rule(state))
# Volcano Rules
add_rule(self.get_location("Volcano Bonus"), lambda state:
self.get_barrier(self.barrier_types["Gauntlet"]).access_rule(state))
for item in ["Volcano Candle (First Room)", "Volcano Coin",
"Volcano Candle (Last Room)", "Crystal of Refraction"]:
add_rule(self.get_location(item), lambda state:
state.has_group("magic") or self.config["logic"]["tricky_jumps"] or
self.config["logic"]["damage_boost"])
add_rule(self.get_location("Volcano Coin"), lambda state:
state.has("Griffin Boots") or state.has("Winged Belt") or
(state.has("Backstep") and self.config["logic"]["tricky_jumps"]))
# Beach Rules
add_rule(self.get_location("Beach Key (First House)"), lambda state:
state.has("Griffin Boots") or state.has("Winged Belt"))
add_rule(self.get_location("Beach Coin"), lambda state:
state.has("Griffin Boots") and
self.get_barrier(self.barrier_types["Blue"]).access_rule(state))
for item in ["Beach Key (Tork Cabin)", "Beach Candle (Tork Cabin)", "Beach Plant",
"Beach Bonus", "Beach Candle (Cave)", "Fatal Flute", "Beach Beacon",
"Beach Fleetus", "Beach Tork"]:
add_rule(self.get_location(item), lambda state:
state.has("Beach Key (First House)") and