From 34cf660cbdd850d72e11358910094036b2a80ca6 Mon Sep 17 00:00:00 2001 From: andy Date: Sun, 1 Nov 2020 19:54:50 -0400 Subject: [PATCH] dont make new inventory --- src/ship/items/inventory.rs | 4 ++++ src/ship/items/manager.rs | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ship/items/inventory.rs b/src/ship/items/inventory.rs index b4dcc58..6360037 100644 --- a/src/ship/items/inventory.rs +++ b/src/ship/items/inventory.rs @@ -631,5 +631,9 @@ impl CharacterInventory { pub fn items(&self) -> &Vec { &self.items } + + pub fn set_items(&mut self, sorted_items: Vec) { + self.items = sorted_items; + } } diff --git a/src/ship/items/manager.rs b/src/ship/items/manager.rs index dcf9c86..642ec51 100644 --- a/src/ship/items/manager.rs +++ b/src/ship/items/manager.rs @@ -988,11 +988,13 @@ impl ItemManager { let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; let sorted_inventory_items: Vec = item_ids.iter() .filter(|&client_item_id| *client_item_id < 0xFFFFFFFF) - .map(|&client_item_id| inventory.get_item_by_id(ClientItemId(client_item_id)).cloned().unwrap()) + .map(|&client_item_id| inventory.get_item_by_id(ClientItemId(client_item_id))) + .filter(|&x| x.is_some() == true) + .map(|x| x.cloned().unwrap()) .collect(); - let sorted_inventory = CharacterInventory::new(sorted_inventory_items); - update_inventory_slots(entity_gateway, character, &sorted_inventory).await; + inventory.set_items(sorted_inventory_items); + update_inventory_slots(entity_gateway, character, &inventory).await; Ok(()) } }