From fbfe82f57f35757ce040c7436881c9f439591e69 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:57:22 +0200 Subject: [PATCH] The Witness: Make item links work properly with the hint system (#3110) --- worlds/witness/hints.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/worlds/witness/hints.py b/worlds/witness/hints.py index 28631438..fa6f658b 100644 --- a/worlds/witness/hints.py +++ b/worlds/witness/hints.py @@ -2,7 +2,7 @@ import logging from dataclasses import dataclass from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, Union -from BaseClasses import CollectionState, Item, Location, LocationProgressType +from BaseClasses import CollectionState, Item, Location, LocationProgressType, MultiWorld from .data import static_logic as static_witness_logic from .data.utils import weighted_sample @@ -184,17 +184,26 @@ def word_direct_hint(world: "WitnessWorld", hint: WitnessLocationHint) -> Witnes def hint_from_item(world: "WitnessWorld", item_name: str, own_itempool: List[Item]) -> Optional[WitnessLocationHint]: + def get_real_location(multiworld: MultiWorld, location: Location): + """If this location is from an item_link pseudo-world, get the location that the item_link item is on. + Return the original location otherwise / as a fallback.""" + if location.player not in world.multiworld.groups: + return location - locations = [item.location for item in own_itempool if item.name == item_name and item.location] + try: + return multiworld.find_item(location.item.name, location.player) + except StopIteration: + return location + + locations = [ + get_real_location(world.multiworld, item.location) + for item in own_itempool if item.name == item_name and item.location + ] if not locations: return None location_obj = world.random.choice(locations) - location_name = location_obj.name - - if location_obj.player != world.player: - location_name += " (" + world.multiworld.get_player_name(location_obj.player) + ")" return WitnessLocationHint(location_obj, False)