Skip to content

Commit

Permalink
move to stage_pre_fill
Browse files Browse the repository at this point in the history
  • Loading branch information
qwint committed May 5, 2024
1 parent 8295311 commit 34fbab1
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions worlds/hk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,42 +444,48 @@ def set_rules(self):
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()
pass # will set in stage_pre_fill()
else:
# Any goal
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)

set_rules(self)

def pre_fill(self):
grub_hunt_goal = self.options.GrubHuntGoal
goal = self.options.Goal
if goal in ["any", "grub_hunt"]:
def stage_pre_fill(multiworld: "MultiWorld"):
cls = HKWorld
worlds = [world for world in multiworld.get_game_worlds(cls.game) if world.options.Goal in ["any", "grub_hunt"]]
if worlds:
grubs = [item for item in multiworld.get_items() if item.name == "Grub"]

for world in worlds:
player = world.player
grub_hunt_goal = world.options.GrubHuntGoal

def set_goal(grub_rule: typing.Callable[[CollectionState], bool]):
if goal == "grub_hunt":
self.multiworld.completion_condition[self.player] = grub_rule
if world.options.Goal == "grub_hunt":
multiworld.completion_condition[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)
old_rule = multiworld.completion_condition[player]
multiworld.completion_condition[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)
relevant_groups = multiworld.get_player_groups(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})
for grub in grubs:
if grub.player in relevant_groups or grub.player == player:
grub_player_count[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
world.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))
world.grub_count = grub_hunt_goal.value
set_goal(lambda state: state.has("Grub", player, world.grub_count))

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

0 comments on commit 34fbab1

Please sign in to comment.