Skip to content

Commit

Permalink
Fix mypy errors in Item.py and ItemPool.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fenhl committed Mar 27, 2024
1 parent a8c4389 commit 5ee13ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
8 changes: 4 additions & 4 deletions Item.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class ItemInfo:
def __init__(self, name: str = '', event: bool = False) -> None:
if event:
item_type = 'Event'
progressive = True
progressive: Optional[bool] = True
item_id = None
special: dict[str, Any] = {}
else:
(item_type, progressive, item_id, special) = item_table[name]
item_type, progressive, item_id, special = item_table[name]

self.name: str = name
self.advancement: bool = (progressive is True)
Expand Down Expand Up @@ -198,11 +198,11 @@ def ItemFactory(items: str, world: Optional[World] = None, event: bool = False)


@overload
def ItemFactory(items: Iterable[str], world: Optional[World] = None, event: bool = False) -> list[Item]:
def ItemFactory(items: list[str] | tuple[str], world: Optional[World] = None, event: bool = False) -> list[Item]:
pass


def ItemFactory(items: str | Iterable[str], world: Optional[World] = None, event: bool = False) -> Item | list[Item]:
def ItemFactory(items: str | list[str] | tuple[str], world: Optional[World] = None, event: bool = False) -> Item | list[Item]:
if isinstance(items, str):
if not event and items not in ItemInfo.items:
raise KeyError('Unknown Item: %s' % items)
Expand Down
34 changes: 19 additions & 15 deletions ItemPool.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,16 +489,16 @@ def get_pool_core(world: World) -> tuple[list[str], dict[str, Item]]:
if world.settings.shuffle_gerudo_card:
pending_junk_pool.append('Gerudo Membership Card')
if world.settings.shuffle_smallkeys in ('any_dungeon', 'overworld', 'keysanity', 'regional'):
for dungeon in ('Forest Temple', 'Fire Temple', 'Water Temple', 'Shadow Temple', 'Spirit Temple',
for dungeon_name in ('Forest Temple', 'Fire Temple', 'Water Temple', 'Shadow Temple', 'Spirit Temple',
'Bottom of the Well', 'Gerudo Training Ground', 'Ganons Castle'):
if world.keyring(dungeon):
pending_junk_pool.append(f"Small Key Ring ({dungeon})")
if world.keyring(dungeon_name):
pending_junk_pool.append(f"Small Key Ring ({dungeon_name})")
else:
pending_junk_pool.append(f"Small Key ({dungeon})")
pending_junk_pool.append(f"Small Key ({dungeon_name})")
if world.settings.shuffle_bosskeys in ('any_dungeon', 'overworld', 'keysanity', 'regional'):
for dungeon in ('Forest Temple', 'Fire Temple', 'Water Temple', 'Shadow Temple', 'Spirit Temple'):
if not world.keyring_give_bk(dungeon):
pending_junk_pool.append(f"Boss Key ({dungeon})")
for dungeon_name in ('Forest Temple', 'Fire Temple', 'Water Temple', 'Shadow Temple', 'Spirit Temple'):
if not world.keyring_give_bk(dungeon_name):
pending_junk_pool.append(f"Boss Key ({dungeon_name})")
if world.settings.shuffle_ganon_bosskey in ('any_dungeon', 'overworld', 'keysanity', 'regional'):
pending_junk_pool.append('Boss Key (Ganons Castle)')
if world.settings.shuffle_silver_rupees in ('any_dungeon', 'overworld', 'anywhere', 'regional'):
Expand All @@ -525,7 +525,7 @@ def get_pool_core(world: World) -> tuple[list[str], dict[str, Item]]:
pending_junk_pool.append('Ocarina C right Button')

# Use the vanilla items in the world's locations when appropriate.
vanilla_items_processed = Counter()
vanilla_items_processed: Counter[str] = Counter()
for location in world.get_locations():
if location.vanilla_item is None:
continue
Expand All @@ -541,9 +541,11 @@ def get_pool_core(world: World) -> tuple[list[str], dict[str, Item]]:

# Gold Skulltula Tokens
elif location.vanilla_item == 'Gold Skulltula Token':
shuffle_item = (world.settings.tokensanity == 'all'
or (world.settings.tokensanity == 'dungeons' and location.dungeon)
or (world.settings.tokensanity == 'overworld' and not location.dungeon))
shuffle_item = (
world.settings.tokensanity == 'all'
or (world.settings.tokensanity == 'dungeons' and location.dungeon is not None)
or (world.settings.tokensanity == 'overworld' and location.dungeon is None)
)

# Shops
elif location.type == "Shop":
Expand All @@ -559,9 +561,11 @@ def get_pool_core(world: World) -> tuple[list[str], dict[str, Item]]:
elif world.settings.shuffle_scrubs == 'off':
shuffle_item = False
else:
item = deku_scrubs_items[location.vanilla_item]
if isinstance(item, list):
item = random.choices([i[0] for i in item], weights=[i[1] for i in item], k=1)[0]
scrub_item = deku_scrubs_items[location.vanilla_item]
if isinstance(scrub_item, list):
item = random.choices([i[0] for i in scrub_item], weights=[i[1] for i in scrub_item], k=1)[0]
else:
item = scrub_item
shuffle_item = True

# Kokiri Sword
Expand Down Expand Up @@ -911,7 +915,7 @@ def get_pool_core(world: World) -> tuple[list[str], dict[str, Item]]:

remove_junk_pool, _ = zip(*junk_pool_base)
# Omits Rupees (200) and Deku Nuts (10)
remove_junk_pool = list(remove_junk_pool) + ['Recovery Heart', 'Bombs (20)', 'Arrows (30)', 'Ice Trap']
remove_junk_pool = *remove_junk_pool, 'Recovery Heart', 'Bombs (20)', 'Arrows (30)', 'Ice Trap'

junk_candidates = [item for item in pool if item in remove_junk_pool]
while pending_junk_pool:
Expand Down

0 comments on commit 5ee13ba

Please sign in to comment.