From 631b6788c69a64a05a3d383617280b27fe5d7d09 Mon Sep 17 00:00:00 2001 From: espeon65536 Date: Tue, 31 Aug 2021 19:19:26 -0500 Subject: [PATCH] remove keys option for get_all_state, collect dungeon-local keys, and fix all uses of the state --- BaseClasses.py | 30 +++++++----------------------- worlds/alttp/Dungeons.py | 2 ++ worlds/alttp/Rules.py | 2 +- worlds/alttp/__init__.py | 2 +- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/BaseClasses.py b/BaseClasses.py index e101642a..e799af5e 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -213,9 +213,8 @@ class MultiWorld(): except KeyError as e: raise KeyError('No such dungeon %s for player %d' % (dungeonname, player)) from e - def get_all_state(self, keys=False) -> CollectionState: - key = f"_all_state_{keys}" - cached = getattr(self, key, None) + def get_all_state(self) -> CollectionState: + cached = getattr(self, "_all_state", None) if cached: return cached.copy() @@ -223,27 +222,12 @@ class MultiWorld(): for item in self.itempool: self.worlds[item.player].collect(ret, item) - - if keys: - for p in self.get_game_players("A Link to the Past"): - world = self.worlds[p] - from worlds.alttp.Items import ItemFactory - for item in ItemFactory( - ['Small Key (Hyrule Castle)', 'Big Key (Eastern Palace)', 'Big Key (Desert Palace)', - 'Small Key (Desert Palace)', 'Big Key (Tower of Hera)', 'Small Key (Tower of Hera)', - 'Small Key (Agahnims Tower)', 'Small Key (Agahnims Tower)', - 'Big Key (Palace of Darkness)'] + ['Small Key (Palace of Darkness)'] * 6 + [ - 'Big Key (Thieves Town)', 'Small Key (Thieves Town)', 'Big Key (Skull Woods)'] + [ - 'Small Key (Skull Woods)'] * 3 + ['Big Key (Swamp Palace)', - 'Small Key (Swamp Palace)', 'Big Key (Ice Palace)'] + [ - 'Small Key (Ice Palace)'] * 2 + ['Big Key (Misery Mire)', 'Big Key (Turtle Rock)', - 'Big Key (Ganons Tower)'] + [ - 'Small Key (Misery Mire)'] * 3 + ['Small Key (Turtle Rock)'] * 4 + [ - 'Small Key (Ganons Tower)'] * 4, - p): - world.collect(ret, item) + from worlds.alttp.Dungeons import get_dungeon_item_pool + for item in get_dungeon_item_pool(self): + subworld = self.worlds[item.player] + if item.name in subworld.dungeon_local_item_names: + subworld.collect(ret, item) ret.sweep_for_events() - setattr(self, key, ret) return ret def get_items(self) -> list: diff --git a/worlds/alttp/Dungeons.py b/worlds/alttp/Dungeons.py index 76d4953f..000af504 100644 --- a/worlds/alttp/Dungeons.py +++ b/worlds/alttp/Dungeons.py @@ -157,6 +157,8 @@ def fill_dungeons_restrictive(autoworld, world): in_dungeon_items.sort( key=lambda item: sort_order.get(item.type, 1) + (5 if (item.player, item.name) in dungeon_specific else 0)) + for item in in_dungeon_items: + all_state_base.remove(item) fill_restrictive(world, all_state_base, locations, in_dungeon_items, True, True) diff --git a/worlds/alttp/Rules.py b/worlds/alttp/Rules.py index 97fe40ff..083f0aba 100644 --- a/worlds/alttp/Rules.py +++ b/worlds/alttp/Rules.py @@ -853,7 +853,7 @@ def set_trock_key_rules(world, player): for entrance in ['Turtle Rock Dark Room Staircase', 'Turtle Rock (Chain Chomp Room) (North)', 'Turtle Rock (Chain Chomp Room) (South)', 'Turtle Rock Pokey Room', 'Turtle Rock Big Key Door']: set_rule(world.get_entrance(entrance, player), lambda state: False) - all_state = world.get_all_state(True) + all_state = world.get_all_state() all_state.reachable_regions[player] = set() # wipe reachable regions so that the locked doors actually work # Check if each of the four main regions of the dungoen can be reached. The previous code section prevents key-costing moves within the dungeon. diff --git a/worlds/alttp/__init__.py b/worlds/alttp/__init__.py index 5ef5d332..b7bdb348 100644 --- a/worlds/alttp/__init__.py +++ b/worlds/alttp/__init__.py @@ -212,7 +212,7 @@ class ALTTPWorld(World): attempts = 5 world = self.world player = self.player - all_state = world.get_all_state(keys=True) + all_state = world.get_all_state() crystals = [self.create_item(name) for name in ['Red Pendant', 'Blue Pendant', 'Green Pendant', 'Crystal 1', 'Crystal 2', 'Crystal 3', 'Crystal 4', 'Crystal 7', 'Crystal 5', 'Crystal 6']] crystal_locations = [world.get_location('Turtle Rock - Prize', player), world.get_location('Eastern Palace - Prize', player),