Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

310 lines
8.7 KiB

  1. #include "cbase.h"
  2. #include "econ_item_interface.h"
  3. // --------------------------------------------------------------------------
  4. // Purpose:
  5. // --------------------------------------------------------------------------
  6. RTime32 IEconItemInterface::GetExpirationDate() const
  7. {
  8. COMPILE_TIME_ASSERT( sizeof( float ) == sizeof( RTime32 ) );
  9. // dynamic attributes, if present, will override any static expiration timer
  10. static CSchemaAttributeDefHandle pAttrib_ExpirationDate( "expiration date" );
  11. attrib_value_t unAttribExpirationTimeBits;
  12. COMPILE_TIME_ASSERT( sizeof( unAttribExpirationTimeBits ) == sizeof( RTime32 ) );
  13. if ( pAttrib_ExpirationDate && FindAttribute( pAttrib_ExpirationDate, &unAttribExpirationTimeBits ) )
  14. return *(RTime32 *)&unAttribExpirationTimeBits;
  15. // do we have a static timer set in the schema for all instances to expire?
  16. return GetItemDefinition()
  17. ? GetItemDefinition()->GetExpirationDate()
  18. : RTime32( 0 );
  19. }
  20. // --------------------------------------------------------------------------
  21. // Purpose:
  22. // --------------------------------------------------------------------------
  23. RTime32 IEconItemInterface::GetTradableAfterDateTime() const
  24. {
  25. static CSchemaAttributeDefHandle pAttrib( "tradable after date" );
  26. Assert( pAttrib );
  27. if ( !pAttrib )
  28. return 0;
  29. RTime32 rtTimestamp;
  30. if ( !FindAttribute( pAttrib, &rtTimestamp ) )
  31. return 0;
  32. return rtTimestamp;
  33. }
  34. RTime32 IEconItemInterface::GetUseAfterDateTime() const
  35. {
  36. static CSchemaAttributeDefHandle pAttrib( "use after date" );
  37. Assert( pAttrib );
  38. if ( !pAttrib )
  39. return 0;
  40. RTime32 rtTimestamp;
  41. if ( !FindAttribute( pAttrib, &rtTimestamp ) )
  42. return 0;
  43. return rtTimestamp;
  44. }
  45. RTime32 IEconItemInterface::GetCacheRefreshDateTime() const
  46. {
  47. RTime32 rtExpiration = 0;
  48. /** Removed for partner depot **/
  49. return rtExpiration;
  50. }
  51. int IEconItemInterface::GetCustomPaintKitIndex( void ) const
  52. {
  53. static CSchemaAttributeDefHandle pAttrDef_PaintKit( "set item texture prefab" );
  54. float flPaintKit = 0;
  55. FindAttribute_UnsafeBitwiseCast<attrib_value_t>( this, pAttrDef_PaintKit, &flPaintKit );
  56. return flPaintKit;
  57. }
  58. int IEconItemInterface::GetCustomPaintKitSeed( void ) const
  59. {
  60. static CSchemaAttributeDefHandle pAttrDef_PaintKitSeed( "set item texture seed" );
  61. float flPaintSeed = 0;
  62. FindAttribute_UnsafeBitwiseCast<attrib_value_t>( this, pAttrDef_PaintKitSeed, &flPaintSeed );
  63. return flPaintSeed;
  64. }
  65. float IEconItemInterface::GetCustomPaintKitWear( float flWearDefault /*= 0.0f*/ ) const
  66. {
  67. static CSchemaAttributeDefHandle pAttrDef_PaintKitWear( "set item texture wear" );
  68. float flPaintKitWear = flWearDefault;
  69. FindAttribute_UnsafeBitwiseCast<attrib_value_t>( this, pAttrDef_PaintKitWear, &flPaintKitWear );
  70. return flPaintKitWear;
  71. }
  72. float IEconItemInterface::GetStickerAttributeBySlotIndexFloat( int nSlotIndex, EStickerAttributeType type, float flDefault ) const
  73. {
  74. const CSchemaAttributeDefHandle &attrDef = GetStickerAttributeDefHandle( nSlotIndex, type );
  75. if ( attrDef )
  76. {
  77. if ( attrDef->IsStoredAsFloat() )
  78. {
  79. float flOutput = 0.0f;
  80. if ( FindAttribute_UnsafeBitwiseCast< attrib_value_t >( this, attrDef, &flOutput ) )
  81. {
  82. return flOutput;
  83. }
  84. }
  85. else
  86. {
  87. Assert( false );
  88. }
  89. }
  90. return flDefault;
  91. }
  92. uint32 IEconItemInterface::GetStickerAttributeBySlotIndexInt( int nSlotIndex, EStickerAttributeType type, uint32 uiDefault ) const
  93. {
  94. const CSchemaAttributeDefHandle &attrDef = GetStickerAttributeDefHandle( nSlotIndex, type );
  95. if ( attrDef )
  96. {
  97. if ( attrDef->IsStoredAsFloat() )
  98. {
  99. Assert( false );
  100. }
  101. else
  102. {
  103. uint32 unOutput;
  104. if ( FindAttribute( attrDef, &unOutput ) )
  105. {
  106. return unOutput;
  107. }
  108. }
  109. }
  110. return uiDefault;
  111. }
  112. // --------------------------------------------------------------------------
  113. // Purpose:
  114. // --------------------------------------------------------------------------
  115. bool IEconItemInterface::IsTradable() const
  116. {
  117. /** Removed for partner depot **/
  118. return false;
  119. }
  120. bool IEconItemInterface::IsPotentiallyTradable() const
  121. {
  122. if ( GetItemDefinition() == NULL )
  123. return false;
  124. // check attributes
  125. static CSchemaAttributeDefHandle pAttrDef_AlwaysTradableAndUsableInCrafting( "always tradable" );
  126. static CSchemaAttributeDefHandle pAttrib_CannotTrade( "cannot trade" );
  127. Assert( pAttrDef_AlwaysTradableAndUsableInCrafting != NULL );
  128. Assert( pAttrib_CannotTrade != NULL );
  129. if ( pAttrDef_AlwaysTradableAndUsableInCrafting == NULL || pAttrib_CannotTrade == NULL )
  130. return false;
  131. // NOTE: we are not checking the time delay on trade restriction here - the item is considered potentially tradable in future = true
  132. // if ( GetTradableAfterDateTime() > CRTime::RTime32TimeCur() )
  133. // return false;
  134. // Explicit rules by item quality to validate trading eligibility
  135. switch ( GetQuality() )
  136. {
  137. case AE_UNIQUE:
  138. break;
  139. case AE_STRANGE:
  140. return ( GetOrigin() == kEconItemOrigin_FoundInCrate || GetOrigin() == kEconItemOrigin_Crafted || GetOrigin() == kEconItemOrigin_Purchased );
  141. case AE_UNUSUAL:
  142. case AE_TOURNAMENT:
  143. return ( GetOrigin() == kEconItemOrigin_FoundInCrate );
  144. default:
  145. // all other qualities are untradable
  146. return false;
  147. }
  148. if ( FindAttribute( pAttrDef_AlwaysTradableAndUsableInCrafting ) )
  149. return true;
  150. if ( FindAttribute( pAttrib_CannotTrade ) )
  151. return false;
  152. // items gained in this way are not tradable
  153. switch ( GetOrigin() )
  154. {
  155. case kEconItemOrigin_Invalid:
  156. case kEconItemOrigin_Achievement:
  157. case kEconItemOrigin_Foreign:
  158. case kEconItemOrigin_PreviewItem:
  159. case kEconItemOrigin_SteamWorkshopContribution:
  160. case kEconItemOrigin_StockItem:
  161. return false;
  162. }
  163. // certain quality levels are not tradable
  164. if ( GetQuality() >= AE_COMMUNITY && GetQuality() <= AE_SELFMADE )
  165. return false;
  166. // explicitly marked cannot trade?
  167. if ( ( kEconItemFlags_CheckFlags_CannotTrade & GetFlags() ) != 0 )
  168. return false;
  169. // tagged to not be a part of the economy?
  170. if ( ( kEconItemFlag_NonEconomy & GetFlags() ) != 0 )
  171. return false;
  172. // This code catches stock items with name tags (rarity is stock) and prevents them from trading/marketing
  173. // until we have a better solution for extracting value out of reselling these items and avoiding scams
  174. if ( GetRarity() <= 0 )
  175. return false;
  176. return true;
  177. }
  178. // --------------------------------------------------------------------------
  179. // Purpose:
  180. // --------------------------------------------------------------------------
  181. bool IEconItemInterface::IsMarketable() const
  182. {
  183. /** Removed for partner depot **/
  184. return false;
  185. }
  186. // --------------------------------------------------------------------------
  187. // Purpose:
  188. // --------------------------------------------------------------------------
  189. bool IEconItemInterface::IsCommodity() const
  190. {
  191. const CEconItemDefinition *pItemDef = GetItemDefinition();
  192. if ( pItemDef == NULL )
  193. return false;
  194. static CSchemaAttributeDefHandle pAttrib_IsCommodity( "is commodity" );
  195. Assert( pAttrib_IsCommodity != NULL );
  196. if ( pAttrib_IsCommodity == NULL )
  197. return false;
  198. attrib_value_t unAttribValue;
  199. if ( FindAttribute( pAttrib_IsCommodity, &unAttribValue ) && unAttribValue )
  200. return true;
  201. return false;
  202. }
  203. bool IEconItemInterface::IsHiddenFromDropList() const
  204. {
  205. const CEconItemDefinition *pItemDef = GetItemDefinition();
  206. if ( pItemDef == NULL )
  207. return false;
  208. static CSchemaAttributeDefHandle pAttrib_HideFromDropList( "hide from drop list" );
  209. Assert( pAttrib_HideFromDropList != NULL );
  210. if ( pAttrib_HideFromDropList == NULL )
  211. return false;
  212. attrib_value_t unAttribValue;
  213. if ( FindAttribute( pAttrib_HideFromDropList, &unAttribValue ) && unAttribValue )
  214. return true;
  215. return false;
  216. }
  217. // --------------------------------------------------------------------------
  218. // Purpose:
  219. // --------------------------------------------------------------------------
  220. bool IEconItemInterface::IsUsableInCrafting() const
  221. {
  222. if ( GetItemDefinition() == NULL )
  223. return false;
  224. // check attribute
  225. static CSchemaAttributeDefHandle pAttrDef_AlwaysTradableAndUsableInCrafting( "always tradable" );
  226. Assert( pAttrDef_AlwaysTradableAndUsableInCrafting );
  227. if ( FindAttribute( pAttrDef_AlwaysTradableAndUsableInCrafting ) )
  228. return true;
  229. // explicitly marked not usable in crafting?
  230. if ( ( kEconItemFlags_CheckFlags_NotUsableInCrafting & GetFlags() ) != 0 )
  231. return false;
  232. // items gained in this way are not craftable
  233. switch ( GetOrigin() )
  234. {
  235. case kEconItemOrigin_Invalid:
  236. case kEconItemOrigin_Foreign:
  237. case kEconItemOrigin_PreviewItem:
  238. case kEconItemOrigin_Purchased:
  239. case kEconItemOrigin_StorePromotion:
  240. case kEconItemOrigin_SteamWorkshopContribution:
  241. return false;
  242. }
  243. // certain quality levels are not craftable
  244. if ( GetQuality() >= AE_COMMUNITY && GetQuality() <= AE_SELFMADE )
  245. return false;
  246. // tagged to not be a part of the economy?
  247. if ( ( kEconItemFlag_NonEconomy & GetFlags() ) != 0 )
  248. return false;
  249. return true;
  250. }