|
|
@ -1193,6 +1193,38 @@ impl ItemManager { |
|
|
|
.await
|
|
|
|
.map_err(|err| err.into())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn increase_kill_counters<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, character: &CharacterEntity, equipped_items: &EquippedEntity) -> Result<(), anyhow::Error> {
|
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
if let Some(weapon_entity) = equipped_items.weapon {
|
|
|
|
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))?;
|
|
|
|
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_w
|
|
|
|
.weapon_mut()
|
|
|
|
.ok_or(ItemManagerError::WrongItemType(weapon_id))?;
|
|
|
|
|
|
|
|
weapon.increment_kill_counter();
|
|
|
|
}
|
|
|
|
for units in equipped_items.unit.iter().flatten() {
|
|
|
|
let unit_id = inventory.get_item_by_entity_id(*units).ok_or(ItemManagerError::EntityIdNotInInventory(*units))?.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.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
@ -1375,41 +1407,6 @@ impl<EG: EntityGateway> ItemAction<EG> for TradeMeseta { |
|
|
|
dest_meseta.0 += self.amount as u32;
|
|
|
|
entity_gateway.set_character_meseta(&self.dest_character_id, *dest_meseta).await?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn increase_kill_counters<EG: EntityGateway>( &mut self,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
character: &CharacterEntity,
|
|
|
|
equipped_items: &EquippedEntity)
|
|
|
|
-> Result<(), anyhow::Error> {
|
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
if let Some(weapon_entity) = equipped_items.weapon {
|
|
|
|
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))?;
|
|
|
|
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_w
|
|
|
|
.weapon_mut()
|
|
|
|
.ok_or(ItemManagerError::WrongItemType(weapon_id))?;
|
|
|
|
|
|
|
|
weapon.increment_kill_counter();
|
|
|
|
}
|
|
|
|
for units in equipped_items.unit.iter().flatten() {
|
|
|
|
let unit_id = inventory.get_item_by_entity_id(*units).ok_or(ItemManagerError::EntityIdNotInInventory(*units))?.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.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|