diff options
Diffstat (limited to 'apworld/player_logic.py')
| -rw-r--r-- | apworld/player_logic.py | 118 |
1 files changed, 94 insertions, 24 deletions
| diff --git a/apworld/player_logic.py b/apworld/player_logic.py index 84c93c8..3ee8f38 100644 --- a/apworld/player_logic.py +++ b/apworld/player_logic.py | |||
| @@ -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 | ||
| @@ -227,9 +229,45 @@ class Lingo2PlayerLogic: | |||
| 227 | self.real_items = list() | 229 | self.real_items = list() |
| 228 | self.double_letter_amount = dict() | 230 | self.double_letter_amount = dict() |
| 229 | 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 | |||
| 230 | if self.world.options.shuffle_doors: | 264 | if self.world.options.shuffle_doors: |
| 231 | for progressive in world.static_logic.objects.progressives: | 265 | for progressive in world.static_logic.objects.progressives: |
| 232 | 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 | |||
| 233 | self.item_by_door[progressive.doors[i]] = (progressive.name, i + 1) | 271 | self.item_by_door[progressive.doors[i]] = (progressive.name, i + 1) |
| 234 | self.real_items.append(progressive.name) | 272 | self.real_items.append(progressive.name) |
| 235 | 273 | ||
| @@ -246,14 +284,21 @@ class Lingo2PlayerLogic: | |||
| 246 | else: | 284 | else: |
| 247 | continue | 285 | continue |
| 248 | 286 | ||
| 249 | for door in door_group.doors: | 287 | shuffleable_doors = [door_id for door_id in door_group.doors |
| 250 | self.item_by_door[door] = (door_group.name, 1) | 288 | if world.static_logic.objects.doors[door_id].map_id in self.shuffled_maps] |
| 251 | 289 | ||
| 252 | 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) | ||
| 253 | 295 | ||
| 254 | # 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 |
| 255 | # before we calculate any access requirements. | 297 | # before we calculate any access requirements. |
| 256 | 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 | |||
| 257 | 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]: |
| 258 | continue | 303 | continue |
| 259 | 304 | ||
| @@ -282,18 +327,28 @@ class Lingo2PlayerLogic: | |||
| 282 | if door_group.type != data_pb2.DoorGroupType.CYAN_DOORS: | 327 | if door_group.type != data_pb2.DoorGroupType.CYAN_DOORS: |
| 283 | continue | 328 | continue |
| 284 | 329 | ||
| 285 | for door in door_group.doors: | 330 | shuffleable_doors = [door_id for door_id in door_group.doors |
| 286 | 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: | ||
| 287 | self.item_by_door[door] = (door_group.name, 1) | 336 | self.item_by_door[door] = (door_group.name, 1) |
| 288 | 337 | ||
| 289 | self.real_items.append(door_group.name) | 338 | self.real_items.append(door_group.name) |
| 290 | 339 | ||
| 291 | 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 | |||
| 292 | 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]: |
| 293 | 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, |
| 294 | self.get_door_reqs(door.id))) | 346 | self.get_door_reqs(door.id))) |
| 295 | 347 | ||
| 296 | 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 | |||
| 297 | 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, |
| 298 | AccessRequirements())) | 353 | AccessRequirements())) |
| 299 | behavior = self.get_letter_behavior(letter.key, letter.level2) | 354 | behavior = self.get_letter_behavior(letter.key, letter.level2) |
| @@ -313,28 +368,42 @@ class Lingo2PlayerLogic: | |||
| 313 | 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 |
| 314 | 369 | ||
| 315 | 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 | |||
| 316 | 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, |
| 317 | AccessRequirements())) | 375 | AccessRequirements())) |
| 318 | 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 | |||
| 319 | for ending in world.static_logic.objects.endings: | 381 | for ending in world.static_logic.objects.endings: |
| 320 | # Don't create a location for your selected ending, and never create a location for White Ending. | 382 | if world.static_logic.get_room_object_map_id(ending) not in self.shuffled_maps: |
| 383 | continue | ||
| 384 | |||
| 385 | # Don't create a location for your selected ending. Also don't create a location for White Ending if it's | ||
| 386 | # necessarily in the postgame, i.e. it requires all 12 other endings. | ||
| 321 | if world.options.victory_condition.current_key.removesuffix("_ending").upper() != ending.name\ | 387 | if world.options.victory_condition.current_key.removesuffix("_ending").upper() != ending.name\ |
| 322 | and ending.name != "WHITE": | 388 | and (ending.name != "WHITE" or world.options.endings_requirement < 12): |
| 323 | 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, |
| 324 | AccessRequirements())) | 390 | AccessRequirements())) |
| 325 | 391 | ||
| 326 | event_name = f"{ending.name.capitalize()} Ending (Achieved)" | ||
| 327 | item_name = event_name | ||
| 328 | |||
| 329 | 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: |
| 330 | 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" | ||
| 331 | self.goal_room_id = ending.room_id | 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") | ||
