From 484ee9f0651724469287da1bc78b14a9d2d8e391 Mon Sep 17 00:00:00 2001 From: CaitSith2 Date: Sat, 20 Aug 2022 16:55:41 -0700 Subject: [PATCH] OoT: More item.type bugs. (#930) --- worlds/oot/Hints.py | 2 ++ worlds/oot/Items.py | 6 ++++++ worlds/oot/Rules.py | 5 +++-- worlds/oot/__init__.py | 16 ++++++++-------- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/worlds/oot/Hints.py b/worlds/oot/Hints.py index b8ae7dfa..aaafeb20 100644 --- a/worlds/oot/Hints.py +++ b/worlds/oot/Hints.py @@ -129,6 +129,8 @@ def getItemGenericName(item): def isRestrictedDungeonItem(dungeon, item): + if not isinstance(item, OOTItem): + return False if (item.map or item.compass) and dungeon.world.shuffle_mapcompass == 'dungeon': return item in dungeon.dungeon_items if item.type == 'SmallKey' and dungeon.world.shuffle_smallkeys == 'dungeon': diff --git a/worlds/oot/Items.py b/worlds/oot/Items.py index b4c07197..31e6c31f 100644 --- a/worlds/oot/Items.py +++ b/worlds/oot/Items.py @@ -22,6 +22,12 @@ def ap_id_to_oot_data(ap_id): raise Exception(f'Could not find desired item ID: {ap_id}') +def oot_is_item_of_type(item, item_type): + if not isinstance(item, OOTItem): + return False + return item.type == item_type + + class OOTItem(Item): game: str = "Ocarina of Time" type: str diff --git a/worlds/oot/Rules.py b/worlds/oot/Rules.py index c55407b4..915aae77 100644 --- a/worlds/oot/Rules.py +++ b/worlds/oot/Rules.py @@ -3,6 +3,7 @@ import logging from .SaveContext import SaveContext from .Regions import TimeOfDay +from .Items import oot_is_item_of_type from BaseClasses import CollectionState from worlds.generic.Rules import set_rule, add_rule, add_item_rule, forbid_item @@ -138,7 +139,7 @@ def set_rules(ootworld): # Sheik in Ice Cavern is the only song location in a dungeon; need to ensure that it cannot be anything else. # This is required if map/compass included, or any_dungeon shuffle. location = world.get_location('Sheik in Ice Cavern', player) - add_item_rule(location, lambda item: item.player == player and item.type == 'Song') + add_item_rule(location, lambda item: item.player == player and oot_is_item_of_type(item, 'Song')) if ootworld.skip_child_zelda: # If skip child zelda is on, the item at Song from Impa must be giveable by the save context. @@ -181,7 +182,7 @@ def set_shop_rules(ootworld): wallet = ootworld.parser.parse_rule('Progressive_Wallet') wallet2 = ootworld.parser.parse_rule('(Progressive_Wallet, 2)') - for location in filter(lambda location: location.item and location.item.type == 'Shop', ootworld.get_locations()): + for location in filter(lambda location: location.item and oot_is_item_of_type(location.item, 'Shop'), ootworld.get_locations()): # Add wallet requirements if location.item.name in ['Buy Arrows (50)', 'Buy Fish', 'Buy Goron Tunic', 'Buy Bombchu (20)', 'Buy Bombs (30)']: add_rule(location, wallet) diff --git a/worlds/oot/__init__.py b/worlds/oot/__init__.py index fb90b04e..b4635ad7 100644 --- a/worlds/oot/__init__.py +++ b/worlds/oot/__init__.py @@ -8,7 +8,7 @@ logger = logging.getLogger("Ocarina of Time") from .Location import OOTLocation, LocationFactory, location_name_to_id from .Entrance import OOTEntrance from .EntranceShuffle import shuffle_random_entrances, entrance_shuffle_table, EntranceShuffleError -from .Items import OOTItem, item_table, oot_data_to_ap_id +from .Items import OOTItem, item_table, oot_data_to_ap_id, oot_is_item_of_type from .ItemPool import generate_itempool, add_dungeon_items, get_junk_item, get_junk_pool from .Regions import OOTRegion, TimeOfDay from .Rules import set_rules, set_shop_rules, set_entrances_based_rules @@ -793,7 +793,7 @@ class OOTWorld(World): # This includes all locations for which show_in_spoiler is false, and shuffled shop items. for loc in self.get_locations(): if loc.address is not None and ( - not loc.show_in_spoiler or (loc.item is not None and loc.item.type == 'Shop') + not loc.show_in_spoiler or oot_is_item_of_type(loc.item, 'Shop') or (self.skip_child_zelda and loc.name in ['HC Zeldas Letter', 'Song from Impa'])): loc.address = None @@ -869,11 +869,11 @@ class OOTWorld(World): autoworld.major_item_locations.append(loc) if loc.game == "Ocarina of Time" and loc.item.code and (not loc.locked or - (loc.item.type == 'Song' or - (loc.item.type == 'SmallKey' and world.worlds[loc.player].shuffle_smallkeys == 'any_dungeon') or - (loc.item.type == 'HideoutSmallKey' and world.worlds[loc.player].shuffle_fortresskeys == 'any_dungeon') or - (loc.item.type == 'BossKey' and world.worlds[loc.player].shuffle_bosskeys == 'any_dungeon') or - (loc.item.type == 'GanonBossKey' and world.worlds[loc.player].shuffle_ganon_bosskey == 'any_dungeon'))): + (oot_is_item_of_type(loc.item, 'Song') or + (oot_is_item_of_type(loc.item, 'SmallKey') and world.worlds[loc.player].shuffle_smallkeys == 'any_dungeon') or + (oot_is_item_of_type(loc.item, 'HideoutSmallKey') and world.worlds[loc.player].shuffle_fortresskeys == 'any_dungeon') or + (oot_is_item_of_type(loc.item, 'BossKey') and world.worlds[loc.player].shuffle_bosskeys == 'any_dungeon') or + (oot_is_item_of_type(loc.item, 'GanonBossKey') and world.worlds[loc.player].shuffle_ganon_bosskey == 'any_dungeon'))): if loc.player in barren_hint_players: hint_area = get_hint_area(loc) items_by_region[loc.player][hint_area]['weight'] += 1 @@ -888,7 +888,7 @@ class OOTWorld(World): elif barren_hint_players or woth_hint_players: # Check only relevant oot locations for barren/woth for player in (barren_hint_players | woth_hint_players): for loc in world.worlds[player].get_locations(): - if loc.item.code and (not loc.locked or loc.item.type == 'Song'): + if loc.item.code and (not loc.locked or oot_is_item_of_type(loc.item, 'Song')): if player in barren_hint_players: hint_area = get_hint_area(loc) items_by_region[player][hint_area]['weight'] += 1