1
0
python-roguelike/components/inventory.py
2022-01-12 16:24:09 -05:00

29 lines
737 B
Python

from __future__ import annotations
from typing import List, TYPE_CHECKING
from components.base_component import BaseComponent
if TYPE_CHECKING:
from entity import Actor, Item
class Inventory(BaseComponent):
parent: Actor
def __init__(self, capacity: int):
self.capacity = capacity
self.items: List[Item] = []
def drop(self, item: Item) -> None:
"""
Removes an item from the inventory and restores it to the game map,
at the player's current location.
:param item:
:return:
"""
self.items.remove(item)
item.place(self.parent.x, self.parent.y, self.gamemap)
self.engine.message_log.add_message(f"You dropped the {item.name}.")