move tool usage logic into own file
This commit is contained in:
		
							parent
							
								
									c3bf42d367
								
							
						
					
					
						commit
						23bc39b5bf
					
				@ -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);
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										51
									
								
								src/ship/items/use_tool.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								src/ship/items/use_tool.rs
									
									
									
									
									
										Normal file
									
								
							@ -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<EG: EntityGateway>(entity_gateway: &mut EG, character: &mut CharacterEntity) {
 | 
			
		||||
    character.materials.power += 1;
 | 
			
		||||
    entity_gateway.save_character(character).await;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub async fn mind_material<EG: EntityGateway>(entity_gateway: &mut EG, character: &mut CharacterEntity) {
 | 
			
		||||
    character.materials.mind += 1;
 | 
			
		||||
    entity_gateway.save_character(character).await;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub async fn evade_material<EG: EntityGateway>(entity_gateway: &mut EG, character: &mut CharacterEntity) {
 | 
			
		||||
    character.materials.evade += 1;
 | 
			
		||||
    entity_gateway.save_character(character).await;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub async fn def_material<EG: EntityGateway>(entity_gateway: &mut EG, character: &mut CharacterEntity) {
 | 
			
		||||
    character.materials.def += 1;
 | 
			
		||||
    entity_gateway.save_character(character).await;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub async fn luck_material<EG: EntityGateway>(entity_gateway: &mut EG, character: &mut CharacterEntity) {
 | 
			
		||||
    character.materials.luck += 1;
 | 
			
		||||
    entity_gateway.save_character(character).await;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub async fn hp_material<EG: EntityGateway>(entity_gateway: &mut EG, character: &mut CharacterEntity) {
 | 
			
		||||
    character.materials.hp += 1;
 | 
			
		||||
    entity_gateway.save_character(character).await;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub async fn tp_material<EG: EntityGateway>(entity_gateway: &mut EG, character: &mut CharacterEntity) {
 | 
			
		||||
    character.materials.tp += 1;
 | 
			
		||||
    entity_gateway.save_character(character).await;
 | 
			
		||||
}
 | 
			
		||||
@ -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<EG: EntityGateway>(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;
 | 
			
		||||
                },
 | 
			
		||||
                _ => {}
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user