Browse Source

fix warnings

pbs
jake 4 years ago
parent
commit
1474c91dcd
  1. 16
      src/ship/items/bank.rs
  2. 16
      src/ship/items/floor.rs
  3. 24
      src/ship/items/inventory.rs
  4. 37
      src/ship/items/manager.rs
  5. 3
      src/ship/items/mod.rs
  6. 1
      src/ship/packet/builder/message.rs
  7. 4
      src/ship/packet/handler/message.rs
  8. 2
      tests/common.rs
  9. 1
      tests/test_bank.rs
  10. 1
      tests/test_item_pickup.rs

16
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 {

16
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};

24
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<InventoryItem> {
// 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)))
}

37
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<EG: EntityGateway>(&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<EG: EntityGateway>(&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<EG: EntityGateway>(&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(())
}
}

3
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::*;

1
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;

4
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<EG: EntityGateway>(id: ClientId,
@ -214,7 +214,7 @@ where
pub async fn use_item<EG>(id: ClientId,
player_use_tool: &PlayerUseItem,
entity_gateway: &mut EG,
client_location: &ClientLocation,
_client_location: &ClientLocation,
clients: &mut Clients,
item_manager: &mut ItemManager)
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError>

2
tests/common.rs

@ -1,4 +1,4 @@
#[allow(dead_code)]
#![allow(dead_code)]
use std::time::SystemTime;
use elseware::common::serverstate::{ClientId, ServerState};

1
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::*;

1
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::*;

Loading…
Cancel
Save