|
@ -1,10 +1,12 @@ |
|
|
use thiserror::Error;
|
|
|
use thiserror::Error;
|
|
|
|
|
|
use std::convert::TryFrom;
|
|
|
|
|
|
use std::convert::TryInto;
|
|
|
use crate::entity::gateway::{EntityGateway, GatewayError};
|
|
|
use crate::entity::gateway::{EntityGateway, GatewayError};
|
|
|
use crate::entity::character::CharacterEntity;
|
|
|
use crate::entity::character::CharacterEntity;
|
|
|
use crate::entity::item::mag::MagCell;
|
|
|
|
|
|
|
|
|
use crate::entity::item::mag::{MagCell, MagCellError};
|
|
|
use crate::entity::item::tool::ToolType;
|
|
|
use crate::entity::item::tool::ToolType;
|
|
|
use crate::entity::item::ItemDetail;
|
|
|
|
|
|
use crate::ship::items::state::{ItemStateProxy, InventoryState, InventoryItem, InventoryItemDetail};
|
|
|
|
|
|
|
|
|
use crate::entity::item::{ItemDetail, ItemEntityId};
|
|
|
|
|
|
use crate::ship::items::state::{ItemStateProxy, InventoryState, InventoryItem, InventoryItemDetail, ItemStateError};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
|
|
#[derive(Error, Debug)]
|
|
@ -17,6 +19,18 @@ pub enum ApplyItemError { |
|
|
InvalidItem,
|
|
|
InvalidItem,
|
|
|
#[error("gateway error {0}")]
|
|
|
#[error("gateway error {0}")]
|
|
|
GatewayError(#[from] GatewayError),
|
|
|
GatewayError(#[from] GatewayError),
|
|
|
|
|
|
|
|
|
|
|
|
#[error("itemstate error {0}")]
|
|
|
|
|
|
ItemStateError(Box<ItemStateError>),
|
|
|
|
|
|
|
|
|
|
|
|
#[error("magcell error {0}")]
|
|
|
|
|
|
MagCellError(#[from] MagCellError),
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl From<ItemStateError> for ApplyItemError {
|
|
|
|
|
|
fn from(other: ItemStateError) -> ApplyItemError {
|
|
|
|
|
|
ApplyItemError::ItemStateError(Box::new(other))
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// TODO: make all these functions not-pub
|
|
|
// TODO: make all these functions not-pub
|
|
@ -81,9 +95,34 @@ async fn mag_cell<EG: EntityGateway>(entity_gateway: &mut EG, used_cell: &Consum |
|
|
|
|
|
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async fn mag_cell<'a, EG>(item_state: &mut ItemStateProxy<'a>,
|
|
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
|
|
character: &CharacterEntity,
|
|
|
|
|
|
cell_entity_id: ItemEntityId,
|
|
|
|
|
|
mag_cell_type: MagCell)
|
|
|
|
|
|
-> Result<(), ApplyItemError>
|
|
|
|
|
|
where
|
|
|
|
|
|
EG: EntityGateway + ?Sized,
|
|
|
|
|
|
{
|
|
|
|
|
|
let mut inventory = item_state.inventory(&character.id)?;
|
|
|
|
|
|
|
|
|
|
|
|
let (mag_entity_id, mag) = inventory.equipped_mag_mut()
|
|
|
|
|
|
.ok_or_else(|| ApplyItemError::ItemNotEquipped)?;
|
|
|
|
|
|
mag.apply_mag_cell(mag_cell_type)?;
|
|
|
|
|
|
|
|
|
|
|
|
entity_gateway.use_mag_cell(&mag_entity_id, &cell_entity_id).await?;
|
|
|
|
|
|
entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
|
|
|
|
|
|
item_state.set_inventory(inventory);
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
pub async fn cell_of_mag_502<EG: EntityGateway>(entity_gateway: &mut EG, used_cell: &ConsumedItem, inventory: &mut CharacterInventory) -> Result<(), ApplyItemError> {
|
|
|
pub async fn cell_of_mag_502<EG: EntityGateway>(entity_gateway: &mut EG, used_cell: &ConsumedItem, inventory: &mut CharacterInventory) -> Result<(), ApplyItemError> {
|
|
|
mag_cell(entity_gateway, used_cell, inventory, MagCell::CellOfMag502).await
|
|
|
|
|
|
|
|
|
mag_cell(entity_gateway, inventory, MagCell::CellOfMag502).await
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
pub async fn cell_of_mag_213<EG: EntityGateway>(entity_gateway: &mut EG, used_cell: &ConsumedItem, inventory: &mut CharacterInventory) -> Result<(), ApplyItemError> {
|
|
|
pub async fn cell_of_mag_213<EG: EntityGateway>(entity_gateway: &mut EG, used_cell: &ConsumedItem, inventory: &mut CharacterInventory) -> Result<(), ApplyItemError> {
|
|
@ -179,7 +218,15 @@ pub async fn liberta_kit<EG: EntityGateway>(entity_gateway: &mut EG, used_cell: |
|
|
}
|
|
|
}
|
|
|
*/
|
|
|
*/
|
|
|
|
|
|
|
|
|
async fn apply_tool<'a, EG: EntityGateway + ?Sized>(item_state: &mut ItemStateProxy<'a>, entity_gateway: &mut EG, character: &mut CharacterEntity, tool: ToolType) -> Result<(), ApplyItemError> {
|
|
|
|
|
|
|
|
|
async fn apply_tool<'a, EG>(item_state: &mut ItemStateProxy<'a>,
|
|
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
|
|
character: &mut CharacterEntity,
|
|
|
|
|
|
entity_id: ItemEntityId,
|
|
|
|
|
|
tool: ToolType)
|
|
|
|
|
|
-> Result<(), ApplyItemError>
|
|
|
|
|
|
where
|
|
|
|
|
|
EG: EntityGateway + ?Sized,
|
|
|
|
|
|
{
|
|
|
match tool {
|
|
|
match tool {
|
|
|
ToolType::PowerMaterial => power_material(entity_gateway, character).await,
|
|
|
ToolType::PowerMaterial => power_material(entity_gateway, character).await,
|
|
|
ToolType::MindMaterial => mind_material(entity_gateway, character).await,
|
|
|
ToolType::MindMaterial => mind_material(entity_gateway, character).await,
|
|
@ -195,6 +242,32 @@ async fn apply_tool<'a, EG: EntityGateway + ?Sized>(item_state: &mut ItemStatePr |
|
|
ToolType::Difluid => Ok(()),
|
|
|
ToolType::Difluid => Ok(()),
|
|
|
ToolType::Trifluid => Ok(()),
|
|
|
ToolType::Trifluid => Ok(()),
|
|
|
ToolType::HuntersReport => Ok(()),
|
|
|
ToolType::HuntersReport => Ok(()),
|
|
|
|
|
|
ToolType::CellOfMag502
|
|
|
|
|
|
| ToolType::CellOfMag213
|
|
|
|
|
|
| ToolType::PartsOfRobochao
|
|
|
|
|
|
| ToolType::HeartOfOpaOpa
|
|
|
|
|
|
| ToolType::HeartOfPian
|
|
|
|
|
|
| ToolType::HeartOfChao
|
|
|
|
|
|
| ToolType::HeartOfAngel
|
|
|
|
|
|
| ToolType::KitOfHamburger
|
|
|
|
|
|
| ToolType::PanthersSpirit
|
|
|
|
|
|
| ToolType::KitOfMark3
|
|
|
|
|
|
| ToolType::KitOfMasterSystem
|
|
|
|
|
|
| ToolType::KitOfGenesis
|
|
|
|
|
|
| ToolType::KitOfSegaSaturn
|
|
|
|
|
|
| ToolType::KitOfDreamcast
|
|
|
|
|
|
| ToolType::Tablet
|
|
|
|
|
|
| ToolType::DragonScale
|
|
|
|
|
|
| ToolType::HeavenStrikerCoat
|
|
|
|
|
|
| ToolType::PioneerParts
|
|
|
|
|
|
| ToolType::AmitiesMemo
|
|
|
|
|
|
| ToolType::HeartOfMorolian
|
|
|
|
|
|
| ToolType::RappysBeak
|
|
|
|
|
|
| ToolType::YahoosEngine
|
|
|
|
|
|
| ToolType::DPhotonCore
|
|
|
|
|
|
| ToolType::LibertaKit => {
|
|
|
|
|
|
mag_cell(item_state, entity_gateway, character, entity_id, tool.try_into()?).await
|
|
|
|
|
|
}
|
|
|
// TODO: rest of these
|
|
|
// TODO: rest of these
|
|
|
_ => Err(ApplyItemError::InvalidItem)
|
|
|
_ => Err(ApplyItemError::InvalidItem)
|
|
|
}
|
|
|
}
|
|
@ -203,17 +276,18 @@ async fn apply_tool<'a, EG: EntityGateway + ?Sized>(item_state: &mut ItemStatePr |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn apply_item<'a, EG: EntityGateway + ?Sized>(item_state: &mut ItemStateProxy<'a>, entity_gateway: &mut EG, character: &mut CharacterEntity, item: InventoryItem) -> Result<(), ApplyItemError> {
|
|
|
pub async fn apply_item<'a, EG: EntityGateway + ?Sized>(item_state: &mut ItemStateProxy<'a>, entity_gateway: &mut EG, character: &mut CharacterEntity, item: InventoryItem) -> Result<(), ApplyItemError> {
|
|
|
let item_detail = match item.item {
|
|
|
|
|
|
|
|
|
match item.item {
|
|
|
InventoryItemDetail::Individual(individual_item) => {
|
|
|
InventoryItemDetail::Individual(individual_item) => {
|
|
|
individual_item.item
|
|
|
|
|
|
|
|
|
match individual_item.item {
|
|
|
|
|
|
ItemDetail::Tool(tool) => apply_tool(item_state, entity_gateway, character, individual_item.entity_id, tool.tool).await,
|
|
|
|
|
|
_ => Err(ApplyItemError::InvalidItem)
|
|
|
|
|
|
}
|
|
|
},
|
|
|
},
|
|
|
InventoryItemDetail::Stacked(stacked_item) => {
|
|
|
InventoryItemDetail::Stacked(stacked_item) => {
|
|
|
ItemDetail::Tool(stacked_item.tool)
|
|
|
|
|
|
|
|
|
for entity_id in stacked_item.entity_ids {
|
|
|
|
|
|
apply_tool(item_state, entity_gateway, character, entity_id, stacked_item.tool.tool).await?
|
|
|
|
|
|
}
|
|
|
|
|
|
Ok(())
|
|
|
},
|
|
|
},
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
match item_detail {
|
|
|
|
|
|
ItemDetail::Tool(tool) => apply_tool(item_state, entity_gateway, character, tool.tool).await,
|
|
|
|
|
|
_ => Err(ApplyItemError::InvalidItem)
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|