|
@ -1,10 +1,13 @@ |
|
|
use std::collections::HashMap;
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
use std::default::Default;
|
|
|
|
|
|
|
|
|
use crate::entity::account::*;
|
|
|
use crate::entity::account::*;
|
|
|
use crate::entity::character::*;
|
|
|
use crate::entity::character::*;
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
|
|
|
use crate::entity::item::*;
|
|
|
|
|
|
|
|
|
use libpso::character::settings;
|
|
|
use libpso::character::settings;
|
|
|
|
|
|
use libpso::item;
|
|
|
|
|
|
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
|
|
|
|
@ -14,6 +17,7 @@ pub struct InMemoryGateway { |
|
|
user_settings: Arc<Mutex<HashMap<u32, UserSettings>>>,
|
|
|
user_settings: Arc<Mutex<HashMap<u32, UserSettings>>>,
|
|
|
//guildcard: Arc<Mutex<HashMap<u32, GuildCardData>>>,
|
|
|
//guildcard: Arc<Mutex<HashMap<u32, GuildCardData>>>,
|
|
|
characters: Arc<Mutex<HashMap<u32, Character>>>,
|
|
|
characters: Arc<Mutex<HashMap<u32, Character>>>,
|
|
|
|
|
|
items: Arc<Mutex<HashMap<u32, Item>>>,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl InMemoryGateway {
|
|
|
impl InMemoryGateway {
|
|
@ -21,8 +25,8 @@ impl InMemoryGateway { |
|
|
InMemoryGateway {
|
|
|
InMemoryGateway {
|
|
|
users: Arc::new(Mutex::new(HashMap::new())),
|
|
|
users: Arc::new(Mutex::new(HashMap::new())),
|
|
|
user_settings: Arc::new(Mutex::new(HashMap::new())),
|
|
|
user_settings: Arc::new(Mutex::new(HashMap::new())),
|
|
|
//guildcard: Arc::new(Mutex::new(HashMap::new())),
|
|
|
|
|
|
characters: Arc::new(Mutex::new(HashMap::new())),
|
|
|
characters: Arc::new(Mutex::new(HashMap::new())),
|
|
|
|
|
|
items: Arc::new(Mutex::new(HashMap::new())),
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -101,4 +105,43 @@ impl EntityGateway for InMemoryGateway { |
|
|
fn get_guild_card_data_by_user(&self, _user: &UserAccount) -> GuildCardData {
|
|
|
fn get_guild_card_data_by_user(&self, _user: &UserAccount) -> GuildCardData {
|
|
|
GuildCardData::default()
|
|
|
GuildCardData::default()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn new_item(&mut self, item: item::Item, location: ItemLocation) -> Item {
|
|
|
|
|
|
let mut items = self.items.lock().unwrap();
|
|
|
|
|
|
let id = items
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.fold(0, |sum, (i, _)| std::cmp::max(sum, *i))
|
|
|
|
|
|
+ 1;
|
|
|
|
|
|
let new_item = Item {
|
|
|
|
|
|
id: id,
|
|
|
|
|
|
location: location,
|
|
|
|
|
|
item: item,
|
|
|
|
|
|
};
|
|
|
|
|
|
items.insert(id, new_item.clone());
|
|
|
|
|
|
new_item
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn set_item(&self, item: &Item) {
|
|
|
|
|
|
let mut items = self.items.lock().unwrap();
|
|
|
|
|
|
items.insert(item.id, item.clone());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn get_items_by_character(&self, character: &Character) -> Vec<Item> {
|
|
|
|
|
|
let items = self.items.lock().unwrap();
|
|
|
|
|
|
items
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.filter(|(_, k)| {
|
|
|
|
|
|
if let ItemLocation::Inventory{character_id, index} = k.location {
|
|
|
|
|
|
character_id == character.id
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
false
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.map(|(_, k)| {
|
|
|
|
|
|
k.clone()
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|