|
|
@ -89,7 +89,7 @@ impl ItemManager { |
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Result
|
|
|
|
pub async fn load_character<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, character: &CharacterEntity) -> Result<(), ItemManagerError> {
|
|
|
|
pub async fn load_character<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, character: &CharacterEntity) -> Result<(), anyhow::Error> {
|
|
|
|
let inventory = entity_gateway.get_character_inventory(&character.id).await?;
|
|
|
|
let bank = entity_gateway.get_character_bank(&character.id, BankName("".into())).await?;
|
|
|
|
let equipped = entity_gateway.get_character_equips(&character.id).await?;
|
|
|
@ -176,12 +176,12 @@ impl ItemManager { |
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_character_inventory(&self, character: &CharacterEntity) -> Result<&CharacterInventory, ItemManagerError> {
|
|
|
|
pub fn get_character_inventory(&self, character: &CharacterEntity) -> Result<&CharacterInventory, anyhow::Error> {
|
|
|
|
Ok(self.character_inventory.get(&character.id)
|
|
|
|
.ok_or(ItemManagerError::NoCharacter(character.id))?)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_character_bank(&self, character: &CharacterEntity) -> Result<&CharacterBank, ItemManagerError> {
|
|
|
|
pub fn get_character_bank(&self, character: &CharacterEntity) -> Result<&CharacterBank, anyhow::Error> {
|
|
|
|
Ok(self.character_bank
|
|
|
|
.get(&character.id)
|
|
|
|
.ok_or(ItemManagerError::NoCharacter(character.id))?)
|
|
|
@ -210,7 +210,7 @@ impl ItemManager { |
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_floor_item_by_id(&self, character: &CharacterEntity, item_id: ClientItemId) -> Result<(&FloorItem, FloorType), ItemManagerError> {
|
|
|
|
pub fn get_floor_item_by_id(&self, character: &CharacterEntity, item_id: ClientItemId) -> Result<(&FloorItem, FloorType), anyhow::Error> {
|
|
|
|
let local_floor = self.character_floor.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
let room = self.character_room.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
let shared_floor = self.room_floor.get(room).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
@ -219,7 +219,7 @@ impl ItemManager { |
|
|
|
.or_else(|| {
|
|
|
|
shared_floor.get_item_by_id(item_id).map(|item| (item, FloorType::Shared))
|
|
|
|
})
|
|
|
|
.ok_or(ItemManagerError::NoSuchItemId(item_id))
|
|
|
|
.ok_or(ItemManagerError::NoSuchItemId(item_id).into())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn character_picks_up_item<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, character: &mut CharacterEntity, item_id: ClientItemId)
|
|
|
@ -300,7 +300,7 @@ impl ItemManager { |
|
|
|
Ok(trigger_create_item)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn enemy_drop_item_on_local_floor<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, character: &CharacterEntity, item_drop: ItemDrop) -> Result<&FloorItem, ItemManagerError> {
|
|
|
|
pub async fn enemy_drop_item_on_local_floor<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, character: &CharacterEntity, item_drop: ItemDrop) -> Result<&FloorItem, anyhow::Error> {
|
|
|
|
let room_id = self.character_room.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
|
|
|
|
enum ItemOrMeseta {
|
|
|
@ -382,7 +382,7 @@ impl ItemManager { |
|
|
|
|
|
|
|
self.character_floor.entry(character.id).or_insert(RoomFloorItems::new()).add_item(floor_item);
|
|
|
|
// TODO: make these real errors
|
|
|
|
self.character_floor.get(&character.id).ok_or(ItemManagerError::Idunnoman)?.get_item_by_id(item_id).ok_or(ItemManagerError::Idunnoman)
|
|
|
|
self.character_floor.get(&character.id).ok_or(ItemManagerError::Idunnoman)?.get_item_by_id(item_id).ok_or(ItemManagerError::Idunnoman.into())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn player_drop_item_on_shared_floor<EG: EntityGateway>(&mut self,
|
|
|
@ -466,7 +466,7 @@ impl ItemManager { |
|
|
|
item_id: ClientItemId,
|
|
|
|
drop_location: ItemDropLocation,
|
|
|
|
amount: usize)
|
|
|
|
-> Result<&StackedFloorItem, ItemManagerError> {
|
|
|
|
-> Result<&StackedFloorItem, anyhow::Error> {
|
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
let room_id = self.character_room.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
let shared_floor = self.room_floor.get_mut(&room_id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
@ -498,7 +498,7 @@ impl ItemManager { |
|
|
|
character: &mut CharacterEntity,
|
|
|
|
item_id: ClientItemId,
|
|
|
|
amount: usize)
|
|
|
|
-> Result<ConsumedItem, ItemManagerError> {
|
|
|
|
-> Result<ConsumedItem, anyhow::Error> {
|
|
|
|
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)?;
|
|
|
@ -523,7 +523,7 @@ impl ItemManager { |
|
|
|
character: &CharacterEntity,
|
|
|
|
item_id: ClientItemId,
|
|
|
|
amount: usize)
|
|
|
|
-> Result<(), ItemManagerError> {
|
|
|
|
-> Result<(), anyhow::Error> {
|
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
let bank = self.character_bank
|
|
|
|
.get_mut(&character.id)
|
|
|
@ -561,7 +561,7 @@ impl ItemManager { |
|
|
|
character: &CharacterEntity,
|
|
|
|
item_id: ClientItemId,
|
|
|
|
amount: usize)
|
|
|
|
-> Result<&InventoryItem, ItemManagerError> {
|
|
|
|
-> Result<&InventoryItem, anyhow::Error> {
|
|
|
|
|
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
let bank = self.character_bank
|
|
|
@ -593,7 +593,7 @@ impl ItemManager { |
|
|
|
|
|
|
|
entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
|
|
|
|
entity_gateway.set_character_bank(&character.id, &bank.as_bank_entity(&character.id, &BankName("".into())), BankName("".into())).await?;
|
|
|
|
inventory.slot(inventory_item_slot).ok_or(ItemManagerError::Idunnoman)
|
|
|
|
inventory.slot(inventory_item_slot).ok_or(ItemManagerError::Idunnoman.into())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn player_feeds_mag_item<EG: EntityGateway>(&mut self,
|
|
|
@ -601,7 +601,7 @@ impl ItemManager { |
|
|
|
character: &CharacterEntity,
|
|
|
|
mag_id: ClientItemId,
|
|
|
|
tool_id: ClientItemId)
|
|
|
|
-> Result<(), ItemManagerError> {
|
|
|
|
-> Result<(), anyhow::Error> {
|
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
let consumed_tool = {
|
|
|
|
let item_to_feed = inventory.get_item_handle_by_id(tool_id).ok_or(ItemManagerError::NoSuchItemId(tool_id))?;
|
|
|
@ -619,7 +619,7 @@ impl ItemManager { |
|
|
|
|
|
|
|
let consumed_tool_type = match &consumed_tool {
|
|
|
|
ConsumedItem::Stacked(stacked_consumed_item) => stacked_consumed_item.tool.tool,
|
|
|
|
_ => return Err(ItemManagerError::WrongItemType(tool_id))
|
|
|
|
_ => return Err(ItemManagerError::WrongItemType(tool_id).into())
|
|
|
|
};
|
|
|
|
mag.feed(consumed_tool_type);
|
|
|
|
|
|
|
@ -637,7 +637,7 @@ impl ItemManager { |
|
|
|
pub async fn use_item<EG: EntityGateway>(&mut self,
|
|
|
|
used_item: ConsumedItem,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
character: &mut CharacterEntity) -> Result<(), ItemManagerError> {
|
|
|
|
character: &mut CharacterEntity) -> Result<(), anyhow::Error> {
|
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
match &used_item.item() {
|
|
|
|
ItemDetail::Weapon(_w) => {
|
|
|
@ -754,7 +754,7 @@ impl ItemManager { |
|
|
|
shop_item: &(dyn ShopItem + Send + Sync),
|
|
|
|
item_id: ClientItemId,
|
|
|
|
amount: usize)
|
|
|
|
-> Result<&InventoryItem, ItemManagerError> {
|
|
|
|
-> Result<&InventoryItem, anyhow::Error> {
|
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
|
|
|
|
let item_detail = shop_item.as_item();
|
|
|
@ -853,7 +853,7 @@ impl ItemManager { |
|
|
|
character: &CharacterEntity,
|
|
|
|
item_id: ClientItemId,
|
|
|
|
equip_slot: u8)
|
|
|
|
-> Result<(), ItemManagerError> {
|
|
|
|
-> Result<(), anyhow::Error> {
|
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
inventory.equip(&item_id, equip_slot);
|
|
|
|
entity_gateway.set_character_equips(&character.id, &inventory.as_equipped_entity()).await?;
|
|
|
@ -864,7 +864,7 @@ impl ItemManager { |
|
|
|
entity_gateway: &mut EG,
|
|
|
|
character: &CharacterEntity,
|
|
|
|
item_id: ClientItemId)
|
|
|
|
-> Result<(), ItemManagerError> {
|
|
|
|
-> Result<(), anyhow::Error> {
|
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
inventory.unequip(&item_id);
|
|
|
|
entity_gateway.set_character_equips(&character.id, &inventory.as_equipped_entity()).await?;
|
|
|
@ -875,7 +875,7 @@ impl ItemManager { |
|
|
|
entity_gateway: &mut EG,
|
|
|
|
character: &CharacterEntity,
|
|
|
|
item_ids: [u32; 30])
|
|
|
|
-> Result<(), ItemManagerError> {
|
|
|
|
-> Result<(), anyhow::Error> {
|
|
|
|
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
|
|
|
|
let sorted_inventory_items: Vec<InventoryItem> = item_ids.iter()
|
|
|
|
.filter(|&client_item_id| *client_item_id < 0xFFFFFFFF)
|
|
|
|