forked from Roman971/OoT-Randomizer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ItemPool.py
1142 lines (1036 loc) · 48.6 KB
/
ItemPool.py
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
from __future__ import annotations
import random
from collections import Counter
from collections.abc import Sequence
from decimal import Decimal, ROUND_UP
from typing import TYPE_CHECKING, Optional
from Item import Item, ItemInfo, ItemFactory
from Location import DisableType
if TYPE_CHECKING:
from Plandomizer import ItemPoolRecord
from World import World
closed_forest_restricted_items: tuple[str, ...] = (
'Bomb Bag',
'Bombchus (5)',
'Bombchus (10)',
'Bombchus (20)',
'Bombchus',
'Dins Fire',
'Progressive Scale',
'Bolero of Fire',
'Serenade of Water',
'Nocturne of Shadow',
'Requiem of Spirit',
'Prelude of Light',
)
eggs: tuple[str, ...] = (
'Easter Egg (Pink)',
'Easter Egg (Orange)',
'Easter Egg (Green)',
'Easter Egg (Blue)',
)
triforce_blitz_items: tuple[str, ...] = (
'Triforce of Power',
'Triforce of Wisdom',
'Triforce of Courage',
)
triforce_pieces: tuple[str, ...] = (
'Triforce Piece',
*eggs,
*triforce_blitz_items,
)
plentiful_items: list[str] = [
'Biggoron Sword',
'Boomerang',
'Lens of Truth',
'Megaton Hammer',
'Iron Boots',
'Goron Tunic',
'Zora Tunic',
'Hover Boots',
'Mirror Shield',
'Fire Arrows',
'Light Arrows',
'Dins Fire',
'Progressive Hookshot',
'Progressive Strength Upgrade',
'Progressive Scale',
'Progressive Wallet',
'Magic Meter',
'Deku Stick Capacity',
'Deku Nut Capacity',
'Bow',
'Bomb Bag',
'Double Defense',
]
# List of items that can be multiplied in ludicrous mode.
# Used to filter the pre-plando pool for candidates instead
# of appending directly, making this list settings-independent.
# Excludes Gold Skulltula Tokens, Triforce Pieces, and health
# upgrades as they are directly tied to win conditions and
# already have a large count relative to available locations
# in the game.
#
# Base items will always be candidates to replace junk items,
# even if the player starts with all "normal" copies of an item.
ludicrous_items_base: list[str] = [
'Light Arrows',
'Megaton Hammer',
'Progressive Hookshot',
'Progressive Strength Upgrade',
'Dins Fire',
'Hover Boots',
'Mirror Shield',
'Boomerang',
'Iron Boots',
'Fire Arrows',
'Progressive Scale',
'Progressive Wallet',
'Magic Meter',
'Bow',
'Bomb Bag',
'Bombchus (10)',
'Lens of Truth',
'Goron Tunic',
'Zora Tunic',
'Biggoron Sword',
'Double Defense',
'Farores Wind',
'Nayrus Love',
'Stone of Agony',
'Deku Stick Capacity',
'Deku Nut Capacity'
]
ludicrous_items_extended: list[str] = [
'Kokiri Emerald',
'Goron Ruby',
'Zora Sapphire',
'Light Medallion',
'Forest Medallion',
'Fire Medallion',
'Water Medallion',
'Shadow Medallion',
'Spirit Medallion',
'Zeldas Lullaby',
'Eponas Song',
'Suns Song',
'Sarias Song',
'Song of Time',
'Song of Storms',
'Minuet of Forest',
'Prelude of Light',
'Bolero of Fire',
'Serenade of Water',
'Nocturne of Shadow',
'Requiem of Spirit',
'Ocarina',
'Kokiri Sword',
'Deku Seed Bag',
'Boss Key (Ganons Castle)',
'Boss Key (Forest Temple)',
'Boss Key (Fire Temple)',
'Boss Key (Water Temple)',
'Boss Key (Shadow Temple)',
'Boss Key (Spirit Temple)',
'Gerudo Membership Card',
'Small Key (Treasure Chest Game)',
'Small Key (Thieves Hideout)',
'Small Key (Shadow Temple)',
'Small Key (Ganons Castle)',
'Small Key (Forest Temple)',
'Small Key (Spirit Temple)',
'Small Key (Fire Temple)',
'Small Key (Water Temple)',
'Small Key (Bottom of the Well)',
'Small Key (Gerudo Training Ground)',
'Small Key Ring (Treasure Chest Game)',
'Small Key Ring (Thieves Hideout)',
'Small Key Ring (Shadow Temple)',
'Small Key Ring (Ganons Castle)',
'Small Key Ring (Forest Temple)',
'Small Key Ring (Spirit Temple)',
'Small Key Ring (Fire Temple)',
'Small Key Ring (Water Temple)',
'Small Key Ring (Bottom of the Well)',
'Small Key Ring (Gerudo Training Ground)',
'Magic Bean Pack',
'Ice Arrows',
'Blue Fire Arrows',
'Weird Egg',
'Chicken',
'Zeldas Letter',
'Keaton Mask',
'Skull Mask',
'Spooky Mask',
'Bunny Hood',
'Mask of Truth',
'Pocket Egg',
'Pocket Cucco',
'Cojiro',
'Odd Mushroom',
'Odd Potion',
'Poachers Saw',
'Broken Sword',
'Prescription',
'Eyeball Frog',
'Eyedrops',
'Claim Check'
'Silver Rupee (Dodongos Cavern Staircase)',
'Silver Rupee (Ice Cavern Spinning Scythe)',
'Silver Rupee (Ice Cavern Push Block)',
'Silver Rupee (Bottom of the Well Basement)',
'Silver Rupee (Shadow Temple Scythe Shortcut)',
'Silver Rupee (Shadow Temple Invisible Blades)',
'Silver Rupee (Shadow Temple Huge Pit)',
'Silver Rupee (Shadow Temple Invisible Spikes)',
'Silver Rupee (Gerudo Training Ground Slopes)',
'Silver Rupee (Gerudo Training Ground Lava)',
'Silver Rupee (Gerudo Training Ground Water)',
'Silver Rupee (Spirit Temple Child Early Torches)',
'Silver Rupee (Spirit Temple Adult Boulders)',
'Silver Rupee (Spirit Temple Lobby and Lower Adult)',
'Silver Rupee (Spirit Temple Sun Block)',
'Silver Rupee (Spirit Temple Adult Climb)',
'Silver Rupee (Ganons Castle Spirit Trial)',
'Silver Rupee (Ganons Castle Light Trial)',
'Silver Rupee (Ganons Castle Fire Trial)',
'Silver Rupee (Ganons Castle Shadow Trial)',
'Silver Rupee (Ganons Castle Water Trial)',
'Silver Rupee (Ganons Castle Forest Trial)',
'Silver Rupee Pouch (Dodongos Cavern Staircase)',
'Silver Rupee Pouch (Ice Cavern Spinning Scythe)',
'Silver Rupee Pouch (Ice Cavern Push Block)',
'Silver Rupee Pouch (Bottom of the Well Basement)',
'Silver Rupee Pouch (Shadow Temple Scythe Shortcut)',
'Silver Rupee Pouch (Shadow Temple Invisible Blades)',
'Silver Rupee Pouch (Shadow Temple Huge Pit)',
'Silver Rupee Pouch (Shadow Temple Invisible Spikes)',
'Silver Rupee Pouch (Gerudo Training Ground Slopes)',
'Silver Rupee Pouch (Gerudo Training Ground Lava)',
'Silver Rupee Pouch (Gerudo Training Ground Water)',
'Silver Rupee Pouch (Spirit Temple Child Early Torches)',
'Silver Rupee Pouch (Spirit Temple Adult Boulders)',
'Silver Rupee Pouch (Spirit Temple Lobby and Lower Adult)',
'Silver Rupee Pouch (Spirit Temple Sun Block)',
'Silver Rupee Pouch (Spirit Temple Adult Climb)',
'Silver Rupee Pouch (Ganons Castle Spirit Trial)',
'Silver Rupee Pouch (Ganons Castle Light Trial)',
'Silver Rupee Pouch (Ganons Castle Fire Trial)',
'Silver Rupee Pouch (Ganons Castle Shadow Trial)',
'Silver Rupee Pouch (Ganons Castle Water Trial)',
'Silver Rupee Pouch (Ganons Castle Forest Trial)',
'Ocarina A Button',
'Ocarina C up Button',
'Ocarina C left Button',
'Ocarina C down Button',
'Ocarina C right Button',
]
ludicrous_exclusions: tuple[str, ...] = (
*triforce_pieces,
'Gold Skulltula Token',
'Rutos Letter',
'Heart Container',
'Piece of Heart',
'Piece of Heart (Treasure Chest Game)',
)
item_difficulty_max: dict[str, dict[str, int]] = {
'ludicrous': {},
'plentiful': {},
'balanced': {},
'scarce': {
'Bombchus (5)': 1,
'Bombchus (10)': 2,
'Bombchus (20)': 0,
'Magic Meter': 1,
'Double Defense': 0,
'Deku Stick Capacity': 1,
'Deku Nut Capacity': 1,
'Bow': 2,
'Slingshot': 2,
'Deku Seed Bag': 1,
'Bomb Bag': 2,
'Heart Container': 0,
},
'minimal': {
'Bombchus (5)': 1,
'Bombchus (10)': 0,
'Bombchus (20)': 0,
'Magic Meter': 1,
'Nayrus Love': 1,
'Double Defense': 0,
'Deku Stick Capacity': 0,
'Deku Nut Capacity': 0,
'Bow': 1,
'Slingshot': 1,
'Deku Seed Bag': 0,
'Bomb Bag': 1,
'Heart Container': 0,
'Piece of Heart': 0,
},
}
shopsanity_rupees: list[str] = (
['Rupees (20)'] * 5 +
['Rupees (50)'] * 3 +
['Rupees (200)'] * 2
)
min_shop_items: list[str] = (
['Buy Deku Shield'] +
['Buy Hylian Shield'] +
['Buy Goron Tunic'] +
['Buy Zora Tunic'] +
['Buy Deku Nut (5)'] * 2 + ['Buy Deku Nut (10)'] +
['Buy Deku Stick (1)'] * 2 +
['Buy Deku Seeds (30)'] +
['Buy Arrows (10)'] * 2 + ['Buy Arrows (30)'] + ['Buy Arrows (50)'] +
['Buy Bombchu (5)'] + ['Buy Bombchu (10)'] * 2 + ['Buy Bombchu (20)'] +
['Buy Bombs (5) for 25 Rupees'] + ['Buy Bombs (5) for 35 Rupees'] + ['Buy Bombs (10)'] + ['Buy Bombs (20)'] +
['Buy Green Potion'] +
['Buy Red Potion for 30 Rupees'] +
['Buy Blue Fire'] +
["Buy Fairy's Spirit"] +
['Buy Bottle Bug'] +
['Buy Fish']
)
deku_scrubs_items: dict[str, str | list[tuple[str, int]]] = {
'Buy Deku Shield': 'Deku Shield',
'Buy Deku Nut (5)': 'Deku Nuts (5)',
'Buy Deku Stick (1)': 'Deku Stick (1)',
'Buy Bombs (5) for 35 Rupees': 'Bombs (5)',
'Buy Red Potion for 30 Rupees': 'Recovery Heart',
'Buy Green Potion': 'Rupees (5)',
'Buy Arrows (30)': [('Arrows (30)', 3), ('Deku Seeds (30)', 1)],
'Buy Deku Seeds (30)': [('Arrows (30)', 3), ('Deku Seeds (30)', 1)],
}
trade_items: tuple[str, ...] = (
"Pocket Egg",
"Pocket Cucco",
"Cojiro",
"Odd Mushroom",
"Odd Potion",
"Poachers Saw",
"Broken Sword",
"Prescription",
"Eyeball Frog",
"Eyedrops",
"Claim Check",
)
child_trade_items: tuple[str, ...] = (
"Weird Egg",
"Chicken",
"Zeldas Letter",
"Keaton Mask",
"Skull Mask",
"Spooky Mask",
"Bunny Hood",
"Goron Mask",
"Zora Mask",
"Gerudo Mask",
"Mask of Truth",
)
normal_bottles: list[str] = [bottle for bottle in sorted(ItemInfo.bottles) if bottle not in ('Deliver Letter', 'Sell Big Poe')] + ['Bottle with Big Poe']
reward_list: list[str] = [item.name for item in sorted([i for n, i in ItemInfo.items.items() if i.type == 'DungeonReward'], key=lambda x: x.special['item_id'])]
song_list: list[str] = [item.name for item in sorted([i for n, i in ItemInfo.items.items() if i.type == 'Song'], key=lambda x: x.index if x.index is not None else 0)]
junk_pool_base: list[tuple[str, int]] = [(item, weight) for (item, weight) in sorted(ItemInfo.junk_weight.items()) if weight > 0]
remove_junk_items: list[str] = [item for (item, weight) in sorted(ItemInfo.junk_weight.items()) if weight >= 0]
remove_junk_ludicrous_items: list[str] = [
'Ice Arrows',
'Deku Nut Capacity',
'Deku Stick Capacity',
'Double Defense',
'Biggoron Sword'
]
# a useless placeholder item placed at some skipped and inaccessible locations
# (e.g. HC Malon Egg with Skip Child Zelda, or the carpenters with Open Gerudo Fortress)
IGNORE_LOCATION: str = 'Nothing'
pending_junk_pool: list[str] = []
junk_pool: list[tuple[str, int]] = []
exclude_from_major: list[str] = [
'Deliver Letter',
'Sell Big Poe',
'Magic Bean',
'Buy Magic Bean',
'Zeldas Letter',
'Bombchus (5)',
'Bombchus (10)',
'Bombchus (20)',
'Odd Potion',
*triforce_pieces,
'Heart Container',
'Piece of Heart',
'Piece of Heart (Treasure Chest Game)',
]
item_groups: dict[str, Sequence[str]] = {
'Junk': remove_junk_items,
'JunkSong': ('Prelude of Light', 'Serenade of Water'),
'AdultTrade': trade_items,
'ChildTrade': child_trade_items,
'Bottle': normal_bottles,
'Spell': ('Dins Fire', 'Farores Wind', 'Nayrus Love'),
'Shield': ('Deku Shield', 'Hylian Shield'),
'Song': song_list,
'NonWarpSong': song_list[6:],
'WarpSong': song_list[0:6],
'HealthUpgrade': ('Heart Container', 'Piece of Heart', 'Piece of Heart (Treasure Chest Game)'),
'ProgressItem': sorted([name for name, item in ItemInfo.items.items() if item.type == 'Item' and item.advancement]),
'MajorItem': sorted([name for name, item in ItemInfo.items.items() if item.type in ('Item', 'Song') and item.advancement and name not in exclude_from_major]),
'DungeonReward': reward_list,
'Map': sorted([name for name, item in ItemInfo.items.items() if item.type == 'Map']),
'Compass': sorted([name for name, item in ItemInfo.items.items() if item.type == 'Compass']),
'BossKey': sorted([name for name, item in ItemInfo.items.items() if item.type == 'BossKey']),
'SmallKey': sorted([name for name, item in ItemInfo.items.items() if item.type in ('SmallKey', 'SmallKeyRing')]),
'ForestFireWater': ('Forest Medallion', 'Fire Medallion', 'Water Medallion'),
'FireWater': ('Fire Medallion', 'Water Medallion'),
}
def get_junk_item(count: int = 1, pool: Optional[list[str]] = None, plando_pool: Optional[dict[str, ItemPoolRecord]] = None) -> list[str]:
if count < 1:
raise ValueError("get_junk_item argument 'count' must be greater than 0.")
return_pool = []
if pending_junk_pool:
pending_count = min(len(pending_junk_pool), count)
return_pool = [pending_junk_pool.pop() for _ in range(pending_count)]
count -= pending_count
if pool and plando_pool:
jw_dict = {junk: weight for (junk, weight) in junk_pool
if junk not in plando_pool or pool.count(junk) < plando_pool[junk].count}
if not jw_dict:
raise RuntimeError("Not enough junk is available in the item pool to replace removed items.")
else:
jw_dict = {junk: weight for (junk, weight) in junk_pool}
return_pool.extend(random.choices(list(jw_dict.keys()), weights=list(jw_dict.values()), k=count))
return return_pool
def get_pool_count(pool: list[str], item_list: list[str]) -> int:
count = 0
for val in pool:
if val in item_list:
count += 1
return count
def replace_x_items(items: list[str], replace_list: list[str], x: int) -> None:
random.shuffle(items)
count = 0
for i, val in enumerate(items):
if val in replace_list:
if count < x:
items[i] = get_junk_item()[0]
count += 1
else:
return
def replace_max_item(items: list[str], item: str, max_count: int) -> None:
count = 0
for i, val in enumerate(items):
if val == item:
if count >= max_count:
items[i] = get_junk_item()[0]
count += 1
def generate_itempool(world: World) -> None:
junk_pool[:] = list(junk_pool_base)
if world.settings.junk_ice_traps == 'on':
junk_pool.append(('Ice Trap', 10))
elif world.settings.junk_ice_traps in ('mayhem', 'onslaught'):
junk_pool[:] = [('Ice Trap', 1)]
# set up item pool
(pool, placed_items) = get_pool_core(world)
placed_items_count = {}
world.itempool = ItemFactory(pool, world)
world.initialize_items(world.itempool + list(placed_items.values()))
placed_locations = list(filter(lambda loc: loc.name in placed_items, world.get_locations()))
for location in placed_locations:
item = placed_items[location.name]
placed_items_count[item.name] = placed_items_count.get(item.name, 0) + 1
world.push_item(location, item)
world.get_location(location).locked = True
world.distribution.set_complete_itempool(world.itempool)
# make sure that there are enough gold skulltulas for bridge/ganon boss key/lacs
world.available_tokens = (placed_items_count.get("Gold Skulltula Token", 0)
+ pool.count("Gold Skulltula Token")
+ world.distribution.get_starting_item("Gold Skulltula Token"))
if world.max_progressions["Gold Skulltula Token"] > world.available_tokens:
raise ValueError(f"Not enough available Gold Skulltula Tokens to meet requirements. Available: {world.available_tokens}, Required: {world.max_progressions['Gold Skulltula Token']}.")
def get_pool_core(world: World) -> tuple[list[str], dict[str, Item]]:
from Dungeon import Dungeon
pool = []
placed_items = {}
remain_shop_items = []
ruto_bottles = 1
blue_potions = 1
if world.settings.zora_fountain == 'open':
ruto_bottles = 0
if world.settings.shopsanity not in ('off', '0'):
pending_junk_pool.append('Progressive Wallet')
if world.settings.item_pool_value == 'plentiful':
if world.settings.shuffle_base_item_pool:
pending_junk_pool.extend(plentiful_items)
if world.settings.require_gohma and world.settings.world_count > 1:
pending_junk_pool.append('Deku Seed Bag')
else:
pending_junk_pool.append('Slingshot')
if world.settings.shuffle_child_trade:
pending_junk_pool.extend(world.settings.shuffle_child_trade)
# Weird Egg is always chosen if both Egg and Chicken are selected to be shuffled.
# Make the duplicate item consistent with that.
if 'Weird Egg' in world.settings.shuffle_child_trade and 'Chicken' in world.settings.shuffle_child_trade:
pending_junk_pool.remove('Chicken')
if world.skip_child_zelda:
for item in ('Weird Egg', 'Chicken', 'Zeldas Letter'):
if item in pending_junk_pool:
pending_junk_pool.remove(item)
if world.settings.adult_trade_shuffle:
pending_junk_pool.extend(world.settings.adult_trade_start)
# Pocket Egg is always chosen if both Egg and Pocket Cucco are selected to be shuffled.
# Make the duplicate item consistent with that.
if 'Pocket Egg' in world.settings.adult_trade_start and 'Pocket Cucco' in world.settings.adult_trade_start:
pending_junk_pool.remove('Pocket Cucco')
elif world.settings.adult_trade_start:
# With adult trade shuffle off, add a random extra adult trade item
item = random.choice(world.settings.adult_trade_start)
pending_junk_pool.append(item)
if world.settings.zora_fountain != 'open':
ruto_bottles += 1
if world.settings.shuffle_kokiri_sword:
pending_junk_pool.append('Kokiri Sword')
if world.settings.shuffle_ocarinas:
pending_junk_pool.append('Ocarina')
if world.settings.shuffle_beans and world.distribution.get_starting_item('Magic Bean') < 10:
pending_junk_pool.append('Magic Bean Pack')
if (world.settings.gerudo_fortress != "open"
and world.settings.shuffle_hideoutkeys in ('any_dungeon', 'overworld', 'keysanity', 'regional')):
if world.keyring('Thieves Hideout'):
pending_junk_pool.append('Small Key Ring (Thieves Hideout)')
else:
pending_junk_pool.append('Small Key (Thieves Hideout)')
if world.settings.shuffle_tcgkeys in ('any_dungeon', 'overworld', 'keysanity', 'regional'):
if world.keyring('Treasure Chest Game'):
pending_junk_pool.append('Small Key Ring (Treasure Chest Game)')
else:
pending_junk_pool.append('Small Key (Treasure Chest Game)')
if world.settings.shuffle_gerudo_card:
pending_junk_pool.append('Gerudo Membership Card')
if world.settings.shuffle_smallkeys in ('any_dungeon', 'overworld', 'keysanity', 'regional'):
for dungeon in ('Forest Temple', 'Fire Temple', 'Water Temple', 'Shadow Temple', 'Spirit Temple',
'Bottom of the Well', 'Gerudo Training Ground', 'Ganons Castle'):
if world.keyring(dungeon):
pending_junk_pool.append(f"Small Key Ring ({dungeon})")
else:
pending_junk_pool.append(f"Small Key ({dungeon})")
if world.settings.shuffle_bosskeys in ('any_dungeon', 'overworld', 'keysanity', 'regional'):
for dungeon in ('Forest Temple', 'Fire Temple', 'Water Temple', 'Shadow Temple', 'Spirit Temple'):
if not world.keyring_give_bk(dungeon):
pending_junk_pool.append(f"Boss Key ({dungeon})")
if world.shuffle_ganon_bosskey in ('any_dungeon', 'overworld', 'keysanity', 'regional'):
pending_junk_pool.append('Boss Key (Ganons Castle)')
if world.settings.shuffle_silver_rupees in ('any_dungeon', 'overworld', 'anywhere', 'regional'):
for puzzle in world.silver_rupee_puzzles():
if puzzle in world.settings.silver_rupee_pouches:
pending_junk_pool.append(f"Silver Rupee Pouch ({puzzle})")
else:
pending_junk_pool.append(f"Silver Rupee ({puzzle})")
if world.settings.shuffle_dungeon_rewards in ('any_dungeon', 'overworld', 'anywhere', 'regional'):
pending_junk_pool.extend(reward_list)
if world.settings.shuffle_song_items == 'any':
pending_junk_pool.extend(song_list)
if world.settings.shuffle_individual_ocarina_notes:
pending_junk_pool.extend(['Ocarina A Button', 'Ocarina C up Button', 'Ocarina C left Button', 'Ocarina C down Button', 'Ocarina C right Button'])
if world.settings.triforce_hunt:
if world.settings.triforce_hunt_mode == 'normal':
pending_junk_pool.extend(['Triforce Piece'] * world.triforce_count_per_world)
elif world.settings.triforce_hunt_mode == 'easter_egg_hunt':
pending_junk_pool.extend(eggs * (world.triforce_count_per_world // len(eggs)))
pending_junk_pool.extend(eggs[:world.triforce_count_per_world % len(eggs)])
elif world.settings.triforce_hunt_mode == 'blitz':
pending_junk_pool.extend(triforce_blitz_items)
# Ice% is handled below
if world.settings.shuffle_individual_ocarina_notes:
pending_junk_pool.append('Ocarina A Button')
pending_junk_pool.append('Ocarina C up Button')
pending_junk_pool.append('Ocarina C left Button')
pending_junk_pool.append('Ocarina C down Button')
pending_junk_pool.append('Ocarina C right Button')
# Use the vanilla items in the world's locations when appropriate.
vanilla_items_processed = Counter()
for location in world.get_locations():
if location.vanilla_item is None:
continue
item = location.vanilla_item
shuffle_item = None # None for don't handle, False for place item, True for add to pool.
# Always Placed Items
if (location.vanilla_item in ('Triforce', 'Scarecrow Song',
'Deliver Letter', 'Time Travel', 'Bombchu Drop')
or location.type == 'Drop'):
shuffle_item = False
# Ice%
elif location.vanilla_item == 'Iron Boots':
if world.settings.triforce_hunt_mode == 'ice_percent':
pending_junk_pool.append(item)
item = 'Triforce Piece'
shuffle_item = False
else:
shuffle_item = world.settings.shuffle_base_item_pool
# Gold Skulltula Tokens
elif location.vanilla_item == 'Gold Skulltula Token':
shuffle_item = (world.settings.tokensanity == 'all'
or (world.settings.tokensanity == 'dungeons' and location.dungeon)
or (world.settings.tokensanity == 'overworld' and not location.dungeon))
# Shops
elif location.type == "Shop":
if world.settings.shopsanity == 'off':
shuffle_item = False
else:
remain_shop_items.append(item)
# Business Scrubs
elif location.type in ("Scrub", "GrottoScrub"):
if location.vanilla_item in ('Piece of Heart', 'Deku Stick Capacity', 'Deku Nut Capacity'):
shuffle_item = world.settings.shuffle_base_item_pool
elif world.settings.shuffle_scrubs == 'off':
shuffle_item = False
else:
item = deku_scrubs_items[location.vanilla_item]
if isinstance(item, list):
item = random.choices([i[0] for i in item], weights=[i[1] for i in item], k=1)[0]
shuffle_item = True
# Kokiri Sword
elif location.vanilla_item == 'Kokiri Sword':
shuffle_item = world.settings.shuffle_kokiri_sword
# Ice Arrows/Blue Fire Arrows
elif location.vanilla_item == 'Ice Arrows':
if world.settings.blue_fire_arrows:
item = 'Blue Fire Arrows'
shuffle_item = world.settings.shuffle_base_item_pool
# Ocarinas
elif location.vanilla_item == 'Ocarina':
shuffle_item = world.settings.shuffle_ocarinas
# Giant's Knife
elif location.vanilla_item == 'Giants Knife':
shuffle_item = world.settings.shuffle_expensive_merchants
# Bombchu Bowling 3rd and 4th prizes (must be checked before Bombchu vanilla items!)
elif location.name in ('Market Bombchu Bowling Bombchus', 'Market Bombchu Bowling Bomb'):
shuffle_item = False
# Bombchus
elif location.vanilla_item in ('Bombchus', 'Bombchus (5)', 'Bombchus (10)', 'Bombchus (20)'):
shuffle_item = world.settings.shuffle_expensive_merchants if location.name == 'Wasteland Bombchu Salesman' else world.settings.shuffle_base_item_pool
# Blue Potion from Granny's Potion Shop
elif location.vanilla_item == 'Blue Potion':
if world.settings.shuffle_expensive_merchants:
shuffle_item = True
# Don't shuffle the shop item. One of the bottles is forced to be a blue potion
# to simulate shuffling.
item = get_junk_item()[0]
else:
shuffle_item = False
# Cows
elif location.vanilla_item == 'Milk':
if world.settings.shuffle_cows:
item = get_junk_item()[0]
shuffle_item = world.settings.shuffle_cows
# Gerudo Card
elif location.vanilla_item == 'Gerudo Membership Card':
shuffle_item = world.settings.shuffle_gerudo_card and world.settings.gerudo_fortress != 'open'
if world.settings.gerudo_fortress == 'open':
if world.settings.shuffle_gerudo_card:
pending_junk_pool.append(item)
item = IGNORE_LOCATION
else:
world.state.collect(ItemFactory(item))
# Bottles
elif location.vanilla_item in ('Bottle', 'Bottle with Milk', 'Rutos Letter'):
if world.settings.shuffle_base_item_pool:
if ruto_bottles:
item = 'Rutos Letter'
ruto_bottles -= 1
# Add one blue potion to world if Granny's Potion Shop is shuffled
elif world.settings.shuffle_expensive_merchants and blue_potions:
item = "Bottle with Blue Potion"
blue_potions -= 1
else:
item = random.choice(normal_bottles)
shuffle_item = world.settings.shuffle_base_item_pool
# Magic Beans
elif location.vanilla_item == 'Buy Magic Bean':
if world.settings.shuffle_beans:
item = 'Magic Bean Pack' if world.distribution.get_starting_item('Magic Bean') < 10 else get_junk_item()[0]
shuffle_item = world.settings.shuffle_beans
# Frogs Purple Rupees
elif location.scene == 0x54 and location.vanilla_item == 'Rupees (50)':
shuffle_item = world.settings.shuffle_frog_song_rupees
# Hyrule Loach Reward
elif location.scene == 0x49 and location.vanilla_item == 'Rupees (50)':
shuffle_item = world.settings.shuffle_loach_reward != 'off'
# Adult Trade Quest Items
elif location.vanilla_item in trade_items:
if not world.settings.adult_trade_shuffle:
if location.vanilla_item == 'Pocket Egg' and world.settings.adult_trade_start:
item = world.selected_adult_trade_item
shuffle_item = True
else:
shuffle_item = False
elif location.vanilla_item in world.settings.adult_trade_start:
shuffle_item = True
else:
# Upgrade Pocket Egg to Pocket Cucco if the Cucco is shuffled but not the Egg.
# If both are selected to be shuffled, only the Egg gets shuffled.
if location.vanilla_item == 'Pocket Egg' and 'Pocket Cucco' in world.settings.adult_trade_start:
item = 'Pocket Cucco'
shuffle_item = True
else:
shuffle_item = False
# Child Trade Quest Items
elif location.vanilla_item in child_trade_items:
if location.vanilla_item == 'Weird Egg' and world.skip_child_zelda:
world.state.collect(ItemFactory(location.vanilla_item, world))
item = IGNORE_LOCATION
shuffle_item = False
elif not world.settings.shuffle_child_trade:
shuffle_item = False
elif location.vanilla_item in world.settings.shuffle_child_trade:
shuffle_item = True
else:
# Upgrade Weird Egg to Chicken if the Chicken is shuffled but not the Egg.
# If both are selected to be shuffled, only the Egg gets shuffled.
if location.vanilla_item == 'Weird Egg' and 'Chicken' in world.settings.shuffle_child_trade:
item = 'Chicken'
shuffle_item = True
else:
shuffle_item = False
# Gerudo Fortress Freestanding Heart Piece
elif location.vanilla_item == 'Piece of Heart (Out of Logic)':
shuffle_item = world.settings.shuffle_gerudo_fortress_heart_piece == 'shuffle'
if world.settings.shuffle_hideout_entrances or world.settings.logic_rules == 'glitched':
if world.settings.shuffle_hideout_entrances and world.settings.shuffle_gerudo_fortress_heart_piece == 'remove':
item = IGNORE_LOCATION
else:
item = 'Piece of Heart'
# Thieves' Hideout
elif location.vanilla_item == 'Small Key (Thieves Hideout)':
shuffle_item = world.settings.shuffle_hideoutkeys != 'vanilla'
if (world.settings.gerudo_fortress == 'open'
or world.settings.gerudo_fortress == 'fast' and location.name != 'Hideout 1 Torch Jail Gerudo Key'):
item = IGNORE_LOCATION
shuffle_item = False
if shuffle_item and world.keyring('Thieves Hideout'):
item = get_junk_item()[0] if vanilla_items_processed[location.vanilla_item] else 'Small Key Ring (Thieves Hideout)'
# Treasure Chest Game Key Shuffle
elif location.vanilla_item != 'Piece of Heart (Treasure Chest Game)' and location.scene == 0x10:
if world.settings.shuffle_tcgkeys in ('regional', 'overworld', 'any_dungeon', 'keysanity'):
if world.keyring('Treasure Chest Game') and location.vanilla_item == 'Small Key (Treasure Chest Game)':
item = get_junk_item()[0] if location.name != 'Market Treasure Chest Game Salesman' else 'Small Key Ring (Treasure Chest Game)'
shuffle_item = True
elif world.settings.shuffle_tcgkeys == 'remove':
if location.vanilla_item == 'Small Key (Treasure Chest Game)':
world.state.collect(ItemFactory(item))
item = get_junk_item()[0]
shuffle_item = True
else:
shuffle_item = False
location.disabled = DisableType.DISABLED
# Freestanding Rupees and Hearts
elif location.type in ('ActorOverride', 'Freestanding', 'RupeeTower'):
if world.settings.shuffle_freestanding_items == 'all':
shuffle_item = True
elif world.settings.shuffle_freestanding_items == 'dungeons' and location.dungeon is not None:
shuffle_item = True
elif world.settings.shuffle_freestanding_items == 'overworld' and location.dungeon is None:
shuffle_item = True
else:
shuffle_item = False
location.disabled = DisableType.DISABLED
# Pots
elif location.type in ('Pot', 'FlyingPot'):
shuffle_item = False
if world.settings.shuffle_pots == 'all':
shuffle_item = True
elif world.settings.shuffle_pots == 'dungeons' and (location.dungeon is not None or (location.parent_region is not None and location.parent_region.is_boss_room)):
shuffle_item = True
elif world.settings.shuffle_pots == 'overworld' and not (location.dungeon is not None or (location.parent_region is not None and location.parent_region.is_boss_room)):
shuffle_item = True
if shuffle_item and (location.vanilla_item != 'Nothing' or world.settings.shuffle_empty_pots):
shuffle_item = True
else:
shuffle_item = False
location.disabled = DisableType.DISABLED
# Crates
elif location.type in ('Crate', 'SmallCrate'):
shuffle_item = False
if world.settings.shuffle_crates == 'all':
shuffle_item = True
elif world.settings.shuffle_crates == 'dungeons' and location.dungeon is not None:
shuffle_item = True
elif world.settings.shuffle_crates == 'overworld' and location.dungeon is None:
shuffle_item = True
if shuffle_item and (location.vanilla_item != 'Nothing' or world.settings.shuffle_empty_crates):
shuffle_item = True
else:
shuffle_item = False
location.disabled = DisableType.DISABLED
# Beehives
elif location.type == 'Beehive':
if world.settings.shuffle_beehives:
shuffle_item = True
else:
shuffle_item = False
location.disabled = DisableType.DISABLED
# Wonderitems
elif location.type == 'Wonderitem':
if world.settings.shuffle_wonderitems:
shuffle_item = True
else:
shuffle_item = False
location.disabled = DisableType.DISABLED
# Dungeon Rewards
elif location.name == 'ToT Reward from Rauru':
if world.settings.shuffle_dungeon_rewards in ('vanilla', 'reward'):
pass # handled in World.fill_bosses
else:
shuffle_item = True
elif location.type == 'Boss':
if world.settings.shuffle_dungeon_rewards in ('vanilla', 'reward'):
pass # handled in World.fill_bosses
elif world.settings.shuffle_dungeon_rewards in ('any_dungeon', 'overworld', 'regional', 'anywhere'):
shuffle_item = True
else:
dungeon = Dungeon.from_vanilla_reward(ItemFactory(location.vanilla_item, world))
dungeon.reward.append(ItemFactory(item, world))
# Ganon boss key
elif location.vanilla_item == 'Boss Key (Ganons Castle)':
if world.shuffle_ganon_bosskey == 'vanilla':
shuffle_item = False
elif world.shuffle_ganon_bosskey == 'remove':
world.state.collect(ItemFactory(item, world))
item = get_junk_item()[0]
shuffle_item = True
elif world.shuffle_ganon_bosskey in ('any_dungeon', 'overworld', 'keysanity', 'regional'):
shuffle_item = True
else:
dungeon = [dungeon for dungeon in world.dungeons if dungeon.name == 'Ganons Castle'][0]
dungeon.boss_key.append(ItemFactory(item, world))
# Slingshots
elif location.vanilla_item == 'Deku Seed Bag':
if world.settings.item_pool_value != 'ludicrous' and (not world.settings.require_gohma or world.settings.world_count == 1):
item = 'Slingshot'
shuffle_item = world.settings.shuffle_base_item_pool
# Dungeon Items
elif location.dungeon is not None:
dungeon = location.dungeon
shuffle_setting = None
dungeon_collection = None
# Boss Key
if location.vanilla_item == dungeon.item_name("Boss Key"):
if world.keyring_give_bk(dungeon.name):
item = get_junk_item()[0]
shuffle_item = True
else:
shuffle_setting = world.settings.shuffle_bosskeys
dungeon_collection = dungeon.boss_key
if shuffle_setting == 'vanilla':
shuffle_item = False
# Map or Compass
elif location.vanilla_item in (dungeon.item_name("Map"), dungeon.item_name("Compass")):
shuffle_setting = world.settings.shuffle_mapcompass
dungeon_collection = dungeon.dungeon_items
if shuffle_setting == 'vanilla':
shuffle_item = False
# Small Key
elif location.vanilla_item == dungeon.item_name("Small Key"):
shuffle_setting = world.settings.shuffle_smallkeys
dungeon_collection = dungeon.small_keys
if shuffle_setting == 'vanilla':
shuffle_item = False
elif world.keyring(dungeon.name) and not vanilla_items_processed[location.vanilla_item]:
item = dungeon.item_name("Small Key Ring")
elif world.keyring(dungeon.name):
item = get_junk_item()[0]
shuffle_item = True
# Silver Rupee
elif location.type == 'SilverRupee':
shuffle_setting = world.settings.shuffle_silver_rupees
dungeon_collection = dungeon.silver_rupees
puzzle = location.vanilla_item[:-1].split('(')[1]
if shuffle_setting == 'vanilla':
shuffle_item = False
elif puzzle in world.settings.silver_rupee_pouches:
item = f'Silver Rupee Pouch ({puzzle})'
if vanilla_items_processed[location.vanilla_item]:
item = get_junk_item()[0]
shuffle_item = True
# Song
elif location.type == 'Song':
shuffle_item = world.settings.shuffle_song_items != 'vanilla'
# Any other item in a dungeon.
elif location.type in ("Chest", "NPC", "Collectable", "Cutscene", "BossHeart"):
shuffle_item = world.settings.shuffle_base_item_pool
# Handle dungeon item.
if shuffle_setting is not None and dungeon_collection is not None and not shuffle_item:
if shuffle_setting in ('remove', 'startwith'):
world.state.collect(ItemFactory(item, world))
item = get_junk_item()[0]
shuffle_item = True
elif shuffle_setting in ('any_dungeon', 'overworld', 'keysanity', 'regional', 'anywhere') and not world.empty_dungeons[dungeon.name].empty:
shuffle_item = True
elif shuffle_item is None:
dungeon_collection.append(ItemFactory(item, world))
# Songs
elif location.type == 'Song':
shuffle_item = world.settings.shuffle_song_items != 'vanilla'
# The rest of the overworld items.
elif location.type in ("Chest", "NPC", "Collectable", "Cutscene", "BossHeart"):
shuffle_item = world.settings.shuffle_base_item_pool
# Now, handle the item as necessary.
if shuffle_item:
pool.append(item)
elif shuffle_item is not None:
placed_items[location.name] = ItemFactory(item, world)
vanilla_items_processed[location.vanilla_item] += 1
# End of Locations loop.
if world.settings.shopsanity != 'off':
pool.extend(min_shop_items)
for item in min_shop_items:
remain_shop_items.remove(item)
shop_slots_count = len(remain_shop_items)
shop_non_item_count = len(world.shop_prices)
shop_item_count = shop_slots_count - shop_non_item_count
pool.extend(random.sample(remain_shop_items, shop_item_count))
if shop_non_item_count:
pool.extend(get_junk_item(shop_non_item_count))
# Extra rupees for shopsanity.
if world.settings.shopsanity not in ('off', '0'):
for rupee in shopsanity_rupees:
if 'Rupees (5)' in pool:
pool[pool.index('Rupees (5)')] = rupee
else:
pending_junk_pool.append(rupee)
if world.settings.free_scarecrow:
world.state.collect(ItemFactory('Scarecrow Song', world))
if world.settings.no_epona_race:
world.state.collect(ItemFactory('Epona', world, event=True))
if world.settings.shuffle_smallkeys == 'vanilla':
# Logic cannot handle vanilla key layout in some dungeons
# this is because vanilla expects the dungeon major item to be
# locked behind the keys, which is not always true in rando.
# We can resolve this by starting with some extra keys
if world.dungeon_mq['Spirit Temple']:
# Yes somehow you need 3 keys. This dungeon is bonkers