(Underdepth) Pass 3
This commit is contained in:
30 files changed
+4151
No files matched your search
@@ -0,0 +1,90 @@
|
||||
"""Player: stats, inventory, equipment, leveling, effect timers."""
|
||||
|
||||
from __future__ import annotations
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
from entities.entity import Entity
|
||||
from data.constants import (
|
||||
XP_THRESHOLDS, LEVEL_HP_GAINS, LEVEL_POWER_GAINS, MAX_LEVEL, STRENGTH_POWER_BONUS,
|
||||
)
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class Player(Entity):
|
||||
hp: int = 50
|
||||
max_hp: int = 50
|
||||
power: int = 4
|
||||
armor: int = 0
|
||||
accuracy: int = 5
|
||||
evasion: int = 2
|
||||
crit_chance: float = 0.10
|
||||
speed: int = 1
|
||||
level: int = 1
|
||||
xp: int = 0
|
||||
inventory: list = field(default_factory=list)
|
||||
weapon: Any = None
|
||||
armor_item: Any = None
|
||||
timers: dict = field(default_factory=dict)
|
||||
|
||||
@property
|
||||
def effective_power(self) -> int:
|
||||
bonus = STRENGTH_POWER_BONUS if self.timers.get("strength", 0) > 0 else 0
|
||||
return self.power + (self.weapon.power if self.weapon is not None else 0) + bonus
|
||||
|
||||
@property
|
||||
def effective_armor(self) -> int:
|
||||
return self.armor + (self.armor_item.armor if self.armor_item is not None else 0)
|
||||
|
||||
@property
|
||||
def effective_accuracy(self) -> int:
|
||||
return self.accuracy
|
||||
|
||||
@property
|
||||
def effective_evasion(self) -> float:
|
||||
base = self.evasion
|
||||
if self.armor_item is not None:
|
||||
base += self.armor_item.evasion_delta
|
||||
return base
|
||||
|
||||
@property
|
||||
def effective_crit_chance(self) -> float:
|
||||
base = self.crit_chance
|
||||
if self.weapon is not None:
|
||||
base += self.weapon.crit_delta
|
||||
return base
|
||||
|
||||
def equip_item(self, item: Any) -> None:
|
||||
if item.kind == "weapon":
|
||||
if self.weapon is not None:
|
||||
self.inventory.append(self.weapon)
|
||||
self.weapon = item
|
||||
elif item.kind == "armor":
|
||||
if self.armor_item is not None:
|
||||
self.inventory.append(self.armor_item)
|
||||
self.armor_item = item
|
||||
|
||||
def gain_xp(self, amount: int, log: list[str]) -> None:
|
||||
self.xp += amount
|
||||
while self.level < MAX_LEVEL and self.xp >= XP_THRESHOLDS[self.level - 1]:
|
||||
idx = self.level - 1
|
||||
hp_gain = LEVEL_HP_GAINS[idx]
|
||||
pow_gain = LEVEL_POWER_GAINS[idx]
|
||||
self.level += 1
|
||||
self.max_hp += hp_gain
|
||||
self.power += pow_gain
|
||||
self.hp = self.max_hp
|
||||
log.append(f"You reach level {self.level}! (HP +{hp_gain}, Power +{pow_gain})")
|
||||
|
||||
def tick_timers(self, log: list[str]) -> None:
|
||||
expired = []
|
||||
for name in self.timers:
|
||||
self.timers[name] -= 1
|
||||
if self.timers[name] <= 0:
|
||||
expired.append(name)
|
||||
for name in expired:
|
||||
del self.timers[name]
|
||||
if name == "strength":
|
||||
log.append("Your surge of strength fades.")
|
||||
elif name == "invisibility":
|
||||
log.append("You flicker back into view.")
|
||||
Reference in new issue
Block a user