Browse Source

Item -> ItemEntity

pbs
jake 5 years ago
parent
commit
44c35f350d
  1. 6
      src/entity/gateway/entitygateway.rs
  2. 10
      src/entity/gateway/inmemory.rs
  3. 2
      src/entity/item/mod.rs
  4. 32
      src/ship/items.rs
  5. 2
      src/ship/ship.rs

6
src/entity/gateway/entitygateway.rs

@ -41,15 +41,15 @@ pub trait EntityGateway {
unimplemented!(); unimplemented!();
} }
fn new_item(&mut self, _item: ItemDetail, _location: ItemLocation) -> Item {
fn new_item(&mut self, _item: ItemDetail, _location: ItemLocation) -> ItemEntity {
unimplemented!(); unimplemented!();
} }
fn set_item(&self, _item: &Item) {
fn set_item(&self, _item: &ItemEntity) {
unimplemented!(); unimplemented!();
} }
fn get_items_by_character(&self, _char: &CharacterEntity) -> Vec<Item> {
fn get_items_by_character(&self, _char: &CharacterEntity) -> Vec<ItemEntity> {
unimplemented!(); unimplemented!();
} }
} }

10
src/entity/gateway/inmemory.rs

@ -16,7 +16,7 @@ pub struct InMemoryGateway {
users: Arc<Mutex<HashMap<u32, UserAccount>>>, users: Arc<Mutex<HashMap<u32, UserAccount>>>,
user_settings: Arc<Mutex<HashMap<u32, UserSettings>>>, user_settings: Arc<Mutex<HashMap<u32, UserSettings>>>,
characters: Arc<Mutex<HashMap<CharacterEntityId, CharacterEntity>>>, characters: Arc<Mutex<HashMap<CharacterEntityId, CharacterEntity>>>,
items: Arc<Mutex<HashMap<ItemEntityId, Item>>>,
items: Arc<Mutex<HashMap<ItemEntityId, ItemEntity>>>,
} }
impl InMemoryGateway { impl InMemoryGateway {
@ -105,13 +105,13 @@ impl EntityGateway for InMemoryGateway {
GuildCardData::default() GuildCardData::default()
} }
fn new_item(&mut self, item: ItemDetail, location: ItemLocation) -> Item {
fn new_item(&mut self, item: ItemDetail, location: ItemLocation) -> ItemEntity {
let mut items = self.items.lock().unwrap(); let mut items = self.items.lock().unwrap();
let id = items let id = items
.iter() .iter()
.fold(0, |sum, (i, _)| std::cmp::max(sum, i.0)) .fold(0, |sum, (i, _)| std::cmp::max(sum, i.0))
+ 1; + 1;
let new_item = Item {
let new_item = ItemEntity {
id: ItemEntityId(id), id: ItemEntityId(id),
location: location, location: location,
item: item, item: item,
@ -120,12 +120,12 @@ impl EntityGateway for InMemoryGateway {
new_item new_item
} }
fn set_item(&self, item: &Item) {
fn set_item(&self, item: &ItemEntity) {
let mut items = self.items.lock().unwrap(); let mut items = self.items.lock().unwrap();
items.insert(item.id, item.clone()); items.insert(item.id, item.clone());
} }
fn get_items_by_character(&self, character: &CharacterEntity) -> Vec<Item> {
fn get_items_by_character(&self, character: &CharacterEntity) -> Vec<ItemEntity> {
let items = self.items.lock().unwrap(); let items = self.items.lock().unwrap();
items items
.iter() .iter()

2
src/entity/item/mod.rs

@ -87,7 +87,7 @@ impl ItemDetail {
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct Item {
pub struct ItemEntity {
pub id: ItemEntityId, pub id: ItemEntityId,
pub location: ItemLocation, pub location: ItemLocation,
pub item: ItemDetail, pub item: ItemDetail,

32
src/ship/items.rs

@ -4,7 +4,7 @@ use libpso::character::character::InventoryItem;
use crate::entity::gateway::EntityGateway; use crate::entity::gateway::EntityGateway;
use crate::entity::character::CharacterEntity; use crate::entity::character::CharacterEntity;
use crate::entity::item::{Item, ItemId, ItemDetail, ItemLocation};
use crate::entity::item::{ItemEntity, ItemId, ItemDetail, ItemLocation};
use crate::entity::item::weapon::Weapon; use crate::entity::item::weapon::Weapon;
use crate::entity::item::armor::Armor; use crate::entity::item::armor::Armor;
use crate::entity::item::shield::Shield; use crate::entity::item::shield::Shield;
@ -15,8 +15,8 @@ use crate::entity::item::mag::Mag;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum StackedItem { pub enum StackedItem {
Individual(Item),
Stacked(Vec<Item>),
Individual(ItemEntity),
Stacked(Vec<ItemEntity>),
} }
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
@ -68,12 +68,12 @@ impl ActiveInventory {
// does this do anything? // does this do anything?
inventory[index].equipped = match item.item { inventory[index].equipped = match item.item {
StackedItem::Individual(Item {location: ItemLocation::Inventory{ equipped: true, ..}, ..}) => 1,
StackedItem::Individual(ItemEntity {location: ItemLocation::Inventory{ equipped: true, ..}, ..}) => 1,
_ => 0, _ => 0,
}; };
// because this actually equips the item // because this actually equips the item
inventory[index].flags |= match item.item { inventory[index].flags |= match item.item {
StackedItem::Individual(Item {location: ItemLocation::Inventory{ equipped: true, ..}, ..}) => 8,
StackedItem::Individual(ItemEntity {location: ItemLocation::Inventory{ equipped: true, ..}, ..}) => 8,
_ => 0, _ => 0,
}; };
inventory inventory
@ -102,7 +102,7 @@ fn inventory_item_index(item: &StackedItem) -> usize {
} }
} }
fn stack_items(items: Vec<Item>) -> Vec<StackedItem> {
fn stack_items(items: Vec<ItemEntity>) -> Vec<StackedItem> {
let mut stacks = HashMap::new(); let mut stacks = HashMap::new();
for item in items { for item in items {
@ -174,10 +174,10 @@ mod test {
use super::*; use super::*;
use crate::entity::character::CharacterEntityId; use crate::entity::character::CharacterEntityId;
use crate::entity::item; use crate::entity::item;
use crate::entity::item::{Item, ItemDetail, ItemEntityId, ItemLocation};
use crate::entity::item::{ItemEntity, ItemDetail, ItemEntityId, ItemLocation};
#[test] #[test]
fn test_stack_items() { fn test_stack_items() {
let item1 = Item {
let item1 = ItemEntity {
id: ItemEntityId(1), id: ItemEntityId(1),
location: ItemLocation::Inventory { location: ItemLocation::Inventory {
character_id: CharacterEntityId(0), character_id: CharacterEntityId(0),
@ -192,7 +192,7 @@ mod test {
tekked: true, tekked: true,
}) })
}; };
let item2 = Item {
let item2 = ItemEntity {
id: ItemEntityId(2), id: ItemEntityId(2),
location: ItemLocation::Inventory { location: ItemLocation::Inventory {
character_id: CharacterEntityId(0), character_id: CharacterEntityId(0),
@ -203,7 +203,7 @@ mod test {
tool: item::tool::ToolType::Monofluid, tool: item::tool::ToolType::Monofluid,
}) })
}; };
let item3 = Item {
let item3 = ItemEntity {
id: ItemEntityId(3), id: ItemEntityId(3),
location: ItemLocation::Inventory { location: ItemLocation::Inventory {
character_id: CharacterEntityId(0), character_id: CharacterEntityId(0),
@ -218,7 +218,7 @@ mod test {
tekked: true, tekked: true,
}) })
}; };
let item4 = Item {
let item4 = ItemEntity {
id: ItemEntityId(4), id: ItemEntityId(4),
location: ItemLocation::Inventory { location: ItemLocation::Inventory {
character_id: CharacterEntityId(0), character_id: CharacterEntityId(0),
@ -229,7 +229,7 @@ mod test {
tool: item::tool::ToolType::Monofluid, tool: item::tool::ToolType::Monofluid,
}) })
}; };
let item5 = Item {
let item5 = ItemEntity {
id: ItemEntityId(5), id: ItemEntityId(5),
location: ItemLocation::Inventory { location: ItemLocation::Inventory {
character_id: CharacterEntityId(0), character_id: CharacterEntityId(0),
@ -240,7 +240,7 @@ mod test {
tool: item::tool::ToolType::Monofluid, tool: item::tool::ToolType::Monofluid,
}) })
}; };
let item6 = Item {
let item6 = ItemEntity {
id: ItemEntityId(6), id: ItemEntityId(6),
location: ItemLocation::Inventory { location: ItemLocation::Inventory {
character_id: CharacterEntityId(0), character_id: CharacterEntityId(0),
@ -255,7 +255,7 @@ mod test {
tekked: true, tekked: true,
}) })
}; };
let item7 = Item {
let item7 = ItemEntity {
id: ItemEntityId(7), id: ItemEntityId(7),
location: ItemLocation::Inventory { location: ItemLocation::Inventory {
character_id: CharacterEntityId(0), character_id: CharacterEntityId(0),
@ -266,7 +266,7 @@ mod test {
tool: item::tool::ToolType::Monomate, tool: item::tool::ToolType::Monomate,
}) })
}; };
let item8 = Item {
let item8 = ItemEntity {
id: ItemEntityId(8), id: ItemEntityId(8),
location: ItemLocation::Inventory { location: ItemLocation::Inventory {
character_id: CharacterEntityId(0), character_id: CharacterEntityId(0),
@ -277,7 +277,7 @@ mod test {
tool: item::tool::ToolType::Monomate, tool: item::tool::ToolType::Monomate,
}) })
}; };
let item9 = Item {
let item9 = ItemEntity {
id: ItemEntityId(9), id: ItemEntityId(9),
location: ItemLocation::Inventory { location: ItemLocation::Inventory {
character_id: CharacterEntityId(0), character_id: CharacterEntityId(0),

2
src/ship/ship.rs

@ -19,7 +19,7 @@ use crate::common::leveltable::CharacterLevelTable;
use crate::entity::gateway::EntityGateway; use crate::entity::gateway::EntityGateway;
use crate::entity::account::{UserAccount, UserSettings, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM}; use crate::entity::account::{UserAccount, UserSettings, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM};
use crate::entity::character::CharacterEntity; use crate::entity::character::CharacterEntity;
use crate::entity::item::{ItemLocation, Item};
use crate::entity::item::{ItemLocation, ItemEntity};
use crate::login::login::get_login_status; use crate::login::login::get_login_status;
use crate::ship::location::{ClientLocation, LobbyId, RoomId, AreaType, MAX_ROOMS}; use crate::ship::location::{ClientLocation, LobbyId, RoomId, AreaType, MAX_ROOMS};
use crate::ship::character::{CharacterBytesBuilder, FullCharacterBytesBuilder}; use crate::ship::character::{CharacterBytesBuilder, FullCharacterBytesBuilder};

Loading…
Cancel
Save