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

@ -87,9 +87,9 @@ class Rabbit(Monster):
A rabbit monster
"""
def __init__(self, name: str = "rabbit", strength: int = 1,
maxhealth: int = 15, *args, **kwargs) -> None:
maxhealth: int = 15, critical: int = 30, *args, **kwargs) -> None:
super().__init__(name=name, strength=strength,
maxhealth=maxhealth, *args, **kwargs)
maxhealth=maxhealth, critical=critical, *args, **kwargs)
class TeddyBear(Monster):

View File

@ -25,12 +25,12 @@ class Player(InventoryHolder, FightingEntity):
dexterity: int = 1, constitution: int = 1, level: int = 1,
current_xp: int = 0, max_xp: int = 10, inventory: list = None,
hazel: int = 42, equipped_item: Optional[Item] = None,
equipped_armor: Optional[Item] = None, *args, **kwargs) \
-> None:
equipped_armor: Optional[Item] = None, critical: int = 5,\
*args, **kwargs) -> None:
super().__init__(name=name, maxhealth=maxhealth, strength=strength,
intelligence=intelligence, charisma=charisma,
dexterity=dexterity, constitution=constitution,
level=level, *args, **kwargs)
level=level, critical=critical, *args, **kwargs)
self.current_xp = current_xp
self.max_xp = max_xp
self.inventory = self.translate_inventory(inventory or [])

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:
"""