Core: Move Location.always_allow to a subclass

This commit is contained in:
Fabian Dill
2024-01-01 18:07:08 +01:00
parent e674e37e08
commit ad2275c78a
6 changed files with 22 additions and 13 deletions

View File

@@ -1018,10 +1018,9 @@ class Location:
self.parent_region = parent
def can_fill(self, state: CollectionState, item: Item, check_access=True) -> bool:
return ((self.always_allow(state, item) and item.name not in state.multiworld.non_local_items[item.player])
or ((self.progress_type != LocationProgressType.EXCLUDED or not (item.advancement or item.useful))
and self.item_rule(item)
and (not check_access or self.can_reach(state))))
return ((self.progress_type != LocationProgressType.EXCLUDED or not (item.advancement or item.useful))
and self.item_rule(item)
and (not check_access or self.can_reach(state)))
def can_reach(self, state: CollectionState) -> bool:
# self.access_rule computes faster on average, so placing it first for faster abort
@@ -1062,6 +1061,15 @@ class Location:
return "at " + self.name.replace("_", " ").replace("-", " ")
class AlwaysAllowLocation(Location):
"""Subclass of Location that allows an always_allow item rule, which overrides all other requirements."""
always_allow: Callable[[Item], bool] = staticmethod(lambda item, state: False)
def can_fill(self, state: CollectionState, item: Item, check_access=True) -> bool:
return ((self.always_allow(state, item) and item.name not in state.multiworld.non_local_items[item.player])
or super().can_fill(state, item, check_access))
class ItemClassification(IntFlag):
filler = 0b0000 # aka trash, as in filler items like ammo, currency etc,
progression = 0b0001 # Item that is logically relevant