Skip to content

Commit

Permalink
refactor collect/remove
Browse files Browse the repository at this point in the history
  • Loading branch information
qwint committed Aug 1, 2024
1 parent 8826f7a commit 0b6d7eb
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions worlds/hk_rework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,17 @@ def edit_effects(state, player: int, item: str, add: bool):
if state.prog_items[player][effect_name] < 1:
del (state.prog_items[player][effect_name])

@staticmethod
def set_resource_thresholds(prog_items, item_name):
if item_name == "Vessel_Fragment":
prog_items["TOTAL_SOUL"] = 12 + (4 * int(prog_items["Vessel_Fragment"] / 3))
elif item_name == "Mask_Shard":
prog_items["TOTAL_HEALTH"] = 4 + (4 * int(prog_items["Mask_Shard"] / 4))
prog_items["SHADE_HEALTH"] = max(int(prog_items["TOTAL_HEALTH"]/2), 1)
elif item_name == "Charm_Notch":
# TODO consider switching to += 1
prog_items["TOTAL_NOTCHES"] = 3 + prog_items["Charm_Notch"]

def collect(self, state, item: HKItem) -> bool:
change = super(HKWorld, self).collect(state, item)
if change:
Expand All @@ -997,15 +1008,7 @@ def collect(self, state, item: HKItem) -> bool:
([max(prog_items["RIGHTDASH"], prog_items["LEFTDASH"])] * 2)
else:
self.edit_effects(state, item.player, item.name, add=True)

if item.name == "Vessel_Fragment":
prog_items["TOTAL_SOUL"] = 12 + (4 * int(prog_items["Vessel_Fragment"] / 3))
if item.name == "Mask_Shard":
prog_items["TOTAL_HEALTH"] = 4 + (4 * int(prog_items["Mask_Shard"] / 4))
prog_items["SHADE_HEALTH"] = max(int(prog_items["TOTAL_HEALTH"]/2), 1)
if item.name == "Charm_Notch":
# TODO consider switching to += 1
prog_items["TOTAL_NOTCHES"] = 3 + prog_items["Charm_Notch"]
self.set_resource_thresholds(prog_items, item.name)
return change

def remove(self, state, item: HKItem) -> bool:
Expand All @@ -1031,14 +1034,7 @@ def remove(self, state, item: HKItem) -> bool:
else:
self.edit_effects(state, item.player, item.name, add=False)

if item.name == "Vessel_Fragment":
prog_items["TOTAL_SOUL"] = 12 + (4 * int(prog_items["Vessel_Fragment"] / 3))
if item.name == "Mask_Shard":
prog_items["TOTAL_HEALTH"] = 4 + (4 * int(prog_items["Mask_Shard"] / 4))
prog_items["SHADE_HEALTH"] = max(int(prog_items["TOTAL_HEALTH"]/2), 1)
if item.name == "Charm_Notch":
# TODO consider switching to -= 1
prog_items["TOTAL_NOTCHES"] = 3 + prog_items["Charm_Notch"]
self.set_resource_thresholds(prog_items, item.name)
return change

def fill_slot_data(self):
Expand Down

0 comments on commit 0b6d7eb

Please sign in to comment.