|
@ -8,7 +8,8 @@ use crate::entity::character::{CharacterEntity, CharacterEntityId, TechLevel}; |
|
|
use crate::entity::item::{ItemDetail, ItemNote, BankName};
|
|
|
use crate::entity::item::{ItemDetail, ItemNote, BankName};
|
|
|
use crate::entity::item::{Meseta, NewItemEntity, ItemEntity, InventoryItemEntity, BankItemEntity, EquippedEntity, ItemEntityId};
|
|
|
use crate::entity::item::{Meseta, NewItemEntity, ItemEntity, InventoryItemEntity, BankItemEntity, EquippedEntity, ItemEntityId};
|
|
|
use crate::entity::item::tool::{Tool, ToolType};
|
|
|
use crate::entity::item::tool::{Tool, ToolType};
|
|
|
use crate::entity::item::weapon;
|
|
|
|
|
|
|
|
|
use crate::entity::item::weapon::{Weapon, WeaponModifier};
|
|
|
|
|
|
use crate::entity::item::unit::UnitModifier;
|
|
|
use crate::ship::map::MapArea;
|
|
|
use crate::ship::map::MapArea;
|
|
|
use crate::ship::ship::ItemDropLocation;
|
|
|
use crate::ship::ship::ItemDropLocation;
|
|
|
use crate::ship::trade::TradeItem;
|
|
|
use crate::ship::trade::TradeItem;
|
|
@ -22,6 +23,7 @@ use crate::ship::items::floor::*; |
|
|
use crate::ship::items::inventory::*;
|
|
|
use crate::ship::items::inventory::*;
|
|
|
use crate::ship::items::use_tool;
|
|
|
use crate::ship::items::use_tool;
|
|
|
use crate::ship::items::transaction::{ItemTransaction, ItemAction, TransactionError, TransactionCommitError};
|
|
|
use crate::ship::items::transaction::{ItemTransaction, ItemAction, TransactionError, TransactionCommitError};
|
|
|
|
|
|
use crate::ship::monster::MonsterType;
|
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
|
|
#[derive(PartialEq, Eq)]
|
|
|
pub enum FloorType {
|
|
|
pub enum FloorType {
|
|
@ -984,8 +986,8 @@ impl ItemManager { |
|
|
entity_gateway: &mut EG,
|
|
|
entity_gateway: &mut EG,
|
|
|
character: &CharacterEntity,
|
|
|
character: &CharacterEntity,
|
|
|
item_id: ClientItemId,
|
|
|
item_id: ClientItemId,
|
|
|
tek: weapon::WeaponModifier)
|
|
|
|
|
|
-> Result<weapon::Weapon, anyhow::Error> {
|
|
|
|
|
|
|
|
|
tek: WeaponModifier)
|
|
|
|
|
|
-> Result<Weapon, anyhow::Error> {
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
|
|
|
|
|
let item = inventory.remove_by_id(item_id)
|
|
|
let item = inventory.remove_by_id(item_id)
|
|
@ -1194,20 +1196,11 @@ impl ItemManager { |
|
|
.map_err(|err| err.into())
|
|
|
.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> {
|
|
|
|
|
|
|
|
|
pub async fn increase_kill_counters<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, character: &CharacterEntity, equipped_items: &EquippedEntity, monstertype: MonsterType) -> Result<(), anyhow::Error> {
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
if let Some(weapon_entity) = equipped_items.weapon {
|
|
|
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();
|
|
|
|
|
|
|
|
|
let wmodifier = WeaponModifier::AddKill { enemy: monstertype };
|
|
|
|
|
|
entity_gateway.add_weapon_modifier(&weapon_entity, wmodifier).await?;
|
|
|
}
|
|
|
}
|
|
|
for units in equipped_items.unit.iter().flatten() {
|
|
|
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 unit_id = inventory.get_item_by_entity_id(*units).ok_or(ItemManagerError::EntityIdNotInInventory(*units))?.item_id();
|
|
@ -1220,7 +1213,9 @@ impl ItemManager { |
|
|
.unit_mut()
|
|
|
.unit_mut()
|
|
|
.ok_or(ItemManagerError::WrongItemType(unit_id))?;
|
|
|
.ok_or(ItemManagerError::WrongItemType(unit_id))?;
|
|
|
|
|
|
|
|
|
unit.increment_kill_counter();
|
|
|
|
|
|
|
|
|
let umodifier = UnitModifier::AddKill { enemy: monstertype };
|
|
|
|
|
|
unit.apply_modifier(&umodifier);
|
|
|
|
|
|
entity_gateway.add_unit_modifier(units, umodifier).await?;
|
|
|
}
|
|
|
}
|
|
|
entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
|
|
|
entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|