diff --git a/src/common/leveltable.rs b/src/common/leveltable.rs index 94ad8ae..1ca6cd1 100644 --- a/src/common/leveltable.rs +++ b/src/common/leveltable.rs @@ -3,7 +3,7 @@ use std::fs::File; use serde_json::Value; use crate::entity::character::CharacterClass; -#[derive(Default, Copy, Clone, Debug, PartialEq)] +#[derive(Default, Copy, Clone, Debug, PartialEq, Eq)] pub struct CharacterStats { pub hp: u16, pub atp: u16, diff --git a/src/entity/gateway/postgres/postgres.rs b/src/entity/gateway/postgres/postgres.rs index 81ae972..8987ab1 100644 --- a/src/entity/gateway/postgres/postgres.rs +++ b/src/entity/gateway/postgres/postgres.rs @@ -51,11 +51,9 @@ impl PostgresGateway { embedded::migrations::runner().run(&mut conn).unwrap(); let pool = async_std::task::block_on(async move { - let pool = PgPoolOptions::new() + PgPoolOptions::new() .max_connections(5) - .connect(&format!("postgresql://{}:{}@{}:5432/{}", username, password, host, dbname)).await.unwrap(); - - pool + .connect(&format!("postgresql://{}:{}@{}:5432/{}", username, password, host, dbname)).await.unwrap() }); PostgresGateway { diff --git a/src/entity/item/armor.rs b/src/entity/item/armor.rs index 451852b..45e9ed4 100644 --- a/src/entity/item/armor.rs +++ b/src/entity/item/armor.rs @@ -289,7 +289,7 @@ impl ArmorType { } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum ArmorModifier { AddSlot { addslot: ItemEntityId, @@ -297,7 +297,7 @@ pub enum ArmorModifier { } -#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub struct Armor { pub armor: ArmorType, pub dfp: u8, diff --git a/src/entity/item/esweapon.rs b/src/entity/item/esweapon.rs index 3a88ccd..2997780 100644 --- a/src/entity/item/esweapon.rs +++ b/src/entity/item/esweapon.rs @@ -121,7 +121,7 @@ impl ESWeaponType { } } -#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, strum_macros::EnumIter)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, strum_macros::EnumIter)] pub enum ESWeaponSpecial { Jellen = 1, Zalure, @@ -169,7 +169,7 @@ impl ESWeaponSpecial { } } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct ESWeapon { pub esweapon: ESWeaponType, pub special: Option, diff --git a/src/entity/item/mag.rs b/src/entity/item/mag.rs index e55491c..dbdb4a7 100644 --- a/src/entity/item/mag.rs +++ b/src/entity/item/mag.rs @@ -519,7 +519,7 @@ pub enum MagCellError { IsRareMag, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum MagModifier { FeedMag{ food: ItemEntityId, @@ -529,7 +529,7 @@ pub enum MagModifier { OwnerChange(CharacterClass, SectionID) } -#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize, enum_utils::FromStr)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, enum_utils::FromStr)] pub enum PhotonBlast { Farlla, Estlla, @@ -539,7 +539,7 @@ pub enum PhotonBlast { MyllaYoulla, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Mag { pub mag: MagType, def: u16, diff --git a/src/entity/item/mod.rs b/src/entity/item/mod.rs index e89a7a4..a1f78bd 100644 --- a/src/entity/item/mod.rs +++ b/src/entity/item/mod.rs @@ -13,7 +13,7 @@ use crate::entity::character::CharacterEntityId; use crate::ship::map::MapArea; use crate::ship::drops::ItemDropType; -#[derive(PartialEq, Copy, Clone, Debug, Hash, Eq, PartialOrd, Ord, Serialize, Deserialize)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash, PartialOrd, Ord, Serialize, Deserialize)] pub struct ItemEntityId(pub u32); #[derive(Hash, PartialEq, Eq, Debug, Clone)] pub struct ItemId(u32); @@ -70,7 +70,7 @@ pub enum ItemNote { }, } -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct Meseta(pub u32); impl Meseta { @@ -95,12 +95,12 @@ pub enum ItemType { ESWeapon(esweapon::ESWeaponType), } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum ItemParseError { InvalidBytes } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum ItemDetail { Weapon(weapon::Weapon), Armor(armor::Armor), @@ -186,7 +186,7 @@ pub struct NewItemEntity { pub item: ItemDetail, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct ItemEntity { pub id: ItemEntityId, pub item: ItemDetail, diff --git a/src/entity/item/shield.rs b/src/entity/item/shield.rs index 5c42598..4161c19 100644 --- a/src/entity/item/shield.rs +++ b/src/entity/item/shield.rs @@ -519,7 +519,7 @@ impl ShieldType { } -#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Shield { pub shield: ShieldType, pub dfp: u8, diff --git a/src/entity/item/tool.rs b/src/entity/item/tool.rs index f24f596..3826bbd 100644 --- a/src/entity/item/tool.rs +++ b/src/entity/item/tool.rs @@ -642,7 +642,7 @@ impl ToolType { } -#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Tool { pub tool: ToolType, } diff --git a/src/entity/item/unit.rs b/src/entity/item/unit.rs index 371f450..5dc73b6 100644 --- a/src/entity/item/unit.rs +++ b/src/entity/item/unit.rs @@ -323,7 +323,7 @@ impl UnitType { } } -#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum UnitModifier { PlusPlus, Plus, @@ -331,7 +331,7 @@ pub enum UnitModifier { MinusMinus, } -#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Unit { pub unit: UnitType, pub modifier: Option, diff --git a/src/entity/item/weapon.rs b/src/entity/item/weapon.rs index 11a8709..8e9db4b 100644 --- a/src/entity/item/weapon.rs +++ b/src/entity/item/weapon.rs @@ -10,7 +10,7 @@ pub enum ItemParseError { InvalidWeaponAttribute, } -#[derive(Debug, Copy, Clone, PartialEq, Hash, Eq, Ord, PartialOrd, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)] pub enum Attribute { Native = 1, ABeast, @@ -32,7 +32,7 @@ impl Attribute { } } -#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct WeaponAttribute { pub attr: Attribute, pub value: i8, @@ -45,7 +45,7 @@ impl WeaponAttribute { } -#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize, strum_macros::EnumIter)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, strum_macros::EnumIter)] pub enum WeaponSpecial { Draw = 1, Drain, @@ -1424,14 +1424,14 @@ impl WeaponType { } -#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum TekSpecialModifier { Plus, Neutral, Minus, } -#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum TekPercentModifier { PlusPlus, Plus, @@ -1440,7 +1440,7 @@ pub enum TekPercentModifier { MinusMinus, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum WeaponModifier { AddPercents { attr: WeaponAttribute, @@ -1457,7 +1457,7 @@ pub enum WeaponModifier { }, } -#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub struct Weapon { pub weapon: WeaponType, pub special: Option, diff --git a/src/ship/drops/mod.rs b/src/ship/drops/mod.rs index e5037af..5e9747f 100644 --- a/src/ship/drops/mod.rs +++ b/src/ship/drops/mod.rs @@ -89,7 +89,7 @@ pub struct MonsterDropStats { pub max_meseta: u32, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum ItemDropType { Weapon(weapon::Weapon), Armor(armor::Armor), diff --git a/src/ship/items/actions.rs b/src/ship/items/actions.rs index 10af797..bc0180e 100644 --- a/src/ship/items/actions.rs +++ b/src/ship/items/actions.rs @@ -1,3 +1,5 @@ +// TODO: replace various u32s and usizes denoting item amounts for ItemAmount(u32) for consistency + use crate::ship::items::ClientItemId; use crate::entity::item::{Meseta, ItemNote}; use std::future::Future; @@ -14,7 +16,7 @@ use crate::entity::item::tool::Tool; use crate::entity::item::ItemModifier; use crate::ship::shops::ShopItem; use crate::ship::trade::TradeItem; -use crate::ship::location::{AreaClient, RoomId}; +use crate::ship::location::AreaClient; use crate::ship::drops::{ItemDrop, ItemDropType}; pub enum TriggerCreateItem { @@ -107,7 +109,7 @@ fn take_item_from_inventory(character_id: CharacterEntityId, item_id: ClientItem move |(mut item_state, mut transaction), _| { Box::pin(async move { let mut inventory = item_state.inventory(&character_id)?; - let item = inventory.take_item(&item_id, amount).ok_or_else (|| ItemStateError::NoFloorItem(item_id))?; + let item = inventory.take_item(&item_id, amount).ok_or (ItemStateError::NoFloorItem(item_id))?; transaction.gateway().set_character_inventory(&character_id, &inventory.as_inventory_entity(&character_id)).await?; item_state.set_inventory(inventory); @@ -235,7 +237,7 @@ fn add_meseta_to_shared_floor(character_id: CharacterEntityId, amount: u32, map_ let floor_item = FloorItem { item_id: item_state.new_item_id()?, item: FloorItemDetail::Meseta(Meseta(amount)), - map_area: map_area, + map_area, x: drop_position.0, y: 0.0, z: drop_position.1, @@ -352,7 +354,7 @@ where { entity_gateway.with_transaction(|transaction| async move { let item_state_proxy = ItemStateProxy::new(item_state); - let ((item_state_proxy, transaction), result) = ItemStateAction::default() + let ((item_state_proxy, transaction), _) = ItemStateAction::default() .act(take_meseta_from_inventory(character.id, amount)) .act(add_meseta_to_bank(character.id, amount)) .commit((item_state_proxy, transaction)) @@ -369,7 +371,7 @@ fn take_item_from_bank(character_id: CharacterEntityId, item_id: ClientItemId, a move |(mut item_state, mut transaction), _| { Box::pin(async move { let mut bank = item_state.bank(&character_id)?; - let item = bank.take_item(&item_id, amount).ok_or_else(|| ItemStateError::NoBankItem(item_id))?; + let item = bank.take_item(&item_id, amount).ok_or(ItemStateError::NoBankItem(item_id))?; transaction.gateway().set_character_bank(&character_id, &bank.as_bank_entity(), &bank.name).await?; item_state.set_bank(bank); @@ -440,7 +442,7 @@ where .act(take_item_from_bank(character.id, *item_id, amount)) //.act(bank_item_to_inventory_item) //.act(add_item_to_inventory) - .act(add_bank_item_to_inventory(&character)) + .act(add_bank_item_to_inventory(character)) .commit((item_state_proxy, transaction)) .await?; item_state_proxy.commit(); @@ -664,10 +666,10 @@ fn feed_mag_item(character: CharacterEntity, mag_item_id: ClientItemId) Box::pin(async move { let mut inventory = item_state.inventory(&character.id)?; let mag_entity = inventory.get_by_client_id_mut(&mag_item_id) - .ok_or_else(|| ItemStateError::InvalidItemId(mag_item_id))? + .ok_or(ItemStateError::InvalidItemId(mag_item_id))? .item .as_individual_mut() - .ok_or_else(|| ItemStateError::NotAMag(mag_item_id))?; + .ok_or(ItemStateError::NotAMag(mag_item_id))?; let mag_entity_id = mag_entity.entity_id; let mut transaction = tool.with_entity_id(transaction, |mut transaction, entity_id| { @@ -683,13 +685,13 @@ fn feed_mag_item(character: CharacterEntity, mag_item_id: ClientItemId) let food_tool = tool .item .stacked() - .ok_or_else(|| ItemStateError::NotMagFood(tool.item_id))? + .ok_or(ItemStateError::NotMagFood(tool.item_id))? .tool .tool; let mag_entity = mag_entity .as_mag_mut() - .ok_or_else(|| ItemStateError::NotAMag(mag_item_id))?; + .ok_or(ItemStateError::NotAMag(mag_item_id))?; mag_entity.feed(food_tool); @@ -745,7 +747,7 @@ fn add_bought_item_to_inventory<'a>(character_id: CharacterEntityId, item: ItemDetail::Tool(tool), }).await?; transaction.gateway().add_item_note(&item_entity.id, ItemNote::BoughtAtShop { - character_id: character_id, + character_id, }).await?; item_entities.push(item_entity); } @@ -754,7 +756,7 @@ fn add_bought_item_to_inventory<'a>(character_id: CharacterEntityId, item_id, item: InventoryItemDetail::Stacked(StackedItemDetail { entity_ids: item_entities.into_iter().map(|i| i.id).collect(), - tool: tool, + tool, }) }; inventory.add_item(inventory_item)?.1 @@ -764,7 +766,7 @@ fn add_bought_item_to_inventory<'a>(character_id: CharacterEntityId, item: item_detail.clone(), }).await?; transaction.gateway().add_item_note(&item_entity.id, ItemNote::BoughtAtShop { - character_id: character_id, + character_id, }).await?; let inventory_item = InventoryItem { @@ -816,7 +818,7 @@ fn sell_inventory_item<'a>(character_id: CharacterEntityId) -> impl Fn((ItemStateProxy<'a>, Box), InventoryItem) -> Pin, Box), InventoryItem), ItemStateError>> + Send + 'a>> { - move |(mut item_state, mut transaction), inventory_item| { + move |(mut item_state, transaction), inventory_item| { Box::pin(async move { let mut inventory = item_state.inventory(&character_id)?; let price = inventory_item.item.sell_price()?; @@ -899,7 +901,7 @@ where -> Pin, Box), O), ItemStateError>> + Send + 'a>> + Send + Sync, T: Clone + Send + Sync, { - move |(mut item_state, mut transaction), arg| { + move |(item_state, transaction), arg| { let input = input.clone(); let func = func.clone(); println!("i {:?} {:?}", input, arg); @@ -958,18 +960,6 @@ where } } - -fn clear<'a, T: Send + Clone + 'a>() - -> impl Fn((ItemStateProxy<'a>, Box), T) - -> Pin, Box), ()), ItemStateError>> + Send + 'a>> -{ - move |state, _| { - Box::pin(async move { - Ok((state, ())) - }) - } -} - fn insert<'a, T: Send + Clone + 'a>(element: T) -> impl Fn((ItemStateProxy<'a>, Box), ()) -> Pin, Box), T), ItemStateError>> + Send + 'a>> @@ -986,26 +976,10 @@ fn add_item_to_inventory(character: CharacterEntity) -> impl for<'a> Fn((ItemStateProxy<'a>, Box), InventoryItem) -> Pin, Box), InventoryItem), ItemStateError>> + Send + 'a>> + Clone { - let character = character.clone(); move |(mut item_state, transaction), inventory_item| { let character = character.clone(); Box::pin(async move { - //let bank_name = item_state.bank(&character.id)?.name; let mut inventory = item_state.inventory(&character.id)?; - - let character_id = character.id; - /* - let transaction = bank_item.with_entity_id(transaction, |mut transaction, entity_id| { - let bank_name = bank_name.clone(); - async move { - transaction.gateway().add_item_note(&entity_id, ItemNote::Withdraw { - character_id, - bank: bank_name, - }).await?; - Ok(transaction) - }}).await?; - */ - let mut transaction = inventory_item.with_mag(transaction, |mut transaction, entity_id, _mag| { let character = character.clone(); async move { @@ -1060,7 +1034,6 @@ fn assign_new_item_id() pub async fn trade_items<'a, EG> ( item_state: &'a mut ItemState, entity_gateway: &mut EG, - room_id: RoomId, p1: (&AreaClient, &CharacterEntity, &Vec, Meseta), p2: (&AreaClient, &CharacterEntity, &Vec, Meseta)) -> Result<(Vec, Vec), ItemStateError> @@ -1137,9 +1110,9 @@ pub async fn take_meseta<'a, EG> ( where EG: EntityGateway, { - entity_gateway.with_transaction(|mut transaction| async move { + entity_gateway.with_transaction(|transaction| async move { let item_state_proxy = ItemStateProxy::new(item_state); - let ((item_state_proxy, transaction), p1_removed_items) = ItemStateAction::default() + let ((item_state_proxy, transaction), _) = ItemStateAction::default() .act(take_meseta_from_inventory(*character_id, meseta.0)) .commit((item_state_proxy, transaction)) .await?; @@ -1270,7 +1243,7 @@ pub async fn enemy_drops_item<'a, EG> ( where EG: EntityGateway, { - entity_gateway.with_transaction(|mut transaction| async move { + entity_gateway.with_transaction(|transaction| async move { let item_state_proxy = ItemStateProxy::new(item_state); let ((item_state_proxy, transaction), floor_item) = ItemStateAction::default() .act(convert_item_drop_to_floor_item(character_id, item_drop)) @@ -1283,17 +1256,17 @@ where }).await } -fn apply_modifier_to_inventory_item(character_id: CharacterEntityId, modifier: ItemModifier) +fn apply_modifier_to_inventory_item(modifier: ItemModifier) -> impl for<'a> Fn((ItemStateProxy<'a>, Box), InventoryItem) -> Pin, Box), InventoryItem), ItemStateError>> + Send + 'a>> { move |(item_state, mut transaction), mut inventory_item| { let modifier = modifier.clone(); Box::pin(async move { - match (&inventory_item.item, modifier) { - (InventoryItemDetail::Individual(IndividualItemDetail{entity_id, item: ItemDetail::Weapon(mut weapon), ..}), ItemModifier::WeaponModifier(modifier)) => { + match (&mut inventory_item.item, modifier) { + (InventoryItemDetail::Individual(IndividualItemDetail{entity_id, item: ItemDetail::Weapon(ref mut weapon), ..}), ItemModifier::WeaponModifier(modifier)) => { weapon.apply_modifier(&modifier); - transaction.gateway().add_weapon_modifier(&entity_id, modifier).await?; + transaction.gateway().add_weapon_modifier(entity_id, modifier).await?; }, _ => return Err(ItemStateError::InvalidModifier) } @@ -1334,7 +1307,7 @@ where let item_state_proxy = ItemStateProxy::new(item_state); let ((item_state_proxy, transaction), item) = ItemStateAction::default() .act(take_item_from_inventory(character.id, item_id, 1)) - .act(apply_modifier_to_inventory_item(character.id, modifier)) + .act(apply_modifier_to_inventory_item(modifier)) .act(add_item_to_inventory(character.clone())) .act(as_individual_item()) .commit((item_state_proxy, transaction)) diff --git a/src/ship/items/apply_item.rs b/src/ship/items/apply_item.rs index ce4a701..c88066e 100644 --- a/src/ship/items/apply_item.rs +++ b/src/ship/items/apply_item.rs @@ -109,7 +109,7 @@ where let mut inventory = item_state.inventory(&character.id)?; let (mag_entity_id, mag) = inventory.equipped_mag_mut() - .ok_or_else(|| ApplyItemError::ItemNotEquipped)?; + .ok_or(ApplyItemError::ItemNotEquipped)?; mag.apply_mag_cell(mag_cell_type)?; entity_gateway.use_mag_cell(&mag_entity_id, &cell_entity_id).await?; diff --git a/src/ship/items/state.rs b/src/ship/items/state.rs index dd39b83..4ff10d3 100644 --- a/src/ship/items/state.rs +++ b/src/ship/items/state.rs @@ -492,15 +492,6 @@ pub enum FloorItemDetail { Meseta(Meseta), } -impl FloorItemDetail { - fn stacked(&self) -> Option<&StackedItemDetail> { - match self { - FloorItemDetail::Stacked(sitem) => Some(sitem), - _ => None, - } - } -} - #[derive(Debug, Clone)] pub struct FloorItem { pub item_id: ClientItemId, @@ -767,7 +758,7 @@ impl InventoryState { Some(InventoryItem { item_id: ClientItemId(self.item_id_counter), item: InventoryItemDetail::Stacked(StackedItemDetail { - entity_ids: entity_ids, + entity_ids, tool: stacked_item.tool, })}) } @@ -870,7 +861,7 @@ impl InventoryState { .find(|(entity_id, _)| *entity_id == mag_id) } - pub fn sort(&mut self, item_ids: &Vec) { + pub fn sort(&mut self, item_ids: &[ClientItemId]) { self.inventory.0.sort_by(|a, b| { let a_index = item_ids.iter().position(|item_id| *item_id == a.item_id); let b_index = item_ids.iter().position(|item_id| *item_id == b.item_id); @@ -984,7 +975,7 @@ impl BankState { if self.meseta.0 + amount > 999999 { return Err(ItemStateError::FullOfMeseta) } - self.meseta.0 += self.meseta.0 + amount; + self.meseta.0 += amount; Ok(()) } @@ -1070,7 +1061,7 @@ impl BankState { Some(BankItem { item_id: ClientItemId(self.item_id_counter), item: BankItemDetail::Stacked(StackedItemDetail { - entity_ids: entity_ids, + entity_ids, tool: stacked_item.tool, })}) } @@ -1223,7 +1214,7 @@ impl FloorState { InventoryItemDetail::Individual(individual_item) => FloorItemDetail::Individual(individual_item), InventoryItemDetail::Stacked(stacked_item) => FloorItemDetail::Stacked(stacked_item), }, - map_area: map_area, + map_area, x: position.0, y: position.1, z: position.2, @@ -1271,13 +1262,13 @@ impl Default for ItemState { impl ItemState { pub fn get_character_inventory(&self, character: &CharacterEntity) -> Result<&InventoryState, ItemStateError> { - Ok(self.character_inventory.get(&character.id) - .ok_or(ItemStateError::NoCharacter(character.id))?) + self.character_inventory.get(&character.id) + .ok_or(ItemStateError::NoCharacter(character.id)) } pub fn get_character_bank(&self, character: &CharacterEntity) -> Result<&BankState, ItemStateError> { - Ok(self.character_bank.get(&character.id) - .ok_or(ItemStateError::NoCharacter(character.id))?) + self.character_bank.get(&character.id) + .ok_or(ItemStateError::NoCharacter(character.id)) } } @@ -1327,7 +1318,7 @@ impl ItemState { character_id: character.id, item_id_counter: 0, inventory: Inventory(inventory_items), - equipped: equipped, + equipped, meseta: character_meseta, }; @@ -1408,7 +1399,7 @@ impl ItemState { .find(|item| item.item_id == *item_id) .map(|item| (item, FloorType::Shared)) }) - .ok_or_else(|| ItemStateError::NoFloorItem(*item_id)) + .ok_or(ItemStateError::NoFloorItem(*item_id)) } } diff --git a/src/ship/location.rs b/src/ship/location.rs index efba55f..f4a1433 100644 --- a/src/ship/location.rs +++ b/src/ship/location.rs @@ -12,7 +12,7 @@ pub enum AreaType { } -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct LobbyId(pub usize); #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, derive_more::Display)] @@ -25,7 +25,7 @@ impl LobbyId { } -#[derive(Error, Debug, PartialEq)] +#[derive(Error, Debug, PartialEq, Eq)] #[error("create room")] pub enum CreateRoomError { NoOpenSlots, @@ -33,7 +33,7 @@ pub enum CreateRoomError { JoinError, } -#[derive(Error, Debug, PartialEq)] +#[derive(Error, Debug, PartialEq, Eq)] #[error("join room")] pub enum JoinRoomError { RoomDoesNotExist, @@ -41,7 +41,7 @@ pub enum JoinRoomError { ClientInAreaAlready, } -#[derive(Error, Debug, PartialEq)] +#[derive(Error, Debug, PartialEq, Eq)] #[error("join lobby")] pub enum JoinLobbyError { LobbyDoesNotExist, @@ -49,7 +49,7 @@ pub enum JoinLobbyError { ClientInAreaAlready, } -#[derive(Error, Debug, PartialEq)] +#[derive(Error, Debug, PartialEq, Eq)] #[error("get area")] pub enum GetAreaError { NotInRoom, @@ -57,28 +57,28 @@ pub enum GetAreaError { InvalidClient, } -#[derive(Error, Debug, PartialEq)] +#[derive(Error, Debug, PartialEq, Eq)] #[error("client removal")] pub enum ClientRemovalError { ClientNotInArea, InvalidArea, } -#[derive(Error, Debug, PartialEq)] +#[derive(Error, Debug, PartialEq, Eq)] #[error("get clients")] pub enum GetClientsError { InvalidClient, InvalidArea, } -#[derive(Error, Debug, PartialEq)] +#[derive(Error, Debug, PartialEq, Eq)] #[error("get neighbor")] pub enum GetNeighborError { InvalidClient, InvalidArea, } -#[derive(Error, Debug, PartialEq)] +#[derive(Error, Debug, PartialEq, Eq)] #[error("get leader")] pub enum GetLeaderError { InvalidClient, @@ -86,7 +86,7 @@ pub enum GetLeaderError { NoClientInArea, } -#[derive(Error, Debug, PartialEq)] +#[derive(Error, Debug, PartialEq, Eq)] #[error("clientlocation")] pub enum ClientLocationError { CreateRoomError(#[from] CreateRoomError), @@ -100,7 +100,7 @@ pub enum ClientLocationError { } -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct LocalClientId(usize); impl LocalClientId { @@ -115,19 +115,19 @@ impl PartialEq for LocalClientId { } } -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct AreaClient { pub client: ClientId, pub local_client: LocalClientId, time_join: SystemTime, } -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] struct Lobby([Option; 12]); -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] struct Room([Option; 4]); -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum RoomLobby { Room(RoomId), Lobby(LobbyId), diff --git a/src/ship/map/area.rs b/src/ship/map/area.rs index 3eaa06b..eb6bb68 100644 --- a/src/ship/map/area.rs +++ b/src/ship/map/area.rs @@ -5,7 +5,7 @@ use thiserror::Error; use crate::ship::room::Episode; use std::fmt; -#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum MapArea { Pioneer2Ep1, Forest1, diff --git a/src/ship/map/variant.rs b/src/ship/map/variant.rs index 819bcdb..0fa7c65 100644 --- a/src/ship/map/variant.rs +++ b/src/ship/map/variant.rs @@ -5,7 +5,7 @@ use rand::Rng; // TODO: don't use * use crate::ship::map::*; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum MapVariantMode { Online, Offline, diff --git a/src/ship/packet/handler/direct_message.rs b/src/ship/packet/handler/direct_message.rs index 79ed06d..9bb04bd 100644 --- a/src/ship/packet/handler/direct_message.rs +++ b/src/ship/packet/handler/direct_message.rs @@ -24,15 +24,11 @@ const SHOP_OPTION_TOOL: u8 = 0; const SHOP_OPTION_WEAPON: u8 = 1; const SHOP_OPTION_ARMOR: u8 = 2; -const INVENTORY_MESETA_CAPACITY: u32 = 999999; -const BANK_MESETA_CAPACITY: u32 = 999999; - -//const BANK_ACTION_: u8 = 1; - #[derive(thiserror::Error, Debug)] -#[error("")] pub enum MessageError { + #[error("invalid tek {0}")] InvalidTek(ClientItemId), + #[error("mismatched tek {0} {1}")] MismatchedTekIds(ClientItemId, ClientItemId), } @@ -158,7 +154,7 @@ where }; //match item_manager.character_picks_up_item(entity_gateway, &mut client.character, ClientItemId(pickup_item.item_id)).await { - match pick_up_item(item_state, entity_gateway, &mut client.character, &ClientItemId(pickup_item.item_id)).await { + match pick_up_item(item_state, entity_gateway, &client.character, &ClientItemId(pickup_item.item_id)).await { Ok(trigger_create_item) => { let remove_packets: Box + Send> = match floor_type { FloorType::Local => { @@ -374,7 +370,7 @@ where } }; - let inventory_item = buy_shop_item(item_state, entity_gateway, &mut client.character, item, ClientItemId(buy_item.item_id), buy_item.amount as u32).await?; + let inventory_item = buy_shop_item(item_state, entity_gateway, &client.character, item, ClientItemId(buy_item.item_id), buy_item.amount as u32).await?; let create = builder::message::create_withdrawn_inventory_item(area_client, &inventory_item)?; if remove { @@ -432,11 +428,10 @@ where let inventory = item_state.get_character_inventory(&client.character)?; let item = inventory.get_by_client_id(&ClientItemId(tek_request.item_id)) .ok_or(ItemStateError::WrongItemType(ClientItemId(tek_request.item_id)))?; - let mut weapon = item.item.as_individual() + let mut weapon = *item.item.as_individual() .ok_or(ItemStateError::WrongItemType(ClientItemId(tek_request.item_id)))? .as_weapon() - .ok_or(ItemStateError::WrongItemType(ClientItemId(tek_request.item_id)))? - .clone(); + .ok_or(ItemStateError::WrongItemType(ClientItemId(tek_request.item_id)))?; weapon.apply_modifier(&item::weapon::WeaponModifier::Tekked { special: special_mod, diff --git a/src/ship/packet/handler/trade.rs b/src/ship/packet/handler/trade.rs index b6b9faa..60b05c3 100644 --- a/src/ship/packet/handler/trade.rs +++ b/src/ship/packet/handler/trade.rs @@ -10,10 +10,8 @@ use crate::ship::trade::{TradeItem, TradeState, TradeStatus}; use crate::entity::gateway::EntityGateway; use crate::ship::packet::builder; use crate::ship::items::actions::trade_items; -use crate::entity::item::ItemDetail; -use crate::entity::item::tool::Tool; -use crate::ship::location::AreaClient; -use crate::entity::item::{Meseta, ItemNote}; +use crate::ship::location::{AreaClient, RoomId}; +use crate::entity::item::Meseta; pub const MESETA_ITEM_ID: ClientItemId = ClientItemId(0xFFFFFF01); pub const OTHER_MESETA_ITEM_ID: ClientItemId = ClientItemId(0xFFFFFFFF); @@ -441,9 +439,9 @@ where { enum TradeReady<'a> { OnePlayer, - BothPlayers(crate::ship::location::RoomId, - (crate::ship::location::AreaClient, &'a crate::ship::ship::ClientState, crate::ship::trade::ClientTradeState), - (crate::ship::location::AreaClient, &'a crate::ship::ship::ClientState, crate::ship::trade::ClientTradeState)), + BothPlayers(RoomId, + (AreaClient, &'a crate::ship::ship::ClientState, crate::ship::trade::ClientTradeState), + (AreaClient, &'a crate::ship::ship::ClientState, crate::ship::trade::ClientTradeState)), } let trade_instructions = trades @@ -476,7 +474,7 @@ where TradeReady::OnePlayer => { Ok(Box::new(None.into_iter()) as Box + Send>) }, - TradeReady::BothPlayers(room_id, (this_local_client, this_client, this), (other_local_client, other_client, other)) => { + TradeReady::BothPlayers(_room_id, (this_local_client, this_client, this), (other_local_client, other_client, other)) => { let remove_item_packets = this.items .clone() .into_iter() @@ -495,7 +493,6 @@ where let (this_new_items, other_new_items) = trade_items(item_state, entity_gateway, - room_id, (&this_local_client, &this_client.character, &this.items, Meseta(this.meseta as u32)), (&other_local_client, &other_client.character, &other.items, Meseta(other.meseta as u32))).await?;