From ebdd4b28dea914e447a0e1c061b3648e8b49738e Mon Sep 17 00:00:00 2001 From: jake Date: Sat, 5 Sep 2020 22:06:39 -0600 Subject: [PATCH] actually this makes more sense --- src/ship/items/manager.rs | 44 +++++++++++++++++++++++++++++- src/ship/items/use_tool.rs | 7 ++++- src/ship/packet/handler/message.rs | 37 +------------------------ 3 files changed, 50 insertions(+), 38 deletions(-) diff --git a/src/ship/items/manager.rs b/src/ship/items/manager.rs index 276e433..9537bb4 100644 --- a/src/ship/items/manager.rs +++ b/src/ship/items/manager.rs @@ -5,7 +5,7 @@ use crate::entity::gateway::EntityGateway; use crate::entity::character::{CharacterEntity, CharacterEntityId}; use crate::entity::item::{ItemDetail, ItemLocation, BankName}; use crate::entity::item::{Meseta, NewItemEntity}; -use crate::entity::item::tool::Tool; +use crate::entity::item::tool::{Tool, ToolType}; use crate::ship::map::MapArea; use crate::ship::ship::ItemDropLocation; use crate::ship::drops::{ItemDrop, ItemDropType}; @@ -14,6 +14,7 @@ use crate::ship::location::{AreaClient, RoomId}; use crate::ship::items::bank::*; use crate::ship::items::floor::*; use crate::ship::items::inventory::*; +use crate::ship::items::use_tool; pub enum TriggerCreateItem { @@ -636,4 +637,45 @@ impl ItemManager { Ok(()) } + + + pub async fn use_item(&mut self, + used_item: ItemDetail, + entity_gateway: &mut EG, + character: &mut CharacterEntity) -> Result<(), ItemManagerError> { + match used_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; + }, + _ => {} + } + } + _ => {} + } + Ok(()) + } } diff --git a/src/ship/items/use_tool.rs b/src/ship/items/use_tool.rs index 59e157b..30a016e 100644 --- a/src/ship/items/use_tool.rs +++ b/src/ship/items/use_tool.rs @@ -1,3 +1,4 @@ +use thiserror::Error; use crate::entity::gateway::EntityGateway; use crate::entity::character::CharacterEntity; use crate::entity::item::ItemDetail; @@ -7,7 +8,11 @@ use crate::entity::item::tool::ToolType; - +#[derive(Error, Debug)] +#[error("")] +pub enum UseItemError { + NoCharacter, +} diff --git a/src/ship/packet/handler/message.rs b/src/ship/packet/handler/message.rs index 4f28e0e..0307993 100644 --- a/src/ship/packet/handler/message.rs +++ b/src/ship/packet/handler/message.rs @@ -10,7 +10,6 @@ use crate::ship::location::{ClientLocation, ClientLocationError}; use crate::ship::map::{MapArea}; use crate::ship::items::{ItemManager, ClientItemId}; use crate::ship::packet::builder; -use crate::ship::items::use_tool; pub async fn request_exp(id: ClientId, request_exp: &RequestExp, @@ -264,43 +263,9 @@ where EG: EntityGateway { let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?; - let item_used_type = item_manager.player_consumes_tool(entity_gateway, &client.character, ClientItemId(player_use_tool.item_id), 1).await?; - match item_used_type { - 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, &mut client.character).await; - }, - ToolType::MindMaterial => { - use_tool::mind_material(entity_gateway, &mut client.character).await; - }, - ToolType::EvadeMaterial => { - use_tool::evade_material(entity_gateway, &mut client.character).await; - }, - ToolType::DefMaterial => { - use_tool::def_material(entity_gateway, &mut client.character).await; - }, - ToolType::LuckMaterial => { - use_tool::luck_material(entity_gateway, &mut client.character).await; - }, - ToolType::HpMaterial => { - use_tool::hp_material(entity_gateway, &mut client.character).await; - }, - ToolType::TpMaterial => { - use_tool::tp_material(entity_gateway, &mut client.character).await; - }, - _ => {} - } - } - _ => {} - } - + item_manager.use_item(item_used_type, entity_gateway, &mut client.character).await?; Ok(Box::new(None.into_iter())) }