|
|
@ -2,7 +2,7 @@ use crate::ship::items::ClientItemId; |
|
|
|
use std::collections::{HashMap, BTreeMap};
|
|
|
|
use thiserror::Error;
|
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
|
use crate::entity::character::{CharacterEntity, CharacterEntityId};
|
|
|
|
use crate::entity::character::{CharacterEntity, CharacterEntityId, TechLevel};
|
|
|
|
use crate::entity::item::{ItemDetail, ItemLocation, BankName};
|
|
|
|
use crate::entity::item::{Meseta, NewItemEntity, ItemEntity, InventoryItemEntity, EquippedEntity, InventoryEntity, BankItemEntity, BankEntity};
|
|
|
|
use crate::entity::item::tool::{Tool, ToolType};
|
|
|
@ -490,13 +490,19 @@ impl ItemManager { |
|
|
|
|
|
|
|
pub async fn player_consumes_tool<EG: EntityGateway>(&mut self,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
character: &CharacterEntity,
|
|
|
|
character: &mut CharacterEntity,
|
|
|
|
item_id: ClientItemId,
|
|
|
|
amount: usize)
|
|
|
|
-> Result<ConsumedItem, ItemManagerError> {
|
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
let used_item = inventory.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?;
|
|
|
|
let consumed_item = used_item.consume(amount)?;
|
|
|
|
|
|
|
|
if let ItemDetail::TechniqueDisk(tech_disk) = consumed_item.item() {
|
|
|
|
// TODO: validate tech level in packet is in bounds [1..30]
|
|
|
|
character.techs.set_tech(tech_disk.tech, TechLevel(tech_disk.level as u8));
|
|
|
|
entity_gateway.save_character(character).await?;
|
|
|
|
};
|
|
|
|
|
|
|
|
for entity_id in consumed_item.entity_ids() {
|
|
|
|
entity_gateway.change_item_location(&entity_id,
|
|
|
|