Team Fortress 2 Source Code as on 22/4/2020
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.

266 lines
11 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. #include "cbase.h"
  3. #include "econ_item_tools.h"
  4. //---------------------------------------------------------------------------------------
  5. // Purpose:
  6. //---------------------------------------------------------------------------------------
  7. const char *IEconTool::GetUseCommandLocalizationToken( const IEconItemInterface *pItem, int i ) const
  8. {
  9. Assert( i == 0 ); // Default only has 1 use, so this should be 0.
  10. Assert( pItem );
  11. Assert( pItem->GetItemDefinition() );
  12. Assert( pItem->GetItemDefinition()->GetEconTool() == this );
  13. // If we have a custom schema-specified use string, use that.
  14. return GetUseString();
  15. }
  16. //---------------------------------------------------------------------------------------
  17. // Purpose:
  18. //---------------------------------------------------------------------------------------
  19. const char* IEconTool::GetUseCommand( const IEconItemInterface *pItem, int i ) const
  20. {
  21. Assert( i == 0 ); // Default only has 1 use, so this should be 0.
  22. Assert( pItem );
  23. Assert( pItem->GetItemDefinition() );
  24. Assert( pItem->GetItemDefinition()->GetEconTool() == this );
  25. const bool bIsGCConsumable = ( ( pItem->GetItemDefinition()->GetCapabilities() & ITEM_CAP_USABLE_GC ) != 0 );
  26. return bIsGCConsumable ? "Context_UseConsumableItem" : "Context_ApplyOnItem";
  27. }
  28. //---------------------------------------------------------------------------------------
  29. // Purpose:
  30. //---------------------------------------------------------------------------------------
  31. bool IsLocalPlayerWrappedGift( const IEconItemInterface *pItem )
  32. {
  33. Assert( pItem );
  34. Assert( pItem->GetItemDefinition() );
  35. Assert( pItem->GetItemDefinition()->GetTypedEconTool<CEconTool_WrappedGift>() );
  36. static CSchemaAttributeDefHandle pAttr_GifterAccountID( "gifter account id" );
  37. uint32 unGifterAccountID;
  38. if ( !pItem->FindAttribute( pAttr_GifterAccountID, &unGifterAccountID ) )
  39. return false;
  40. const uint32 unLocalAccountID = steamapicontext->SteamUser()->GetSteamID().GetAccountID();
  41. return unGifterAccountID == unLocalAccountID;
  42. }
  43. //---------------------------------------------------------------------------------------
  44. // Purpose:
  45. //---------------------------------------------------------------------------------------
  46. bool CEconTool_WrappedGift::CanBeUsedNow( const IEconItemInterface *pItem ) const
  47. {
  48. static CSchemaItemDefHandle pItemDef_WrappedGiftapultPackage( "Wrapped Giftapult Package" );
  49. static CSchemaItemDefHandle pItemDef_DeliveredGiftapultPackage( "Delivered Giftapult Package" );
  50. static CSchemaItemDefHandle pItemDef_CompetitiveBetaPassGift( "Competitive Matchmaking Beta Giftable Invite" );
  51. Assert( pItem );
  52. Assert( pItem->GetItemDefinition() );
  53. Assert( pItem->GetItemDefinition()->GetEconTool() == this );
  54. if ( ( pItem->GetItemDefinition() == pItemDef_WrappedGiftapultPackage ) ||
  55. ( pItem->GetItemDefinition() == pItemDef_CompetitiveBetaPassGift ) ||
  56. ( pItem->GetItemDefinition() == pItemDef_DeliveredGiftapultPackage ) )
  57. return true;
  58. return pItem->IsTradable();
  59. }
  60. //---------------------------------------------------------------------------------------
  61. // Purpose:
  62. //---------------------------------------------------------------------------------------
  63. bool CEconTool_WrappedGift::ShouldShowContainedItemPanel( const IEconItemInterface *pItem ) const
  64. {
  65. Assert( pItem );
  66. Assert( pItem->GetItemDefinition() );
  67. Assert( pItem->GetItemDefinition()->GetEconTool() == this );
  68. return IsLocalPlayerWrappedGift( pItem );
  69. }
  70. //---------------------------------------------------------------------------------------
  71. // Purpose:
  72. //---------------------------------------------------------------------------------------
  73. const char *CEconTool_WrappedGift::GetUseCommandLocalizationToken( const IEconItemInterface *pItem, int i ) const
  74. {
  75. Assert( pItem );
  76. Assert( pItem->GetItemDefinition() );
  77. Assert( pItem->GetItemDefinition()->GetEconTool() == this );
  78. Assert( i == 0 || ( IsLocalPlayerWrappedGift( pItem ) && i == 1 ) );
  79. // NOTE! Keep in sync with CEconTool_WrappedGift::GetUseCommand
  80. if ( BIsDirectGift() ||
  81. ( IsLocalPlayerWrappedGift( pItem ) && i == 0 ) )
  82. return "#DeliverGift";
  83. return "#UnwrapGift";
  84. }
  85. //---------------------------------------------------------------------------------------
  86. // Purpose:
  87. //---------------------------------------------------------------------------------------
  88. int CEconTool_WrappedGift::GetUseCommandCount( const IEconItemInterface *pItem ) const
  89. {
  90. Assert( pItem );
  91. Assert( pItem->GetItemDefinition() );
  92. Assert( pItem->GetItemDefinition()->GetEconTool() == this );
  93. if ( IsLocalPlayerWrappedGift( pItem ) )
  94. return 2;
  95. return 1;
  96. }
  97. //---------------------------------------------------------------------------------------
  98. // Purpose:
  99. //---------------------------------------------------------------------------------------
  100. const char* CEconTool_WrappedGift::GetUseCommand( const IEconItemInterface *pItem, int i ) const
  101. {
  102. // NOTE! Keep in sync with CEconTool_WrappedGift::GetUseCommandLocalizationToken
  103. Assert( pItem );
  104. Assert( pItem->GetItemDefinition() );
  105. Assert( pItem->GetItemDefinition()->GetEconTool() == this );
  106. Assert( i == 0 || ( IsLocalPlayerWrappedGift( pItem ) && i == 1 ) );
  107. // NOTE! Keep in sync with CEconTool_WrappedGift::GetUseCommand
  108. if ( BIsDirectGift() ||
  109. ( IsLocalPlayerWrappedGift( pItem ) && i == 0 ) )
  110. return "Context_DeliverItem";
  111. return "Context_UnwrapItem";
  112. }
  113. //---------------------------------------------------------------------------------------
  114. // Purpose:
  115. //---------------------------------------------------------------------------------------
  116. const char *CEconTool_WeddingRing::GetUseCommandLocalizationToken( const IEconItemInterface *pItem, int i ) const
  117. {
  118. Assert( i == 0 ); // We only have one action.
  119. Assert( pItem );
  120. Assert( pItem->GetItemDefinition() );
  121. Assert( pItem->GetItemDefinition()->GetEconTool() == this );
  122. // If the wedding ring has been gifted to us, we can use it to accept/reject the proposal.
  123. // If it hasn't been gifted we can't use it at all.
  124. static CSchemaAttributeDefHandle pAttrDef_GifterAccountID( "gifter account id" );
  125. if ( !pItem->FindAttribute( pAttrDef_GifterAccountID ) )
  126. return NULL;
  127. return "#ToolAction_WeddingRing_AcceptReject";
  128. }
  129. #ifndef TF_CLIENT_DLL
  130. //---------------------------------------------------------------------------------------
  131. // Purpose:
  132. //---------------------------------------------------------------------------------------
  133. void CEconTool_Noisemaker::OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const
  134. {
  135. Assert( !"CEconTool_Noisemaker::OnClientUseConsumable() is unimplemented!" );
  136. }
  137. //-----------------------------------------------------------------------------
  138. // Purpose:
  139. //-----------------------------------------------------------------------------
  140. void CEconTool_WrappedGift::OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const
  141. {
  142. Assert( !"CEconTool_WrappedGift::OnClientUseConsumable() is unimplemented!" );
  143. }
  144. //-----------------------------------------------------------------------------
  145. // Purpose:
  146. //-----------------------------------------------------------------------------
  147. void CEconTool_WeddingRing::OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const
  148. {
  149. Assert( !"CEconTool_WeddingRing::OnClientUseConsumable() is unimplemented!" );
  150. }
  151. //-----------------------------------------------------------------------------
  152. // Purpose:
  153. //-----------------------------------------------------------------------------
  154. void CEconTool_BackpackExpander::OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const
  155. {
  156. Assert( !"CEconTool_BackpackExpander::OnClientUseConsumable() is unimplemented!" );
  157. }
  158. //-----------------------------------------------------------------------------
  159. // Purpose:
  160. //-----------------------------------------------------------------------------
  161. void CEconTool_AccountUpgradeToPremium::OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const
  162. {
  163. Assert( !"CEconTool_AccountUpgradeToPremium::OnClientUseConsumable() is unimplemented!" );
  164. }
  165. //-----------------------------------------------------------------------------
  166. // Purpose:
  167. //-----------------------------------------------------------------------------
  168. void CEconTool_ClaimCode::OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const
  169. {
  170. Assert( !"CEconTool_ClaimCode::OnClientUseConsumable() is unimplemented!" );
  171. }
  172. //-----------------------------------------------------------------------------
  173. // Purpose:
  174. //-----------------------------------------------------------------------------
  175. void CEconTool_Collection::OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const
  176. {
  177. Assert( !"CEconTool_Collection::OnClientUseConsumable() is unimplemented!" );
  178. }
  179. //-----------------------------------------------------------------------------
  180. // Purpose:
  181. //-----------------------------------------------------------------------------
  182. void CEconTool_StrangifierBase::OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const
  183. {
  184. Assert( !"CEconTool_StrangifierBase::OnClientUseConsumable() is unimplemented!" );
  185. }
  186. //-----------------------------------------------------------------------------
  187. // Purpose:
  188. //-----------------------------------------------------------------------------
  189. void CEconTool_PaintCan::OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const
  190. {
  191. Assert( !"CEconTool_PaintCan::OnClientUseConsumable() is unimplemented!" );
  192. }
  193. //-----------------------------------------------------------------------------
  194. // Purpose:
  195. //-----------------------------------------------------------------------------
  196. void CEconTool_Gift::OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const
  197. {
  198. Assert( !"CEconTool_Gift::OnClientUseConsumable() is unimplemented!" );
  199. }
  200. //-----------------------------------------------------------------------------
  201. // Purpose:
  202. //-----------------------------------------------------------------------------
  203. void CEconTool_DuelingMinigame::OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const
  204. {
  205. Assert( !"CEconTool_DuelingMinigame::OnClientUseConsumable() is unimplemented!" );
  206. }
  207. //-----------------------------------------------------------------------------
  208. void CEconTool_DuckToken::OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const
  209. {
  210. Assert( !"CEconTool_DuckToken::OnClientUseConsumable() is unimplemented!" );
  211. }
  212. //-----------------------------------------------------------------------------
  213. void CEconTool_GrantOperationPass::OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const
  214. {
  215. Assert( !"CEconTool_DuckToken::CEconTool_GrantOperationPass() is unimplemented!" );
  216. }
  217. //-----------------------------------------------------------------------------
  218. // Purpose:
  219. //-----------------------------------------------------------------------------
  220. void CEconTool_Default::OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const
  221. {
  222. Assert( !"CEconTool_Default::OnClientUseConsumable() is unimplemented!" );
  223. }
  224. #endif // !defined( TF_CLIENT_DLL )