|
|
@ -83,6 +83,8 @@ pub enum ItemManagerError { |
|
|
|
#[error("invalid trade")]
|
|
|
|
InvalidTrade,
|
|
|
|
EntityIdNotInInventory(ItemEntityId),
|
|
|
|
WeaponCannotCombine,
|
|
|
|
NotEnoughKills(u16),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<E> std::convert::From<TransactionError<E>> for ItemManagerError
|
|
|
@ -696,7 +698,6 @@ impl ItemManager { |
|
|
|
match &used_item.item() {
|
|
|
|
ItemDetail::Weapon(_w) => {
|
|
|
|
// something like when items are used to combine/transform them?
|
|
|
|
//_ => {}
|
|
|
|
},
|
|
|
|
ItemDetail::Tool(t) => {
|
|
|
|
match t.tool {
|
|
|
@ -793,7 +794,7 @@ impl ItemManager { |
|
|
|
ToolType::LibertaKit => {
|
|
|
|
use_tool::liberta_kit(entity_gateway, &used_item, inventory).await?;
|
|
|
|
},
|
|
|
|
_ => {}
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
@ -1382,33 +1383,39 @@ impl<EG: EntityGateway> ItemAction<EG> for TradeMeseta { |
|
|
|
equipped_items: &EquippedEntity)
|
|
|
|
-> Result<(), anyhow::Error> {
|
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
// weapon
|
|
|
|
if let Some(weapon_entity) = equipped_items.weapon {
|
|
|
|
println!("updating weapon kill counter for weapon {:?}", weapon_entity);
|
|
|
|
// weapon_entity = &InventoryItem
|
|
|
|
|
|
|
|
// let weapon_id = weapon_entity.item_id();
|
|
|
|
let weapon_id = inventory.get_item_by_entity_id(weapon_entity).ok_or(ItemManagerError::EntityIdNotInInventory(weapon_entity))?.item_id();
|
|
|
|
let mut weapon_handle = inventory.get_item_handle_by_id(weapon_id).ok_or(ItemManagerError::NoSuchItemId(weapon_id))?;
|
|
|
|
// weapon_handle = InventoryItemHandle
|
|
|
|
let individual_item = weapon_handle.item_mut()
|
|
|
|
let individual_item_w = weapon_handle.item_mut()
|
|
|
|
.ok_or(ItemManagerError::NoSuchItemId(weapon_id))?
|
|
|
|
.individual_mut()
|
|
|
|
.ok_or(ItemManagerError::WrongItemType(weapon_id))?;
|
|
|
|
let weapon = individual_item
|
|
|
|
let weapon = individual_item_w
|
|
|
|
.weapon_mut()
|
|
|
|
.ok_or(ItemManagerError::WrongItemType(weapon_id))?;
|
|
|
|
|
|
|
|
weapon.increment_kill_counter();
|
|
|
|
entity_gateway.increment_kill_counter(&weapon_entity).await?;
|
|
|
|
entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
|
|
|
|
}
|
|
|
|
// for units in equipped_items.unit {
|
|
|
|
// if let Some(unit_id) = units {
|
|
|
|
// println!("UNIMPLEMENTED - updating unit kill counter for unit {:?}", unit_id);
|
|
|
|
// // entity_gateway.increase_kill_counter(&unit_id).await?;
|
|
|
|
// // let unit = inventory.get_item_by_entity_id(&unit_id)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// limiter
|
|
|
|
for units in equipped_items.unit {
|
|
|
|
if let Some(unit_entity) = units {
|
|
|
|
let unit_id = inventory.get_item_by_entity_id(unit_entity).ok_or(ItemManagerError::EntityIdNotInInventory(unit_entity))?.item_id();
|
|
|
|
let mut unit_handle = inventory.get_item_handle_by_id(unit_id).ok_or(ItemManagerError::NoSuchItemId(unit_id))?;
|
|
|
|
let individual_item_u = unit_handle.item_mut()
|
|
|
|
.ok_or(ItemManagerError::NoSuchItemId(unit_id))?
|
|
|
|
.individual_mut()
|
|
|
|
.ok_or(ItemManagerError::WrongItemType(unit_id))?;
|
|
|
|
let unit = individual_item_u
|
|
|
|
.unit_mut()
|
|
|
|
.ok_or(ItemManagerError::WrongItemType(unit_id))?;
|
|
|
|
|
|
|
|
unit.increment_kill_counter();
|
|
|
|
entity_gateway.increment_kill_counter(&unit_entity).await?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|