Stepwise/source/entity.py
Kayne Ruse f831019148 Items can be picked up and stored in the inventory
When more than one item can be picked up, and options window is shown.

Stubs for "using" an item are in place.
2025-03-29 16:30:44 +11:00

72 lines
1.4 KiB
Python

from __future__ import annotations
import copy
from typing import Optional, Tuple, Type
from stats import Stats
from ai import BaseAI
from useable import BaseUseable
from inventory import Inventory
class Entity:
stats: Stats
ai: BaseAI
useable: BaseUseable
def __init__(
self,
x: int = 0,
y: int = 0,
char: str = "?",
color: Tuple[int, int, int] = (255, 255, 255),
name: str = "<Unnamed>",
walkable: bool = True,
floor_map = None,
#monster-specific stuff
ai_class: Type[BaseAI] = None,
stats: Stats = None,
#item-specific stuff
useable: BaseUseable = None,
inventory: Inventory = None,
):
self.x = x
self.y = y
self.char = char
self.color = color
self.name = name
self.walkable = walkable
self.floor_map = floor_map
#monster-specific stuff
if ai_class:
self.ai: Optional[BaseAI] = ai_class(self)
self.stats = stats
self.stats.entity = self
#item-specific stuff
self.useable = useable
self.inventory = inventory
#generic entity stuff
def spawn(self, x: int, y: int, floor_map):
clone = copy.deepcopy(self)
clone.x = x
clone.y = y
clone.floor_map = floor_map
clone.floor_map.entities.add(clone)
return clone
def set_pos(self, x: int, y: int) -> None:
self.x = x
self.y = y
#monster-specific stuff
def is_alive(self) -> bool:
return bool(self.ai)
#item-specific stuff
def is_item(self) -> bool:
return bool(self.useable)