Items can be put in inventory by default
This commit is contained in:
parent
d35331fdb0
commit
ac22aef860
|
@ -6,8 +6,10 @@ from ..interfaces import Entity, FightingEntity, Map
|
||||||
|
|
||||||
class Item(Entity):
|
class Item(Entity):
|
||||||
held: bool
|
held: bool
|
||||||
hold_by: Optional["Player"]
|
held_by: Optional["Player"]
|
||||||
can_be_in_inventory: bool = False
|
# 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):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
@ -15,13 +17,13 @@ class Item(Entity):
|
||||||
|
|
||||||
def drop(self, y: int, x: int) -> None:
|
def drop(self, y: int, x: int) -> None:
|
||||||
self.held = False
|
self.held = False
|
||||||
self.hold_by = None
|
self.held_by = None
|
||||||
self.map.add_entity(self)
|
self.map.add_entity(self)
|
||||||
self.move(y, x)
|
self.move(y, x)
|
||||||
|
|
||||||
def hold(self, player: "Player") -> None:
|
def hold(self, player: "Player") -> None:
|
||||||
self.held = True
|
self.held = True
|
||||||
self.hold_by = player
|
self.held_by = player
|
||||||
self.map.remove_entity(self)
|
self.map.remove_entity(self)
|
||||||
if self.can_be_in_inventory:
|
if self.can_be_in_inventory:
|
||||||
player.inventory.append(self)
|
player.inventory.append(self)
|
||||||
|
|
Loading…
Reference in New Issue