From 29e1c3dcf4f86245c97cd5b2381dca2131eadb8e Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Thu, 19 Jan 2023 09:17:16 -0600 Subject: [PATCH] LTTP: fix open pyramid for real this time (#1393) --- test/TestBase.py | 3 ++ worlds/alttp/Items.py | 2 +- worlds/alttp/Rules.py | 2 +- worlds/alttp/test/options/TestOpenPyramid.py | 37 ++++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 worlds/alttp/test/options/TestOpenPyramid.py diff --git a/test/TestBase.py b/test/TestBase.py index 8a17232b..5ffcb5ce 100644 --- a/test/TestBase.py +++ b/test/TestBase.py @@ -169,6 +169,9 @@ class WorldTestBase(unittest.TestCase): def can_reach_location(self, location: str) -> bool: return self.multiworld.state.can_reach(location, "Location", 1) + def can_reach_entrance(self, entrance: str) -> bool: + return self.multiworld.state.can_reach(entrance, "Entrance", 1) + def count(self, item_name: str) -> int: return self.multiworld.state.count(item_name, 1) diff --git a/worlds/alttp/Items.py b/worlds/alttp/Items.py index 3663db5c..caa916ca 100644 --- a/worlds/alttp/Items.py +++ b/worlds/alttp/Items.py @@ -20,7 +20,7 @@ def GetBeemizerItem(world, player: int, item): # should be replaced with direct world.create_item(item) call in the future -def ItemFactory(items, player: int): +def ItemFactory(items: typing.Union[str, typing.Iterable[str]], player: int): from worlds.alttp import ALTTPWorld world = ALTTPWorld(None, player) ret = [] diff --git a/worlds/alttp/Rules.py b/worlds/alttp/Rules.py index e9f45c4c..2cee568e 100644 --- a/worlds/alttp/Rules.py +++ b/worlds/alttp/Rules.py @@ -526,7 +526,7 @@ def default_rules(world, player): set_rule(world.get_entrance('Floating Island Mirror Spot', player), lambda state: state.has('Magic Mirror', player)) set_rule(world.get_entrance('Turtle Rock', player), lambda state: state.has('Moon Pearl', player) and state.has_sword(player) and state.has_turtle_rock_medallion(player) and state.can_reach('Turtle Rock (Top)', 'Region', player)) # sword required to cast magic (!) - set_rule(world.get_entrance('Pyramid Hole', player), lambda state: state.has('Beat Agahnim 2', player) or world.open_pyramid[player]) + set_rule(world.get_entrance('Pyramid Hole', player), lambda state: state.has('Beat Agahnim 2', player) or world.open_pyramid[player].to_bool(world, player)) if world.swordless[player]: swordless_rules(world, player) diff --git a/worlds/alttp/test/options/TestOpenPyramid.py b/worlds/alttp/test/options/TestOpenPyramid.py new file mode 100644 index 00000000..c66eb2ee --- /dev/null +++ b/worlds/alttp/test/options/TestOpenPyramid.py @@ -0,0 +1,37 @@ +from test.TestBase import WorldTestBase +from ...Items import ItemFactory + + +class PyramidTestBase(WorldTestBase): + game = "A Link to the Past" + + +class OpenPyramidTest(PyramidTestBase): + options = { + "open_pyramid": "open" + } + + def testAccess(self): + self.assertFalse(self.can_reach_entrance("Pyramid Hole")) + self.collect_by_name(["Hammer", "Progressive Glove", "Moon Pearl"]) + self.assertTrue(self.can_reach_entrance("Pyramid Hole")) + + +class GoalPyramidTest(PyramidTestBase): + options = { + "open_pyramid": "goal" + } + + def testCrystalsGoalAccess(self): + self.multiworld.goal[1] = "crystals" + self.assertFalse(self.can_reach_entrance("Pyramid Hole")) + self.collect_by_name(["Hammer", "Progressive Glove", "Moon Pearl"]) + self.assertTrue(self.can_reach_entrance("Pyramid Hole")) + + def testGanonGoalAccess(self): + self.assertFalse(self.can_reach_entrance("Pyramid Hole")) + self.collect_by_name(["Hammer", "Progressive Glove", "Moon Pearl"]) + self.assertFalse(self.can_reach_entrance("Pyramid Hole")) + self.multiworld.state.collect(ItemFactory("Beat Agahnim 2", 1)) + self.assertTrue(self.can_reach_entrance("Pyramid Hole")) +