Skip to content

Commit

Permalink
Register indirect conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
TRPG0 committed Jun 16, 2024
1 parent 9eeea7d commit 2d0bcc8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 7 additions & 4 deletions worlds/blasphemous/Rules.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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 = {
Expand Down Expand Up @@ -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])
Expand Down
6 changes: 4 additions & 2 deletions worlds/blasphemous/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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")

Expand Down

0 comments on commit 2d0bcc8

Please sign in to comment.