Browse Source

Character -> CharacterEntity

pbs
jake 5 years ago
parent
commit
bf595f9693
  1. 8
      src/entity/character.rs
  2. 12
      src/entity/gateway/entitygateway.rs
  3. 16
      src/entity/gateway/inmemory.rs
  4. 10
      src/login/character.rs
  5. 10
      src/ship/character.rs
  6. 4
      src/ship/items.rs
  7. 6
      src/ship/ship.rs

8
src/entity/character.rs

@ -225,7 +225,7 @@ impl CharacterInfoboard {
#[derive(Clone)]
pub struct Character {
pub struct CharacterEntity {
pub id: u32,
pub user_id: u32,
pub slot: u32,
@ -242,9 +242,9 @@ pub struct Character {
pub info_board: CharacterInfoboard,
}
impl std::default::Default for Character {
fn default() -> Character {
Character {
impl std::default::Default for CharacterEntity {
fn default() -> CharacterEntity {
CharacterEntity {
id: 0,
user_id: 0,
slot: 0,

12
src/entity/gateway/entitygateway.rs

@ -25,15 +25,15 @@ pub trait EntityGateway {
unimplemented!();
}
fn get_characters_by_user(&self, _user: &UserAccount) -> [Option<Character>; 4] {
fn get_characters_by_user(&self, _user: &UserAccount) -> [Option<CharacterEntity>; 4] {
unimplemented!();
}
fn set_character(&mut self, _char: &Character) {
fn set_character(&mut self, _char: &CharacterEntity) {
unimplemented!();
}
fn new_character_by_user(&mut self, _user: &UserAccount) -> Character {
fn new_character_by_user(&mut self, _user: &UserAccount) -> CharacterEntity {
unimplemented!();
}
@ -49,15 +49,15 @@ pub trait EntityGateway {
unimplemented!();
}
fn get_items_by_character(&self, _char: &Character) -> Vec<Item> {
fn get_items_by_character(&self, _char: &CharacterEntity) -> Vec<Item> {
unimplemented!();
}
fn create_guild_card_by_character(&self, _character: &Character) -> GuildCard {
fn create_guild_card_by_character(&self, _character: &CharacterEntity) -> GuildCard {
unimplemented!();
}
fn get_guild_card_by_character(&self, _character: &Character) -> Option<GuildCard> {
fn get_guild_card_by_character(&self, _character: &CharacterEntity) -> Option<GuildCard> {
unimplemented!();
}
}

16
src/entity/gateway/inmemory.rs

@ -16,7 +16,7 @@ pub struct InMemoryGateway {
users: Arc<Mutex<HashMap<u32, UserAccount>>>,
user_settings: Arc<Mutex<HashMap<u32, UserSettings>>>,
guildcards: Arc<Mutex<HashMap<u32, GuildCard>>>,
characters: Arc<Mutex<HashMap<u32, Character>>>,
characters: Arc<Mutex<HashMap<u32, CharacterEntity>>>,
items: Arc<Mutex<HashMap<ItemEntityId, Item>>>,
}
@ -74,7 +74,7 @@ impl EntityGateway for InMemoryGateway {
new_settings
}
fn get_characters_by_user(&self, user: &UserAccount) -> [Option<Character>; 4] {
fn get_characters_by_user(&self, user: &UserAccount) -> [Option<CharacterEntity>; 4] {
let characters = self.characters.lock().unwrap();
let mut chars = [None; 4];
characters
@ -84,21 +84,21 @@ impl EntityGateway for InMemoryGateway {
chars
}
fn new_character_by_user(&mut self, user: &UserAccount) -> Character {
fn new_character_by_user(&mut self, user: &UserAccount) -> CharacterEntity {
let mut characters = self.characters.lock().unwrap();
let id = characters
.iter()
.fold(0, |sum, (i, _)| std::cmp::max(sum, *i))
+ 1;
let mut c = Character::default();
let mut c = CharacterEntity::default();
c.id = id;
c.user_id = user.id;
characters.insert(id, c.clone());
c
}
fn set_character(&mut self, char: &Character) {
fn set_character(&mut self, char: &CharacterEntity) {
let mut characters = self.characters.lock().unwrap();
characters.insert(char.id, char.clone());
}
@ -127,7 +127,7 @@ impl EntityGateway for InMemoryGateway {
items.insert(item.id, item.clone());
}
fn get_items_by_character(&self, character: &Character) -> Vec<Item> {
fn get_items_by_character(&self, character: &CharacterEntity) -> Vec<Item> {
let items = self.items.lock().unwrap();
items
.iter()
@ -144,7 +144,7 @@ impl EntityGateway for InMemoryGateway {
.collect()
}
fn create_guild_card_by_character(&self, character: &Character) -> GuildCard {
fn create_guild_card_by_character(&self, character: &CharacterEntity) -> GuildCard {
let mut guildcards = self.guildcards.lock().unwrap();
let user = self.get_user_by_id(character.user_id).unwrap();
let settings = self.get_user_settings_by_user(&user).unwrap();
@ -172,7 +172,7 @@ impl EntityGateway for InMemoryGateway {
new_guildcard
}
fn get_guild_card_by_character(&self, character: &Character) -> Option<GuildCard> {
fn get_guild_card_by_character(&self, character: &CharacterEntity) -> Option<GuildCard> {
let guildcards = self.guildcards.lock().unwrap();
guildcards
.iter()

10
src/login/character.rs

@ -23,7 +23,7 @@ use crate::entity::item::armor::Armor;
use crate::entity::item::tech::Technique;
use crate::entity::item::tool::Tool;
use crate::entity::item::mag::{Mag, MagType};
use crate::entity::character::{Character, CharacterClass, TechLevel};
use crate::entity::character::{CharacterEntity, CharacterClass, TechLevel};
use crate::login::login::get_login_status;
@ -143,7 +143,7 @@ fn generate_param_data(path: &str) -> (ParamDataHeader, Vec<u8>) {
struct ClientState {
param_index: usize,
user: Option<UserAccount>,
characters: Option<[Option<Character>; 4]>,
characters: Option<[Option<CharacterEntity>; 4]>,
guildcard_data_buffer: Option<Vec<u8>>,
session: Session,
}
@ -552,7 +552,7 @@ impl<EG: EntityGateway> ServerState for CharacterServerState<EG> {
}
fn new_character_from_preview(character: &mut Character, preview: &CharacterPreview) {
fn new_character_from_preview(character: &mut CharacterEntity, preview: &CharacterPreview) {
character.slot = preview.slot;
character.name = String::from_utf16_lossy(&preview.character.name).trim_matches(char::from(0)).into();
character.section_id = preview.character.section_id.into();
@ -571,7 +571,7 @@ fn new_character_from_preview(character: &mut Character, preview: &CharacterPrev
struct SelectScreenCharacterBuilder<'a> {
character: Option<&'a Character>,
character: Option<&'a CharacterEntity>,
level: Option<u32>,
}
@ -583,7 +583,7 @@ impl<'a> SelectScreenCharacterBuilder<'a> {
}
}
fn character(self, character: &'a Character) -> SelectScreenCharacterBuilder<'a> {
fn character(self, character: &'a CharacterEntity) -> SelectScreenCharacterBuilder<'a> {
SelectScreenCharacterBuilder {
character: Some(character),
..self

10
src/ship/character.rs

@ -1,11 +1,11 @@
use libpso::character::character;
use crate::common::leveltable::CharacterStats;
use crate::entity::character::Character;
use crate::entity::character::CharacterEntity;
use crate::ship::items::ActiveInventory;
// TODO: exp
pub struct CharacterBytesBuilder<'a> {
character: Option<&'a Character>,
character: Option<&'a CharacterEntity>,
stats: Option<&'a CharacterStats>,
level: Option<u32>,
}
@ -20,7 +20,7 @@ impl<'a> CharacterBytesBuilder<'a> {
}
}
pub fn character(self, character: &'a Character) -> CharacterBytesBuilder<'a> {
pub fn character(self, character: &'a CharacterEntity) -> CharacterBytesBuilder<'a> {
CharacterBytesBuilder {
character: Some(character),
..self
@ -76,7 +76,7 @@ impl<'a> CharacterBytesBuilder<'a> {
pub struct FullCharacterBytesBuilder<'a> {
character: Option<&'a Character>,
character: Option<&'a CharacterEntity>,
stats: Option<&'a CharacterStats>,
level: Option<u32>,
inventory: Option<&'a ActiveInventory>,
@ -97,7 +97,7 @@ impl<'a> FullCharacterBytesBuilder<'a> {
}
}
pub fn character(self, character: &'a Character) -> FullCharacterBytesBuilder<'a> {
pub fn character(self, character: &'a CharacterEntity) -> FullCharacterBytesBuilder<'a> {
FullCharacterBytesBuilder {
character: Some(character),
..self

4
src/ship/items.rs

@ -3,7 +3,7 @@ use std::collections::HashMap;
use libpso::character::character::InventoryItem;
use crate::entity::gateway::EntityGateway;
use crate::entity::character::Character;
use crate::entity::character::CharacterEntity;
use crate::entity::item::{Item, ItemId, ItemDetail, ItemLocation};
use crate::entity::item::weapon::Weapon;
use crate::entity::item::armor::Armor;
@ -151,7 +151,7 @@ impl ActiveItemDatabase {
// deactivate item
pub fn get_character_inventory<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, character: &Character) -> ActiveInventory {
pub fn get_character_inventory<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, character: &CharacterEntity) -> ActiveInventory {
let items = entity_gateway.get_items_by_character(&character);
let inventory_items = items.into_iter()
.filter(|item| {

6
src/ship/ship.rs

@ -17,7 +17,7 @@ use crate::common::leveltable::CharacterLevelTable;
use crate::entity::gateway::EntityGateway;
use crate::entity::account::{UserAccount, UserSettings, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM, GuildCard};
use crate::entity::character::Character;
use crate::entity::character::CharacterEntity;
use crate::entity::item::{ItemLocation, Item};
use crate::login::login::get_login_status;
use crate::ship::location::{ClientLocation, LobbyId, RoomId, AreaType, MAX_ROOMS};
@ -120,7 +120,7 @@ impl SendServerPacket for SendShipPacket {
struct ClientState {
user: UserAccount,
settings: UserSettings,
character: Character,
character: CharacterEntity,
session: Session,
guildcard: GuildCard,
inventory: items::ActiveInventory,
@ -129,7 +129,7 @@ struct ClientState {
}
impl ClientState {
fn new(user: UserAccount, settings: UserSettings, character: Character, inventory: items::ActiveInventory, /*bank: Bank,*/ session: Session, guildcard: GuildCard) -> ClientState {
fn new(user: UserAccount, settings: UserSettings, character: CharacterEntity, inventory: items::ActiveInventory, /*bank: Bank,*/ session: Session, guildcard: GuildCard) -> ClientState {
ClientState {
user: user,
settings: settings,

Loading…
Cancel
Save