From cf37a69e53e7175716d2aaf3791d1ba71416636b Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Fri, 28 Jul 2023 09:39:56 +0200 Subject: [PATCH] Witness: Fix 2 generation crashes (#2043) * Fix for error in get_early_items when removing plandoed items. * Fix Early Caves * Remove unnecessary list() call * Update worlds/witness/items.py Co-authored-by: Fabian Dill --------- Co-authored-by: blastron Co-authored-by: Fabian Dill --- worlds/witness/__init__.py | 1 + worlds/witness/items.py | 26 +++++++++++++------------- worlds/witness/player_logic.py | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/worlds/witness/__init__.py b/worlds/witness/__init__.py index c746dcdc..ccbacb41 100644 --- a/worlds/witness/__init__.py +++ b/worlds/witness/__init__.py @@ -128,6 +128,7 @@ class WitnessWorld(World): item_pool.pop(inventory_item_name) else: item_pool[inventory_item_name] -= 1 + self.multiworld.push_precollected(self.create_item(inventory_item_name)) if len(item_pool) > pool_size: error_string = "The Witness world has too few locations ({num_loc}) to place its necessary items " \ diff --git a/worlds/witness/items.py b/worlds/witness/items.py index dbb06adf..b8e439d7 100644 --- a/worlds/witness/items.py +++ b/worlds/witness/items.py @@ -3,7 +3,7 @@ Defines progression, junk and event items for The Witness """ import copy from dataclasses import dataclass -from typing import Optional, Dict, List +from typing import Optional, Dict, List, Set from BaseClasses import Item, MultiWorld, ItemClassification from .Options import get_option_value, is_option_enabled, the_witness_options @@ -197,36 +197,36 @@ class WitnessPlayerItems: """ Returns items that are ideal for placing on extremely early checks, like the tutorial gate. """ - output: List[str] = [] + output: Set[str] = set() if "shuffle_symbols" not in the_witness_options.keys() \ or is_option_enabled(self._world, self._player_id, "shuffle_symbols"): if get_option_value(self._world, self._player_id, "shuffle_doors") > 0: - output = ["Dots", "Black/White Squares", "Symmetry"] + output = {"Dots", "Black/White Squares", "Symmetry"} else: - output = ["Dots", "Black/White Squares", "Symmetry", "Shapers", "Stars"] + output = {"Dots", "Black/White Squares", "Symmetry", "Shapers", "Stars"} if is_option_enabled(self._world, self._player_id, "shuffle_discarded_panels"): if get_option_value(self._world, self._player_id, "puzzle_randomization") == 1: - output.append("Arrows") + output.add("Arrows") else: - output.append("Triangles") + output.add("Triangles") # Replace progressive items with their parents. - output = [StaticWitnessLogic.get_parent_progressive_item(item) for item in output] + output = {StaticWitnessLogic.get_parent_progressive_item(item) for item in output} # Remove items that are mentioned in any plando options. (Hopefully, in the future, plando will get resolved # before create_items so that we'll be able to check placed items instead of just removing all items mentioned # regardless of whether or not they actually wind up being manually placed. for plando_setting in self._world.plando_items[self._player_id]: if plando_setting.get("from_pool", True): - if "item" in plando_setting and type(plando_setting["item"]) is str: - output.remove(plando_setting["item"]) - elif "items" in plando_setting: - if type(plando_setting["items"]) is dict: - output -= [item for item, weight in plando_setting["items"].items() if weight] + for item_setting_key in (key for key in ["item", "items"] if key in plando_setting): + if type(plando_setting[item_setting_key]) is str: + output.remove(plando_setting[item_setting_key]) + elif type(plando_setting[item_setting_key]) is dict: + output -= {item for item, weight in plando_setting[item_setting_key].items() if weight} else: # Assume this is some other kind of iterable. - output -= plando_setting["items"] + output -= plando_setting[item_setting_key] # Sort the output for consistency across versions if the implementation changes but the logic does not. return sorted(output) diff --git a/worlds/witness/player_logic.py b/worlds/witness/player_logic.py index 38943773..be1a34ae 100644 --- a/worlds/witness/player_logic.py +++ b/worlds/witness/player_logic.py @@ -157,7 +157,7 @@ class WitnessPlayerLogic: if StaticWitnessLogic.all_items[item_name].category in [ItemCategory.DOOR, ItemCategory.LASER]: panel_hexes = cast(DoorItemDefinition, StaticWitnessLogic.all_items[item_name]).panel_id_hexes for panel_hex in panel_hexes: - if panel_hex in self.DOOR_ITEMS_BY_ID: + if panel_hex in self.DOOR_ITEMS_BY_ID and item_name in self.DOOR_ITEMS_BY_ID[panel_hex]: self.DOOR_ITEMS_BY_ID[panel_hex].remove(item_name) if adj_type == "Starting Inventory":