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 = "", 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)