update inmemory gateway to reflect how inventory actually works
This commit is contained in:
		
							parent
							
								
									f3bfa658cd
								
							
						
					
					
						commit
						6a2703ed6c
					
				| @ -213,6 +213,12 @@ impl EntityGatewayTransaction for InMemoryGatewayTransaction { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| #[derive(Clone)] | ||||
| enum InventoryItemElement { | ||||
|     Individual(ItemEntityId), | ||||
|     Stacked(Vec<ItemEntityId>), | ||||
| } | ||||
| 
 | ||||
| #[derive(Clone)] | ||||
| pub struct InMemoryGateway { | ||||
|     users: Arc<Mutex<BTreeMap<UserAccountId, UserAccountEntity>>>, | ||||
| @ -221,7 +227,7 @@ pub struct InMemoryGateway { | ||||
|     character_meseta: Arc<Mutex<BTreeMap<CharacterEntityId, Meseta>>>, | ||||
|     bank_meseta: Arc<Mutex<BTreeMap<(CharacterEntityId, BankName), Meseta>>>, | ||||
|     items: Arc<Mutex<BTreeMap<ItemEntityId, ItemEntity>>>, | ||||
|     inventories: Arc<Mutex<BTreeMap<CharacterEntityId, InventoryEntity>>>, | ||||
|     inventories: Arc<Mutex<BTreeMap<CharacterEntityId, Vec<InventoryItemElement>>>>, | ||||
|     banks: Arc<Mutex<BTreeMap<CharacterEntityId, BankEntity>>>, | ||||
|     equips: Arc<Mutex<BTreeMap<CharacterEntityId, EquippedEntity>>>, | ||||
|     mag_modifiers: Arc<Mutex<BTreeMap<ItemEntityId, Vec<mag::MagModifier>>>>, | ||||
| @ -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(()) | ||||
|     } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user