(Underdepths) Pass 4
This commit is contained in:
1 parent
a219ad17d5
commit
6147ab3121
29 files changed
+4888
No files matched your search
@@ -0,0 +1,87 @@
|
||||
"""The player adventurer: stats, inventory, equipment, leveling."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from data import constants as C
|
||||
from entities.entity import Entity
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class Effect:
|
||||
"""A timed status effect on the player (plan.md §6 potions).
|
||||
|
||||
`kind` is "strength" (+power) or "invisibility". `duration` is turns left;
|
||||
actions.tick decrements it and expires the effect at 0.
|
||||
"""
|
||||
kind: str
|
||||
power: int = 0
|
||||
duration: int = 0
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class Player(Entity):
|
||||
name: str = "You"
|
||||
sprite_key: str = "player"
|
||||
# stats
|
||||
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
|
||||
# progression
|
||||
level: int = 1
|
||||
xp: int = 0
|
||||
# gear / effects
|
||||
inventory: list = field(default_factory=list)
|
||||
equipped: dict = field(default_factory=dict)
|
||||
effects: list = field(default_factory=list)
|
||||
facing: str = "down"
|
||||
invisible: bool = False
|
||||
# transient: level-up messages the game loop flushes into the session log
|
||||
pending_log: list = field(default_factory=list)
|
||||
|
||||
def total_power(self) -> int:
|
||||
"""Base power + equipped weapon bonus + active strength effect."""
|
||||
p = self.power
|
||||
weapon = self.equipped.get("weapon")
|
||||
if weapon is not None and hasattr(weapon, "stats"):
|
||||
p += weapon.stats.get("power", 0)
|
||||
for eff in self.effects:
|
||||
if getattr(eff, "kind", None) == "strength":
|
||||
p += getattr(eff, "power", 0)
|
||||
return int(p)
|
||||
|
||||
def total_armor(self) -> int:
|
||||
"""Base armor + equipped armor bonus."""
|
||||
a = self.armor
|
||||
armor = self.equipped.get("armor")
|
||||
if armor is not None and hasattr(armor, "stats"):
|
||||
a += armor.stats.get("armor", 0)
|
||||
return int(a)
|
||||
|
||||
def gain_xp(self, amount: int) -> bool:
|
||||
"""Award XP, applying chained level-ups from the plan table.
|
||||
|
||||
Fully heals and raises max_hp/power on each level-up. Level-up lines
|
||||
are buffered into `pending_log` for the game loop to flush. Returns
|
||||
True if any level-up occurred.
|
||||
"""
|
||||
self.xp += amount
|
||||
levelled = False
|
||||
while self.level < C.MAX_LEVEL and self.xp >= C.XP_THRESHOLDS[self.level + 1]:
|
||||
new_level = self.level + 1
|
||||
hp_gain = C.LEVEL_HP_GAIN[new_level]
|
||||
pow_gain = C.LEVEL_POWER_GAIN[new_level]
|
||||
self.level = new_level
|
||||
self.max_hp += hp_gain
|
||||
self.power += pow_gain
|
||||
self.hp = self.max_hp
|
||||
levelled = True
|
||||
self.pending_log.append(
|
||||
f"You reach level {self.level}! (HP +{hp_gain}, Power +{pow_gain})"
|
||||
)
|
||||
return levelled
|
||||
Reference in new issue
Block a user