diff --git a/squirrelbattle/entities/items.py b/squirrelbattle/entities/items.py index 123362f..4192674 100644 --- a/squirrelbattle/entities/items.py +++ b/squirrelbattle/entities/items.py @@ -49,7 +49,7 @@ class Item(Entity): """ self.held = True self.held_by = player - self.map.remove_entity(self) + self.held_by.map.remove_entity(self) player.add_to_inventory(self) def save_state(self) -> dict: @@ -80,7 +80,7 @@ class Heart(Item): When holding a heart, heal the player and don't put item in inventory. """ player.health = min(player.maxhealth, player.health + self.healing) - self.map.remove_entity(self) + player.map.remove_entity(self) def save_state(self) -> dict: """ diff --git a/squirrelbattle/game.py b/squirrelbattle/game.py index 685eb6b..7c13e61 100644 --- a/squirrelbattle/game.py +++ b/squirrelbattle/game.py @@ -194,7 +194,7 @@ class Game: if self.store_menu.values and not self.player.dead: if key == KeyValues.ENTER: item = self.store_menu.validate() - self.player.add_to_inventory(item) + item.hold(self.player) self.store_menu.merchant.inventory.remove(item) # Ensure that the cursor has a good position self.store_menu.position = min(self.store_menu.position, diff --git a/squirrelbattle/interfaces.py b/squirrelbattle/interfaces.py index 5efdf7f..e3e29da 100644 --- a/squirrelbattle/interfaces.py +++ b/squirrelbattle/interfaces.py @@ -68,7 +68,8 @@ class Map: """ Unregister an entity from the map. """ - self.entities.remove(entity) + if entity in self.entities: + self.entities.remove(entity) def find_entities(self, entity_class: type) -> list: return [entity for entity in self.entities