From 3776c3571e16018079f3b04e8e3c4487ea0f03f4 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Mon, 5 Aug 2024 19:54:33 -0700 Subject: [PATCH] Make sure to send AP IDs for infused/upgraded weapons --- worlds/dark_souls_3/Items.py | 9 +++++++++ worlds/dark_souls_3/__init__.py | 21 ++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/worlds/dark_souls_3/Items.py b/worlds/dark_souls_3/Items.py index 42a256355be0..ab436c05561f 100644 --- a/worlds/dark_souls_3/Items.py +++ b/worlds/dark_souls_3/Items.py @@ -238,6 +238,15 @@ def upgrade(self, level: int) -> "DS3ItemData": ds3_code = cast(int, self.ds3_code) + level, filler = False, ) + + def __hash__(self) -> int: + return (self.name, self.ds3_code).__hash__() + + def __eq__(self, other: any) -> bool: + if isinstance(other, self.__class__): + return self.name == other.name and self.ds3_code == other.ds3_code + else: + return False class DarkSouls3Item(Item): diff --git a/worlds/dark_souls_3/__init__.py b/worlds/dark_souls_3/__init__.py index 5ed3fee28b83..3e1160d0cb27 100644 --- a/worlds/dark_souls_3/__init__.py +++ b/worlds/dark_souls_3/__init__.py @@ -3,17 +3,17 @@ from collections import defaultdict import json from logging import warning -from typing import Any, Callable, Dict, Set, List, Optional, TextIO, Union +from typing import cast, Any, Callable, Dict, Set, List, Optional, TextIO, Union -from BaseClasses import CollectionState, MultiWorld, Region, Item, Location, LocationProgressType, Entrance, Tutorial, ItemClassification +from BaseClasses import CollectionState, MultiWorld, Region, Location, LocationProgressType, Entrance, Tutorial, ItemClassification from worlds.AutoWorld import World, WebWorld from worlds.generic.Rules import CollectionRule, ItemRule, add_rule, add_item_rule from .Bosses import DS3BossInfo, all_bosses, default_yhorm_location -from .Items import DarkSouls3Item, DS3ItemCategory, DS3ItemData, Infusion, UsefulIf, filler_item_names, item_descriptions, item_dictionary, item_name_groups +from .Items import DarkSouls3Item, DS3ItemData, Infusion, UsefulIf, filler_item_names, item_descriptions, item_dictionary, item_name_groups from .Locations import DarkSouls3Location, DS3LocationData, location_tables, location_descriptions, location_dictionary, location_name_groups, region_order -from .Options import DarkSouls3Options, EarlySmallLothricBanner, option_groups +from .Options import DarkSouls3Options, option_groups class DarkSouls3Web(WebWorld): @@ -1495,9 +1495,20 @@ def fill_slot_data(self) -> Dict[str, object]: # Once all clients support overlapping item IDs, adjust the DS3 AP item IDs to encode the # in-game ID as well as the count so that we don't need to send this information at all. + # + # We include all the items the game knows about so that users can manually request items + # that aren't randomized, and then we _also_ include all the items that are placed in + # practice `item_dictionary.values()` doesn't include upgraded or infused weapons. + all_items = { + cast(DS3ItemData, location.item).data + for location in self.multiworld.get_filled_locations() + # item.code None is used for events, which we want to skip + if location.item.code is not None and location.item.player == self.player + }.union(item_dictionary.values()) + ap_ids_to_ds3_ids: Dict[str, int] = {} item_counts: Dict[str, int] = {} - for item in item_dictionary.values(): + for item in all_items: if item.ap_code is None: continue if item.ds3_code: ap_ids_to_ds3_ids[str(item.ap_code)] = item.ds3_code if item.count != 1: item_counts[str(item.ap_code)] = item.count