diff --git a/Cargo.toml b/Cargo.toml index 5737f97..dac1d62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,35 +6,41 @@ edition = "2021" [workspace] members = [ - "client", - "drops", - "entity", - "items", - "location", - "maps", - "networking", - "pktbuilder", - "quests", - "room", - "shops", - "stats", - "trade", + "src/client", + "src/drops", + "src/entity", + "src/items", + "src/location", + "src/maps", + "src/networking", + "src/pktbuilder", + "src/quests", + "src/room", + "src/shops", + "src/stats", + "src/trade", + "src/patch_server", + "src/login_server", + "src/ship_server", ] [workspace.dependencies] -entity = { path = "./entity" } -maps = { path = "./maps" } -networking = { path = "./networking" } -shops = { path = "./shops" } -stats = { path = "./stats" } -items = { path = "./items" } -pktbuilder = { path = "./pktbuilder" } -quests = { path = "./quests" } -location = { path = "./location" } -client = { path = "./client" } -drops = { path = "./drops" } -trade = { path = "./trade" } -room = { path = "./room" } +entity = { path = "./src/entity" } +maps = { path = "./src/maps" } +networking = { path = "./src/networking" } +shops = { path = "./src/shops" } +stats = { path = "./src/stats" } +items = { path = "./src/items" } +pktbuilder = { path = "./src/pktbuilder" } +quests = { path = "./src/quests" } +location = { path = "./src/location" } +client = { path = "./src/client" } +drops = { path = "./src/drops" } +trade = { path = "./src/trade" } +room = { path = "./src/room" } +patch_server = { path = "./src/patch_server" } +login_server = { path = "./src/login_server" } +ship_server = { path = "./src/ship_server" } libpso = { git = "http://git.sharnoth.com/jake/libpso" } @@ -59,7 +65,6 @@ ages-prs = "0.1" async-trait = "0.1.51" async-recursion= "1.0.0" lazy_static = "1.4.0" -barrel = { version = "0.6.5", features = ["pg"] } refinery = { version = "0.5.0", features = ["postgres"] } sqlx = { version = "0.6.2", features = ["runtime-async-std-native-tls", "postgres", "json", "chrono"] } strum = "0.19.5" @@ -70,37 +75,23 @@ anyhow = { version = "1.0.68", features = ["backtrace"] } entity = { workspace = true } maps = { workspace = true } networking = { workspace = true } -shops = { workspace = true } -stats = { workspace = true } -items = { workspace = true } -pktbuilder = { workspace = true } -quests = { workspace = true } -location = { workspace = true } -client = { workspace = true } -drops = { workspace = true } -trade = { workspace = true } -room = { workspace = true } +patch_server = { workspace = true } +login_server = { workspace = true } +ship_server = { workspace = true } libpso = { workspace = true } -ages-prs = { workspace = true } -anyhow = { workspace = true } -async-recursion = { workspace = true } async-std = { workspace = true } -async-trait = { workspace = true } bcrypt = { workspace = true } -byteorder = { workspace = true } chrono = { workspace = true } -crc = { workspace = true } -derive_more = { workspace = true } -enum-utils = { workspace = true } fern = { workspace = true } futures = { workspace = true } log = { workspace = true } -rand = { workspace = true } -rand_chacha = { workspace = true } -ron = { workspace = true } -serde = { workspace = true } -serde_json = { workspace = true } -toml = { workspace = true } -thiserror = { workspace = true } \ No newline at end of file + +[dev-dependencies] +drops = { workspace = true } +shops = { workspace = true } +items = { workspace = true } +quests = { workspace = true } +stats = { workspace = true } +async-trait = { workspace = true } \ No newline at end of file diff --git a/items/src/manager.rs b/items/src/manager.rs deleted file mode 100644 index d368ec6..0000000 --- a/items/src/manager.rs +++ /dev/null @@ -1,1380 +0,0 @@ -use crate::ClientItemId; -use std::collections::HashMap; -use std::cmp::Ordering; -use std::cell::RefCell; -use thiserror::Error; -use crate::entity::gateway::{EntityGateway, GatewayError}; -use crate::entity::character::{CharacterEntity, CharacterEntityId, TechLevel}; -use crate::entity::item::{ItemDetail, ItemNote, BankName}; -use crate::entity::item::{Meseta, NewItemEntity, ItemEntity, InventoryItemEntity, BankItemEntity}; -use crate::entity::item::tool::{Tool, ToolType}; -use crate::entity::item::weapon; -use maps::area::MapArea; -use crate::ship::ship::ItemDropLocation; -use crate::ship::trade::TradeItem; -use drops::{ItemDrop, ItemDropType}; -use location::{AreaClient, RoomId}; -use shops::ShopItem; -use crate::ship::packet::handler::trade::{TradeError, OTHER_MESETA_ITEM_ID}; - -use crate::bank::*; -use crate::floor::*; -use crate::inventory::*; -use crate::transaction::{ItemTransaction, ItemAction, TransactionError, TransactionCommitError}; - -#[derive(PartialEq, Eq)] -pub enum FloorType { - Local, - Shared, -} - -pub enum TriggerCreateItem { - Yes, - No -} - -#[derive(Error, Debug)] -#[error("itemmanager")] -pub enum ItemManagerError { - #[error("gateway")] - EntityGatewayError, - #[error("no such item id {0}")] - NoSuchItemId(ClientItemId), - NoCharacter(CharacterEntityId), - NoRoom(RoomId), - CouldNotAddToInventory(ClientItemId), - //ItemBelongsToOtherPlayer, - #[error("shrug")] - Idunnoman, - CouldNotSplitItem(ClientItemId), - #[error("could not drop meseta")] - CouldNotDropMeseta, - InvalidBankName(BankName), - #[error("not enough tools")] - NotEnoughTools(Tool, usize, usize), // have, expected - InventoryItemConsumeError(#[from] InventoryItemConsumeError), - #[error("bank full")] - BankFull, - WrongItemType(ClientItemId), - UseItemError(#[from] use_tool::UseItemError), - #[error("could not buy item")] - CouldNotBuyItem, - #[error("could not add bought item to inventory")] - CouldNotAddBoughtItemToInventory, - ItemIdNotInInventory(ClientItemId), - #[error("cannot get mut item")] - CannotGetMutItem, - #[error("cannot get individual item")] - CannotGetIndividualItem, - InvalidSlot(u8, u8), // slots available, slot attempted - #[error("no armor equipped")] - NoArmorEquipped, - GatewayError(#[from] GatewayError), - #[error("stacked item")] - StackedItemError(Vec), - #[error("item not sellable")] - ItemNotSellable(InventoryItem), - #[error("wallet full")] - WalletFull, - #[error("invalid sale")] - InvalidSale, - ItemTransactionAction(Box), - #[error("invalid trade")] - InvalidTrade, -} - -impl std::convert::From> for ItemManagerError -where - E: std::fmt::Debug + std::marker::Send + std::marker::Sync + std::error::Error + 'static, -{ - fn from(other: TransactionError) -> ItemManagerError { - match other { - TransactionError::Action(err) => { - ItemManagerError::ItemTransactionAction(Box::new(err)) - }, - TransactionError::Commit(err) => { - match err { - TransactionCommitError::Gateway(gw) => { - ItemManagerError::GatewayError(gw) - }, - TransactionCommitError::ItemManager(im) => { - im - } - } - } - } - } -} - - -pub struct ItemManager { - pub(super) id_counter: u32, - - pub(self) character_inventory: HashMap, - pub(self) character_meseta: HashMap, - pub(self) bank_meseta: HashMap, - //character_bank: HashMap>, - pub(self) character_bank: HashMap, - pub(self) character_floor: HashMap, - - pub(self) character_room: HashMap, - pub(self) room_floor: HashMap, - pub(self) room_item_id_counter: RefCell ClientItemId + Send>>>, -} - -impl Default for ItemManager { - fn default() -> ItemManager { - ItemManager { - id_counter: 0, - character_inventory: HashMap::new(), - character_meseta: HashMap::new(), - bank_meseta: HashMap::new(), - character_bank: HashMap::new(), - character_floor: HashMap::new(), - character_room: HashMap::new(), - room_floor: HashMap::new(), - room_item_id_counter: RefCell::new(HashMap::new()), - } - } -} - -impl ItemManager { - pub fn next_global_item_id(&mut self) -> ClientItemId { - self.id_counter += 1; - ClientItemId(self.id_counter) - } - - pub async fn load_character(&mut self, entity_gateway: &mut EG, character: &CharacterEntity) -> Result<(), anyhow::Error> { - let inventory = entity_gateway.get_character_inventory(&character.id).await?; - let bank = entity_gateway.get_character_bank(&character.id, &BankName("".into())).await?; - let equipped = entity_gateway.get_character_equips(&character.id).await?; - - let inventory_items = inventory.items.into_iter() - .map(|item| -> Result { - Ok(match item { - InventoryItemEntity::Individual(item) => { - InventoryItem::Individual(IndividualInventoryItem { - entity_id: item.id, - item_id: self.next_global_item_id(), - item: item.item, - }) - }, - InventoryItemEntity::Stacked(items) => { - InventoryItem::Stacked(StackedInventoryItem { - entity_ids: items.iter().map(|i| i.id).collect(), - item_id: self.next_global_item_id(), - tool: items.get(0) - .ok_or_else(|| ItemManagerError::StackedItemError(items.clone()))? - .item - .clone() - .as_tool() - .ok_or_else(|| ItemManagerError::StackedItemError(items.clone()))? - }) - }, - }) - }) - .collect::, _>>()?; - let character_inventory = CharacterInventory::new(inventory_items, &equipped); - - let bank_items = bank.items.into_iter() - .map(|item| -> Result { - Ok(match item { - BankItemEntity::Individual(item) => { - BankItem::Individual(IndividualBankItem { - entity_id: item.id, - item_id: self.next_global_item_id(), - item: item.item, - }) - }, - BankItemEntity::Stacked(items) => { - BankItem::Stacked(StackedBankItem { - entity_ids: items.iter().map(|i| i.id).collect(), - item_id: self.next_global_item_id(), - tool: items.get(0) - .ok_or_else(|| ItemManagerError::StackedItemError(items.clone()))? - .item - .clone() - .as_tool() - .ok_or_else(|| ItemManagerError::StackedItemError(items.clone()))? - }) - }, - }) - }) - .collect::, _>>()?; - let character_bank = CharacterBank::new(bank_items); - - let character_meseta = entity_gateway.get_character_meseta(&character.id).await?; - let bank_meseta = entity_gateway.get_bank_meseta(&character.id, &BankName("".into())).await?; - - self.character_inventory.insert(character.id, character_inventory); - self.character_bank.insert(character.id, character_bank); - self.character_meseta.insert(character.id, character_meseta); - self.bank_meseta.insert(character.id, bank_meseta); - Ok(()) - } - - pub fn add_character_to_room(&mut self, room_id: RoomId, character: &CharacterEntity, area_client: AreaClient) { - let base_inventory_id = ((area_client.local_client.id() as u32) << 21) | 0x10000; - let inventory = self.character_inventory.get_mut(&character.id).unwrap(); - inventory.initialize_item_ids(base_inventory_id); - let base_bank_id = ((area_client.local_client.id() as u32) << 21) | 0x20000; - let default_bank = self.character_bank.get_mut(&character.id); - if let Some(default_bank ) = default_bank { - default_bank.initialize_item_ids(base_bank_id); - } - self.character_room.insert(character.id, room_id); - self.character_floor.insert(character.id, RoomFloorItems::default()); - self.room_floor.entry(room_id).or_insert_with(RoomFloorItems::default); - - let mut inc = 0x00810000; - self.room_item_id_counter.borrow_mut().entry(room_id).or_insert_with(|| Box::new(move || { - inc += 1; - ClientItemId(inc) - })); - } - - pub fn get_character_inventory(&self, character: &CharacterEntity) -> Result<&CharacterInventory, anyhow::Error> { - Ok(self.character_inventory.get(&character.id) - .ok_or(ItemManagerError::NoCharacter(character.id))?) - } - - pub fn get_character_inventory_mut<'a>(&'a mut self, character: &CharacterEntity) -> Result<&'a mut CharacterInventory, anyhow::Error> { - Ok(self.character_inventory.get_mut(&character.id) - .ok_or(ItemManagerError::NoCharacter(character.id))?) - } - - pub fn get_character_bank(&self, character: &CharacterEntity) -> Result<&CharacterBank, anyhow::Error> { - self.character_bank - .get(&character.id) - .ok_or_else(|| ItemManagerError::NoCharacter(character.id).into()) - } - - pub fn get_character_meseta(&self, character_id: &CharacterEntityId) -> Result<&Meseta, ItemManagerError> { - self.character_meseta.get(character_id) - .ok_or(ItemManagerError::NoCharacter(*character_id)) - } - - pub fn get_character_meseta_mut<'a>(&'a mut self, character_id: &CharacterEntityId) -> Result<&'a mut Meseta, ItemManagerError> { - self.character_meseta.get_mut(character_id) - .ok_or(ItemManagerError::NoCharacter(*character_id)) - } - - pub fn get_bank_meseta(&self, character_id: &CharacterEntityId) -> Result<&Meseta, ItemManagerError> { - self.bank_meseta.get(character_id) - .ok_or(ItemManagerError::NoCharacter(*character_id)) - } - - pub fn get_bank_meseta_mut<'a>(&'a mut self, character_id: &CharacterEntityId) -> Result<&'a mut Meseta, ItemManagerError> { - self.bank_meseta.get_mut(character_id) - .ok_or(ItemManagerError::NoCharacter(*character_id)) - } - - pub fn get_character_and_bank_meseta_mut<'a>(&'a mut self, character_id: &CharacterEntityId) -> Result<(&'a mut Meseta, &'a mut Meseta), ItemManagerError> { - Ok(( - self.character_meseta.get_mut(character_id) - .ok_or(ItemManagerError::NoCharacter(*character_id))?, - self.bank_meseta.get_mut(character_id) - .ok_or(ItemManagerError::NoCharacter(*character_id))? - )) - } - - pub fn remove_character_from_room(&mut self, character: &CharacterEntity) { - self.character_inventory.remove(&character.id); - self.character_floor.remove(&character.id); - if let Some(room) = self.character_room.remove(&character.id).as_ref() { - if self.character_room.iter().any(|(_, r)| r == room) { - self.room_floor.remove(room); - } - } - } - - pub fn get_floor_item_by_id(&self, character: &CharacterEntity, item_id: ClientItemId) -> Result<(&FloorItem, FloorType), anyhow::Error> { - let local_floor = self.character_floor.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let room = self.character_room.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let shared_floor = self.room_floor.get(room).ok_or(ItemManagerError::NoCharacter(character.id))?; - - local_floor.get_item_by_id(item_id).map(|item| (item, FloorType::Local)) - .or_else(|| { - shared_floor.get_item_by_id(item_id).map(|item| (item, FloorType::Shared)) - }) - .ok_or_else(|| ItemManagerError::NoSuchItemId(item_id).into()) - } - - pub async fn character_picks_up_item(&mut self, entity_gateway: &mut EG, character: &mut CharacterEntity, item_id: ClientItemId) - -> Result { - let it = ItemTransaction::new(self, (character, item_id)) - .act(|it, (character, item_id)| -> Result<_, ItemManagerError> { - let local_floor = it.manager.character_floor.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let inventory = it.manager.character_inventory.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let room_id = it.manager.character_room.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let shared_floor = it.manager.room_floor.get(room_id).ok_or(ItemManagerError::NoRoom(*room_id))?; - - let floor_item = match local_floor.get_item_by_id(*item_id) { - Some(floor_item) => { - it.action(Box::new(RemoveFromLocalFloor { - character_id: character.id, - item_id: *item_id - })); - floor_item - }, - None => { - match shared_floor.get_item_by_id(*item_id) { - Some(floor_item) => { - it.action(Box::new(RemoveFromSharedFloor { - room_id: *room_id, - item_id: *item_id - })); - floor_item - }, - None => { - return Err(ItemManagerError::NoSuchItemId(*item_id)) - } - } - } - }; - - let create_trigger = match floor_item { - FloorItem::Individual(individual_floor_item) => { - if inventory.space_for_individual_item() { - it.action(Box::new(AddIndividualFloorItemToInventory { - character: (**character).clone(), - item: individual_floor_item.clone() - })) - } - else { - return Err(ItemManagerError::CouldNotAddToInventory(*item_id)); - } - TriggerCreateItem::Yes - }, - FloorItem::Stacked(stacked_floor_item) => { - match inventory.space_for_stacked_item(&stacked_floor_item.tool, stacked_floor_item.entity_ids.len()) { - SpaceForStack::Yes(YesThereIsSpace::NewStack) => { - it.action(Box::new(AddStackedFloorItemToInventory { - character_id: character.id, - item: stacked_floor_item.clone() - })); - TriggerCreateItem::Yes - }, - SpaceForStack::Yes(YesThereIsSpace::ExistingStack) => { - it.action(Box::new(AddStackedFloorItemToInventory { - character_id: character.id, - item: stacked_floor_item.clone() - })); - TriggerCreateItem::No - }, - SpaceForStack::No(_) => { - return Err(ItemManagerError::CouldNotAddToInventory(*item_id)); - }, - } - }, - FloorItem::Meseta(meseta_floor_item) => { - let character_meseta = it.manager.character_meseta.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - if character_meseta.0 >= 999999 { - return Err(ItemManagerError::CouldNotAddToInventory(*item_id)); - } - it.action(Box::new(AddMesetaFloorItemToInventory { - character_id: character.id, - item: meseta_floor_item.clone() - })); - - TriggerCreateItem::No - }, - }; - Ok(create_trigger) - }); - it.commit(self, entity_gateway) - .await - .map_err(|err| err.into()) - } - - pub async fn enemy_drop_item_on_local_floor<'a, EG: EntityGateway>(&'a mut self, entity_gateway: &'a mut EG, character: &'a CharacterEntity, item_drop: ItemDrop) -> Result<&'a FloorItem, anyhow::Error> { - let room_id = self.character_room.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - - enum ItemOrMeseta { - Individual(ItemDetail), - Stacked(Tool), - Meseta(Meseta) - } - - let item = match item_drop.item { - ItemDropType::Weapon(w) => ItemOrMeseta::Individual(ItemDetail::Weapon(w)), - ItemDropType::Armor(w) => ItemOrMeseta::Individual(ItemDetail::Armor(w)), - ItemDropType::Shield(w) => ItemOrMeseta::Individual(ItemDetail::Shield(w)), - ItemDropType::Unit(w) => ItemOrMeseta::Individual(ItemDetail::Unit(w)), - ItemDropType::TechniqueDisk(w) => ItemOrMeseta::Individual(ItemDetail::TechniqueDisk(w)), - ItemDropType::Mag(w) => ItemOrMeseta::Individual(ItemDetail::Mag(w)), - //ItemDropType::IndividualTool(t) => ItemOrMeseta::Individual(ItemDetail::Tool(t)), - //ItemDropType::StackedTool(t, _) => ItemOrMeseta::Stacked(t), - ItemDropType::Tool(t) if t.tool.is_stackable() => ItemOrMeseta::Stacked(t), - ItemDropType::Tool(t) if !t.tool.is_stackable() => ItemOrMeseta::Individual(ItemDetail::Tool(t)), - ItemDropType::Meseta(m) => ItemOrMeseta::Meseta(Meseta(m)), - _ => unreachable!() // rust isnt smart enough to see that the conditional on tool catches everything - }; - - let item_id = self.room_item_id_counter.borrow_mut().get_mut(room_id).ok_or(ItemManagerError::NoCharacter(character.id))?(); - let floor_item = match item { - ItemOrMeseta::Individual(item_detail) => { - let entity = entity_gateway.create_item(NewItemEntity { - item: item_detail.clone(), - }).await?; - entity_gateway.add_item_note(&entity.id, ItemNote::EnemyDrop { - character_id: character.id, - map_area: item_drop.map_area, - x: item_drop.x, - y: item_drop.y, - z: item_drop.z, - }).await?; - FloorItem::Individual(IndividualFloorItem { - entity_id: entity.id, - item_id, - item: item_detail, - map_area: item_drop.map_area, - x: item_drop.x, - y: item_drop.y, - z: item_drop.z, - }) - }, - ItemOrMeseta::Stacked(tool) => { - let entity = entity_gateway.create_item(NewItemEntity { - item: ItemDetail::Tool(tool), - }).await?; - entity_gateway.add_item_note(&entity.id, ItemNote::EnemyDrop { - character_id: character.id, - map_area: item_drop.map_area, - x: item_drop.x, - y: item_drop.y, - z: item_drop.z, - }).await?; - FloorItem::Stacked(StackedFloorItem { - entity_ids: vec![entity.id], - item_id, - tool, - map_area: item_drop.map_area, - x: item_drop.x, - y: item_drop.y, - z: item_drop.z, - }) - }, - ItemOrMeseta::Meseta(meseta) => { - FloorItem::Meseta(MesetaFloorItem { - item_id, - meseta, - map_area: item_drop.map_area, - x: item_drop.x, - y: item_drop.y, - z: item_drop.z, - }) - }, - }; - - self.character_floor.entry(character.id).or_insert_with(RoomFloorItems::default).add_item(floor_item); - // TODO: make these real errors - self.character_floor.get(&character.id).ok_or(ItemManagerError::Idunnoman)?.get_item_by_id(item_id).ok_or_else(|| ItemManagerError::Idunnoman.into()) - } - - pub async fn player_drop_item_on_shared_floor(&mut self, - entity_gateway: &mut EG, - character: &CharacterEntity, - //inventory_item: InventoryItem, - item_id: ClientItemId, - item_drop_location: (MapArea, f32, f32, f32)) - -> Result<(), anyhow::Error> { - let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let room_id = self.character_room.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let shared_floor = self.room_floor.get_mut(room_id).ok_or(ItemManagerError::NoCharacter(character.id))?; - - let dropped_inventory_item = inventory.take_item_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?; - - match dropped_inventory_item { - InventoryItem::Individual(individual_inventory_item) => { - let individual_floor_item = shared_floor.drop_individual_inventory_item(individual_inventory_item, item_drop_location); - entity_gateway.add_item_note( - &individual_floor_item.entity_id, - ItemNote::PlayerDrop { - character_id: character.id, - map_area: item_drop_location.0, - x: item_drop_location.1, - y: item_drop_location.2, - z: item_drop_location.3, - } - ).await?; - }, - InventoryItem::Stacked(stacked_inventory_item) => { - let stacked_floor_item = shared_floor.drop_stacked_inventory_item(stacked_inventory_item, item_drop_location); - for entity_id in &stacked_floor_item.entity_ids { - entity_gateway.add_item_note( - entity_id, - ItemNote::PlayerDrop { - character_id: character.id, - map_area: item_drop_location.0, - x: item_drop_location.1, - y: item_drop_location.2, - z: item_drop_location.3, - } - ).await?; - } - }, - } - - entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; - Ok(()) - } - - pub async fn player_drops_meseta_on_shared_floor(&mut self, - entity_gateway: &mut EG, - character: &mut CharacterEntity, - drop_location: ItemDropLocation, - amount: u32) - -> Result { - let room_id = self.character_room.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let shared_floor = self.room_floor.get_mut(room_id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let character_meseta = self.character_meseta.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - if character_meseta.0 < amount { - return Err(ItemManagerError::CouldNotDropMeseta.into()) - } - character_meseta.0 -= amount; - entity_gateway.set_character_meseta(&character.id, *character_meseta).await?; - - let item_id = self.room_item_id_counter.borrow_mut().get_mut(room_id).ok_or(ItemManagerError::NoCharacter(character.id))?(); - let floor_item = FloorItem::Meseta(MesetaFloorItem { - item_id, - meseta: Meseta(amount), - map_area: drop_location.map_area, - x: drop_location.x, - y: 0.0, - z: drop_location.z, - }); - - shared_floor.add_item(floor_item.clone()); - Ok(floor_item) - } - - pub async fn player_drops_partial_stack_on_shared_floor<'a, EG: EntityGateway>(&'a mut self, - entity_gateway: &'a mut EG, - character: &'a CharacterEntity, - //inventory_item: InventoryItem, - item_id: ClientItemId, - drop_location: ItemDropLocation, - amount: usize) - -> Result<&'a StackedFloorItem, anyhow::Error> { - let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let room_id = self.character_room.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let shared_floor = self.room_floor.get_mut(room_id).ok_or(ItemManagerError::NoCharacter(character.id))?; - - let item_to_split = inventory.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?; - - let new_item_id = self.room_item_id_counter.borrow_mut().get_mut(room_id).ok_or(ItemManagerError::NoCharacter(character.id))?(); - let stacked_floor_item = shared_floor.drop_partial_stacked_inventory_item(item_to_split, amount, new_item_id, (drop_location.map_area, drop_location.x, 0.0, drop_location.z)) - .ok_or(ItemManagerError::CouldNotSplitItem(item_id))?; - - for entity_id in &stacked_floor_item.entity_ids { - entity_gateway.add_item_note( - entity_id, - ItemNote::PlayerDrop { - character_id: character.id, - map_area: drop_location.map_area, - x: drop_location.x, - y: 0.0, - z: drop_location.z, - } - ).await?; - } - - entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; - Ok(stacked_floor_item) - } - - pub async fn player_consumes_tool(&mut self, - entity_gateway: &mut EG, - character: &mut CharacterEntity, - item_id: ClientItemId, - amount: usize) - -> Result { - let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let used_item = inventory.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?; - let consumed_item = used_item.consume(amount)?; - - if let ItemDetail::TechniqueDisk(tech_disk) = consumed_item.item() { - // TODO: validate tech level in packet is in bounds [1..30] - character.techs.set_tech(tech_disk.tech, TechLevel(tech_disk.level as u8)); - entity_gateway.save_character(character).await?; - }; - - for entity_id in consumed_item.entity_ids() { - entity_gateway.add_item_note(&entity_id, - ItemNote::Consumed).await?; - } - - entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; - Ok(consumed_item) - } - - pub async fn player_deposits_item(&mut self, - entity_gateway: &mut EG, - character: &CharacterEntity, - item_id: ClientItemId, - amount: usize) - -> Result<(), anyhow::Error> { - let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let bank = self.character_bank - .get_mut(&character.id) - .ok_or(ItemManagerError::NoCharacter(character.id))?; - - let item_to_deposit = inventory.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?; - let _bank_item = bank.deposit_item(item_to_deposit, amount).ok_or(ItemManagerError::Idunnoman)?; - - entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; - entity_gateway.set_character_bank(&character.id, &bank.as_bank_entity(&character.id, &BankName("".into())), &BankName("".into())).await?; - Ok(()) - } - - pub async fn player_withdraws_item<'a, EG: EntityGateway>(&'a mut self, - entity_gateway: &'a mut EG, - character: &'a CharacterEntity, - item_id: ClientItemId, - amount: usize) - -> Result<&'a InventoryItem, anyhow::Error> { - - let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let bank = self.character_bank - .get_mut(&character.id) - .ok_or(ItemManagerError::NoCharacter(character.id))?; - - let item_to_withdraw = bank.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?; - let inventory_item_slot = { - let inventory_item = inventory.withdraw_item(item_to_withdraw, amount).ok_or(ItemManagerError::Idunnoman)?; - inventory_item.1 - }; - - entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; - entity_gateway.set_character_bank(&character.id, &bank.as_bank_entity(&character.id, &BankName("".into())), &BankName("".into())).await?; - inventory.slot(inventory_item_slot).ok_or_else(|| ItemManagerError::Idunnoman.into()) - } - - pub async fn player_feeds_mag_item(&mut self, - entity_gateway: &mut EG, - character: &CharacterEntity, - mag_id: ClientItemId, - tool_id: ClientItemId) - -> Result<(), anyhow::Error> { - let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let consumed_tool = { - let item_to_feed = inventory.get_item_handle_by_id(tool_id).ok_or(ItemManagerError::NoSuchItemId(tool_id))?; - item_to_feed.consume(1)? - }; - let mut mag_handle = inventory.get_item_handle_by_id(mag_id).ok_or(ItemManagerError::NoSuchItemId(mag_id))?; - - let individual_item = mag_handle.item_mut() - .ok_or(ItemManagerError::NoSuchItemId(mag_id))? - .individual_mut() - .ok_or(ItemManagerError::WrongItemType(mag_id))?; - let mag = individual_item - .mag_mut() - .ok_or(ItemManagerError::WrongItemType(mag_id))?; - - let consumed_tool_type = match &consumed_tool { - ConsumedItem::Stacked(stacked_consumed_item) => stacked_consumed_item.tool.tool, - _ => return Err(ItemManagerError::WrongItemType(tool_id).into()) - }; - mag.feed(consumed_tool_type); - - for entity_id in consumed_tool.entity_ids() { - entity_gateway.feed_mag(&individual_item.entity_id, &entity_id).await?; - entity_gateway.add_item_note(&entity_id, ItemNote::FedToMag { - mag: individual_item.entity_id, - }).await?; - } - - entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; - Ok(()) - } - - pub async fn use_item(&mut self, - used_item: ConsumedItem, - entity_gateway: &mut EG, - character: &mut CharacterEntity) -> Result<(), anyhow::Error> { - let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - match &used_item.item() { - ItemDetail::Weapon(_w) => { - // something like when items are used to combine/transform them? - //_ => {} - }, - ItemDetail::Tool(t) => { - match t.tool { - ToolType::PowerMaterial => { - use_tool::power_material(entity_gateway, character).await; - }, - ToolType::MindMaterial => { - use_tool::mind_material(entity_gateway, character).await; - }, - ToolType::EvadeMaterial => { - use_tool::evade_material(entity_gateway, character).await; - }, - ToolType::DefMaterial => { - use_tool::def_material(entity_gateway, character).await; - }, - ToolType::LuckMaterial => { - use_tool::luck_material(entity_gateway, character).await; - }, - ToolType::HpMaterial => { - use_tool::hp_material(entity_gateway, character).await; - }, - ToolType::TpMaterial => { - use_tool::tp_material(entity_gateway, character).await; - }, - ToolType::CellOfMag502 => { - use_tool::cell_of_mag_502(entity_gateway, &used_item, inventory).await?; - }, - ToolType::CellOfMag213 => { - use_tool::cell_of_mag_213(entity_gateway, &used_item, inventory).await?; - }, - ToolType::PartsOfRobochao => { - use_tool::parts_of_robochao(entity_gateway, &used_item, inventory).await?; - }, - ToolType::HeartOfOpaOpa => { - use_tool::heart_of_opaopa(entity_gateway, &used_item, inventory).await?; - }, - ToolType::HeartOfPian => { - use_tool::heart_of_pian(entity_gateway, &used_item, inventory).await?; - }, - ToolType::HeartOfChao=> { - use_tool::heart_of_chao(entity_gateway, &used_item, inventory).await?; - }, - ToolType::HeartOfAngel => { - use_tool::heart_of_angel(entity_gateway, &used_item, inventory).await?; - }, - ToolType::KitOfHamburger => { - use_tool::kit_of_hamburger(entity_gateway, &used_item, inventory).await?; - }, - ToolType::PanthersSpirit => { - use_tool::panthers_spirit(entity_gateway, &used_item, inventory).await?; - }, - ToolType::KitOfMark3 => { - use_tool::kit_of_mark3(entity_gateway, &used_item, inventory).await?; - }, - ToolType::KitOfMasterSystem=> { - use_tool::kit_of_master_system(entity_gateway, &used_item, inventory).await?; - }, - ToolType::KitOfGenesis => { - use_tool::kit_of_genesis(entity_gateway, &used_item, inventory).await?; - }, - ToolType::KitOfSegaSaturn => { - use_tool::kit_of_sega_saturn(entity_gateway, &used_item, inventory).await?; - }, - ToolType::KitOfDreamcast => { - use_tool::kit_of_dreamcast(entity_gateway, &used_item, inventory).await?; - }, - ToolType::Tablet => { - use_tool::tablet(entity_gateway, &used_item, inventory).await?; - }, - ToolType::DragonScale => { - use_tool::dragon_scale(entity_gateway, &used_item, inventory).await?; - }, - ToolType::HeavenStrikerCoat => { - use_tool::heaven_striker_coat(entity_gateway, &used_item, inventory).await?; - }, - ToolType::PioneerParts => { - use_tool::pioneer_parts(entity_gateway, &used_item, inventory).await?; - }, - ToolType::AmitiesMemo => { - use_tool::amities_memo(entity_gateway, &used_item, inventory).await?; - }, - ToolType::HeartOfMorolian => { - use_tool::heart_of_morolian(entity_gateway, &used_item, inventory).await?; - }, - ToolType::RappysBeak => { - use_tool::rappys_beak(entity_gateway, &used_item, inventory).await?; - }, - ToolType::YahoosEngine => { - use_tool::yahoos_engine(entity_gateway, &used_item, inventory).await?; - }, - ToolType::DPhotonCore => { - use_tool::d_photon_core(entity_gateway, &used_item, inventory).await?; - }, - ToolType::LibertaKit => { - use_tool::liberta_kit(entity_gateway, &used_item, inventory).await?; - }, - _ => {} - } - } - _ => {} - } - entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; - Ok(()) - } - - pub async fn player_buys_item<'a, EG: EntityGateway>(&'a mut self, - entity_gateway: &'a mut EG, - character: &'a CharacterEntity, - shop_item: &'a (dyn ShopItem + Send + Sync), - item_id: ClientItemId, - amount: usize) - -> Result<&'a InventoryItem, anyhow::Error> { - let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - - let item_detail = shop_item.as_item(); - let inventory_item = match item_detail { - ItemDetail::Tool(tool) => { - if tool.is_stackable() { - let mut item_entities = Vec::new(); - for _ in 0..amount { - let item_entity = entity_gateway.create_item(NewItemEntity { - item: ItemDetail::Tool(tool), - }).await?; - entity_gateway.add_item_note(&item_entity.id, ItemNote::BoughtAtShop { - character_id: character.id, - }).await?; - item_entities.push(item_entity); - } - let floor_item = StackedFloorItem { - entity_ids: item_entities.into_iter().map(|i| i.id).collect(), - item_id, - tool, - // TODO: this is gonna choke if I ever require the item being near the player for pickup - map_area: MapArea::Pioneer2Ep1, - x: 0.0, - y: 0.0, - z: 0.0, - }; - let item_id = { - let (picked_up_item, _slot) = inventory.pick_up_stacked_floor_item(&floor_item).ok_or(ItemManagerError::CouldNotAddBoughtItemToInventory)?; - picked_up_item.item_id - }; - inventory.get_item_by_id(item_id).ok_or(ItemManagerError::ItemIdNotInInventory(item_id))? - } - else { - let item_entity = entity_gateway.create_item(NewItemEntity { - item: ItemDetail::Tool(tool), - }).await?; - entity_gateway.add_item_note(&item_entity.id, ItemNote::BoughtAtShop { - character_id: character.id, - }).await?; - - let floor_item = IndividualFloorItem { - entity_id: item_entity.id, - item_id, - item: ItemDetail::Tool(tool), - // TODO: this is gonna choke if I ever require the item being near the player for pickup - map_area: MapArea::Pioneer2Ep1, - x: 0.0, - y: 0.0, - z: 0.0, - }; - let item_id = { - let (picked_up_item, _slot) = inventory.pick_up_individual_floor_item(&floor_item).ok_or(ItemManagerError::CouldNotAddBoughtItemToInventory)?; - picked_up_item.item_id - }; - inventory.get_item_by_id(item_id).ok_or(ItemManagerError::ItemIdNotInInventory(item_id))? - } - }, - item_detail => { - let item_entity = entity_gateway.create_item(NewItemEntity { - item: item_detail.clone(), - }).await?; - entity_gateway.add_item_note(&item_entity.id, ItemNote::BoughtAtShop { - character_id: character.id, - }).await?; - let floor_item = IndividualFloorItem { - entity_id: item_entity.id, - item_id, - item: item_detail, - // TODO: this is gonna choke if I ever require the item being near the player for pickup - map_area: MapArea::Pioneer2Ep1, - x: 0.0, - y: 0.0, - z: 0.0, - }; - let item_id = { - let (picked_up_item, _slot) = inventory.pick_up_individual_floor_item(&floor_item).ok_or(ItemManagerError::CouldNotAddBoughtItemToInventory)?; - picked_up_item.item_id - }; - inventory.get_item_by_id(item_id).ok_or(ItemManagerError::ItemIdNotInInventory(item_id))? - }, - }; - - entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; - Ok(inventory_item) - } - - pub async fn player_sells_item(&mut self, - entity_gateway: &mut EG, - character: &mut CharacterEntity, - item_id: ClientItemId, - amount: usize) - -> Result<(), anyhow::Error> { - let character_meseta = self.get_character_meseta(&character.id)?.0; - let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let sold_item_handle = inventory.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?; - if let Some(item_sold) = sold_item_handle.item() { - let unit_price = item_sold.get_sell_price()?; { - let total_sale = unit_price * amount as u32; - if character_meseta + total_sale <= 999999 { - match item_sold { - InventoryItem::Individual(i) => { - entity_gateway.add_item_note(&i.entity_id, ItemNote::SoldToShop).await?; - inventory.remove_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?; - }, - InventoryItem::Stacked(s) => { - match amount.cmp(&s.count()) { - Ordering::Less | Ordering::Equal => { - sold_item_handle.consume(amount)?; - }, - Ordering::Greater => return Err(ItemManagerError::InvalidSale.into()), - }; - }, - } - entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; - let character_meseta = self.get_character_meseta_mut(&character.id)?; - character_meseta.0 += total_sale; - entity_gateway.set_character_meseta(&character.id, *character_meseta).await?; - } - else { - return Err(ItemManagerError::WalletFull.into()) - } - } - } else { - return Err(ItemManagerError::ItemIdNotInInventory(item_id).into()) - } - Ok(()) - } - - // TODO: check if slot exists before putting units into it - pub async fn player_equips_item(&mut self, - entity_gateway: &mut EG, - character: &CharacterEntity, - item_id: ClientItemId, - equip_slot: u8) - -> Result<(), anyhow::Error> { - let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - inventory.equip(&item_id, equip_slot); - entity_gateway.set_character_equips(&character.id, &inventory.as_equipped_entity()).await?; - Ok(()) - } - - pub async fn player_unequips_item(&mut self, - entity_gateway: &mut EG, - character: &CharacterEntity, - item_id: ClientItemId) - -> Result<(), anyhow::Error> { - let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - inventory.unequip(&item_id); - entity_gateway.set_character_equips(&character.id, &inventory.as_equipped_entity()).await?; - Ok(()) - } - - pub async fn player_sorts_items(&mut self, - entity_gateway: &mut EG, - character: &CharacterEntity, - item_ids: [u32; 30]) - -> Result<(), anyhow::Error> { - let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - let sorted_inventory_items: Vec = item_ids.iter() - .filter(|&client_item_id| *client_item_id < 0xFFFFFFFF) - .map(|&client_item_id| inventory.get_item_by_id(ClientItemId(client_item_id))) - .filter(|&x| x.is_some()) - .map(|x| x.cloned().unwrap()) - .collect(); - - inventory.set_items(sorted_inventory_items); - entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; - Ok(()) - } - - pub async fn replace_item_with_tekked(&mut self, - entity_gateway: &mut EG, - character: &CharacterEntity, - item_id: ClientItemId, - tek: weapon::WeaponModifier) - -> Result { - let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; - - let item = inventory.remove_by_id(item_id) - .ok_or(ItemManagerError::NoSuchItemId(item_id))?; - let individual = item - .individual() - .ok_or(ItemManagerError::WrongItemType(item_id))?; - - let entity_id = individual.entity_id; - let mut weapon = *individual - .weapon() - .ok_or(ItemManagerError::WrongItemType(item_id))?; - - weapon.apply_modifier(&tek); - entity_gateway.add_weapon_modifier(&entity_id, tek).await?; - - inventory.add_item(InventoryItem::Individual(IndividualInventoryItem { - entity_id, - item_id, - item: ItemDetail::Weapon(weapon), - })); - - entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; - - Ok(weapon) - } - - pub async fn trade_items(&mut self, - entity_gateway: &mut EG, - room_id: RoomId, - p1: (&AreaClient, &CharacterEntity, &Vec, usize), - p2: (&AreaClient, &CharacterEntity, &Vec, usize)) - -> Result, anyhow::Error> { - let it = ItemTransaction::new(self, (p1, p2, room_id)) - .act(|it, (p1, p2, room_id)| -> Result<_, anyhow::Error> { - let p1_inventory = it.manager.get_character_inventory(p1.1)?; - let p2_inventory = it.manager.get_character_inventory(p2.1)?; - - [(p2_inventory, p1_inventory, p2.2, p1.2), (p1_inventory, p2_inventory, p1.2, p2.2)].iter() - .map(|(src_inventory, dest_inventory, trade_recv, trade_send)| { - let item_slots_lost_to_trade = trade_send - .iter() - .fold(0, |acc, item| { - match item { - TradeItem::Individual(..) => { - acc + 1 - }, - TradeItem::Stacked(item_id, amount) => { - let stacked_inventory_item = try { - src_inventory - .get_item_by_id(*item_id)? - .stacked() - }; - if let Some(Some(item)) = stacked_inventory_item { - if item.count() == *amount { - acc + 1 - } - else { - acc - } - } - else { - acc - } - } - } - }); - trade_recv - .iter() - .try_fold(dest_inventory.count(), |acc, item| { - match item { - TradeItem::Individual(..) => { - if acc >= (30 + item_slots_lost_to_trade) { - Err(TradeError::NoInventorySpace) - } - else { - Ok(acc + 1) - } - }, - TradeItem::Stacked(item_id, amount) => { - let stacked_inventory_item = src_inventory - .get_item_by_id(*item_id) - .ok_or(TradeError::InvalidItemId(*item_id))? - .stacked() - .ok_or(TradeError::InvalidItemId(*item_id))?; - match dest_inventory.space_for_stacked_item(&stacked_inventory_item.tool, *amount) { - SpaceForStack::Yes(YesThereIsSpace::ExistingStack) => { - Ok(acc) - }, - SpaceForStack::Yes(YesThereIsSpace::NewStack) => { - Ok(acc + 1) - }, - SpaceForStack::No(NoThereIsNotSpace::FullStack) => { - Err(TradeError::NoStackSpace) - }, - SpaceForStack::No(NoThereIsNotSpace::FullInventory) => { - if acc >= (30 + item_slots_lost_to_trade) { - Err(TradeError::NoInventorySpace) - } - else { - Ok(acc + 1) - } - }, - } - } - } - }) - }) - .collect::, _>>()?; - - let trade_items = [(p1, p2, p1_inventory), (p2, p1, p2_inventory)] - .map(|(src_client, dest_client, src_inventory)| { - src_client.2.iter() - .map(|item| -> Option<(Option, Box>)> { - match item { - TradeItem::Individual(item_id) => { - let item = src_inventory.get_item_by_id(*item_id)?.individual()?; - let new_item_id = it.manager.room_item_id_counter.borrow_mut().get_mut(room_id)?(); - Some(( - Some(ItemToTrade { - add_to: *dest_client.0, - remove_from: *src_client.0, - current_item_id: *item_id, - new_item_id, - item_detail: ItemToTradeDetail::Individual(item.item.clone()) - }), - Box::new(TradeIndividualItem { - src_character_id: src_client.1.id, - dest_character_id: dest_client.1.id, - current_item_id: *item_id, - new_item_id, - }), - )) - }, - TradeItem::Stacked(item_id, amount) => { - let item = src_inventory.get_item_by_id(*item_id)?.stacked()?; - if item.count() < *amount { - None - } - else { - let new_item_id = it.manager.room_item_id_counter.borrow_mut().get_mut(room_id)?(); - Some(( - Some(ItemToTrade { - add_to: *dest_client.0, - remove_from: *src_client.0, - current_item_id: *item_id, - new_item_id, - item_detail: ItemToTradeDetail::Stacked(item.tool, *amount) - }), - Box::new(TradeStackedItem { - src_character_id: src_client.1.id, - dest_character_id: dest_client.1.id, - //item_ids: item.entity_ids.iter().cloned().take(*amount).collect(), - current_item_id: *item_id, - new_item_id, - amount: *amount, - }), - )) - } - } - } - }) - .chain( - if src_client.3 > 0 { - Box::new(std::iter::once(Some( - (Some(ItemToTrade { - add_to: *dest_client.0, - remove_from: *src_client.0, - current_item_id: OTHER_MESETA_ITEM_ID, - new_item_id: OTHER_MESETA_ITEM_ID, - item_detail: ItemToTradeDetail::Meseta(src_client.3) - }), - Box::new(TradeMeseta { - src_character_id: src_client.1.id, - dest_character_id: dest_client.1.id, - amount: src_client.3, - }) as Box>)))) as Box> - } - else { - Box::new(std::iter::empty()) as Box> - }) - .collect::>>() - }); - - - if let [Some(p1_trades), Some(p2_trades)] = trade_items { - let (p1_item_trades, p1_item_actions): (Vec<_>, Vec<_>) = p1_trades.into_iter().unzip(); - let (p2_item_trades, p2_item_actions): (Vec<_>, Vec<_>) = p2_trades.into_iter().unzip(); - - let item_trades = p1_item_trades.into_iter().flatten().chain(p2_item_trades.into_iter().flatten()); - let item_actions = p1_item_actions.into_iter().chain(p2_item_actions.into_iter()); - - for action in item_actions { - it.action(action); - } - - Ok(item_trades.collect()) - } - else { - Err(ItemManagerError::InvalidTrade.into()) - } - - }); - it.commit(self, entity_gateway) - .await - .map_err(|err| err.into()) - } -} - -#[derive(Debug)] -pub enum ItemToTradeDetail { - Individual(ItemDetail), - Stacked(Tool, usize), - Meseta(usize), -} - -#[derive(Debug)] -pub struct ItemToTrade { - pub add_to: AreaClient, - pub remove_from: AreaClient, - pub current_item_id: ClientItemId, - pub new_item_id: ClientItemId, - pub item_detail: ItemToTradeDetail, -} - - -#[derive(Debug)] -struct RemoveFromLocalFloor { - character_id: CharacterEntityId, - item_id: ClientItemId, -} - -#[async_trait::async_trait] -impl ItemAction for RemoveFromLocalFloor { - async fn commit(&self, item_manager: &mut ItemManager, _entity_gateway: &mut EG) -> Result<(), TransactionCommitError> { - let local_floor = item_manager.character_floor.get_mut(&self.character_id).ok_or(ItemManagerError::NoCharacter(self.character_id))?; - local_floor.remove_item(&self.item_id); - Ok(()) - } -} - - -#[derive(Debug)] -struct RemoveFromSharedFloor { - room_id: RoomId, - item_id: ClientItemId, -} - -#[async_trait::async_trait] -impl ItemAction for RemoveFromSharedFloor { - async fn commit(&self, item_manager: &mut ItemManager, _entity_gateway: &mut EG) -> Result<(), TransactionCommitError> { - let shared_floor = item_manager.room_floor.get_mut(&self.room_id).ok_or(ItemManagerError::NoRoom(self.room_id))?; - shared_floor.remove_item(&self.item_id); - Ok(()) - } -} - - -#[derive(Debug)] -struct AddIndividualFloorItemToInventory{ - character: CharacterEntity, - item: IndividualFloorItem, -} - -#[async_trait::async_trait] -impl ItemAction for AddIndividualFloorItemToInventory { - async fn commit(&self, item_manager: &mut ItemManager, entity_gateway: &mut EG) -> Result<(), TransactionCommitError> { - let inventory = item_manager.character_inventory.get_mut(&self.character.id).ok_or(ItemManagerError::NoCharacter(self.character.id))?; - let inv_item = inventory.add_individual_floor_item(&self.item); - - entity_gateway.add_item_note( - &self.item.entity_id, - ItemNote::Pickup { - character_id: self.character.id, - } - ).await?; - - if inv_item.mag().is_some() { - entity_gateway.change_mag_owner(&self.item.entity_id, &self.character).await?; - } - - entity_gateway.set_character_inventory(&self.character.id, &inventory.as_inventory_entity(&self.character.id)).await?; - Ok(()) - } -} - - -#[derive(Debug)] -struct AddStackedFloorItemToInventory{ - character_id: CharacterEntityId, - item: StackedFloorItem, -} - -#[async_trait::async_trait] -impl ItemAction for AddStackedFloorItemToInventory { - async fn commit(&self, item_manager: &mut ItemManager, entity_gateway: &mut EG) -> Result<(), TransactionCommitError> { - let inventory = item_manager.character_inventory.get_mut(&self.character_id).ok_or(ItemManagerError::NoCharacter(self.character_id))?; - inventory.add_stacked_floor_item(&self.item); - - entity_gateway.set_character_inventory(&self.character_id, &inventory.as_inventory_entity(&self.character_id)).await?; - Ok(()) - } -} - - -#[derive(Debug)] -struct AddMesetaFloorItemToInventory{ - character_id: CharacterEntityId, - item: MesetaFloorItem, -} - -#[async_trait::async_trait] -impl ItemAction for AddMesetaFloorItemToInventory { - async fn commit(&self, item_manager: &mut ItemManager, entity_gateway: &mut EG) -> Result<(), TransactionCommitError> { - let character_meseta = item_manager.character_meseta.get_mut(&self.character_id).ok_or(ItemManagerError::NoCharacter(self.character_id))?; - character_meseta.0 = std::cmp::min(character_meseta.0 + self.item.meseta.0, 999999); - entity_gateway.set_character_meseta(&self.character_id, *character_meseta).await?; - Ok(()) - } -} - - -#[derive(Debug)] -struct TradeIndividualItem { - src_character_id: CharacterEntityId, - dest_character_id: CharacterEntityId, - current_item_id: ClientItemId, - new_item_id: ClientItemId, -} - -#[async_trait::async_trait] -impl ItemAction for TradeIndividualItem { - async fn commit(&self, item_manager: &mut ItemManager, entity_gateway: &mut EG) -> Result<(), TransactionCommitError> { - let src_inventory = item_manager.character_inventory.get_mut(&self.src_character_id).ok_or(ItemManagerError::NoCharacter(self.src_character_id))?; - let inventory_item = src_inventory.take_item_by_id(self.current_item_id).ok_or(ItemManagerError::NoSuchItemId(self.current_item_id))?; - entity_gateway.set_character_inventory(&self.src_character_id, &src_inventory.as_inventory_entity(&self.src_character_id)).await?; - - let dest_inventory = item_manager.character_inventory.get_mut(&self.dest_character_id).ok_or(ItemManagerError::NoCharacter(self.dest_character_id))?; - dest_inventory.add_item_with_new_item_id(inventory_item, self.new_item_id); - entity_gateway.set_character_inventory(&self.dest_character_id, &dest_inventory.as_inventory_entity(&self.dest_character_id)).await?; - - Ok(()) - } -} - -#[derive(Debug)] -struct TradeStackedItem { - src_character_id: CharacterEntityId, - dest_character_id: CharacterEntityId, - current_item_id: ClientItemId, - new_item_id: ClientItemId, - amount: usize, -} - -#[async_trait::async_trait] -impl ItemAction for TradeStackedItem { - async fn commit(&self, item_manager: &mut ItemManager, entity_gateway: &mut EG) -> Result<(), TransactionCommitError> { - let src_inventory = item_manager.character_inventory.get_mut(&self.src_character_id).ok_or(ItemManagerError::NoCharacter(self.src_character_id))?; - let inventory_item = src_inventory.take_stacked_item_by_id(self.current_item_id, self.amount).ok_or(ItemManagerError::NoSuchItemId(self.current_item_id))?; - entity_gateway.set_character_inventory(&self.src_character_id, &src_inventory.as_inventory_entity(&self.src_character_id)).await?; - - let dest_inventory = item_manager.character_inventory.get_mut(&self.dest_character_id).ok_or(ItemManagerError::NoCharacter(self.dest_character_id))?; - dest_inventory.add_item_with_new_item_id(InventoryItem::Stacked(inventory_item), self.new_item_id); - entity_gateway.set_character_inventory(&self.dest_character_id, &dest_inventory.as_inventory_entity(&self.dest_character_id)).await?; - - Ok(()) - } -} - -#[derive(Debug)] -struct TradeMeseta { - src_character_id: CharacterEntityId, - dest_character_id: CharacterEntityId, - amount: usize, -} - -#[async_trait::async_trait] -impl ItemAction for TradeMeseta { - async fn commit(&self, item_manager: &mut ItemManager, entity_gateway: &mut EG) -> Result<(), TransactionCommitError> { - { - let src_meseta = item_manager.get_character_meseta_mut(&self.src_character_id)?; - src_meseta.0 -= self.amount as u32; - entity_gateway.set_character_meseta(&self.src_character_id, *src_meseta).await?; - } - { - let dest_meseta = item_manager.get_character_meseta_mut(&self.dest_character_id)?; - dest_meseta.0 += self.amount as u32; - entity_gateway.set_character_meseta(&self.dest_character_id, *dest_meseta).await?; - } - Ok(()) - } -} diff --git a/src/bin/login.rs b/src/bin/login.rs index f4c5335..8f8832b 100644 --- a/src/bin/login.rs +++ b/src/bin/login.rs @@ -1,7 +1,7 @@ use log::{info}; use entity::gateway::postgres::PostgresGateway; -use elseware::login::login::LoginServerState; -use elseware::login::character::CharacterServerState; +use login_server::login::LoginServerState; +use login_server::character::CharacterServerState; use networking::interserver::AuthToken; fn main() { @@ -38,17 +38,17 @@ fn main() { let login_state = LoginServerState::new(entity_gateway.clone(), charserv_ip); let login_loop = async_std::task::spawn(async move { - networking::mainloop::run_server(login_state, elseware::login::login::LOGIN_PORT).await; + networking::mainloop::run_server(login_state, login_server::login::LOGIN_PORT).await; }); let char_state = CharacterServerState::new(entity_gateway, AuthToken(shipgate_token)); let sub_char_state = char_state.clone(); let character_loop = async_std::task::spawn(async move { - networking::mainloop::run_server(sub_char_state, elseware::login::character::CHARACTER_PORT).await; + networking::mainloop::run_server(sub_char_state, login_server::character::CHARACTER_PORT).await; }); let inter_character_loop = async_std::task::spawn(async move { - networking::mainloop::run_interserver_listen(char_state, elseware::login::login::COMMUNICATION_PORT).await; + networking::mainloop::run_interserver_listen(char_state, login_server::login::COMMUNICATION_PORT).await; }); info!("[auth/character] starting server"); diff --git a/src/bin/main.rs b/src/bin/main.rs index e50db30..ec67554 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -2,10 +2,10 @@ use std::net::Ipv4Addr; use log::{info}; use networking::interserver::AuthToken; -use elseware::login::login::LoginServerState; -use elseware::login::character::CharacterServerState; -use elseware::patch::{PatchServerState, generate_patch_tree, load_config, load_motd}; -use elseware::ship::ship::ShipServerStateBuilder; +use login_server::login::LoginServerState; +use login_server::character::CharacterServerState; +use patch_server::{PatchServerState, generate_patch_tree, load_config, load_motd}; +use ship_server::ShipServerStateBuilder; use maps::Holiday; use entity::gateway::{EntityGateway, InMemoryGateway}; @@ -344,67 +344,67 @@ fn main() { info!("[auth] starting server"); let login_state = LoginServerState::new(entity_gateway.clone(), "127.0.0.1".parse().unwrap()); let login_loop = async_std::task::spawn(async move { - networking::mainloop::run_server(login_state, elseware::login::login::LOGIN_PORT).await; + networking::mainloop::run_server(login_state, login_server::login::LOGIN_PORT).await; }); info!("[character] starting server"); let char_state = CharacterServerState::new(entity_gateway.clone(), AuthToken("".into())); let sub_char_state = char_state.clone(); let character_loop = async_std::task::spawn(async move { - networking::mainloop::run_server(sub_char_state, elseware::login::character::CHARACTER_PORT).await; + networking::mainloop::run_server(sub_char_state, login_server::character::CHARACTER_PORT).await; }); let sub_char_state = char_state.clone(); let inter_character_loop = async_std::task::spawn(async move { - networking::mainloop::run_interserver_listen(sub_char_state, elseware::login::login::COMMUNICATION_PORT).await; + networking::mainloop::run_interserver_listen(sub_char_state, login_server::login::COMMUNICATION_PORT).await; }); info!("[ship] starting servers"); let ship_state = ShipServerStateBuilder::default() .name("US/Sona-Nyl".into()) .ip(Ipv4Addr::new(127,0,0,1)) - .port(elseware::ship::ship::SHIP_PORT) + .port(ship_server::SHIP_PORT) .event(Holiday::Halloween) .gateway(entity_gateway.clone()) .build(); let sub_ship_state = ship_state.clone(); let ship_loop1 = async_std::task::spawn(async move { - networking::mainloop::run_server(sub_ship_state, elseware::ship::ship::SHIP_PORT).await; + networking::mainloop::run_server(sub_ship_state, ship_server::SHIP_PORT).await; }); let sub_ship_state = ship_state.clone(); let inter_ship_loop1 = async_std::task::spawn(async move { - networking::mainloop::run_interserver_connect(sub_ship_state, std::net::Ipv4Addr::new(127, 0, 0, 1), elseware::login::login::COMMUNICATION_PORT).await; + networking::mainloop::run_interserver_connect(sub_ship_state, std::net::Ipv4Addr::new(127, 0, 0, 1), login_server::login::COMMUNICATION_PORT).await; }); let ship_state = ShipServerStateBuilder::default() .name("EU/Dylath-Leen".into()) .ip(Ipv4Addr::new(127,0,0,1)) - .port(elseware::ship::ship::SHIP_PORT+2000) + .port(ship_server::SHIP_PORT+2000) .event(Holiday::Christmas) .gateway(entity_gateway.clone()) .build(); let sub_ship_state = ship_state.clone(); let ship_loop2 = async_std::task::spawn(async move { - networking::mainloop::run_server(sub_ship_state, elseware::ship::ship::SHIP_PORT+2000).await; + networking::mainloop::run_server(sub_ship_state, ship_server::SHIP_PORT+2000).await; }); let sub_ship_state = ship_state.clone(); let inter_ship_loop2 = async_std::task::spawn(async move { - networking::mainloop::run_interserver_connect(sub_ship_state, std::net::Ipv4Addr::new(127, 0, 0, 1), elseware::login::login::COMMUNICATION_PORT).await; + networking::mainloop::run_interserver_connect(sub_ship_state, std::net::Ipv4Addr::new(127, 0, 0, 1), login_server::login::COMMUNICATION_PORT).await; }); let ship_state = ShipServerStateBuilder::default() .name("JP/Thalarion".into()) .ip(Ipv4Addr::new(127,0,0,1)) - .port(elseware::ship::ship::SHIP_PORT+3000) + .port(ship_server::SHIP_PORT+3000) .gateway(entity_gateway.clone()) .build(); let sub_ship_state = ship_state.clone(); let ship_loop3 = async_std::task::spawn(async move { - networking::mainloop::run_server(sub_ship_state, elseware::ship::ship::SHIP_PORT+3000).await; + networking::mainloop::run_server(sub_ship_state, ship_server::SHIP_PORT+3000).await; }); let sub_ship_state = ship_state.clone(); let inter_ship_loop3 = async_std::task::spawn(async move { - networking::mainloop::run_interserver_connect(sub_ship_state, std::net::Ipv4Addr::new(127, 0, 0, 1), elseware::login::login::COMMUNICATION_PORT).await; + networking::mainloop::run_interserver_connect(sub_ship_state, std::net::Ipv4Addr::new(127, 0, 0, 1), login_server::login::COMMUNICATION_PORT).await; }); futures::future::join_all(vec![patch_loop, login_loop, character_loop, inter_character_loop, diff --git a/src/bin/patch.rs b/src/bin/patch.rs index a9fb839..c38f025 100644 --- a/src/bin/patch.rs +++ b/src/bin/patch.rs @@ -1,4 +1,4 @@ -use elseware::patch::{PatchServerState, generate_patch_tree, load_config_env, load_motd}; +use patch_server::{PatchServerState, generate_patch_tree, load_config_env, load_motd}; use log::info; fn main() { diff --git a/src/bin/ship.rs b/src/bin/ship.rs index c021601..b664bda 100644 --- a/src/bin/ship.rs +++ b/src/bin/ship.rs @@ -1,6 +1,6 @@ use log::info; use entity::gateway::postgres::PostgresGateway; -use elseware::ship::ship::ShipServerStateBuilder; +use ship_server::ShipServerStateBuilder; use networking::interserver::AuthToken; fn main() { @@ -40,7 +40,7 @@ fn main() { let ship_state = ShipServerStateBuilder::default() .name(ship_name) .ip(ip) - .port(elseware::ship::ship::SHIP_PORT) + .port(ship_server::SHIP_PORT) .gateway(entity_gateway) .auth_token(AuthToken(shipgate_token)) .build(); @@ -49,10 +49,10 @@ fn main() { let sub_ship_state = ship_state.clone(); let ship_loop = async_std::task::spawn(async move { - networking::mainloop::run_server(sub_ship_state, elseware::ship::ship::SHIP_PORT).await; + networking::mainloop::run_server(sub_ship_state, ship_server::SHIP_PORT).await; }); let inter_ship_loop = async_std::task::spawn(async move { - networking::mainloop::run_interserver_connect(ship_state, shipgate_ip, elseware::login::login::COMMUNICATION_PORT).await; + networking::mainloop::run_interserver_connect(ship_state, shipgate_ip, login_server::login::COMMUNICATION_PORT).await; }); info!("[auth/character] starting server"); diff --git a/client/Cargo.toml b/src/client/Cargo.toml similarity index 100% rename from client/Cargo.toml rename to src/client/Cargo.toml diff --git a/client/src/lib.rs b/src/client/src/lib.rs similarity index 100% rename from client/src/lib.rs rename to src/client/src/lib.rs diff --git a/drops/Cargo.toml b/src/drops/Cargo.toml similarity index 100% rename from drops/Cargo.toml rename to src/drops/Cargo.toml diff --git a/drops/src/box_drop_table.rs b/src/drops/src/box_drop_table.rs similarity index 100% rename from drops/src/box_drop_table.rs rename to src/drops/src/box_drop_table.rs diff --git a/drops/src/generic_armor.rs b/src/drops/src/generic_armor.rs similarity index 100% rename from drops/src/generic_armor.rs rename to src/drops/src/generic_armor.rs diff --git a/drops/src/generic_shield.rs b/src/drops/src/generic_shield.rs similarity index 100% rename from drops/src/generic_shield.rs rename to src/drops/src/generic_shield.rs diff --git a/drops/src/generic_unit.rs b/src/drops/src/generic_unit.rs similarity index 100% rename from drops/src/generic_unit.rs rename to src/drops/src/generic_unit.rs diff --git a/drops/src/generic_weapon.rs b/src/drops/src/generic_weapon.rs similarity index 100% rename from drops/src/generic_weapon.rs rename to src/drops/src/generic_weapon.rs diff --git a/drops/src/lib.rs b/src/drops/src/lib.rs similarity index 100% rename from drops/src/lib.rs rename to src/drops/src/lib.rs diff --git a/drops/src/rare_drop_table.rs b/src/drops/src/rare_drop_table.rs similarity index 100% rename from drops/src/rare_drop_table.rs rename to src/drops/src/rare_drop_table.rs diff --git a/drops/src/tech_table.rs b/src/drops/src/tech_table.rs similarity index 100% rename from drops/src/tech_table.rs rename to src/drops/src/tech_table.rs diff --git a/drops/src/tool_table.rs b/src/drops/src/tool_table.rs similarity index 100% rename from drops/src/tool_table.rs rename to src/drops/src/tool_table.rs diff --git a/entity/Cargo.toml b/src/entity/Cargo.toml similarity index 100% rename from entity/Cargo.toml rename to src/entity/Cargo.toml diff --git a/entity/src/account.rs b/src/entity/src/account.rs similarity index 100% rename from entity/src/account.rs rename to src/entity/src/account.rs diff --git a/entity/src/character.rs b/src/entity/src/character.rs similarity index 100% rename from entity/src/character.rs rename to src/entity/src/character.rs diff --git a/entity/src/gateway/entitygateway.rs b/src/entity/src/gateway/entitygateway.rs similarity index 100% rename from entity/src/gateway/entitygateway.rs rename to src/entity/src/gateway/entitygateway.rs diff --git a/entity/src/gateway/inmemory.rs b/src/entity/src/gateway/inmemory.rs similarity index 100% rename from entity/src/gateway/inmemory.rs rename to src/entity/src/gateway/inmemory.rs diff --git a/entity/src/gateway/mod.rs b/src/entity/src/gateway/mod.rs similarity index 100% rename from entity/src/gateway/mod.rs rename to src/entity/src/gateway/mod.rs diff --git a/entity/src/gateway/postgres/migrations/V0001__initial.sql b/src/entity/src/gateway/postgres/migrations/V0001__initial.sql similarity index 100% rename from entity/src/gateway/postgres/migrations/V0001__initial.sql rename to src/entity/src/gateway/postgres/migrations/V0001__initial.sql diff --git a/entity/src/gateway/postgres/migrations/V0002__equips.sql b/src/entity/src/gateway/postgres/migrations/V0002__equips.sql similarity index 100% rename from entity/src/gateway/postgres/migrations/V0002__equips.sql rename to src/entity/src/gateway/postgres/migrations/V0002__equips.sql diff --git a/entity/src/gateway/postgres/migrations/V0003__item_notes.sql b/src/entity/src/gateway/postgres/migrations/V0003__item_notes.sql similarity index 100% rename from entity/src/gateway/postgres/migrations/V0003__item_notes.sql rename to src/entity/src/gateway/postgres/migrations/V0003__item_notes.sql diff --git a/entity/src/gateway/postgres/migrations/V0004__meseta.sql b/src/entity/src/gateway/postgres/migrations/V0004__meseta.sql similarity index 100% rename from entity/src/gateway/postgres/migrations/V0004__meseta.sql rename to src/entity/src/gateway/postgres/migrations/V0004__meseta.sql diff --git a/entity/src/gateway/postgres/migrations/V0005__trade.sql b/src/entity/src/gateway/postgres/migrations/V0005__trade.sql similarity index 100% rename from entity/src/gateway/postgres/migrations/V0005__trade.sql rename to src/entity/src/gateway/postgres/migrations/V0005__trade.sql diff --git a/entity/src/gateway/postgres/migrations/V0006__playtime.sql b/src/entity/src/gateway/postgres/migrations/V0006__playtime.sql similarity index 100% rename from entity/src/gateway/postgres/migrations/V0006__playtime.sql rename to src/entity/src/gateway/postgres/migrations/V0006__playtime.sql diff --git a/entity/src/gateway/postgres/migrations/V0007__player_keyconfig.sql b/src/entity/src/gateway/postgres/migrations/V0007__player_keyconfig.sql similarity index 100% rename from entity/src/gateway/postgres/migrations/V0007__player_keyconfig.sql rename to src/entity/src/gateway/postgres/migrations/V0007__player_keyconfig.sql diff --git a/entity/src/gateway/postgres/migrations/V0008__playtime_not_null.sql b/src/entity/src/gateway/postgres/migrations/V0008__playtime_not_null.sql similarity index 100% rename from entity/src/gateway/postgres/migrations/V0008__playtime_not_null.sql rename to src/entity/src/gateway/postgres/migrations/V0008__playtime_not_null.sql diff --git a/entity/src/gateway/postgres/migrations/V0009__no_player_keyconfig.sql b/src/entity/src/gateway/postgres/migrations/V0009__no_player_keyconfig.sql similarity index 100% rename from entity/src/gateway/postgres/migrations/V0009__no_player_keyconfig.sql rename to src/entity/src/gateway/postgres/migrations/V0009__no_player_keyconfig.sql diff --git a/entity/src/gateway/postgres/migrations/V0010__char_create_timestamp.sql b/src/entity/src/gateway/postgres/migrations/V0010__char_create_timestamp.sql similarity index 100% rename from entity/src/gateway/postgres/migrations/V0010__char_create_timestamp.sql rename to src/entity/src/gateway/postgres/migrations/V0010__char_create_timestamp.sql diff --git a/entity/src/gateway/postgres/migrations/V0011__shared_bank.sql b/src/entity/src/gateway/postgres/migrations/V0011__shared_bank.sql similarity index 100% rename from entity/src/gateway/postgres/migrations/V0011__shared_bank.sql rename to src/entity/src/gateway/postgres/migrations/V0011__shared_bank.sql diff --git a/entity/src/gateway/postgres/migrations/V0012__room.sql b/src/entity/src/gateway/postgres/migrations/V0012__room.sql similarity index 100% rename from entity/src/gateway/postgres/migrations/V0012__room.sql rename to src/entity/src/gateway/postgres/migrations/V0012__room.sql diff --git a/entity/src/gateway/postgres/migrations/V0013__room2.sql b/src/entity/src/gateway/postgres/migrations/V0013__room2.sql similarity index 100% rename from entity/src/gateway/postgres/migrations/V0013__room2.sql rename to src/entity/src/gateway/postgres/migrations/V0013__room2.sql diff --git a/entity/src/gateway/postgres/migrations/mod.rs b/src/entity/src/gateway/postgres/migrations/mod.rs similarity index 100% rename from entity/src/gateway/postgres/migrations/mod.rs rename to src/entity/src/gateway/postgres/migrations/mod.rs diff --git a/entity/src/gateway/postgres/mod.rs b/src/entity/src/gateway/postgres/mod.rs similarity index 100% rename from entity/src/gateway/postgres/mod.rs rename to src/entity/src/gateway/postgres/mod.rs diff --git a/entity/src/gateway/postgres/models.rs b/src/entity/src/gateway/postgres/models.rs similarity index 100% rename from entity/src/gateway/postgres/models.rs rename to src/entity/src/gateway/postgres/models.rs diff --git a/entity/src/gateway/postgres/postgres.rs b/src/entity/src/gateway/postgres/postgres.rs similarity index 100% rename from entity/src/gateway/postgres/postgres.rs rename to src/entity/src/gateway/postgres/postgres.rs diff --git a/entity/src/item/armor.rs b/src/entity/src/item/armor.rs similarity index 100% rename from entity/src/item/armor.rs rename to src/entity/src/item/armor.rs diff --git a/entity/src/item/esweapon.rs b/src/entity/src/item/esweapon.rs similarity index 100% rename from entity/src/item/esweapon.rs rename to src/entity/src/item/esweapon.rs diff --git a/entity/src/item/mag.rs b/src/entity/src/item/mag.rs similarity index 100% rename from entity/src/item/mag.rs rename to src/entity/src/item/mag.rs diff --git a/entity/src/item/mod.rs b/src/entity/src/item/mod.rs similarity index 100% rename from entity/src/item/mod.rs rename to src/entity/src/item/mod.rs diff --git a/entity/src/item/shield.rs b/src/entity/src/item/shield.rs similarity index 100% rename from entity/src/item/shield.rs rename to src/entity/src/item/shield.rs diff --git a/entity/src/item/tech.rs b/src/entity/src/item/tech.rs similarity index 100% rename from entity/src/item/tech.rs rename to src/entity/src/item/tech.rs diff --git a/entity/src/item/tool.rs b/src/entity/src/item/tool.rs similarity index 100% rename from entity/src/item/tool.rs rename to src/entity/src/item/tool.rs diff --git a/entity/src/item/unit.rs b/src/entity/src/item/unit.rs similarity index 100% rename from entity/src/item/unit.rs rename to src/entity/src/item/unit.rs diff --git a/entity/src/item/weapon.rs b/src/entity/src/item/weapon.rs similarity index 100% rename from entity/src/item/weapon.rs rename to src/entity/src/item/weapon.rs diff --git a/entity/src/lib.rs b/src/entity/src/lib.rs similarity index 100% rename from entity/src/lib.rs rename to src/entity/src/lib.rs diff --git a/entity/src/room.rs b/src/entity/src/room.rs similarity index 100% rename from entity/src/room.rs rename to src/entity/src/room.rs diff --git a/entity/src/team.rs b/src/entity/src/team.rs similarity index 100% rename from entity/src/team.rs rename to src/entity/src/team.rs diff --git a/items/Cargo.toml b/src/items/Cargo.toml similarity index 100% rename from items/Cargo.toml rename to src/items/Cargo.toml diff --git a/items/src/actions.rs b/src/items/src/actions.rs similarity index 100% rename from items/src/actions.rs rename to src/items/src/actions.rs diff --git a/items/src/apply_item.rs b/src/items/src/apply_item.rs similarity index 100% rename from items/src/apply_item.rs rename to src/items/src/apply_item.rs diff --git a/items/src/bank.rs b/src/items/src/bank.rs similarity index 100% rename from items/src/bank.rs rename to src/items/src/bank.rs diff --git a/items/src/floor.rs b/src/items/src/floor.rs similarity index 100% rename from items/src/floor.rs rename to src/items/src/floor.rs diff --git a/items/src/inventory.rs b/src/items/src/inventory.rs similarity index 100% rename from items/src/inventory.rs rename to src/items/src/inventory.rs diff --git a/items/src/itemstateaction.rs b/src/items/src/itemstateaction.rs similarity index 100% rename from items/src/itemstateaction.rs rename to src/items/src/itemstateaction.rs diff --git a/items/src/lib.rs b/src/items/src/lib.rs similarity index 100% rename from items/src/lib.rs rename to src/items/src/lib.rs diff --git a/items/src/state.rs b/src/items/src/state.rs similarity index 100% rename from items/src/state.rs rename to src/items/src/state.rs diff --git a/items/src/tasks.rs b/src/items/src/tasks.rs similarity index 100% rename from items/src/tasks.rs rename to src/items/src/tasks.rs diff --git a/items/src/trade.rs b/src/items/src/trade.rs similarity index 100% rename from items/src/trade.rs rename to src/items/src/trade.rs diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index f194399..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![allow(clippy::type_complexity)] -#![allow(incomplete_features)] -#![feature(inline_const)] -#![feature(extract_if)] -#![feature(try_blocks)] -#![feature(test)] -#![feature(error_generic_member_access)] - -extern crate test; - -//pub mod common; -//pub mod entity; -pub mod patch; -pub mod login; -pub mod ship; diff --git a/location/Cargo.toml b/src/location/Cargo.toml similarity index 100% rename from location/Cargo.toml rename to src/location/Cargo.toml diff --git a/location/src/lib.rs b/src/location/src/lib.rs similarity index 100% rename from location/src/lib.rs rename to src/location/src/lib.rs diff --git a/src/login/mod.rs b/src/login/mod.rs deleted file mode 100644 index a5b3370..0000000 --- a/src/login/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -#[allow(clippy::module_inception)] -pub mod login; -pub mod character; diff --git a/src/login/models.rs b/src/login/models.rs deleted file mode 100644 index c5fb059..0000000 --- a/src/login/models.rs +++ /dev/null @@ -1,92 +0,0 @@ -use std::time::SystemTime; -use std::io::Write; -//use diesel::sql_types::Timestamp; -use diesel::{Insertable, Queryable, Identifiable, Associations, AsExpression, FromSqlRow}; -//use bcrypt::{DEFAULT_COST, hash}; -use diesel::pg::Pg; -use diesel::sql_types; -use diesel::deserialize::{self, FromSql}; -use diesel::serialize::{self, ToSql, Output, IsNull}; -use diesel::backend::Backend; - -use libpso::character::settings; - -use elseware::schema::*; - -//const ELSEWHERE_COST: u32 = bcrypt::DEFAULT_COST; -const ELSEWHERE_COST: u32 = 5; - -#[derive(Debug, AsExpression, FromSqlRow)] -#[sql_type="sql_types::Binary"] -pub struct EUserSettings(pub settings::UserSettings); - -impl std::ops::Deref for EUserSettings { - type Target = settings::UserSettings; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -#[derive(Queryable, Identifiable, Debug)] -pub struct UserAccount { - pub id: i32, - pub username: String, - pub password: String, - pub guildcard: Option, - pub team_id: Option, - pub banned: bool, - pub muted_until: SystemTime, - pub created_at: SystemTime, -} - -#[derive(Insertable)] -#[table_name="user_accounts"] -pub struct NewUser { - username: String, - password: String, -} - -impl NewUser { - pub fn new(username: String, password: String) -> NewUser { - let crypt_password = bcrypt::hash(password, ELSEWHERE_COST).expect("could not hash password?"); - NewUser { - username: username, - password: crypt_password, - } - } -} - -#[derive(Queryable, Identifiable, Associations)] -#[belongs_to(UserAccount, foreign_key="user_id")] -#[table_name="user_settings"] -pub struct UserSettings { - pub id: i32, - pub user_id: i32, - //settings: Vec, - pub settings: EUserSettings, -} - -#[derive(Insertable, Debug)] -#[table_name="user_settings"] -pub struct NewUserSettings { - pub user_id: i32, - pub settings: EUserSettings, -} - -impl ToSql for EUserSettings { - fn to_sql(&self, out: &mut Output) -> serialize::Result { - out.write_all(&self.0.as_bytes()[..]) - .map(|_| IsNull::No) - .map_err(|e| Box::new(e) as Box) - } -} - -impl FromSql for EUserSettings { - fn from_sql(bytes: Option<&[u8]>) -> deserialize::Result { - let bytes_vec: Vec = as FromSql>::from_sql(bytes)?; - let mut static_bytes = [0u8; 0x1160]; - static_bytes[..0x1160].clone_from_slice(&bytes_vec); - Ok(EUserSettings(settings::UserSettings::from_bytes(static_bytes))) - } -} diff --git a/src/login_server/Cargo.toml b/src/login_server/Cargo.toml new file mode 100644 index 0000000..8ce2441 --- /dev/null +++ b/src/login_server/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "login_server" +version = "0.1.0" +edition = "2021" + +[dependencies] +entity = { workspace = true } +networking = { workspace = true } +pktbuilder = { workspace = true } +stats = { workspace = true } + +libpso = { workspace = true } + +async-std = { workspace = true } +async-trait = { workspace = true } +anyhow = { workspace = true } +bcrypt = { workspace = true } +crc = { workspace = true } +thiserror = { workspace = true } +chrono = { workspace = true } +rand= { workspace = true } diff --git a/src/login/character.rs b/src/login_server/src/character.rs similarity index 99% rename from src/login/character.rs rename to src/login_server/src/character.rs index 6529f3d..ec9d3d3 100644 --- a/src/login/character.rs +++ b/src/login_server/src/character.rs @@ -31,7 +31,7 @@ use entity::item::tool::Tool; use entity::item::mag::Mag; use entity::character::{CharacterEntity, NewCharacterEntity, CharacterClass, TechLevel}; -use crate::login::login::{get_login_status}; +use crate::login::get_login_status; use networking::interserver::AuthToken; use pktbuilder::ship::SHIP_MENU_ID; diff --git a/src/login_server/src/lib.rs b/src/login_server/src/lib.rs new file mode 100644 index 0000000..0006241 --- /dev/null +++ b/src/login_server/src/lib.rs @@ -0,0 +1,2 @@ +pub mod login; +pub mod character; diff --git a/src/login/login.rs b/src/login_server/src/login.rs similarity index 98% rename from src/login/login.rs rename to src/login_server/src/login.rs index cdc32d9..70bb5a4 100644 --- a/src/login/login.rs +++ b/src/login_server/src/login.rs @@ -83,21 +83,13 @@ pub async fn get_login_status(entity_gateway: &mut impl EntityGateway, pkt: &Log pub fn check_if_already_online(user: UserAccountEntity) -> Result { Ok(user) - /* - if user.is_currently_online() { - Err(AccountStatus::PayUp) -} - else { - Ok(user) -} - */ } #[derive(Clone)] pub struct LoginServerState { character_server_ip: net::Ipv4Addr, entity_gateway: EG, - clients: HashMap, + clients: HashMap, // TODO: this should be arc/mutex'd? } impl LoginServerState { @@ -119,7 +111,7 @@ impl LoginServerState { let response = SendLoginPacket::LoginResponse(LoginResponse::by_status(AccountStatus::Ok, pkt.session)); let ip = u32::from_ne_bytes(self.character_server_ip.octets()); Ok(vec![response, - SendLoginPacket::RedirectClient(RedirectClient::new(ip, crate::login::character::CHARACTER_PORT))]) + SendLoginPacket::RedirectClient(RedirectClient::new(ip, crate::character::CHARACTER_PORT))]) }, Err(err) => { Ok(vec![SendLoginPacket::LoginResponse(LoginResponse::by_status(err, pkt.session))]) diff --git a/maps/Cargo.toml b/src/maps/Cargo.toml similarity index 100% rename from maps/Cargo.toml rename to src/maps/Cargo.toml diff --git a/maps/src/area.rs b/src/maps/src/area.rs similarity index 100% rename from maps/src/area.rs rename to src/maps/src/area.rs diff --git a/maps/src/enemy.rs b/src/maps/src/enemy.rs similarity index 100% rename from maps/src/enemy.rs rename to src/maps/src/enemy.rs diff --git a/maps/src/lib.rs b/src/maps/src/lib.rs similarity index 100% rename from maps/src/lib.rs rename to src/maps/src/lib.rs diff --git a/maps/src/maps.rs b/src/maps/src/maps.rs similarity index 100% rename from maps/src/maps.rs rename to src/maps/src/maps.rs diff --git a/maps/src/monster.rs b/src/maps/src/monster.rs similarity index 100% rename from maps/src/monster.rs rename to src/maps/src/monster.rs diff --git a/maps/src/object.rs b/src/maps/src/object.rs similarity index 100% rename from maps/src/object.rs rename to src/maps/src/object.rs diff --git a/maps/src/room.rs b/src/maps/src/room.rs similarity index 100% rename from maps/src/room.rs rename to src/maps/src/room.rs diff --git a/maps/src/variant.rs b/src/maps/src/variant.rs similarity index 100% rename from maps/src/variant.rs rename to src/maps/src/variant.rs diff --git a/networking/Cargo.toml b/src/networking/Cargo.toml similarity index 100% rename from networking/Cargo.toml rename to src/networking/Cargo.toml diff --git a/networking/src/cipherkeys.rs b/src/networking/src/cipherkeys.rs similarity index 100% rename from networking/src/cipherkeys.rs rename to src/networking/src/cipherkeys.rs diff --git a/networking/src/interserver.rs b/src/networking/src/interserver.rs similarity index 100% rename from networking/src/interserver.rs rename to src/networking/src/interserver.rs diff --git a/networking/src/lib.rs b/src/networking/src/lib.rs similarity index 100% rename from networking/src/lib.rs rename to src/networking/src/lib.rs diff --git a/networking/src/mainloop/client.rs b/src/networking/src/mainloop/client.rs similarity index 100% rename from networking/src/mainloop/client.rs rename to src/networking/src/mainloop/client.rs diff --git a/networking/src/mainloop/interserver.rs b/src/networking/src/mainloop/interserver.rs similarity index 100% rename from networking/src/mainloop/interserver.rs rename to src/networking/src/mainloop/interserver.rs diff --git a/networking/src/mainloop/mod.rs b/src/networking/src/mainloop/mod.rs similarity index 100% rename from networking/src/mainloop/mod.rs rename to src/networking/src/mainloop/mod.rs diff --git a/networking/src/serverstate.rs b/src/networking/src/serverstate.rs similarity index 100% rename from networking/src/serverstate.rs rename to src/networking/src/serverstate.rs diff --git a/src/patch_server/Cargo.toml b/src/patch_server/Cargo.toml new file mode 100644 index 0000000..f528b04 --- /dev/null +++ b/src/patch_server/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "patch_server" +version = "0.1.0" +edition = "2021" + +[dependencies] +networking = { workspace = true } + +libpso = { workspace = true } + +async-trait = { workspace = true } +rand = { workspace = true } +crc = { workspace = true } +ron = { workspace = true } +serde = { workspace = true } diff --git a/src/patch/mod.rs b/src/patch_server/src/lib.rs similarity index 100% rename from src/patch/mod.rs rename to src/patch_server/src/lib.rs diff --git a/pktbuilder/Cargo.toml b/src/pktbuilder/Cargo.toml similarity index 100% rename from pktbuilder/Cargo.toml rename to src/pktbuilder/Cargo.toml diff --git a/pktbuilder/src/character.rs b/src/pktbuilder/src/character.rs similarity index 100% rename from pktbuilder/src/character.rs rename to src/pktbuilder/src/character.rs diff --git a/pktbuilder/src/lib.rs b/src/pktbuilder/src/lib.rs similarity index 100% rename from pktbuilder/src/lib.rs rename to src/pktbuilder/src/lib.rs diff --git a/pktbuilder/src/lobby.rs b/src/pktbuilder/src/lobby.rs similarity index 100% rename from pktbuilder/src/lobby.rs rename to src/pktbuilder/src/lobby.rs diff --git a/pktbuilder/src/message.rs b/src/pktbuilder/src/message.rs similarity index 100% rename from pktbuilder/src/message.rs rename to src/pktbuilder/src/message.rs diff --git a/pktbuilder/src/quest.rs b/src/pktbuilder/src/quest.rs similarity index 100% rename from pktbuilder/src/quest.rs rename to src/pktbuilder/src/quest.rs diff --git a/pktbuilder/src/room.rs b/src/pktbuilder/src/room.rs similarity index 100% rename from pktbuilder/src/room.rs rename to src/pktbuilder/src/room.rs diff --git a/pktbuilder/src/ship.rs b/src/pktbuilder/src/ship.rs similarity index 100% rename from pktbuilder/src/ship.rs rename to src/pktbuilder/src/ship.rs diff --git a/pktbuilder/src/team.rs b/src/pktbuilder/src/team.rs similarity index 100% rename from pktbuilder/src/team.rs rename to src/pktbuilder/src/team.rs diff --git a/pktbuilder/src/trade.rs b/src/pktbuilder/src/trade.rs similarity index 100% rename from pktbuilder/src/trade.rs rename to src/pktbuilder/src/trade.rs diff --git a/quests/Cargo.toml b/src/quests/Cargo.toml similarity index 100% rename from quests/Cargo.toml rename to src/quests/Cargo.toml diff --git a/quests/src/lib.rs b/src/quests/src/lib.rs similarity index 100% rename from quests/src/lib.rs rename to src/quests/src/lib.rs diff --git a/room/Cargo.toml b/src/room/Cargo.toml similarity index 100% rename from room/Cargo.toml rename to src/room/Cargo.toml diff --git a/room/src/lib.rs b/src/room/src/lib.rs similarity index 100% rename from room/src/lib.rs rename to src/room/src/lib.rs diff --git a/src/ship/mod.rs b/src/ship/mod.rs deleted file mode 100644 index cf2a804..0000000 --- a/src/ship/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -#[allow(clippy::module_inception)] -pub mod ship; -pub mod packet; -pub mod chatcommand; diff --git a/src/ship/packet/handler/mod.rs b/src/ship/packet/handler/mod.rs deleted file mode 100644 index c921d28..0000000 --- a/src/ship/packet/handler/mod.rs +++ /dev/null @@ -1,10 +0,0 @@ -pub mod auth; -pub mod communication; -pub mod direct_message; -pub mod lobby; -pub mod message; -pub mod room; -pub mod settings; -pub mod quest; -pub mod ship; -pub mod trade; diff --git a/src/ship/packet/mod.rs b/src/ship/packet/mod.rs deleted file mode 100644 index 9b5f908..0000000 --- a/src/ship/packet/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -//pub mod builder; -pub mod handler; diff --git a/src/ship_server/Cargo.toml b/src/ship_server/Cargo.toml new file mode 100644 index 0000000..604dda8 --- /dev/null +++ b/src/ship_server/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "ship_server" +version = "0.1.0" +edition = "2021" + +[dependencies] +networking = { workspace = true } +trade = { workspace = true } +maps = { workspace = true } +location = { workspace = true } +room = { workspace = true } +shops = { workspace = true } +client = { workspace = true } +pktbuilder = { workspace = true } +items = { workspace = true } +entity = { workspace = true } +drops = { workspace = true } +quests = { workspace = true } +stats = { workspace = true } + +login_server = { workspace = true } + +libpso = { workspace = true } + +async-std = { workspace = true } +async-trait = { workspace = true } +log = { workspace = true } +anyhow = { workspace = true } +thiserror = { workspace = true } +rand = { workspace = true } +serde = { workspace = true } +futures = { workspace = true } diff --git a/src/ship/packet/handler/auth.rs b/src/ship_server/src/auth.rs similarity index 94% rename from src/ship/packet/handler/auth.rs rename to src/ship_server/src/auth.rs index 915da68..b8f746e 100644 --- a/src/ship/packet/handler/auth.rs +++ b/src/ship_server/src/auth.rs @@ -1,8 +1,9 @@ use libpso::packet::login::{Login, LoginResponse, AccountStatus, Session}; use libpso::packet::ship::*; use networking::serverstate::ClientId; -use crate::ship::ship::{SendShipPacket, ShipError, ClientState, Clients}; -use crate::login::login::get_login_status; +use crate::{SendShipPacket, ShipError}; +use client::{Clients, ClientState}; +use login_server::login::get_login_status; use entity::gateway::EntityGateway; use items::state::ItemState; use networking::interserver::ShipMessage; diff --git a/src/ship/chatcommand.rs b/src/ship_server/src/chatcommand.rs similarity index 98% rename from src/ship/chatcommand.rs rename to src/ship_server/src/chatcommand.rs index 7799e17..a2d3ff1 100644 --- a/src/ship/chatcommand.rs +++ b/src/ship_server/src/chatcommand.rs @@ -1,7 +1,7 @@ use libpso::packet::ship::PlayerChat; use entity::gateway::EntityGateway; use networking::serverstate::ClientId; -use crate::ship::ship::{ShipServerState, SendShipPacket}; +use crate::{ShipServerState, SendShipPacket}; use client::Clients; use items::state::ItemState; use entity::item::{BankName, BankIdentifier}; diff --git a/src/ship/packet/handler/communication.rs b/src/ship_server/src/communication.rs similarity index 96% rename from src/ship/packet/handler/communication.rs rename to src/ship_server/src/communication.rs index 3982efc..4949acd 100644 --- a/src/ship/packet/handler/communication.rs +++ b/src/ship_server/src/communication.rs @@ -1,7 +1,7 @@ use libpso::packet::ship::*; use networking::serverstate::ClientId; -use crate::ship::ship::{SendShipPacket, Clients}; -use location::{ClientLocation}; +use crate::{SendShipPacket, Clients}; +use location::ClientLocation; use entity::gateway::EntityGateway; use futures::future::join_all; diff --git a/src/ship/packet/handler/direct_message.rs b/src/ship_server/src/direct_message.rs similarity index 99% rename from src/ship/packet/handler/direct_message.rs rename to src/ship_server/src/direct_message.rs index c93ae0d..9ec6f52 100644 --- a/src/ship/packet/handler/direct_message.rs +++ b/src/ship_server/src/direct_message.rs @@ -6,7 +6,7 @@ use libpso::packet::ship::*; use libpso::packet::messages::*; use stats::leveltable::LEVEL_TABLE; use networking::serverstate::ClientId; -use crate::ship::ship::{SendShipPacket, ShipError, Clients}; +use crate::{SendShipPacket, ShipError, Clients}; use location::ClientLocation; use drops::ItemDrop; use room::Rooms; diff --git a/src/ship/ship.rs b/src/ship_server/src/lib.rs similarity index 80% rename from src/ship/ship.rs rename to src/ship_server/src/lib.rs index 5eacf5c..11e5ad6 100644 --- a/src/ship/ship.rs +++ b/src/ship_server/src/lib.rs @@ -1,4 +1,16 @@ -#![allow(dead_code, unused_must_use)] +#![allow(clippy::type_complexity)] +mod auth; +mod communication; +mod direct_message; +mod lobby; +mod message; +mod room; +mod settings; +mod quest; +mod ship; +pub mod trade; +mod chatcommand; + use std::net::Ipv4Addr; use async_std::channel; @@ -22,18 +34,15 @@ use entity::character::SectionID; use entity::room::RoomNote; use location::{ClientLocation, RoomLobby, ClientLocationError, RoomId}; use drops::{DropTable, StandardDropTable}; -use items; -use room; +use ::room::{Rooms, RoomCreationError}; use maps::room::{RoomMode, Episode, Difficulty}; use quests::{load_standard_quests, load_government_quests}; use quests::{QuestList, QuestLoadError}; use maps::Holiday; use maps::area::MapAreaError; use maps::maps::{Maps, MapsError, generate_free_roam_maps}; -use crate::ship::packet::handler; use shops::{ItemShops, StandardItemShops}; -use trade::TradeState; -use crate::ship::chatcommand; +use ::trade::{TradeState, TradeStateError}; use pktbuilder::quest::{QUEST_CATEGORY_MENU_ID, QUEST_SELECT_MENU_ID}; pub use client::{Clients, ClientState}; @@ -98,13 +107,13 @@ pub enum ShipError { #[error("invalid item {0}")] InvalidItem(items::ClientItemId), #[error("trade error {0}")] - TradeError(#[from] crate::ship::packet::handler::trade::TradeError), + TradeError(#[from] trade::TradeError), #[error("trade state error {0}")] - TradeStateError(#[from] trade::TradeStateError), + TradeStateError(#[from] TradeStateError), #[error("message error {0}")] - MessageError(#[from] crate::ship::packet::handler::direct_message::MessageError), + MessageError(#[from] crate::direct_message::MessageError), #[error("room creation error {0}")] - RoomCreationError(#[from] room::RoomCreationError), + RoomCreationError(#[from] RoomCreationError), #[error("channel send error {0}")] SendError(#[from] async_std::channel::SendError), } @@ -430,7 +439,7 @@ impl ShipServerStateBuilder { #[derive(Clone, Default)] pub struct Block { client_location: ClientLocation, - pub rooms: room::Rooms, + pub rooms: Rooms, } #[derive(Clone)] @@ -479,58 +488,58 @@ impl ShipServerState { Ok(match msg.msg { GameMessage::RequestExp(request_exp) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::message::request_exp(id, request_exp, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms).await? + message::request_exp(id, request_exp, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms).await? }, GameMessage::PlayerDropItem(player_drop_item) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::message::player_drop_item(id, player_drop_item, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms, &mut self.item_state).await? + message::player_drop_item(id, player_drop_item, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms, &mut self.item_state).await? }, GameMessage::DropCoordinates(drop_coordinates) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::message::drop_coordinates(id, drop_coordinates, &block.client_location, &self.clients, &block.rooms).await? + message::drop_coordinates(id, drop_coordinates, &block.client_location, &self.clients, &block.rooms).await? }, GameMessage::PlayerNoLongerHasItem(no_longer_has_item) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::message::no_longer_has_item(id, no_longer_has_item, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? + message::no_longer_has_item(id, no_longer_has_item, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? }, GameMessage::PlayerChangedMap(_) | GameMessage::PlayerChangedMap2(_) | GameMessage::TellOtherPlayerMyLocation(_) | GameMessage::PlayerWarpingToFloor(_) | GameMessage::PlayerTeleported(_) | GameMessage::PlayerStopped(_) | GameMessage::PlayerLoadedIn(_) | GameMessage::PlayerWalking(_) | GameMessage::PlayerRunning(_) | GameMessage::PlayerWarped(_) | GameMessage::PlayerChangedFloor(_) | GameMessage::InitializeSpeechNpc(_) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::message::update_player_position(id, msg, &self.clients, &block.client_location, &block.rooms).await? + message::update_player_position(id, msg, &self.clients, &block.client_location, &block.rooms).await? }, GameMessage::ChargeAttack(charge_attack) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::message::charge_attack(id, charge_attack, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? + message::charge_attack(id, charge_attack, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? }, GameMessage::PlayerUseItem(player_use_item) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::message::player_uses_item(id, player_use_item, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? + message::player_uses_item(id, player_use_item, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? }, GameMessage::PlayerUsedMedicalCenter(player_used_medical_center) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::message::player_used_medical_center(id, player_used_medical_center, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? + message::player_used_medical_center(id, player_used_medical_center, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? }, GameMessage::PlayerFeedMag(player_feed_mag) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::message::player_feed_mag(id, player_feed_mag, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? + message::player_feed_mag(id, player_feed_mag, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? }, GameMessage::PlayerEquipItem(player_equip_item) => { - handler::message::player_equips_item(id, player_equip_item, &mut self.entity_gateway, &self.clients, &mut self.item_state).await? + message::player_equips_item(id, player_equip_item, &mut self.entity_gateway, &self.clients, &mut self.item_state).await? }, GameMessage::PlayerUnequipItem(player_unequip_item) => { - handler::message::player_unequips_item(id, player_unequip_item, &mut self.entity_gateway, &self.clients, &mut self.item_state).await? + message::player_unequips_item(id, player_unequip_item, &mut self.entity_gateway, &self.clients, &mut self.item_state).await? }, GameMessage::SortItems(sort_items) => { - handler::message::player_sorts_items(id, sort_items, &mut self.entity_gateway, &self.clients, &mut self.item_state).await? + message::player_sorts_items(id, sort_items, &mut self.entity_gateway, &self.clients, &mut self.item_state).await? }, GameMessage::PlayerSoldItem(player_sold_item) => { - handler::message::player_sells_item(id, player_sold_item, &mut self.entity_gateway, &self.clients, &mut self.item_state).await? + message::player_sells_item(id, player_sold_item, &mut self.entity_gateway, &self.clients, &mut self.item_state).await? }, GameMessage::FloorItemLimitItemDeletion(floor_item_limit_delete) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::message::floor_item_limit_deletion(id, floor_item_limit_delete, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms, &mut self.item_state).await? + message::floor_item_limit_deletion(id, floor_item_limit_delete, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms, &mut self.item_state).await? }, _ => { let cmsg = msg.clone(); @@ -549,37 +558,37 @@ impl ShipServerState { let block = self.blocks.get_from_client(id, &self.clients).await?; Ok(match msg.msg { GameMessage::GuildcardSend(guildcard_send) => { - handler::direct_message::guildcard_send(id, guildcard_send, target, &block.client_location, &self.clients).await? + direct_message::guildcard_send(id, guildcard_send, target, &block.client_location, &self.clients).await? }, GameMessage::RequestItem(request_item) => { - handler::direct_message::request_item(id, request_item, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms, &mut self.item_state).await? + direct_message::request_item(id, request_item, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms, &mut self.item_state).await? }, GameMessage::PickupItem(pickup_item) => { - handler::direct_message::pickup_item(id, pickup_item, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? + direct_message::pickup_item(id, pickup_item, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? }, GameMessage::BoxDropRequest(box_drop_request) => { - handler::direct_message::request_box_item(id, box_drop_request, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms, &mut self.item_state).await? + direct_message::request_box_item(id, box_drop_request, &mut self.entity_gateway, &block.client_location, &self.clients, &block.rooms, &mut self.item_state).await? }, GameMessage::BankRequest(_bank_request) => { - handler::direct_message::send_bank_list(id, &self.clients, &mut self.item_state).await? + direct_message::send_bank_list(id, &self.clients, &mut self.item_state).await? }, GameMessage::BankInteraction(bank_interaction) => { - handler::direct_message::bank_interaction(id, bank_interaction, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? + direct_message::bank_interaction(id, bank_interaction, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? }, GameMessage::ShopRequest(shop_request) => { - handler::direct_message::shop_request(id, shop_request, &block.client_location, &self.clients, &block.rooms, &self.shops).await? + direct_message::shop_request(id, shop_request, &block.client_location, &self.clients, &block.rooms, &self.shops).await? }, GameMessage::BuyItem(buy_item) => { - handler::direct_message::buy_item(id, buy_item, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? + direct_message::buy_item(id, buy_item, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? }, GameMessage::TekRequest(tek_request) => { - handler::direct_message::request_tek_item(id, tek_request, &mut self.entity_gateway, &self.clients, &mut self.item_state).await? + direct_message::request_tek_item(id, tek_request, &mut self.entity_gateway, &self.clients, &mut self.item_state).await? }, GameMessage::TekAccept(tek_accept) => { - handler::direct_message::accept_tek_item(id, tek_accept, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? + direct_message::accept_tek_item(id, tek_accept, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state).await? }, GameMessage::TradeRequest(trade_request) => { - handler::trade::trade_request(id, trade_request, target, &block.client_location, &self.clients, &mut self.item_state, &mut self.trades).await? + trade::trade_request(id, trade_request, target, &block.client_location, &self.clients, &mut self.item_state, &mut self.trades).await? }, _ => { let cmsg = msg.clone(); @@ -625,7 +634,7 @@ impl ServerState for ShipServerState { Ok(match pkt { RecvShipPacket::Login(login) => { - handler::auth::validate_login(id, login, &mut self.entity_gateway, &mut self.clients, &mut self.item_state, &self.shipgate_sender, &self.name, self.blocks.0.len()) + auth::validate_login(id, login, &mut self.entity_gateway, &mut self.clients, &mut self.item_state, &self.shipgate_sender, &self.name, self.blocks.0.len()) .await? .into_iter() .map(move |pkt| (id, pkt)) @@ -634,7 +643,7 @@ impl ServerState for ShipServerState { RecvShipPacket::QuestDetailRequest(questdetailrequest) => { let block = self.blocks.get_from_client(id, &self.clients).await?; match questdetailrequest.menu { - QUEST_SELECT_MENU_ID => handler::quest::quest_detail(id, questdetailrequest, &block.client_location, &block.rooms).await?, + QUEST_SELECT_MENU_ID => quest::quest_detail(id, questdetailrequest, &block.client_location, &block.rooms).await?, _ => unreachable!(), } }, @@ -642,27 +651,27 @@ impl ServerState for ShipServerState { let block = self.blocks.get_from_client(id, &self.clients).await?; match menuselect.menu { SHIP_MENU_ID => { - let leave_lobby = handler::lobby::remove_from_lobby(id, &mut block.client_location).await.into_iter().flatten(); - let select_ship = handler::ship::selected_ship(id, menuselect, &self.ship_list).await?; + let leave_lobby = lobby::remove_from_lobby(id, &mut block.client_location).await.into_iter().flatten(); + let select_ship = ship::selected_ship(id, menuselect, &self.ship_list).await?; leave_lobby.chain(select_ship).collect() } BLOCK_MENU_ID => { - let leave_lobby = handler::lobby::remove_from_lobby(id, &mut block.client_location).await.into_iter().flatten(); - let select_block = handler::lobby::block_selected(id, menuselect, &self.clients, &self.item_state).await?.into_iter(); + let leave_lobby = lobby::remove_from_lobby(id, &mut block.client_location).await.into_iter().flatten(); + let select_block = lobby::block_selected(id, menuselect, &self.clients, &self.item_state).await?.into_iter(); leave_lobby.chain(select_block).collect() } - ROOM_MENU_ID => handler::room::join_room(id, menuselect, &mut self.entity_gateway, &mut block.client_location, &self.clients, &mut self.item_state, &block.rooms, self.event).await?, - QUEST_CATEGORY_MENU_ID => handler::quest::select_quest_category(id, menuselect, &block.client_location, &block.rooms).await?, + ROOM_MENU_ID => room::join_room(id, menuselect, &mut self.entity_gateway, &mut block.client_location, &self.clients, &mut self.item_state, &block.rooms, self.event).await?, + QUEST_CATEGORY_MENU_ID => quest::select_quest_category(id, menuselect, &block.client_location, &block.rooms).await?, _ => unreachable!(), } }, RecvShipPacket::QuestMenuSelect(questmenuselect) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::quest::player_chose_quest(id, questmenuselect, &self.clients, &block.client_location, &block.rooms, self.event).await? + quest::player_chose_quest(id, questmenuselect, &self.clients, &block.client_location, &block.rooms, self.event).await? }, RecvShipPacket::MenuDetail(menudetail) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::lobby::get_room_tab_info(id, menudetail, &mut block.client_location, &self.clients).await? + lobby::get_room_tab_info(id, menudetail, &mut block.client_location, &self.clients).await? }, RecvShipPacket::RoomPasswordReq(room_password_req) => { let block = self.blocks.get_from_client(id, &self.clients).await?; @@ -676,7 +685,7 @@ impl ServerState for ShipServerState { menu: room_password_req.menu, item: room_password_req.item, }; - handler::room::join_room(id, menuselect, &mut self.entity_gateway, &mut block.client_location, &self.clients, &mut self.item_state, &block.rooms, self.event).await? + room::join_room(id, menuselect, &mut self.entity_gateway, &mut block.client_location, &self.clients, &mut self.item_state, &block.rooms, self.event).await? } else { vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("Incorrect password".into())))] @@ -684,7 +693,7 @@ impl ServerState for ShipServerState { }, RecvShipPacket::CharData(chardata) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::lobby::send_player_to_lobby(id, chardata, &mut block.client_location, &self.clients, &self.item_state, self.event).await? + lobby::send_player_to_lobby(id, chardata, &mut block.client_location, &self.clients, &self.item_state, self.event).await? }, RecvShipPacket::Message(msg) => { self.message(id, msg).await? @@ -702,40 +711,40 @@ impl ServerState for ShipServerState { }, None => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::communication::player_chat(id, msg, &block.client_location, &self.clients).await? + communication::player_chat(id, msg, &block.client_location, &self.clients).await? } } }, RecvShipPacket::CreateRoom(create_room) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::room::create_room(id, create_room, &mut self.entity_gateway, &mut block.client_location, &self.clients, &mut self.item_state, + room::create_room(id, create_room, &mut self.entity_gateway, &mut block.client_location, &self.clients, &mut self.item_state, &block.rooms, self.map_builder.clone(), self.drop_table_builder.clone(), self.standard_quest_builder.clone(), self.government_quest_builder.clone(), self.event).await? }, RecvShipPacket::RoomNameRequest(_req) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::room::room_name_request(id, &block.client_location, &block.rooms).await? + room::room_name_request(id, &block.client_location, &block.rooms).await? }, RecvShipPacket::UpdateTechMenu(pkt) => { - handler::settings::update_tech_menu(id, pkt, &self.clients, &mut self.entity_gateway).await? + settings::update_tech_menu(id, pkt, &self.clients, &mut self.entity_gateway).await? }, RecvShipPacket::UpdateConfig(pkt) => { - handler::settings::update_config(id, pkt, &self.clients, &mut self.entity_gateway).await? + settings::update_config(id, pkt, &self.clients, &mut self.entity_gateway).await? }, RecvShipPacket::ViewInfoboardRequest(_pkt) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::communication::request_infoboard(id, &block.client_location, &self.clients).await? + communication::request_infoboard(id, &block.client_location, &self.clients).await? }, RecvShipPacket::WriteInfoboard(pkt) => { - handler::communication::write_infoboard(id, pkt, &self.clients, &mut self.entity_gateway).await? + communication::write_infoboard(id, pkt, &self.clients, &mut self.entity_gateway).await? }, RecvShipPacket::RoomListRequest(_req) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::room::request_room_list(id, &block.client_location, &block.rooms).await + room::request_room_list(id, &block.client_location, &block.rooms).await }, RecvShipPacket::Like62ButCooler(cool62) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::room::cool_62(id, cool62, &block.client_location).await? + room::cool_62(id, cool62, &block.client_location).await? }, RecvShipPacket::ClientCharacterData(_) => { // TOOD: validate this in some way? @@ -743,57 +752,57 @@ impl ServerState for ShipServerState { }, RecvShipPacket::DoneBursting(_) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::room::done_bursting(id, &block.client_location, &block.rooms).await? + room::done_bursting(id, &block.client_location, &block.rooms).await? }, RecvShipPacket::DoneBursting2(_) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::room::done_bursting(id, &block.client_location, &block.rooms).await? + room::done_bursting(id, &block.client_location, &block.rooms).await? }, RecvShipPacket::LobbySelect(pkt) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::lobby::change_lobby(id, pkt.lobby, &mut block.client_location, &self.clients, &mut self.item_state, &block.rooms, &mut self.entity_gateway, self.event).await? + lobby::change_lobby(id, pkt.lobby, &mut block.client_location, &self.clients, &mut self.item_state, &block.rooms, &mut self.entity_gateway, self.event).await? }, RecvShipPacket::RequestQuestList(rql) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::quest::send_quest_category_list(id, rql, &block.client_location, &block.rooms).await? + quest::send_quest_category_list(id, rql, &block.client_location, &block.rooms).await? }, RecvShipPacket::QuestFileRequest(quest_file_request) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::quest::quest_file_request(id, quest_file_request, &block.client_location, &mut block.rooms).await? + quest::quest_file_request(id, quest_file_request, &block.client_location, &mut block.rooms).await? }, RecvShipPacket::QuestChunkAck(quest_chunk_ack) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::quest::quest_chunk_ack(id, quest_chunk_ack, &block.client_location, &block.rooms).await? + quest::quest_chunk_ack(id, quest_chunk_ack, &block.client_location, &block.rooms).await? }, RecvShipPacket::DoneLoadingQuest(_) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::quest::done_loading_quest(id, &self.clients, &block.client_location).await? + quest::done_loading_quest(id, &self.clients, &block.client_location).await? }, RecvShipPacket::FullCharacterData(_full_character_data) => { Vec::new() }, RecvShipPacket::SaveOptions(save_options) => { - handler::settings::save_options(id, save_options, &self.clients, &mut self.entity_gateway).await? + settings::save_options(id, save_options, &self.clients, &mut self.entity_gateway).await? }, RecvShipPacket::RequestShipList(_) => { - handler::ship::ship_list(id, &self.ship_list).await + ship::ship_list(id, &self.ship_list).await }, RecvShipPacket::RequestShipBlockList(_) => { - handler::ship::block_list(id, &self.name, self.blocks.0.len()) + ship::block_list(id, &self.name, self.blocks.0.len()) }, RecvShipPacket::ItemsToTrade(items_to_trade) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::trade::items_to_trade(id, items_to_trade, &block.client_location, &self.clients, &mut self.item_state, &mut self.trades).await? + trade::items_to_trade(id, items_to_trade, &block.client_location, &self.clients, &mut self.item_state, &mut self.trades).await? }, RecvShipPacket::TradeConfirmed(_) => { let block = self.blocks.get_from_client(id, &self.clients).await?; - handler::trade::trade_confirmed(id, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state, &mut self.trades).await? + trade::trade_confirmed(id, &mut self.entity_gateway, &block.client_location, &self.clients, &mut self.item_state, &mut self.trades).await? }, RecvShipPacket::KeyboardConfig(keyboard_config) => { - handler::settings::keyboard_config(id, keyboard_config, &self.clients, &mut self.entity_gateway).await? + settings::keyboard_config(id, keyboard_config, &self.clients, &mut self.entity_gateway).await? }, RecvShipPacket::GamepadConfig(gamepad_config) => { - handler::settings::gamepad_config(id, gamepad_config, &self.clients, &mut self.entity_gateway).await? + settings::gamepad_config(id, gamepad_config, &self.clients, &mut self.entity_gateway).await? }, }) } @@ -814,7 +823,7 @@ impl ServerState for ShipServerState { entity_gateway.add_room_note(room.room_id, RoomNote::PlayerJoin { character_id, }).await - })}).await; + })}).await??; if neighbors.is_empty() { block.rooms.remove(room).await; } @@ -829,9 +838,9 @@ impl ServerState for ShipServerState { if let Some(mut client) = self.clients.remove(&id).await { client.user.at_ship = false; - self.entity_gateway.save_user(&client.user).await; + self.entity_gateway.save_user(&client.user).await?; if let Some(shipgate_sender) = self.shipgate_sender.as_ref() { - shipgate_sender.send(ShipMessage::RemoveUser(client.user.id)).await; + shipgate_sender.send(ShipMessage::RemoveUser(client.user.id)).await?; } self.item_state.remove_character_from_room(&client.character).await } diff --git a/src/ship/packet/handler/lobby.rs b/src/ship_server/src/lobby.rs similarity index 99% rename from src/ship/packet/handler/lobby.rs rename to src/ship_server/src/lobby.rs index 3033091..8e6090a 100644 --- a/src/ship/packet/handler/lobby.rs +++ b/src/ship_server/src/lobby.rs @@ -1,13 +1,12 @@ use libpso::packet::ship::*; use networking::serverstate::ClientId; use stats::leveltable::LEVEL_TABLE; -use crate::ship::ship::{SendShipPacket, ShipError}; +use crate::{SendShipPacket, ShipError}; use maps::Holiday; use client::Clients; use room::Rooms; use pktbuilder::character::FullCharacterBytesBuilder; use location::{ClientLocation, LobbyId, RoomLobby, ClientLocationError, RoomId}; -//use pktbuilder; use items::state::ItemState; use entity::gateway::EntityGateway; use entity::room::RoomNote; diff --git a/src/ship/packet/handler/message.rs b/src/ship_server/src/message.rs similarity index 99% rename from src/ship/packet/handler/message.rs rename to src/ship_server/src/message.rs index ca731c9..31a6541 100644 --- a/src/ship/packet/handler/message.rs +++ b/src/ship_server/src/message.rs @@ -4,7 +4,7 @@ use entity::gateway::EntityGateway; use entity::item::Meseta; use networking::serverstate::ClientId; use stats::leveltable::LEVEL_TABLE; -use crate::ship::ship::{SendShipPacket, ShipError}; +use crate::{SendShipPacket, ShipError}; use client::{Clients, ItemDropLocation}; use ::room::Rooms; use location::{ClientLocation, ClientLocationError}; diff --git a/src/ship/packet/handler/quest.rs b/src/ship_server/src/quest.rs similarity index 99% rename from src/ship/packet/handler/quest.rs rename to src/ship_server/src/quest.rs index 6193530..b40c718 100644 --- a/src/ship/packet/handler/quest.rs +++ b/src/ship_server/src/quest.rs @@ -2,7 +2,7 @@ use std::io::{Cursor, Read, Seek, SeekFrom}; use futures::stream::{FuturesOrdered, StreamExt}; use libpso::packet::ship::*; use networking::serverstate::ClientId; -use crate::ship::ship::{SendShipPacket, ShipError}; +use crate::{SendShipPacket, ShipError}; use client::Clients; use maps::Holiday; use room::Rooms; diff --git a/src/ship/packet/handler/room.rs b/src/ship_server/src/room.rs similarity index 99% rename from src/ship/packet/handler/room.rs rename to src/ship_server/src/room.rs index 563385d..254fdd0 100644 --- a/src/ship/packet/handler/room.rs +++ b/src/ship_server/src/room.rs @@ -11,7 +11,7 @@ use entity::gateway::EntityGateway; use entity::character::SectionID; use entity::room::{NewRoomEntity, RoomEntityMode, RoomNote}; use drops::DropTable; -use crate::ship::ship::SendShipPacket; +use crate::SendShipPacket; use client::Clients; use room::{Rooms, RoomState, RoomCreationError}; use maps::Holiday; diff --git a/src/ship/packet/handler/settings.rs b/src/ship_server/src/settings.rs similarity index 98% rename from src/ship/packet/handler/settings.rs rename to src/ship_server/src/settings.rs index 4bd665d..b21491b 100644 --- a/src/ship/packet/handler/settings.rs +++ b/src/ship_server/src/settings.rs @@ -1,6 +1,6 @@ use libpso::packet::ship::*; use networking::serverstate::ClientId; -use crate::ship::ship::{SendShipPacket, Clients}; +use crate::{SendShipPacket, Clients}; use entity::gateway::EntityGateway; pub async fn update_config(id: ClientId, diff --git a/src/ship/packet/handler/ship.rs b/src/ship_server/src/ship.rs similarity index 95% rename from src/ship/packet/handler/ship.rs rename to src/ship_server/src/ship.rs index 762e73f..a006004 100644 --- a/src/ship/packet/handler/ship.rs +++ b/src/ship_server/src/ship.rs @@ -3,7 +3,7 @@ use libpso::packet::ship::*; use libpso::packet::login::RedirectClient; use networking::serverstate::ClientId; use networking::interserver::Ship; -use crate::ship::ship::{SendShipPacket, ShipError}; +use crate::{SendShipPacket, ShipError}; use pktbuilder as builder; pub async fn ship_list(id: ClientId, ship_list: &Arc>>) -> Vec<(ClientId, SendShipPacket)> { diff --git a/src/ship/packet/handler/trade.rs b/src/ship_server/src/trade.rs similarity index 99% rename from src/ship/packet/handler/trade.rs rename to src/ship_server/src/trade.rs index 8da8f38..b57b218 100644 --- a/src/ship/packet/handler/trade.rs +++ b/src/ship_server/src/trade.rs @@ -2,7 +2,7 @@ use std::convert::TryInto; use libpso::packet::ship::*; use libpso::packet::messages::*; use networking::serverstate::ClientId; -use crate::ship::ship::{SendShipPacket, ShipError, Clients}; +use crate::{SendShipPacket, ShipError, Clients}; use location::{ClientLocation}; use items::ClientItemId; use items::state::{ItemState, ItemStateError}; diff --git a/shops/Cargo.toml b/src/shops/Cargo.toml similarity index 100% rename from shops/Cargo.toml rename to src/shops/Cargo.toml diff --git a/shops/src/armor.rs b/src/shops/src/armor.rs similarity index 100% rename from shops/src/armor.rs rename to src/shops/src/armor.rs diff --git a/shops/src/lib.rs b/src/shops/src/lib.rs similarity index 100% rename from shops/src/lib.rs rename to src/shops/src/lib.rs diff --git a/shops/src/tool.rs b/src/shops/src/tool.rs similarity index 100% rename from shops/src/tool.rs rename to src/shops/src/tool.rs diff --git a/shops/src/weapon.rs b/src/shops/src/weapon.rs similarity index 100% rename from shops/src/weapon.rs rename to src/shops/src/weapon.rs diff --git a/stats/Cargo.toml b/src/stats/Cargo.toml similarity index 100% rename from stats/Cargo.toml rename to src/stats/Cargo.toml diff --git a/stats/src/items.rs b/src/stats/src/items.rs similarity index 100% rename from stats/src/items.rs rename to src/stats/src/items.rs diff --git a/stats/src/leveltable.rs b/src/stats/src/leveltable.rs similarity index 100% rename from stats/src/leveltable.rs rename to src/stats/src/leveltable.rs diff --git a/stats/src/lib.rs b/src/stats/src/lib.rs similarity index 100% rename from stats/src/lib.rs rename to src/stats/src/lib.rs diff --git a/trade/Cargo.toml b/src/trade/Cargo.toml similarity index 100% rename from trade/Cargo.toml rename to src/trade/Cargo.toml diff --git a/trade/src/lib.rs b/src/trade/src/lib.rs similarity index 100% rename from trade/src/lib.rs rename to src/trade/src/lib.rs diff --git a/tests/common.rs b/tests/common.rs index db91ab8..ebab507 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -5,7 +5,7 @@ use entity::gateway::EntityGateway; use entity::account::{UserAccountEntity, NewUserAccountEntity, NewUserSettingsEntity}; use entity::character::{CharacterEntity, NewCharacterEntity, SectionID}; use entity::item::{Meseta, BankIdentifier}; -use elseware::ship::ship::{ShipServerState, ShipServerStateBuilder, RecvShipPacket}; +use ship_server::{ShipServerState, ShipServerStateBuilder, RecvShipPacket}; use maps::room::{RoomMode, Difficulty, Episode}; use maps::area::MapArea; use maps::maps::null_free_roam_maps; @@ -77,7 +77,7 @@ pub fn standard_ship(gateway: EG) -> ShipServerState } //TODO: remove kb_conf_preset -pub async fn new_user_character(entity_gateway: &mut EG, username: &str, password: &str, _kb_conf_preset: usize) -> (UserAccountEntity, CharacterEntity) { +pub async fn new_user_character(entity_gateway: &mut EG, username: &str, password: &str) -> (UserAccountEntity, CharacterEntity) { let new_user = NewUserAccountEntity { email: format!("{}@pso.com", username), username: username.into(), @@ -161,9 +161,23 @@ pub async fn join_room(ship: &mut ShipServerState pub struct WeaponBuilder { weapon: item::weapon::WeaponType, grind: u8, + special: Option, + attributes: [Option; 3], + tekked: bool, } + impl WeaponBuilder { + fn new(weapon: item::weapon::WeaponType) -> WeaponBuilder { + WeaponBuilder { + weapon, + grind: 0, + special: None, + attributes: [None; 3], + tekked: true, + } + } + pub fn grind(self, grind: u8) -> WeaponBuilder { WeaponBuilder { grind, @@ -171,28 +185,267 @@ impl WeaponBuilder { } } + pub fn special(self, special: item::weapon::WeaponSpecial) -> WeaponBuilder { + WeaponBuilder { + special: Some(special), + ..self + } + } + + pub fn attr(mut self, attr: item::weapon::Attribute, value: i8) -> WeaponBuilder { + self.attributes + .iter_mut() + .find(|k| k.is_none()) + .map(|empty_attr| { + *empty_attr = Some(item::weapon::WeaponAttribute { + attr, + value, + }) + }); + + self + } + + pub fn untekked(self) -> WeaponBuilder { + WeaponBuilder { + tekked: false, + ..self + } + } + pub fn as_new(self) -> item::NewItemEntity { item::NewItemEntity { item: item::ItemDetail::Weapon( item::weapon::Weapon { weapon: self.weapon, grind: self.grind, - special: None, - attrs: [None, None, None], - tekked: true, + special: self.special, + attrs: self.attributes, + tekked: self.tekked, + } + ) + } + } +} + +pub struct ArmorBuilder { + armor: item::armor::ArmorType, + dfp: u8, + evp: u8, + slots: u8, +} + +impl ArmorBuilder { + pub fn new(armor: item::armor::ArmorType) -> ArmorBuilder { + ArmorBuilder { + armor: armor, + dfp: 0, + evp: 0, + slots: 0, + } + } + + pub fn slots(self, slots: u8) -> ArmorBuilder { + ArmorBuilder { + slots, + ..self + } + } + + pub fn dfp(self, dfp: u8) -> ArmorBuilder { + ArmorBuilder { + dfp, + ..self + } + } + + pub fn evp(self, evp: u8) -> ArmorBuilder { + ArmorBuilder { + evp, + ..self + } + } + + pub fn as_new(self) -> item::NewItemEntity { + item::NewItemEntity { + item: item::ItemDetail::Armor( + item::armor::Armor { + armor: self.armor, + dfp: self.dfp, + evp: self.evp, + slots: self.slots, + } + ) + } + } +} + +pub struct ShieldBuilder { + shield: item::shield::ShieldType, + dfp: u8, + evp: u8, +} + +impl ShieldBuilder { + pub fn new(shield: item::shield::ShieldType) -> ShieldBuilder { + ShieldBuilder { + shield: shield, + dfp: 0, + evp: 0, + } + } + + pub fn dfp(self, dfp: u8) -> ShieldBuilder { + ShieldBuilder { + dfp, + ..self + } + } + + pub fn evp(self, evp: u8) -> ShieldBuilder { + ShieldBuilder { + evp, + ..self + } + } + + pub fn as_new(self) -> item::NewItemEntity { + item::NewItemEntity { + item: item::ItemDetail::Shield( + item::shield::Shield { + shield: self.shield, + dfp: self.dfp, + evp: self.evp, + } + ) + } + } +} + + +pub struct UnitBuilder { + unit: item::unit::UnitType, + modifier: Option, +} + +impl UnitBuilder { + pub fn modifier(self, modifier: item::unit::UnitModifier) -> UnitBuilder { + UnitBuilder { + modifier: Some(modifier), + ..self + } + } + + pub fn as_new(self) -> item::NewItemEntity { + item::NewItemEntity { + item: item::ItemDetail::Unit( + item::unit::Unit { + unit: self.unit, + modifier: self.modifier, } ) } } } + +pub struct MagBuilder { +} + +impl MagBuilder { + pub fn as_new(self) -> item::NewItemEntity { + item::NewItemEntity { + item: item::ItemDetail::Mag( + item::mag::Mag::baby_mag(0) + ) + } + } +} + + + +pub struct ToolBuilder { + tool: item::tool::ToolType, +} + +impl ToolBuilder { + pub fn as_new(self) -> item::NewItemEntity { + item::NewItemEntity { + item: item::ItemDetail::Tool ( + item::tool::Tool { + tool: self.tool, + } + ), + } + } +} + +pub struct TechBuilder { + tech: item::tech::Technique, + level: u32, +} + + +impl TechBuilder { + pub fn level(self, level: u32) -> TechBuilder { + TechBuilder { + level, + ..self + } + } + + pub fn as_new(self) -> item::NewItemEntity { + item::NewItemEntity { + item: item::ItemDetail::TechniqueDisk ( + item::tech::TechniqueDisk { + tech: self.tech, + level: self.level, + } + ) + } + } +} + + pub struct ItemBuilder; impl ItemBuilder { pub fn weapon(weapon: item::weapon::WeaponType) -> WeaponBuilder { - WeaponBuilder { - weapon, - grind: 0, + WeaponBuilder::new(weapon) + } + + pub fn armor(armor: item::armor::ArmorType) -> ArmorBuilder { + ArmorBuilder::new(armor) + } + + pub fn shield(shield: item::shield::ShieldType) -> ShieldBuilder { + ShieldBuilder::new(shield) + } + + pub fn unit(unit: item::unit::UnitType) -> UnitBuilder { + UnitBuilder { + unit: unit, + modifier: None, + } + } + + pub fn baby_mag() -> MagBuilder { + MagBuilder { } } + + pub fn tool(tool: item::tool::ToolType) -> ToolBuilder { + ToolBuilder { + tool: tool, + } + } + + pub fn tech(tech: item::tech::Technique) -> TechBuilder { + TechBuilder { + tech: tech, + level: 0, + } + } + + } diff --git a/tests/test_bank.rs b/tests/test_bank.rs index 443da34..7f825af 100644 --- a/tests/test_bank.rs +++ b/tests/test_bank.rs @@ -2,7 +2,7 @@ use std::collections::BTreeSet; use networking::serverstate::{ClientId, ServerState}; use entity::gateway::{EntityGateway, InMemoryGateway}; use entity::item; -use elseware::ship::ship::{RecvShipPacket, SendShipPacket}; +use ship_server::{RecvShipPacket, SendShipPacket}; use shops::StandardItemShops; use libpso::packet::ship::*; @@ -16,21 +16,13 @@ use common::*; async fn test_bank_items_sent_in_character_login() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let item = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap(); entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![item]), &item::BankIdentifier::Character).await.unwrap(); @@ -49,23 +41,15 @@ async fn test_bank_items_sent_in_character_login() { async fn test_request_bank_items() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut bank = Vec::new(); for _ in 0..3 { bank.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), &item::BankIdentifier::Character).await.unwrap(); @@ -95,19 +79,15 @@ async fn test_request_bank_items() { async fn test_request_stacked_bank_items() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut monomates = Vec::new(); for _ in 0..3usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool ( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), &item::BankIdentifier::Character).await.unwrap(); @@ -136,41 +116,21 @@ async fn test_request_stacked_bank_items() { async fn test_request_bank_items_sorted() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let item1 = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap(); let monomate = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool ( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap(); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap(); let item2 = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Calibur, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(); + ItemBuilder::weapon(item::weapon::WeaponType::Calibur) + .as_new() + ).await.unwrap(); let bank = vec![item::BankItemEntity::Individual(item1), vec![monomate].into(), item2.into()]; entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), &item::BankIdentifier::Character).await.unwrap(); @@ -200,33 +160,17 @@ async fn test_request_bank_items_sorted() { async fn test_deposit_individual_item() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let item0 = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(); + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap(); let item1 = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap(); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![item0, item1])).await.unwrap(); @@ -277,19 +221,15 @@ async fn test_deposit_individual_item() { async fn test_deposit_stacked_item() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut monomates = Vec::new(); for _ in 0..3usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![monomates])).await.unwrap(); @@ -336,19 +276,15 @@ async fn test_deposit_stacked_item() { async fn test_deposit_partial_stacked_item() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut monomates = Vec::new(); for _ in 0..3usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![monomates])).await.unwrap(); @@ -404,29 +340,21 @@ async fn test_deposit_partial_stacked_item() { async fn test_deposit_stacked_item_with_stack_already_in_bank() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut bank_monomates = Vec::new(); let mut inventory_monomates = Vec::new(); for _ in 0..2usize { inventory_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); bank_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![inventory_monomates])).await.unwrap(); @@ -474,30 +402,22 @@ async fn test_deposit_stacked_item_with_stack_already_in_bank() { async fn test_deposit_stacked_item_with_full_stack_in_bank() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut inventory_monomates = Vec::new(); for _ in 0..2usize { inventory_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } let mut bank_monomates = Vec::new(); for _ in 0..10 { bank_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![inventory_monomates])).await.unwrap(); @@ -544,36 +464,20 @@ async fn test_deposit_stacked_item_with_full_stack_in_bank() { async fn test_deposit_individual_item_in_full_bank() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut inventory = Vec::new(); inventory.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap()); let mut bank = Vec::new(); for _ in 0..200usize { bank.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap(); @@ -616,34 +520,22 @@ async fn test_deposit_individual_item_in_full_bank() { async fn test_deposit_stacked_item_in_full_bank() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut monomates = Vec::new(); for _ in 0..2usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } let mut full_bank = Vec::new(); for _ in 0..200usize { full_bank.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![monomates])).await.unwrap(); @@ -687,46 +579,30 @@ async fn test_deposit_stacked_item_in_full_bank() { async fn test_deposit_stacked_item_in_full_bank_with_partial_stack() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut monomates = Vec::new(); for _ in 0..2usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } let mut bank_monomates = Vec::new(); for _ in 0..2usize { bank_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } let mut almost_full_bank: Vec = Vec::new(); for _ in 0..199usize { almost_full_bank.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap().into()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap().into()); } almost_full_bank.push(bank_monomates.into()); @@ -768,7 +644,7 @@ async fn test_deposit_stacked_item_in_full_bank_with_partial_stack() { async fn test_deposit_meseta() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; entity_gateway.set_character_meseta(&char1.id, item::Meseta(300)).await.unwrap(); let mut ship = standard_ship(entity_gateway.clone()); @@ -802,7 +678,7 @@ async fn test_deposit_meseta() { async fn test_deposit_too_much_meseta() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; entity_gateway.set_character_meseta(&char1.id, item::Meseta(300)).await.unwrap(); entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Character, item::Meseta(999980)).await.unwrap(); @@ -839,7 +715,7 @@ async fn test_deposit_too_much_meseta() { async fn test_deposit_meseta_when_bank_is_maxed() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; entity_gateway.set_character_meseta(&char1.id, item::Meseta(300)).await.unwrap(); entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Character, item::Meseta(999999)).await.unwrap(); @@ -877,22 +753,14 @@ async fn test_deposit_meseta_when_bank_is_maxed() { async fn test_withdraw_individual_item() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut bank = Vec::new(); bank.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap()); entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), &item::BankIdentifier::Character).await.unwrap(); @@ -937,19 +805,15 @@ async fn test_withdraw_individual_item() { async fn test_withdraw_stacked_item() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut monomates = Vec::new(); for _ in 0..3usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), &item::BankIdentifier::Character).await.unwrap(); @@ -995,19 +859,15 @@ async fn test_withdraw_stacked_item() { async fn test_withdraw_partial_stacked_item() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut monomates = Vec::new(); for _ in 0..3usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), &item::BankIdentifier::Character).await.unwrap(); @@ -1059,29 +919,21 @@ async fn test_withdraw_partial_stacked_item() { async fn test_withdraw_stacked_item_with_stack_already_in_inventory() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut inventory_monomates = Vec::new(); let mut bank_monomates = Vec::new(); for _ in 0..2usize { inventory_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); bank_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![inventory_monomates])).await.unwrap(); @@ -1131,30 +983,22 @@ async fn test_withdraw_stacked_item_with_stack_already_in_inventory() { async fn test_withdraw_stacked_item_with_full_stack_in_inventory() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut bank_monomates = Vec::new(); for _ in 0..2usize { bank_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } let mut inventory_monomates = Vec::new(); for _ in 0..10usize { inventory_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![inventory_monomates])).await.unwrap(); @@ -1201,36 +1045,20 @@ async fn test_withdraw_stacked_item_with_full_stack_in_inventory() { async fn test_withdraw_individual_item_in_full_inventory() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut bank = Vec::new(); bank.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap()); let mut inventory = Vec::new(); for _ in 0..30usize { inventory.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap(); @@ -1269,34 +1097,22 @@ async fn test_withdraw_individual_item_in_full_inventory() { async fn test_withdraw_stacked_item_in_full_inventory() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut monomates = Vec::new(); for _ in 0..2usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } let mut inventory = Vec::new(); for _ in 0..30usize { inventory.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap(); @@ -1341,47 +1157,31 @@ async fn test_withdraw_stacked_item_in_full_inventory() { async fn test_withdraw_stacked_item_in_full_inventory_with_partial_stack() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut bank_item = Vec::new(); for _ in 0..2usize { bank_item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_item]), &item::BankIdentifier::Character).await.unwrap(); let mut items = Vec::new(); for _i in 0..29usize { items.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap().into()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap().into()); } let mut item29 = Vec::new(); for _ in 0..2usize { item29.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } items.push(item::InventoryItemEntity::Stacked(item29)); @@ -1425,7 +1225,7 @@ async fn test_withdraw_stacked_item_in_full_inventory_with_partial_stack() { async fn test_withdraw_meseta() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Character, item::Meseta(300)).await.unwrap(); let mut ship = standard_ship(entity_gateway.clone()); @@ -1459,7 +1259,7 @@ async fn test_withdraw_meseta() { async fn test_withdraw_too_much_meseta() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; entity_gateway.set_character_meseta(&char1.id, item::Meseta(999980)).await.unwrap(); entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Character, item::Meseta(300)).await.unwrap(); @@ -1496,7 +1296,7 @@ async fn test_withdraw_too_much_meseta() { async fn test_withdraw_meseta_inventory_is_maxed() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap(); entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Character, item::Meseta(300)).await.unwrap(); @@ -1535,7 +1335,7 @@ async fn test_withdraw_meseta_inventory_is_maxed() { async fn test_withdraw_meseta_and_buy_a_few_monomates_with_it() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; entity_gateway.set_character_meseta(&char1.id, item::Meseta(100)).await.unwrap(); entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Character, item::Meseta(300)).await.unwrap(); @@ -1587,7 +1387,7 @@ async fn test_withdraw_meseta_and_buy_a_few_monomates_with_it() { async fn test_deposit_items_into_shared_banks() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let item0 = entity_gateway.create_item(ItemBuilder::weapon(item::weapon::WeaponType::Saber).as_new()).await.unwrap(); let item1 = entity_gateway.create_item(ItemBuilder::weapon(item::weapon::WeaponType::Buster).as_new()).await.unwrap(); @@ -1709,7 +1509,7 @@ async fn test_deposit_items_into_shared_banks() { async fn test_deposit_meseta_into_shared_banks() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; entity_gateway.set_character_meseta(&char1.id, item::Meseta(300)).await.unwrap(); let mut ship = standard_ship(entity_gateway.clone()); @@ -1784,7 +1584,7 @@ async fn test_deposit_meseta_into_shared_banks() { async fn test_withdraw_items_from_shared_banks() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let item0 = entity_gateway.create_item(ItemBuilder::weapon(item::weapon::WeaponType::Saber).as_new()).await.unwrap(); let item1 = entity_gateway.create_item(ItemBuilder::weapon(item::weapon::WeaponType::Buster).as_new()).await.unwrap(); @@ -1894,7 +1694,7 @@ async fn test_withdraw_items_from_shared_banks() { async fn test_withdraw_meseta_from_shared_banks() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Character, item::Meseta(300)).await.unwrap(); entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Shared(item::BankName("asdf".into())), item::Meseta(300)).await.unwrap(); entity_gateway.set_bank_meseta(&char1.id, &item::BankIdentifier::Shared(item::BankName("qwer".into())), item::Meseta(300)).await.unwrap(); diff --git a/tests/test_character.rs b/tests/test_character.rs index 0c8cecf..237ded9 100644 --- a/tests/test_character.rs +++ b/tests/test_character.rs @@ -1,6 +1,6 @@ use networking::serverstate::{ClientId, ServerState}; use entity::gateway::{EntityGateway, InMemoryGateway}; -use elseware::ship::ship::RecvShipPacket; +use ship_server::RecvShipPacket; use libpso::character::settings::{DEFAULT_KEYBOARD_CONFIG1, DEFAULT_KEYBOARD_CONFIG4}; use libpso::packet::ship::*; @@ -13,7 +13,7 @@ use common::*; async fn test_save_options() { let mut entity_gateway = InMemoryGateway::default(); - let (user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut ship = standard_ship(entity_gateway.clone()); log_in_char(&mut ship, ClientId(1), "a1", "a").await; @@ -33,7 +33,7 @@ async fn test_save_options() { async fn test_change_keyboard_mappings() { let mut entity_gateway = InMemoryGateway::default(); - let (user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 2).await; + let (user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut ship = standard_ship(entity_gateway.clone()); log_in_char(&mut ship, ClientId(1), "a1", "a").await; diff --git a/tests/test_exp_gain.rs b/tests/test_exp_gain.rs index ae49fce..db71ec9 100644 --- a/tests/test_exp_gain.rs +++ b/tests/test_exp_gain.rs @@ -1,7 +1,7 @@ use networking::serverstate::{ClientId, ServerState}; use entity::gateway::{EntityGateway, InMemoryGateway}; use stats::leveltable::CharacterLevelTable; -use elseware::ship::ship::{SendShipPacket, RecvShipPacket}; +use ship_server::{SendShipPacket, RecvShipPacket}; use maps::variant::{MapVariant, MapVariantMode}; use maps::maps::Maps; use maps::area::MapArea; @@ -19,7 +19,7 @@ use common::*; async fn test_character_gains_exp() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut ship = standard_ship_buildable(entity_gateway.clone()) .map_builder(Box::new(|_room_mode, _event| { @@ -52,7 +52,7 @@ async fn test_character_gains_exp() { async fn test_character_levels_up() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; char1.exp = 49; entity_gateway.save_character(&char1).await.unwrap(); @@ -90,7 +90,7 @@ async fn test_character_levels_up() { async fn test_character_levels_up_multiple_times() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut ship = standard_ship_buildable(entity_gateway.clone()) .map_builder(Box::new(|_room_mode, _event| { @@ -125,8 +125,8 @@ async fn test_character_levels_up_multiple_times() { async fn test_one_character_gets_full_exp_and_other_attacker_gets_partial() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut ship = standard_ship_buildable(entity_gateway.clone()) .map_builder(Box::new(|_room_mode, _event| { diff --git a/tests/test_item_actions.rs b/tests/test_item_actions.rs index 758aa10..1237063 100644 --- a/tests/test_item_actions.rs +++ b/tests/test_item_actions.rs @@ -1,6 +1,6 @@ use networking::serverstate::{ClientId, ServerState}; use entity::gateway::{EntityGateway, InMemoryGateway}; -use elseware::ship::ship::RecvShipPacket; +use ship_server::RecvShipPacket; use entity::item; use libpso::packet::ship::*; @@ -14,37 +14,25 @@ use common::*; async fn test_equip_unit_from_equip_menu() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Armor( - item::armor::Armor{ - armor: item::armor::ArmorType::Frame, - dfp: 0, - evp: 0, - slots: 4, - }), - }).await.unwrap()); + ItemBuilder::armor(item::armor::ArmorType::Frame) + .slots(4) + .as_new() + ).await.unwrap()); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit{ - unit: item::unit::UnitType::KnightPower, - modifier: None, - }), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::KnightPower) + .as_new() + ).await.unwrap()); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit{ - unit: item::unit::UnitType::KnightPower, - modifier: Some(item::unit::UnitModifier::Plus), - }), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::KnightPower) + .modifier(item::unit::UnitModifier::Plus) + .as_new() + ).await.unwrap()); let equipped = item::EquippedEntity { weapon: None, @@ -89,37 +77,25 @@ async fn test_equip_unit_from_equip_menu() { async fn test_unequip_armor_with_units() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Armor( - item::armor::Armor{ - armor: item::armor::ArmorType::Frame, - dfp: 0, - evp: 0, - slots: 4, - }), - }).await.unwrap()); + ItemBuilder::armor(item::armor::ArmorType::Frame) + .slots(4) + .as_new() + ).await.unwrap()); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit{ - unit: item::unit::UnitType::KnightPower, - modifier: None, - }), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::KnightPower) + .as_new() + ).await.unwrap()); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit{ - unit: item::unit::UnitType::KnightPower, - modifier: Some(item::unit::UnitModifier::Plus), - }), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::KnightPower) + .modifier(item::unit::UnitModifier::Plus) + .as_new() + ).await.unwrap()); let equipped = item::EquippedEntity { weapon: None, @@ -155,37 +131,25 @@ async fn test_unequip_armor_with_units() { async fn test_sort_items() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Armor( - item::armor::Armor{ - armor: item::armor::ArmorType::Frame, - dfp: 0, - evp: 0, - slots: 4, - }), - }).await.unwrap()); + ItemBuilder::armor(item::armor::ArmorType::Frame) + .slots(4) + .as_new() + ).await.unwrap()); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit{ - unit: item::unit::UnitType::KnightPower, - modifier: None, - }), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::KnightPower) + .as_new() + ).await.unwrap()); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit{ - unit: item::unit::UnitType::KnightPower, - modifier: Some(item::unit::UnitModifier::Plus), - }), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::KnightPower) + .modifier(item::unit::UnitModifier::Plus) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -210,8 +174,8 @@ async fn test_sort_items() { ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::SortItems(SortItems { client: 255, target: 255, - item_ids: [0x10001u32, 0x10002, 0x10000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + item_ids: [0x10001u32, 0x10002, 0x10000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF], })))).await.unwrap(); diff --git a/tests/test_item_drop.rs b/tests/test_item_drop.rs index 0c700bb..91f179b 100644 --- a/tests/test_item_drop.rs +++ b/tests/test_item_drop.rs @@ -1,6 +1,6 @@ use networking::serverstate::{ClientId, ServerState}; use entity::gateway::InMemoryGateway; -use elseware::ship::ship::{SendShipPacket, RecvShipPacket}; +use ship_server::{SendShipPacket, RecvShipPacket}; use maps::monster::MonsterType; use drops::{StandardDropTable, MonsterDropStats, MonsterDropType}; use drops::rare_drop_table::{RareDropTable, RareDropRate, RareDropItem}; @@ -20,7 +20,7 @@ use common::*; #[async_std::test] async fn test_enemy_drops_item() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut ship = standard_ship_buildable(entity_gateway.clone()) .map_builder(Box::new(|_room_mode, _event| { @@ -74,8 +74,8 @@ async fn test_enemy_drops_item() { #[async_std::test] async fn test_enemy_drops_item_for_two_players() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut ship = standard_ship_buildable(entity_gateway.clone()) .map_builder(Box::new(|_room_mode, _event| { @@ -141,8 +141,8 @@ async fn test_enemy_drops_item_for_two_players() { #[async_std::test] async fn test_enemy_drops_item_for_two_players_and_pick_up() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut ship = standard_ship_buildable(entity_gateway.clone()) .map_builder(Box::new(|_room_mode, _event| { diff --git a/tests/test_item_id.rs b/tests/test_item_id.rs index ad2f860..3302806 100644 --- a/tests/test_item_id.rs +++ b/tests/test_item_id.rs @@ -1,7 +1,7 @@ use networking::serverstate::{ClientId, ServerState}; use entity::gateway::{EntityGateway, InMemoryGateway}; use entity::item; -use elseware::ship::ship::RecvShipPacket; +use ship_server::RecvShipPacket; use libpso::packet::ship::*; use libpso::packet::messages::*; @@ -14,21 +14,17 @@ use common::*; #[async_std::test] async fn test_use_monomate_after_leaving_and_rejoining_room() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut p1_items = Vec::new(); for tool in vec![item::tool::ToolType::Monomate, item::tool::ToolType::Monofluid].into_iter() { let mut item = Vec::new(); for _ in 0..2usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p1_items.push(item::InventoryItemEntity::Stacked(item)); } @@ -40,13 +36,9 @@ async fn test_use_monomate_after_leaving_and_rejoining_room() { let mut item = Vec::new(); for _ in 0..2usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p2_items.push(item::InventoryItemEntity::Stacked(item)); } @@ -107,22 +99,18 @@ async fn test_use_monomate_after_leaving_and_rejoining_room() { #[async_std::test] async fn test_using_some_monomates_after_a_convoluted_series_of_leaves_and_joins() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; - let (_user3, char3) = new_user_character(&mut entity_gateway, "a3", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; + let (_user3, char3) = new_user_character(&mut entity_gateway, "a3", "a").await; let mut p1_items = Vec::new(); for tool in vec![item::tool::ToolType::Monofluid, item::tool::ToolType::Difluid, item::tool::ToolType::Trifluid].into_iter() { let mut item = Vec::new(); for _ in 0..2usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p1_items.push(item::InventoryItemEntity::Stacked(item)); } @@ -133,13 +121,9 @@ async fn test_using_some_monomates_after_a_convoluted_series_of_leaves_and_joins let mut item = Vec::new(); for _ in 0..6usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p2_items.push(item::InventoryItemEntity::Stacked(item)); } @@ -150,17 +134,9 @@ async fn test_using_some_monomates_after_a_convoluted_series_of_leaves_and_joins p3_items.push( item::InventoryItemEntity::Individual( entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap() + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap() )); } entity_gateway.set_character_inventory(&char3.id, &item::InventoryEntity::new(p3_items)).await.unwrap(); @@ -294,20 +270,16 @@ async fn test_using_some_monomates_after_a_convoluted_series_of_leaves_and_joins #[async_std::test] async fn test_depositing_a_full_stack_then_withdrawing_part() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_items = Vec::new(); for tool in vec![item::tool::ToolType::Monofluid, item::tool::ToolType::Difluid, item::tool::ToolType::Trifluid].into_iter() { let mut item = Vec::new(); for _ in 0..5usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p1_items.push(item::InventoryItemEntity::Stacked(item)); } @@ -316,13 +288,9 @@ async fn test_depositing_a_full_stack_then_withdrawing_part() { let mut monomates = Vec::new(); for _ in 0..3usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), &item::BankIdentifier::Character).await.unwrap(); diff --git a/tests/test_item_pickup.rs b/tests/test_item_pickup.rs index 3ec0b9c..ccef78a 100644 --- a/tests/test_item_pickup.rs +++ b/tests/test_item_pickup.rs @@ -1,7 +1,7 @@ use networking::serverstate::{ClientId, ServerState}; use entity::gateway::{EntityGateway, InMemoryGateway}; use entity::item; -use elseware::ship::ship::RecvShipPacket; +use ship_server::RecvShipPacket; use libpso::packet::ship::*; use libpso::packet::messages::*; @@ -14,22 +14,14 @@ use common::*; async fn test_pick_up_individual_item() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::::new())).await.unwrap(); @@ -83,31 +75,23 @@ async fn test_pick_up_individual_item() { async fn test_pick_up_item_stack_of_items_already_in_inventory() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut p1_monomate = Vec::new(); p1_monomate.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); let mut p2_items = Vec::new(); for (_slot, tool) in vec![item::tool::ToolType::Monomate, item::tool::ToolType::Monofluid].into_iter().enumerate() { let mut item = Vec::new(); for _ in 0..5usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p2_items.push(item); } @@ -157,18 +141,14 @@ async fn test_pick_up_item_stack_of_items_already_in_inventory() { async fn test_pick_up_item_stack_of_items_not_already_held() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut p2_monomate = Vec::new(); p2_monomate.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(vec![p2_monomate])).await.unwrap(); @@ -214,23 +194,15 @@ async fn test_pick_up_item_stack_of_items_not_already_held() { async fn test_pick_up_meseta_when_inventory_full() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut p1_items = Vec::new(); for _ in 0..30usize { p1_items.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_items)).await.unwrap(); @@ -285,43 +257,27 @@ async fn test_pick_up_meseta_when_inventory_full() { async fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut p1_inv = Vec::new(); for _slot in 0..29usize { p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap().into()); + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap().into()); } p1_inv.push(item::InventoryItemEntity::Stacked(vec![entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()])); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()])); let mut p2_monomates = Vec::new(); p2_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(vec![p2_monomates])).await.unwrap(); @@ -366,38 +322,22 @@ async fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() { async fn test_can_not_pick_up_item_when_inventory_full() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut p1_inv = Vec::new(); for _slot in 0..30usize { p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap()); } let mut p2_inv = Vec::new(); p2_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(p2_inv)).await.unwrap(); @@ -454,7 +394,7 @@ async fn test_can_not_pick_up_item_when_inventory_full() { async fn test_can_not_drop_more_meseta_than_is_held() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; entity_gateway.set_character_meseta(&char1.id, item::Meseta(300)).await.unwrap(); @@ -492,31 +432,23 @@ async fn test_can_not_drop_more_meseta_than_is_held() { async fn test_pick_up_stack_that_would_exceed_stack_limit() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut p1_monomates = Vec::new(); for _ in 0..6usize { p1_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } let mut p2_monomates = Vec::new(); for _ in 0..6usize { p2_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![p1_monomates])).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(vec![p2_monomates])).await.unwrap(); @@ -564,8 +496,8 @@ async fn test_pick_up_stack_that_would_exceed_stack_limit() { async fn test_can_not_pick_up_meseta_when_full() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap(); entity_gateway.set_character_meseta(&char2.id, item::Meseta(300)).await.unwrap(); @@ -617,8 +549,8 @@ async fn test_can_not_pick_up_meseta_when_full() { async fn test_meseta_caps_at_999999_when_trying_to_pick_up_more() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; entity_gateway.set_character_meseta(&char1.id, item::Meseta(999998)).await.unwrap(); entity_gateway.set_character_meseta(&char2.id, item::Meseta(300)).await.unwrap(); @@ -669,19 +601,15 @@ async fn test_meseta_caps_at_999999_when_trying_to_pick_up_more() { async fn test_player_drops_partial_stack_and_other_player_picks_it_up() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut monomates = Vec::new(); for _ in 0..5usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![monomates])).await.unwrap(); diff --git a/tests/test_item_use.rs b/tests/test_item_use.rs index 13f2310..274a344 100644 --- a/tests/test_item_use.rs +++ b/tests/test_item_use.rs @@ -1,7 +1,7 @@ use networking::serverstate::{ClientId, ServerState}; use entity::gateway::{EntityGateway, InMemoryGateway}; use entity::item; -use elseware::ship::ship::RecvShipPacket; +use ship_server::RecvShipPacket; use entity::character::TechLevel; use libpso::packet::ship::*; @@ -16,20 +16,16 @@ use common::*; async fn test_use_monomate() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_items = Vec::new(); for tool in vec![item::tool::ToolType::Monomate, item::tool::ToolType::Monofluid].into_iter() { let mut item = Vec::new(); for _ in 0..2usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p1_items.push(item::InventoryItemEntity::Stacked(item)); } @@ -61,20 +57,16 @@ async fn test_use_monomate() { async fn test_use_monomate_twice() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_items = Vec::new(); for tool in vec![item::tool::ToolType::Monomate, item::tool::ToolType::Monofluid].into_iter() { let mut item = Vec::new(); for _ in 0..3usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p1_items.push(item::InventoryItemEntity::Stacked(item)); } @@ -111,18 +103,14 @@ async fn test_use_monomate_twice() { async fn test_use_last_monomate() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); for tool in vec![item::tool::ToolType::Monomate, item::tool::ToolType::Monofluid].into_iter() { p1_inv.push(item::InventoryItemEntity::Stacked(vec![entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()])); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()])); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -151,17 +139,13 @@ async fn test_use_last_monomate() { async fn test_use_nonstackable_tool() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_items = Vec::new(); p1_items.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::HuntersReport, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::HuntersReport) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_items)).await.unwrap(); @@ -184,20 +168,16 @@ async fn test_use_nonstackable_tool() { async fn test_use_materials() { let mut entity_gateway = InMemoryGateway::default(); - let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); for tool in vec![item::tool::ToolType::PowerMaterial, item::tool::ToolType::LuckMaterial].into_iter() { let mut item = Vec::new(); for _ in 0..5usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p1_inv.push(item::InventoryItemEntity::Stacked(item)); } @@ -244,26 +224,19 @@ async fn test_use_materials() { #[async_std::test] async fn test_jackolantern() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let p1_inv = vec![ item::InventoryItemEntity::Stacked( vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::JackOLantern, - } - ), - }).await.unwrap(), - entity_gateway.create_item(item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::JackOLantern, - } - ), - }).await.unwrap(), + ItemBuilder::tool(item::tool::ToolType::JackOLantern) + .as_new() + ).await.unwrap(), + entity_gateway.create_item( + ItemBuilder::tool(item::tool::ToolType::JackOLantern) + .as_new() + ).await.unwrap(), ])]; entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -297,38 +270,23 @@ async fn test_jackolantern() { async fn test_use_barta_1() { let mut entity_gateway = InMemoryGateway::default(); - let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::TechniqueDisk( - item::tech::TechniqueDisk { - tech: item::tech::Technique::Foie, - level: 3, - } - ) - } + ItemBuilder::tech(item::tech::Technique::Foie) + .level(3) + .as_new() ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::TechniqueDisk( - item::tech::TechniqueDisk { - tech: item::tech::Technique::Barta, - level: 4, - } - ) - } + ItemBuilder::tech(item::tech::Technique::Barta) + .level(4) + .as_new() ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::TechniqueDisk( - item::tech::TechniqueDisk { - tech: item::tech::Technique::Zonde, - level: 5, - } - ) - } + ItemBuilder::tech(item::tech::Technique::Zonde) + .level(5) + .as_new() ).await.unwrap() ]; @@ -365,31 +323,19 @@ async fn test_use_barta_1() { async fn test_use_monogrinder() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let saber = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(); + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap(); let mut grinders = Vec::new(); for _ in 0..3usize { grinders.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monogrinder, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monogrinder) + .as_new() + ).await.unwrap()); } let equipped = item::EquippedEntity { diff --git a/tests/test_mags.rs b/tests/test_mags.rs index dac0e06..8ffc6a9 100644 --- a/tests/test_mags.rs +++ b/tests/test_mags.rs @@ -1,7 +1,7 @@ use networking::serverstate::{ClientId, ServerState}; use entity::gateway::{EntityGateway, InMemoryGateway}; use entity::item; -use elseware::ship::ship::RecvShipPacket; +use ship_server::RecvShipPacket; use entity::character::{CharacterClass, SectionID}; use libpso::packet::ship::*; @@ -15,25 +15,19 @@ use common::*; async fn test_mag_feed() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mag = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Mag( - item::mag::Mag::baby_mag(0) - ), - }).await.unwrap(); + ItemBuilder::baby_mag() + .as_new() + ).await.unwrap(); let mut monomates = Vec::new(); for _ in 0..7usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } let equipped = item::EquippedEntity { @@ -85,8 +79,8 @@ async fn test_mag_feed() { async fn test_mag_change_owner() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await; char1.char_class = CharacterClass::RAmarl; char1.section_id = SectionID::Redria; entity_gateway.save_character(&char1).await.unwrap(); @@ -95,11 +89,9 @@ async fn test_mag_change_owner() { entity_gateway.save_character(&char2).await.unwrap(); let mag = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Mag( - item::mag::Mag::baby_mag(0) - ), - }).await.unwrap(); + ItemBuilder::baby_mag() + .as_new() + ).await.unwrap(); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![mag])).await.unwrap(); @@ -148,34 +140,24 @@ async fn test_mag_change_owner() { async fn test_mag_cell() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mag = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Mag( - item::mag::Mag::baby_mag(0) - ), - }).await.unwrap(); + ItemBuilder::baby_mag() + .as_new() + ).await.unwrap(); for _ in 0..1000usize { let fed_tool = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool ( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap(); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap(); entity_gateway.feed_mag(&mag.id, &fed_tool.id).await.unwrap(); } let mag_cell = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::CellOfMag502, - } - ), - }).await.unwrap(); + ItemBuilder::tool(item::tool::ToolType::CellOfMag502) + .as_new() + ).await.unwrap(); let equipped = item::EquippedEntity { weapon: None, diff --git a/tests/test_rooms.rs b/tests/test_rooms.rs index 447ea7b..5e65574 100644 --- a/tests/test_rooms.rs +++ b/tests/test_rooms.rs @@ -1,6 +1,6 @@ use networking::serverstate::{ClientId, ServerState}; use entity::gateway::{EntityGateway, InMemoryGateway}; -use elseware::ship::ship::{RecvShipPacket, SendShipPacket}; +use ship_server::{RecvShipPacket, SendShipPacket}; use libpso::packet::ship::*; //use libpso::packet::messages::*; @@ -13,7 +13,7 @@ use common::*; #[async_std::test] async fn test_set_valid_quest_group() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut ship = standard_ship_buildable(entity_gateway.clone()) .standard_quest_builder(Box::new(quests::load_standard_quests)) .build(); @@ -33,7 +33,7 @@ async fn test_set_valid_quest_group() { #[async_std::test] async fn test_set_invalid_quest_group() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut ship = standard_ship_buildable(entity_gateway.clone()) .standard_quest_builder(Box::new(quests::load_standard_quests)) .government_quest_builder(Box::new(quests::load_government_quests)) @@ -56,10 +56,10 @@ async fn test_set_invalid_quest_group() { #[async_std::test] async fn test_get_room_info() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, mut _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, mut _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; _char1.name = String::from("GODmar"); entity_gateway.save_character(&_char1).await.unwrap(); - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut ship = standard_ship(entity_gateway.clone()); log_in_char(&mut ship, ClientId(1), "a1", "a").await; log_in_char(&mut ship, ClientId(2), "a2", "a").await; @@ -77,8 +77,8 @@ async fn test_get_room_info() { #[async_std::test] async fn test_cannot_get_room_info_after_room_is_closed() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut ship = standard_ship(entity_gateway.clone()); log_in_char(&mut ship, ClientId(1), "a1", "a").await; log_in_char(&mut ship, ClientId(2), "a2", "a").await; @@ -97,8 +97,8 @@ async fn test_cannot_get_room_info_after_room_is_closed() { #[async_std::test] async fn test_cannot_join_room_after_its_closed() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut ship = standard_ship(entity_gateway.clone()); log_in_char(&mut ship, ClientId(1), "a1", "a").await; log_in_char(&mut ship, ClientId(2), "a2", "a").await; diff --git a/tests/test_shops.rs b/tests/test_shops.rs index cfcb749..59540b7 100644 --- a/tests/test_shops.rs +++ b/tests/test_shops.rs @@ -1,7 +1,7 @@ use networking::serverstate::{ClientId, ServerState}; use entity::gateway::{EntityGateway, InMemoryGateway}; use entity::item; -use elseware::ship::ship::{RecvShipPacket, SendShipPacket}; +use ship_server::{RecvShipPacket, SendShipPacket}; use maps::room::Difficulty; use items::state::ItemStateError; use shops::StandardItemShops; @@ -17,7 +17,7 @@ use common::*; async fn test_player_opens_weapon_shop() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; char1.exp = 80000000; entity_gateway.save_character(&char1).await.unwrap(); @@ -47,7 +47,7 @@ async fn test_player_opens_weapon_shop() { async fn test_player_opens_tool_shop() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; char1.exp = 80000000; entity_gateway.save_character(&char1).await.unwrap(); @@ -77,7 +77,7 @@ async fn test_player_opens_tool_shop() { async fn test_player_opens_armor_shop() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; char1.exp = 80000000; entity_gateway.save_character(&char1).await.unwrap(); @@ -107,7 +107,7 @@ async fn test_player_opens_armor_shop() { async fn test_player_buys_from_weapon_shop() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; char1.exp = 80000000; entity_gateway.save_character(&char1).await.unwrap(); entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap(); @@ -145,7 +145,7 @@ async fn test_player_buys_from_weapon_shop() { async fn test_player_buys_from_tool_shop() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; char1.exp = 80000000; entity_gateway.save_character(&char1).await.unwrap(); entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap(); @@ -182,7 +182,7 @@ async fn test_player_buys_from_tool_shop() { async fn test_player_buys_multiple_from_tool_shop() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; char1.exp = 80000000; entity_gateway.save_character(&char1).await.unwrap(); entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap(); @@ -223,7 +223,7 @@ async fn test_player_buys_multiple_from_tool_shop() { async fn test_player_buys_from_armor_shop() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; char1.exp = 80000000; entity_gateway.save_character(&char1).await.unwrap(); entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap(); @@ -260,24 +260,19 @@ async fn test_player_buys_from_armor_shop() { async fn test_player_sells_3_attr_weapon_to_shop() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 5, - special: Some(item::weapon::WeaponSpecial::Charge), - attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}), - Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}), - Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .grind(5) + .special(item::weapon::WeaponSpecial::Charge) + .attr(item::weapon::Attribute::Hit, 100) + .attr(item::weapon::Attribute::Dark, 100) + .attr(item::weapon::Attribute::Native, 100) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -302,8 +297,8 @@ async fn test_player_sells_3_attr_weapon_to_shop() { async fn test_other_clients_see_purchase() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; char1.exp = 80000000; entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap(); entity_gateway.save_character(&char1).await.unwrap(); @@ -345,19 +340,15 @@ async fn test_other_clients_see_purchase() { async fn test_other_clients_see_stacked_purchase() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; char1.exp = 80000000; entity_gateway.save_character(&char1).await.unwrap(); entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap(); entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate - } - ), - }).await.unwrap(); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap(); let mut ship = standard_ship_buildable(entity_gateway.clone()) .item_shops(StandardItemShops::default()) @@ -396,7 +387,7 @@ async fn test_other_clients_see_stacked_purchase() { async fn test_buying_item_without_enough_mseseta() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut ship = standard_ship(entity_gateway.clone()); log_in_char(&mut ship, ClientId(1), "a1", "a").await; @@ -429,7 +420,7 @@ async fn test_buying_item_without_enough_mseseta() { async fn test_player_double_buys_from_tool_shop() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; char1.exp = 80000000; entity_gateway.save_character(&char1).await.unwrap(); entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap(); @@ -494,7 +485,7 @@ async fn test_player_double_buys_from_tool_shop() { async fn test_techs_disappear_from_shop_when_bought() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; char1.exp = 80000000; entity_gateway.save_character(&char1).await.unwrap(); entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap(); @@ -556,7 +547,7 @@ async fn test_techs_disappear_from_shop_when_bought() { async fn test_units_disappear_from_shop_when_bought() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; char1.exp = 80000000; entity_gateway.save_character(&char1).await.unwrap(); entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap(); @@ -617,24 +608,20 @@ async fn test_units_disappear_from_shop_when_bought() { async fn test_player_sells_untekked_weapon() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 5, - special: Some(item::weapon::WeaponSpecial::Charge), - attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}), - Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}), - Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),], - tekked: false, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .untekked() + .grind(5) + .special(item::weapon::WeaponSpecial::Charge) + .attr(item::weapon::Attribute::Hit, 100) + .attr(item::weapon::Attribute::Dark, 100) + .attr(item::weapon::Attribute::Native, 100) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -659,24 +646,18 @@ async fn test_player_sells_untekked_weapon() { async fn test_player_sells_rare_item() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::DarkFlow, - grind: 5, - special: None, - attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}), - Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}), - Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::DarkFlow) + .grind(5) + .attr(item::weapon::Attribute::Hit, 100) + .attr(item::weapon::Attribute::Dark, 100) + .attr(item::weapon::Attribute::Native, 100) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -701,20 +682,16 @@ async fn test_player_sells_rare_item() { async fn test_player_sells_partial_photon_drop_stack() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); let mut photon_drops = Vec::new(); for _ in 0..7usize { photon_drops.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::PhotonDrop, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::PhotonDrop) + .as_new() + ).await.unwrap()); } p1_inv.push(item::InventoryItemEntity::Stacked(photon_drops)); @@ -742,21 +719,14 @@ async fn test_player_sells_partial_photon_drop_stack() { async fn test_player_sells_basic_frame() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Armor( - item::armor::Armor { - armor: item::armor::ArmorType::Frame, - dfp: 0, - evp: 0, - slots: 0, - } - ), - }).await.unwrap()); + ItemBuilder::armor(item::armor::ArmorType::Frame) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -781,21 +751,17 @@ async fn test_player_sells_basic_frame() { async fn test_player_sells_max_frame() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Armor( - item::armor::Armor { - armor: item::armor::ArmorType::Frame, - dfp: 2, - evp: 2, - slots: 4, - } - ), - }).await.unwrap()); + ItemBuilder::armor(item::armor::ArmorType::Frame) + .dfp(2) + .evp(2) + .slots(4) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -820,20 +786,14 @@ async fn test_player_sells_max_frame() { async fn test_player_sells_basic_barrier() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Shield( - item::shield::Shield { - shield: item::shield::ShieldType::Barrier, - dfp: 0, - evp: 0, - } - ), - }).await.unwrap()); + ItemBuilder::shield(item::shield::ShieldType::Barrier) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -858,20 +818,16 @@ async fn test_player_sells_basic_barrier() { async fn test_player_sells_max_barrier() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Shield( - item::shield::Shield { - shield: item::shield::ShieldType::Barrier, - dfp: 5, - evp: 5, - } - ), - }).await.unwrap()); + ItemBuilder::shield(item::shield::ShieldType::Barrier) + .dfp(5) + .evp(5) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -896,19 +852,15 @@ async fn test_player_sells_max_barrier() { async fn test_player_sells_1_star_minusminus_unit() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit { - unit: item::unit::UnitType::PriestMind, - modifier: Some(item::unit::UnitModifier::MinusMinus), - } - ), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::PriestMind) + .modifier(item::unit::UnitModifier::MinusMinus) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -933,19 +885,15 @@ async fn test_player_sells_1_star_minusminus_unit() { async fn test_player_sells_5_star_plusplus_unit() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit { - unit: item::unit::UnitType::GeneralHp, - modifier: Some(item::unit::UnitModifier::PlusPlus), - } - ), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::GeneralHp) + .modifier(item::unit::UnitModifier::PlusPlus) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -970,21 +918,17 @@ async fn test_player_sells_5_star_plusplus_unit() { async fn test_player_sells_rare_frame() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Armor( - item::armor::Armor { - armor: item::armor::ArmorType::StinkFrame, - dfp: 10, - evp: 20, - slots: 3, - } - ), - }).await.unwrap()); + ItemBuilder::armor(item::armor::ArmorType::StinkFrame) + .dfp(10) + .evp(20) + .slots(3) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -1009,20 +953,16 @@ async fn test_player_sells_rare_frame() { async fn test_player_sells_rare_barrier() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Shield( - item::shield::Shield { - shield: item::shield::ShieldType::RedRing, - dfp: 10, - evp: 20, - } - ), - }).await.unwrap()); + ItemBuilder::shield(item::shield::ShieldType::RedRing) + .dfp(10) + .evp(20) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -1047,19 +987,14 @@ async fn test_player_sells_rare_barrier() { async fn test_player_sells_rare_unit() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit { - unit: item::unit::UnitType::V101, - modifier: None, - } - ), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::V101) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -1084,20 +1019,15 @@ async fn test_player_sells_rare_unit() { async fn test_player_cant_sell_if_meseta_would_go_over_max() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; entity_gateway.set_character_meseta(&char1.id, item::Meseta(999995)).await.unwrap(); let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit { - unit: item::unit::UnitType::V101, - modifier: None, - } - ), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::V101) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); diff --git a/tests/test_trade.rs b/tests/test_trade.rs index 4a08d0a..8266892 100644 --- a/tests/test_trade.rs +++ b/tests/test_trade.rs @@ -2,9 +2,9 @@ use std::convert::TryInto; use networking::serverstate::{ClientId, ServerState}; use entity::gateway::{EntityGateway, InMemoryGateway}; use entity::item; -use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket}; +use ship_server::{ShipServerState, RecvShipPacket, SendShipPacket}; use entity::item::{Meseta, ItemEntity, InventoryItemEntity}; -use elseware::ship::packet::handler::trade::TradeError; +use ship_server::trade::TradeError; use libpso::packet::ship::*; use libpso::packet::messages::*; @@ -113,22 +113,14 @@ impl TradeItemBuilder { async fn test_trade_one_individual_item() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::::new())).await.unwrap(); @@ -212,22 +204,14 @@ async fn test_trade_one_individual_item() { async fn test_trade_player2_to_player1() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut p2_inv = Vec::new(); p2_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(Vec::::new())).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(p2_inv)).await.unwrap(); @@ -311,22 +295,14 @@ async fn test_trade_player2_to_player1() { async fn test_reverse_trade_ack_order() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::::new())).await.unwrap(); @@ -410,20 +386,16 @@ async fn test_reverse_trade_ack_order() { async fn test_trade_one_stacked_item() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_stack = futures::future::join_all((0..2).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -512,20 +484,16 @@ async fn test_trade_one_stacked_item() { async fn test_trade_partial_stacked_item() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_stack = futures::future::join_all((0..2).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -617,35 +585,19 @@ async fn test_trade_partial_stacked_item() { async fn test_trade_individual_both() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()]; + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap()]; let p2_inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()]; + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()]; entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(p2_inv)).await.unwrap(); @@ -780,20 +732,16 @@ async fn test_trade_individual_both() { async fn test_trade_stacked_both() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_stack = futures::future::join_all((0..2).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -804,13 +752,9 @@ async fn test_trade_stacked_both() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monofluid, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monofluid) + .as_new() + ).await }})) .await .into_iter() @@ -948,20 +892,16 @@ async fn test_trade_stacked_both() { async fn test_trade_partial_stack_both() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_stack = futures::future::join_all((0..2).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -972,13 +912,9 @@ async fn test_trade_partial_stack_both() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monofluid, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monofluid) + .as_new() + ).await }})) .await .into_iter() @@ -1122,20 +1058,16 @@ async fn test_trade_partial_stack_both() { async fn test_trade_same_stacked_item_to_eachother() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_stack = futures::future::join_all((0..3).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -1146,13 +1078,9 @@ async fn test_trade_same_stacked_item_to_eachother() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -1292,20 +1220,16 @@ async fn test_trade_same_stacked_item_to_eachother() { async fn test_trade_stacked_when_already_have_partial_stack() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_stack = futures::future::join_all((0..3).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -1316,13 +1240,9 @@ async fn test_trade_stacked_when_already_have_partial_stack() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -1430,34 +1350,22 @@ async fn test_trade_stacked_when_already_have_partial_stack() { async fn test_trade_individual_for_stacked() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()]; + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap()]; let p2_stack = futures::future::join_all((0..2).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -1598,60 +1506,28 @@ async fn test_trade_individual_for_stacked() { async fn test_trade_multiple_individual() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Buster, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Buster) + .as_new() + ).await.unwrap(), ]; let p2_inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Autogun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Autogun) + .as_new() + ).await.unwrap(), ]; entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -1854,20 +1730,16 @@ async fn test_trade_multiple_individual() { async fn test_trade_multiple_stacked() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_stack1 = futures::future::join_all((0..2).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -1877,13 +1749,9 @@ async fn test_trade_multiple_stacked() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Dimate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Dimate) + .as_new() + ).await }})) .await .into_iter() @@ -1894,13 +1762,9 @@ async fn test_trade_multiple_stacked() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monofluid, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monofluid) + .as_new() + ).await }})) .await .into_iter() @@ -1910,13 +1774,9 @@ async fn test_trade_multiple_stacked() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Difluid, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Difluid) + .as_new() + ).await }})) .await .into_iter() @@ -2119,24 +1979,15 @@ async fn test_trade_multiple_stacked() { async fn test_trade_not_enough_inventory_space_individual() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_inv = futures::future::join_all((0..2).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - } + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() ).await }})) .await @@ -2148,17 +1999,8 @@ async fn test_trade_not_enough_inventory_space_individual() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - } + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() ).await }})) .await @@ -2240,20 +2082,16 @@ async fn test_trade_not_enough_inventory_space_individual() { async fn test_trade_not_enough_inventory_space_stacked() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_stack = futures::future::join_all((0..2).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -2264,17 +2102,8 @@ async fn test_trade_not_enough_inventory_space_stacked() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - } + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() ).await }})) .await @@ -2355,20 +2184,16 @@ async fn test_trade_not_enough_inventory_space_stacked() { async fn test_trade_stack_too_big() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_stack = futures::future::join_all((0..8).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -2379,13 +2204,9 @@ async fn test_trade_stack_too_big() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -2469,8 +2290,8 @@ async fn test_trade_stack_too_big() { async fn test_trade_meseta() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; entity_gateway.set_character_meseta(&char1.id, Meseta(2323)).await.unwrap(); @@ -2548,8 +2369,8 @@ async fn test_trade_meseta() { async fn test_trade_too_much_meseta() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; entity_gateway.set_character_meseta(&char1.id, Meseta(4000)).await.unwrap(); entity_gateway.set_character_meseta(&char2.id, Meseta(999000)).await.unwrap(); @@ -2598,8 +2419,8 @@ async fn test_trade_too_much_meseta() { async fn test_trade_invalid_amount_of_meseta() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; entity_gateway.set_character_meseta(&char1.id, Meseta(4000)).await.unwrap(); entity_gateway.set_character_meseta(&char2.id, Meseta(999000)).await.unwrap(); @@ -2648,8 +2469,8 @@ async fn test_trade_invalid_amount_of_meseta() { async fn test_trade_meseta_request_and_items_dont_match() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; entity_gateway.set_character_meseta(&char1.id, Meseta(4000)).await.unwrap(); entity_gateway.set_character_meseta(&char2.id, Meseta(999000)).await.unwrap(); @@ -2698,8 +2519,8 @@ async fn test_trade_meseta_request_and_items_dont_match() { async fn test_player_declined_trade() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut ship = standard_ship(entity_gateway.clone()); log_in_char(&mut ship, ClientId(1), "a1", "a").await; @@ -2727,22 +2548,14 @@ async fn test_player_declined_trade() { async fn test_back_out_of_trade_last_minute() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::::new())).await.unwrap(); @@ -2791,24 +2604,15 @@ async fn test_back_out_of_trade_last_minute() { async fn test_valid_trade_when_both_inventories_are_full() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_inv = futures::future::join_all((0..30).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - } + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() ).await }})) .await @@ -2820,17 +2624,8 @@ async fn test_valid_trade_when_both_inventories_are_full() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - } + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() ).await }})) .await @@ -2931,24 +2726,15 @@ async fn test_valid_trade_when_both_inventories_are_full() { async fn test_invalid_trade_when_both_inventories_are_full() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_inv = futures::future::join_all((0..30).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - } + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() ).await }})) .await @@ -2960,17 +2746,8 @@ async fn test_invalid_trade_when_both_inventories_are_full() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - } + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() ).await }})) .await @@ -3081,9 +2858,9 @@ async fn test_invalid_trade_when_both_inventories_are_full() { async fn test_client_tries_to_start_two_trades() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; - let (_user2, _char3) = new_user_character(&mut entity_gateway, "a3", "a", 1).await; + let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; + let (_user2, _char3) = new_user_character(&mut entity_gateway, "a3", "a").await; let mut ship = standard_ship(entity_gateway.clone()); log_in_char(&mut ship, ClientId(1), "a1", "a").await; @@ -3112,9 +2889,9 @@ async fn test_client_tries_to_start_two_trades() { async fn test_client_tries_trading_with_client_already_trading() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; - let (_user2, _char3) = new_user_character(&mut entity_gateway, "a3", "a", 1).await; + let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; + let (_user2, _char3) = new_user_character(&mut entity_gateway, "a3", "a").await; let mut ship = standard_ship(entity_gateway.clone()); log_in_char(&mut ship, ClientId(1), "a1", "a").await; @@ -3149,23 +2926,15 @@ async fn test_client_tries_trading_with_client_already_trading() { async fn test_add_then_remove_individual_item() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut p1_inv = Vec::new(); for _ in 0..2 { p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -3260,20 +3029,16 @@ async fn test_add_then_remove_individual_item() { async fn test_add_then_remove_stacked_item() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_stack1 = futures::future::join_all((0..2).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -3284,13 +3049,9 @@ async fn test_add_then_remove_stacked_item() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monofluid, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monofluid) + .as_new() + ).await }})) .await .into_iter() @@ -3393,20 +3154,16 @@ async fn test_add_then_remove_stacked_item() { async fn test_add_then_remove_partial_stack() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_stack1 = futures::future::join_all((0..2).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -3417,13 +3174,9 @@ async fn test_add_then_remove_partial_stack() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monofluid, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monofluid) + .as_new() + ).await }})) .await .into_iter() @@ -3515,8 +3268,8 @@ async fn test_add_then_remove_partial_stack() { async fn test_add_then_remove_meseta() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; entity_gateway.set_character_meseta(&char1.id, Meseta(2323)).await.unwrap(); @@ -3599,22 +3352,14 @@ async fn test_add_then_remove_meseta() { async fn test_items_to_trade_data_does_not_match() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::::new())).await.unwrap(); @@ -3680,22 +3425,14 @@ async fn test_items_to_trade_data_does_not_match() { async fn test_items_to_trade_id_does_not_match() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::::new())).await.unwrap(); @@ -3749,20 +3486,16 @@ async fn test_items_to_trade_id_does_not_match() { async fn test_stack_is_same_amount_in_request_and_items_to_trade() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_stack = futures::future::join_all((0..2).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -3821,20 +3554,16 @@ async fn test_stack_is_same_amount_in_request_and_items_to_trade() { async fn test_stack_is_same_amount_in_request_and_items_to_trade2() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_stack = futures::future::join_all((0..2).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -3893,46 +3622,22 @@ async fn test_stack_is_same_amount_in_request_and_items_to_trade2() { async fn test_items_to_trade_count_less_than() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Brand, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Brand) + .as_new() + ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Buster, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Buster) + .as_new() + ).await.unwrap(), ]; entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -3993,48 +3698,24 @@ async fn test_items_to_trade_count_less_than() { async fn test_items_to_trade_count_greater_than() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; entity_gateway.set_character_meseta(&char1.id, Meseta(23)).await.unwrap(); let p1_inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Brand, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Brand) + .as_new() + ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Buster, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Buster) + .as_new() + ).await.unwrap(), ]; entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -4101,46 +3782,22 @@ async fn test_items_to_trade_count_greater_than() { async fn test_items_to_trade_count_mismatch_with_meseta() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let p1_inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Brand, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Brand) + .as_new() + ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Buster, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Buster) + .as_new() + ).await.unwrap(), ]; entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -4201,22 +3858,14 @@ async fn test_items_to_trade_count_mismatch_with_meseta() { async fn test_dropping_item_after_trade() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::::new())).await.unwrap();