|
@ -13,7 +13,7 @@ pub struct InMemoryGateway { |
|
|
user_settings: Arc<Mutex<BTreeMap<UserSettingsId, UserSettingsEntity>>>,
|
|
|
user_settings: Arc<Mutex<BTreeMap<UserSettingsId, UserSettingsEntity>>>,
|
|
|
characters: Arc<Mutex<BTreeMap<CharacterEntityId, CharacterEntity>>>,
|
|
|
characters: Arc<Mutex<BTreeMap<CharacterEntityId, CharacterEntity>>>,
|
|
|
items: Arc<Mutex<BTreeMap<ItemEntityId, ItemEntity>>>,
|
|
|
items: Arc<Mutex<BTreeMap<ItemEntityId, ItemEntity>>>,
|
|
|
mag_feedings: Arc<Mutex<BTreeMap<ItemEntityId, Vec<ItemEntityId>>>>,
|
|
|
|
|
|
|
|
|
mag_modifiers: Arc<Mutex<BTreeMap<ItemEntityId, Vec<mag::MagModifier>>>>,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl InMemoryGateway {
|
|
|
impl InMemoryGateway {
|
|
@ -23,7 +23,7 @@ impl InMemoryGateway { |
|
|
user_settings: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
user_settings: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
characters: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
characters: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
items: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
items: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
mag_feedings: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
|
|
|
|
|
|
mag_modifiers: Arc::new(Mutex::new(BTreeMap::new())),
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -168,10 +168,19 @@ impl EntityGateway for InMemoryGateway { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn feed_mag(&mut self, mag_item_id: &ItemEntityId, tool_item_id: &ItemEntityId) {
|
|
|
async fn feed_mag(&mut self, mag_item_id: &ItemEntityId, tool_item_id: &ItemEntityId) {
|
|
|
self.mag_feedings.lock().unwrap()
|
|
|
|
|
|
|
|
|
self.mag_modifiers.lock().unwrap()
|
|
|
.entry(*mag_item_id)
|
|
|
.entry(*mag_item_id)
|
|
|
.or_insert(Vec::new())
|
|
|
.or_insert(Vec::new())
|
|
|
.push(*tool_item_id);
|
|
|
|
|
|
|
|
|
.push(mag::MagModifier::FeedMag {
|
|
|
|
|
|
food: *tool_item_id
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn change_mag_owner(&mut self, mag_item_id: &ItemEntityId, character: &CharacterEntity) {
|
|
|
|
|
|
self.mag_modifiers.lock().unwrap()
|
|
|
|
|
|
.entry(*mag_item_id)
|
|
|
|
|
|
.or_insert(Vec::new())
|
|
|
|
|
|
.push(mag::MagModifier::OwnerChange(character.char_class, character.section_id));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
async fn get_items_by_character(&self, character: &CharacterEntity) -> Vec<ItemEntity> {
|
|
|
async fn get_items_by_character(&self, character: &CharacterEntity) -> Vec<ItemEntity> {
|
|
@ -191,14 +200,22 @@ impl EntityGateway for InMemoryGateway { |
|
|
.map(|mut item| {
|
|
|
.map(|mut item| {
|
|
|
item.item = match item.item {
|
|
|
item.item = match item.item {
|
|
|
ItemDetail::Mag(mut mag) => {
|
|
|
ItemDetail::Mag(mut mag) => {
|
|
|
self.mag_feedings.lock().unwrap().get(&item.id).map(|mag_feedings| {
|
|
|
|
|
|
for mag_feed_id in mag_feedings.iter() {
|
|
|
|
|
|
items.get(&mag_feed_id).map(|mag_feed| {
|
|
|
|
|
|
|
|
|
self.mag_modifiers.lock().unwrap().get(&item.id).map(|mag_modifiers| {
|
|
|
|
|
|
for mag_modifier in mag_modifiers.iter() {
|
|
|
|
|
|
match mag_modifier {
|
|
|
|
|
|
mag::MagModifier::FeedMag {food} => {
|
|
|
|
|
|
items.get(&food).map(|mag_feed| {
|
|
|
match mag_feed.item {
|
|
|
match mag_feed.item {
|
|
|
ItemDetail::Tool(mag_feed) => mag.feed(mag_feed.tool),
|
|
|
ItemDetail::Tool(mag_feed) => mag.feed(mag_feed.tool),
|
|
|
_ => {}
|
|
|
_ => {}
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
mag::MagModifier::OwnerChange(class, section_id) => {
|
|
|
|
|
|
mag.change_owner(*class, *section_id)
|
|
|
|
|
|
},
|
|
|
|
|
|
_ => {}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
ItemDetail::Mag(mag)
|
|
|
ItemDetail::Mag(mag)
|
|
|