From d4b422840ae39f30e95a4b42ea33c1c98b8de406 Mon Sep 17 00:00:00 2001
From: Fabian Dill <fabian.dill@web.de>
Date: Sat, 10 Apr 2021 06:36:06 +0200
Subject: [PATCH] Fix dynamic world attributes not updating

---
 BaseClasses.py        | 26 ++++++++++++++------------
 worlds/alttp/Rom.py   |  2 +-
 worlds/alttp/Rules.py |  2 +-
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/BaseClasses.py b/BaseClasses.py
index 3f31a536..4d8e8db2 100644
--- a/BaseClasses.py
+++ b/BaseClasses.py
@@ -24,6 +24,12 @@ class MultiWorld():
     plando_connections: List[PlandoConnection]
     er_seeds: Dict[int, str]
 
+    class AttributeProxy():
+        def __init__(self, rule):
+            self.rule = rule
+        def __getitem__(self, player) -> bool:
+            return self.rule(player)
+
     def __init__(self, players: int):
         # TODO: move per-player settings into new classes per game-type instead of clumping it all together here
 
@@ -56,6 +62,11 @@ class MultiWorld():
         self.dynamic_regions = []
         self.dynamic_locations = []
         self.spoiler = Spoiler(self)
+        self.fix_trock_doors = self.AttributeProxy(lambda player: self.shuffle[player] != 'vanilla' or self.mode[player] == 'inverted')
+        self.fix_skullwoods_exit = self.AttributeProxy(lambda player: self.shuffle[player] not in ['vanilla', 'simple', 'restricted', 'dungeonssimple'])
+        self.fix_palaceofdarkness_exit = self.AttributeProxy(lambda player: self.shuffle[player] not in ['vanilla', 'simple', 'restricted', 'dungeonssimple'])
+        self.fix_trock_exit = self.AttributeProxy(lambda player: self.shuffle[player] not in ['vanilla', 'simple', 'restricted', 'dungeonssimple'])
+        self.NOTCURSED = self.AttributeProxy(lambda player: not self.CURSED[player])
 
         for player in range(1, players + 1):
             def set_player_attr(attr, val):
@@ -81,11 +92,6 @@ class MultiWorld():
             set_player_attr('powder_patch_required', False)
             set_player_attr('ganon_at_pyramid', True)
             set_player_attr('ganonstower_vanilla', True)
-            set_player_attr('sewer_light_cone', self.mode[player] == 'standard')
-            set_player_attr('fix_trock_doors', self.shuffle[player] != 'vanilla' or self.mode[player] == 'inverted')
-            set_player_attr('fix_skullwoods_exit', self.shuffle[player] not in ['vanilla', 'simple', 'restricted', 'dungeonssimple'])
-            set_player_attr('fix_palaceofdarkness_exit', self.shuffle[player] not in ['vanilla', 'simple', 'restricted', 'dungeonssimple'])
-            set_player_attr('fix_trock_exit', self.shuffle[player] not in ['vanilla', 'simple', 'restricted', 'dungeonssimple'])
             set_player_attr('can_access_trock_eyebridge', None)
             set_player_attr('can_access_trock_front', None)
             set_player_attr('can_access_trock_big_chest', None)
@@ -137,13 +143,9 @@ class MultiWorld():
             for hk_option in Options.hollow_knight_options:
                 set_player_attr(hk_option, False)
 
-        self.worlds = []
-        #for i in range(players):
-        #    self.worlds.append(worlds.alttp.ALTTPWorld({}, i))
-
-    @property
-    def NOTCURSED(self):  # not here to stay
-        return {player: not cursed for player, cursed in self.CURSED.items()}
+        # self.worlds = []
+        # for i in range(players):
+        #     self.worlds.append(worlds.alttp.ALTTPWorld({}, i))
 
     def secure(self):
         self.random = secrets.SystemRandom()
diff --git a/worlds/alttp/Rom.py b/worlds/alttp/Rom.py
index 0e94e132..6be9d711 100644
--- a/worlds/alttp/Rom.py
+++ b/worlds/alttp/Rom.py
@@ -879,7 +879,7 @@ def patch_rom(world, rom, player, team, enemized):
         rom.write_bytes(0x6D323, [0x00, 0x00, 0xe4, 0xff, 0x08, 0x0E])
 
     # set light cones
-    rom.write_byte(0x180038, 0x01 if world.sewer_light_cone[player] else 0x00)
+    rom.write_byte(0x180038, 0x01 if world.mode[player] == "standard" else 0x00)
     rom.write_byte(0x180039, 0x01 if world.light_world_light_cone else 0x00)
     rom.write_byte(0x18003A, 0x01 if world.dark_world_light_cone else 0x00)
 
diff --git a/worlds/alttp/Rules.py b/worlds/alttp/Rules.py
index 897083de..e195d229 100644
--- a/worlds/alttp/Rules.py
+++ b/worlds/alttp/Rules.py
@@ -781,7 +781,7 @@ def add_conditional_lamps(world, player):
     add_conditional_lamp('Eastern Palace - Boss', 'Eastern Palace', 'Location', True)
     add_conditional_lamp('Eastern Palace - Prize', 'Eastern Palace', 'Location', True)
 
-    if not world.sewer_light_cone[player]:
+    if not world.mode[player] == "standard":
         add_lamp_requirement(world, world.get_location('Sewers - Dark Cross', player), player)
         add_lamp_requirement(world, world.get_entrance('Sewers Back Door', player), player)
         add_lamp_requirement(world, world.get_entrance('Throne Room', player), player)