Skip to content

Commit

Permalink
not the best solution but will work in any unforseen situation as rem…
Browse files Browse the repository at this point in the history
…ove just recalculates what collect would have done to get to the state it is at
  • Loading branch information
qwint committed Sep 20, 2024
1 parent 42ba6a8 commit 01a4c56
Showing 1 changed file with 46 additions and 12 deletions.
58 changes: 46 additions & 12 deletions worlds/hk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,27 +596,61 @@ def create_vanilla_location(self, location: str, item: Item):
location.costs = costs.pop()
return location

def edit_effects(self, state, item_name, player, add: bool):
for effect_name, effect_value in item_effects.get(item_name, {}).items():
if add:
state.prog_items[player][effect_name] += effect_value
else:
state.prog_items[player][effect_name] -= effect_value
if state.prog_items[player][effect_name] < 1:
del state.prog_items[player][effect_name]

def collect(self, state, item: HKItem) -> bool:
change = super(HKWorld, self).collect(state, item)
if change:
for effect_name, effect_value in item_effects.get(item.name, {}).items():
state.prog_items[item.player][effect_name] += effect_value
prog_items = state.prog_items[item.player]
if item.name in {"Left_Mothwing_Cloak", "Right_Mothwing_Cloak"}:
if state.prog_items[item.player].get('RIGHTDASH', 0) and \
state.prog_items[item.player].get('LEFTDASH', 0):
(state.prog_items[item.player]["RIGHTDASH"], state.prog_items[item.player]["LEFTDASH"]) = \
([max(state.prog_items[item.player]["RIGHTDASH"], state.prog_items[item.player]["LEFTDASH"])] * 2)
# # reset dash effects to 0 and recalc
# prog_items['RIGHTDASH'] = 0
# prog_items['LEFTDASH'] = 0
# for _ in range(prog_items["Right_Mothwing_Cloak"]):
# self.edit_effects(state, "Right_Mothwing_Cloak", item.player, add=True)
# for _ in range(prog_items["Left_Mothwing_Cloak"]):
# self.edit_effects(state, "Left_Mothwing_Cloak", item.player, add=True)

# should just be able to add the new effect
self.edit_effects(state, item.name, item.player, add=True)

# if we have both cloaks keep them in step to account for shade cloak
if prog_items.get('RIGHTDASH', 0) and \
prog_items.get('LEFTDASH', 0):
(prog_items["RIGHTDASH"], prog_items["LEFTDASH"]) = \
([max(prog_items["RIGHTDASH"], prog_items["LEFTDASH"])] * 2)
else:
self.edit_effects(state, item.name, item.player, add=True)

return change

def remove(self, state, item: HKItem) -> bool:
change = super(HKWorld, self).remove(state, item)

if change:
for effect_name, effect_value in item_effects.get(item.name, {}).items():
if state.prog_items[item.player][effect_name] == effect_value:
del state.prog_items[item.player][effect_name]
else:
state.prog_items[item.player][effect_name] -= effect_value
prog_items = state.prog_items[item.player]
if item.name in {"Left_Mothwing_Cloak", "Right_Mothwing_Cloak"}:
# reset dash effects to 0 and recalc
prog_items['RIGHTDASH'] = 0
prog_items['LEFTDASH'] = 0
for _ in range(prog_items["Right_Mothwing_Cloak"]):
self.edit_effects(state, "Right_Mothwing_Cloak", item.player, add=True)
for _ in range(prog_items["Left_Mothwing_Cloak"]):
self.edit_effects(state, "Left_Mothwing_Cloak", item.player, add=True)

# if we have both cloaks keep them in step to account for shade cloak
if prog_items.get('RIGHTDASH', 0) and \
prog_items.get('LEFTDASH', 0):
(prog_items["RIGHTDASH"], prog_items["LEFTDASH"]) = \
([max(prog_items["RIGHTDASH"], prog_items["LEFTDASH"])] * 2)
else:
self.edit_effects(state, item.name, item.player, add=False)

return change

Expand Down

0 comments on commit 01a4c56

Please sign in to comment.