(Underdepths) Pass 4

This commit is contained in:
AlexKucera committed 2026-08-13 15:23:35 +02:00
1 parent a219ad17d5
commit 6147ab3121
29 files changed
+4888

No files matched your search

+69
View File
@@ -0,0 +1,69 @@
"""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