Browse Source

anyhow the rest of the itemmanager

pbs
jake 4 years ago
parent
commit
4b78a110f0
  1. 16
      src/ship/items/manager.rs

16
src/ship/items/manager.rs

@ -223,7 +223,7 @@ impl ItemManager {
} }
pub async fn character_picks_up_item<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, character: &mut CharacterEntity, item_id: ClientItemId) pub async fn character_picks_up_item<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, character: &mut CharacterEntity, item_id: ClientItemId)
-> Result<TriggerCreateItem, ItemManagerError> {
-> Result<TriggerCreateItem, anyhow::Error> {
let local_floor = self.character_floor.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; let local_floor = self.character_floor.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 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 room_id = self.character_room.get(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
@ -251,7 +251,7 @@ impl ItemManager {
} }
}, },
None => { None => {
return Err(ItemManagerError::CouldNotAddToInventory(item_id));
return Err(ItemManagerError::CouldNotAddToInventory(item_id).into());
}, },
} }
TriggerCreateItem::Yes TriggerCreateItem::Yes
@ -278,20 +278,20 @@ impl ItemManager {
} }
}, },
None => { None => {
return Err(ItemManagerError::CouldNotAddToInventory(item_id));
return Err(ItemManagerError::CouldNotAddToInventory(item_id).into());
} }
} }
}, },
Some(FloorItem::Meseta(meseta_floor_item)) => { Some(FloorItem::Meseta(meseta_floor_item)) => {
if character.meseta >= 999999 { if character.meseta >= 999999 {
return Err(ItemManagerError::CouldNotAddToInventory(item_id));
return Err(ItemManagerError::CouldNotAddToInventory(item_id).into());
} }
character.meseta = std::cmp::min(character.meseta + meseta_floor_item.meseta.0, 999999); character.meseta = std::cmp::min(character.meseta + meseta_floor_item.meseta.0, 999999);
entity_gateway.save_character(&character).await?; entity_gateway.save_character(&character).await?;
TriggerCreateItem::No TriggerCreateItem::No
}, },
None => { None => {
return Err(ItemManagerError::CouldNotAddToInventory(item_id));
return Err(ItemManagerError::CouldNotAddToInventory(item_id).into());
} }
}; };
@ -391,7 +391,7 @@ impl ItemManager {
//inventory_item: InventoryItem, //inventory_item: InventoryItem,
item_id: ClientItemId, item_id: ClientItemId,
item_drop_location: (MapArea, f32, f32, f32)) item_drop_location: (MapArea, f32, f32, f32))
-> Result<(), ItemManagerError> {
-> 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))?;
let room_id = self.character_room.get(&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))?; let shared_floor = self.room_floor.get_mut(&room_id).ok_or(ItemManagerError::NoCharacter(character.id))?;
@ -436,11 +436,11 @@ impl ItemManager {
character: &mut CharacterEntity, character: &mut CharacterEntity,
drop_location: ItemDropLocation, drop_location: ItemDropLocation,
amount: u32) amount: u32)
-> Result<FloorItem, ItemManagerError> {
-> Result<FloorItem, anyhow::Error> {
let room_id = self.character_room.get(&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))?; let shared_floor = self.room_floor.get_mut(&room_id).ok_or(ItemManagerError::NoCharacter(character.id))?;
if character.meseta < amount { if character.meseta < amount {
return Err(ItemManagerError::CouldNotDropMeseta)
return Err(ItemManagerError::CouldNotDropMeseta.into())
} }
character.meseta -= amount; character.meseta -= amount;
entity_gateway.save_character(&character).await?; entity_gateway.save_character(&character).await?;

Loading…
Cancel
Save