Browse Source

cleanup todos

pull/47/head
andy 3 years ago
parent
commit
66d882d336
  1. 21
      src/ship/items/inventory.rs
  2. 10
      src/ship/items/manager.rs

21
src/ship/items/inventory.rs

@ -222,7 +222,6 @@ impl InventoryItem {
}
}
// pub fn get_sell_price(&self) -> Option<u32> {
pub fn get_sell_price(&self) -> Result<u32, ItemManagerError> {
match self {
InventoryItem::Individual(individual_item) => {
@ -230,66 +229,50 @@ impl InventoryItem {
// TODO: can wrapped items be sold?
ItemDetail::Weapon(w) => {
if !w.tekked {
// return Some(1u32)
return Ok(1u32)
}
if w.is_rare_item() {
// return Some(10u32)
return Ok(10u32)
}
// other item factors?
// 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 Ok(10u32)
}
// 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 Ok(10u32)
}
// 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 Ok(10u32)
}
// 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 Ok(10u32)
}
// 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::from(d).price() / 8) as u32)
ItemDetail::TechniqueDisk(d) => {
return Ok((ToolShopItem::from(d).price() / 8) as u32)
},
ItemDetail::Mag(_m) => { //TODO: error. mags are not sellable
// None
ItemDetail::Mag(_m) => {
return Err(ItemManagerError::ItemNotSellable(self.clone()))
},
ItemDetail::ESWeapon(_e) => {
// 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::from(&stacked_item.tool).price() / 8) as u32)
return Ok((ToolShopItem::from(&stacked_item.tool).price() / 8) as u32)
},
}

10
src/ship/items/manager.rs

@ -56,8 +56,9 @@ pub enum ItemManagerError {
NoArmorEquipped,
GatewayError(#[from] crate::entity::gateway::GatewayError),
StackedItemError(Vec<ItemEntity>),
ItemNotSellable(InventoryItem), // TODO: capture what item was attempted to be sold
ItemNotSellable(InventoryItem),
WalletFull,
InvalidSale,
}
pub struct ItemManager {
@ -856,8 +857,7 @@ impl ItemManager {
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
let sold_item_handle = inventory.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?;
if let Some(item_sold) = sold_item_handle.item() {
// if let Some(unit_price) = item_sold.get_sell_price() { // -> Option<u32> u32 = meseta, or None if error
let unit_price = item_sold.get_sell_price()?; { // -> Result<u32, ItemManagerError> // ItemMangerError::InvalidSale
let unit_price = item_sold.get_sell_price()?; {
let total_sale = unit_price * amount as u32;
if character.meseta + total_sale <= 999999 {
character.meseta += total_sale;
@ -871,8 +871,7 @@ impl ItemManager {
Ordering::Less | Ordering::Equal => {
sold_item_handle.consume(amount)?;
},
// TODO: put a real error here
Ordering::Greater => {println!("i can't believe you've done this.");},
Ordering::Greater => return Err(ItemManagerError::InvalidSale.into()),
};
},
}
@ -885,7 +884,6 @@ impl ItemManager {
} else {
return Err(ItemManagerError::ItemIdNotInInventory(item_id).into())
}
// TODO: why did i put this
Ok(())
}

Loading…
Cancel
Save