|
@ -4,8 +4,9 @@ use thiserror::Error; |
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
use crate::entity::character::{CharacterEntity, CharacterEntityId};
|
|
|
use crate::entity::character::{CharacterEntity, CharacterEntityId};
|
|
|
use crate::entity::item::{ItemDetail, ItemLocation, BankName};
|
|
|
use crate::entity::item::{ItemDetail, ItemLocation, BankName};
|
|
|
use crate::entity::item::{Meseta, NewItemEntity};
|
|
|
|
|
|
|
|
|
use crate::entity::item::{Meseta, NewItemEntity, ItemEntity};
|
|
|
use crate::entity::item::tool::{Tool, ToolType};
|
|
|
use crate::entity::item::tool::{Tool, ToolType};
|
|
|
|
|
|
use crate::entity::item::unit;
|
|
|
use crate::ship::map::MapArea;
|
|
|
use crate::ship::map::MapArea;
|
|
|
use crate::ship::ship::ItemDropLocation;
|
|
|
use crate::ship::ship::ItemDropLocation;
|
|
|
use crate::ship::drops::{ItemDrop, ItemDropType};
|
|
|
use crate::ship::drops::{ItemDrop, ItemDropType};
|
|
@ -898,20 +899,43 @@ impl ItemManager { |
|
|
pub async fn player_equips_item<EG: EntityGateway>(&mut self,
|
|
|
pub async fn player_equips_item<EG: EntityGateway>(&mut self,
|
|
|
entity_gateway: &mut EG,
|
|
|
entity_gateway: &mut EG,
|
|
|
character: &CharacterEntity,
|
|
|
character: &CharacterEntity,
|
|
|
item_id: ClientItemId)
|
|
|
|
|
|
|
|
|
item_id: ClientItemId,
|
|
|
|
|
|
equip_slot: u8)
|
|
|
-> Result<(), ItemManagerError> {
|
|
|
-> Result<(), ItemManagerError> {
|
|
|
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 mut inventory_item_handle = inventory.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?;
|
|
|
let mut inventory_item_handle = inventory.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?;
|
|
|
let slot = inventory_item_handle.get_slot();
|
|
|
let slot = inventory_item_handle.get_slot();
|
|
|
let inventory_item = inventory_item_handle.item_mut().ok_or(ItemManagerError::CannotGetMutItem)?.individual().ok_or(ItemManagerError::CannotGetIndividualItem)?;
|
|
|
let inventory_item = inventory_item_handle.item_mut().ok_or(ItemManagerError::CannotGetMutItem)?.individual().ok_or(ItemManagerError::CannotGetIndividualItem)?;
|
|
|
inventory_item.equipped = true;
|
|
|
inventory_item.equipped = true;
|
|
|
|
|
|
if let ItemDetail::Unit(u) = inventory_item.item {
|
|
|
|
|
|
if equip_slot > 0 {
|
|
|
|
|
|
inventory_item.item = ItemDetail::Unit(unit::Unit {
|
|
|
|
|
|
unit: u.unit,
|
|
|
|
|
|
modifier: u.modifier,
|
|
|
|
|
|
armour_slot: ((equip_slot & 0x7) - 1) % 4,
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
inventory_item.item = ItemDetail::Unit(unit::Unit {
|
|
|
|
|
|
unit: u.unit,
|
|
|
|
|
|
modifier: u.modifier,
|
|
|
|
|
|
armour_slot: 0,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
entity_gateway.change_item_location(&inventory_item.entity_id, ItemLocation::Inventory{
|
|
|
entity_gateway.change_item_location(&inventory_item.entity_id, ItemLocation::Inventory{
|
|
|
character_id: character.id,
|
|
|
character_id: character.id,
|
|
|
slot: slot,
|
|
|
slot: slot,
|
|
|
equipped: true,
|
|
|
equipped: true,
|
|
|
}).await;
|
|
|
}).await;
|
|
|
|
|
|
|
|
|
entity_gateway.save_character(character).await;
|
|
|
|
|
|
|
|
|
entity_gateway.save_item(&ItemEntity{
|
|
|
|
|
|
id: inventory_item.entity_id,
|
|
|
|
|
|
location: ItemLocation::Inventory{
|
|
|
|
|
|
character_id: character.id,
|
|
|
|
|
|
slot: slot,
|
|
|
|
|
|
equipped: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
item: inventory_item.item.clone(),
|
|
|
|
|
|
}).await;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
@ -925,13 +949,27 @@ impl ItemManager { |
|
|
let slot = inventory_item_handle.get_slot();
|
|
|
let slot = inventory_item_handle.get_slot();
|
|
|
let inventory_item = inventory_item_handle.item_mut().ok_or(ItemManagerError::CannotGetMutItem)?.individual().ok_or(ItemManagerError::CannotGetIndividualItem)?;
|
|
|
let inventory_item = inventory_item_handle.item_mut().ok_or(ItemManagerError::CannotGetMutItem)?.individual().ok_or(ItemManagerError::CannotGetIndividualItem)?;
|
|
|
inventory_item.equipped = false;
|
|
|
inventory_item.equipped = false;
|
|
|
|
|
|
if let ItemDetail::Unit(u) = inventory_item.item {
|
|
|
|
|
|
inventory_item.item = ItemDetail::Unit(unit::Unit {
|
|
|
|
|
|
unit: u.unit,
|
|
|
|
|
|
modifier: u.modifier,
|
|
|
|
|
|
armour_slot: 0,
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
entity_gateway.change_item_location(&inventory_item.entity_id, ItemLocation::Inventory{
|
|
|
entity_gateway.change_item_location(&inventory_item.entity_id, ItemLocation::Inventory{
|
|
|
character_id: character.id,
|
|
|
character_id: character.id,
|
|
|
slot: slot,
|
|
|
slot: slot,
|
|
|
equipped: false,
|
|
|
equipped: false,
|
|
|
}).await;
|
|
|
}).await;
|
|
|
|
|
|
|
|
|
entity_gateway.save_character(character).await;
|
|
|
|
|
|
|
|
|
entity_gateway.save_item(&ItemEntity{
|
|
|
|
|
|
id: inventory_item.entity_id,
|
|
|
|
|
|
location: ItemLocation::Inventory{
|
|
|
|
|
|
character_id: character.id,
|
|
|
|
|
|
slot: slot,
|
|
|
|
|
|
equipped: false,
|
|
|
|
|
|
},
|
|
|
|
|
|
item: inventory_item.item.clone(),
|
|
|
|
|
|
}).await;
|
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|