Added critical hit system: the player and rabbit entities have a chance of making x4 damage! Closes #52

This commit is contained in:
eichhornchen
2021-01-05 19:07:15 +01:00
parent c01307202a
commit 9b8dfb00da
3 changed files with 16 additions and 8 deletions

View File

@ -403,11 +403,12 @@ class FightingEntity(Entity):
dexterity: int
constitution: int
level: int
critical: int
def __init__(self, maxhealth: int = 0, health: Optional[int] = None,
strength: int = 0, intelligence: int = 0, charisma: int = 0,
dexterity: int = 0, constitution: int = 0, level: int = 0,
*args, **kwargs) -> None:
critical: int = 0, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.maxhealth = maxhealth
self.health = maxhealth if health is None else health
@ -417,6 +418,7 @@ class FightingEntity(Entity):
self.dexterity = dexterity
self.constitution = constitution
self.level = level
self.critical = critical
@property
def dead(self) -> bool:
@ -426,10 +428,16 @@ class FightingEntity(Entity):
"""
Deals damage to the opponent, based on the stats
"""
diceroll = randint(0, 100)
damage = self.strength
string = " "
if diceroll <= self.critical: # It is a critical hit
damage *= 4
string = _(" It's a critical hit! ")
return _("{name} hits {opponent}.")\
.format(name=_(self.translated_name.capitalize()),
opponent=_(opponent.translated_name)) + " " + \
opponent.take_damage(self, self.strength)
opponent=_(opponent.translated_name)) + string + \
opponent.take_damage(self, damage)
def take_damage(self, attacker: "Entity", amount: int) -> str:
"""