Browse Source

remove unwrap

pbs
jake 5 years ago
parent
commit
bd195a2ffd
  1. 10
      src/ship/items.rs
  2. 2
      src/ship/packet/handler/direct_message.rs
  3. 1
      src/ship/ship.rs

10
src/ship/items.rs

@ -14,6 +14,7 @@ use crate::entity::item::mag::Mag;
use crate::entity::item::{Meseta, NewItemEntity};
use crate::ship::map::MapArea;
use crate::ship::drops::{ItemDrop, ItemDropType};
use crate::ship::ship::ShipError;
#[derive(Debug)]
@ -182,8 +183,7 @@ impl ActiveItemDatabase {
ActiveInventory(activated.take(30).collect())
}
// TODO: Result
pub fn activate_item_drop<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, item_drop: ItemDrop) -> ActiveItemOnFloor {
pub fn activate_item_drop<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, item_drop: ItemDrop) -> Result<ActiveItemOnFloor, ShipError> {
let item_detail = match item_drop.item {
ItemDropType::Weapon(w) => Some(ItemDetail::Weapon(w)),
ItemDropType::Armor(w) => Some(ItemDetail::Armor(w)),
@ -205,7 +205,7 @@ impl ActiveItemDatabase {
z: item_drop.z,
}
}).unwrap();
stack_items(vec![item_entity]).pop().unwrap()
stack_items(vec![item_entity]).pop().ok_or(ShipError::ItemError)?
},
None => {
let meseta = match item_drop.item {
@ -217,13 +217,13 @@ impl ActiveItemDatabase {
};
let active_item = self.activate_item(item_instance);
ActiveItemOnFloor {
Ok(ActiveItemOnFloor {
map_area: item_drop.map_area,
x: item_drop.x,
y: item_drop.y,
z: item_drop.z,
item: active_item,
}
})
}
}

2
src/ship/packet/handler/direct_message.rs

@ -88,7 +88,7 @@ where EG: EntityGateway {
item: item_drop_type,
};
let activated_item = active_items.activate_item_drop(entity_gateway, item_drop);
let activated_item = active_items.activate_item_drop(entity_gateway, item_drop)?;
let mut client = clients.get_mut(&area_client.client).ok_or(ShipError::ClientNotFound(area_client.client))?;
let item_drop_msg = builder::message::item_drop(request_item.client, request_item.target, &activated_item)?;
client.floor_items.push(activated_item);

1
src/ship/ship.rs

@ -44,6 +44,7 @@ pub enum ShipError {
InvalidRoom(u32),
MonsterAlreadyDroppedItem(ClientId, u16),
SliceError(#[from] std::array::TryFromSliceError),
ItemError, // TODO: refine this
}
#[derive(Debug)]

Loading…
Cancel
Save