32 lines
876 B
Python
32 lines
876 B
Python
"""Item: equipment and consumables. Built from the data.items catalog."""
|
|
|
|
from __future__ import annotations
|
|
from dataclasses import dataclass
|
|
|
|
from entities.entity import Entity
|
|
from data.items import ITEM_CATALOG
|
|
from data.constants import COLORS
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class Item(Entity):
|
|
# kind has a default because Entity's fields already carry defaults, and a
|
|
# dataclass cannot place a required field after defaulted ones. make_item
|
|
# always sets it, so "" is never observed in practice.
|
|
kind: str = ""
|
|
sub: str = ""
|
|
power: int = 0
|
|
armor: int = 0
|
|
evasion_delta: float = 0.0
|
|
crit_delta: float = 0.0
|
|
heal: int = 0
|
|
duration: int = 0
|
|
radius: int = 0
|
|
damage: int = 0
|
|
value: int = 0
|
|
|
|
|
|
def make_item(name: str) -> Item:
|
|
stats = ITEM_CATALOG[name]
|
|
return Item(name=name, color=COLORS[stats["kind"]], **stats)
|