Convert the passive healing clock to a more granular tick mechanism
Instead of counting turns, count clock ticks. A WaitAction adds 10 ticks to the passive healing clock and a WalkAction adds 5. So, you will heal while walking but at a slower rate.
This commit is contained in:
parent
31bec25dcf
commit
99838cbd00
2 changed files with 34 additions and 13 deletions
|
@ -182,6 +182,13 @@ class WalkAction(MoveAction):
|
||||||
log.ACTIONS.debug('Moving %s to %s', self.actor, new_position)
|
log.ACTIONS.debug('Moving %s to %s', self.actor, new_position)
|
||||||
self.actor.position = new_position
|
self.actor.position = new_position
|
||||||
|
|
||||||
|
try:
|
||||||
|
should_recover_hit_points = self.actor.fighter.passively_recover_hit_points(5)
|
||||||
|
if should_recover_hit_points:
|
||||||
|
return ActionResult(self, alternate=HealAction(self.actor, 1))
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
return self.success()
|
return self.success()
|
||||||
|
|
||||||
class MeleeAction(MoveAction):
|
class MeleeAction(MoveAction):
|
||||||
|
@ -223,7 +230,7 @@ class WaitAction(Action):
|
||||||
log.ACTIONS.debug('%s is waiting a turn', self.actor)
|
log.ACTIONS.debug('%s is waiting a turn', self.actor)
|
||||||
|
|
||||||
if self.actor == engine.hero:
|
if self.actor == engine.hero:
|
||||||
should_recover_hit_points = self.actor.fighter.passively_recover_hit_points()
|
should_recover_hit_points = self.actor.fighter.passively_recover_hit_points(10)
|
||||||
if should_recover_hit_points:
|
if should_recover_hit_points:
|
||||||
return ActionResult(self, alternate=HealAction(self.actor, 1))
|
return ActionResult(self, alternate=HealAction(self.actor, 1))
|
||||||
|
|
||||||
|
@ -273,4 +280,4 @@ class HealAction(Action):
|
||||||
|
|
||||||
fighter.hit_points += self.hit_points_to_recover
|
fighter.hit_points += self.hit_points_to_recover
|
||||||
|
|
||||||
return self.success()
|
return self.success()
|
||||||
|
|
|
@ -26,12 +26,15 @@ class Fighter(Component):
|
||||||
def __init__(self, *, maximum_hit_points: int, attack_power: int, defense: int, hit_points: Optional[int] = None):
|
def __init__(self, *, maximum_hit_points: int, attack_power: int, defense: int, hit_points: Optional[int] = None):
|
||||||
self.maximum_hit_points = maximum_hit_points
|
self.maximum_hit_points = maximum_hit_points
|
||||||
self.__hit_points = hit_points if hit_points else maximum_hit_points
|
self.__hit_points = hit_points if hit_points else maximum_hit_points
|
||||||
|
|
||||||
# TODO: Rename these two attributes something better
|
# TODO: Rename these two attributes something better
|
||||||
self.attack_power = attack_power
|
self.attack_power = attack_power
|
||||||
self.defense = defense
|
self.defense = defense
|
||||||
|
|
||||||
self.turns_since_last_heal = 0
|
# TODO: Factor this out into a dedicated Clock class
|
||||||
self.turn_for_next_passive_heal = random.randint(3, 7)
|
self.__ticks_since_last_passive_heal = 0
|
||||||
|
self.__ticks_for_next_passive_heal = 0
|
||||||
|
self._reset_passive_heal_clock()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hit_points(self) -> int:
|
def hit_points(self) -> int:
|
||||||
|
@ -47,16 +50,27 @@ class Fighter(Component):
|
||||||
'''True if the Fighter has died, i.e. reached 0 hit points'''
|
'''True if the Fighter has died, i.e. reached 0 hit points'''
|
||||||
return self.__hit_points == 0
|
return self.__hit_points == 0
|
||||||
|
|
||||||
def passively_recover_hit_points(self) -> bool:
|
def passively_recover_hit_points(self, number_of_ticks: int) -> bool:
|
||||||
'''Check the passive healing clock to see if this fighter should recover hit points. If not, increment the
|
'''
|
||||||
counter.'''
|
Check the passive healing clock to see if this fighter should recover hit points. If not, increment the
|
||||||
if self.hit_points == self.maximum_hit_points:
|
counter.
|
||||||
self.turns_since_last_heal = 0
|
|
||||||
|
|
||||||
if self.turns_since_last_heal < self.turn_for_next_passive_heal:
|
Arguments
|
||||||
self.turns_since_last_heal += 1
|
---------
|
||||||
|
number_of_ticks : int
|
||||||
|
The number of ticks to increment the clock
|
||||||
|
'''
|
||||||
|
if self.hit_points == self.maximum_hit_points:
|
||||||
|
self.__ticks_since_last_passive_heal = 0
|
||||||
|
|
||||||
|
if self.__ticks_since_last_passive_heal < self.__ticks_for_next_passive_heal:
|
||||||
|
self.__ticks_since_last_passive_heal += number_of_ticks
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.turns_since_last_heal = 0
|
self._reset_passive_heal_clock()
|
||||||
self.turn_for_next_passive_heal = random.randint(3, 7)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _reset_passive_heal_clock(self) -> None:
|
||||||
|
self.__ticks_since_last_passive_heal = 0
|
||||||
|
self.__ticks_for_next_passive_heal = random.randint(30, 70)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue