139 lines
4.4 KiB
Python
139 lines
4.4 KiB
Python
"""Item catalog — every base-game item, its category, stats and effect.
|
|
|
|
Each entry is a plain dict consumed by ``entities.item.make_item``. Keys:
|
|
category : one of "weapon" | "armor" | "potion" | "scroll"
|
|
stats : equipment bonuses applied while the item is equipped
|
|
(weapons/armor). E.g. {"power": 4} or {"armor": 7, "evasion": -0.10}.
|
|
effect : what happens when the item is consumed (potion) or read (scroll).
|
|
Always carries a "kind" tag the player methods dispatch on.
|
|
|
|
Glyphs/colors default by category in ``make_item``; entries may override.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import random as _random
|
|
from typing import Optional
|
|
|
|
__all__ = ["ITEMS", "CATEGORIES", "ITEM_BY_FLOOR"]
|
|
|
|
CATEGORIES = ("weapon", "armor", "potion", "scroll")
|
|
|
|
ITEMS: dict[str, dict] = {
|
|
# --- weapons (power, occasionally a crit tweak) ----------------------- #
|
|
"Rusty Dagger": {
|
|
"category": "weapon",
|
|
"stats": {"power": 2},
|
|
"effect": {},
|
|
},
|
|
"Short Sword": {
|
|
"category": "weapon",
|
|
"stats": {"power": 4},
|
|
"effect": {},
|
|
},
|
|
"Battle Axe": {
|
|
"category": "weapon",
|
|
"stats": {"power": 7},
|
|
"effect": {},
|
|
},
|
|
"War Hammer": {
|
|
"category": "weapon",
|
|
"stats": {"power": 10, "crit_chance": -0.05},
|
|
"effect": {},
|
|
},
|
|
# --- armor (damage reduction, heavy armor hampers evasion) ------------ #
|
|
"Leather Armor": {
|
|
"category": "armor",
|
|
"stats": {"armor": 2},
|
|
"effect": {},
|
|
},
|
|
"Chain Mail": {
|
|
"category": "armor",
|
|
"stats": {"armor": 4},
|
|
"effect": {},
|
|
},
|
|
"Plate Armor": {
|
|
"category": "armor",
|
|
"stats": {"armor": 7, "evasion": -0.10},
|
|
"effect": {},
|
|
},
|
|
# --- potions (consumed on quaff) -------------------------------------- #
|
|
"Healing Potion": {
|
|
"category": "potion",
|
|
"stats": {},
|
|
"effect": {"kind": "heal", "amount": 30},
|
|
},
|
|
"Strength Potion": {
|
|
"category": "potion",
|
|
"stats": {},
|
|
"effect": {"kind": "strength", "power": 5, "duration": 20},
|
|
},
|
|
"Invisibility Potion": {
|
|
"category": "potion",
|
|
"stats": {},
|
|
"effect": {"kind": "invisibility", "duration": 15},
|
|
},
|
|
# --- scrolls (consumed on read) --------------------------------------- #
|
|
"Scroll of Fireball": {
|
|
"category": "scroll",
|
|
"stats": {},
|
|
"effect": {"kind": "fireball", "damage": 20, "radius": 3},
|
|
},
|
|
"Scroll of Teleport": {
|
|
"category": "scroll",
|
|
"stats": {},
|
|
"effect": {"kind": "teleport"},
|
|
},
|
|
"Scroll of Mapping": {
|
|
"category": "scroll",
|
|
"stats": {},
|
|
"effect": {"kind": "mapping"},
|
|
},
|
|
}
|
|
|
|
# Depth-scaled gear pools. Each tier lists the gear that may appear once the
|
|
# player has reached its min floor; deeper tiers supersede (but may repeat)
|
|
# shallower gear. Consumables are uniform across the whole descent.
|
|
_GEAR_TIERS = (
|
|
# (min_floor, weapons, armors)
|
|
(0, ["Rusty Dagger", "Short Sword"], ["Leather Armor"]),
|
|
(3, ["Short Sword", "Battle Axe"], ["Leather Armor", "Chain Mail"]),
|
|
(6, ["Battle Axe", "War Hammer"], ["Chain Mail", "Plate Armor"]),
|
|
)
|
|
_CONSUMABLES = [
|
|
"Healing Potion",
|
|
"Strength Potion",
|
|
"Invisibility Potion",
|
|
"Scroll of Fireball",
|
|
"Scroll of Teleport",
|
|
"Scroll of Mapping",
|
|
]
|
|
|
|
|
|
def _tier_pool(floor_index: int, kind: str) -> list[str]:
|
|
"""Return the depth-appropriate weapon/armor pool for ``floor_index``."""
|
|
pool: list[str] = []
|
|
for min_floor, weapons, armors in _GEAR_TIERS:
|
|
if floor_index >= min_floor:
|
|
pool = weapons if kind == "weapon" else armors
|
|
return pool
|
|
|
|
|
|
def ITEM_BY_FLOOR(floor_index: int, rng: Optional[random.Random] = None) -> str:
|
|
"""Pick a random item name, depth-scaled.
|
|
|
|
Weapons and armor improve with depth (a Rusty Dagger won't spawn on floor 7);
|
|
potions and scrolls are uniform across every floor. Roughly half of all
|
|
drops are consumables so the player always has a supply of tools.
|
|
"""
|
|
r = rng if rng is not None else _random
|
|
if r.random() < 0.5 or not _GEAR_TIERS:
|
|
return r.choice(_CONSUMABLES)
|
|
if r.random() < 0.5:
|
|
pool = _tier_pool(floor_index, "weapon")
|
|
else:
|
|
pool = _tier_pool(floor_index, "armor")
|
|
if not pool:
|
|
return r.choice(_CONSUMABLES)
|
|
return r.choice(pool)
|