slots need to be updated when an item leaves inventory
This commit is contained in:
parent
6de4b677ef
commit
a148d96adc
@ -565,5 +565,9 @@ impl CharacterInventory {
|
||||
(item, slot)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = &InventoryItem> {
|
||||
self.items.iter()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,35 @@ pub enum ItemManagerError {
|
||||
ItemIdNotInInventory(ClientItemId)
|
||||
}
|
||||
|
||||
|
||||
async fn update_inventory_slots<EG: EntityGateway>(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(())
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user