"""Item catalog and depth-scaled rolling. ITEM_CATALOG maps a name to the exact Item constructor fields (no x/y/name/color; those are filled by make_item). roll_item gates gear by floor depth and leaves consumables uniform, per plan.md item distribution. """ from __future__ import annotations import random ITEM_CATALOG: dict[str, dict] = { "Rusty Dagger": {"kind": "weapon", "power": 2}, "Short Sword": {"kind": "weapon", "power": 4}, "Battle Axe": {"kind": "weapon", "power": 7}, "War Hammer": {"kind": "weapon", "power": 10, "crit_delta": -0.05}, "Leather Armor": {"kind": "armor", "armor": 2}, "Chain Mail": {"kind": "armor", "armor": 4}, "Plate Armor": {"kind": "armor", "armor": 7, "evasion_delta": -0.10}, "Healing Potion": {"kind": "potion", "sub": "healing", "heal": 30}, "Strength Potion": {"kind": "potion", "sub": "strength", "duration": 20}, "Invisibility Potion": {"kind": "potion", "sub": "invisibility", "duration": 15}, "Scroll of Fireball": {"kind": "scroll", "sub": "fireball", "damage": 20, "radius": 3}, "Scroll of Teleport": {"kind": "scroll", "sub": "teleport"}, "Scroll of Mapping": {"kind": "scroll", "sub": "mapping"}, } # Minimum floor index at which a piece of gear may roll. Consumables have no # entry -> available on every floor. ITEM_MIN_FLOOR: dict[str, int] = { "Rusty Dagger": 0, "Short Sword": 2, "Battle Axe": 4, "War Hammer": 6, "Leather Armor": 0, "Chain Mail": 3, "Plate Armor": 5, } def roll_item(floor_index: int, rng: random.Random): # Lazy import: entities.item imports this module at top level. from entities.item import make_item gear = [n for n, d in ITEM_MIN_FLOOR.items() if floor_index >= d] if rng.random() < 0.60 and gear: name = rng.choice(gear) else: consumables = [n for n, s in ITEM_CATALOG.items() if s["kind"] in ("potion", "scroll")] name = rng.choice(consumables) return make_item(name)