diff --git a/src/entity/gateway/inmemory.rs b/src/entity/gateway/inmemory.rs index 88636ec..db485e8 100644 --- a/src/entity/gateway/inmemory.rs +++ b/src/entity/gateway/inmemory.rs @@ -213,6 +213,12 @@ impl EntityGatewayTransaction for InMemoryGatewayTransaction { } } +#[derive(Clone)] +enum InventoryItemElement { + Individual(ItemEntityId), + Stacked(Vec), +} + #[derive(Clone)] pub struct InMemoryGateway { users: Arc>>, @@ -221,7 +227,7 @@ pub struct InMemoryGateway { character_meseta: Arc>>, bank_meseta: Arc>>, items: Arc>>, - inventories: Arc>>, + inventories: Arc>>>, banks: Arc>>, equips: Arc>>, mag_modifiers: Arc>>>, @@ -538,7 +544,29 @@ impl EntityGateway for InMemoryGateway { Ok(inventories .iter() .find(|(id, _)| **id == *char_id) - .map(|(_, inv)| inv.clone()) + .map(|(_, inv)| { + InventoryEntity { + items: inv + .iter() + .map(|inv_item_id| { + match inv_item_id { + InventoryItemElement::Individual(individual_id) => { + InventoryItemEntity::Individual(items.get(individual_id).unwrap().clone()) + }, + InventoryItemElement::Stacked(stacked_ids) => { + InventoryItemEntity::Stacked( + stacked_ids.iter() + .map(|stacked_id| { + items.get(stacked_id).unwrap().clone() + }) + .collect() + ) + } + } + }) + .collect() + } + }) .map(|inv| apply_modifiers(&items, &weapon_modifiers, &mag_modifiers, inv)) .unwrap_or_default()) } @@ -554,7 +582,25 @@ impl EntityGateway for InMemoryGateway { async fn set_character_inventory(&mut self, char_id: &CharacterEntityId, inventory: &InventoryEntity) -> Result<(), GatewayError> { let mut inventories = self.inventories.lock().await; - inventories.insert(*char_id, inventory.clone()); + inventories.insert(*char_id, inventory.items + .iter() + .map(|inventory_item| { + match inventory_item { + InventoryItemEntity::Individual(individual) => { + InventoryItemElement::Individual(individual.id) + }, + InventoryItemEntity::Stacked(stacked) => { + InventoryItemElement::Stacked( + stacked.iter() + .map(|stacked| { + stacked.id + }) + .collect() + ) + } + } + }) + .collect()); Ok(()) }