(Underdepths) Pass 6
This commit is contained in:
28 files changed
+5639
-31
No files matched your search
@@ -0,0 +1,72 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from data.constants import (
|
||||
PLAYER_ACCURACY,
|
||||
PLAYER_ARMOR,
|
||||
PLAYER_CRIT_CHANCE,
|
||||
PLAYER_EVASION,
|
||||
PLAYER_MAX_HP,
|
||||
PLAYER_POWER,
|
||||
PLAYER_SPEED,
|
||||
STRENGTH_BONUS,
|
||||
)
|
||||
from entities.entity import Entity
|
||||
from entities.item import Item
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class Player(Entity):
|
||||
name: str = "Player"
|
||||
sprite_key: str = "player"
|
||||
hp: int = PLAYER_MAX_HP
|
||||
max_hp: int = PLAYER_MAX_HP
|
||||
power: int = PLAYER_POWER
|
||||
armor: int = PLAYER_ARMOR
|
||||
accuracy: int = PLAYER_ACCURACY
|
||||
evasion: int = PLAYER_EVASION
|
||||
crit_chance: float = PLAYER_CRIT_CHANCE
|
||||
speed: int = PLAYER_SPEED
|
||||
level: int = 1
|
||||
xp: int = 0
|
||||
inventory: list[Item] = field(default_factory=list)
|
||||
equipped_weapon: Item | None = None
|
||||
equipped_armor: Item | None = None
|
||||
strength_turns: int = 0
|
||||
invisible_turns: int = 0
|
||||
|
||||
@property
|
||||
def total_power(self) -> int:
|
||||
bonus = self.equipped_weapon.power if self.equipped_weapon else 0
|
||||
if self.strength_turns > 0:
|
||||
bonus += STRENGTH_BONUS
|
||||
return self.power + bonus
|
||||
|
||||
@property
|
||||
def total_armor(self) -> int:
|
||||
return self.armor + (self.equipped_armor.armor if self.equipped_armor else 0)
|
||||
|
||||
@property
|
||||
def total_evasion(self) -> int:
|
||||
return self.evasion + (self.equipped_armor.evasion_modifier if self.equipped_armor else 0)
|
||||
|
||||
@property
|
||||
def total_crit(self) -> float:
|
||||
return max(
|
||||
0.0,
|
||||
self.crit_chance + (self.equipped_weapon.crit_modifier if self.equipped_weapon else 0.0),
|
||||
)
|
||||
|
||||
@property
|
||||
def is_invisible(self) -> bool:
|
||||
return self.invisible_turns > 0
|
||||
|
||||
@property
|
||||
def alive(self) -> bool:
|
||||
return self.hp > 0
|
||||
|
||||
def heal(self, amount: int) -> int:
|
||||
old_hp = self.hp
|
||||
self.hp = min(self.max_hp, self.hp + max(0, amount))
|
||||
return self.hp - old_hp
|
||||
Reference in new issue
Block a user