107 lines
3.3 KiB
Python
107 lines
3.3 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from collections.abc import Mapping
|
|
from types import MappingProxyType
|
|
|
|
from data.constants import (
|
|
FIREBALL_DAMAGE,
|
|
FIREBALL_RADIUS,
|
|
HEALING_AMOUNT,
|
|
INVISIBILITY_DURATION,
|
|
STRENGTH_BONUS,
|
|
STRENGTH_DURATION,
|
|
)
|
|
from entities.item import Item
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class ItemDefinition:
|
|
name: str
|
|
category: str
|
|
glyph: str
|
|
color: tuple[int, int, int]
|
|
min_floor: int = 0
|
|
power_bonus: int = 0
|
|
armor_bonus: int = 0
|
|
crit_bonus: float = 0.0
|
|
evasion_bonus: float = 0.0
|
|
effect: str = ""
|
|
amount: int = 0
|
|
duration: int = 0
|
|
radius: int = 0
|
|
|
|
|
|
ITEM_CATALOG: Mapping[str, ItemDefinition] = MappingProxyType({
|
|
"Rusty Dagger": ItemDefinition("Rusty Dagger", "weapon", "/", (230, 210, 80), power_bonus=2),
|
|
"Short Sword": ItemDefinition("Short Sword", "weapon", "/", (230, 210, 80), min_floor=2, power_bonus=4),
|
|
"Battle Axe": ItemDefinition("Battle Axe", "weapon", "/", (230, 210, 80), min_floor=4, power_bonus=7),
|
|
"War Hammer": ItemDefinition(
|
|
"War Hammer", "weapon", "/", (230, 210, 80), min_floor=7, power_bonus=10, crit_bonus=-0.05
|
|
),
|
|
"Leather Armor": ItemDefinition("Leather Armor", "armor", "[", (70, 130, 230), armor_bonus=2),
|
|
"Chain Mail": ItemDefinition("Chain Mail", "armor", "[", (70, 130, 230), min_floor=3, armor_bonus=4),
|
|
"Plate Armor": ItemDefinition(
|
|
"Plate Armor", "armor", "[", (70, 130, 230), min_floor=6, armor_bonus=7, evasion_bonus=-2.0
|
|
),
|
|
"Healing Potion": ItemDefinition(
|
|
"Healing Potion", "potion", "!", (220, 50, 50), effect="healing", amount=HEALING_AMOUNT
|
|
),
|
|
"Strength Potion": ItemDefinition(
|
|
"Strength Potion",
|
|
"potion",
|
|
"!",
|
|
(220, 50, 50),
|
|
effect="strength",
|
|
amount=STRENGTH_BONUS,
|
|
duration=STRENGTH_DURATION,
|
|
),
|
|
"Invisibility Potion": ItemDefinition(
|
|
"Invisibility Potion",
|
|
"potion",
|
|
"!",
|
|
(220, 50, 50),
|
|
effect="invisibility",
|
|
duration=INVISIBILITY_DURATION,
|
|
),
|
|
"Scroll of Fireball": ItemDefinition(
|
|
"Scroll of Fireball",
|
|
"scroll",
|
|
"?",
|
|
(50, 220, 220),
|
|
effect="fireball",
|
|
amount=FIREBALL_DAMAGE,
|
|
radius=FIREBALL_RADIUS,
|
|
),
|
|
"Scroll of Teleport": ItemDefinition(
|
|
"Scroll of Teleport", "scroll", "?", (50, 220, 220), effect="teleport"
|
|
),
|
|
"Scroll of Mapping": ItemDefinition(
|
|
"Scroll of Mapping", "scroll", "?", (50, 220, 220), effect="mapping"
|
|
),
|
|
})
|
|
|
|
|
|
def create_item(name: str, x: int = 0, y: int = 0) -> Item:
|
|
definition = ITEM_CATALOG[name]
|
|
return Item(
|
|
x=x,
|
|
y=y,
|
|
glyph=definition.glyph,
|
|
color=definition.color,
|
|
name=definition.name,
|
|
category=definition.category,
|
|
power_bonus=definition.power_bonus,
|
|
armor_bonus=definition.armor_bonus,
|
|
crit_bonus=definition.crit_bonus,
|
|
evasion_bonus=definition.evasion_bonus,
|
|
effect=definition.effect,
|
|
amount=definition.amount,
|
|
duration=definition.duration,
|
|
radius=definition.radius,
|
|
)
|
|
|
|
|
|
def item_names_for_floor(floor_index: int) -> tuple[str, ...]:
|
|
return tuple(name for name, item in ITEM_CATALOG.items() if item.min_floor <= floor_index)
|