diff --git a/src/ship/items/inventory.rs b/src/ship/items/inventory.rs index e1519e6..0ad1126 100644 --- a/src/ship/items/inventory.rs +++ b/src/ship/items/inventory.rs @@ -565,5 +565,9 @@ impl CharacterInventory { (item, slot) }) } + + pub fn iter(&self) -> impl Iterator { + self.items.iter() + } } diff --git a/src/ship/items/manager.rs b/src/ship/items/manager.rs index ace390b..59de10f 100644 --- a/src/ship/items/manager.rs +++ b/src/ship/items/manager.rs @@ -45,6 +45,35 @@ pub enum ItemManagerError { ItemIdNotInInventory(ClientItemId) } + +async fn update_inventory_slots(entity_gateway: &mut EG, character: &CharacterEntity, inventory: &CharacterInventory) { + for (slot, item) in inventory.iter().enumerate() { + match item { + InventoryItem::Individual(individual_inventory_item) => { + entity_gateway.change_item_location( + &individual_inventory_item.entity_id, + ItemLocation::Inventory { + character_id: character.id, + slot: slot, + equipped: individual_inventory_item.equipped, + } + ).await + }, + InventoryItem::Stacked(stacked_inventory_item) => { + for entity_id in stacked_inventory_item.entity_ids.iter() { + entity_gateway.change_item_location( + entity_id, + ItemLocation::Inventory { + character_id: character.id, + slot: slot, + equipped: false, + }).await; + }} + } + } +} + + pub struct ItemManager { id_counter: u32, @@ -449,6 +478,7 @@ impl ItemManager { }, } + update_inventory_slots(entity_gateway, character, &inventory).await; Ok(()) } @@ -528,6 +558,7 @@ impl ItemManager { ItemLocation::Consumed).await; } + update_inventory_slots(entity_gateway, character, &inventory).await; Ok(consumed_item) } @@ -564,6 +595,7 @@ impl ItemManager { } } + update_inventory_slots(entity_gateway, character, &inventory).await; Ok(()) } @@ -640,6 +672,7 @@ impl ItemManager { }).await; } + update_inventory_slots(entity_gateway, character, &inventory).await; Ok(()) } @@ -754,6 +787,7 @@ impl ItemManager { } _ => {} } + update_inventory_slots(entity_gateway, character, &inventory).await; Ok(()) }