diff options
Diffstat (limited to 'apworld/player_logic.py')
| -rw-r--r-- | apworld/player_logic.py | 144 |
1 files changed, 107 insertions, 37 deletions
| diff --git a/apworld/player_logic.py b/apworld/player_logic.py index 4aa481d..3ee8f38 100644 --- a/apworld/player_logic.py +++ b/apworld/player_logic.py | |||
| @@ -4,7 +4,7 @@ from .generated import data_pb2 as data_pb2 | |||
| 4 | from .items import SYMBOL_ITEMS | 4 | from .items import SYMBOL_ITEMS |
| 5 | from typing import TYPE_CHECKING, NamedTuple | 5 | from typing import TYPE_CHECKING, NamedTuple |
| 6 | 6 | ||
| 7 | from .options import VictoryCondition, ShuffleLetters, CyanDoorBehavior | 7 | from .options import ShuffleLetters, CyanDoorBehavior |
| 8 | 8 | ||
| 9 | if TYPE_CHECKING: | 9 | if TYPE_CHECKING: |
| 10 | from . import Lingo2World | 10 | from . import Lingo2World |
| @@ -73,7 +73,7 @@ class AccessRequirements: | |||
| 73 | self.cyans = self.cyans or other.cyans | 73 | self.cyans = self.cyans or other.cyans |
| 74 | 74 | ||
| 75 | for disjunction in other.or_logic: | 75 | for disjunction in other.or_logic: |
| 76 | self.or_logic.append(disjunction) | 76 | self.or_logic.append([sub_req.copy() for sub_req in disjunction]) |
| 77 | 77 | ||
| 78 | if other.complete_at is not None: | 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 | 79 | # Merging multiple requirements that use complete_at sucks, and is part of why we want to minimize use of |
| @@ -84,7 +84,7 @@ class AccessRequirements: | |||
| 84 | 84 | ||
| 85 | left_req = AccessRequirements() | 85 | left_req = AccessRequirements() |
| 86 | left_req.complete_at = self.complete_at | 86 | left_req.complete_at = self.complete_at |
| 87 | left_req.possibilities = self.possibilities | 87 | left_req.possibilities = [sub_req.copy() for sub_req in self.possibilities] |
| 88 | self.or_logic.append([left_req]) | 88 | self.or_logic.append([left_req]) |
| 89 | 89 | ||
| 90 | self.complete_at = None | 90 | self.complete_at = None |
| @@ -92,11 +92,11 @@ class AccessRequirements: | |||
| 92 | 92 | ||
| 93 | right_req = AccessRequirements() | 93 | right_req = AccessRequirements() |
| 94 | right_req.complete_at = other.complete_at | 94 | right_req.complete_at = other.complete_at |
| 95 | right_req.possibilities = other.possibilities | 95 | right_req.possibilities = [sub_req.copy() for sub_req in other.possibilities] |
| 96 | self.or_logic.append([right_req]) | 96 | self.or_logic.append([right_req]) |
| 97 | else: | 97 | else: |
| 98 | self.complete_at = other.complete_at | 98 | self.complete_at = other.complete_at |
| 99 | self.possibilities = other.possibilities | 99 | self.possibilities = [sub_req.copy() for sub_req in other.possibilities] |
| 100 | 100 | ||
| 101 | def is_empty(self) -> bool: | 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 | 102 | return (len(self.items) == 0 and len(self.progressives) == 0 and len(self.rooms) == 0 and len(self.letters) == 0 |
| @@ -202,6 +202,8 @@ class LetterBehavior(IntEnum): | |||
| 202 | class Lingo2PlayerLogic: | 202 | class Lingo2PlayerLogic: |
| 203 | world: "Lingo2World" | 203 | world: "Lingo2World" |
| 204 | 204 | ||
| 205 | shuffled_maps: set[int] | ||
| 206 | |||
| 205 | locations_by_room: dict[int, list[PlayerLocation]] | 207 | locations_by_room: dict[int, list[PlayerLocation]] |
| 206 | event_loc_item_by_room: dict[int, dict[str, str]] | 208 | event_loc_item_by_room: dict[int, dict[str, str]] |
| 207 | 209 | ||
| @@ -214,6 +216,7 @@ class Lingo2PlayerLogic: | |||
| 214 | real_items: list[str] | 216 | real_items: list[str] |
| 215 | 217 | ||
| 216 | double_letter_amount: dict[str, int] | 218 | double_letter_amount: dict[str, int] |
| 219 | goal_room_id: int | ||
| 217 | 220 | ||
| 218 | def __init__(self, world: "Lingo2World"): | 221 | def __init__(self, world: "Lingo2World"): |
| 219 | self.world = world | 222 | self.world = world |
| @@ -226,18 +229,54 @@ class Lingo2PlayerLogic: | |||
| 226 | self.real_items = list() | 229 | self.real_items = list() |
| 227 | self.double_letter_amount = dict() | 230 | self.double_letter_amount = dict() |
| 228 | 231 | ||
| 232 | def should_shuffle_map(game_map) -> bool: | ||
| 233 | if game_map.type == data_pb2.MapType.NORMAL_MAP: | ||
| 234 | return True | ||
| 235 | elif game_map.type == data_pb2.MapType.ICARUS: | ||
| 236 | return bool(world.options.enable_icarus) | ||
| 237 | elif game_map.type == data_pb2.MapType.GIFT_MAP: | ||
| 238 | if game_map.name == "the_advanced": | ||
| 239 | return "The Advanced" in world.options.enable_gift_maps.value | ||
| 240 | elif game_map.name == "the_charismatic": | ||
| 241 | return "The Charismatic" in world.options.enable_gift_maps.value | ||
| 242 | elif game_map.name == "the_crystalline": | ||
| 243 | return "The Crystalline" in world.options.enable_gift_maps.value | ||
| 244 | elif game_map.name == "the_fuzzy": | ||
| 245 | return "The Fuzzy" in world.options.enable_gift_maps.value | ||
| 246 | elif game_map.name == "the_stellar": | ||
| 247 | return "The Stellar" in world.options.enable_gift_maps.value | ||
| 248 | |||
| 249 | return False | ||
| 250 | |||
| 251 | self.shuffled_maps = set(game_map.id for game_map in world.static_logic.objects.maps | ||
| 252 | if should_shuffle_map(game_map)) | ||
| 253 | |||
| 254 | maximum_masteries = 13 + len(world.options.enable_gift_maps.value) | ||
| 255 | if world.options.enable_icarus: | ||
| 256 | maximum_masteries += 1 | ||
| 257 | |||
| 258 | if world.options.masteries_requirement > maximum_masteries: | ||
| 259 | world.options.masteries_requirement.value = maximum_masteries | ||
| 260 | |||
| 261 | if "The Fuzzy" in world.options.enable_gift_maps.value: | ||
| 262 | self.real_items.append("Numbers") | ||
| 263 | |||
| 229 | if self.world.options.shuffle_doors: | 264 | if self.world.options.shuffle_doors: |
| 230 | for progressive in world.static_logic.objects.progressives: | 265 | for progressive in world.static_logic.objects.progressives: |
| 231 | for i in range(0, len(progressive.doors)): | 266 | for i in range(0, len(progressive.doors)): |
| 267 | door = world.static_logic.objects.doors[progressive.doors[i]] | ||
| 268 | if door.map_id not in self.shuffled_maps: | ||
| 269 | continue | ||
| 270 | |||
| 232 | self.item_by_door[progressive.doors[i]] = (progressive.name, i + 1) | 271 | self.item_by_door[progressive.doors[i]] = (progressive.name, i + 1) |
| 233 | self.real_items.append(progressive.name) | 272 | self.real_items.append(progressive.name) |
| 234 | 273 | ||
| 235 | for door_group in world.static_logic.objects.door_groups: | 274 | for door_group in world.static_logic.objects.door_groups: |
| 236 | if door_group.type == data_pb2.DoorGroupType.CONNECTOR: | 275 | if door_group.type == data_pb2.DoorGroupType.CONNECTOR: |
| 237 | if not self.world.options.shuffle_doors: | 276 | if not self.world.options.shuffle_doors or self.world.options.shuffle_worldports: |
| 238 | continue | 277 | continue |
| 239 | elif door_group.type == data_pb2.DoorGroupType.COLOR_CONNECTOR: | 278 | elif door_group.type == data_pb2.DoorGroupType.COLOR_CONNECTOR: |
| 240 | if not self.world.options.shuffle_control_center_colors: | 279 | if not self.world.options.shuffle_control_center_colors or self.world.options.shuffle_worldports: |
| 241 | continue | 280 | continue |
| 242 | elif door_group.type == data_pb2.DoorGroupType.SHUFFLE_GROUP: | 281 | elif door_group.type == data_pb2.DoorGroupType.SHUFFLE_GROUP: |
| 243 | if not self.world.options.shuffle_doors: | 282 | if not self.world.options.shuffle_doors: |
| @@ -245,14 +284,21 @@ class Lingo2PlayerLogic: | |||
| 245 | else: | 284 | else: |
| 246 | continue | 285 | continue |
| 247 | 286 | ||
| 248 | for door in door_group.doors: | 287 | shuffleable_doors = [door_id for door_id in door_group.doors |
| 249 | self.item_by_door[door] = (door_group.name, 1) | 288 | if world.static_logic.objects.doors[door_id].map_id in self.shuffled_maps] |
| 250 | 289 | ||
| 251 | self.real_items.append(door_group.name) | 290 | if len(shuffleable_doors) > 0: |
| 291 | for door in shuffleable_doors: | ||
| 292 | self.item_by_door[door] = (door_group.name, 1) | ||
| 293 | |||
| 294 | self.real_items.append(door_group.name) | ||
| 252 | 295 | ||
| 253 | # We iterate through the doors in two parts because it is essential that we determine which doors are shuffled | 296 | # 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. | 297 | # before we calculate any access requirements. |
| 255 | for door in world.static_logic.objects.doors: | 298 | for door in world.static_logic.objects.doors: |
| 299 | if door.map_id not in self.shuffled_maps: | ||
| 300 | continue | ||
| 301 | |||
| 256 | if door.type in [data_pb2.DoorType.EVENT, data_pb2.DoorType.LOCATION_ONLY, data_pb2.DoorType.GRAVESTONE]: | 302 | if door.type in [data_pb2.DoorType.EVENT, data_pb2.DoorType.LOCATION_ONLY, data_pb2.DoorType.GRAVESTONE]: |
| 257 | continue | 303 | continue |
| 258 | 304 | ||
| @@ -281,29 +327,40 @@ class Lingo2PlayerLogic: | |||
| 281 | if door_group.type != data_pb2.DoorGroupType.CYAN_DOORS: | 327 | if door_group.type != data_pb2.DoorGroupType.CYAN_DOORS: |
| 282 | continue | 328 | continue |
| 283 | 329 | ||
| 284 | for door in door_group.doors: | 330 | shuffleable_doors = [door_id for door_id in door_group.doors |
| 285 | if not door in self.item_by_door: | 331 | if world.static_logic.objects.doors[door_id].map_id in self.shuffled_maps |
| 332 | and door_id not in self.item_by_door] | ||
| 333 | |||
| 334 | if len(shuffleable_doors) > 0: | ||
| 335 | for door in shuffleable_doors: | ||
| 286 | self.item_by_door[door] = (door_group.name, 1) | 336 | self.item_by_door[door] = (door_group.name, 1) |
| 287 | 337 | ||
| 288 | self.real_items.append(door_group.name) | 338 | self.real_items.append(door_group.name) |
| 289 | 339 | ||
| 290 | for door in world.static_logic.objects.doors: | 340 | for door in world.static_logic.objects.doors: |
| 341 | if door.map_id not in self.shuffled_maps: | ||
| 342 | continue | ||
| 343 | |||
| 291 | if door.type in [data_pb2.DoorType.STANDARD, data_pb2.DoorType.LOCATION_ONLY, data_pb2.DoorType.GRAVESTONE]: | 344 | 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, | 345 | self.locations_by_room.setdefault(door.room_id, []).append(PlayerLocation(door.ap_id, |
| 293 | self.get_door_reqs(door.id))) | 346 | self.get_door_reqs(door.id))) |
| 294 | 347 | ||
| 295 | for letter in world.static_logic.objects.letters: | 348 | for letter in world.static_logic.objects.letters: |
| 349 | if world.static_logic.get_room_object_map_id(letter) not in self.shuffled_maps: | ||
| 350 | continue | ||
| 351 | |||
| 296 | self.locations_by_room.setdefault(letter.room_id, []).append(PlayerLocation(letter.ap_id, | 352 | self.locations_by_room.setdefault(letter.room_id, []).append(PlayerLocation(letter.ap_id, |
| 297 | AccessRequirements())) | 353 | AccessRequirements())) |
| 298 | behavior = self.get_letter_behavior(letter.key, letter.level2) | 354 | behavior = self.get_letter_behavior(letter.key, letter.level2) |
| 299 | if behavior == LetterBehavior.VANILLA: | 355 | if behavior == LetterBehavior.VANILLA: |
| 300 | letter_name = f"{letter.key.upper()}{'2' if letter.level2 else '1'}" | 356 | if not world.for_tracker: |
| 301 | event_name = f"{letter_name} (Collected)" | 357 | letter_name = f"{letter.key.upper()}{'2' if letter.level2 else '1'}" |
| 302 | self.event_loc_item_by_room.setdefault(letter.room_id, {})[event_name] = letter.key.upper() | 358 | event_name = f"{letter_name} (Collected)" |
| 303 | |||
| 304 | if letter.level2: | ||
| 305 | event_name = f"{letter_name} (Double Collected)" | ||
| 306 | self.event_loc_item_by_room.setdefault(letter.room_id, {})[event_name] = letter.key.upper() | 359 | self.event_loc_item_by_room.setdefault(letter.room_id, {})[event_name] = letter.key.upper() |
| 360 | |||
| 361 | if letter.level2: | ||
| 362 | event_name = f"{letter_name} (Double Collected)" | ||
| 363 | self.event_loc_item_by_room.setdefault(letter.room_id, {})[event_name] = letter.key.upper() | ||
| 307 | elif behavior == LetterBehavior.ITEM: | 364 | elif behavior == LetterBehavior.ITEM: |
| 308 | self.real_items.append(letter.key.upper()) | 365 | self.real_items.append(letter.key.upper()) |
| 309 | 366 | ||
| @@ -311,30 +368,42 @@ class Lingo2PlayerLogic: | |||
| 311 | self.double_letter_amount[letter.key.upper()] = self.double_letter_amount.get(letter.key.upper(), 0) + 1 | 368 | self.double_letter_amount[letter.key.upper()] = self.double_letter_amount.get(letter.key.upper(), 0) + 1 |
| 312 | 369 | ||
| 313 | for mastery in world.static_logic.objects.masteries: | 370 | for mastery in world.static_logic.objects.masteries: |
| 371 | if world.static_logic.get_room_object_map_id(mastery) not in self.shuffled_maps: | ||
| 372 | continue | ||
| 373 | |||
| 314 | self.locations_by_room.setdefault(mastery.room_id, []).append(PlayerLocation(mastery.ap_id, | 374 | self.locations_by_room.setdefault(mastery.room_id, []).append(PlayerLocation(mastery.ap_id, |
| 315 | AccessRequirements())) | 375 | AccessRequirements())) |
| 316 | 376 | ||
| 377 | if world.options.masteries_requirement > 0: | ||
| 378 | event_name = f"{world.static_logic.get_room_object_map_name(mastery)} - Mastery (Collected)" | ||
| 379 | self.event_loc_item_by_room.setdefault(mastery.room_id, {})[event_name] = "Mastery" | ||
| 380 | |||
| 317 | for ending in world.static_logic.objects.endings: | 381 | 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 | 382 | if world.static_logic.get_room_object_map_id(ending) not in self.shuffled_maps: |
| 319 | # condition, since it is necessarily going to be in the postgame. | 383 | continue |
| 320 | if ending.name == "WHITE": | 384 | |
| 321 | if self.world.options.victory_condition != VictoryCondition.option_white_ending: | 385 | # Don't create a location for your selected ending. Also don't create a location for White Ending if it's |
| 322 | continue | 386 | # necessarily in the postgame, i.e. it requires all 12 other endings. |
| 323 | else: | 387 | if world.options.victory_condition.current_key.removesuffix("_ending").upper() != ending.name\ |
| 388 | and (ending.name != "WHITE" or world.options.endings_requirement < 12): | ||
| 324 | self.locations_by_room.setdefault(ending.room_id, []).append(PlayerLocation(ending.ap_id, | 389 | self.locations_by_room.setdefault(ending.room_id, []).append(PlayerLocation(ending.ap_id, |
| 325 | AccessRequirements())) | 390 | AccessRequirements())) |
| 326 | 391 | ||
| 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: | 392 | if world.options.victory_condition.current_key.removesuffix("_ending").upper() == ending.name: |
| 331 | item_name = "Victory" | 393 | event_name = f"{ending.name.capitalize()} Ending (Goal)" |
| 394 | self.event_loc_item_by_room.setdefault(ending.room_id, {})[event_name] = "Victory" | ||
| 395 | self.goal_room_id = ending.room_id | ||
| 332 | 396 | ||
| 333 | self.event_loc_item_by_room.setdefault(ending.room_id, {})[event_name] = item_name | 397 | if ending.name != "WHITE": |
| 398 | event_name = f"{ending.name.capitalize()} Ending (Achieved)" | ||
| 399 | self.event_loc_item_by_room.setdefault(ending.room_id, {})[event_name] = "Ending" | ||
| 334 | 400 | ||
| 335 | if self.world.options.keyholder_sanity: | 401 | if self.world.options.keyholder_sanity: |
| 336 | for keyholder in world.static_logic.objects.keyholders: | 402 | for keyholder in world.static_logic.objects.keyholders: |
| 337 | if keyholder.HasField("key"): | 403 | if keyholder.HasField("key"): |
| 404 | if world.static_logic.get_room_object_map_id(keyholder) not in self.shuffled_maps: | ||
| 405 | continue | ||
| 406 | |||
| 338 | reqs = AccessRequirements() | 407 | reqs = AccessRequirements() |
| 339 | 408 | ||
| 340 | if self.get_letter_behavior(keyholder.key, False) != LetterBehavior.UNLOCKED: | 409 | if self.get_letter_behavior(keyholder.key, False) != LetterBehavior.UNLOCKED: |
| @@ -442,7 +511,6 @@ class Lingo2PlayerLogic: | |||
| 442 | reqs.possibilities.append(panel_reqs) | 511 | reqs.possibilities.append(panel_reqs) |
| 443 | 512 | ||
| 444 | if door.HasField("control_center_color"): | 513 | 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") | 514 | reqs.rooms.add("Control Center - Main Area") |
| 447 | self.add_solution_reqs(reqs, door.control_center_color) | 515 | self.add_solution_reqs(reqs, door.control_center_color) |
| 448 | 516 | ||
| @@ -468,13 +536,12 @@ class Lingo2PlayerLogic: | |||
| 468 | for room in door.rooms: | 536 | for room in door.rooms: |
| 469 | reqs.rooms.add(self.world.static_logic.get_room_region_name(room)) | 537 | reqs.rooms.add(self.world.static_logic.get_room_region_name(room)) |
| 470 | 538 | ||
| 471 | for ending_id in door.endings: | 539 | if door.white_ending: |
| 472 | ending = self.world.static_logic.objects.endings[ending_id] | 540 | if self.world.options.endings_requirement > 0: |
| 541 | reqs.progressives["Ending"] = self.world.options.endings_requirement.value | ||
| 473 | 542 | ||
| 474 | if self.world.options.victory_condition.current_key.removesuffix("_ending").upper() == ending.name: | 543 | if self.world.options.masteries_requirement > 0: |
| 475 | reqs.items.add("Victory") | 544 | reqs.progressives["Mastery"] = self.world.options.masteries_requirement.value |
| 476 | else: | ||
| 477 | reqs.items.add(f"{ending.name.capitalize()} Ending (Achieved)") | ||
| 478 | 545 | ||
| 479 | for sub_door_id in door.doors: | 546 | for sub_door_id in door.doors: |
| 480 | sub_reqs = self.get_door_open_reqs(sub_door_id) | 547 | sub_reqs = self.get_door_open_reqs(sub_door_id) |
| @@ -536,3 +603,6 @@ class Lingo2PlayerLogic: | |||
| 536 | 603 | ||
| 537 | if needed > 0: | 604 | if needed > 0: |
| 538 | reqs.letters[l] = max(reqs.letters.get(l, 0), needed) | 605 | reqs.letters[l] = max(reqs.letters.get(l, 0), needed) |
| 606 | |||
| 607 | if any(l.isnumeric() for l in solution): | ||
| 608 | reqs.items.add("Numbers") | ||
