diff options
Diffstat (limited to 'apworld/player_logic.py')
| -rw-r--r-- | apworld/player_logic.py | 410 |
1 files changed, 204 insertions, 206 deletions
| diff --git a/apworld/player_logic.py b/apworld/player_logic.py index 4aa481d..2c3e08b 100644 --- a/apworld/player_logic.py +++ b/apworld/player_logic.py | |||
| @@ -1,10 +1,12 @@ | |||
| 1 | from enum import IntEnum, auto | 1 | from enum import IntEnum, auto |
| 2 | 2 | ||
| 3 | from Options import OptionError | ||
| 3 | from .generated import data_pb2 as data_pb2 | 4 | from .generated import data_pb2 as data_pb2 |
| 4 | from .items import SYMBOL_ITEMS | 5 | from .items import SYMBOL_ITEMS |
| 5 | from typing import TYPE_CHECKING, NamedTuple | 6 | from typing import TYPE_CHECKING, NamedTuple |
| 6 | 7 | ||
| 7 | from .options import VictoryCondition, ShuffleLetters, CyanDoorBehavior | 8 | from .options import ShuffleLetters, CyanDoorBehavior, VictoryCondition, FastTravelAccess |
| 9 | from .rules import AccessRequirements | ||
| 8 | 10 | ||
| 9 | if TYPE_CHECKING: | 11 | if TYPE_CHECKING: |
| 10 | from . import Lingo2World | 12 | from . import Lingo2World |
| @@ -20,177 +22,10 @@ def calculate_letter_histogram(solution: str) -> dict[str, int]: | |||
| 20 | return histogram | 22 | return histogram |
| 21 | 23 | ||
| 22 | 24 | ||
| 23 | class AccessRequirements: | ||
| 24 | items: set[str] | ||
| 25 | progressives: dict[str, int] | ||
| 26 | rooms: set[str] | ||
| 27 | letters: dict[str, int] | ||
| 28 | cyans: bool | ||
| 29 | |||
| 30 | # This is an AND of ORs. | ||
| 31 | or_logic: list[list["AccessRequirements"]] | ||
| 32 | |||
| 33 | # When complete_at is set, at least that many of the requirements in possibilities must be accessible. This should | ||
| 34 | # only be used for doors with complete_at > 1, as or_logic is more efficient for complete_at == 1. | ||
| 35 | complete_at: int | None | ||
| 36 | possibilities: list["AccessRequirements"] | ||
| 37 | |||
| 38 | def __init__(self): | ||
| 39 | self.items = set() | ||
| 40 | self.progressives = dict() | ||
| 41 | self.rooms = set() | ||
| 42 | self.letters = dict() | ||
| 43 | self.cyans = False | ||
| 44 | self.or_logic = list() | ||
| 45 | self.complete_at = None | ||
| 46 | self.possibilities = list() | ||
| 47 | |||
| 48 | def copy(self) -> "AccessRequirements": | ||
| 49 | reqs = AccessRequirements() | ||
| 50 | reqs.items = self.items.copy() | ||
| 51 | reqs.progressives = self.progressives.copy() | ||
| 52 | reqs.rooms = self.rooms.copy() | ||
| 53 | reqs.letters = self.letters.copy() | ||
| 54 | reqs.cyans = self.cyans | ||
| 55 | reqs.or_logic = [[other_req.copy() for other_req in disjunction] for disjunction in self.or_logic] | ||
| 56 | reqs.complete_at = self.complete_at | ||
| 57 | reqs.possibilities = self.possibilities.copy() | ||
| 58 | return reqs | ||
| 59 | |||
| 60 | def merge(self, other: "AccessRequirements"): | ||
| 61 | for item in other.items: | ||
| 62 | self.items.add(item) | ||
| 63 | |||
| 64 | for item, amount in other.progressives.items(): | ||
| 65 | self.progressives[item] = max(amount, self.progressives.get(item, 0)) | ||
| 66 | |||
| 67 | for room in other.rooms: | ||
| 68 | self.rooms.add(room) | ||
| 69 | |||
| 70 | for letter, level in other.letters.items(): | ||
| 71 | self.letters[letter] = max(self.letters.get(letter, 0), level) | ||
| 72 | |||
| 73 | self.cyans = self.cyans or other.cyans | ||
| 74 | |||
| 75 | for disjunction in other.or_logic: | ||
| 76 | self.or_logic.append(disjunction) | ||
| 77 | |||
| 78 | if other.complete_at is not None: | ||
| 79 | # Merging multiple requirements that use complete_at sucks, and is part of why we want to minimize use of | ||
| 80 | # it. If both requirements use complete_at, we will cheat by using the or_logic field, which supports | ||
| 81 | # conjunctions of requirements. | ||
| 82 | if self.complete_at is not None: | ||
| 83 | print("Merging requirements with complete_at > 1. This is messy and should be avoided!") | ||
| 84 | |||
| 85 | left_req = AccessRequirements() | ||
| 86 | left_req.complete_at = self.complete_at | ||
| 87 | left_req.possibilities = self.possibilities | ||
| 88 | self.or_logic.append([left_req]) | ||
| 89 | |||
| 90 | self.complete_at = None | ||
| 91 | self.possibilities = list() | ||
| 92 | |||
| 93 | right_req = AccessRequirements() | ||
| 94 | right_req.complete_at = other.complete_at | ||
| 95 | right_req.possibilities = other.possibilities | ||
| 96 | self.or_logic.append([right_req]) | ||
| 97 | else: | ||
| 98 | self.complete_at = other.complete_at | ||
| 99 | self.possibilities = other.possibilities | ||
| 100 | |||
| 101 | def is_empty(self) -> bool: | ||
| 102 | return (len(self.items) == 0 and len(self.progressives) == 0 and len(self.rooms) == 0 and len(self.letters) == 0 | ||
| 103 | and not self.cyans and len(self.or_logic) == 0 and self.complete_at is None) | ||
| 104 | |||
| 105 | def __eq__(self, other: "AccessRequirements"): | ||
| 106 | return (self.items == other.items and self.progressives == other.progressives and self.rooms == other.rooms and | ||
| 107 | self.letters == other.letters and self.cyans == other.cyans and self.or_logic == other.or_logic and | ||
| 108 | self.complete_at == other.complete_at and self.possibilities == other.possibilities) | ||
| 109 | |||
| 110 | def simplify(self): | ||
| 111 | resimplify = False | ||
| 112 | |||
| 113 | if len(self.or_logic) > 0: | ||
| 114 | old_or_logic = self.or_logic | ||
| 115 | |||
| 116 | def remove_redundant(sub_reqs: "AccessRequirements"): | ||
| 117 | new_reqs = sub_reqs.copy() | ||
| 118 | new_reqs.letters = {l: v for l, v in new_reqs.letters.items() if self.letters.get(l, 0) < v} | ||
| 119 | if new_reqs != sub_reqs: | ||
| 120 | return new_reqs | ||
| 121 | else: | ||
| 122 | return sub_reqs | ||
| 123 | |||
| 124 | self.or_logic = [] | ||
| 125 | for disjunction in old_or_logic: | ||
| 126 | new_disjunction = [] | ||
| 127 | for ssr in disjunction: | ||
| 128 | new_ssr = remove_redundant(ssr) | ||
| 129 | if not new_ssr.is_empty(): | ||
| 130 | new_disjunction.append(new_ssr) | ||
| 131 | else: | ||
| 132 | new_disjunction.clear() | ||
| 133 | break | ||
| 134 | if len(new_disjunction) == 1: | ||
| 135 | self.merge(new_disjunction[0]) | ||
| 136 | resimplify = True | ||
| 137 | elif len(new_disjunction) > 1: | ||
| 138 | if all(cjr == new_disjunction[0] for cjr in new_disjunction): | ||
| 139 | self.merge(new_disjunction[0]) | ||
| 140 | resimplify = True | ||
| 141 | else: | ||
| 142 | self.or_logic.append(new_disjunction) | ||
| 143 | |||
| 144 | if resimplify: | ||
| 145 | self.simplify() | ||
| 146 | |||
| 147 | def get_referenced_rooms(self): | ||
| 148 | result = set(self.rooms) | ||
| 149 | |||
| 150 | for disjunction in self.or_logic: | ||
| 151 | for sub_req in disjunction: | ||
| 152 | result = result.union(sub_req.get_referenced_rooms()) | ||
| 153 | |||
| 154 | for sub_req in self.possibilities: | ||
| 155 | result = result.union(sub_req.get_referenced_rooms()) | ||
| 156 | |||
| 157 | return result | ||
| 158 | |||
| 159 | def remove_room(self, room: str): | ||
| 160 | if room in self.rooms: | ||
| 161 | self.rooms.remove(room) | ||
| 162 | |||
| 163 | for disjunction in self.or_logic: | ||
| 164 | for sub_req in disjunction: | ||
| 165 | sub_req.remove_room(room) | ||
| 166 | |||
| 167 | for sub_req in self.possibilities: | ||
| 168 | sub_req.remove_room(room) | ||
| 169 | |||
| 170 | def __repr__(self): | ||
| 171 | parts = [] | ||
| 172 | if len(self.items) > 0: | ||
| 173 | parts.append(f"items={self.items}") | ||
| 174 | if len(self.progressives) > 0: | ||
| 175 | parts.append(f"progressives={self.progressives}") | ||
| 176 | if len(self.rooms) > 0: | ||
| 177 | parts.append(f"rooms={self.rooms}") | ||
| 178 | if len(self.letters) > 0: | ||
| 179 | parts.append(f"letters={self.letters}") | ||
| 180 | if self.cyans: | ||
| 181 | parts.append(f"cyans=True") | ||
| 182 | if len(self.or_logic) > 0: | ||
| 183 | parts.append(f"or_logic={self.or_logic}") | ||
| 184 | if self.complete_at is not None: | ||
| 185 | parts.append(f"complete_at={self.complete_at}") | ||
| 186 | if len(self.possibilities) > 0: | ||
| 187 | parts.append(f"possibilities={self.possibilities}") | ||
| 188 | return "AccessRequirements(" + ", ".join(parts) + ")" | ||
| 189 | |||
| 190 | |||
| 191 | class PlayerLocation(NamedTuple): | 25 | class PlayerLocation(NamedTuple): |
| 192 | code: int | None | 26 | code: int | None |
| 193 | reqs: AccessRequirements | 27 | reqs: AccessRequirements |
| 28 | is_letter: bool = False | ||
| 194 | 29 | ||
| 195 | 30 | ||
| 196 | class LetterBehavior(IntEnum): | 31 | class LetterBehavior(IntEnum): |
| @@ -202,6 +37,10 @@ class LetterBehavior(IntEnum): | |||
| 202 | class Lingo2PlayerLogic: | 37 | class Lingo2PlayerLogic: |
| 203 | world: "Lingo2World" | 38 | world: "Lingo2World" |
| 204 | 39 | ||
| 40 | shuffled_maps: set[int] | ||
| 41 | shuffled_rooms: set[int] | ||
| 42 | shuffled_doors: set[int] | ||
| 43 | |||
| 205 | locations_by_room: dict[int, list[PlayerLocation]] | 44 | locations_by_room: dict[int, list[PlayerLocation]] |
| 206 | event_loc_item_by_room: dict[int, dict[str, str]] | 45 | event_loc_item_by_room: dict[int, dict[str, str]] |
| 207 | 46 | ||
| @@ -212,11 +51,17 @@ class Lingo2PlayerLogic: | |||
| 212 | door_reqs: dict[int, AccessRequirements] | 51 | door_reqs: dict[int, AccessRequirements] |
| 213 | 52 | ||
| 214 | real_items: list[str] | 53 | real_items: list[str] |
| 54 | starting_items: list[str] | ||
| 215 | 55 | ||
| 216 | double_letter_amount: dict[str, int] | 56 | double_letter_amount: dict[str, int] |
| 57 | goal_room_id: int | ||
| 58 | rte_mapping: list[int] | ||
| 59 | custom_mint_ending: str | None | ||
| 217 | 60 | ||
| 218 | def __init__(self, world: "Lingo2World"): | 61 | def __init__(self, world: "Lingo2World"): |
| 219 | self.world = world | 62 | self.world = world |
| 63 | self.shuffled_rooms = set() | ||
| 64 | self.shuffled_doors = set() | ||
| 220 | self.locations_by_room = {} | 65 | self.locations_by_room = {} |
| 221 | self.event_loc_item_by_room = {} | 66 | self.event_loc_item_by_room = {} |
| 222 | self.item_by_door = {} | 67 | self.item_by_door = {} |
| @@ -224,35 +69,141 @@ class Lingo2PlayerLogic: | |||
| 224 | self.proxy_reqs = dict() | 69 | self.proxy_reqs = dict() |
| 225 | self.door_reqs = dict() | 70 | self.door_reqs = dict() |
| 226 | self.real_items = list() | 71 | self.real_items = list() |
| 72 | self.starting_items = list() | ||
| 227 | self.double_letter_amount = dict() | 73 | self.double_letter_amount = dict() |
| 74 | self.custom_mint_ending = None | ||
| 75 | |||
| 76 | def should_shuffle_map(game_map) -> bool | set[int]: | ||
| 77 | if world.options.daedalus_only: | ||
| 78 | return game_map.daedalus_only_mode == data_pb2.DaedalusOnlyMode.DAED_ONLY_ALLOW | ||
| 79 | |||
| 80 | if game_map.type == data_pb2.MapType.NORMAL_MAP: | ||
| 81 | return True | ||
| 82 | elif game_map.type == data_pb2.MapType.ICARUS: | ||
| 83 | return bool(world.options.enable_icarus) | ||
| 84 | elif game_map.type == data_pb2.MapType.GIFT_MAP: | ||
| 85 | if game_map.name == "the_advanced": | ||
| 86 | return "The Advanced" in world.options.enable_gift_maps.value | ||
| 87 | elif game_map.name == "the_charismatic": | ||
| 88 | return "The Charismatic" in world.options.enable_gift_maps.value | ||
| 89 | elif game_map.name == "the_crystalline": | ||
| 90 | return "The Crystalline" in world.options.enable_gift_maps.value | ||
| 91 | elif game_map.name == "the_fuzzy": | ||
| 92 | return "The Fuzzy" in world.options.enable_gift_maps.value | ||
| 93 | elif game_map.name == "the_stellar": | ||
| 94 | return "The Stellar" in world.options.enable_gift_maps.value | ||
| 95 | |||
| 96 | return False | ||
| 97 | |||
| 98 | self.shuffled_maps = set(game_map.id for game_map in world.static_logic.objects.maps | ||
| 99 | if should_shuffle_map(game_map)) | ||
| 100 | |||
| 101 | if world.options.daedalus_only: | ||
| 102 | if world.options.victory_condition not in [VictoryCondition.option_orange_ending, | ||
| 103 | VictoryCondition.option_gold_ending]: | ||
| 104 | raise OptionError(f"When Daedalus Only mode is enabled, the victory condition must be Orange Ending or " | ||
| 105 | f"Gold Ending (Player {world.player}).") | ||
| 106 | |||
| 107 | if not world.options.shuffle_worldports: | ||
| 108 | raise OptionError(f"When Daedalus Only mode is enabled, worldport shuffle must also be enabled (Player " | ||
| 109 | f"{world.player}).") | ||
| 110 | |||
| 111 | if world.options.shuffle_letters != ShuffleLetters.option_unlocked: | ||
| 112 | raise OptionError(f"When Daedalus Only mode is enabled, letter shuffle must be set to Unlocked (Player " | ||
| 113 | f"{world.player}).") | ||
| 114 | |||
| 115 | if world.options.cyan_door_behavior == CyanDoorBehavior.option_collect_h2: | ||
| 116 | raise OptionError(f"When Daedalus Only mode is enabled, Cyan Door Behavior cannot be set to Collect H2 " | ||
| 117 | f"(Player {world.player}).") | ||
| 118 | |||
| 119 | if not world.options.shuffle_control_center_colors: | ||
| 120 | raise OptionError(f"When Daedalus Only mode is enabled, control center color shuffle must be enabled " | ||
| 121 | f"(Player {world.player}).") | ||
| 122 | |||
| 123 | if world.options.shuffle_symbols and not world.options.keyholder_sanity: | ||
| 124 | raise OptionError(f"When Daedalus Only mode is enabled and symbols are shuffled, keyholdersanity must " | ||
| 125 | f"also be enabled (Player {world.player}).") | ||
| 126 | |||
| 127 | for game_map in world.static_logic.objects.maps: | ||
| 128 | if game_map.daedalus_only_mode == data_pb2.DaedalusOnlyMode.DAED_ONLY_PARTIAL: | ||
| 129 | self.shuffled_rooms.update(set(room.id for room in world.static_logic.objects.rooms | ||
| 130 | if room.map_id == game_map.id and room.daedalus_only_allow)) | ||
| 131 | self.shuffled_doors.update(set(door.id for door in world.static_logic.objects.doors | ||
| 132 | if door.map_id == game_map.id and door.daedalus_only_allow)) | ||
| 133 | |||
| 134 | if (world.options.restrict_letter_placements | ||
| 135 | and world.options.shuffle_letters == ShuffleLetters.option_progressive | ||
| 136 | and (world.options.shuffle_doors or world.options.shuffle_symbols)): | ||
| 137 | raise OptionError(f"When Restrict Letter Placements is enabled and Shuffle Letters is set to Progressive, " | ||
| 138 | f"both Shuffle Doors and Shuffle Symbols must be disabled (Player {world.player}).") | ||
| 139 | |||
| 140 | if world.options.custom_mint_ending.value != "": | ||
| 141 | self.custom_mint_ending = ''.join(filter(str.isalpha, world.options.custom_mint_ending.value)).lower() | ||
| 142 | |||
| 143 | if len(self.custom_mint_ending) > 52: | ||
| 144 | raise OptionError(f"Custom Mint Ending should not be greater than 52 letters (Player {world.player}).") | ||
| 145 | |||
| 146 | maximum_masteries = 13 + len(world.options.enable_gift_maps.value) | ||
| 147 | if world.options.enable_icarus: | ||
| 148 | maximum_masteries += 1 | ||
| 149 | |||
| 150 | if world.options.masteries_requirement > maximum_masteries: | ||
| 151 | world.options.masteries_requirement.value = maximum_masteries | ||
| 152 | |||
| 153 | if "The Fuzzy" in world.options.enable_gift_maps.value: | ||
| 154 | self.real_items.append("Numbers") | ||
| 155 | |||
| 156 | if world.options.shuffle_fast_travel: | ||
| 157 | travelable_maps = [map_id for map_id in self.shuffled_maps | ||
| 158 | if world.static_logic.objects.maps[map_id].HasField("rte_room")] | ||
| 159 | self.rte_mapping = world.random.sample(travelable_maps, 4) | ||
| 160 | else: | ||
| 161 | canonical_rtes = ["the_plaza", "the_gallery", "daedalus", "control_center"] | ||
| 162 | self.rte_mapping = [world.static_logic.map_id_by_name[map_name] for map_name in canonical_rtes | ||
| 163 | if world.static_logic.map_id_by_name[map_name] in self.shuffled_maps] | ||
| 164 | |||
| 165 | if world.options.fast_travel_access == FastTravelAccess.option_items: | ||
| 166 | for rte_map in self.rte_mapping: | ||
| 167 | self.real_items.append(world.static_logic.get_map_rte_item_name(rte_map)) | ||
| 228 | 168 | ||
| 229 | if self.world.options.shuffle_doors: | 169 | if self.world.options.shuffle_doors: |
| 230 | for progressive in world.static_logic.objects.progressives: | 170 | for progressive in world.static_logic.objects.progressives: |
| 231 | for i in range(0, len(progressive.doors)): | 171 | for i in range(0, len(progressive.doors)): |
| 172 | door = world.static_logic.objects.doors[progressive.doors[i]] | ||
| 173 | if not self.should_shuffle_door(door.id): | ||
| 174 | continue | ||
| 175 | |||
| 232 | self.item_by_door[progressive.doors[i]] = (progressive.name, i + 1) | 176 | self.item_by_door[progressive.doors[i]] = (progressive.name, i + 1) |
| 233 | self.real_items.append(progressive.name) | 177 | self.real_items.append(progressive.name) |
| 234 | 178 | ||
| 235 | for door_group in world.static_logic.objects.door_groups: | 179 | for door_group in world.static_logic.objects.door_groups: |
| 236 | if door_group.type == data_pb2.DoorGroupType.CONNECTOR: | 180 | if door_group.type == data_pb2.DoorGroupType.CONNECTOR: |
| 237 | if not self.world.options.shuffle_doors: | 181 | if not self.world.options.shuffle_doors or self.world.options.shuffle_worldports: |
| 238 | continue | 182 | continue |
| 239 | elif door_group.type == data_pb2.DoorGroupType.COLOR_CONNECTOR: | 183 | elif door_group.type == data_pb2.DoorGroupType.COLOR_CONNECTOR: |
| 240 | if not self.world.options.shuffle_control_center_colors: | 184 | if not self.world.options.shuffle_control_center_colors or self.world.options.shuffle_worldports: |
| 241 | continue | 185 | continue |
| 242 | elif door_group.type == data_pb2.DoorGroupType.SHUFFLE_GROUP: | 186 | elif door_group.type == data_pb2.DoorGroupType.SHUFFLE_GROUP: |
| 243 | if not self.world.options.shuffle_doors: | 187 | if (not self.world.options.shuffle_doors and |
| 188 | not (door_group.daedalus_only_always_item and self.world.options.daedalus_only)): | ||
| 244 | continue | 189 | continue |
| 245 | else: | 190 | else: |
| 246 | continue | 191 | continue |
| 247 | 192 | ||
| 248 | for door in door_group.doors: | 193 | shuffleable_doors = [door_id for door_id in door_group.doors if self.should_shuffle_door(door_id)] |
| 249 | self.item_by_door[door] = (door_group.name, 1) | ||
| 250 | 194 | ||
| 251 | self.real_items.append(door_group.name) | 195 | if len(shuffleable_doors) > 0: |
| 196 | for door in shuffleable_doors: | ||
| 197 | self.item_by_door[door] = (door_group.name, 1) | ||
| 198 | |||
| 199 | self.real_items.append(door_group.name) | ||
| 252 | 200 | ||
| 253 | # We iterate through the doors in two parts because it is essential that we determine which doors are shuffled | 201 | # We iterate through the doors in two parts because it is essential that we determine which doors are shuffled |
| 254 | # before we calculate any access requirements. | 202 | # before we calculate any access requirements. |
| 255 | for door in world.static_logic.objects.doors: | 203 | for door in world.static_logic.objects.doors: |
| 204 | if not self.should_shuffle_door(door.id): | ||
| 205 | continue | ||
| 206 | |||
| 256 | if door.type in [data_pb2.DoorType.EVENT, data_pb2.DoorType.LOCATION_ONLY, data_pb2.DoorType.GRAVESTONE]: | 207 | if door.type in [data_pb2.DoorType.EVENT, data_pb2.DoorType.LOCATION_ONLY, data_pb2.DoorType.GRAVESTONE]: |
| 257 | continue | 208 | continue |
| 258 | 209 | ||
| @@ -260,7 +211,8 @@ class Lingo2PlayerLogic: | |||
| 260 | continue | 211 | continue |
| 261 | 212 | ||
| 262 | if (door.type in [data_pb2.DoorType.STANDARD, data_pb2.DoorType.ITEM_ONLY] and | 213 | if (door.type in [data_pb2.DoorType.STANDARD, data_pb2.DoorType.ITEM_ONLY] and |
| 263 | not self.world.options.shuffle_doors): | 214 | not self.world.options.shuffle_doors and |
| 215 | not (door.daedalus_only_always_item and self.world.options.daedalus_only)): | ||
| 264 | continue | 216 | continue |
| 265 | 217 | ||
| 266 | if (door.type == data_pb2.DoorType.CONTROL_CENTER_COLOR and | 218 | if (door.type == data_pb2.DoorType.CONTROL_CENTER_COLOR and |
| @@ -281,29 +233,41 @@ class Lingo2PlayerLogic: | |||
| 281 | if door_group.type != data_pb2.DoorGroupType.CYAN_DOORS: | 233 | if door_group.type != data_pb2.DoorGroupType.CYAN_DOORS: |
| 282 | continue | 234 | continue |
| 283 | 235 | ||
| 284 | for door in door_group.doors: | 236 | shuffleable_doors = [door_id for door_id in door_group.doors |
| 285 | if not door in self.item_by_door: | 237 | if self.should_shuffle_door(door_id) and door_id not in self.item_by_door] |
| 238 | |||
| 239 | if len(shuffleable_doors) > 0: | ||
| 240 | for door in shuffleable_doors: | ||
| 286 | self.item_by_door[door] = (door_group.name, 1) | 241 | self.item_by_door[door] = (door_group.name, 1) |
| 287 | 242 | ||
| 288 | self.real_items.append(door_group.name) | 243 | self.real_items.append(door_group.name) |
| 289 | 244 | ||
| 290 | for door in world.static_logic.objects.doors: | 245 | for door in world.static_logic.objects.doors: |
| 246 | if not self.should_shuffle_door(door.id): | ||
| 247 | continue | ||
| 248 | |||
| 291 | if door.type in [data_pb2.DoorType.STANDARD, data_pb2.DoorType.LOCATION_ONLY, data_pb2.DoorType.GRAVESTONE]: | 249 | if door.type in [data_pb2.DoorType.STANDARD, data_pb2.DoorType.LOCATION_ONLY, data_pb2.DoorType.GRAVESTONE]: |
| 292 | self.locations_by_room.setdefault(door.room_id, []).append(PlayerLocation(door.ap_id, | 250 | self.locations_by_room.setdefault(door.room_id, []).append(PlayerLocation(door.ap_id, |
| 293 | self.get_door_reqs(door.id))) | 251 | self.get_door_reqs(door.id))) |
| 294 | 252 | ||
| 295 | for letter in world.static_logic.objects.letters: | 253 | for letter in world.static_logic.objects.letters: |
| 296 | self.locations_by_room.setdefault(letter.room_id, []).append(PlayerLocation(letter.ap_id, | 254 | if not self.should_shuffle_room(letter.room_id): |
| 297 | AccessRequirements())) | 255 | continue |
| 256 | |||
| 298 | behavior = self.get_letter_behavior(letter.key, letter.level2) | 257 | behavior = self.get_letter_behavior(letter.key, letter.level2) |
| 299 | if behavior == LetterBehavior.VANILLA: | ||
| 300 | letter_name = f"{letter.key.upper()}{'2' if letter.level2 else '1'}" | ||
| 301 | event_name = f"{letter_name} (Collected)" | ||
| 302 | self.event_loc_item_by_room.setdefault(letter.room_id, {})[event_name] = letter.key.upper() | ||
| 303 | 258 | ||
| 304 | if letter.level2: | 259 | self.locations_by_room.setdefault(letter.room_id, []).append( |
| 305 | event_name = f"{letter_name} (Double Collected)" | 260 | PlayerLocation(letter.ap_id, AccessRequirements(), behavior == LetterBehavior.ITEM)) |
| 261 | |||
| 262 | if behavior == LetterBehavior.VANILLA: | ||
| 263 | if not world.for_tracker: | ||
| 264 | letter_name = f"{letter.key.upper()}{'2' if letter.level2 else '1'}" | ||
| 265 | event_name = f"{letter_name} (Collected)" | ||
| 306 | self.event_loc_item_by_room.setdefault(letter.room_id, {})[event_name] = letter.key.upper() | 266 | self.event_loc_item_by_room.setdefault(letter.room_id, {})[event_name] = letter.key.upper() |
| 267 | |||
| 268 | if letter.level2: | ||
| 269 | event_name = f"{letter_name} (Double Collected)" | ||
| 270 | self.event_loc_item_by_room.setdefault(letter.room_id, {})[event_name] = letter.key.upper() | ||
| 307 | elif behavior == LetterBehavior.ITEM: | 271 | elif behavior == LetterBehavior.ITEM: |
| 308 | self.real_items.append(letter.key.upper()) | 272 | self.real_items.append(letter.key.upper()) |
| 309 | 273 | ||
| @@ -311,30 +275,42 @@ class Lingo2PlayerLogic: | |||
| 311 | self.double_letter_amount[letter.key.upper()] = self.double_letter_amount.get(letter.key.upper(), 0) + 1 | 275 | self.double_letter_amount[letter.key.upper()] = self.double_letter_amount.get(letter.key.upper(), 0) + 1 |
| 312 | 276 | ||
| 313 | for mastery in world.static_logic.objects.masteries: | 277 | for mastery in world.static_logic.objects.masteries: |
| 278 | if not self.should_shuffle_room(mastery.room_id): | ||
| 279 | continue | ||
| 280 | |||
| 314 | self.locations_by_room.setdefault(mastery.room_id, []).append(PlayerLocation(mastery.ap_id, | 281 | self.locations_by_room.setdefault(mastery.room_id, []).append(PlayerLocation(mastery.ap_id, |
| 315 | AccessRequirements())) | 282 | AccessRequirements())) |
| 316 | 283 | ||
| 284 | if world.options.masteries_requirement > 0: | ||
| 285 | event_name = f"{world.static_logic.get_room_object_map_name(mastery)} - Mastery (Collected)" | ||
| 286 | self.event_loc_item_by_room.setdefault(mastery.room_id, {})[event_name] = "Mastery" | ||
| 287 | |||
| 317 | for ending in world.static_logic.objects.endings: | 288 | for ending in world.static_logic.objects.endings: |
| 318 | # Don't ever create a location for White Ending. Don't even make an event for it if it's not the victory | 289 | if not self.should_shuffle_room(ending.room_id): |
| 319 | # condition, since it is necessarily going to be in the postgame. | 290 | continue |
| 320 | if ending.name == "WHITE": | 291 | |
| 321 | if self.world.options.victory_condition != VictoryCondition.option_white_ending: | 292 | # Don't create a location for your selected ending. Also don't create a location for White Ending if it's |
| 322 | continue | 293 | # necessarily in the postgame, i.e. it requires all 12 other endings. |
| 323 | else: | 294 | if world.options.victory_condition.current_key.removesuffix("_ending").upper() != ending.name\ |
| 295 | and (ending.name != "WHITE" or world.options.endings_requirement < 12): | ||
| 324 | self.locations_by_room.setdefault(ending.room_id, []).append(PlayerLocation(ending.ap_id, | 296 | self.locations_by_room.setdefault(ending.room_id, []).append(PlayerLocation(ending.ap_id, |
| 325 | AccessRequirements())) | 297 | AccessRequirements())) |
| 326 | 298 | ||
| 327 | event_name = f"{ending.name.capitalize()} Ending (Achieved)" | ||
| 328 | item_name = event_name | ||
| 329 | |||
| 330 | if world.options.victory_condition.current_key.removesuffix("_ending").upper() == ending.name: | 299 | if world.options.victory_condition.current_key.removesuffix("_ending").upper() == ending.name: |
| 331 | item_name = "Victory" | 300 | event_name = f"{ending.name.capitalize()} Ending (Goal)" |
| 301 | self.event_loc_item_by_room.setdefault(ending.room_id, {})[event_name] = "Victory" | ||
| 302 | self.goal_room_id = ending.room_id | ||
| 332 | 303 | ||
| 333 | self.event_loc_item_by_room.setdefault(ending.room_id, {})[event_name] = item_name | 304 | if ending.name != "WHITE": |
| 305 | event_name = f"{ending.name.capitalize()} Ending (Achieved)" | ||
| 306 | self.event_loc_item_by_room.setdefault(ending.room_id, {})[event_name] = "Ending" | ||
| 334 | 307 | ||
| 335 | if self.world.options.keyholder_sanity: | 308 | if self.world.options.keyholder_sanity: |
| 336 | for keyholder in world.static_logic.objects.keyholders: | 309 | for keyholder in world.static_logic.objects.keyholders: |
| 337 | if keyholder.HasField("key"): | 310 | if keyholder.HasField("key"): |
| 311 | if not self.should_shuffle_room(keyholder.room_id): | ||
| 312 | continue | ||
| 313 | |||
| 338 | reqs = AccessRequirements() | 314 | reqs = AccessRequirements() |
| 339 | 315 | ||
| 340 | if self.get_letter_behavior(keyholder.key, False) != LetterBehavior.UNLOCKED: | 316 | if self.get_letter_behavior(keyholder.key, False) != LetterBehavior.UNLOCKED: |
| @@ -345,7 +321,10 @@ class Lingo2PlayerLogic: | |||
| 345 | 321 | ||
| 346 | if self.world.options.shuffle_symbols: | 322 | if self.world.options.shuffle_symbols: |
| 347 | for symbol_name in SYMBOL_ITEMS.values(): | 323 | for symbol_name in SYMBOL_ITEMS.values(): |
| 348 | self.real_items.append(symbol_name) | 324 | if self.world.options.daedalus_only and symbol_name == "Sun Symbol": |
| 325 | self.starting_items.append(symbol_name) | ||
| 326 | else: | ||
| 327 | self.real_items.append(symbol_name) | ||
| 349 | 328 | ||
| 350 | def get_panel_reqs(self, panel_id: int, answer: str | None) -> AccessRequirements: | 329 | def get_panel_reqs(self, panel_id: int, answer: str | None) -> AccessRequirements: |
| 351 | if answer is None: | 330 | if answer is None: |
| @@ -442,7 +421,6 @@ class Lingo2PlayerLogic: | |||
| 442 | reqs.possibilities.append(panel_reqs) | 421 | reqs.possibilities.append(panel_reqs) |
| 443 | 422 | ||
| 444 | if door.HasField("control_center_color"): | 423 | if door.HasField("control_center_color"): |
| 445 | # TODO: Logic for ensuring two CC states aren't needed at once. | ||
| 446 | reqs.rooms.add("Control Center - Main Area") | 424 | reqs.rooms.add("Control Center - Main Area") |
| 447 | self.add_solution_reqs(reqs, door.control_center_color) | 425 | self.add_solution_reqs(reqs, door.control_center_color) |
| 448 | 426 | ||
| @@ -468,13 +446,12 @@ class Lingo2PlayerLogic: | |||
| 468 | for room in door.rooms: | 446 | for room in door.rooms: |
| 469 | reqs.rooms.add(self.world.static_logic.get_room_region_name(room)) | 447 | reqs.rooms.add(self.world.static_logic.get_room_region_name(room)) |
| 470 | 448 | ||
| 471 | for ending_id in door.endings: | 449 | if door.white_ending: |
| 472 | ending = self.world.static_logic.objects.endings[ending_id] | 450 | if self.world.options.endings_requirement > 0: |
| 451 | reqs.progressives["Ending"] = self.world.options.endings_requirement.value | ||
| 473 | 452 | ||
| 474 | if self.world.options.victory_condition.current_key.removesuffix("_ending").upper() == ending.name: | 453 | if self.world.options.masteries_requirement > 0: |
| 475 | reqs.items.add("Victory") | 454 | reqs.progressives["Mastery"] = self.world.options.masteries_requirement.value |
| 476 | else: | ||
| 477 | reqs.items.add(f"{ending.name.capitalize()} Ending (Achieved)") | ||
| 478 | 455 | ||
| 479 | for sub_door_id in door.doors: | 456 | for sub_door_id in door.doors: |
| 480 | sub_reqs = self.get_door_open_reqs(sub_door_id) | 457 | sub_reqs = self.get_door_open_reqs(sub_door_id) |
| @@ -536,3 +513,24 @@ class Lingo2PlayerLogic: | |||
| 536 | 513 | ||
| 537 | if needed > 0: | 514 | if needed > 0: |
| 538 | reqs.letters[l] = max(reqs.letters.get(l, 0), needed) | 515 | reqs.letters[l] = max(reqs.letters.get(l, 0), needed) |
| 516 | |||
| 517 | if any(l.isnumeric() for l in solution): | ||
| 518 | reqs.items.add("Numbers") | ||
| 519 | |||
| 520 | def should_shuffle_room(self, room_id: int) -> bool: | ||
| 521 | if room_id in self.shuffled_rooms: | ||
| 522 | return True | ||
| 523 | |||
| 524 | room = self.world.static_logic.objects.rooms[room_id] | ||
| 525 | game_map = self.world.static_logic.objects.maps[room.map_id] | ||
| 526 | |||
| 527 | return game_map.id in self.shuffled_maps | ||
| 528 | |||
| 529 | def should_shuffle_door(self, door_id: int) -> bool: | ||
| 530 | if door_id in self.shuffled_doors: | ||
| 531 | return True | ||
| 532 | |||
| 533 | door = self.world.static_logic.objects.doors[door_id] | ||
| 534 | game_map = self.world.static_logic.objects.maps[door.map_id] | ||
| 535 | |||
| 536 | return game_map.id in self.shuffled_maps | ||
