diff --git a/src/ship/items/bank.rs b/src/ship/items/bank.rs index 2a91755..b130a79 100644 --- a/src/ship/items/bank.rs +++ b/src/ship/items/bank.rs @@ -1,19 +1,7 @@ use crate::ship::items::ClientItemId; -use std::collections::{HashMap, BTreeMap, BinaryHeap}; -use std::cmp::{Ordering, PartialOrd, PartialEq}; -use thiserror::Error; -use futures::future::join_all; use libpso::character::character;//::InventoryItem; -use crate::entity::gateway::EntityGateway; -use crate::entity::character::{CharacterEntity, CharacterEntityId}; -use crate::entity::item::{ItemEntityId, ItemEntity, ItemDetail, ItemLocation, BankName}; -use crate::entity::item::{Meseta, NewItemEntity}; -use crate::entity::item::tool::{Tool, ToolType}; -use crate::ship::map::MapArea; -use crate::ship::ship::ItemDropLocation; -use crate::ship::drops::{ItemDrop, ItemDropType}; -use crate::ship::location::{AreaClient, RoomId}; - +use crate::entity::item::{ItemEntityId, ItemDetail}; +use crate::entity::item::tool::Tool; #[derive(Debug, Clone)] pub struct IndividualBankItem { diff --git a/src/ship/items/floor.rs b/src/ship/items/floor.rs index b74ae7b..80bc582 100644 --- a/src/ship/items/floor.rs +++ b/src/ship/items/floor.rs @@ -1,18 +1,8 @@ use crate::ship::items::ClientItemId; -use std::collections::{HashMap, BTreeMap, BinaryHeap}; -use std::cmp::{Ordering, PartialOrd, PartialEq}; -use thiserror::Error; -use futures::future::join_all; -use libpso::character::character;//::InventoryItem; -use crate::entity::gateway::EntityGateway; -use crate::entity::character::{CharacterEntity, CharacterEntityId}; -use crate::entity::item::{ItemEntityId, ItemEntity, ItemDetail, ItemLocation, BankName}; -use crate::entity::item::{Meseta, NewItemEntity}; -use crate::entity::item::tool::{Tool, ToolType}; +use crate::entity::item::{ItemEntityId, ItemDetail}; +use crate::entity::item::Meseta; +use crate::entity::item::tool::Tool; use crate::ship::map::MapArea; -use crate::ship::ship::ItemDropLocation; -use crate::ship::drops::{ItemDrop, ItemDropType}; -use crate::ship::location::{AreaClient, RoomId}; use crate::ship::items::inventory::{IndividualInventoryItem, StackedInventoryItem, InventoryItemHandle}; diff --git a/src/ship/items/inventory.rs b/src/ship/items/inventory.rs index 84fe1f3..c831dcf 100644 --- a/src/ship/items/inventory.rs +++ b/src/ship/items/inventory.rs @@ -1,17 +1,8 @@ -use std::collections::{HashMap, BTreeMap, BinaryHeap}; -use std::cmp::{Ordering, PartialOrd, PartialEq}; +use std::cmp::Ordering; use thiserror::Error; -use futures::future::join_all; use libpso::character::character;//::InventoryItem; -use crate::entity::gateway::EntityGateway; -use crate::entity::character::{CharacterEntity, CharacterEntityId}; -use crate::entity::item::{ItemEntityId, ItemEntity, ItemDetail, ItemLocation, BankName}; -use crate::entity::item::{Meseta, NewItemEntity}; -use crate::entity::item::tool::{Tool, ToolType}; -use crate::ship::map::MapArea; -use crate::ship::ship::ItemDropLocation; -use crate::ship::drops::{ItemDrop, ItemDropType}; -use crate::ship::location::{AreaClient, RoomId}; +use crate::entity::item::{ItemEntityId, ItemDetail}; +use crate::entity::item::tool::Tool; use crate::ship::items::ClientItemId; use crate::ship::items::floor::{IndividualFloorItem, StackedFloorItem}; @@ -316,13 +307,6 @@ impl CharacterInventory { .nth(0) } - pub fn take_stacked_item_by_id(&mut self, item_id: ClientItemId, amount: usize) -> Option { - // TODO: amount? - self.0 - .drain_filter(|i| i.item_id() == item_id) - .nth(0) - } - pub fn add_item(&mut self, item: InventoryItem) -> Result<(), ()> { // TODO: errors // TODO: check slot conflict? self.0.push(item); @@ -364,7 +348,7 @@ impl CharacterInventory { if let Some(existing_stack_position) = existing_stack_position { if let Some(InventoryItem::Stacked(stacked_item)) = self.0.get_mut(existing_stack_position) { - if (stacked_item.count() + floor_item.count() <= stacked_item.tool.max_stack()) { + if stacked_item.count() + floor_item.count() <= stacked_item.tool.max_stack() { stacked_item.entity_ids.append(&mut floor_item.entity_ids.clone()); Some((stacked_item, InventorySlot(existing_stack_position))) } diff --git a/src/ship/items/manager.rs b/src/ship/items/manager.rs index 7f3a4a4..b51afce 100644 --- a/src/ship/items/manager.rs +++ b/src/ship/items/manager.rs @@ -1,14 +1,11 @@ use crate::ship::items::ClientItemId; -use std::collections::{HashMap, BTreeMap, BinaryHeap}; -use std::cmp::{Ordering, PartialOrd, PartialEq}; +use std::collections::{HashMap, BTreeMap}; use thiserror::Error; -use futures::future::join_all; -use libpso::character::character;//::InventoryItem; use crate::entity::gateway::EntityGateway; use crate::entity::character::{CharacterEntity, CharacterEntityId}; -use crate::entity::item::{ItemEntityId, ItemEntity, ItemDetail, ItemLocation, BankName}; +use crate::entity::item::{ItemDetail, ItemLocation, BankName}; use crate::entity::item::{Meseta, NewItemEntity}; -use crate::entity::item::tool::{Tool, ToolType}; +use crate::entity::item::tool::Tool; use crate::ship::map::MapArea; use crate::ship::ship::ItemDropLocation; use crate::ship::drops::{ItemDrop, ItemDropType}; @@ -117,7 +114,7 @@ impl ItemManager { }) .into_iter() .map(|(bank_name, bank_items)| { - let mut stacked_bank_items = bank_items.into_iter() + let stacked_bank_items = bank_items.into_iter() .fold(Vec::new(), |mut acc, (id, bank_item)| { if bank_item.is_stackable() { let existing_item = acc.iter_mut() @@ -163,7 +160,7 @@ impl ItemManager { self.character_inventory.insert(character.id, inventory); self.character_bank.insert(character.id, bank_items); } - + 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(); @@ -216,7 +213,7 @@ impl ItemManager { 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) .or_else(|| { shared_floor.get_item_by_id(item_id) @@ -302,7 +299,7 @@ impl ItemManager { floor_item.remove_from_floor(); Ok(trigger_create_item) } - + pub async fn enemy_drop_item_on_local_floor(&mut self, entity_gateway: &mut EG, character: &CharacterEntity, item_drop: ItemDrop) -> Result<&FloorItem, ItemManagerError> { let room_id = self.character_room.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; @@ -382,7 +379,7 @@ impl ItemManager { }) }, }; - + self.character_floor.entry(character.id).or_insert(RoomFloorItems::new()).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(ItemManagerError::Idunnoman) @@ -513,20 +510,20 @@ impl ItemManager { } pub async fn player_deposits_item(&mut self, - entity_gateway: &mut EG, - character: &CharacterEntity, - item_id: ClientItemId, - amount: usize) + _entity_gateway: &mut EG, + _character: &CharacterEntity, + _item_id: ClientItemId, + _amount: usize) -> Result<(), ItemManagerError> { Ok(()) } pub async fn player_withdraws_item(&mut self, - entity_gateway: &mut EG, - character: &CharacterEntity, - item_id: ClientItemId, - amount: usize) - -> Result<(), ItemManagerError> { + _entity_gateway: &mut EG, + _character: &CharacterEntity, + _item_id: ClientItemId, + _amount: usize) + -> Result<(), ItemManagerError> { Ok(()) } } diff --git a/src/ship/items/mod.rs b/src/ship/items/mod.rs index 00d1667..08150f2 100644 --- a/src/ship/items/mod.rs +++ b/src/ship/items/mod.rs @@ -6,8 +6,7 @@ mod manager; #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct ClientItemId(pub u32); -//pub use inventory::InventoryItem; -//pub use floor::FloorItem; +// TODO: remove these and fix use statements in the rest of the codebase pub use inventory::*; pub use floor::*; pub use bank::*; diff --git a/src/ship/packet/builder/message.rs b/src/ship/packet/builder/message.rs index 33c1c89..1fc85da 100644 --- a/src/ship/packet/builder/message.rs +++ b/src/ship/packet/builder/message.rs @@ -1,4 +1,3 @@ -use libpso::character::character; use libpso::packet::messages::*; use libpso::packet::ship::*; use crate::common::leveltable::CharacterStats; diff --git a/src/ship/packet/handler/message.rs b/src/ship/packet/handler/message.rs index 7467783..87fb505 100644 --- a/src/ship/packet/handler/message.rs +++ b/src/ship/packet/handler/message.rs @@ -8,7 +8,7 @@ use crate::common::leveltable::CharacterLevelTable; use crate::ship::ship::{SendShipPacket, ShipError, Rooms, Clients, ItemDropLocation}; use crate::ship::location::{ClientLocation, ClientLocationError}; use crate::ship::map::{MapArea}; -use crate::ship::items::{ItemManager, ClientItemId, InventoryItem}; +use crate::ship::items::{ItemManager, ClientItemId}; use crate::ship::packet::builder; pub async fn request_exp(id: ClientId, @@ -214,7 +214,7 @@ where pub async fn use_item(id: ClientId, player_use_tool: &PlayerUseItem, entity_gateway: &mut EG, - client_location: &ClientLocation, + _client_location: &ClientLocation, clients: &mut Clients, item_manager: &mut ItemManager) -> Result + Send>, ShipError> diff --git a/tests/common.rs b/tests/common.rs index c6a4736..693f1f8 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -1,4 +1,4 @@ -#[allow(dead_code)] +#![allow(dead_code)] use std::time::SystemTime; use elseware::common::serverstate::{ClientId, ServerState}; diff --git a/tests/test_bank.rs b/tests/test_bank.rs index 5caa545..c355ef2 100644 --- a/tests/test_bank.rs +++ b/tests/test_bank.rs @@ -2,7 +2,6 @@ use elseware::common::serverstate::{ClientId, ServerState}; use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; use elseware::entity::item; use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket}; -use elseware::ship::items::{ClientItemId}; use libpso::packet::ship::*; use libpso::packet::messages::*; diff --git a/tests/test_item_pickup.rs b/tests/test_item_pickup.rs index acdb9b7..4e70915 100644 --- a/tests/test_item_pickup.rs +++ b/tests/test_item_pickup.rs @@ -2,7 +2,6 @@ use elseware::common::serverstate::{ClientId, ServerState}; use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; use elseware::entity::item; use elseware::ship::ship::{ShipServerState, RecvShipPacket}; -use elseware::ship::items::{ClientItemId}; use libpso::packet::ship::*; use libpso::packet::messages::*;