Calculate defense and power based on equipment
This commit is contained in:
parent
aa0b19ca59
commit
359258862d
@ -13,11 +13,11 @@ if TYPE_CHECKING:
|
||||
class Fighter(BaseComponent):
|
||||
parent: Actor
|
||||
|
||||
def __init__(self, hp: int, defense: int, power: int):
|
||||
def __init__(self, hp: int, base_defense: int, base_power: int):
|
||||
self.max_hp = hp
|
||||
self._hp = hp
|
||||
self.defense = defense
|
||||
self.power = power
|
||||
self.base_defense = base_defense
|
||||
self.base_power = base_power
|
||||
|
||||
@property
|
||||
def hp(self) -> int:
|
||||
@ -29,6 +29,28 @@ class Fighter(BaseComponent):
|
||||
if self._hp == 0 and self.parent.ai:
|
||||
self.die()
|
||||
|
||||
@property
|
||||
def defense(self) -> int:
|
||||
return self.base_defense + self.defense_bonus
|
||||
|
||||
@property
|
||||
def power(self) -> int:
|
||||
return self.base_power + self.power_bonus
|
||||
|
||||
@property
|
||||
def defense_bonus(self) -> int:
|
||||
if self.parent.equipment:
|
||||
return self.parent.equipment.defense_bonuse
|
||||
else:
|
||||
return 0
|
||||
|
||||
@property
|
||||
def power_bonus(self) -> int:
|
||||
if self.parent.equipment:
|
||||
return self.parent.equipment.power_bonus
|
||||
else:
|
||||
return 0
|
||||
|
||||
def die(self) -> None:
|
||||
if self.engine.player is self.parent:
|
||||
death_message = "You died!"
|
||||
|
@ -60,14 +60,14 @@ class Level(BaseComponent):
|
||||
self.increase_level()
|
||||
|
||||
def increase_power(self, amount: int = 1) -> None:
|
||||
self.parent.fighter.power += amount
|
||||
self.parent.fighter.base_power += amount
|
||||
|
||||
self.engine.message_log.add_message("You feel stronger!")
|
||||
|
||||
self.increase_level()
|
||||
|
||||
def increase_defense(self, amount: int = 1) -> None:
|
||||
self.parent.fighter.defense += amount
|
||||
self.parent.fighter.base_defense += amount
|
||||
|
||||
self.engine.message_log.add_message("Your movements are getting swifter!")
|
||||
|
||||
|
@ -12,7 +12,7 @@ player = Actor(
|
||||
name="Player",
|
||||
ai_cls=HostileEnemy,
|
||||
equipment=Equipment(),
|
||||
fighter=Fighter(hp=30, defense=2, power=5),
|
||||
fighter=Fighter(hp=30, base_defense=1, base_power=2),
|
||||
inventory=Inventory(capacity=26),
|
||||
level=Level(level_up_base=200),
|
||||
)
|
||||
@ -23,7 +23,7 @@ orc = Actor(
|
||||
name="Orc",
|
||||
ai_cls=HostileEnemy,
|
||||
equipment=Equipment(),
|
||||
fighter=Fighter(hp=10, defense=0, power=3),
|
||||
fighter=Fighter(hp=10, base_defense=0, base_power=3),
|
||||
inventory=Inventory(capacity=0),
|
||||
level=Level(xp_given=35),
|
||||
)
|
||||
@ -33,7 +33,7 @@ troll = Actor(
|
||||
name="Troll",
|
||||
ai_cls=HostileEnemy,
|
||||
equipment=Equipment(),
|
||||
fighter=Fighter(hp=16, defense=1, power=4),
|
||||
fighter=Fighter(hp=16, base_defense=1, base_power=4),
|
||||
inventory=Inventory(capacity=0),
|
||||
level=Level(xp_given=100),
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user