diff --git a/worlds/messenger/__init__.py b/worlds/messenger/__init__.py index 2382a46c..09911fd5 100644 --- a/worlds/messenger/__init__.py +++ b/worlds/messenger/__init__.py @@ -16,8 +16,8 @@ from .portals import PORTALS, add_closed_portal_reqs, disconnect_portals, shuffl from .regions import LEVELS, MEGA_SHARDS, LOCATIONS, REGION_CONNECTIONS from .rules import MessengerHardRules, MessengerOOBRules, MessengerRules from .shop import FIGURINES, PROG_SHOP_ITEMS, SHOP_ITEMS, USEFUL_SHOP_ITEMS, shuffle_shop_prices -from .subclasses import MessengerEntrance, MessengerItem, MessengerRegion, MessengerShopLocation -from .transitions import shuffle_transitions +from .subclasses import MessengerItem, MessengerRegion, MessengerShopLocation +from .transitions import disconnect_entrances, shuffle_transitions components.append( Component("The Messenger", component_type=Type.CLIENT, func=launch_game, game_name="The Messenger", supports_uri=True) @@ -266,6 +266,8 @@ class MessengerWorld(World): # MessengerOOBRules(self).set_messenger_rules() def connect_entrances(self) -> None: + if self.options.shuffle_transitions: + disconnect_entrances(self) add_closed_portal_reqs(self) # i need portal shuffle to happen after rules exist so i can validate it attempts = 5 diff --git a/worlds/messenger/portals.py b/worlds/messenger/portals.py index 70428589..c04fc696 100644 --- a/worlds/messenger/portals.py +++ b/worlds/messenger/portals.py @@ -292,12 +292,10 @@ def disconnect_portals(world: "MessengerWorld") -> None: def validate_portals(world: "MessengerWorld") -> bool: - if world.options.shuffle_transitions: - return True - new_state = CollectionState(world.multiworld) + new_state = CollectionState(world.multiworld, True) new_state.update_reachable_regions(world.player) reachable_locs = 0 - for loc in world.multiworld.get_locations(world.player): + for loc in world.get_locations(): reachable_locs += loc.can_reach(new_state) if reachable_locs > 5: return True diff --git a/worlds/messenger/subclasses.py b/worlds/messenger/subclasses.py index 0138a3f0..2e438fdb 100644 --- a/worlds/messenger/subclasses.py +++ b/worlds/messenger/subclasses.py @@ -10,25 +10,8 @@ if TYPE_CHECKING: from . import MessengerWorld -class MessengerEntrance(Entrance): - world: "MessengerWorld | None" = None - - def can_connect_to(self, other: Entrance, dead_end: bool, state: "ERPlacementState") -> bool: - can_connect = super().can_connect_to(other, dead_end, state) - world: MessengerWorld = getattr(self, "world", None) - if not world or world.reachable_locs or not can_connect: - return can_connect - empty_state = CollectionState(world.multiworld, True) - self.connected_region = other.connected_region - empty_state.update_reachable_regions(world.player) - world.reachable_locs = any(loc.can_reach(empty_state) and not loc.is_event for loc in world.get_locations()) - self.connected_region = None - return world.reachable_locs and (not state.coupled or self.name != other.name) - - class MessengerRegion(Region): parent: str | None - entrance_type = MessengerEntrance def __init__(self, name: str, world: "MessengerWorld", parent: str | None = None) -> None: super().__init__(name, world.player, world.multiworld) diff --git a/worlds/messenger/transitions.py b/worlds/messenger/transitions.py index 53cfd836..c0ae64c5 100644 --- a/worlds/messenger/transitions.py +++ b/worlds/messenger/transitions.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING -from BaseClasses import Region +from BaseClasses import Entrance, Region from entrance_rando import EntranceType, randomize_entrances from .connections import RANDOMIZED_CONNECTIONS, TRANSITIONS from .options import ShuffleTransitions, TransitionPlando @@ -9,6 +9,33 @@ if TYPE_CHECKING: from . import MessengerWorld +def disconnect_entrances(world: "MessengerWorld") -> None: + def disconnect_entrance() -> None: + child = entrance.connected_region.name + child_region = entrance.connected_region + child_region.entrances.remove(entrance) + entrance.connected_region = None + + er_type = EntranceType.ONE_WAY if child == "Glacial Peak - Left" else \ + EntranceType.TWO_WAY if child in RANDOMIZED_CONNECTIONS else EntranceType.ONE_WAY + if er_type == EntranceType.TWO_WAY: + mock_entrance = entrance.parent_region.create_er_target(entrance.name) + else: + mock_entrance = child_region.create_er_target(child) + + entrance.randomization_type = er_type + mock_entrance.randomization_type = er_type + + + for parent, child in RANDOMIZED_CONNECTIONS.items(): + if child == "Corrupted Future": + entrance = world.get_entrance("Artificer's Portal") + elif child == "Tower of Time - Left": + entrance = world.get_entrance("Artificer's Challenge") + else: + entrance = world.get_entrance(f"{parent} -> {child}") + disconnect_entrance() + def connect_plando(world: "MessengerWorld", plando_connections: TransitionPlando) -> None: def remove_dangling_exit(region: Region) -> None: # find the disconnected exit and remove references to it @@ -59,32 +86,6 @@ def connect_plando(world: "MessengerWorld", plando_connections: TransitionPlando def shuffle_transitions(world: "MessengerWorld") -> None: coupled = world.options.shuffle_transitions == ShuffleTransitions.option_coupled - def disconnect_entrance() -> None: - child_region.entrances.remove(entrance) - entrance.connected_region = None - - er_type = EntranceType.ONE_WAY if child == "Glacial Peak - Left" else \ - EntranceType.TWO_WAY if child in RANDOMIZED_CONNECTIONS else EntranceType.ONE_WAY - if er_type == EntranceType.TWO_WAY: - mock_entrance = parent_region.create_er_target(entrance.name) - else: - mock_entrance = child_region.create_er_target(child) - - entrance.randomization_type = er_type - mock_entrance.randomization_type = er_type - - for parent, child in RANDOMIZED_CONNECTIONS.items(): - if child == "Corrupted Future": - entrance = world.get_entrance("Artificer's Portal") - elif child == "Tower of Time - Left": - entrance = world.get_entrance("Artificer's Challenge") - else: - entrance = world.get_entrance(f"{parent} -> {child}") - parent_region = entrance.parent_region - child_region = entrance.connected_region - entrance.world = world - disconnect_entrance() - plando = world.options.plando_connections if plando: connect_plando(world, plando)