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.

1043 lines
39 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. #ifndef ECONITEMTOOLS_H
  3. #define ECONITEMTOOLS_H
  4. #ifdef _WIN32
  5. #pragma once
  6. #endif
  7. enum EConsumptionAttemptResult
  8. {
  9. kConsumptionResult_CannotConsume, // could be bum definitions or doesnt meet criteria or anything -- this is failure
  10. kConsumptionResult_CanConsume, // able to consume
  11. kConsumptionResult_WillCompleteCollection, // able to consume and is the final item to be consumed
  12. };
  13. //---------------------------------------------------------------------------------------
  14. // Purpose:
  15. //---------------------------------------------------------------------------------------
  16. class CEconSharedToolSupport
  17. {
  18. public:
  19. // Can the given tool instance apply to a specific instance of an item. This should be used in the general
  20. // case whenever a CEconItem or a CEconItemView is available.
  21. static bool ToolCanApplyTo( const IEconItemInterface *pToolDef, const IEconItemInterface *pToolSubject );
  22. // Can the given tool definition apply to an item definition? This will check things like restrictions,
  23. // matching tool capabilities, etc. but will ignore instance-specific properties. This should only be used
  24. // by code that doesn't have any access to an instance of the definition.
  25. static bool ToolCanApplyToDefinition( const GameItemDefinition_t *pToolDef, const GameItemDefinition_t *pToolSubjectDef );
  26. // Can the given tool definition apply to a base item definition?
  27. static bool ToolCanApplyToBaseItem( const GameItemDefinition_t *pToolDef, const GameItemDefinition_t *pToolSubjectDef );
  28. };
  29. //---------------------------------------------------------------------------------------
  30. // Purpose:
  31. //---------------------------------------------------------------------------------------
  32. class CEconTool_DuelingMinigame : public IEconTool
  33. {
  34. public:
  35. CEconTool_DuelingMinigame( const char *pszTypeName, const char *pszUseString ) : IEconTool( pszTypeName, pszUseString, NULL, ITEM_CAP_NONE ) { }
  36. #ifdef CLIENT_DLL
  37. virtual void OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const;
  38. #endif // CLIENT_DLL
  39. #ifdef GC_DLL
  40. virtual class CGCEconConsumableBehavior *CreateGCConsumableBehavior() const;
  41. #endif // GC_DLL
  42. };
  43. //---------------------------------------------------------------------------------------
  44. // Purpose:
  45. //---------------------------------------------------------------------------------------
  46. class CEconTool_Noisemaker : public IEconTool
  47. {
  48. public:
  49. CEconTool_Noisemaker( const char *pszTypeName, const char *pszUseString ) : IEconTool( pszTypeName, pszUseString, NULL, ITEM_CAP_NONE ) { }
  50. #ifdef CLIENT_DLL
  51. virtual void OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const;
  52. #endif // CLIENT_DLL
  53. };
  54. //---------------------------------------------------------------------------------------
  55. // Purpose:
  56. //---------------------------------------------------------------------------------------
  57. class CEconTool_WrappedGift : public IEconTool
  58. {
  59. public:
  60. CEconTool_WrappedGift( const char *pszTypeName, const char *pszUseString, item_capabilities_t unCapabilities, KeyValues *pUsageKV );
  61. virtual bool BFinishInitialization() OVERRIDE;
  62. bool BIsGlobalGift() const { return m_bIsGlobalGift; }
  63. // Allows the item to be directly used rather than via the trading system
  64. bool BIsDirectGift() const { return m_bIsDirectGift; }
  65. const CEconItemDefinition *GetDeliveredItemDefinition() const { return m_pDeliveredGiftItemDef; } // can return NULL! (means "don't change definitions on delivery")
  66. #ifdef CLIENT_DLL
  67. virtual bool CanBeUsedNow( const IEconItemInterface *pItem ) const;
  68. virtual bool ShouldShowContainedItemPanel( const IEconItemInterface *pItem ) const;
  69. virtual const char *GetUseCommandLocalizationToken( const IEconItemInterface *pItem, int i = 0 ) const;
  70. virtual void OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const;
  71. virtual int GetUseCommandCount( const IEconItemInterface *pItem ) const;
  72. virtual const char* GetUseCommand( const IEconItemInterface *pItem, int i = 0 ) const;
  73. #endif // CLIENT_DLL
  74. #ifdef GC_DLL
  75. virtual class CGCEconConsumableBehavior *CreateGCConsumableBehavior() const;
  76. #endif // GC_DLL
  77. private:
  78. const char *m_pszDeliveredGiftItemDefName; // points to memory inside our init KV -- only valid between the constructor call and the BFinishInitialization() call (this is messy but Fletcher and I agree it makes more sense than switching to a full two-pass schema parse just for this)
  79. const CEconItemDefinition *m_pDeliveredGiftItemDef;
  80. bool m_bIsGlobalGift;
  81. bool m_bIsDirectGift;
  82. };
  83. //---------------------------------------------------------------------------------------
  84. // Purpose:
  85. //---------------------------------------------------------------------------------------
  86. class CEconTool_WeddingRing : public IEconTool
  87. {
  88. public:
  89. CEconTool_WeddingRing( const char *pszTypeName, const char *pszUseString, item_capabilities_t unCapabilities ) : IEconTool( pszTypeName, pszUseString, NULL, unCapabilities ) { }
  90. virtual bool RequiresToolEscrowPeriod() const { return false; }
  91. #ifdef CLIENT_DLL
  92. virtual const char *GetUseCommandLocalizationToken( const IEconItemInterface *pItem, int i = 0 ) const;
  93. virtual void OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const;
  94. #endif // CLIENT_DLL
  95. #ifdef GC_DLL
  96. virtual class CGCEconConsumableBehavior *CreateGCConsumableBehavior() const;
  97. #endif // GC_DLL
  98. };
  99. //---------------------------------------------------------------------------------------
  100. // Purpose:
  101. //---------------------------------------------------------------------------------------
  102. class CEconTool_TagsList
  103. {
  104. public:
  105. CEconTool_TagsList( KeyValues *pKVTags )
  106. {
  107. if ( pKVTags )
  108. {
  109. FOR_EACH_SUBKEY( pKVTags, pKVTag )
  110. {
  111. m_vecTags.AddToTail( GetItemSchema()->GetHandleForTag( pKVTag->GetName() ) );
  112. }
  113. }
  114. }
  115. const CUtlVector<econ_tag_handle_t>& GetTagsList() const { return m_vecTags; }
  116. private:
  117. CUtlVector<econ_tag_handle_t> m_vecTags;
  118. };
  119. //---------------------------------------------------------------------------------------
  120. // Purpose:
  121. //---------------------------------------------------------------------------------------
  122. class CEconTool_StrangeCountTransfer : public IEconTool
  123. {
  124. public:
  125. CEconTool_StrangeCountTransfer( const char *pszTypeName, item_capabilities_t unCapabilities );
  126. static bool AreItemsEligibleForStrangeCountTransfer( const IEconItemInterface *pItem1, const IEconItemInterface *pItem2 );
  127. #ifdef CLIENT_DLL
  128. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  129. //virtual void OnClientApplyCommit( CEconItemView *pTool, CEconItemView *pSubject ) const;
  130. bool SetItems( CEconItemView *pItem1, CEconItemView *pItem2 );
  131. CEconItemView *m_pItemSrc;
  132. CEconItemView *m_pItemDest;
  133. #endif
  134. };
  135. //---------------------------------------------------------------------------------------
  136. // Purpose:
  137. //---------------------------------------------------------------------------------------
  138. class CEconTool_StrangePart : public IEconTool
  139. {
  140. public:
  141. CEconTool_StrangePart( const char *pszTypeName, const char *pszUseString, item_capabilities_t unCapabilities, KeyValues *pUsageKV )
  142. : IEconTool( pszTypeName, pszUseString, NULL, unCapabilities )
  143. , m_RequiredTags( pUsageKV ? pUsageKV->FindKey( "required_tags" ) : NULL )
  144. , m_RequiredMissingTags( pUsageKV ? pUsageKV->FindKey( "required_missing_tags" ) : NULL )
  145. {
  146. //
  147. }
  148. virtual bool CanApplyTo( const IEconItemInterface *pTool, const IEconItemInterface *pToolSubject ) const;
  149. #ifdef CLIENT_DLL
  150. virtual bool ShouldDisplayAsUseableOnItemsInArmory() const { return false; }
  151. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  152. #endif // CLIENT_DLL
  153. private:
  154. CEconTool_TagsList m_RequiredTags;
  155. CEconTool_TagsList m_RequiredMissingTags;
  156. };
  157. //---------------------------------------------------------------------------------------
  158. // Purpose:
  159. //---------------------------------------------------------------------------------------
  160. class CEconTool_StrangePartRestriction : public IEconTool
  161. {
  162. public:
  163. CEconTool_StrangePartRestriction( const char *pszTypeName, const char *pszUseString, item_capabilities_t unCapabilities, KeyValues *pUsageKV );
  164. virtual bool CanApplyTo( const IEconItemInterface *pTool, const IEconItemInterface *pToolSubject ) const;
  165. virtual bool BFinishInitialization() OVERRIDE;
  166. #ifdef CLIENT_DLL
  167. virtual bool ShouldDisplayAsUseableOnItemsInArmory() const { return false; }
  168. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  169. #endif // CLIENT_DLL
  170. unsigned int GetRestrictionType() const { return m_eRestrictionType; }
  171. unsigned int GetRestrictionValue() const { return m_unRestrictionValue; }
  172. private:
  173. unsigned int /*strange_event_restriction_t*/ m_eRestrictionType;
  174. const char *m_pszRestrictionValue; // points to memory inside our init KV -- only valid between the constructor call and the BFinishInitialization() call (this is messy but Fletcher and I agree it makes more sense than switching to a full two-pass schema parse just for this)
  175. unsigned int m_unRestrictionValue;
  176. };
  177. //---------------------------------------------------------------------------------------
  178. // Purpose: New crafting! This new systems allows for dynamic crafting recipes to be
  179. // generated in the form of an item itself. Players can "feed" in items on the
  180. // recipe's input list, either all at once or once at a time, until the inputs
  181. // are all fulfilled. Once that happens at which the outputs of the recipe are given to the player.
  182. //
  183. // This is done using new attribute types that encode the recipe's inputs and outputs.
  184. // Inputs and outputs can either be specific items of specific qualities, or lootlist
  185. // with a specific quality -- for now. Lootlist will roll the specific item to be the input/output
  186. // when the recipe item is created. Any gc generated attributes that would come
  187. // from the lootlists will also get encoded as a string in the recipe's attribute, so things like
  188. // unusual particle effects will get applied to outputs. These string-encoded attributes
  189. // are ignored during input criteria matching for now.
  190. //
  191. // Components are allowed to have nested components defined within them. These child
  192. // components only roll their chance to apply if their parent successfully rolls their
  193. // chance to apply.
  194. //---------------------------------------------------------------------------------------
  195. class CEconTool_ItemDynamicRecipe : public IEconTool
  196. {
  197. public:
  198. // This enum lets the CDynamicRecipeComponentLootList class specify
  199. // "uniqueness" of the item def that it will roll. This allows us to
  200. // do things like ensure that the output item will never be one of the
  201. // input items, or there's never duplicate inputs.
  202. enum EItemDefUniqueness_t
  203. {
  204. UNIQUE_AMONG_INPUTS = 0,
  205. UNIQUE_AMONG_OUTPUTS,
  206. UNIQUE_AMONG_EVERYTHING,
  207. UNIQUE_AMONG_NOTHING,
  208. };
  209. CEconTool_ItemDynamicRecipe( const char *pszTypeName, const char *pszUseString, item_capabilities_t unCapabilities, KeyValues *pUsageKV );
  210. ~CEconTool_ItemDynamicRecipe();
  211. virtual bool CanApplyTo( const IEconItemInterface *pTool, const IEconItemInterface *pToolSubject ) const;
  212. virtual bool BFinishInitialization() OVERRIDE;
  213. #ifdef CLIENT_DLL
  214. virtual bool ShouldDisplayAsUseableOnItemsInArmory() const { return false; }
  215. #endif // CLIENT_DLL
  216. virtual bool BInitFromKV( KeyValues *pKVDefinition, CUtlVector<CUtlString> *pVecErrors );
  217. #ifdef GC_DLL
  218. virtual bool BGenerateDynamicAttributes( CEconItem* pItem, const CEconGameAccount *pGameAccount ) const OVERRIDE;
  219. #endif
  220. class CBaseRecipeComponent
  221. {
  222. public:
  223. struct StringEncodedAttribute_t
  224. {
  225. attrib_definition_index_t m_AttrIndex;
  226. CUtlConstString m_strAttrData;
  227. };
  228. struct CountChance_t
  229. {
  230. int m_nMinCount;
  231. int m_nMaxCount;
  232. float m_flChance;
  233. };
  234. typedef CUtlVector<const CEconItemAttributeDefinition *> ComponentAttribVector_t;
  235. CBaseRecipeComponent( bool bIsOutput, const CBaseRecipeComponent* pParent );
  236. virtual ~CBaseRecipeComponent();
  237. static bool ParseComponentsBlock( KeyValues *pKV, CUtlVector<CBaseRecipeComponent*>& vecComponents, CUtlVector<CUtlString> *pVecErrors, const CBaseRecipeComponent* pParent );
  238. static bool ParseComponents( KeyValues *pKV, CUtlVector<CBaseRecipeComponent*>& vecComponents, bool bIsOutput, CUtlVector<CUtlString> *pVecErrors, const CBaseRecipeComponent* pParent );
  239. virtual bool ParseKV( KeyValues *pKV, CUtlVector<CUtlString> *pVecErrors );
  240. void SetIsOutput( bool bIsOutput ) { m_bIsOutput = bIsOutput; }
  241. void SetParent( CBaseRecipeComponent* pParent ) { m_pParent = pParent; }
  242. void SetChanceOfApplying( float flChance );
  243. virtual bool BFinishInitialization_Internal( CUtlVector<CUtlString>* pVecErrors, ComponentAttribVector_t* attribVec );
  244. bool GetIsOutput() const { return m_bIsOutput; }
  245. void GetIsGuaranteed( int &nFlags ) const;
  246. const CUtlVector< CountChance_t >& GetRollChances() const { return m_vecCountChances; }
  247. #ifdef GC_DLL
  248. bool RollChanceOfApplying() const;
  249. float GetRollChance() const { return m_flChanceOfApplying; }
  250. int RollCount() const;
  251. virtual bool AddRecipeComponentAsAttribute( CEconItem *pItem, const CEconGameAccount *pGameAccount ) const = 0;
  252. #endif
  253. protected:
  254. #ifdef GC_DLL
  255. virtual const char* GetAttributeName() const { return "recipe component defined item"; }
  256. static CEconItemAttributeDefinition* GetNextAvailableAttributeWithBaseName( const char* pszBaseAttribName, ComponentAttribVector_t *pAttribVec );
  257. #endif
  258. const CBaseRecipeComponent* m_pParent;
  259. CUtlVector< CBaseRecipeComponent* > m_vecAdditionalComponents;
  260. float m_flChanceOfApplying;
  261. bool m_bIsOutput;
  262. CUtlVector< CountChance_t > m_vecCountChances;
  263. float m_flTotalWeights;
  264. EEconItemQuality m_eQuality;
  265. enum EAttributesMatchingType_t
  266. {
  267. ATTRIBUTES_MATCH_NONE = 0,
  268. ATTRIBUTES_MATCH_ALL,
  269. ATTRIBUTES_MATCH_ANY,
  270. };
  271. EAttributesMatchingType_t m_attributesMatchingType;
  272. CUtlVector< StringEncodedAttribute_t > m_vecDynamicAttributes;
  273. CUtlString m_strName;
  274. static const char* m_pszUseParentNameIdentifier;
  275. };
  276. public:
  277. class CDynamicRecipeComponentLootList;
  278. // Defined item type: Use this when you want to quickly define a specific item as
  279. // a component for a recipe. A "defined item" is considered an
  280. // itemdef, a quality, and any additional attributes.
  281. class CDynamicRecipeComponentDefinedItem : public CBaseRecipeComponent
  282. {
  283. typedef CBaseRecipeComponent BaseClass;
  284. public:
  285. CDynamicRecipeComponentDefinedItem( bool bIsOutput, const CBaseRecipeComponent* pParent );
  286. virtual ~CDynamicRecipeComponentDefinedItem();
  287. virtual bool BFinishInitialization_Internal( CUtlVector<CUtlString>* pVecErrors, ComponentAttribVector_t* attribVec ) OVERRIDE;
  288. #ifdef GC_DLL
  289. virtual bool AddRecipeComponentAsAttribute( CEconItem *pItem, const CEconGameAccount *pGameAccount ) const OVERRIDE;
  290. #endif
  291. protected:
  292. virtual bool ParseKV( KeyValues *pKV, CUtlVector<CUtlString> *pVecErrors ) OVERRIDE;
  293. friend class CDynamicRecipeComponentLootList;
  294. };
  295. // Lootlist type: Use this when you want a random item from a lootlist to be a
  296. // component in a recipe. You must specify a quality in the definition
  297. // but it can get stomped if the lootlist-generated item gets an "elevate quality"
  298. // attribute rolled onto it.
  299. class CDynamicRecipeComponentLootList : public CBaseRecipeComponent
  300. {
  301. typedef CBaseRecipeComponent BaseClass;
  302. public:
  303. CDynamicRecipeComponentLootList( bool bIsOutput, const CBaseRecipeComponent* pParent );
  304. virtual ~CDynamicRecipeComponentLootList();
  305. virtual bool BFinishInitialization_Internal( CUtlVector<CUtlString>* pVecErrors, ComponentAttribVector_t* attribVec ) OVERRIDE;
  306. protected:
  307. virtual bool ParseKV( KeyValues *pKV, CUtlVector<CUtlString> *pVecErrors ) OVERRIDE;
  308. private:
  309. #ifdef GC_DLL
  310. virtual bool AddRecipeComponentAsAttribute( CEconItem *pItem, const CEconGameAccount *pGameAccount ) const OVERRIDE;
  311. bool RollLootlistItemAndAttributes( CUtlVector< StringEncodedAttribute_t >& vecAdditionalAttributes
  312. , const char** pszDefName
  313. , const CUtlVector< item_definition_index_t > *pVecAvoidItemDefs
  314. , const CEconGameAccount *pGameAccount ) const;
  315. EItemDefUniqueness_t m_eUniqueness;
  316. #endif
  317. };
  318. class CRecipeComponentInputDefIndexIterator : public CEconItemSpecificAttributeIterator
  319. {
  320. public:
  321. CRecipeComponentInputDefIndexIterator( EItemDefUniqueness_t eUniqueness );
  322. virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef,
  323. const CAttribute_DynamicRecipeComponent& value ) OVERRIDE;
  324. const CUtlVector< item_definition_index_t >& GetMatchingComponentInputs() const { return m_vecInputItemDefs; }
  325. private:
  326. CUtlVector< item_definition_index_t > m_vecInputItemDefs;
  327. EItemDefUniqueness_t m_eUniqueness;
  328. };
  329. const CUtlVector<CBaseRecipeComponent*>& GetComponents() const { return m_vecComponents; }
  330. private:
  331. // All the different components for this recipe
  332. CUtlVector<CBaseRecipeComponent*> m_vecComponents;
  333. // Errors we ecounter during initialization
  334. CUtlVector<CUtlString> m_vecErrors;
  335. };
  336. class CWorldItemPlacementAttributeIterator : public CEconItemSpecificAttributeIterator
  337. {
  338. public:
  339. CWorldItemPlacementAttributeIterator() {}
  340. virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, const CAttribute_WorldItemPlacement &value ) OVERRIDE
  341. {
  342. Assert( pAttrDef );
  343. if ( pAttrDef )
  344. {
  345. m_vecPlacementAttributes.AddToTail( pAttrDef );
  346. }
  347. return true;
  348. }
  349. const CUtlVector< const CEconItemAttributeDefinition* > &GetPlacementAttributes( void ) const { return m_vecPlacementAttributes; }
  350. private:
  351. CUtlVector< const CEconItemAttributeDefinition* > m_vecPlacementAttributes;
  352. };
  353. //---------------------------------------------------------------------------------------
  354. // Purpose: Turns valid target items in to strange
  355. //---------------------------------------------------------------------------------------
  356. class CEconTool_Xifier : public IEconTool
  357. {
  358. public:
  359. CEconTool_Xifier( const char *pszTypeName, const char *pszUseString, item_capabilities_t unCapabilities, KeyValues *pUsageKV )
  360. : IEconTool( pszTypeName, pszUseString, NULL, unCapabilities )
  361. , m_RequiredTags( pUsageKV ? pUsageKV->FindKey( "required_tags" ) : NULL )
  362. {
  363. if ( pUsageKV )
  364. {
  365. KeyValues *pKVItemDefRestrictions = pUsageKV->FindKey( "itemdef_restrictions" );
  366. if ( pKVItemDefRestrictions )
  367. {
  368. FOR_EACH_SUBKEY( pKVItemDefRestrictions, pKVTag )
  369. {
  370. m_ItemDefTargetRestrictions.AddToTail( atoi(pKVTag->GetName()) );
  371. }
  372. }
  373. m_ItemRarityRestriction = pUsageKV->GetInt( "itemrarity_restrictions", k_unItemRarity_Any );
  374. }
  375. m_sItemDescLocToken = pUsageKV ? pUsageKV->GetString( "item_desc_tool_target", "" ) : "";
  376. }
  377. virtual bool CanApplyTo( const IEconItemInterface *pTool, const IEconItemInterface *pToolSubject ) const;
  378. const char *GetItemDescToolTargetLocToken() const { return m_sItemDescLocToken.String(); }
  379. #ifdef GC
  380. virtual CEconItem *GenerateNewItem( const IEconItemInterface *pTool, const CEconItem *pTarget ) const = 0;
  381. #endif
  382. #ifdef CLIENT_DLL
  383. virtual bool ShouldDisplayAsUseableOnItemsInArmory() const { return false; }
  384. virtual void OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const;
  385. #endif // CLIENT_DLL
  386. private:
  387. bool ItemDefMatch( const CEconItemDefinition* pTargetItemDef, const CEconItemDefinition* pSubjectItemDef ) const;
  388. CUtlString m_sItemDescLocToken;
  389. CEconTool_TagsList m_RequiredTags;
  390. CUtlVector<item_definition_index_t> m_ItemDefTargetRestrictions;
  391. uint8 m_ItemRarityRestriction;
  392. };
  393. class CEconTool_Strangifier : public CEconTool_Xifier
  394. {
  395. public:
  396. CEconTool_Strangifier( const char *pszTypeName, const char *pszUseString, item_capabilities_t unCapabilities, KeyValues *pUsageKV )
  397. : CEconTool_Xifier( pszTypeName, pszUseString, unCapabilities, pUsageKV ) {}
  398. virtual bool CanApplyTo( const IEconItemInterface *pTool, const IEconItemInterface *pToolSubject ) const;
  399. #ifdef GC
  400. virtual CEconItem *GenerateNewItem( const IEconItemInterface *pTool, const CEconItem *pTarget ) const;
  401. #endif
  402. #ifdef CLIENT_DLL
  403. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  404. #endif // CLIENT_DLL
  405. };
  406. //---------------------------------------------------------------------------------------
  407. class CEconTool_KillStreakifier : public CEconTool_Xifier
  408. {
  409. public:
  410. CEconTool_KillStreakifier( const char *pszTypeName, const char *pszUseString, item_capabilities_t unCapabilities, KeyValues *pUsageKV )
  411. : CEconTool_Xifier( pszTypeName, pszUseString, unCapabilities, pUsageKV ) {}
  412. virtual bool CanApplyTo( const IEconItemInterface *pTool, const IEconItemInterface *pToolSubject ) const;
  413. #ifdef GC
  414. virtual CEconItem *GenerateNewItem( const IEconItemInterface *pTool, const CEconItem *pTarget ) const;
  415. #endif
  416. #ifdef CLIENT_DLL
  417. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  418. #endif // CLIENT_DLL
  419. };
  420. //---------------------------------------------------------------------------------------
  421. class CEconTool_Festivizer : public CEconTool_Xifier
  422. {
  423. public:
  424. CEconTool_Festivizer( const char *pszTypeName, const char *pszUseString, item_capabilities_t unCapabilities, KeyValues *pUsageKV )
  425. : CEconTool_Xifier( pszTypeName, pszUseString, unCapabilities, pUsageKV )
  426. {
  427. }
  428. virtual bool CanApplyTo( const IEconItemInterface *pTool, const IEconItemInterface *pToolSubject ) const;
  429. #ifdef GC
  430. virtual CEconItem *GenerateNewItem( const IEconItemInterface *pTool, const CEconItem *pTarget ) const;
  431. #endif
  432. #ifdef CLIENT_DLL
  433. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  434. #endif // CLIENT_DLL
  435. };
  436. //---------------------------------------------------------------------------------------
  437. class CEconTool_Unusualifier : public CEconTool_Xifier
  438. {
  439. public:
  440. CEconTool_Unusualifier( const char *pszTypeName, const char *pszUseString, item_capabilities_t unCapabilities, KeyValues *pUsageKV )
  441. : CEconTool_Xifier( pszTypeName, pszUseString, unCapabilities, pUsageKV ) {}
  442. virtual bool CanApplyTo( const IEconItemInterface *pTool, const IEconItemInterface *pToolSubject ) const;
  443. #ifdef GC
  444. virtual CEconItem *GenerateNewItem( const IEconItemInterface *pTool, const CEconItem *pTarget ) const;
  445. #endif
  446. #ifdef CLIENT_DLL
  447. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  448. #endif // CLIENT_DLL
  449. };
  450. //---------------------------------------------------------------------------------------
  451. // Eats an item to give it charges
  452. //---------------------------------------------------------------------------------------
  453. class CEconTool_ItemEaterRecharger: public IEconTool
  454. {
  455. public:
  456. CEconTool_ItemEaterRecharger( const char *pszTypeName, const char *pszUseString, item_capabilities_t unCapabilities, KeyValues *pUsageKV )
  457. : IEconTool( pszTypeName, pszUseString, NULL, unCapabilities )
  458. , m_RequiredTags( pUsageKV ? pUsageKV->FindKey( "required_tags" ) : NULL )
  459. {
  460. if ( pUsageKV )
  461. {
  462. KeyValues *pKVItemDefRestrictions = pUsageKV->FindKey( "itemdef_restrictions" );
  463. if ( pKVItemDefRestrictions )
  464. {
  465. FOR_EACH_SUBKEY( pKVItemDefRestrictions, pKVTag )
  466. {
  467. m_ItemDefTargetRestrictions.AddToTail( atoi(pKVTag->GetName()) );
  468. m_ItemDefTargetChargeValues.AddToTail( pKVItemDefRestrictions->GetInt( pKVTag->GetName(), 0 ) );
  469. }
  470. }
  471. }
  472. }
  473. int GetChargesForItemDefId ( item_definition_index_t defIndex ) const;
  474. virtual bool CanApplyTo( const IEconItemInterface *pTool, const IEconItemInterface *pToolSubject ) const;
  475. #ifdef CLIENT_DLL
  476. virtual bool ShouldDisplayAsUseableOnItemsInArmory() const { return false; }
  477. virtual void OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const;
  478. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  479. #endif // CLIENT_DLL
  480. #ifdef GC_DLL
  481. virtual class CGCEconConsumableBehavior *CreateGCConsumableBehavior() const;
  482. #endif // GC_DLL
  483. private:
  484. CEconTool_TagsList m_RequiredTags;
  485. CUtlVector<item_definition_index_t> m_ItemDefTargetRestrictions;
  486. CUtlVector<int> m_ItemDefTargetChargeValues;
  487. };
  488. //---------------------------------------------------------------------------------------
  489. // Purpose:
  490. //---------------------------------------------------------------------------------------
  491. class CEconTool_UpgradeCard : public IEconTool
  492. {
  493. public:
  494. struct upgrade_card_attr_value_t
  495. {
  496. const CEconItemAttributeDefinition *m_pAttrDef;
  497. attrib_value_t m_value;
  498. };
  499. typedef CUtlVectorFixedGrowable<upgrade_card_attr_value_t, 1> UpgradeCardAttributeVec_t;
  500. CEconTool_UpgradeCard( const char *pszTypeName, const char *pszUseString, item_capabilities_t unCapabilities, KeyValues *pUsageKV )
  501. : IEconTool( pszTypeName, pszUseString, NULL, unCapabilities )
  502. , m_RequiredTags( pUsageKV ? pUsageKV->FindKey( "required_tags" ) : NULL )
  503. {
  504. COMPILE_TIME_ASSERT( sizeof( attrib_value_t ) == sizeof( uint32 ) );
  505. COMPILE_TIME_ASSERT( sizeof( attrib_value_t ) == sizeof( float ) );
  506. if ( pUsageKV )
  507. {
  508. KeyValues *pAttributesKV = pUsageKV->FindKey( "attributes" );
  509. if ( pAttributesKV )
  510. {
  511. FOR_EACH_SUBKEY( pAttributesKV, pAttrKV )
  512. {
  513. const char *pszAttributeName = pAttrKV->GetName();
  514. const CEconItemAttributeDefinition *pAttrDef = GetItemSchema()->GetAttributeDefinitionByName( pszAttributeName );
  515. // Kyle says: this is bad, dumb code, and more importantly it's bad dumb code that doesn't
  516. // make any sense here, way down inside the "parse a tool" function.
  517. attrib_value_t value;
  518. const bool bParseAsFloat = pAttrDef && pAttrDef->IsStoredAsFloat();
  519. if ( bParseAsFloat )
  520. {
  521. *(float *)&value = pAttrKV->GetFloat();
  522. }
  523. else
  524. {
  525. *(uint32 *)&value = pAttrKV->GetInt();
  526. }
  527. // Add this attribute to our list. Adding a NULL pointer is safe here. We'll use that to check
  528. // later in BFinishInitialization() whether we had a successful init or not.
  529. upgrade_card_attr_value_t attrValue = { pAttrDef, value };
  530. m_vecAttributes.AddToTail( attrValue );
  531. }
  532. }
  533. }
  534. }
  535. virtual bool BFinishInitialization() OVERRIDE
  536. {
  537. // Make sure we didn't fail to find any attributes.
  538. FOR_EACH_VEC( m_vecAttributes, i )
  539. {
  540. if ( m_vecAttributes[i].m_pAttrDef == NULL )
  541. return false;
  542. }
  543. // Make sure we have a non-zero number of attributes. If we don't have at least one, applicable would be
  544. // a nonsensical action.
  545. return m_vecAttributes.Count() > 0
  546. && IEconTool::BFinishInitialization();
  547. }
  548. const UpgradeCardAttributeVec_t& GetAttributes() const { return m_vecAttributes; }
  549. virtual bool CanApplyTo( const IEconItemInterface *pTool, const IEconItemInterface *pToolSubject ) const;
  550. #ifdef CLIENT_DLL
  551. virtual bool ShouldDisplayAsUseableOnItemsInArmory() const { return false; }
  552. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  553. #endif // CLIENT_DLL
  554. private:
  555. CEconTool_TagsList m_RequiredTags;
  556. UpgradeCardAttributeVec_t m_vecAttributes;
  557. };
  558. //---------------------------------------------------------------------------------------
  559. // Purpose:
  560. //---------------------------------------------------------------------------------------
  561. class CEconTool_ClassTransmogrifier : public IEconTool
  562. {
  563. public:
  564. CEconTool_ClassTransmogrifier( const char *pszTypeName, const char *pszUseString, item_capabilities_t unCapabilities, KeyValues *pUsageKV )
  565. : IEconTool( pszTypeName, pszUseString, NULL, unCapabilities )
  566. , m_RequiredTags( pUsageKV ? pUsageKV->FindKey( "required_tags" ) : NULL )
  567. , m_iClass( -1 )
  568. {
  569. KeyValues *pKVOutputClass = pUsageKV->FindKey( "output_class" );
  570. if ( pKVOutputClass )
  571. {
  572. m_iClass = StringFieldToInt( pKVOutputClass->GetString( "" ), GetItemSchema()->GetClassUsabilityStrings() );
  573. }
  574. }
  575. virtual bool BFinishInitialization() OVERRIDE
  576. {
  577. return m_iClass > 0
  578. && m_iClass < LOADOUT_COUNT
  579. && IEconTool::BFinishInitialization();
  580. }
  581. int GetOutputClass() const { return m_iClass; }
  582. const CEconTool_TagsList& GetRequiredTags() const { return m_RequiredTags; }
  583. virtual bool CanApplyTo( const IEconItemInterface *pTool, const IEconItemInterface *pToolSubject ) const;
  584. #ifdef CLIENT_DLL
  585. virtual bool ShouldDisplayAsUseableOnItemsInArmory() const { return false; }
  586. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  587. #endif // CLIENT_DLL
  588. private:
  589. CEconTool_TagsList m_RequiredTags; // required for both the input item and the output item
  590. int m_iClass;
  591. };
  592. //---------------------------------------------------------------------------------------
  593. // Purpose:
  594. //---------------------------------------------------------------------------------------
  595. class CEconTool_BackpackExpander : public IEconTool
  596. {
  597. public:
  598. CEconTool_BackpackExpander ( const char *pszTypeName, const char *pszUseString, KeyValues *pUsageKV )
  599. : IEconTool( pszTypeName, pszUseString, NULL, ITEM_CAP_NONE )
  600. , m_iBackpackSlots( 0 )
  601. {
  602. if ( pUsageKV )
  603. {
  604. m_iBackpackSlots = pUsageKV->GetInt( "backpack_slots", 0 );
  605. }
  606. }
  607. virtual bool BFinishInitialization() OVERRIDE
  608. {
  609. return m_iBackpackSlots > 0
  610. && IEconTool::BFinishInitialization();
  611. }
  612. int GetBackpackSlots() const { return m_iBackpackSlots; }
  613. #ifdef CLIENT_DLL
  614. virtual void OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const;
  615. #endif // CLIENT_DLL
  616. #ifdef GC_DLL
  617. virtual class CGCEconConsumableBehavior *CreateGCConsumableBehavior() const;
  618. #endif // GC_DLL
  619. private:
  620. int m_iBackpackSlots;
  621. };
  622. //---------------------------------------------------------------------------------------
  623. // Purpose:
  624. //---------------------------------------------------------------------------------------
  625. class CEconTool_AccountUpgradeToPremium : public IEconTool
  626. {
  627. public:
  628. CEconTool_AccountUpgradeToPremium( const char *pszTypeName, const char *pszUseString ) : IEconTool( pszTypeName, pszUseString, NULL, ITEM_CAP_NONE ) { }
  629. #ifdef CLIENT_DLL
  630. virtual void OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const;
  631. #endif // CLIENT_DLL
  632. #ifdef GC_DLL
  633. virtual class CGCEconConsumableBehavior *CreateGCConsumableBehavior() const;
  634. #endif // GC_DLL
  635. };
  636. //---------------------------------------------------------------------------------------
  637. class CEconTool_DuckToken: public IEconTool
  638. {
  639. public:
  640. CEconTool_DuckToken( const char *pszTypeName, item_capabilities_t unCapabilities ) : IEconTool( pszTypeName, NULL, NULL, unCapabilities ) { }
  641. virtual bool CanApplyTo( const IEconItemInterface *pTool, const IEconItemInterface *pToolSubject ) const;
  642. #ifdef CLIENT_DLL
  643. virtual void OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const;
  644. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  645. #endif // CLIENT_DLL
  646. #ifdef GC_DLL
  647. //virtual class CGCEconConsumableBehavior *CreateGCConsumableBehavior() const;
  648. #endif // GC_DLL
  649. };
  650. //---------------------------------------------------------------------------------------
  651. class CEconTool_GrantOperationPass : public IEconTool
  652. {
  653. public:
  654. CEconTool_GrantOperationPass( const char *pszTypeName, const char *pszUseString, item_capabilities_t unCapabilities, KeyValues *pUsageKV ) : IEconTool( pszTypeName, pszUseString, NULL, ITEM_CAP_NONE )
  655. {
  656. m_pOperationPassName = NULL;
  657. m_pOptionalBonusLootList = NULL;
  658. if ( pUsageKV )
  659. {
  660. // Find the Item
  661. m_pOperationPassName = pUsageKV->GetString( "operation_pass", NULL );
  662. m_pOptionalBonusLootList = pUsageKV->GetString( "bonus_lootlist", NULL );
  663. }
  664. }
  665. #ifdef CLIENT_DLL
  666. virtual void OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const;
  667. #endif // CLIENT_DLL
  668. #ifdef GC_DLL
  669. virtual class CGCEconConsumableBehavior *CreateGCConsumableBehavior() const;
  670. #endif // GC_DLL
  671. const char *m_pOperationPassName;
  672. const char *m_pOptionalBonusLootList;
  673. };
  674. //---------------------------------------------------------------------------------------
  675. // Purpose:
  676. //---------------------------------------------------------------------------------------
  677. class CEconTool_ClaimCode : public IEconTool
  678. {
  679. public:
  680. CEconTool_ClaimCode ( const char *pszTypeName, const char *pszUseString, KeyValues *pUsageKV )
  681. : IEconTool( pszTypeName, pszUseString, NULL, ITEM_CAP_NONE )
  682. , m_pszClaimType( NULL )
  683. {
  684. if ( pUsageKV )
  685. {
  686. m_pszClaimType = pUsageKV->GetString( "claim_type", NULL );
  687. }
  688. }
  689. virtual bool BFinishInitialization() OVERRIDE
  690. {
  691. return m_pszClaimType
  692. && IEconTool::BFinishInitialization();
  693. }
  694. const char *GetClaimType() const { return m_pszClaimType; }
  695. #ifdef CLIENT_DLL
  696. virtual void OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const;
  697. #endif // CLIENT_DLL
  698. #ifdef GC_DLL
  699. virtual class CGCEconConsumableBehavior *CreateGCConsumableBehavior() const;
  700. #endif // GC_DLL
  701. private:
  702. const char *m_pszClaimType;
  703. };
  704. //---------------------------------------------------------------------------------------
  705. // Purpose:
  706. //---------------------------------------------------------------------------------------
  707. enum EGiftTargetRule
  708. {
  709. kGiftTargetRule_OnlyOthers = 0,
  710. kGiftTargetRule_OnlySelf = 1,
  711. };
  712. class CEconTool_Gift : public IEconTool
  713. {
  714. public:
  715. CEconTool_Gift ( const char *pszTypeName, const char *pszUseString, KeyValues *pUsageKV )
  716. : IEconTool( pszTypeName, pszUseString, NULL, ITEM_CAP_NONE )
  717. , m_pszLootListName( NULL )
  718. , m_iMaxRecipients( 0 )
  719. , m_eTargetRule( kGiftTargetRule_OnlySelf )
  720. {
  721. if ( pUsageKV )
  722. {
  723. m_pszLootListName = pUsageKV->GetString( "loot_list", NULL );
  724. m_iMaxRecipients = pUsageKV->GetInt( "max_recipients", 0 );
  725. m_eTargetRule = !Q_stricmp( pUsageKV->GetString( "target_rule", "only_others" ), "only_self" )
  726. ? kGiftTargetRule_OnlySelf
  727. : kGiftTargetRule_OnlyOthers;
  728. }
  729. }
  730. virtual bool BFinishInitialization() OVERRIDE
  731. {
  732. return m_pszLootListName
  733. && GetItemSchema()->GetLootListByName( m_pszLootListName )
  734. && m_iMaxRecipients > 0
  735. && IEconTool::BFinishInitialization();
  736. }
  737. const char *GetLootListName() const { return m_pszLootListName; }
  738. int GetMaxRecipients() const { return m_iMaxRecipients; }
  739. EGiftTargetRule GetTargetRule() const { return m_eTargetRule; }
  740. #ifdef CLIENT_DLL
  741. virtual void OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const;
  742. #endif // CLIENT_DLL
  743. #ifdef GC_DLL
  744. virtual class CGCEconConsumableBehavior *CreateGCConsumableBehavior() const;
  745. #endif // GC_DLL
  746. private:
  747. const char *m_pszLootListName;
  748. int m_iMaxRecipients;
  749. EGiftTargetRule m_eTargetRule;
  750. };
  751. //---------------------------------------------------------------------------------------
  752. // Purpose:
  753. //---------------------------------------------------------------------------------------
  754. class CEconTool_PaintCan : public IEconTool
  755. {
  756. public:
  757. CEconTool_PaintCan( const char *pszTypeName, item_capabilities_t unCapabilities ) : IEconTool( pszTypeName, NULL, NULL, unCapabilities ) { }
  758. #ifdef CLIENT_DLL
  759. virtual void OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const;
  760. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  761. #endif // CLIENT_DLL
  762. };
  763. //---------------------------------------------------------------------------------------
  764. // Purpose:
  765. //---------------------------------------------------------------------------------------
  766. class CEconTool_GiftWrap : public IEconTool
  767. {
  768. public:
  769. CEconTool_GiftWrap( const char *pszTypeName, const char *pszUseString, item_capabilities_t unCapabilities, KeyValues *pUsageKV );
  770. virtual bool BFinishInitialization() OVERRIDE;
  771. virtual bool CanApplyTo( const IEconItemInterface *pTool, const IEconItemInterface *pToolSubject ) const;
  772. virtual bool RequiresToolEscrowPeriod() const { return false; }
  773. const CEconItemDefinition *GetWrappedItemDefinition() const { Assert( m_pWrappedGiftItemDef ); return m_pWrappedGiftItemDef; }
  774. #ifdef CLIENT_DLL
  775. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  776. #endif // CLIENT_DLL
  777. private:
  778. const char *m_pszWrappedGiftItemDefName; // points to memory inside our init KV -- only valid between the constructor call and the BFinishInitialization() call (this is messy but Fletcher and I agree it makes more sense than switching to a full two-pass schema parse just for this)
  779. const CEconItemDefinition *m_pWrappedGiftItemDef;
  780. };
  781. //---------------------------------------------------------------------------------------
  782. // Purpose:
  783. //---------------------------------------------------------------------------------------
  784. class CEconTool_NameTag : public IEconTool
  785. {
  786. public:
  787. CEconTool_NameTag( const char *pszTypeName, item_capabilities_t unCapabilities ) : IEconTool( pszTypeName, NULL, NULL, unCapabilities ) { }
  788. #ifdef CLIENT_DLL
  789. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  790. #endif // CLIENT_DLL
  791. };
  792. //---------------------------------------------------------------------------------------
  793. // Purpose:
  794. //---------------------------------------------------------------------------------------
  795. class CEconTool_DescTag : public IEconTool
  796. {
  797. public:
  798. CEconTool_DescTag( const char *pszTypeName, item_capabilities_t unCapabilities ) : IEconTool( pszTypeName, NULL, NULL, unCapabilities ) { }
  799. #ifdef CLIENT_DLL
  800. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  801. #endif // CLIENT_DLL
  802. };
  803. //---------------------------------------------------------------------------------------
  804. // Purpose:
  805. //---------------------------------------------------------------------------------------
  806. class CEconTool_CustomizeTexture : public IEconTool
  807. {
  808. public:
  809. CEconTool_CustomizeTexture( const char *pszTypeName, item_capabilities_t unCapabilities ) : IEconTool( pszTypeName, NULL, NULL, unCapabilities ) { }
  810. #ifdef CLIENT_DLL
  811. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  812. #endif // CLIENT_DLL
  813. };
  814. //---------------------------------------------------------------------------------------
  815. // Purpose:
  816. //---------------------------------------------------------------------------------------
  817. class CEconTool_CrateKey : public IEconTool
  818. {
  819. public:
  820. CEconTool_CrateKey( const char *pszTypeName, const char *pszUsageRestriction, item_capabilities_t unCapabilities ) : IEconTool( pszTypeName, NULL, pszUsageRestriction, unCapabilities ) { }
  821. #ifdef CLIENT_DLL
  822. virtual void OnClientApplyTool( CEconItemView *pTool, CEconItemView *pSubject, vgui::Panel *pParent ) const;
  823. #endif // CLIENT_DLL
  824. };
  825. //---------------------------------------------------------------------------------------
  826. // Purpose:
  827. //---------------------------------------------------------------------------------------
  828. class CEconTool_Default : public IEconTool
  829. {
  830. public:
  831. CEconTool_Default( const char *pszTypeName, const char *pszUseString, const char *pszUsageRestriction, item_capabilities_t unCapabilities )
  832. : IEconTool( pszTypeName, pszUseString, pszUsageRestriction, unCapabilities )
  833. {
  834. Assert( pszTypeName );
  835. }
  836. #ifdef CLIENT_DLL
  837. virtual void OnClientUseConsumable( CEconItemView *pItem, vgui::Panel *pParent ) const;
  838. #endif // CLIENT_DLL
  839. };
  840. //-----------------------------------------------------------------------------
  841. // Purpose:
  842. //-----------------------------------------------------------------------------
  843. class CCountUserGeneratedAttributeIterator : public IEconItemUntypedAttributeIterator
  844. {
  845. public:
  846. CCountUserGeneratedAttributeIterator() : m_iCount( 0 ) { }
  847. virtual bool OnIterateAttributeValueUntyped( const CEconItemAttributeDefinition *pAttrDef ) OVERRIDE
  848. {
  849. if ( pAttrDef->GetUserGenerationType() != 0 )
  850. {
  851. m_iCount++;
  852. }
  853. return true;
  854. }
  855. int GetCount() const { return m_iCount; }
  856. private:
  857. int m_iCount;
  858. };
  859. #endif // ECONITEMTOOLS_H