Items can be put in inventory by default

This commit is contained in:
Yohann D'ANELLO 2020-11-11 16:57:09 +01:00
parent d35331fdb0
commit ac22aef860

View File

@ -6,8 +6,10 @@ from ..interfaces import Entity, FightingEntity, Map
class Item(Entity):
held: bool
hold_by: Optional["Player"]
can_be_in_inventory: bool = False
held_by: Optional["Player"]
# When it is False, items disappear when they are hold.
# Action is done when the item is picked up.
can_be_in_inventory: bool = True
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@ -15,13 +17,13 @@ class Item(Entity):
def drop(self, y: int, x: int) -> None:
self.held = False
self.hold_by = None
self.held_by = None
self.map.add_entity(self)
self.move(y, x)
def hold(self, player: "Player") -> None:
self.held = True
self.hold_by = player
self.held_by = player
self.map.remove_entity(self)
if self.can_be_in_inventory:
player.inventory.append(self)