@ -9,9 +9,10 @@ use crate::ship::map::MapArea;
use crate ::ship ::location ::{ AreaClient , RoomId } ;
use crate ::entity ::character ::{ CharacterEntity , CharacterEntityId } ;
use crate ::entity ::gateway ::{ EntityGateway , GatewayError } ;
use crate ::entity ::item ::tool ::Tool ;
use crate ::entity ::item ::tool ::{ Tool , ToolType } ;
use crate ::entity ::item ::mag ::Mag ;
use crate ::ship ::drops ::ItemDrop ;
use crate ::ship ::shops ::{ ShopItem , ArmorShopItem , ToolShopItem , WeaponShopItem } ;
// TODO: Commit trait that ItemStateProxy and EntityTransaction implement that .commit requires and acts on upon everything succeeding (like 3 less lines of code!)
@ -65,6 +66,9 @@ pub enum ItemStateError {
#[ error( " item is not mag food {0} " ) ]
NotMagFood ( ClientItemId ) ,
#[ error( " item is not sellable " ) ]
ItemNotSellable ,
}
pub enum FloorType {
@ -299,6 +303,64 @@ impl InventoryItemDetail {
} ,
}
}
// TODO: this should probably go somewhere a bit more fundamental like ItemDetail
pub fn sell_price ( & self ) -> Result < u32 , ItemStateError > {
match self {
InventoryItemDetail ::Individual ( individual_item ) = > {
match & individual_item . item {
// TODO: can wrapped items be sold?
ItemDetail ::Weapon ( w ) = > {
if ! w . tekked {
return Ok ( 1 u32 )
}
if w . is_rare_item ( ) {
return Ok ( 10 u32 )
}
Ok ( ( WeaponShopItem ::from ( w ) . price ( ) / 8 ) as u32 )
} ,
ItemDetail ::Armor ( a ) = > {
if a . is_rare_item ( ) {
return Ok ( 10 u32 )
}
Ok ( ( ArmorShopItem ::from ( a ) . price ( ) / 8 ) as u32 )
} ,
ItemDetail ::Shield ( s ) = > {
if s . is_rare_item ( ) {
return Ok ( 10 u32 )
}
Ok ( ( ArmorShopItem ::from ( s ) . price ( ) / 8 ) as u32 )
} ,
ItemDetail ::Unit ( u ) = > {
if u . is_rare_item ( ) {
return Ok ( 10 u32 )
}
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 Ok ( 10 u32 )
}
Ok ( ( ToolShopItem ::from ( t ) . price ( ) / 8 ) as u32 )
} ,
ItemDetail ::TechniqueDisk ( d ) = > {
Ok ( ( ToolShopItem ::from ( d ) . price ( ) / 8 ) as u32 )
} ,
ItemDetail ::Mag ( _m ) = > {
Err ( ItemStateError ::ItemNotSellable )
} ,
ItemDetail ::ESWeapon ( _e ) = > {
Ok ( 10 u32 )
} ,
}
} ,
// the number of stacked items sold is handled by the caller. this is just the price of 1
InventoryItemDetail ::Stacked ( stacked_item ) = > {
Ok ( ( ( ToolShopItem ::from ( & stacked_item . tool ) . price ( ) / 8 ) as u32 ) * stacked_item . count ( ) as u32 )
} ,
}
}
}