|
|
@ -42,7 +42,9 @@ pub enum ItemManagerError { |
|
|
|
UseItemError(#[from] use_tool::UseItemError),
|
|
|
|
CouldNotBuyItem,
|
|
|
|
CouldNotAddBoughtItemToInventory,
|
|
|
|
ItemIdNotInInventory(ClientItemId)
|
|
|
|
ItemIdNotInInventory(ClientItemId),
|
|
|
|
CannotGetMutItem,
|
|
|
|
CannotGetIndividualItem,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -893,4 +895,42 @@ impl ItemManager { |
|
|
|
};
|
|
|
|
Ok(inventory_item)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn player_equips_item<EG: EntityGateway>(&mut self,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
character: &CharacterEntity,
|
|
|
|
item_id: ClientItemId)
|
|
|
|
-> Result<(), ItemManagerError> {
|
|
|
|
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 inventory_item = inventory_item_handle.item_mut().ok_or(ItemManagerError::CannotGetMutItem)?.individual().ok_or(ItemManagerError::CannotGetIndividualItem)?;
|
|
|
|
inventory_item.equipped = true;
|
|
|
|
entity_gateway.change_item_location(&inventory_item.entity_id, ItemLocation::Inventory{
|
|
|
|
character_id: character.id,
|
|
|
|
slot: character.slot as usize,
|
|
|
|
equipped: true,
|
|
|
|
}).await;
|
|
|
|
|
|
|
|
entity_gateway.save_character(character).await;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn player_unequips_item<EG: EntityGateway>(&mut self,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
character: &CharacterEntity,
|
|
|
|
item_id: ClientItemId)
|
|
|
|
-> Result<(), ItemManagerError> {
|
|
|
|
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 inventory_item = inventory_item_handle.item_mut().ok_or(ItemManagerError::CannotGetMutItem)?.individual().ok_or(ItemManagerError::CannotGetIndividualItem)?;
|
|
|
|
inventory_item.equipped = false;
|
|
|
|
entity_gateway.change_item_location(&inventory_item.entity_id, ItemLocation::Inventory{
|
|
|
|
character_id: character.id,
|
|
|
|
slot: character.slot as usize,
|
|
|
|
equipped: false,
|
|
|
|
}).await;
|
|
|
|
|
|
|
|
entity_gateway.save_character(character).await;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|