|
|
@ -60,7 +60,7 @@ impl InventoryItemDetail { |
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: this should probably go somewhere a bit more fundamental like ItemDetail
|
|
|
|
pub fn sell_price(&self) -> Result<u32, ItemStateError> {
|
|
|
|
pub fn sell_price(&self) -> Result<u32, anyhow::Error> {
|
|
|
|
match self {
|
|
|
|
InventoryItemDetail::Individual(individual_item) => {
|
|
|
|
match &individual_item.item {
|
|
|
@ -102,7 +102,7 @@ impl InventoryItemDetail { |
|
|
|
Ok((ToolShopItem::from(d).price() / 8) as u32)
|
|
|
|
},
|
|
|
|
ItemDetail::Mag(_m) => {
|
|
|
|
Err(ItemStateError::ItemNotSellable)
|
|
|
|
Err(ItemStateError::ItemNotSellable.into())
|
|
|
|
},
|
|
|
|
ItemDetail::ESWeapon(_e) => {
|
|
|
|
Ok(10u32)
|
|
|
@ -126,10 +126,10 @@ pub struct InventoryItem { |
|
|
|
}
|
|
|
|
|
|
|
|
impl InventoryItem {
|
|
|
|
pub async fn with_entity_id<F, Fut, T>(&self, mut param: T, mut func: F) -> Result<T, ItemStateError>
|
|
|
|
pub async fn with_entity_id<F, Fut, T>(&self, mut param: T, mut func: F) -> Result<T, anyhow::Error>
|
|
|
|
where
|
|
|
|
F: FnMut(T, ItemEntityId) -> Fut,
|
|
|
|
Fut: Future<Output=Result<T, ItemStateError>>,
|
|
|
|
Fut: Future<Output=Result<T, anyhow::Error>>,
|
|
|
|
{
|
|
|
|
match &self.item {
|
|
|
|
InventoryItemDetail::Individual(individual_item) => {
|
|
|
@ -145,10 +145,10 @@ impl InventoryItem { |
|
|
|
Ok(param)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn with_mag<F, Fut, T>(&self, mut param: T, mut func: F) -> Result<T, ItemStateError>
|
|
|
|
pub async fn with_mag<F, Fut, T>(&self, mut param: T, mut func: F) -> Result<T, anyhow::Error>
|
|
|
|
where
|
|
|
|
F: FnMut(T, ItemEntityId, Mag) -> Fut,
|
|
|
|
Fut: Future<Output=Result<T, ItemStateError>>,
|
|
|
|
Fut: Future<Output=Result<T, anyhow::Error>>,
|
|
|
|
{
|
|
|
|
if let InventoryItemDetail::Individual(individual_item) = &self.item {
|
|
|
|
if let ItemDetail::Mag(mag) = &individual_item.item {
|
|
|
@ -205,11 +205,11 @@ impl InventoryState { |
|
|
|
self.inventory.0.len()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_floor_item(&mut self, item: FloorItem) -> Result<AddItemResult, InventoryError> {
|
|
|
|
pub fn add_floor_item(&mut self, item: FloorItem) -> Result<AddItemResult, anyhow::Error> {
|
|
|
|
match item.item {
|
|
|
|
FloorItemDetail::Individual(iitem) => {
|
|
|
|
if self.inventory.0.len() >= 30 {
|
|
|
|
Err(InventoryError::InventoryFull)
|
|
|
|
Err(InventoryError::InventoryFull.into())
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self.inventory.0.push(InventoryItem {
|
|
|
@ -229,7 +229,7 @@ impl InventoryState { |
|
|
|
match existing_stack {
|
|
|
|
Some(existing_stack) => {
|
|
|
|
if existing_stack.entity_ids.len() + sitem.entity_ids.len() > sitem.tool.max_stack() {
|
|
|
|
Err(InventoryError::StackFull)
|
|
|
|
Err(InventoryError::StackFull.into())
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
existing_stack.entity_ids.append(&mut sitem.entity_ids.clone());
|
|
|
@ -238,7 +238,7 @@ impl InventoryState { |
|
|
|
},
|
|
|
|
None => {
|
|
|
|
if self.inventory.0.len() >= 30 {
|
|
|
|
Err(InventoryError::InventoryFull)
|
|
|
|
Err(InventoryError::InventoryFull.into())
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self.inventory.0.push(InventoryItem {
|
|
|
@ -253,7 +253,7 @@ impl InventoryState { |
|
|
|
},
|
|
|
|
FloorItemDetail::Meseta(meseta) => {
|
|
|
|
if self.meseta == Meseta(999999) {
|
|
|
|
Err(InventoryError::MesetaFull)
|
|
|
|
Err(InventoryError::MesetaFull.into())
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self.meseta.0 = std::cmp::min(self.meseta.0 + meseta.0, 999999);
|
|
|
@ -263,11 +263,11 @@ impl InventoryState { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_item(&mut self, item: InventoryItem) -> Result<(AddItemResult, InventoryItem), InventoryError> {
|
|
|
|
pub fn add_item(&mut self, item: InventoryItem) -> Result<(AddItemResult, InventoryItem), anyhow::Error> {
|
|
|
|
match &item.item {
|
|
|
|
InventoryItemDetail::Individual(_) => {
|
|
|
|
if self.inventory.0.len() >= 30 {
|
|
|
|
Err(InventoryError::InventoryFull)
|
|
|
|
Err(InventoryError::InventoryFull.into())
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self.inventory.0.push(item);
|
|
|
@ -290,7 +290,7 @@ impl InventoryState { |
|
|
|
match existing_stack {
|
|
|
|
Some(existing_stack) => {
|
|
|
|
if existing_stack.entity_ids.len() + sitem.entity_ids.len() > sitem.tool.max_stack() {
|
|
|
|
Err(InventoryError::StackFull)
|
|
|
|
Err(InventoryError::StackFull.into())
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
existing_stack.entity_ids.append(&mut sitem.entity_ids.clone());
|
|
|
@ -307,7 +307,7 @@ impl InventoryState { |
|
|
|
},
|
|
|
|
None => {
|
|
|
|
if self.inventory.0.len() >= 30 {
|
|
|
|
Err(InventoryError::InventoryFull)
|
|
|
|
Err(InventoryError::InventoryFull.into())
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self.inventory.0.push(item);
|
|
|
@ -370,25 +370,25 @@ impl InventoryState { |
|
|
|
.find(|i| i.item_id == *item_id)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_meseta(&mut self, amount: u32) -> Result<(), ItemStateError> {
|
|
|
|
pub fn add_meseta(&mut self, amount: u32) -> Result<(), anyhow::Error> {
|
|
|
|
if self.meseta.0 == 999999 {
|
|
|
|
return Err(ItemStateError::FullOfMeseta)
|
|
|
|
return Err(ItemStateError::FullOfMeseta.into())
|
|
|
|
}
|
|
|
|
self.meseta.0 = std::cmp::min(self.meseta.0 + amount, 999999);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_meseta_no_overflow(&mut self, amount: u32) -> Result<(), ItemStateError> {
|
|
|
|
pub fn add_meseta_no_overflow(&mut self, amount: u32) -> Result<(), anyhow::Error> {
|
|
|
|
if self.meseta.0 + amount > 999999 {
|
|
|
|
return Err(ItemStateError::FullOfMeseta)
|
|
|
|
return Err(ItemStateError::FullOfMeseta.into())
|
|
|
|
}
|
|
|
|
self.meseta.0 += amount;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn remove_meseta(&mut self, amount: u32) -> Result<(), ItemStateError> {
|
|
|
|
pub fn remove_meseta(&mut self, amount: u32) -> Result<(), anyhow::Error> {
|
|
|
|
if amount > self.meseta.0 {
|
|
|
|
return Err(ItemStateError::InvalidMesetaRemoval(amount))
|
|
|
|
return Err(ItemStateError::InvalidMesetaRemoval(amount).into())
|
|
|
|
}
|
|
|
|
self.meseta.0 -= amount;
|
|
|
|
Ok(())
|
|
|
|