remove unwrap
This commit is contained in:
parent
4a526e7673
commit
bd195a2ffd
@ -14,6 +14,7 @@ use crate::entity::item::mag::Mag;
|
|||||||
use crate::entity::item::{Meseta, NewItemEntity};
|
use crate::entity::item::{Meseta, NewItemEntity};
|
||||||
use crate::ship::map::MapArea;
|
use crate::ship::map::MapArea;
|
||||||
use crate::ship::drops::{ItemDrop, ItemDropType};
|
use crate::ship::drops::{ItemDrop, ItemDropType};
|
||||||
|
use crate::ship::ship::ShipError;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -182,8 +183,7 @@ impl ActiveItemDatabase {
|
|||||||
ActiveInventory(activated.take(30).collect())
|
ActiveInventory(activated.take(30).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Result
|
pub fn activate_item_drop<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, item_drop: ItemDrop) -> Result<ActiveItemOnFloor, ShipError> {
|
||||||
pub fn activate_item_drop<EG: EntityGateway>(&mut self, entity_gateway: &mut EG, item_drop: ItemDrop) -> ActiveItemOnFloor {
|
|
||||||
let item_detail = match item_drop.item {
|
let item_detail = match item_drop.item {
|
||||||
ItemDropType::Weapon(w) => Some(ItemDetail::Weapon(w)),
|
ItemDropType::Weapon(w) => Some(ItemDetail::Weapon(w)),
|
||||||
ItemDropType::Armor(w) => Some(ItemDetail::Armor(w)),
|
ItemDropType::Armor(w) => Some(ItemDetail::Armor(w)),
|
||||||
@ -205,7 +205,7 @@ impl ActiveItemDatabase {
|
|||||||
z: item_drop.z,
|
z: item_drop.z,
|
||||||
}
|
}
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
stack_items(vec![item_entity]).pop().unwrap()
|
stack_items(vec![item_entity]).pop().ok_or(ShipError::ItemError)?
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
let meseta = match item_drop.item {
|
let meseta = match item_drop.item {
|
||||||
@ -217,13 +217,13 @@ impl ActiveItemDatabase {
|
|||||||
};
|
};
|
||||||
let active_item = self.activate_item(item_instance);
|
let active_item = self.activate_item(item_instance);
|
||||||
|
|
||||||
ActiveItemOnFloor {
|
Ok(ActiveItemOnFloor {
|
||||||
map_area: item_drop.map_area,
|
map_area: item_drop.map_area,
|
||||||
x: item_drop.x,
|
x: item_drop.x,
|
||||||
y: item_drop.y,
|
y: item_drop.y,
|
||||||
z: item_drop.z,
|
z: item_drop.z,
|
||||||
item: active_item,
|
item: active_item,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ where EG: EntityGateway {
|
|||||||
item: item_drop_type,
|
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 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)?;
|
let item_drop_msg = builder::message::item_drop(request_item.client, request_item.target, &activated_item)?;
|
||||||
client.floor_items.push(activated_item);
|
client.floor_items.push(activated_item);
|
||||||
|
@ -44,6 +44,7 @@ pub enum ShipError {
|
|||||||
InvalidRoom(u32),
|
InvalidRoom(u32),
|
||||||
MonsterAlreadyDroppedItem(ClientId, u16),
|
MonsterAlreadyDroppedItem(ClientId, u16),
|
||||||
SliceError(#[from] std::array::TryFromSliceError),
|
SliceError(#[from] std::array::TryFromSliceError),
|
||||||
|
ItemError, // TODO: refine this
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user