forked from mirror/Archipelago
Core+RB: Make has_from_list, has_from_list_unique, has_group and has_group_unique return True if count <= 0 and list is empty (#6240)
This commit is contained in:
@@ -1038,6 +1038,8 @@ class CollectionState():
|
||||
|
||||
def has_from_list(self, items: Iterable[str], player: int, count: int) -> bool:
|
||||
"""Returns True if the state contains at least `count` items matching any of the item names from a list."""
|
||||
if count <= 0:
|
||||
return True
|
||||
found: int = 0
|
||||
player_prog_items = self.prog_items[player]
|
||||
for item_name in items:
|
||||
@@ -1049,6 +1051,8 @@ class CollectionState():
|
||||
def has_from_list_unique(self, items: Iterable[str], player: int, count: int) -> bool:
|
||||
"""Returns True if the state contains at least `count` items matching any of the item names from a list.
|
||||
Ignores duplicates of the same item."""
|
||||
if count <= 0:
|
||||
return True
|
||||
found: int = 0
|
||||
player_prog_items = self.prog_items[player]
|
||||
for item_name in items:
|
||||
@@ -1077,6 +1081,8 @@ class CollectionState():
|
||||
# item name group related
|
||||
def has_group(self, item_name_group: str, player: int, count: int = 1) -> bool:
|
||||
"""Returns True if the state contains at least `count` items present in a specified item group."""
|
||||
if count <= 0:
|
||||
return True
|
||||
found: int = 0
|
||||
player_prog_items = self.prog_items[player]
|
||||
for item_name in self.multiworld.worlds[player].item_name_groups[item_name_group]:
|
||||
@@ -1089,6 +1095,8 @@ class CollectionState():
|
||||
"""Returns True if the state contains at least `count` items present in a specified item group.
|
||||
Ignores duplicates of the same item.
|
||||
"""
|
||||
if count <= 0:
|
||||
return True
|
||||
found: int = 0
|
||||
player_prog_items = self.prog_items[player]
|
||||
for item_name in self.multiworld.worlds[player].item_name_groups[item_name_group]:
|
||||
|
||||
+17
-6
@@ -1403,14 +1403,16 @@ class HasFromList(Rule[TWorld], game="Archipelago"):
|
||||
|
||||
@override
|
||||
def _instantiate(self, world: TWorld) -> Rule.Resolved:
|
||||
count = resolve_field(self.count, world, int)
|
||||
if count <= 0:
|
||||
return True_().resolve(world)
|
||||
if len(self.item_names) == 0:
|
||||
# match state.has_from_list
|
||||
return False_().resolve(world)
|
||||
if len(self.item_names) == 1:
|
||||
return Has(self.item_names[0], self.count).resolve(world)
|
||||
return self.Resolved(
|
||||
self.item_names,
|
||||
count=resolve_field(self.count, world, int),
|
||||
count=count,
|
||||
player=world.player,
|
||||
caching_enabled=getattr(world, "rule_caching_enabled", False),
|
||||
)
|
||||
@@ -1538,8 +1540,9 @@ class HasFromListUnique(Rule[TWorld], game="Archipelago"):
|
||||
@override
|
||||
def _instantiate(self, world: TWorld) -> Rule.Resolved:
|
||||
count = resolve_field(self.count, world, int)
|
||||
if len(self.item_names) == 0 or len(self.item_names) < count:
|
||||
# match state.has_from_list_unique
|
||||
if count <= 0:
|
||||
return True_().resolve(world)
|
||||
if len(self.item_names) < count:
|
||||
return False_().resolve(world)
|
||||
if len(self.item_names) == 1:
|
||||
return Has(self.item_names[0]).resolve(world)
|
||||
@@ -1657,11 +1660,14 @@ class HasGroup(Rule[TWorld], game="Archipelago"):
|
||||
|
||||
@override
|
||||
def _instantiate(self, world: TWorld) -> Rule.Resolved:
|
||||
count = resolve_field(self.count, world, int)
|
||||
if count <= 0:
|
||||
return True_().resolve(world)
|
||||
item_names = tuple(sorted(world.item_name_groups[self.item_name_group]))
|
||||
return self.Resolved(
|
||||
self.item_name_group,
|
||||
item_names,
|
||||
count=resolve_field(self.count, world, int),
|
||||
count=count,
|
||||
player=world.player,
|
||||
caching_enabled=getattr(world, "rule_caching_enabled", False),
|
||||
)
|
||||
@@ -1731,11 +1737,16 @@ class HasGroupUnique(Rule[TWorld], game="Archipelago"):
|
||||
|
||||
@override
|
||||
def _instantiate(self, world: TWorld) -> Rule.Resolved:
|
||||
count = resolve_field(self.count, world, int)
|
||||
if count <= 0:
|
||||
return True_().resolve(world)
|
||||
item_names = tuple(sorted(world.item_name_groups[self.item_name_group]))
|
||||
if len(item_names) < count:
|
||||
return False_().resolve(world)
|
||||
return self.Resolved(
|
||||
self.item_name_group,
|
||||
item_names,
|
||||
count=resolve_field(self.count, world, int),
|
||||
count=count,
|
||||
player=world.player,
|
||||
caching_enabled=getattr(world, "rule_caching_enabled", False),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user