From 2d0bcc89636d79a07130b63867ddba16a0066f1f Mon Sep 17 00:00:00 2001 From: trevorleslie <80716066+TRPG0@users.noreply.github.com> Date: Sun, 16 Jun 2024 13:06:51 -0600 Subject: [PATCH] Register indirect conditions --- worlds/blasphemous/Rules.py | 11 +++++++---- worlds/blasphemous/__init__.py | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/worlds/blasphemous/Rules.py b/worlds/blasphemous/Rules.py index d97dda3357ad..d32088519da8 100644 --- a/worlds/blasphemous/Rules.py +++ b/worlds/blasphemous/Rules.py @@ -1,4 +1,4 @@ -from typing import Dict, Any, Callable, TYPE_CHECKING +from typing import Dict, List, Tuple, Any, Callable, TYPE_CHECKING from BaseClasses import CollectionState if TYPE_CHECKING: @@ -16,6 +16,7 @@ def __init__(self, world: "BlasphemousWorld") -> None: self.player = world.player self.world = world self.multiworld = world.multiworld + self.indirect_conditions: List[Tuple[str, str]] = [] # BrandenEK/Blasphemous.Randomizer/ItemRando/BlasphemousInventory.cs self.string_rules = { @@ -280,18 +281,20 @@ def __init__(self, world: "BlasphemousWorld") -> None: "canBeatLegionary": self.can_beat_legionary } - def is_region(self, string: str) -> bool: + def req_is_region(self, string: str) -> bool: if (string[0] == "D" and string[3] == "Z" and string[6] == "S")\ or (string[0] == "D" and string[3] == "B" and string[4] == "Z" and string[7] == "S"): return True return False - def load_rule(self, obj: Dict[str, Any]) -> Callable[[CollectionState], bool]: + def load_rule(self, obj_is_region: bool, name: str, obj: Dict[str, Any]) -> Callable[[CollectionState], bool]: clauses = [] for clause in obj["logic"]: reqs = [] for req in clause["item_requirements"]: - if self.is_region(req): + if self.req_is_region(req): + if obj_is_region: + self.indirect_conditions.append((req, f"{name} -> {obj['target']}")) reqs.append(lambda state, req=req: state.can_reach_region(req, self.player)) else: reqs.append(self.string_rules[req]) diff --git a/worlds/blasphemous/__init__.py b/worlds/blasphemous/__init__.py index 222175d2cc30..bc687d8e94b8 100644 --- a/worlds/blasphemous/__init__.py +++ b/worlds/blasphemous/__init__.py @@ -256,7 +256,7 @@ def create_regions(self) -> None: region = multiworld.get_region(r["name"], player) for e in r["exits"]: - region.add_exits({e["target"]}, {e["target"]: blas_logic.load_rule(e)}) + region.add_exits({e["target"]}, {e["target"]: blas_logic.load_rule(True, r["name"], e)}) for l in r["locations"]: if not self.options.boots_of_pleading and l == "RE401": @@ -281,8 +281,10 @@ def create_regions(self) -> None: if not self.options.purified_hand and l["name"] == "RE402": continue location = self.get_location(location_names[l["name"]]) - set_rule(location, blas_logic.load_rule(l)) + set_rule(location, blas_logic.load_rule(False, l["name"], l)) + for rname, ename in blas_logic.indirect_conditions: + self.multiworld.register_indirect_condition(self.get_region(rname), self.get_entrance(ename)) #from Utils import visualize_regions #visualize_regions(self.get_region("Menu"), "blasphemous_regions.puml")