|
@ -18,6 +18,7 @@ pub struct InMemoryGateway { |
|
|
banks: Arc<Mutex<BTreeMap<CharacterEntityId, BankEntity>>>,
|
|
|
banks: Arc<Mutex<BTreeMap<CharacterEntityId, BankEntity>>>,
|
|
|
equips: Arc<Mutex<BTreeMap<CharacterEntityId, EquippedEntity>>>,
|
|
|
equips: Arc<Mutex<BTreeMap<CharacterEntityId, EquippedEntity>>>,
|
|
|
mag_modifiers: Arc<Mutex<BTreeMap<ItemEntityId, Vec<mag::MagModifier>>>>,
|
|
|
mag_modifiers: Arc<Mutex<BTreeMap<ItemEntityId, Vec<mag::MagModifier>>>>,
|
|
|
|
|
|
weapon_modifiers: Arc<Mutex<BTreeMap<ItemEntityId, Vec<weapon::WeaponModifier>>>>,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl InMemoryGateway {
|
|
|
impl InMemoryGateway {
|
|
@ -31,6 +32,7 @@ impl InMemoryGateway { |
|
|
banks: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
banks: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
equips: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
equips: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
mag_modifiers: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
mag_modifiers: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
|
|
|
weapon_modifiers: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -42,9 +44,16 @@ impl InMemoryGateway { |
|
|
.map(|item| {
|
|
|
.map(|item| {
|
|
|
item.map_individual(|mut item| {
|
|
|
item.map_individual(|mut item| {
|
|
|
item.item = match item.item {
|
|
|
item.item = match item.item {
|
|
|
|
|
|
ItemDetail::Weapon(mut weapon) => {
|
|
|
|
|
|
if let Some(weapon_modifiers) = self.weapon_modifiers.lock().unwrap().get(&item.id) {
|
|
|
|
|
|
for weapon_modifier in weapon_modifiers.iter() {
|
|
|
|
|
|
weapon.apply_modifier(&weapon_modifier);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
ItemDetail::Weapon(weapon)
|
|
|
|
|
|
},
|
|
|
ItemDetail::Mag(mag) => {
|
|
|
ItemDetail::Mag(mag) => {
|
|
|
let mut mag = mag::Mag::baby_mag(mag.color as u16);
|
|
|
let mut mag = mag::Mag::baby_mag(mag.color as u16);
|
|
|
println!("mag! {:?}", mag);
|
|
|
|
|
|
if let Some(mag_modifiers) = self.mag_modifiers.lock().unwrap().get(&item.id) {
|
|
|
if let Some(mag_modifiers) = self.mag_modifiers.lock().unwrap().get(&item.id) {
|
|
|
for mag_modifier in mag_modifiers.iter() {
|
|
|
for mag_modifier in mag_modifiers.iter() {
|
|
|
match mag_modifier {
|
|
|
match mag_modifier {
|
|
@ -69,7 +78,6 @@ impl InMemoryGateway { |
|
|
},
|
|
|
},
|
|
|
_ => {}
|
|
|
_ => {}
|
|
|
}
|
|
|
}
|
|
|
println!("{:?} -> {:?}", mag_modifier, mag);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
ItemDetail::Mag(mag)
|
|
|
ItemDetail::Mag(mag)
|
|
@ -257,6 +265,14 @@ impl EntityGateway for InMemoryGateway { |
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError> {
|
|
|
|
|
|
self.weapon_modifiers.lock().unwrap()
|
|
|
|
|
|
.entry(*item_id)
|
|
|
|
|
|
.or_insert(Vec::new())
|
|
|
|
|
|
.push(modifier);
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_character_inventory(&mut self, char_id: &CharacterEntityId) -> Result<InventoryEntity, GatewayError> {
|
|
|
async fn get_character_inventory(&mut self, char_id: &CharacterEntityId) -> Result<InventoryEntity, GatewayError> {
|
|
|
println!("getting inv");
|
|
|
println!("getting inv");
|
|
|
let inventories = self.inventories.lock().unwrap();
|
|
|
let inventories = self.inventories.lock().unwrap();
|
|
|