From 6629c21a61b1434d7250aab9865f961052d5f72a Mon Sep 17 00:00:00 2001 From: qwint Date: Tue, 23 Apr 2024 13:44:50 -0500 Subject: [PATCH] makes grub hunt goal option that calculates the total available grubs (including item link replacements) and requires all of them to be gathered for goal completion --- worlds/hk/Options.py | 1 + worlds/hk/__init__.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/worlds/hk/Options.py b/worlds/hk/Options.py index f7b4420c7447..1885632f7805 100644 --- a/worlds/hk/Options.py +++ b/worlds/hk/Options.py @@ -399,6 +399,7 @@ class Goal(Choice): option_radiance = 3 option_godhome = 4 option_godhome_flower = 5 + option_grub_hunt = 6 default = 0 diff --git a/worlds/hk/__init__.py b/worlds/hk/__init__.py index 4057cded9a5b..cab75c1e068c 100644 --- a/worlds/hk/__init__.py +++ b/worlds/hk/__init__.py @@ -154,6 +154,7 @@ class HKWorld(World): ranges: typing.Dict[str, typing.Tuple[int, int]] charm_costs: typing.List[int] cached_filler_items = {} + grub_count: int data_version = 2 def __init__(self, world, player): @@ -164,6 +165,7 @@ def __init__(self, world, player): self.ranges = {} self.created_shop_items = 0 self.vanilla_shop_costs = deepcopy(vanilla_shop_costs) + self.grub_count = 0 def generate_early(self): world = self.multiworld @@ -441,12 +443,32 @@ def set_rules(self): world.completion_condition[player] = lambda state: state.count("Defeated_Pantheon_5", player) elif goal == Goal.option_godhome_flower: world.completion_condition[player] = lambda state: state.count("Godhome_Flower_Quest", player) + elif goal == Goal.option_grub_hunt: + pass # will set in pre_fill() else: # Any goal world.completion_condition[player] = lambda state: state._hk_can_beat_thk(player) or state._hk_can_beat_radiance(player) set_rules(self) + def pre_fill(self): + if self.options.Goal == "grub_hunt": + from collections import Counter + relevant_groups = self.multiworld.get_player_groups(self.player) + grub_player_count = Counter() + + for grub in [item for item in self.multiworld.get_items() if item.name == "Grub"]: + if grub.player in relevant_groups or grub.player == self.player: + grub_player_count += Counter({grub.player: 1}) + if grub.location and grub.location.player in relevant_groups: + # not counting our grubs stuck in item links because we also will count the group's copy + pass + else: + self.grub_count += 1 + + self.multiworld.completion_condition[self.player] = lambda state, g=grub_player_count: \ + all([state.has("Grub", player, count) for player, count in g.items()]) + def fill_slot_data(self): slot_data = {} @@ -484,6 +506,8 @@ def fill_slot_data(self): slot_data["notch_costs"] = self.charm_costs + slot_data["grub_count"] = self.grub_count + return slot_data def create_item(self, name: str) -> HKItem: