Skip to content

Commit

Permalink
account for 'any' goal and fix overriding non-grub goals
Browse files Browse the repository at this point in the history
  • Loading branch information
qwint committed May 5, 2024
1 parent b3e04e4 commit e4ded1e
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions worlds/hk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,31 +447,39 @@ def set_rules(self):
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)
world.completion_condition[player] = lambda state: state._hk_can_beat_thk(player) or state._hk_can_beat_radiance(player) or state.count("Defeated_Pantheon_5", player) or state.count("Godhome_Flower_Quest", player)

set_rules(self)

def pre_fill(self):
grub_hunt_goal = self.options.GrubHuntGoal
if grub_hunt_goal == grub_hunt_goal.special_range_names["all"]:
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()])
else:
self.grub_count = grub_hunt_goal.value
self.multiworld.completion_condition[self.player] = lambda state: state.has("Grub", self.player, self.grub_count)
goal = self.options.Goal
if goal in ["any", "grub_hunt"]:
def set_goal(grub_rule: Callable[[CollectionState], bool]):
if goal == "grub_hunt":
self.multiworld.completion_condition[self.player] = grub_rule
else:
old_rule = self.multiworld.completion_condition[self.player]
self.multiworld.completion_condition[self.player] = lambda state: old_rule(state) or grub_rule(state)

if grub_hunt_goal == grub_hunt_goal.special_range_names["all"]:
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

set_goal(lambda state, g=grub_player_count: all([state.has("Grub", player, count) for player, count in g.items()]))
else:
self.grub_count = grub_hunt_goal.value
set_goal(lambda state: state.has("Grub", self.player, self.grub_count))

def fill_slot_data(self):
slot_data = {}
Expand Down

0 comments on commit e4ded1e

Please sign in to comment.