Use directly equipped items outside the inventory
This commit is contained in:
parent
9475725228
commit
9aa684fb77
|
@ -29,7 +29,7 @@ class Item(Entity):
|
|||
The item is dropped from the inventory onto the floor
|
||||
"""
|
||||
if self.held:
|
||||
self.held_by.inventory.remove(self)
|
||||
self.held_by.remove_from_inventory(self)
|
||||
self.held_by.map.add_entity(self)
|
||||
self.move(self.held_by.y, self.held_by.x)
|
||||
self.held = False
|
||||
|
@ -46,8 +46,8 @@ class Item(Entity):
|
|||
"""
|
||||
if self.held_by.equipped_item:
|
||||
self.held_by.equipped_item.unequip()
|
||||
self.held_by.equipped_item = self
|
||||
self.held_by.remove_from_inventory(self)
|
||||
self.held_by.equipped_item = self
|
||||
|
||||
def unequip(self) -> None:
|
||||
"""
|
||||
|
|
|
@ -75,6 +75,17 @@ class Player(InventoryHolder, FightingEntity):
|
|||
self.current_xp += xp
|
||||
self.level_up()
|
||||
|
||||
def remove_from_inventory(self, obj: Item) -> None:
|
||||
"""
|
||||
Remove the given item from the inventory, even if the item is equipped.
|
||||
"""
|
||||
if obj == self.equipped_item:
|
||||
self.equipped_item = None
|
||||
elif obj == self.equipped_armor:
|
||||
self.equipped_armor = None
|
||||
else:
|
||||
return super().remove_from_inventory(obj)
|
||||
|
||||
# noinspection PyTypeChecker,PyUnresolvedReferences
|
||||
def check_move(self, y: int, x: int, move_if_possible: bool = False) \
|
||||
-> bool:
|
||||
|
|
|
@ -127,6 +127,8 @@ class Game:
|
|||
elif key == KeyValues.INVENTORY:
|
||||
self.state = GameMode.INVENTORY
|
||||
self.display_actions(DisplayActions.UPDATE)
|
||||
elif key == KeyValues.USE and self.player.equipped_item:
|
||||
self.player.equipped_item.use()
|
||||
elif key == KeyValues.SPACE:
|
||||
self.state = GameMode.MAINMENU
|
||||
elif key == KeyValues.CHAT:
|
||||
|
|
Loading…
Reference in New Issue