(Underdepth) Prepare for Pass 5
This commit is contained in:
1 parent
6147ab3121
commit
05e340dec2
29 files changed
-4888
No files matched your search
Whitespace-only changes.
@@ -1,85 +0,0 @@
|
||||
"""Enemy entities and the full stat roster from plan.md §Enemy Roster."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from entities.entity import Entity
|
||||
|
||||
ENEMY_KINDS: list[str] = [
|
||||
"rat", "goblin", "skeleton_archer", "orc_warrior",
|
||||
"wraith", "green_slime", "ancient_dragon",
|
||||
]
|
||||
|
||||
# kind -> full roster. `floors` is the (min, max) depth gate from plan.md.
|
||||
# `ranged` is ranged_power (skeleton bolt / dragon breath); 0 = no ranged.
|
||||
_ROSTER: dict[str, dict] = {
|
||||
"rat": dict(
|
||||
name="Rat", hp=8, power=3, armor=0, accuracy=4, evasion=2, crit=0.05,
|
||||
speed=1, behavior="wander", xp=5, ranged=0, floors=(0, 3),
|
||||
),
|
||||
"goblin": dict(
|
||||
name="Goblin", hp=15, power=5, armor=1, accuracy=5, evasion=1, crit=0.05,
|
||||
speed=1, behavior="chase", xp=12, ranged=0, floors=(0, 5),
|
||||
),
|
||||
"skeleton_archer": dict(
|
||||
name="Skeleton Archer", hp=12, power=4, armor=1, accuracy=6, evasion=1, crit=0.10,
|
||||
speed=1, behavior="ranged", xp=15, ranged=6, floors=(2, 7),
|
||||
),
|
||||
"orc_warrior": dict(
|
||||
name="Orc Warrior", hp=30, power=8, armor=3, accuracy=5, evasion=0, crit=0.10,
|
||||
speed=1, behavior="flee", xp=25, ranged=0, floors=(3, 8),
|
||||
),
|
||||
"wraith": dict(
|
||||
name="Wraith", hp=20, power=10, armor=0, accuracy=6, evasion=3, crit=0.10,
|
||||
speed=2, behavior="phase", xp=30, ranged=0, floors=(5, 8),
|
||||
),
|
||||
"green_slime": dict(
|
||||
name="Green Slime", hp=18, power=5, armor=1, accuracy=4, evasion=0, crit=0.05,
|
||||
speed=1, behavior="split", xp=18, ranged=0, floors=(4, 8),
|
||||
),
|
||||
"ancient_dragon": dict(
|
||||
name="Ancient Dragon", hp=120, power=15, armor=8, accuracy=7, evasion=0, crit=0.15,
|
||||
speed=1, behavior="chase", xp=200, ranged=15, floors=(9, 9),
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class Enemy(Entity):
|
||||
name: str = ""
|
||||
sprite_key: str = "enemy"
|
||||
hp: int = 1
|
||||
max_hp: int = 1
|
||||
power: int = 0
|
||||
armor: int = 0
|
||||
accuracy: int = 0
|
||||
evasion: int = 0
|
||||
crit_chance: float = 0.0
|
||||
speed: int = 1
|
||||
behavior: str = "wander"
|
||||
xp_value: int = 0
|
||||
last_known_pos: tuple[int, int] | None = None
|
||||
act_counter: int = 0
|
||||
can_split: bool = True
|
||||
ranged_power: int = 0
|
||||
|
||||
|
||||
def make_enemy(kind: str, x: int, y: int) -> Enemy:
|
||||
"""Construct an Enemy of the given kind at (x, y) with full roster stats."""
|
||||
s = _ROSTER[kind]
|
||||
return Enemy(
|
||||
x=x, y=y, name=s["name"], sprite_key=kind,
|
||||
hp=s["hp"], max_hp=s["hp"], power=s["power"], armor=s["armor"],
|
||||
accuracy=s["accuracy"], evasion=s["evasion"], crit_chance=s["crit"],
|
||||
speed=s["speed"], behavior=s["behavior"], xp_value=s["xp"],
|
||||
ranged_power=s["ranged"],
|
||||
)
|
||||
|
||||
|
||||
def kinds_for_floor(floor_index: int) -> list[str]:
|
||||
"""Non-boss enemy kinds allowed to spawn on the given floor (depth-gated)."""
|
||||
return [
|
||||
k for k, s in _ROSTER.items()
|
||||
if k != "ancient_dragon"
|
||||
and s["floors"][0] <= floor_index <= s["floors"][1]
|
||||
]
|
||||
@@ -1,18 +0,0 @@
|
||||
"""Base entity: a thing with a position on the map."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class Entity:
|
||||
"""Anything that lives on a dungeon tile: player, enemies, items, stairs.
|
||||
|
||||
`sprite_key` names the procedural pixel-art sprite to rasterize for it.
|
||||
`blocks` is True when other entities cannot share its tile.
|
||||
"""
|
||||
x: int
|
||||
y: int
|
||||
name: str
|
||||
sprite_key: str
|
||||
blocks: bool = True
|
||||
@@ -1,69 +0,0 @@
|
||||
"""Items: weapons, armor, potions, scrolls (plan.md §6).
|
||||
|
||||
The full fixed catalog lives here. `make_item` builds any catalog entry;
|
||||
`item_pool_for_floor` gives a depth-weighted name list for dungeon population.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from entities.entity import Entity
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class Item(Entity):
|
||||
"""A carryable thing. `blocks` is False — items never occupy a tile alone."""
|
||||
item_type: str = "misc" # weapon | armor | potion | scroll
|
||||
subtype: str = "" # healing | strength | invisibility | fireball | teleport | mapping
|
||||
stats: dict = field(default_factory=dict)
|
||||
|
||||
|
||||
# name -> (item_type, subtype, stats, sprite_key). Stats are read by Player /
|
||||
# actions: weapons carry power (+ optional crit delta), armor carries armor
|
||||
# (+ optional evasion delta), potions/scrolls carry their effect magnitudes.
|
||||
_CATALOG: dict[str, tuple[str, str, dict, str]] = {
|
||||
"Rusty Dagger": ("weapon", "", {"power": 2}, "weapon_dagger"),
|
||||
"Short Sword": ("weapon", "", {"power": 4}, "weapon_sword"),
|
||||
"Battle Axe": ("weapon", "", {"power": 7}, "weapon_axe"),
|
||||
"War Hammer": ("weapon", "", {"power": 10, "crit_chance": -0.05}, "weapon_hammer"),
|
||||
"Leather Armor": ("armor", "", {"armor": 2}, "armor_leather"),
|
||||
"Chain Mail": ("armor", "", {"armor": 4}, "armor_chain"),
|
||||
"Plate Armor": ("armor", "", {"armor": 7, "evasion": -10}, "armor_plate"),
|
||||
"Healing Potion": ("potion", "healing", {"heal": 30}, "potion_healing"),
|
||||
"Strength Potion": ("potion", "strength", {"power": 5, "duration": 20}, "potion_strength"),
|
||||
"Invisibility Potion": ("potion", "invisibility", {"duration": 15}, "potion_invisibility"),
|
||||
"Scroll of Fireball": ("scroll", "fireball", {"damage": 20, "radius": 3}, "scroll_fireball"),
|
||||
"Scroll of Teleport": ("scroll", "teleport", {}, "scroll_teleport"),
|
||||
"Scroll of Mapping": ("scroll", "mapping", {}, "scroll_mapping"),
|
||||
}
|
||||
|
||||
|
||||
def make_item(name: str, x: int, y: int) -> Item:
|
||||
"""Construct a catalog Item named `name` at (x, y)."""
|
||||
itype, subtype, stats, sprite = _CATALOG[name]
|
||||
return Item(
|
||||
x=x, y=y, name=name, sprite_key=sprite, blocks=False,
|
||||
item_type=itype, subtype=subtype, stats=dict(stats),
|
||||
)
|
||||
|
||||
|
||||
def item_pool_for_floor(floor_index: int) -> list[str]:
|
||||
"""Depth-weighted item names droppable on this floor (plan.md §6 distribution).
|
||||
|
||||
Potions and scrolls are uniform across depth; better weapons/armor appear
|
||||
deeper. Floor 9 (boss) is handled separately by the populator.
|
||||
"""
|
||||
pool = [
|
||||
"Healing Potion", "Strength Potion", "Invisibility Potion",
|
||||
"Scroll of Fireball", "Scroll of Teleport", "Scroll of Mapping",
|
||||
]
|
||||
if floor_index >= 5:
|
||||
pool += ["War Hammer", "Plate Armor", "Battle Axe", "Chain Mail",
|
||||
"Short Sword", "Leather Armor", "Rusty Dagger"]
|
||||
elif floor_index >= 3:
|
||||
pool += ["Battle Axe", "Chain Mail", "Short Sword", "Leather Armor", "Rusty Dagger"]
|
||||
elif floor_index >= 1:
|
||||
pool += ["Short Sword", "Leather Armor", "Rusty Dagger"]
|
||||
else:
|
||||
pool += ["Rusty Dagger", "Leather Armor"]
|
||||
return pool
|
||||
@@ -1,87 +0,0 @@
|
||||
"""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