Browse Source

slots need to be updated when an item leaves inventory

pbs
jake 4 years ago
parent
commit
a148d96adc
  1. 4
      src/ship/items/inventory.rs
  2. 34
      src/ship/items/manager.rs

4
src/ship/items/inventory.rs

@ -565,5 +565,9 @@ impl CharacterInventory {
(item, slot) (item, slot)
}) })
} }
pub fn iter(&self) -> impl Iterator<Item = &InventoryItem> {
self.items.iter()
}
} }

34
src/ship/items/manager.rs

@ -45,6 +45,35 @@ pub enum ItemManagerError {
ItemIdNotInInventory(ClientItemId) 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 { pub struct ItemManager {
id_counter: u32, id_counter: u32,
@ -449,6 +478,7 @@ impl ItemManager {
}, },
} }
update_inventory_slots(entity_gateway, character, &inventory).await;
Ok(()) Ok(())
} }
@ -528,6 +558,7 @@ impl ItemManager {
ItemLocation::Consumed).await; ItemLocation::Consumed).await;
} }
update_inventory_slots(entity_gateway, character, &inventory).await;
Ok(consumed_item) Ok(consumed_item)
} }
@ -564,6 +595,7 @@ impl ItemManager {
} }
} }
update_inventory_slots(entity_gateway, character, &inventory).await;
Ok(()) Ok(())
} }
@ -640,6 +672,7 @@ impl ItemManager {
}).await; }).await;
} }
update_inventory_slots(entity_gateway, character, &inventory).await;
Ok(()) Ok(())
} }
@ -754,6 +787,7 @@ impl ItemManager {
} }
_ => {} _ => {}
} }
update_inventory_slots(entity_gateway, character, &inventory).await;
Ok(()) Ok(())
} }

Loading…
Cancel
Save