From 23bc39b5bf5f9dd1c5aaf2d71a4cedb9503ae9cb Mon Sep 17 00:00:00 2001 From: jake Date: Sat, 5 Sep 2020 21:10:12 -0600 Subject: [PATCH] move tool usage logic into own file --- src/ship/items/mod.rs | 1 + src/ship/items/use_tool.rs | 51 ++++++++++++++++++++++++++++++ src/ship/packet/handler/message.rs | 22 +++++-------- 3 files changed, 60 insertions(+), 14 deletions(-) create mode 100644 src/ship/items/use_tool.rs diff --git a/src/ship/items/mod.rs b/src/ship/items/mod.rs index 08150f2..3268b04 100644 --- a/src/ship/items/mod.rs +++ b/src/ship/items/mod.rs @@ -2,6 +2,7 @@ mod bank; mod floor; mod inventory; mod manager; +pub mod use_tool; #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct ClientItemId(pub u32); diff --git a/src/ship/items/use_tool.rs b/src/ship/items/use_tool.rs new file mode 100644 index 0000000..59e157b --- /dev/null +++ b/src/ship/items/use_tool.rs @@ -0,0 +1,51 @@ +use crate::entity::gateway::EntityGateway; +use crate::entity::character::CharacterEntity; +use crate::entity::item::ItemDetail; +use crate::entity::item::tool::ToolType; + + + + + + + + + + + +//pub fn use_tool() + +pub async fn power_material(entity_gateway: &mut EG, character: &mut CharacterEntity) { + character.materials.power += 1; + entity_gateway.save_character(character).await; +} + +pub async fn mind_material(entity_gateway: &mut EG, character: &mut CharacterEntity) { + character.materials.mind += 1; + entity_gateway.save_character(character).await; +} + +pub async fn evade_material(entity_gateway: &mut EG, character: &mut CharacterEntity) { + character.materials.evade += 1; + entity_gateway.save_character(character).await; +} + +pub async fn def_material(entity_gateway: &mut EG, character: &mut CharacterEntity) { + character.materials.def += 1; + entity_gateway.save_character(character).await; +} + +pub async fn luck_material(entity_gateway: &mut EG, character: &mut CharacterEntity) { + character.materials.luck += 1; + entity_gateway.save_character(character).await; +} + +pub async fn hp_material(entity_gateway: &mut EG, character: &mut CharacterEntity) { + character.materials.hp += 1; + entity_gateway.save_character(character).await; +} + +pub async fn tp_material(entity_gateway: &mut EG, character: &mut CharacterEntity) { + character.materials.tp += 1; + entity_gateway.save_character(character).await; +} diff --git a/src/ship/packet/handler/message.rs b/src/ship/packet/handler/message.rs index 09bdd0e..4f28e0e 100644 --- a/src/ship/packet/handler/message.rs +++ b/src/ship/packet/handler/message.rs @@ -10,6 +10,7 @@ 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, @@ -274,32 +275,25 @@ where ItemDetail::Tool(t) => { match t.tool { ToolType::PowerMaterial => { - client.character.materials.power += 1; - entity_gateway.save_character(&client.character).await; + use_tool::power_material(entity_gateway, &mut client.character).await; }, ToolType::MindMaterial => { - client.character.materials.mind += 1; - entity_gateway.save_character(&client.character).await; + use_tool::mind_material(entity_gateway, &mut client.character).await; }, ToolType::EvadeMaterial => { - client.character.materials.evade += 1; - entity_gateway.save_character(&client.character).await; + use_tool::evade_material(entity_gateway, &mut client.character).await; }, ToolType::DefMaterial => { - client.character.materials.def += 1; - entity_gateway.save_character(&client.character).await; + use_tool::def_material(entity_gateway, &mut client.character).await; }, ToolType::LuckMaterial => { - client.character.materials.luck += 1; - entity_gateway.save_character(&client.character).await; + use_tool::luck_material(entity_gateway, &mut client.character).await; }, ToolType::HpMaterial => { - client.character.materials.hp += 1; - entity_gateway.save_character(&client.character).await; + use_tool::hp_material(entity_gateway, &mut client.character).await; }, ToolType::TpMaterial => { - client.character.materials.tp += 1; - entity_gateway.save_character(&client.character).await; + use_tool::tp_material(entity_gateway, &mut client.character).await; }, _ => {} }