|
|
@ -4,7 +4,7 @@ use thiserror::Error; |
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
|
use crate::entity::character::{CharacterEntity, CharacterEntityId, TechLevel};
|
|
|
|
use crate::entity::item::{ItemDetail, ItemLocation, BankName};
|
|
|
|
use crate::entity::item::{Meseta, NewItemEntity, ItemEntity, InventoryItemEntity, EquippedEntity, InventoryEntity, BankItemEntity, BankEntity};
|
|
|
|
use crate::entity::item::{Meseta, NewItemEntity, ItemEntity, InventoryItemEntity, EquippedEntity, InventoryEntity, BankItemEntity, BankEntity, ItemType};
|
|
|
|
use crate::entity::item::tool::{Tool, ToolType};
|
|
|
|
use crate::entity::item::unit;
|
|
|
|
use crate::entity::item::weapon;
|
|
|
@ -636,114 +636,141 @@ impl ItemManager { |
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn use_item<EG: EntityGateway>(&mut self,
|
|
|
|
used_item: ConsumedItem,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
character: &mut CharacterEntity) -> Result<(), anyhow::Error> {
|
|
|
|
character: &mut CharacterEntity,
|
|
|
|
client_item_id: ClientItemId) -> Result<(), anyhow::Error> {
|
|
|
|
// println!("manager::use_item(): ClientItemId: {:?}", client_item_id);
|
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
match &used_item.item() {
|
|
|
|
ItemDetail::Weapon(_w) => {
|
|
|
|
// something like when items are used to combine/transform them?
|
|
|
|
//_ => {}
|
|
|
|
|
|
|
|
let mut used_item_handle = inventory.get_item_handle_by_id(client_item_id).ok_or(ItemManagerError::ItemIdNotInInventory(client_item_id))?;
|
|
|
|
let used_item = used_item_handle.item_mut().ok_or(ItemManagerError::CannotGetMutItem)?;
|
|
|
|
match used_item.item_type() {
|
|
|
|
ItemType::Armor(_) => {
|
|
|
|
|
|
|
|
},
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
ToolType::CellOfMag502 => {
|
|
|
|
use_tool::cell_of_mag_502(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::CellOfMag213 => {
|
|
|
|
use_tool::cell_of_mag_213(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::PartsOfRobochao => {
|
|
|
|
use_tool::parts_of_robochao(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::HeartOfOpaOpa => {
|
|
|
|
use_tool::heart_of_opaopa(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::HeartOfPian => {
|
|
|
|
use_tool::heart_of_pian(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::HeartOfChao=> {
|
|
|
|
use_tool::heart_of_chao(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::HeartOfAngel => {
|
|
|
|
use_tool::heart_of_angel(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::KitOfHamburger => {
|
|
|
|
use_tool::kit_of_hamburger(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::PanthersSpirit => {
|
|
|
|
use_tool::panthers_spirit(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::KitOfMark3 => {
|
|
|
|
use_tool::kit_of_mark3(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::KitOfMasterSystem=> {
|
|
|
|
use_tool::kit_of_master_system(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::KitOfGenesis => {
|
|
|
|
use_tool::kit_of_genesis(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::KitOfSegaSaturn => {
|
|
|
|
use_tool::kit_of_sega_saturn(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::KitOfDreamcast => {
|
|
|
|
use_tool::kit_of_dreamcast(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::Tablet => {
|
|
|
|
use_tool::tablet(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::DragonScale => {
|
|
|
|
use_tool::dragon_scale(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::HeavenStrikerCoat => {
|
|
|
|
use_tool::heaven_striker_coat(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::PioneerParts => {
|
|
|
|
use_tool::pioneer_parts(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::AmitiesMemo => {
|
|
|
|
use_tool::amities_memo(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::HeartOfMorolian => {
|
|
|
|
use_tool::heart_of_morolian(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::RappysBeak => {
|
|
|
|
use_tool::rappys_beak(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::YahoosEngine => {
|
|
|
|
use_tool::yahoos_engine(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::DPhotonCore => {
|
|
|
|
use_tool::d_photon_core(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::LibertaKit => {
|
|
|
|
use_tool::liberta_kit(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ItemType::ESWeapon(_) => {
|
|
|
|
|
|
|
|
},
|
|
|
|
ItemType::Mag(_) => {
|
|
|
|
|
|
|
|
},
|
|
|
|
ItemType::Shield(_) => {
|
|
|
|
|
|
|
|
},
|
|
|
|
ItemType::TechniqueDisk(_) => {
|
|
|
|
|
|
|
|
},
|
|
|
|
ItemType::Tool(_) => {
|
|
|
|
let consumed_item = used_item.as_consumed_item();
|
|
|
|
match &used_item.item_detail() {
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
ToolType::CellOfMag502 => {
|
|
|
|
use_tool::cell_of_mag_502(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::CellOfMag213 => {
|
|
|
|
use_tool::cell_of_mag_213(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::PartsOfRobochao => {
|
|
|
|
use_tool::parts_of_robochao(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::HeartOfOpaOpa => {
|
|
|
|
use_tool::heart_of_opaopa(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::HeartOfPian => {
|
|
|
|
use_tool::heart_of_pian(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::HeartOfChao=> {
|
|
|
|
use_tool::heart_of_chao(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::HeartOfAngel => {
|
|
|
|
use_tool::heart_of_angel(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::KitOfHamburger => {
|
|
|
|
use_tool::kit_of_hamburger(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::PanthersSpirit => {
|
|
|
|
use_tool::panthers_spirit(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::KitOfMark3 => {
|
|
|
|
use_tool::kit_of_mark3(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::KitOfMasterSystem=> {
|
|
|
|
use_tool::kit_of_master_system(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::KitOfGenesis => {
|
|
|
|
use_tool::kit_of_genesis(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::KitOfSegaSaturn => {
|
|
|
|
use_tool::kit_of_sega_saturn(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::KitOfDreamcast => {
|
|
|
|
use_tool::kit_of_dreamcast(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::Tablet => {
|
|
|
|
use_tool::tablet(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::DragonScale => {
|
|
|
|
use_tool::dragon_scale(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::HeavenStrikerCoat => {
|
|
|
|
use_tool::heaven_striker_coat(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::PioneerParts => {
|
|
|
|
use_tool::pioneer_parts(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::AmitiesMemo => {
|
|
|
|
use_tool::amities_memo(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::HeartOfMorolian => {
|
|
|
|
use_tool::heart_of_morolian(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::RappysBeak => {
|
|
|
|
use_tool::rappys_beak(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::YahoosEngine => {
|
|
|
|
use_tool::yahoos_engine(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::DPhotonCore => {
|
|
|
|
use_tool::d_photon_core(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
ToolType::LibertaKit => {
|
|
|
|
use_tool::liberta_kit(entity_gateway, &consumed_item, inventory).await?;
|
|
|
|
},
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
},
|
|
|
|
ItemType::Unit(_) => {
|
|
|
|
|
|
|
|
},
|
|
|
|
ItemType::Weapon(_) => {
|
|
|
|
let actual_used_item = used_item.individual_mut().ok_or(ItemManagerError::CannotGetMutItem)?.weapon_mut().ok_or(ItemManagerError::CannotGetMutItem)?;
|
|
|
|
actual_used_item.unwrap_present();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
|
|
|
|
Ok(())
|
|
|
@ -923,4 +950,10 @@ impl ItemManager { |
|
|
|
|
|
|
|
Ok(weapon)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_inventory_item_by_id(&mut self, character: &CharacterEntity, item_id: ClientItemId) -> Result<&InventoryItem, anyhow::Error> {
|
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
println!("item_manager.get_inventory_item_by_id() inventory: {:?}", inventory);
|
|
|
|
Ok(inventory.get_item_by_id(item_id).ok_or(ItemManagerError::ItemIdNotInInventory(item_id))?)
|
|
|
|
}
|
|
|
|
}
|