From 6c33c7ec9b401ac1fd42ab619ef43c3c0b709853 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 6 Oct 2020 22:36:02 -0300 Subject: [PATCH] dont delete items when unequipping --- src/ship/items/inventory.rs | 6 +++++- src/ship/items/manager.rs | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ship/items/inventory.rs b/src/ship/items/inventory.rs index 0ad1126..1328e80 100644 --- a/src/ship/items/inventory.rs +++ b/src/ship/items/inventory.rs @@ -336,7 +336,11 @@ impl<'a> InventoryItemHandle<'a> { })) } } - } + } + + pub fn get_slot(&self) -> usize { + self.slot + } } diff --git a/src/ship/items/manager.rs b/src/ship/items/manager.rs index e47be8b..ffecb3a 100644 --- a/src/ship/items/manager.rs +++ b/src/ship/items/manager.rs @@ -903,11 +903,12 @@ impl ItemManager { -> Result<(), ItemManagerError> { let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; let mut inventory_item_handle = inventory.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?; + let slot = inventory_item_handle.get_slot(); let inventory_item = inventory_item_handle.item_mut().ok_or(ItemManagerError::CannotGetMutItem)?.individual().ok_or(ItemManagerError::CannotGetIndividualItem)?; inventory_item.equipped = true; entity_gateway.change_item_location(&inventory_item.entity_id, ItemLocation::Inventory{ character_id: character.id, - slot: character.slot as usize, + slot: slot, equipped: true, }).await; @@ -922,11 +923,12 @@ impl ItemManager { -> Result<(), ItemManagerError> { let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; let mut inventory_item_handle = inventory.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?; + let slot = inventory_item_handle.get_slot(); let inventory_item = inventory_item_handle.item_mut().ok_or(ItemManagerError::CannotGetMutItem)?.individual().ok_or(ItemManagerError::CannotGetIndividualItem)?; inventory_item.equipped = false; entity_gateway.change_item_location(&inventory_item.entity_id, ItemLocation::Inventory{ character_id: character.id, - slot: character.slot as usize, + slot: slot, equipped: false, }).await;