2020-09-05 22:06:39 -06:00
|
|
|
use thiserror::Error;
|
2020-09-05 21:10:12 -06:00
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
|
use crate::entity::character::CharacterEntity;
|
2020-09-07 08:02:12 -06:00
|
|
|
use crate::entity::item::{ItemEntityId, ItemDetail};
|
2020-09-05 21:10:12 -06:00
|
|
|
use crate::entity::item::tool::ToolType;
|
2020-09-07 08:02:12 -06:00
|
|
|
use crate::entity::item::mag::MagCell;
|
|
|
|
use crate::ship::items::{ItemManager, ClientItemId, CharacterInventory, ConsumedItem};
|
2020-09-05 21:10:12 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-05 22:06:39 -06:00
|
|
|
#[derive(Error, Debug)]
|
|
|
|
#[error("")]
|
|
|
|
pub enum UseItemError {
|
|
|
|
NoCharacter,
|
2020-09-07 08:02:12 -06:00
|
|
|
ItemNotEquipped,
|
|
|
|
InvalidItem,
|
2020-09-05 22:06:39 -06:00
|
|
|
}
|
2020-09-05 21:10:12 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//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;
|
|
|
|
}
|
2020-09-07 08:02:12 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async fn mag_cell<EG: EntityGateway>(entity_gateway: &mut EG, used_cell: &ConsumedItem, inventory: &mut CharacterInventory, mag_cell_type: MagCell) -> Result<(), UseItemError> {
|
|
|
|
let mut mag_handle = inventory.get_equipped_mag_handle().ok_or(UseItemError::ItemNotEquipped)?;
|
|
|
|
let mag_item = mag_handle.item_mut()
|
|
|
|
.ok_or(UseItemError::InvalidItem)?;
|
|
|
|
let actual_mag = mag_item
|
|
|
|
.individual()
|
|
|
|
.ok_or(UseItemError::InvalidItem)?
|
|
|
|
.mag_mut()
|
|
|
|
.ok_or(UseItemError::InvalidItem)?;
|
|
|
|
actual_mag.apply_mag_cell(mag_cell_type);
|
|
|
|
for mag_entity_id in mag_item.entity_ids() {
|
|
|
|
for cell_entity_id in used_cell.entity_ids() {
|
|
|
|
entity_gateway.use_mag_cell(&mag_entity_id, &cell_entity_id).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn cell_of_mag_502<EG: EntityGateway>(entity_gateway: &mut EG, used_cell: &ConsumedItem, inventory: &mut CharacterInventory) -> Result<(), UseItemError> {
|
|
|
|
println!("used a 502!");
|
|
|
|
mag_cell(entity_gateway, used_cell, inventory, MagCell::CellOfMag502).await
|
|
|
|
}
|