Implement passive healing

This commit is contained in:
Eryn Wells 2022-05-15 16:19:03 -07:00
parent ccd2e04d0e
commit 4e585a2650
3 changed files with 43 additions and 2 deletions

View file

@ -1,8 +1,9 @@
# Eryn Wells <eryn@erynwells.me>
import random
from typing import Optional
# pylint: disable=too-few-public-methods
class Component:
'''A base, abstract Component that implement some aspect of an Entity's behavior.'''
@ -29,6 +30,9 @@ class Fighter(Component):
self.attack_power = attack_power
self.defense = defense
self.turns_since_last_heal = 0
self.turn_for_next_passive_heal = random.randint(3, 7)
@property
def hit_points(self) -> int:
'''Number of hit points remaining. When a Fighter reaches 0 hit points, they die.'''
@ -42,3 +46,17 @@ class Fighter(Component):
def is_dead(self) -> bool:
'''True if the Fighter has died, i.e. reached 0 hit points'''
return self.__hit_points == 0
def passively_recover_hit_points(self) -> bool:
'''Check the passive healing clock to see if this fighter should recover hit points. If not, increment the
counter.'''
if self.hit_points == self.maximum_hit_points:
self.turns_since_last_heal = 0
if self.turns_since_last_heal < self.turn_for_next_passive_heal:
self.turns_since_last_heal += 1
return False
self.turns_since_last_heal = 0
self.turn_for_next_passive_heal = random.randint(3, 7)
return True