use dynamic item name groups in State

This commit is contained in:
Fabian Dill 2021-07-21 09:45:15 +02:00
parent a503134533
commit e105616b96
3 changed files with 21 additions and 24 deletions

View File

@ -571,6 +571,20 @@ class CollectionState(object):
def has_any(self, items: Set[str], player:int):
return any(self.prog_items[item, player] for item in items)
def has_group(self, item_name_group: str, player: int, count: int = 1):
found: int = 0
for item_name in self.world.worlds[player].item_name_groups[item_name_group]:
found += self.prog_items[item_name, player]
if found >= count:
return True
return False
def count_group(self, item_name_group: str, player: int):
found: int = 0
for item_name in self.world.worlds[player].item_name_groups[item_name_group]:
found += self.prog_items[item_name, player]
return found
def has_key(self, item, player, count: int = 1):
if self.world.logic[player] == 'nologic':
return True
@ -603,25 +617,9 @@ class CollectionState(object):
def can_lift_rocks(self, player: int):
return self.has('Power Glove', player) or self.has('Titans Mitts', player)
def has_bottle(self, player: int) -> bool:
return self.has_bottles(1, player)
def bottle_count(self, player: int) -> int:
found: int = 0
for bottlename in item_name_groups["Bottles"]:
found += self.prog_items[bottlename, player]
return min(self.world.difficulty_requirements[player].progressive_bottle_limit, found)
def has_bottles(self, bottles: int, player: int) -> bool:
"""Version of bottle_count that allows fast abort"""
if bottles > self.world.difficulty_requirements[player].progressive_bottle_limit:
return False
found: int = 0
for bottlename in item_name_groups["Bottles"]:
found += self.prog_items[bottlename, player]
if found >= bottles:
return True
return False
return min(self.world.difficulty_requirements[player].progressive_bottle_limit,
self.count_group("Bottles", player))
def has_hearts(self, player: int, count: int) -> int:
# Warning: This only considers items that are marked as advancement items
@ -670,7 +668,7 @@ class CollectionState(object):
def can_get_good_bee(self, player: int) -> bool:
cave = self.world.get_region('Good Bee Cave', player)
return (
self.has_bottle(player) and
self.has_group("Bottles", player) and
self.has('Bug Catching Net', player) and
(self.has('Pegasus Boots', player) or (self.has_sword(player) and self.has('Quake', player))) and
cave.can_reach(self) and
@ -1519,5 +1517,4 @@ class Spoiler(object):
outfile.write('\n'.join(path_listings))
from worlds.alttp.Items import item_name_groups
from worlds.generic import PlandoItem, PlandoConnection

View File

@ -82,7 +82,7 @@ cx_Freeze.setup(
executables=exes,
options={
"build_exe": {
"packages": ["websockets"],
"packages": ["websockets", "worlds"],
"includes": [],
"excludes": ["numpy", "Cython", "PySide2", "PIL",
"pandas"],
@ -172,7 +172,7 @@ cx_Freeze.setup(
executables=exes,
options={
"build_exe": {
"packages": ["websockets", "kivy"],
"packages": ["websockets", "kivy", "worlds"],
"includes": [],
"excludes": ["numpy", "Cython", "PySide2", "PIL",
"pandas"],

View File

@ -188,7 +188,7 @@ def global_rules(world, player):
set_rule(world.get_location('Missing Smith', player), lambda state: state.has('Get Frog', player) and state.can_reach('Blacksmiths Hut', 'Region', player)) # Can't S&Q with smith
set_rule(world.get_location('Blacksmith', player), lambda state: state.has('Return Smith', player))
set_rule(world.get_location('Magic Bat', player), lambda state: state.has('Magic Powder', player))
set_rule(world.get_location('Sick Kid', player), lambda state: state.has_bottle(player))
set_rule(world.get_location('Sick Kid', player), lambda state: state.has_group("Bottles", player))
set_rule(world.get_location('Library', player), lambda state: state.has('Pegasus Boots', player))
set_rule(world.get_location('Mimic Cave', player), lambda state: state.has('Hammer', player))
set_rule(world.get_location('Sahasrahla', player), lambda state: state.has('Green Pendant', player))
@ -563,7 +563,7 @@ def inverted_rules(world, player):
set_rule(world.get_location('Missing Smith', player), lambda state: state.has('Get Frog', player) and state.can_reach('Blacksmiths Hut', 'Region', player)) # Can't S&Q with smith
set_rule(world.get_location('Blacksmith', player), lambda state: state.has('Return Smith', player))
set_rule(world.get_location('Magic Bat', player), lambda state: state.has('Magic Powder', player) and state.has('Moon Pearl', player))
set_rule(world.get_location('Sick Kid', player), lambda state: state.has_bottle(player))
set_rule(world.get_location('Sick Kid', player), lambda state: state.has_group("Bottles", player))
set_rule(world.get_location('Mushroom', player), lambda state: state.has('Moon Pearl', player)) # need pearl to pick up bushes
set_rule(world.get_entrance('Bush Covered Lawn Mirror Spot', player), lambda state: state.has('Magic Mirror', player))
set_rule(world.get_entrance('Bush Covered Lawn Inner Bushes', player), lambda state: state.has('Moon Pearl', player))