|
|
@ -6,7 +6,7 @@ use crate::entity::item::{ItemEntityId, ItemDetail, ItemEntity, ItemType, ItemLo |
|
|
|
use crate::entity::item::tool::{Tool, ToolType};
|
|
|
|
use crate::entity::item::mag::Mag;
|
|
|
|
use crate::entity::item::weapon::Weapon;
|
|
|
|
use crate::ship::items::{ClientItemId, BankItem, BankItemHandle};
|
|
|
|
use crate::ship::items::{ClientItemId, BankItem, BankItemHandle, ItemManagerError};
|
|
|
|
use crate::ship::items::floor::{IndividualFloorItem, StackedFloorItem};
|
|
|
|
use crate::ship::shops::{ShopItem, ArmorShopItem, ToolShopItem, WeaponShopItem};
|
|
|
|
|
|
|
@ -222,59 +222,75 @@ impl InventoryItem { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_sell_price(&self) -> Option<u32> {
|
|
|
|
// pub fn get_sell_price(&self) -> Option<u32> {
|
|
|
|
pub fn get_sell_price(&self) -> Result<u32, ItemManagerError> {
|
|
|
|
match self {
|
|
|
|
InventoryItem::Individual(individual_item) => {
|
|
|
|
match &individual_item.item {
|
|
|
|
// TODO: can wrapped items be sold?
|
|
|
|
ItemDetail::Weapon(w) => {
|
|
|
|
if !w.tekked {
|
|
|
|
return Some(1u32)
|
|
|
|
// return Some(1u32)
|
|
|
|
return Ok(1u32)
|
|
|
|
}
|
|
|
|
if w.is_rare_item() {
|
|
|
|
return Some(10u32)
|
|
|
|
// return Some(10u32)
|
|
|
|
return Ok(10u32)
|
|
|
|
}
|
|
|
|
// other item factors?
|
|
|
|
Some((WeaponShopItem::weapon_from_item(w).price() / 8) as u32)
|
|
|
|
// Some((WeaponShopItem::from(w).price() / 8) as u32)
|
|
|
|
Ok((WeaponShopItem::from(w).price() / 8) as u32)
|
|
|
|
},
|
|
|
|
ItemDetail::Armor(a) => {
|
|
|
|
if a.is_rare_item() {
|
|
|
|
return Some(10u32)
|
|
|
|
// return Some(10u32)
|
|
|
|
return Ok(10u32)
|
|
|
|
}
|
|
|
|
Some((ArmorShopItem::armor_from_item(a).price() / 8) as u32)
|
|
|
|
// Some((ArmorShopItem::from(a).price() / 8) as u32)
|
|
|
|
return Ok((ArmorShopItem::from(a).price() / 8) as u32)
|
|
|
|
},
|
|
|
|
ItemDetail::Shield(s) => {
|
|
|
|
if s.is_rare_item() {
|
|
|
|
return Some(10u32)
|
|
|
|
// return Some(10u32)
|
|
|
|
return Ok(10u32)
|
|
|
|
}
|
|
|
|
Some((ArmorShopItem::shield_from_item(s).price() / 8) as u32)
|
|
|
|
// Some((ArmorShopItem::from(s).price() / 8) as u32)
|
|
|
|
return Ok((ArmorShopItem::from(s).price() / 8) as u32)
|
|
|
|
},
|
|
|
|
ItemDetail::Unit(u) => {
|
|
|
|
if u.is_rare_item() {
|
|
|
|
return Some(10u32)
|
|
|
|
// return Some(10u32)
|
|
|
|
return Ok(10u32)
|
|
|
|
}
|
|
|
|
Some((ArmorShopItem::unit_from_item(u).price() / 8) as u32)
|
|
|
|
// Some((ArmorShopItem::from(u).price() / 8) as u32)
|
|
|
|
return Ok((ArmorShopItem::from(u).price() / 8) as u32)
|
|
|
|
},
|
|
|
|
ItemDetail::Tool(t) => {
|
|
|
|
if !matches!(t.tool, ToolType::PhotonDrop | ToolType::PhotonSphere | ToolType::PhotonCrystal) && t.is_rare_item() {
|
|
|
|
return Some(10u32)
|
|
|
|
// return Some(10u32)
|
|
|
|
return Ok(10u32)
|
|
|
|
}
|
|
|
|
Some((ToolShopItem::tool_from_item(t).price() / 8) as u32)
|
|
|
|
// Some((ToolShopItem::from(t).price() / 8) as u32)
|
|
|
|
return Ok((ToolShopItem::from(t).price() / 8) as u32)
|
|
|
|
},
|
|
|
|
ItemDetail::TechniqueDisk(d) => { // TODO: are all techs the same?
|
|
|
|
Some((ToolShopItem::tech_from_item(d).price() / 8) as u32)
|
|
|
|
// Some((ToolShopItem::from(d).price() / 8) as u32)
|
|
|
|
return Ok((ToolShopItem::from(d).price() / 8) as u32)
|
|
|
|
},
|
|
|
|
ItemDetail::Mag(_m) => { //TODO: error. mags are not sellable
|
|
|
|
None
|
|
|
|
// None
|
|
|
|
return Err(ItemManagerError::ItemNotSellable(self.clone()))
|
|
|
|
},
|
|
|
|
ItemDetail::ESWeapon(_e) => {
|
|
|
|
Some(10u32) // TODO: check price
|
|
|
|
// Some(10u32) // TODO: check price
|
|
|
|
return Ok(10u32)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// the number of stacked items sold is handled by the caller. this is just the price of 1
|
|
|
|
InventoryItem::Stacked(stacked_item) => {
|
|
|
|
Some((ToolShopItem::tool_from_item(&stacked_item.tool).price() / 8) as u32)
|
|
|
|
// Some((ToolShopItem::from(&stacked_item.tool).price() / 8) as u32)
|
|
|
|
return Ok((ToolShopItem::from(&stacked_item.tool).price() / 8) as u32)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|