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.

3374 lines
134 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: EconItemSchema: Defines a schema for econ items
  4. //
  5. //=============================================================================
  6. #ifndef ECONITEMSCHEMA_H
  7. #define ECONITEMSCHEMA_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. // Valve code doesn't play nicely with standard headers on some platforms sometimes.
  12. #ifdef min
  13. #undef min
  14. #endif
  15. #ifdef max
  16. #undef max
  17. #endif
  18. #include <string>
  19. #include "KeyValues.h"
  20. #include "tier1/utldict.h"
  21. #include "tier1/utlhashmaplarge.h"
  22. #include "econ_item_constants.h"
  23. #include "item_selection_criteria.h"
  24. #include "bitvec.h"
  25. #include "language.h"
  26. #include "smartptr.h"
  27. #include "rtime.h"
  28. #include "checksum_sha1.h"
  29. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  30. #include "engine/ivmodelinfo.h"
  31. #include "engine/ivmodelrender.h"
  32. #include "ilocalize.h"
  33. #endif
  34. #include "gamestringpool.h"
  35. class CEconItemSchema;
  36. class CEconItem;
  37. class CEconSharedObjectCache;
  38. class CSOItemRecipe;
  39. union attribute_data_union_t
  40. {
  41. float asFloat;
  42. uint32 asUint32;
  43. byte *asBlobPointer;
  44. };
  45. struct static_attrib_t
  46. {
  47. static_attrib_t()
  48. {
  49. iDefIndex = 0;
  50. m_value.asBlobPointer = NULL;
  51. #ifdef GC_DLL
  52. bForceGCToGenerate = false;
  53. m_pKVCustomData = NULL;
  54. #endif // GC_DLL
  55. }
  56. ~static_attrib_t()
  57. {
  58. #ifdef GC_DLL
  59. if ( m_pKVCustomData )
  60. m_pKVCustomData->deleteThis();
  61. m_pKVCustomData = NULL;
  62. #endif
  63. }
  64. static_attrib_t( const static_attrib_t& rhs )
  65. {
  66. iDefIndex = rhs.iDefIndex;
  67. m_value = rhs.m_value;
  68. #ifdef GC_DLL
  69. m_pKVCustomData = rhs.m_pKVCustomData ? rhs.m_pKVCustomData->MakeCopy() : NULL;
  70. bForceGCToGenerate = rhs.bForceGCToGenerate;
  71. #endif
  72. }
  73. attrib_definition_index_t iDefIndex;
  74. attribute_data_union_t m_value;
  75. #ifdef GC_DLL
  76. bool bForceGCToGenerate;
  77. KeyValues *m_pKVCustomData;
  78. #endif // GC_DLL
  79. // Parses a single subsection from a multi-line attribute block that looks like:
  80. //
  81. // "attributes"
  82. // {
  83. // "cannot trade"
  84. // {
  85. // "attribute_class" "cannot_trade"
  86. // "value" "1"
  87. // }
  88. // "kill eater"
  89. // {
  90. // "attribute_class" "kill_eater"
  91. // "force_gc_to_generate" "1"
  92. // "use_custom_logic" "gifts_given_out"
  93. // }
  94. // }
  95. //
  96. // The "force_gc_to_generate" and "use_custom_logic" fields will only be parsed on the GC. Will return
  97. // true/false based on whether the whole attribute and value parsed successfully.
  98. bool BInitFromKV_MultiLine( const char *pszContext, KeyValues *pKVAttribute, CUtlVector<CUtlString> *pVecErrors );
  99. // Parses a single subsection from a single-line attribute block that looks like:
  100. //
  101. // CharacterAttributes
  102. // {
  103. // "increase buff duration" 9.0
  104. // "damage bonus" 2.0
  105. // }
  106. //
  107. // It's impossible to specify GC-generated attributes in this format. Will return true/false based on
  108. // whether the whole attribute and value parsed successfully.
  109. bool BInitFromKV_SingleLine( const char *pszContext, KeyValues *pKVAttribute, CUtlVector<CUtlString> *pVecErrors, bool bEnableTerribleBackwardsCompatibilitySchemaParsingCode = true );
  110. // Data access helpers.
  111. const class CEconItemAttributeDefinition *GetAttributeDefinition() const;
  112. const class ISchemaAttributeType *GetAttributeType() const;
  113. };
  114. typedef uint16 equipped_class_t;
  115. typedef uint16 equipped_slot_t;
  116. typedef uint8 equipped_preset_t;
  117. #define INVALID_EQUIPPED_SLOT ((equipped_slot_t)-1)
  118. #define INVALID_STYLE_INDEX ((style_index_t)-1)
  119. #define INVALID_PRESET_INDEX ((equipped_preset_t)-1)
  120. enum EEquipType_t
  121. {
  122. EQUIP_TYPE_CLASS = 0,
  123. EQUIP_TYPE_ACCOUNT,
  124. EQUIP_TYPE_INVALID,
  125. };
  126. // Streamable weapons cause stutters when people enter PVS. Turn it off for now.
  127. // #define WITH_STREAMABLE_WEAPONS
  128. //-----------------------------------------------------------------------------
  129. // IEconItemPropertyGenerator
  130. //-----------------------------------------------------------------------------
  131. class IEconItemPropertyGenerator
  132. {
  133. public:
  134. virtual ~IEconItemPropertyGenerator() { }
  135. MUST_CHECK_RETURN virtual bool BGenerateProperties( CEconItem *pItem ) const = 0;
  136. };
  137. //-----------------------------------------------------------------------------
  138. // Item Series
  139. //-----------------------------------------------------------------------------
  140. class CEconItemSeriesDefinition
  141. {
  142. public:
  143. CEconItemSeriesDefinition( void );
  144. CEconItemSeriesDefinition( const CEconItemSeriesDefinition &that );
  145. CEconItemSeriesDefinition &operator=( const CEconItemSeriesDefinition& rhs );
  146. ~CEconItemSeriesDefinition( void ) { }
  147. bool BInitFromKV( KeyValues *pKVItem, CUtlVector<CUtlString> *pVecErrors = NULL );
  148. int32 GetDBValue( void ) const { return m_nValue; }
  149. const char *GetName( void ) const { return !m_strName.IsEmpty() ? m_strName.String() : "unknown"; }
  150. const char *GetLocKey( void ) const { return !m_strLockKey.IsEmpty() ? m_strLockKey.String() : "unknown"; }
  151. const char *GetUiFile( void ) const { return !m_strUiFile.IsEmpty() ? m_strUiFile.String() : "unknown"; }
  152. private:
  153. // The value that the game/DB will know this series by
  154. int32 m_nValue;
  155. CUtlString m_strName; // Key Name
  156. CUtlString m_strLockKey; // Localization key
  157. CUtlString m_strUiFile; // Ui File (.res file)
  158. };
  159. //-----------------------------------------------------------------------------
  160. // CEconItemRarityDefinition
  161. //-----------------------------------------------------------------------------
  162. class CEconItemRarityDefinition
  163. {
  164. public:
  165. CEconItemRarityDefinition( void );
  166. ~CEconItemRarityDefinition( void ) { }
  167. bool BInitFromKV( KeyValues *pKVItem, KeyValues *pKVRarityWeights, CEconItemSchema &pschema, CUtlVector<CUtlString> *pVecErrors = NULL );
  168. int32 GetDBValue( void ) const { return m_nValue; }
  169. const char *GetName( void ) const { return !m_strName.IsEmpty() ? m_strName.String() : "unknown"; }
  170. const char *GetLocKey( void ) const { return m_strLocKey.String(); }
  171. const char *GetWepLocKey( void ) const { return m_strWepLocKey.String(); }
  172. const char *GetDropSound( void ) const { return m_strDropSound.String(); }
  173. attrib_colors_t GetAttribColor( void ) const { return m_iAttribColor; }
  174. const char *GetNextRarity( void ) const { return m_strNextRarity.String(); }
  175. int32 GetLootlistWeight( void ) const { return m_nLootlistWeight; }
  176. private:
  177. // The value that the game/DB will know this rarity by
  178. int32 m_nValue;
  179. attrib_colors_t m_iAttribColor;
  180. // The English name of the rarity
  181. CUtlString m_strName;
  182. // The localization key for this rarity.
  183. CUtlString m_strLocKey;
  184. // The localization key for this rarity, for weapons.
  185. CUtlString m_strWepLocKey;
  186. // The loot list name associated with this rarity.
  187. CUtlString m_strDropSound;
  188. CUtlString m_strNextRarity;
  189. int32 m_nLootlistWeight;
  190. };
  191. //-----------------------------------------------------------------------------
  192. // CEconItemQualityDefinition
  193. // Template Definition of a randomly created item
  194. //-----------------------------------------------------------------------------
  195. class CEconItemQualityDefinition
  196. {
  197. public:
  198. CEconItemQualityDefinition( void );
  199. CEconItemQualityDefinition( const CEconItemQualityDefinition &that );
  200. CEconItemQualityDefinition &operator=( const CEconItemQualityDefinition& rhs );
  201. ~CEconItemQualityDefinition( void ) { }
  202. bool BInitFromKV( KeyValues *pKVItem, CUtlVector<CUtlString> *pVecErrors = NULL );
  203. int32 GetDBValue( void ) const { return m_nValue; }
  204. const char *GetName( void ) const { return !m_strName.IsEmpty() ? m_strName.Get() : "unknown"; }
  205. bool CanSupportSet( void ) const { return m_bCanSupportSet; }
  206. const char *GetHexColor( void ) const { return !m_strHexColor.IsEmpty() ? m_strHexColor.Get() : "B2B2B2"; }
  207. #ifdef DBGFLAG_VALIDATE
  208. void Validate( CValidator &validator, const char *pchName )
  209. {
  210. VALIDATE_SCOPE();
  211. ValidateObj( m_strName );
  212. }
  213. #endif // DBGFLAG_VALIDATE
  214. private:
  215. // The value that the game/DB will know this quality by
  216. int32 m_nValue;
  217. // The English name of the quality
  218. CUtlConstString m_strName;
  219. // if this is true the support tool is allowed to set this quality level on any item
  220. bool m_bCanSupportSet;
  221. // A hex string representing the color this quality should display as. Used primarily for display on the Web.
  222. CUtlConstString m_strHexColor;
  223. };
  224. //-----------------------------------------------------------------------------
  225. // CEconColorDefinition
  226. //-----------------------------------------------------------------------------
  227. class CEconColorDefinition
  228. {
  229. public:
  230. bool BInitFromKV( KeyValues *pKVColor, CUtlVector<CUtlString> *pVecErrors = NULL );
  231. const char *GetName( void ) const { return m_strName.Get(); }
  232. const char *GetColorName( void ) const { return m_strColorName.Get(); } // meant for passing into VGUI styles, etc.
  233. const char *GetHexColor( void ) const { return m_strHexColor.Get(); }
  234. private:
  235. // The English name of this color. Only used for lookup.
  236. CUtlConstString m_strName;
  237. // The VGUI name of the color in our schema. This will be used to set values
  238. // for VGUI controls.
  239. CUtlConstString m_strColorName;
  240. // The hex string value of this color. This will be used for Web display.
  241. CUtlConstString m_strHexColor;
  242. };
  243. //-----------------------------------------------------------------------------
  244. // CEconItemSetDefinition
  245. // Definition of an item set
  246. //-----------------------------------------------------------------------------
  247. class CEconItemSetDefinition
  248. {
  249. public:
  250. CEconItemSetDefinition( void );
  251. CEconItemSetDefinition( const CEconItemSetDefinition &that );
  252. CEconItemSetDefinition &operator=( const CEconItemSetDefinition& rhs );
  253. ~CEconItemSetDefinition( void ) {}
  254. bool BInitFromKV( KeyValues *pKVItemSet, CUtlVector<CUtlString> *pVecErrors = NULL );
  255. void IterateAttributes( class IEconItemAttributeIterator *pIterator ) const;
  256. public:
  257. const char *m_pszName;
  258. const char *m_pszLocalizedName;
  259. CUtlVector<item_definition_index_t> m_iItemDefs;
  260. int m_iBundleItemDef; // Item def of the store bundle for this set, if any
  261. bool m_bIsHiddenSet; // If true, this set and any bonuses will only be visible if the whole set is equipped.
  262. struct itemset_attrib_t
  263. {
  264. attrib_definition_index_t m_iAttribDefIndex;
  265. float m_flValue;
  266. };
  267. CUtlVector<itemset_attrib_t> m_iAttributes;
  268. };
  269. //-----------------------------------------------------------------------------
  270. class CEconItemCollectionDefinition
  271. {
  272. public:
  273. CEconItemCollectionDefinition( void );
  274. ~CEconItemCollectionDefinition( void ) {}
  275. bool BInitFromKV( KeyValues *pKVItemCollection, CUtlVector<CUtlString> *pVecErrors = NULL );
  276. uint8 GetMinRarity() const { return m_iRarityMin; }
  277. uint8 GetMaxRarity() const { return m_iRarityMax; }
  278. public:
  279. const char *m_pszName;
  280. const char *m_pszLocalizedName;
  281. const char *m_pszLocalizedDesc;
  282. CUtlVector<item_definition_index_t> m_iItemDefs;
  283. private:
  284. bool m_bIsReferenceCollection;
  285. uint8 m_iRarityMin;
  286. uint8 m_iRarityMax;
  287. };
  288. //-----------------------------------------------------------------------------
  289. class CEconItemPaintKitDefinition
  290. {
  291. public:
  292. CEconItemPaintKitDefinition( void );
  293. ~CEconItemPaintKitDefinition( void );
  294. bool BInitFromKV( KeyValues *pKVItemPaintKit, CUtlVector<CUtlString> *pVecErrors = NULL );
  295. //KeyValues *GetKVP() { return m_pKVItem; }
  296. const char *GetName() const { return m_pszName; }
  297. const char *GetLocalizeName() const { return m_pszLocalizedName; }
  298. KeyValues *GetPaintKitWearKV( int nWear );
  299. private:
  300. const char *m_pszName;
  301. const char *m_pszLocalizedName;
  302. CUtlVector< KeyValues * > m_vecPaintKitWearKVP;
  303. };
  304. //-----------------------------------------------------------------------------
  305. class CEconOperationDefinition
  306. {
  307. public:
  308. CEconOperationDefinition( void );
  309. ~CEconOperationDefinition( void );
  310. bool BInitFromKV( KeyValues *pKVOperation, CUtlVector<CUtlString> *pVecErrors = NULL );
  311. const char *GetName() const { return m_pszName; }
  312. operation_definition_index_t GetOperationID() const { return m_unOperationID; }
  313. item_definition_index_t GetRequiredItemDefIndex() const { return m_unRequiredItemDefIndex; }
  314. item_definition_index_t GetGatewayItemDefIndex() const { return m_unGatewayItemDefIndex; }
  315. KeyValues *GetKVP() { return m_pKVItem; }
  316. // use the date that we stop giving things to players as expiry date
  317. bool IsExpired() const { return CRTime::RTime32TimeCur() > GetStopGivingToPlayerDate(); }
  318. bool IsActive() const { return CRTime::RTime32TimeCur() >= GetStartDate() && !IsExpired(); }
  319. const char *GetQuestLogOverrideResFile() const { return m_pszQuestLogResFile; }
  320. const char *GetQuestListOverrideResFile() const { return m_pszQuestListResFile; }
  321. RTime32 GetStartDate() const { return m_OperationStartDate; }
  322. RTime32 GetStopGivingToPlayerDate() const { return m_StopGivingToPlayerDate; }
  323. RTime32 GetStopAddingToQueueDate() const { return m_StopAddingToQueueDate; }
  324. const char *GetOperationLootlist() const { return m_pszOperationLootList; }
  325. bool IsCampaign() const { return m_bIsCampaign; }
  326. uint32 GetMaxDropCount() const { return m_unMaxDropCount; }
  327. #ifdef GC_DLL
  328. enum EContractRewardLootlist_t
  329. {
  330. REWARD_CASE,
  331. REWARD_WEAPON,
  332. NUM_REWARDS
  333. };
  334. const char *GetContractRewardLootlist( EContractRewardLootlist_t eType ) const { return m_pszContractRewardLootlist[ eType ]; }
  335. RTime32 GetMinQueueFreq() const;
  336. RTime32 GetMaxQueueFreq() const;
  337. RTime32 GetMinDropFreq() const;
  338. RTime32 GetMaxDropFreq() const;
  339. uint8 GetNumSeededContracts() const { return m_unSeed; }
  340. uint16 GetNumMaxHeldDrops() const { return m_unMaxHeldDrops; }
  341. int GetNumMaxQueueCount() const { return m_nMaxQueueCount; }
  342. uint8 GetMaxDropPerThink() const { return m_unMaxDropPerThink; }
  343. #endif // GC_DLL
  344. private:
  345. const char *m_pszName;
  346. operation_definition_index_t m_unOperationID;
  347. // things operation periodically drops
  348. const char *m_pszOperationLootList;
  349. bool m_bIsCampaign;
  350. uint32 m_unMaxDropCount;
  351. const char *m_pszQuestLogResFile;
  352. const char *m_pszQuestListResFile;
  353. item_definition_index_t m_unRequiredItemDefIndex;
  354. item_definition_index_t m_unGatewayItemDefIndex; // Defindex of the item users need to acquire in order to get the required item. Could be the required item itself.
  355. RTime32 m_OperationStartDate; // when the operation starts and gives out rewards
  356. RTime32 m_StopGivingToPlayerDate; // when the operation stops giving quests to player
  357. RTime32 m_StopAddingToQueueDate; // when the operation stops adding more quests to the bucket
  358. #ifdef GC_DLL
  359. const char *m_pszContractRewardLootlist[ NUM_REWARDS ];
  360. // in seconds
  361. RTime32 m_rtQueueFreqMin;
  362. RTime32 m_rtQueueFreqMax;
  363. RTime32 m_rtDropFreqMin;
  364. RTime32 m_rtDropFreqMax;
  365. uint8 m_unSeed;
  366. uint16 m_unMaxHeldDrops;
  367. int m_nMaxQueueCount;
  368. uint8 m_unMaxDropPerThink;
  369. #endif // GC_DLL
  370. KeyValues *m_pKVItem;
  371. };
  372. //-----------------------------------------------------------------------------
  373. // CEconLootListDefinition
  374. // Definition of a loot list
  375. //-----------------------------------------------------------------------------
  376. class IEconLootList
  377. {
  378. public:
  379. virtual ~IEconLootList() { }
  380. MUST_CHECK_RETURN virtual bool BPublicListContents() const = 0;
  381. MUST_CHECK_RETURN virtual const char *GetLootListHeaderLocalizationKey() const = 0;
  382. MUST_CHECK_RETURN virtual const char *GetLootListFooterLocalizationKey() const = 0;
  383. MUST_CHECK_RETURN virtual const char *GetLootListCollectionReference() const = 0;
  384. class IEconLootListIterator
  385. {
  386. public:
  387. virtual ~IEconLootListIterator() { }
  388. virtual void OnIterate( item_definition_index_t unItemDefIndex ) = 0;
  389. };
  390. virtual void EnumerateUserFacingPotentialDrops( IEconLootListIterator *pIt ) const = 0;
  391. #ifdef GC_DLL
  392. MUST_CHECK_RETURN virtual bool BGenerateSingleRollRandomItems( const CEconGameAccount *pGameAccount, bool bFreeAccount, CUtlVector<CEconItem *> *out_pvecItems, const CUtlVector< item_definition_index_t > *pVecAvoidItemDefs = NULL ) const = 0;
  393. #endif // GC_DLL
  394. };
  395. #ifdef GC_DLL
  396. struct lootlist_attrib_t
  397. {
  398. static_attrib_t m_staticAttrib;
  399. float m_flWeight;
  400. bool BInitFromKV( const char *pszContext, KeyValues *pKVKey, CEconItemSchema &pschema, CUtlVector<CUtlString> *pVecErrors );
  401. };
  402. struct random_attrib_t
  403. {
  404. float m_flChanceOfRandomAttribute;
  405. float m_flTotalAttributeWeight;
  406. bool m_bPickAllAttributes;
  407. CUtlVector<lootlist_attrib_t> m_RandomAttributes;
  408. bool RollRandomAttributes( CUtlVector< static_attrib_t >& vecAttributes, const CEconGameAccount *pGameAccount ) const;
  409. };
  410. #endif // GC_DLL
  411. class CEconLootListDefinition : public IEconLootList
  412. {
  413. public:
  414. struct drop_period_t
  415. {
  416. bool IsValidForTime( const RTime32& time ) const;
  417. RTime32 m_DropStartDate;
  418. RTime32 m_DropEndDate;
  419. };
  420. struct drop_item_t
  421. {
  422. int m_iItemOrLootlistDef; // negative values indicate nested loot lists
  423. float m_flWeight;
  424. drop_period_t m_dropPeriod;
  425. };
  426. struct loot_list_additional_drop_t
  427. {
  428. float m_fChance;
  429. bool m_bPremiumOnly;
  430. const char *m_pszLootListDefName;
  431. int m_iRequiredHolidayIndex;
  432. drop_period_t m_dropPeriod;
  433. };
  434. virtual ~CEconLootListDefinition();
  435. bool BInitFromKV( KeyValues *pKVLootList, CEconItemSchema &pschema, CUtlVector<CUtlString> *pVecErrors );
  436. const char *GetName() const { return m_pszName; }
  437. virtual const char *GetLootListHeaderLocalizationKey() const OVERRIDE { return m_pszLootListHeader; }
  438. virtual const char *GetLootListFooterLocalizationKey() const OVERRIDE { return m_pszLootListFooter; }
  439. virtual const char *GetLootListCollectionReference() const OVERRIDE { return m_pszCollectionReference; }
  440. const CUtlVector<drop_item_t>& GetLootListContents() const { return m_DropList; }
  441. #ifdef GC_DLL
  442. const CUtlVector<loot_list_additional_drop_t>& GetAdditionalDrops() const { return m_AdditionalDrops; }
  443. #endif
  444. virtual void EnumerateUserFacingPotentialDrops( IEconLootListIterator *pIt ) const OVERRIDE;
  445. virtual bool BPublicListContents() const OVERRIDE
  446. {
  447. return m_bPublicListContents;
  448. }
  449. #ifdef GC_DLL
  450. public:
  451. struct rolled_item_defs_t
  452. {
  453. const CEconItemDefinition *m_pItemDef;
  454. CCopyableUtlVector< const CEconLootListDefinition * > m_vecAffectingLootLists;
  455. };
  456. bool AddRandomAtrributes( KeyValues *pRandomAttributesKV, CEconItemSchema &pschema, CUtlVector<CUtlString> *pVecErrors = NULL );
  457. bool AddRandomAttributesFromTemplates( KeyValues *pRandomAttributesKV, CEconItemSchema &pschema, CUtlVector<CUtlString> *pVecErrors = NULL );
  458. // Generates a single roll for this loot list as well as each "additional drop" loot list specified. This will return
  459. // true if all items were created successfully or false if anything went wrong in any of the relevant lootlists. All
  460. // items created will be returned via out_pvecItems.
  461. MUST_CHECK_RETURN virtual bool BGenerateSingleRollRandomItems( const CEconGameAccount *pGameAccount, bool bFreeAccount, CUtlVector<CEconItem *> *out_pvecItems, const CUtlVector< item_definition_index_t > *pVecAvoidItemDefs = NULL ) const OVERRIDE;
  462. void RollRandomAttributes( CUtlVector< static_attrib_t >& vecAttributes, const CEconGameAccount *pGameAccount ) const;
  463. bool RollRandomItemsAndAdditionalItems( IUniformRandomStream *pRandomStream, bool bFreeAccount, CUtlVector<rolled_item_defs_t> *out_pVecRolledItems, const CUtlVector< item_definition_index_t > *pVecAvoidItemDefs = NULL ) const;
  464. uint8 GetRarity() const { return m_unRarity; }
  465. void GetRarityLootLists( CUtlVector< const CEconLootListDefinition* > *out_pVecRarityLootList ) const;
  466. void GetItemDefs( CUtlVector< item_definition_index_t > *out_pVecItemDefs ) const;
  467. private:
  468. bool RollRandomItemDef( IUniformRandomStream *pRandomStream, bool bFreeAccount, CUtlVector<rolled_item_defs_t> *out_pVecRolledItems, const CUtlVector< item_definition_index_t > *pVecAvoidItemDefs = NULL ) const;
  469. bool BIsInternalNoDupesLootList() const { return m_iNoDupesIterations >= 0; }
  470. MUST_CHECK_RETURN bool BInitPropertyGeneratorsFromKV( KeyValues *pKV, CUtlVector<CUtlString> *pVecErrors );
  471. #endif
  472. private:
  473. const char *m_pszName;
  474. const char *m_pszLootListHeader;
  475. const char *m_pszLootListFooter;
  476. const char *m_pszCollectionReference;
  477. CUtlVector<drop_item_t> m_DropList;
  478. bool m_bPublicListContents; // do not show loot list contents to users (ie., when listing crate contents on Steam)
  479. #ifdef GC_DLL
  480. MUST_CHECK_RETURN bool BAttachLootListAttributes( const CEconGameAccount *pGameAccount, CEconItem *pItem ) const;
  481. int m_iNoDupesIterations; // if less than zero, "no dupes" functionality disabled; if greater than or equal to zero, the number of iterations we want to run through passing no-dupe sets
  482. CUtlVector<random_attrib_t*> m_RandomAttribs;
  483. CUtlVector<loot_list_additional_drop_t> m_AdditionalDrops;
  484. CUtlVector<const IEconItemPropertyGenerator *> m_PropertyGenerators;
  485. uint8 m_unRarity;
  486. #endif // GC_DLL
  487. };
  488. //-----------------------------------------------------------------------------
  489. // CEconCraftingRecipeDefinition
  490. // Template Definition of an item recipe
  491. //-----------------------------------------------------------------------------
  492. class CEconCraftingRecipeDefinition
  493. {
  494. public:
  495. CEconCraftingRecipeDefinition( void );
  496. virtual ~CEconCraftingRecipeDefinition( void ) { }
  497. bool BInitFromKV( KeyValues *pKVItem, CUtlVector<CUtlString> *pVecErrors = NULL );
  498. #ifdef GC_DLL
  499. bool BIsCraftableByUnverifiedClients() const { return m_bIsCraftableByUnverifiedClient; }
  500. #endif // GC_DLL
  501. virtual void CopyPolymorphic( const CEconCraftingRecipeDefinition *pSourceDef ) { *this = *pSourceDef; }
  502. void SetDefinitionIndex( uint32 iIndex ) { m_nDefIndex = iIndex; }
  503. int32 GetDefinitionIndex( void ) const { return m_nDefIndex; }
  504. const char *GetName( void ) const { return !m_strName.IsEmpty() ? m_strName.String() : "unknown"; }
  505. const char *GetName_A( void ) const { return !m_strN_A.IsEmpty() ? m_strN_A.String() : "unknown"; }
  506. const char *GetDescInputs( void ) const { return !m_strDescInputs.IsEmpty() ? m_strDescInputs.String() : "unknown"; }
  507. const char *GetDescOutputs( void ) const { return !m_strDescOutputs.IsEmpty() ? m_strDescOutputs.String() : "unknown"; }
  508. const char *GetDescI_A( void ) const { return !m_strDI_A.IsEmpty() ? m_strDI_A.String() : "unknown"; }
  509. const char *GetDescI_B( void ) const { return !m_strDI_B.IsEmpty() ? m_strDI_B.String() : "unknown"; }
  510. const char *GetDescI_C( void ) const { return !m_strDI_C.IsEmpty() ? m_strDI_C.String() : "unknown"; }
  511. const char *GetDescO_A( void ) const { return !m_strDO_A.IsEmpty() ? m_strDO_A.String() : "unknown"; }
  512. const char *GetDescO_B( void ) const { return !m_strDO_B.IsEmpty() ? m_strDO_B.String() : "unknown"; }
  513. const char *GetDescO_C( void ) const { return !m_strDO_C.IsEmpty() ? m_strDO_C.String() : "unknown"; }
  514. bool IsDisabled( void ) const { return m_bDisabled; }
  515. bool RequiresAllSameClass( void ) { return m_bRequiresAllSameClass; }
  516. bool RequiresAllSameSlot( void ) { return m_bRequiresAllSameSlot; }
  517. bool IsPremiumAccountOnly( void ) const { return m_bPremiumAccountOnly; }
  518. recipecategories_t GetCategory( void ) const { return m_iCategory; }
  519. int GetTotalInputItemsRequired( void ) const;
  520. int GetTotalOutputItems( void ) const { return m_OutputItemsCriteria.Count(); }
  521. // Returns true if the vector contains a set of items that matches the inputs for this recipe
  522. virtual bool ItemListMatchesInputs( CUtlVector<CEconItem*> *vecCraftingItems, KeyValues *out_pCraftParams = NULL, bool bIgnoreSlop = false, CUtlVector<uint64> *vecChosenItems = NULL ) const;
  523. const CUtlVector<CItemSelectionCriteria> *GetInputItems( void ) const { return &m_InputItemsCriteria; }
  524. const CUtlVector<uint32> &GetInputItemDupeCounts( void ) const { return m_InputItemDupeCounts; }
  525. const CUtlVector<CItemSelectionCriteria> &GetOutputItems( void ) const { return m_OutputItemsCriteria; }
  526. #ifdef DBGFLAG_VALIDATE
  527. void Validate( CValidator &validator, const char *pchName )
  528. {
  529. VALIDATE_SCOPE();
  530. ValidateObj( m_InputItemsCriteria );
  531. ValidateObj( m_InputItemDupeCounts );
  532. ValidateObj( m_OutputItemsCriteria );
  533. }
  534. #endif // DBGFLAG_VALIDATE
  535. // Serializes the criteria to and from messages
  536. bool BSerializeToMsg( CSOItemRecipe & msg ) const;
  537. bool BDeserializeFromMsg( const CSOItemRecipe & msg );
  538. protected:
  539. // The number used to refer to this definition in the DB
  540. int32 m_nDefIndex;
  541. // Localization key strings
  542. CUtlString m_strName;
  543. CUtlString m_strN_A;
  544. CUtlString m_strDescInputs;
  545. CUtlString m_strDescOutputs;
  546. CUtlString m_strDI_A;
  547. CUtlString m_strDI_B;
  548. CUtlString m_strDI_C;
  549. CUtlString m_strDO_A;
  550. CUtlString m_strDO_B;
  551. CUtlString m_strDO_C;
  552. bool m_bDisabled;
  553. #ifdef GC_DLL
  554. bool m_bIsCraftableByUnverifiedClient;
  555. #endif // GC_DLL
  556. bool m_bRequiresAllSameClass;
  557. bool m_bRequiresAllSameSlot;
  558. int m_iCacheClassUsageForOutputFromItem;
  559. int m_iCacheSlotUsageForOutputFromItem;
  560. int m_iCacheSetForOutputFromItem;
  561. bool m_bPremiumAccountOnly;
  562. recipecategories_t m_iCategory;
  563. // The list of items that a required to make this recipe
  564. CUtlVector<CItemSelectionCriteria> m_InputItemsCriteria;
  565. CUtlVector<uint32> m_InputItemDupeCounts;
  566. // The list of items that are generated by this recipe
  567. CUtlVector<CItemSelectionCriteria> m_OutputItemsCriteria;
  568. };
  569. //-----------------------------------------------------------------------------
  570. // Purpose: Attribute definition details
  571. //-----------------------------------------------------------------------------
  572. enum
  573. {
  574. ATTDESCFORM_VALUE_IS_PERCENTAGE, // Printed as: ((m_flValue*100)-100.0)
  575. ATTDESCFORM_VALUE_IS_INVERTED_PERCENTAGE, // Printed as: ((m_flValue*100)-100.0) if it's > 1.0, or ((1.0-m_flModifier)*100) if it's < 1.0
  576. ATTDESCFORM_VALUE_IS_ADDITIVE, // Printed as: m_flValue
  577. ATTDESCFORM_VALUE_IS_ADDITIVE_PERCENTAGE, // Printed as: (m_flValue*100)
  578. ATTDESCFORM_VALUE_IS_OR, // Printed as: m_flValue, but results are ORd together instead of added
  579. ATTDESCFORM_VALUE_IS_DATE, // Printed as a date
  580. ATTDESCFORM_VALUE_IS_ACCOUNT_ID, // Printed as steam user name
  581. ATTDESCFORM_VALUE_IS_PARTICLE_INDEX, // Printed as a particle description
  582. ATTDESCFORM_VALUE_IS_KILLSTREAKEFFECT_INDEX,// Printed as killstreak effect description
  583. ATTDESCFORM_VALUE_IS_KILLSTREAK_IDLEEFFECT_INDEX, // Printed as idle effect description
  584. ATTDESCFORM_VALUE_IS_ITEM_DEF, // Printed as item name
  585. ATTDESCFORM_VALUE_IS_FROM_LOOKUP_TABLE, // Printed as a string from a lookup table, specified by the attribute definition name
  586. };
  587. // Coloring for attribute lines
  588. enum attrib_effect_types_t
  589. {
  590. ATTRIB_EFFECT_UNUSUAL = 0,
  591. ATTRIB_EFFECT_STRANGE,
  592. ATTRIB_EFFECT_NEUTRAL,
  593. ATTRIB_EFFECT_POSITIVE,
  594. ATTRIB_EFFECT_NEGATIVE,
  595. NUM_EFFECT_TYPES,
  596. };
  597. enum EAssetClassAttrExportRule_t
  598. {
  599. k_EAssetClassAttrExportRule_Default = 0,
  600. k_EAssetClassAttrExportRule_Bucketed = ( 1 << 0 ), // attribute exports bucketed value to Steam Community
  601. k_EAssetClassAttrExportRule_Skip = ( 1 << 1 ), // attribute value is not exported to Steam Community
  602. k_EAssetClassAttrExportRule_GCOnly = ( 1 << 2 ), // attribute only lives on GC and not exported to any external request
  603. };
  604. //-----------------------------------------------------------------------------
  605. // CEconItemAttributeDefinition
  606. // Template definition of a randomly created attribute
  607. //-----------------------------------------------------------------------------
  608. class CEconItemAttributeDefinition
  609. {
  610. public:
  611. CEconItemAttributeDefinition( void );
  612. CEconItemAttributeDefinition( const CEconItemAttributeDefinition &that );
  613. CEconItemAttributeDefinition &operator=( const CEconItemAttributeDefinition& rhs );
  614. ~CEconItemAttributeDefinition( void );
  615. bool BInitFromKV( KeyValues *pKVAttribute, CUtlVector<CUtlString> *pVecErrors = NULL );
  616. attrib_definition_index_t GetDefinitionIndex( void ) const { return m_nDefIndex; }
  617. // Attribute name referenced in the db.
  618. const char *GetDefinitionName( void ) const { return m_pszDefinitionName; }
  619. KeyValues *GetRawDefinition( void ) const { return m_pKVAttribute; }
  620. // Data accessing
  621. bool IsHidden( void ) const { return m_bHidden; }
  622. bool BForceWebSchemaOutput( void ) const { return m_bWebSchemaOutputForced; }
  623. bool BIsSetBonusAttribute( void ) const { return m_bIsSetBonus; }
  624. bool CanAffectMarketName( void ) const { return m_bCanAffectMarketName; }
  625. bool CanAffectRecipeComponentName( void ) const { return m_bCanAffectRecipeComponentName; }
  626. bool IsStoredAsInteger( void ) const { return m_bStoredAsInteger; }
  627. bool IsStoredAsFloat( void ) const { return !m_bStoredAsInteger; }
  628. int GetUserGenerationType( void ) const { return m_iUserGenerationType; }
  629. bool IsInstanceData() const { return m_bInstanceData; }
  630. EAssetClassAttrExportRule_t GetAssetClassAttrExportRule() const { return m_eAssetClassAttrExportRule; }
  631. uint32 GetAssetClassBucket() const { return m_unAssetClassBucket; }
  632. int GetDescriptionFormat( void ) const { return m_iDescriptionFormat; }
  633. const char *GetDescriptionString( void ) const { return m_pszDescriptionString; }
  634. const char *GetArmoryDescString( void ) const { return m_pszArmoryDesc; }
  635. const char *GetAttributeClass( void ) const { return m_pszAttributeClass; }
  636. econ_tag_handle_t GetItemDefinitionTag( void ) const { return m_ItemDefinitionTag; }
  637. attrib_effect_types_t GetEffectType( void ) const { return m_iEffectType; }
  638. const class ISchemaAttributeType *GetAttributeType( void ) const { return m_pAttrType; }
  639. #ifndef GC_DLL
  640. void ClearStringCache( void ) const { m_iszAttributeClass = NULL_STRING; }
  641. string_t GetCachedClass( void ) const
  642. {
  643. if ( m_iszAttributeClass == NULL_STRING && m_pszAttributeClass )
  644. {
  645. m_iszAttributeClass = AllocPooledString( m_pszAttributeClass );
  646. }
  647. return m_iszAttributeClass;
  648. }
  649. #endif
  650. #ifdef DBGFLAG_VALIDATE
  651. void Validate( CValidator &validator, const char *pchName )
  652. {
  653. VALIDATE_SCOPE();
  654. ValidatePtr( m_pKVAttribute );
  655. }
  656. #endif // DBGFLAG_VALIDATE
  657. private:
  658. // The raw keyvalues for this attribute definition.
  659. KeyValues *m_pKVAttribute;
  660. // Required valued from m_pKVAttribute:
  661. // The number used to refer to this definition in the DB
  662. attrib_definition_index_t m_nDefIndex;
  663. // A pointer to the schema-global type data for this attribute. This maps attribute types to functionality
  664. // for loading/storing, both to memory and the DB.
  665. const class ISchemaAttributeType *m_pAttrType;
  666. // ---------------------------------------------
  667. // Display related data
  668. // ---------------------------------------------
  669. // If true, this attribute isn't shown in the item description
  670. bool m_bHidden;
  671. // If true, this attribute's description is always output in web api calls regardless of the hidden flag.
  672. bool m_bWebSchemaOutputForced;
  673. // Whether or not the value is stored as an integer in the DB.
  674. bool m_bStoredAsInteger;
  675. // If this is true the attribute is counted as "instance" data for purposes of asset class in the Steam Economy. Non-instance
  676. // properties are considered things that can differentiate items at a fundamental level (ie., definition index, quality); instance
  677. // properties are more things like additional customizations -- score for strange items, paint color, etc.
  678. bool m_bInstanceData;
  679. EAssetClassAttrExportRule_t m_eAssetClassAttrExportRule; // if this is true the attribute will not be exported for asset class
  680. uint32 m_unAssetClassBucket; // if this is set then attribute value is bucketed when exported for asset class
  681. // Set item bonus attributes use a different attribute parser and make assumptions about memory layout. We
  682. // don't really use these for any new content currently and it isn't worth touching all the old code.
  683. //
  684. // At runtime, this flag is used to determine whether or not to rebuild dynamic attributes attached to
  685. // players on respawn.
  686. bool m_bIsSetBonus;
  687. // Whether or not this attribute is supposed to only come from user actions. These attributes are used for
  688. // player item upgrades, etc. and cannot be set on items directly in the schema.
  689. int m_iUserGenerationType;
  690. // Overall positive/negative effect. Used to color the attribute.
  691. attrib_effect_types_t m_iEffectType;
  692. // Contains the description format & string for this attribute
  693. int m_iDescriptionFormat;
  694. const char *m_pszDescriptionString;
  695. // Contains information on how to describe items with this attribute in the Armory
  696. const char *m_pszArmoryDesc;
  697. // Used to allow unique items to specify attributes by name.
  698. const char *m_pszDefinitionName;
  699. // The class name of this attribute. Used in creation, and to hook the attribute into the actual code that uses it.
  700. const char *m_pszAttributeClass;
  701. // Allowed to affect the market bucketization name. We dont want things like the strange level to affect the name,
  702. // but we do want things like crate series number and strangifier targets to get their own buckets.
  703. bool m_bCanAffectMarketName;
  704. // Allowed to list itself in the name of an item in the recipe component description.
  705. bool m_bCanAffectRecipeComponentName;
  706. // Do item definitions with this attribute specified automatically get an additional tag applied?
  707. econ_tag_handle_t m_ItemDefinitionTag;
  708. #ifndef GC_DLL
  709. mutable string_t m_iszAttributeClass; // Same as the above, but used for fast lookup when applying attributes.
  710. #endif
  711. };
  712. //-----------------------------------------------------------------------------
  713. // Visual data storage in item definitions
  714. //-----------------------------------------------------------------------------
  715. #define TEAM_VISUAL_SECTIONS 5
  716. #define MAX_VISUALS_CUSTOM_SOUNDS 10
  717. struct attachedparticlesystem_t
  718. {
  719. attachedparticlesystem_t() :
  720. pszSystemName( NULL )
  721. , bFollowRootBone( NULL )
  722. , iCustomType( 0 )
  723. , nSystemID( 0 )
  724. , fRefireTime( 0 ) // only works for taunt effects, currently
  725. , bDrawInViewModel( false )
  726. , bUseSuffixName( false )
  727. , bHasViewModelSpecificEffect ( false )
  728. {
  729. V_memset( pszControlPoints, 0, sizeof( pszControlPoints ) );
  730. }
  731. const char *pszSystemName;
  732. bool bFollowRootBone;
  733. int iCustomType;
  734. int nSystemID;
  735. float fRefireTime; // only works for taunt effects, currently
  736. bool bDrawInViewModel;
  737. bool bUseSuffixName;
  738. bool bHasViewModelSpecificEffect;
  739. const char *pszControlPoints[7];
  740. };
  741. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  742. enum
  743. {
  744. kAttachedModelDisplayFlag_WorldModel = 0x01,
  745. kAttachedModelDisplayFlag_ViewModel = 0x02,
  746. kAttachedModelDisplayFlag_MaskAll = kAttachedModelDisplayFlag_WorldModel | kAttachedModelDisplayFlag_ViewModel,
  747. };
  748. struct attachedmodel_t
  749. {
  750. const char *m_pszModelName;
  751. int m_iModelDisplayFlags;
  752. };
  753. enum wearableanimplayback_t
  754. {
  755. WAP_ON_SPAWN, // Play this animation immediately on spawning the wearable
  756. WAP_START_BUILDING, // Game code will start this anim whenever a player wearing this item deploys their builder weapon.
  757. WAP_STOP_BUILDING, // Game code will start this anim whenever a player wearing this item holsters their builder weapon.
  758. WAP_START_TAUNTING, // Game code will start this anim whenever a player wearing this item taunts
  759. WAP_STOP_TAUNTING, // Game code will start this anim whenever a player wearing this item stops taunting
  760. NUM_WAP_TYPES,
  761. };
  762. struct animation_on_wearable_t
  763. {
  764. int iActivity;
  765. const char *pszActivity;
  766. const char *pszReplacement;
  767. int iReplacement; // Replacement activity to play. Might be set to one of kActivityLookup_Unknown/kActivityLookup_Missing.
  768. const char *pszSequence;
  769. const char *pszRequiredItem;
  770. const char *pszScene;
  771. };
  772. struct activity_on_wearable_t
  773. {
  774. wearableanimplayback_t iPlayback;
  775. int iActivity;
  776. const char *pszActivity;
  777. };
  778. struct codecontrolledbodygroupdata_t
  779. {
  780. const char *pFuncName;
  781. void *pFunc;
  782. };
  783. // This is a workaround because Source practice is to disable operator=() for CUtlMap.
  784. struct perteamvisuals_maps_t
  785. {
  786. perteamvisuals_maps_t()
  787. {
  788. m_ModifiedBodyGroupNames.SetLessFunc( StringLessThan );
  789. m_CodeControlledBodyGroupNames.SetLessFunc( StringLessThan );
  790. }
  791. void operator=( const perteamvisuals_maps_t& other )
  792. {
  793. DeepCopyMap( other.m_ModifiedBodyGroupNames, &m_ModifiedBodyGroupNames );
  794. DeepCopyMap( other.m_CodeControlledBodyGroupNames, &m_CodeControlledBodyGroupNames );
  795. }
  796. CUtlMap<const char*, int> m_ModifiedBodyGroupNames; // Better method: hide multiple body groups by name.
  797. CUtlMap<const char*, codecontrolledbodygroupdata_t> m_CodeControlledBodyGroupNames;
  798. };
  799. #endif // defined(CLIENT_DLL) || defined(GAME_DLL)
  800. class CEconStyleInfo
  801. {
  802. public:
  803. CEconStyleInfo()
  804. {
  805. for ( int i = 0; i < TEAM_VISUAL_SECTIONS; i++ )
  806. {
  807. m_iSkins[i] = 0;
  808. m_iViewmodelSkins[i] = -1;
  809. }
  810. m_pszName = NULL;
  811. m_pszBasePlayerModel = NULL;
  812. m_bIsSelectable = true;
  813. m_pszInventoryImage = NULL;
  814. m_pszBodygroupName = NULL;
  815. m_iBodygroupSubmodelIndex = -1;
  816. m_sIconURLSmall = "";
  817. m_sIconURLLarge = "";
  818. }
  819. virtual ~CEconStyleInfo()
  820. {
  821. //
  822. }
  823. virtual void BInitFromKV( KeyValues *pKVItem, CUtlVector<CUtlString> *pVecErrors );
  824. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  825. virtual void GeneratePrecacheModelStringsForStyle( CUtlVector<const char *> *out_pVecModelStrings ) const;
  826. #endif
  827. int GetSkin( int iTeam, bool bViewmodel ) const
  828. {
  829. Assert( iTeam >= 0 );
  830. Assert( iTeam < TEAM_VISUAL_SECTIONS );
  831. if ( bViewmodel && m_iViewmodelSkins[ iTeam ] != -1 )
  832. {
  833. return m_iViewmodelSkins[ iTeam ];
  834. }
  835. return m_iSkins[iTeam];
  836. }
  837. const char *GetName() const { return m_pszName; }
  838. const char *GetBasePlayerDisplayModel() const { return m_pszBasePlayerModel; }
  839. const CUtlVector<const char *>& GetAdditionalHideBodygroups() const { return m_vecAdditionalHideBodygroups; }
  840. bool IsSelectable() const { return m_bIsSelectable; }
  841. const char *GetInventoryImage() const { return m_pszInventoryImage; }
  842. const char *GetBodygroupName() const { return m_pszBodygroupName; }
  843. int GetBodygroupSubmodelIndex() const { return m_iBodygroupSubmodelIndex; }
  844. const char *GetIconURLSmall() const { return m_sIconURLSmall; }
  845. const char *GetIconURLLarge() const { return m_sIconURLLarge; }
  846. void SetIconURLSmall( const char *szURL ) { m_sIconURLSmall = szURL; }
  847. void SetIconURLLarge( const char *szURL ) { m_sIconURLLarge = szURL; }
  848. protected:
  849. int m_iSkins[TEAM_VISUAL_SECTIONS];
  850. int m_iViewmodelSkins[TEAM_VISUAL_SECTIONS];
  851. const char *m_pszName;
  852. const char *m_pszBasePlayerModel;
  853. bool m_bIsSelectable;
  854. const char *m_pszInventoryImage;
  855. const char *m_pszBodygroupName;
  856. int m_iBodygroupSubmodelIndex;
  857. CUtlVector<const char *> m_vecAdditionalHideBodygroups;
  858. private:
  859. CUtlString m_sIconURLSmall;
  860. CUtlString m_sIconURLLarge;
  861. };
  862. struct perteamvisuals_t
  863. {
  864. perteamvisuals_t()
  865. {
  866. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  867. iHideParentBodyGroup = -1;
  868. iSkin = -1;
  869. bUsePerClassBodygroups = false;
  870. pszMaterialOverride = NULL;
  871. pszMuzzleFlash = NULL;
  872. pszTracerEffect = NULL;
  873. pszParticleEffect = NULL;
  874. for ( int i = 0; i < MAX_VISUALS_CUSTOM_SOUNDS; i++ )
  875. {
  876. pszCustomSounds[i] = NULL;
  877. }
  878. for ( int i = 0; i < NUM_SHOOT_SOUND_TYPES; i++ )
  879. {
  880. pszWeaponSoundReplacements[i] = NULL;
  881. }
  882. m_iViewModelBodyGroupOverride = -1;
  883. m_iViewModelBodyGroupStateOverride = -1;
  884. m_iWorldModelBodyGroupOverride = -1;
  885. m_iWorldModelBodyGroupStateOverride = -1;
  886. #endif // defined(CLIENT_DLL) || defined(GAME_DLL)
  887. }
  888. ~perteamvisuals_t()
  889. {
  890. m_Styles.PurgeAndDeleteElements();
  891. }
  892. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  893. int iHideParentBodyGroup;
  894. // Properties necessary for the game client/server but not for the GC.
  895. perteamvisuals_maps_t m_Maps;
  896. int iSkin;
  897. bool bUsePerClassBodygroups;
  898. CUtlVector<attachedmodel_t> m_AttachedModels;
  899. CUtlVector<attachedmodel_t> m_AttachedModelsFestive; // Attr controlled Festive Attachments
  900. CUtlVector<attachedparticlesystem_t> m_AttachedParticles;
  901. CUtlVector<animation_on_wearable_t> m_Animations;
  902. CUtlVector<activity_on_wearable_t> m_Activities;
  903. const char *pszCustomSounds[MAX_VISUALS_CUSTOM_SOUNDS];
  904. const char *pszMaterialOverride;
  905. const char *pszMuzzleFlash;
  906. const char *pszTracerEffect;
  907. const char *pszParticleEffect;
  908. const char *pszWeaponSoundReplacements[NUM_SHOOT_SOUND_TYPES];
  909. int m_iViewModelBodyGroupOverride;
  910. int m_iViewModelBodyGroupStateOverride;
  911. int m_iWorldModelBodyGroupOverride;
  912. int m_iWorldModelBodyGroupStateOverride;
  913. #endif // defined(CLIENT_DLL) || defined(GAME_DLL)
  914. // The GC does care about styles.
  915. CUtlVector<CEconStyleInfo *> m_Styles;
  916. };
  917. enum item_capabilities_t
  918. {
  919. ITEM_CAP_NONE = 0,
  920. ITEM_CAP_PAINTABLE = 1 << 0,
  921. ITEM_CAP_NAMEABLE = 1 << 1,
  922. ITEM_CAP_DECODABLE = 1 << 2,
  923. ITEM_CAP_CAN_BE_CRAFTED_IF_PURCHASED = 1 << 3, // was ITEM_CAP_CAN_MOD_SOCKET
  924. ITEM_CAP_CAN_CUSTOMIZE_TEXTURE = 1 << 4,
  925. ITEM_CAP_USABLE = 1 << 5,
  926. ITEM_CAP_USABLE_GC = 1 << 6,
  927. ITEM_CAP_CAN_GIFT_WRAP = 1 << 7,
  928. ITEM_CAP_USABLE_OUT_OF_GAME = 1 << 8,
  929. ITEM_CAP_CAN_COLLECT = 1 << 9,
  930. ITEM_CAP_CAN_CRAFT_COUNT = 1 << 10,
  931. ITEM_CAP_CAN_CRAFT_MARK = 1 << 11,
  932. ITEM_CAP_PAINTABLE_TEAM_COLORS = 1 << 12,
  933. ITEM_CAP_CAN_BE_RESTORED = 1 << 13, // can users remove properties (paint, nametag, etc.) from this item via the in-game UI?
  934. ITEM_CAP_CAN_USE_STRANGE_PARTS = 1 << 14,
  935. ITEM_CAP_CAN_CARD_UPGRADE = 1 << 15,
  936. ITEM_CAP_CAN_STRANGIFY = 1 << 16,
  937. ITEM_CAP_CAN_KILLSTREAKIFY = 1 << 17,
  938. ITEM_CAP_CAN_CONSUME = 1 << 18,
  939. ITEM_CAP_CAN_SPELLBOOK_PAGE = 1 << 19, // IT'S A VERB OKAY
  940. ITEM_CAP_HAS_SLOTS = 1 << 20,
  941. ITEM_CAP_DUCK_UPGRADABLE = 1 << 21,
  942. ITEM_CAP_CAN_UNUSUALIFY = 1 << 22,
  943. NUM_ITEM_CAPS = 23,
  944. };
  945. enum { ITEM_CAP_DEFAULT = ITEM_CAP_CAN_CRAFT_MARK | ITEM_CAP_CAN_BE_RESTORED | ITEM_CAP_CAN_USE_STRANGE_PARTS | ITEM_CAP_CAN_CARD_UPGRADE | ITEM_CAP_CAN_STRANGIFY | ITEM_CAP_CAN_KILLSTREAKIFY | ITEM_CAP_CAN_CONSUME | ITEM_CAP_CAN_GIFT_WRAP }; // what are the default capabilities on an item?
  946. enum { ITEM_CAP_TOOL_DEFAULT = ITEM_CAP_NONE }; // what are the default capabilities of a tool?
  947. struct bundleinfo_t
  948. {
  949. CUtlVector<CEconItemDefinition *> vecItemDefs;
  950. };
  951. #ifdef GC_DLL
  952. enum EPaymentRuleType
  953. {
  954. kPaymentRule_SteamWorkshopFileID = 0x01,
  955. kPaymentRule_PartnerSteamID = 0x02,
  956. kPaymentRule_Bundle = 0x04,
  957. };
  958. struct econ_item_payment_rule_t
  959. {
  960. double m_RevenueShare;
  961. EPaymentRuleType m_eRuleType;
  962. CCopyableUtlVector<uint64> m_vecValues;
  963. };
  964. #endif // GC_DLL
  965. #ifdef CLIENT_DLL
  966. namespace vgui
  967. {
  968. class Panel;
  969. }
  970. #endif // CLIENT_DLL
  971. class IEconTool
  972. {
  973. friend class CEconSharedToolSupport;
  974. public:
  975. IEconTool( const char *pszTypeName, const char *pszUseString, const char *pszUsageRestriction, item_capabilities_t unCapabilities )
  976. : m_pszTypeName( pszTypeName )
  977. , m_pszUseString( pszUseString )
  978. , m_pszUsageRestriction( pszUsageRestriction )
  979. , m_unCapabilities( unCapabilities )
  980. {
  981. //
  982. }
  983. virtual ~IEconTool() { }
  984. // Shared code.
  985. const char *GetUsageRestriction() const { return m_pszUsageRestriction; }
  986. item_capabilities_t GetCapabilities() const { return m_unCapabilities; }
  987. virtual bool CanApplyTo( const IEconItemInterface *pTool, const IEconItemInterface *pToolSubject ) const { Assert( pTool ); Assert( pToolSubject ); return true; }
  988. virtual bool ShouldDisplayQuantity( const IEconItemInterface *pTool ) const;
  989. virtual bool RequiresToolEscrowPeriod() const { return false; }
  990. // We don't support throwing exceptions from tool construction so this is intended to be checked afterwards
  991. // whenever a new tool is created. (See CreateEconToolImpl().)
  992. virtual bool BFinishInitialization() { return true; }
  993. // Used by the GC only for WebAPI responses and for some weird internal code.
  994. const char *GetTypeName() const { return m_pszTypeName; } // would like to disable on the client so we aren't tempted to check against it, but used for building a unique tool list
  995. const char *GetUseString() const { return m_pszUseString; }
  996. #ifdef CLIENT_DLL
  997. virtual bool CanBeUsedNow( const IEconItemInterface *pItem ) const { return true; }
  998. virtual bool ShouldShowContainedItemPanel( const IEconItemInterface *pItem ) const { Assert( !"IEconTool::ShouldShowContainedItemPanel(): we don't expect this to be called on anything besides gifts!" ); return false; }
  999. virtual bool ShouldDisplayAsUseableOnItemsInArmory() const { return true; }
  1000. virtual const char *GetUseCommandLocalizationToken( const IEconItemInterface *pItem, int i = 0 ) const;
  1001. virtual int GetUseCommandCount( const IEconItemInterface *pItem ) const { return 1; }
  1002. virtual const char* GetUseCommand( const IEconItemInterface *pItem, int i = 0 ) const;
  1003. // Client "do something" interface. At least one of these functions must be implemented or your tool
  1004. // won't do anything on the client. Some tools (ie., collections) will implement both because they
  1005. // have one application behavior and one client-UI behavior.
  1006. // When the client attempts to use a consumable item of any kind, this function will be called. This
  1007. // is called from the UI in response to things like using dueling pistols, using a noisemaker, etc.
  1008. // Usually this opens up some UI, sends off a GC message, etc.
  1009. //
  1010. // There is a "default" implementation of this function in ClientConsumableTool_Generic() that can
  1011. // be called if specific behavior isn't needed.
  1012. virtual void OnClientUseConsumable( class C_EconItemView *pItem, vgui::Panel *pParent ) const
  1013. {
  1014. Assert( !"IEconTool::OnClientUseConsumable(): unimplemented call!" );
  1015. }
  1016. // When the client attempts to apply a tool to a specific other item in their inventory, this function
  1017. // will be called. This is called from the UI is response to things like putting paint on an item,
  1018. // using a key to unlock a crate, etc.
  1019. virtual void OnClientApplyTool( class C_EconItemView *pTool, class C_EconItemView *pSubject, vgui::Panel *pParent ) const
  1020. {
  1021. Assert( !"IEconTool::OnClientApplyTool(): unimplemented call!" );
  1022. }
  1023. #endif // CLIENT_DLL
  1024. #ifdef GC_DLL
  1025. virtual class CGCEconConsumableBehavior *CreateGCConsumableBehavior() const;
  1026. virtual bool BGenerateDynamicAttributes( CEconItem* pItem, const CEconGameAccount *pGameAccount ) const { return true; }
  1027. #endif // GC_DLL
  1028. private:
  1029. const char *m_pszTypeName;
  1030. const char *m_pszUseString;
  1031. const char *m_pszUsageRestriction;
  1032. item_capabilities_t m_unCapabilities;
  1033. };
  1034. //-----------------------------------------------------------------------------
  1035. // CQuestObjectiveDefinition
  1036. //-----------------------------------------------------------------------------
  1037. class CQuestObjectiveDefinition
  1038. {
  1039. public:
  1040. CQuestObjectiveDefinition( void );
  1041. virtual ~CQuestObjectiveDefinition( void );
  1042. virtual bool BInitFromKV( KeyValues *pKVItem, CUtlVector<CUtlString> *pVecErrors = NULL );
  1043. uint32 GetDefinitionIndex( void ) const { return m_nDefIndex; }
  1044. const char *GetDescriptionToken( void ) const { return m_pszDescriptionToken; }
  1045. bool IsOptional() const { return m_bOptional; }
  1046. bool IsAdvanced() const { return m_bAdvanced; }
  1047. uint32 GetPoints() const { return m_nPoints; } // TODO: change to a float
  1048. private:
  1049. const char *m_pszDescriptionToken;
  1050. uint32 m_nDefIndex;
  1051. uint32 m_nPoints;
  1052. bool m_bOptional;
  1053. bool m_bAdvanced;
  1054. };
  1055. //-----------------------------------------------------------------------------
  1056. // CEconItemDefinition
  1057. // Template Definition of a randomly created item
  1058. //-----------------------------------------------------------------------------
  1059. class CEconItemDefinition
  1060. {
  1061. public:
  1062. CEconItemDefinition( void );
  1063. virtual ~CEconItemDefinition( void );
  1064. // BInitFromKV can be implemented on subclasses to parse additional values.
  1065. virtual bool BInitFromKV( KeyValues *pKVItem, CUtlVector<CUtlString> *pVecErrors = NULL );
  1066. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  1067. virtual bool BInitFromTestItemKVs( int iNewDefIndex, KeyValues *pKVItem, CUtlVector<CUtlString>* pVecErrors = NULL );
  1068. virtual void GeneratePrecacheModelStrings( bool bDynamicLoad, CUtlVector<const char *> *out_pVecModelStrings ) const;
  1069. virtual void GeneratePrecacheSoundStrings( bool bDynamicLoad, CUtlVector<const char *> *out_pVecSoundStrings ) const;
  1070. virtual void CopyPolymorphic( const CEconItemDefinition *pSourceDef ) { *this = *pSourceDef; }
  1071. #endif
  1072. bool BInitItemMappings( CUtlVector<CUtlString> *pVecErrors );
  1073. void BInitVisualBlockFromKV( KeyValues *pKVItem, CUtlVector<CUtlString> *pVecErrors = NULL );
  1074. void BInitStylesBlockFromKV( KeyValues *pKVStyles, perteamvisuals_t *pVisData, CUtlVector<CUtlString> *pVecErrors );
  1075. item_definition_index_t GetDefinitionIndex( void ) const { return m_nDefIndex; }
  1076. bool BEnabled( void ) const { return m_bEnabled; }
  1077. bool BLoadOnDemand( void ) const { return m_bLoadOnDemand; }
  1078. bool BHasBeenLoaded( void ) const { return m_bHasBeenLoaded; }
  1079. const char *GetDefinitionName( void ) const { return m_pszDefinitionName; }
  1080. const char *GetItemDefinitionName( void ) const { return m_pszDefinitionName; }
  1081. const char *GetItemClass( void ) const { return m_pszItemClassname; }
  1082. const char *GetItemBaseName( void ) const { return m_pszItemBaseName; }
  1083. const char *GetBrassModelOverride( void ) const{ return m_pszBrassModelOverride; }
  1084. const char *GetItemTypeName( void ) const { return m_pszItemTypeName; }
  1085. uint8 GetMinLevel( void ) const { return m_unMinItemLevel; }
  1086. uint8 GetMaxLevel( void ) const { return m_unMaxItemLevel; }
  1087. uint8 GetItemSeries( void ) const { return m_unItemSeries; }
  1088. uint8 GetQuality( void ) const { return m_nItemQuality; }
  1089. void SetRarity( uint8 nRarity ) { Assert( m_nItemRarity == k_unItemRarity_Any ); m_nItemRarity = nRarity; }
  1090. uint8 GetRarity( void ) const { return m_nItemRarity; }
  1091. uint8 GetForcedQuality( void ) const { return m_nForcedItemQuality; }
  1092. uint16 GetDefaultDropQuantity( void ) const { return m_nDefaultDropQuantity; }
  1093. KeyValues *GetRawDefinition( void ) const { return m_pKVItem; }
  1094. const char *GetDefinitionString( const char *pszKeyName, const char *pszDefaultValue = "" ) const;
  1095. KeyValues *GetDefinitionKey( const char *pszKeyName ) const;
  1096. const CUtlVector<static_attrib_t> &GetStaticAttributes( void ) const { return m_vecStaticAttributes; }
  1097. #ifdef TF_CLIENT_DLL
  1098. uint32 GetNumConcreteItems() const { return m_unNumConcreteItems; }
  1099. #endif // TF_CLIENT_DLL
  1100. // Data accessing
  1101. bool IsHidden( void ) const { return m_bHidden; }
  1102. bool IsImported( void ) const { return m_bImported; }
  1103. bool IsAllowedInMatch( void ) const { return m_bAllowedInThisMatch; }
  1104. bool IsBaseItem( void ) const { return m_bBaseItem; }
  1105. bool IsBundle( void ) const { return m_BundleInfo != NULL; }
  1106. bool HasProperName( void ) const { return m_bProperName; }
  1107. const char *GetClassToken( void ) const { return m_pszClassToken; }
  1108. const char *GetSlotToken( void ) const { return m_pszSlotToken; }
  1109. bool ShouldAttachToHands( void ) const { return m_bAttachToHands; }
  1110. bool ShouldAttachToHandsVMOnly( void ) const { return m_bAttachToHandsVMOnly; }
  1111. bool ShouldFlipViewmodels( void ) const { return m_bFlipViewModel; }
  1112. int GetInventoryImagePosition( int iIndex ) const { Assert( iIndex >= 0 && iIndex < 2); return m_iInventoryImagePosition[iIndex]; }
  1113. int GetInventoryImageSize( int iIndex ) const { Assert( iIndex >= 0 && iIndex < 2); return m_iInventoryImageSize[iIndex]; }
  1114. int GetDropType( void ) const { return m_iDropType; }
  1115. const char *GetHolidayRestriction( void ) const { return m_pszHolidayRestriction; }
  1116. int GetVisionFilterFlags( void ) const { return m_nVisionFilterFlags; }
  1117. int GetSubType( void ) const { return m_iSubType; }
  1118. item_capabilities_t GetCapabilities( void ) const { return m_iCapabilities; }
  1119. int GetArmoryRemap( void ) const { return m_iArmoryRemap; }
  1120. int GetStoreRemap( void ) const { return m_iStoreRemap; }
  1121. item_definition_index_t GetSetItemRemap() const { return m_unSetItemRemapDefIndex; } // what def index do we consider ourself for purposes of determining "is an item equipped that satisfies this set slot?" (ie., Festive Huntsman -> Huntsman); default is to point to itself
  1122. const char *GetXifierRemapClass() const { return m_pszXifierRemapClass; }
  1123. const char *GetBaseFunctionalItemName() const { return m_pszBaseFunctionalItemName; }
  1124. const char *GetParticleSuffix() const { return m_pszParticleSuffix; }
  1125. const CEconItemSetDefinition *GetItemSetDefinition( void ) const { return m_pItemSetDef; }
  1126. void SetItemSetDefinition( const CEconItemSetDefinition *pItemSetDef ) { Assert( !m_pItemSetDef ); m_pItemSetDef = pItemSetDef; }
  1127. const CEconItemCollectionDefinition *GetItemCollectionDefinition( void ) const { return m_pItemCollectionDef; }
  1128. void SetItemCollectionDefinition( const CEconItemCollectionDefinition *pItemCollectionDef ) { Assert( !m_pItemCollectionDef ); m_pItemCollectionDef = pItemCollectionDef; }
  1129. CEconItemPaintKitDefinition *GetCustomPainkKitDefinition( void ) const { return m_pItemPaintKitDef; }
  1130. void SetItemPaintKitDefinition( CEconItemPaintKitDefinition *pItemPaintKitDef ) { Assert( !m_pItemPaintKitDef ); m_pItemPaintKitDef = pItemPaintKitDef; }
  1131. perteamvisuals_t *GetPerTeamVisual( int iTeam ) const { return m_PerTeamVisuals[iTeam]; }
  1132. bool IsTool() const { return m_bIsTool; }
  1133. const IEconTool *GetEconTool() const { return m_pTool; }
  1134. template < class T >
  1135. const T *GetTypedEconTool() const { return dynamic_cast<const T *>( GetEconTool() ); }
  1136. const bundleinfo_t *GetBundleInfo( void ) const { return m_BundleInfo; }
  1137. virtual int GetBundleItemCount( void ) const { return m_BundleInfo ? m_BundleInfo->vecItemDefs.Count() : 0; }
  1138. virtual int GetBundleItem( int iIndex ) const { return m_BundleInfo ? m_BundleInfo->vecItemDefs[iIndex]->GetDefinitionIndex() : -1; }
  1139. // Is this item contained in any bundles? GetContainingBundles() gets the CEconItemDefinitions for those bundles.
  1140. const CUtlVector< const CEconItemDefinition * > &GetContainingBundles() const { return m_vecContainingBundleItemDefs; }
  1141. uint32 GetContainingBundleCount() const { return m_vecContainingBundleItemDefs.Count(); }
  1142. void AddSteamWorkshopContributor( uint32 unAccountID ) { if ( m_vecSteamWorkshopContributors.InvalidIndex() == m_vecSteamWorkshopContributors.Find( unAccountID ) ) { m_vecSteamWorkshopContributors.AddToTail( unAccountID ); } }
  1143. const CUtlVector< uint32 > &GetSteamWorkshopContributors() const { return m_vecSteamWorkshopContributors; }
  1144. bool BIsSteamWorkshopItem() const { return m_vecSteamWorkshopContributors.Count() > 0; }
  1145. const char *GetIconClassname( void ) const { return m_pszItemIconClassname; }
  1146. const char *GetLogClassname( void ) const { return m_pszItemLogClassname; }
  1147. const char *GetInventoryModel( void ) const { return m_pszInventoryModel; }
  1148. const char *GetInventoryImage( void ) const { return m_pszInventoryImage; }
  1149. const char *GetInventoryOverlayImage( int idx ) const { if ( m_pszInventoryOverlayImages.IsValidIndex( idx ) ) return m_pszInventoryOverlayImages[idx]; else return NULL; }
  1150. int GetInventoryOverlayImageCount( void ) const { return m_pszInventoryOverlayImages.Count(); }
  1151. int GetInspectPanelDistance( void ) const { return m_iInspectPanelDistance; }
  1152. const char *GetIconURLSmall() const { return GetIconURL( "s" ); } // Plain small
  1153. const char *GetIconURLLarge() const { return GetIconURL( "l" ); } // Plain large
  1154. void SetIconURL( const char* pszKey, const char *szURL ) { m_pDictIcons->Insert( pszKey, CUtlString( szURL ) ); }
  1155. const char *GetIconURL( const char* pszKey ) const;
  1156. const char *GetBasePlayerDisplayModel() const { return m_pszBaseDisplayModel; }
  1157. int GetDefaultSkin() const { return m_iDefaultSkin; }
  1158. const char *GetWorldDisplayModel() const { return m_pszWorldDisplayModel; }
  1159. const char *GetCollectionReference() const { return m_pszCollectionReference; }
  1160. // Some weapons need a custom model for icon generation. If this value is not present, the world model is used.
  1161. virtual const char *GetIconDisplayModel() const;
  1162. const char *GetExtraWearableModel( void ) const { return m_pszWorldExtraWearableModel; }
  1163. const char *GetExtraWearableViewModel( void ) const { return m_pszWorldExtraWearableViewModel; }
  1164. const char *GetVisionFilteredDisplayModel() const { return m_pszVisionFilteredDisplayModel; }
  1165. const char *GetItemDesc( void ) const { return m_pszItemDesc; }
  1166. const char *GetArmoryDescString( void ) const { return m_pszArmoryDesc; }
  1167. RTime32 GetExpirationDate( void ) const { return m_rtExpiration; }
  1168. bool ShouldShowInArmory( void ) const { return m_bShouldShowInArmory; }
  1169. bool IsActingAsAWearable( void ) const { return m_bActAsWearable; }
  1170. bool IsActingAsAWeapon( void ) const { return m_bActAsWeapon; }
  1171. bool GetHideBodyGroupsDeployedOnly( void ) const { return m_bHideBodyGroupsDeployedOnly; }
  1172. bool IsPackBundle( void ) const { return m_bIsPackBundle; }
  1173. bool IsPackItem( void ) const { return m_bIsPackItem; }
  1174. CEconItemDefinition *GetOwningPackBundle() { return m_pOwningPackBundle; }
  1175. const CEconItemDefinition *GetOwningPackBundle() const { return m_pOwningPackBundle; }
  1176. const char *GetDatabaseAuditTableName( void ) const { return m_pszDatabaseAuditTable; }
  1177. void SetIsPackItem( bool bIsPackItem ) { m_bIsPackItem = bIsPackItem; }
  1178. equip_region_mask_t GetEquipRegionMask( void ) const { return m_unEquipRegionMask; }
  1179. equip_region_mask_t GetEquipRegionConflictMask( void ) const { return m_unEquipRegionConflictMask; }
  1180. // Dynamic modification during gameplay
  1181. void SetAllowedInMatch( bool bAllowed ) { m_bAllowedInThisMatch = bAllowed; }
  1182. void SetHasBeenLoaded( bool bLoaded ) { m_bHasBeenLoaded = bLoaded; }
  1183. // Generate and return a random level according to whatever leveling curve this definition uses.
  1184. uint32 RollItemLevel( void ) const;
  1185. const char *GetFirstSaleDate( void ) const;
  1186. void IterateAttributes( class IEconItemAttributeIterator *pIterator ) const;
  1187. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  1188. // Visuals
  1189. // Attached models
  1190. int GetNumAttachedModels( int iTeam ) const;
  1191. attachedmodel_t *GetAttachedModelData( int iTeam, int iIdx ) const;
  1192. int GetNumAttachedModelsFestivized( int iTeam ) const;
  1193. attachedmodel_t *GetAttachedModelDataFestivized( int iTeam, int iIdx ) const;
  1194. // Attached particle systems
  1195. int GetNumAttachedParticles( int iTeam ) const;
  1196. attachedparticlesystem_t *GetAttachedParticleData( int iTeam, int iIdx ) const;
  1197. // Activities
  1198. int GetNumPlaybackActivities( int iTeam ) const;
  1199. activity_on_wearable_t *GetPlaybackActivityData( int iTeam, int iIdx ) const;
  1200. // Animations
  1201. int GetNumAnimations( int iTeam ) const;
  1202. animation_on_wearable_t *GetAnimationData( int iTeam, int iIdx ) const;
  1203. // Animation Overrides
  1204. Activity GetActivityOverride( int iTeam, Activity baseAct ) const;
  1205. const char *GetActivityOverride( int iTeam, const char *pszActivity ) const;
  1206. const char *GetReplacementForActivityOverride( int iTeam, Activity baseAct ) const;
  1207. // Should the content (meshes, etc.) for this be streamed or preloaded?
  1208. virtual bool IsContentStreamable() const;
  1209. #endif // defined(CLIENT_DLL) || defined(GAME_DLL)
  1210. // FX Overrides
  1211. const char *GetMuzzleFlash( int iTeam ) const;
  1212. const char *GetTracerEffect( int iTeam ) const;
  1213. const char *GetParticleEffect( int iTeam ) const;
  1214. // Materials
  1215. const char *GetMaterialOverride( int iTeam ) const;
  1216. // Sounds
  1217. const char *GetCustomSound( int iTeam, int iSound ) const;
  1218. const char *GetWeaponReplacementSound( int iTeam, /*WeaponSound_t*/ int iSound ) const;
  1219. // Bodygroups
  1220. int GetHiddenParentBodygroup( int iTeam ) const;
  1221. int GetNumModifiedBodyGroups( int iTeam ) const;
  1222. const char* GetModifiedBodyGroup( int iTeam, int i, int& body ) const;
  1223. bool UsesPerClassBodygroups( int iTeam ) const;
  1224. int GetNumCodeControlledBodyGroups( int iTeam ) const;
  1225. const char* GetCodeControlledBodyGroup( int iIteam, int i, struct codecontrolledbodygroupdata_t &ccbgd ) const;
  1226. style_index_t GetNumStyles() const;
  1227. style_index_t GetNumSelectableStyles() const;
  1228. const CEconStyleInfo *GetStyleInfo( style_index_t unStyle ) const;
  1229. int GetViewmodelBodygroupOverride( int iTeam ) const;
  1230. int GetViewmodelBodygroupStateOverride( int iTeam ) const;
  1231. int GetWorldmodelBodygroupOverride( int iTeam ) const;
  1232. int GetWorldmodelBodygroupStateOverride( int iTeam ) const;
  1233. int GetPopularitySeed() const { return m_nPopularitySeed; }
  1234. bool HasEconTag( econ_tag_handle_t tag ) const { return m_vecTags.IsValidIndex( m_vecTags.Find( tag ) ); }
  1235. bool BValidForShuffle( void ) const { return m_bValidForShuffle; }
  1236. bool BValidForSelfMade( void ) const { return m_bValidForSelfMade; }
  1237. #ifdef GC_DLL
  1238. private:
  1239. MUST_CHECK_RETURN bool BInitializeEconItemGenerators( KeyValues *pKV, CUtlVector<CUtlString> *pVecErrors );
  1240. public:
  1241. // If this returns true, all relevant property generators were applied to the item instance
  1242. // passed in. If this returns false, some or none of the generators may have been applied,
  1243. // but there are no guarantees about the item state.
  1244. MUST_CHECK_RETURN bool BApplyPropertyGenerators( CEconItem *pItem ) const;
  1245. const CUtlVector<econ_tag_handle_t>& GetEconTags() const { return m_vecTags; } // meant for internal/debug use only, not for runtime iteration
  1246. const CUtlVector<econ_item_payment_rule_t>& GetPaymentRules() const { return m_vecPaymentRules; }
  1247. private:
  1248. int AddPaymentRule( const econ_item_payment_rule_t& newRule ); // returns which payment rule number was just created
  1249. public:
  1250. #endif // GC_DLL
  1251. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  1252. int GetStyleSkin( style_index_t unStyle, int iTeam, bool bViewmodel ) const;
  1253. const char* GetStyleInventoryImage( style_index_t unStyle ) const;
  1254. int GetBestVisualTeamData( int iTeam ) const;
  1255. #endif // defined(CLIENT_DLL) || defined(GAME_DLL)
  1256. #ifdef DBGFLAG_VALIDATE
  1257. void Validate( CValidator &validator, const char *pchName )
  1258. {
  1259. VALIDATE_SCOPE();
  1260. ValidateObj( m_vecStaticAttributes );
  1261. ValidatePtr( m_pKVItem );
  1262. ValidatePtr( m_pProxyCriteria );
  1263. }
  1264. #endif // DBGFLAG_VALIDATE
  1265. private:
  1266. // Pointer to the raw KeyValue definition of the item
  1267. KeyValues * m_pKVItem;
  1268. // Required values from m_pKVItem:
  1269. // The number used to refer to this definition in the DB
  1270. item_definition_index_t m_nDefIndex;
  1271. // False if this definition has been turned off and we're not using it to generate items
  1272. bool m_bEnabled;
  1273. // These values specify the range of item levels that an item based off this definition can be generated within.
  1274. uint8 m_unMinItemLevel;
  1275. uint8 m_unMaxItemLevel;
  1276. // This specifies an item quality that items from this definition must be set to. Used mostly to specify unique item definitions.
  1277. uint8 m_nItemQuality;
  1278. uint8 m_nForcedItemQuality;
  1279. uint8 m_nItemRarity;
  1280. // Default drop quantity
  1281. uint16 m_nDefaultDropQuantity;
  1282. // Item Series
  1283. uint8 m_unItemSeries;
  1284. // Static attributes (ones that are always on these items)
  1285. CUtlVector<static_attrib_t> m_vecStaticAttributes;
  1286. // Seeds the popular item list with this number of the item when the list is reset.
  1287. uint8 m_nPopularitySeed;
  1288. // ---------------------------------------------
  1289. // Display related data
  1290. // ---------------------------------------------
  1291. // The base name of this item. i.e. "The Kritz-Krieg".
  1292. const char *m_pszItemBaseName;
  1293. bool m_bProperName; // If set, the name will have "The" prepended to it, unless it's got a non-unique quality
  1294. // in which case it'll have "A" prepended to the quality. i.e. A Community Kritzkrieg
  1295. // The base type of this item. i.e. "Rocket Launcher" or "Shotgun".
  1296. // This is often the same as the base name, but not always.
  1297. const char *m_pszItemTypeName;
  1298. // The item's non-attribute description.
  1299. const char *m_pszItemDesc;
  1300. // expiration time
  1301. RTime32 m_rtExpiration;
  1302. // The .mdl file used for this item when it's displayed in inventory-style boxes.
  1303. const char *m_pszInventoryModel;
  1304. // Alternatively, the image used for this item when it's displayed in inventory-style boxes. If specified, it's used over the model.
  1305. const char *m_pszInventoryImage;
  1306. // An optional image that's overlayed over the top of the base inventory image. It'll be RGB colored by the tint color of the item.
  1307. CUtlVector<const char*> m_pszInventoryOverlayImages;
  1308. int m_iInventoryImagePosition[2];
  1309. int m_iInventoryImageSize[2];
  1310. int m_iInspectPanelDistance;
  1311. const char *m_pszBaseDisplayModel;
  1312. int m_iDefaultSkin;
  1313. bool m_bLoadOnDemand;
  1314. bool m_bHasBeenLoaded;
  1315. bool m_bHideBodyGroupsDeployedOnly;
  1316. // The .mdl file used for the world view.
  1317. // This is inferior to using a c_model, but because the geometry of the sticky bomb launcher's
  1318. // world model is significantly different from the view model the demoman pack requires
  1319. // using two separate models for now.
  1320. const char *m_pszWorldDisplayModel;
  1321. const char *m_pszWorldExtraWearableModel; // Some weapons attach an extra wearable item to the player
  1322. const char *m_pszWorldExtraWearableViewModel; // Some weapons attach an extra wearable view model item to the player
  1323. const char *m_pszVisionFilteredDisplayModel; // Some weapons display differently depending on the viewer's filters
  1324. const char *m_pszCollectionReference; // Reference a colletion
  1325. // If set, we use the base hands model for a viewmodel, and bonemerge the above player model
  1326. bool m_bAttachToHands;
  1327. bool m_bAttachToHandsVMOnly;
  1328. // If set, we will force the view model to render flipped. Good for models built left handed.
  1329. bool m_bFlipViewModel;
  1330. // This is a wearable that sits in a non-wearable loadout slot
  1331. bool m_bActAsWearable;
  1332. // This is a weapon that sits in a wearable slot (Action)
  1333. bool m_bActAsWeapon;
  1334. // Is this Item a tool
  1335. bool m_bIsTool;
  1336. // The set this item is a member of
  1337. const CEconItemSetDefinition *m_pItemSetDef;
  1338. const CEconItemCollectionDefinition *m_pItemCollectionDef;
  1339. CEconItemPaintKitDefinition *m_pItemPaintKitDef;
  1340. // A list of per-team visual data used to modify base model for visual recognition
  1341. perteamvisuals_t *m_PerTeamVisuals[TEAM_VISUAL_SECTIONS];
  1342. // Optional override for specifying a custom shell ejection model
  1343. const char *m_pszBrassModelOverride;
  1344. IEconTool *m_pTool;
  1345. bundleinfo_t *m_BundleInfo;
  1346. item_capabilities_t m_iCapabilities;
  1347. #ifdef TF_CLIENT_DLL
  1348. uint32 m_unNumConcreteItems; // This is the number of items that will actually end up in a user's inventory - this can be 0 for some items (e.g. map stamps in TF), 1 for a "regular" item, or many for bundles, etc.
  1349. #endif // TF_CLIENT_DLL
  1350. CUtlDict< CUtlString >* m_pDictIcons;
  1351. // ---------------------------------------------
  1352. // Creation related data
  1353. // ---------------------------------------------
  1354. // The entity classname for this item.
  1355. const char *m_pszItemClassname;
  1356. // The entity name that will be displayed in log files.
  1357. const char *m_pszItemLogClassname;
  1358. // The name of the icon used in the death notices.
  1359. const char *m_pszItemIconClassname;
  1360. // This is the script file name of this definition. Used to generate items by script name.
  1361. const char *m_pszDefinitionName;
  1362. // This is used for auditing purposes
  1363. const char *m_pszDatabaseAuditTable;
  1364. bool m_bHidden;
  1365. bool m_bShouldShowInArmory;
  1366. bool m_bBaseItem;
  1367. bool m_bImported;
  1368. // A pack bundle is a bundle that contains items that are not for sale individually
  1369. bool m_bIsPackBundle;
  1370. // A pack item is an item which is not for sale individually and is only for sale as part of a pack bundle. A 'regular' bundle can only include a pack bundle by explicitly including all of the pack bundle's items individually.
  1371. // If this pointer is non-NULL, this item is considered to be a pack item (see CEconItemDefinition::IsPackItem()).
  1372. CEconItemDefinition *m_pOwningPackBundle;
  1373. bool m_bIsPackItem;
  1374. // Contains information on how to describe items with this attribute in the Armory
  1375. const char *m_pszArmoryDesc;
  1376. // Temporary(?) solution to allow xifiers to work on botkiller and festive variants of weapons
  1377. const char *m_pszXifierRemapClass;
  1378. // Base item name -- used for grouping weapon functionality
  1379. const char *m_pszBaseFunctionalItemName;
  1380. // For particle effects that have derivatives, what is the suffix for this item
  1381. const char *m_pszParticleSuffix;
  1382. // ---------------------------------------------
  1383. // Remapping data for armory/store
  1384. // ---------------------------------------------
  1385. int m_iArmoryRemap;
  1386. int m_iStoreRemap;
  1387. const char *m_pszArmoryRemap;
  1388. const char *m_pszStoreRemap;
  1389. // ---------------------------------------------
  1390. // Crafting related data
  1391. // ---------------------------------------------
  1392. const char *m_pszClassToken;
  1393. const char *m_pszSlotToken;
  1394. // ---------------------------------------------
  1395. // Gameplay related data
  1396. // ---------------------------------------------
  1397. // How to behave when the player wearing the item dies.
  1398. int m_iDropType;
  1399. // Holiday restriction. Item only has an appearance when the holiday is in effect.
  1400. const char *m_pszHolidayRestriction;
  1401. // Meet the pyro makes some items invisible unless you're wearing Pyro Goggles
  1402. int m_nVisionFilterFlags;
  1403. // Temporary. Revisit this in the engineer update. Enables an additional buildable.
  1404. int m_iSubType;
  1405. // Whitelist support for tournament mode
  1406. bool m_bAllowedInThisMatch;
  1407. equip_region_mask_t m_unEquipRegionMask; // which equip regions does this item cover directly
  1408. equip_region_mask_t m_unEquipRegionConflictMask; // which equip regions does equipping this item prevent from having something in them
  1409. item_definition_index_t m_unSetItemRemapDefIndex; // reference to the definition index we want to consider this item for set matching purposes; see GetSetItemRemap()
  1410. #ifdef GC_DLL
  1411. CUtlVector<const IEconItemPropertyGenerator *> m_vecPropertyGenerators;
  1412. CUtlVector<econ_item_payment_rule_t> m_vecPaymentRules;
  1413. #endif // GC_DLL
  1414. // False if this definition is not allowed to be part of a shuffled crate's contents
  1415. bool m_bValidForShuffle;
  1416. // False if this definition should not grant self-made items
  1417. bool m_bValidForSelfMade;
  1418. protected:
  1419. // Protected to allow subclasses to add/remove game-specific tags.
  1420. CUtlVector<econ_tag_handle_t> m_vecTags;
  1421. CUtlVector<const CEconItemDefinition *> m_vecContainingBundleItemDefs; // Item definition indices for any bundles which contain this item
  1422. CUtlVector<uint32> m_vecSteamWorkshopContributors;
  1423. friend class CEconItemSchema;
  1424. };
  1425. //-----------------------------------------------------------------------------
  1426. // Purpose:
  1427. //-----------------------------------------------------------------------------
  1428. inline style_index_t CEconItemDefinition::GetNumStyles() const
  1429. {
  1430. const perteamvisuals_t *pVisData = GetPerTeamVisual( 0 );
  1431. if ( !pVisData )
  1432. return 0;
  1433. // Bad things will happen if we ever get more styles than will fit in our
  1434. // style index type. Not Very Bad things, but bad things. Mostly we'll fail
  1435. // to iterate over all our styles.
  1436. return pVisData->m_Styles.Count();
  1437. }
  1438. //-----------------------------------------------------------------------------
  1439. // Purpose: Similar to GetNumStyles, but only the selectable styles
  1440. //-----------------------------------------------------------------------------
  1441. inline style_index_t CEconItemDefinition::GetNumSelectableStyles() const
  1442. {
  1443. const perteamvisuals_t *pVisData = GetPerTeamVisual(0);
  1444. if (!pVisData)
  1445. return 0;
  1446. style_index_t nCount = 0;
  1447. FOR_EACH_VEC( pVisData->m_Styles, i )
  1448. {
  1449. if( pVisData->m_Styles[i]->IsSelectable() )
  1450. {
  1451. ++nCount;
  1452. }
  1453. }
  1454. return nCount;
  1455. }
  1456. //-----------------------------------------------------------------------------
  1457. // Purpose:
  1458. //-----------------------------------------------------------------------------
  1459. inline const CEconStyleInfo *CEconItemDefinition::GetStyleInfo( style_index_t unStyle ) const
  1460. {
  1461. const perteamvisuals_t *pBaseVisuals = GetPerTeamVisual( 0 );
  1462. if ( !pBaseVisuals || !pBaseVisuals->m_Styles.IsValidIndex( unStyle ) )
  1463. return NULL;
  1464. return pBaseVisuals->m_Styles[unStyle];
  1465. }
  1466. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  1467. //-----------------------------------------------------------------------------
  1468. // Purpose:
  1469. //-----------------------------------------------------------------------------
  1470. inline int CEconItemDefinition::GetNumAttachedModels( int iTeam ) const
  1471. {
  1472. #ifndef CSTRIKE_DLL
  1473. iTeam = GetBestVisualTeamData( iTeam );
  1474. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1475. return 0;
  1476. return GetPerTeamVisual(iTeam)->m_AttachedModels.Count();
  1477. #else
  1478. return 0;
  1479. #endif
  1480. }
  1481. //-----------------------------------------------------------------------------
  1482. inline attachedmodel_t *CEconItemDefinition::GetAttachedModelData( int iTeam, int iIdx ) const
  1483. {
  1484. #ifndef CSTRIKE_DLL
  1485. iTeam = GetBestVisualTeamData( iTeam );
  1486. perteamvisuals_t *pVisuals = GetPerTeamVisual(iTeam);
  1487. Assert( pVisuals );
  1488. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !pVisuals )
  1489. return NULL;
  1490. Assert( iIdx < pVisuals->m_AttachedModels.Count() );
  1491. if ( iIdx >= pVisuals->m_AttachedModels.Count() )
  1492. return NULL;
  1493. return &pVisuals->m_AttachedModels[iIdx];
  1494. #else
  1495. return NULL;
  1496. #endif
  1497. }
  1498. //-----------------------------------------------------------------------------
  1499. inline int CEconItemDefinition::GetNumAttachedModelsFestivized( int iTeam ) const
  1500. {
  1501. #ifndef CSTRIKE_DLL
  1502. iTeam = GetBestVisualTeamData( iTeam );
  1503. perteamvisuals_t *pVisuals = GetPerTeamVisual(iTeam);
  1504. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !pVisuals )
  1505. return 0;
  1506. return pVisuals->m_AttachedModelsFestive.Count();
  1507. #else
  1508. return 0;
  1509. #endif
  1510. }
  1511. //-----------------------------------------------------------------------------
  1512. inline attachedmodel_t *CEconItemDefinition::GetAttachedModelDataFestivized( int iTeam, int iIdx ) const
  1513. {
  1514. #ifndef CSTRIKE_DLL
  1515. iTeam = GetBestVisualTeamData( iTeam );
  1516. perteamvisuals_t *pVisuals = GetPerTeamVisual(iTeam);
  1517. Assert( pVisuals );
  1518. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !pVisuals )
  1519. return NULL;
  1520. Assert( iIdx < pVisuals->m_AttachedModelsFestive.Count() );
  1521. if ( iIdx >= pVisuals->m_AttachedModelsFestive.Count() )
  1522. return NULL;
  1523. return &pVisuals->m_AttachedModelsFestive[iIdx];
  1524. #else
  1525. return NULL;
  1526. #endif
  1527. }
  1528. //-----------------------------------------------------------------------------
  1529. inline int CEconItemDefinition::GetNumPlaybackActivities( int iTeam ) const
  1530. {
  1531. #ifndef CSTRIKE_DLL
  1532. iTeam = GetBestVisualTeamData( iTeam );
  1533. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1534. return 0;
  1535. return GetPerTeamVisual(iTeam)->m_Activities.Count();
  1536. #else
  1537. return 0;
  1538. #endif
  1539. }
  1540. inline activity_on_wearable_t *CEconItemDefinition::GetPlaybackActivityData( int iTeam, int iIdx ) const
  1541. {
  1542. #ifndef CSTRIKE_DLL
  1543. iTeam = GetBestVisualTeamData( iTeam );
  1544. Assert( GetPerTeamVisual(iTeam) );
  1545. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1546. return NULL;
  1547. Assert( iIdx < GetPerTeamVisual(iTeam)->m_Activities.Count() );
  1548. if ( iIdx >= GetPerTeamVisual(iTeam)->m_Activities.Count() )
  1549. return NULL;
  1550. return &GetPerTeamVisual(iTeam)->m_Activities[iIdx];
  1551. #else
  1552. return NULL;
  1553. #endif
  1554. }
  1555. //-----------------------------------------------------------------------------
  1556. // Purpose:
  1557. //-----------------------------------------------------------------------------
  1558. inline int CEconItemDefinition::GetNumAnimations( int iTeam ) const
  1559. {
  1560. #ifndef CSTRIKE_DLL
  1561. iTeam = GetBestVisualTeamData( iTeam );
  1562. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1563. return 0;
  1564. return GetPerTeamVisual(iTeam)->m_Animations.Count();
  1565. #else
  1566. return 0;
  1567. #endif
  1568. }
  1569. inline animation_on_wearable_t *CEconItemDefinition::GetAnimationData( int iTeam, int iIdx ) const
  1570. {
  1571. #ifndef CSTRIKE_DLL
  1572. iTeam = GetBestVisualTeamData( iTeam );
  1573. Assert( GetPerTeamVisual(iTeam) );
  1574. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1575. return NULL;
  1576. Assert( iIdx < GetPerTeamVisual(iTeam)->m_Animations.Count() );
  1577. if ( iIdx >= GetPerTeamVisual(iTeam)->m_Animations.Count() )
  1578. return NULL;
  1579. return &GetPerTeamVisual(iTeam)->m_Animations[iIdx];
  1580. #else
  1581. return NULL;
  1582. #endif
  1583. }
  1584. //-----------------------------------------------------------------------------
  1585. // Purpose:
  1586. //-----------------------------------------------------------------------------
  1587. inline int CEconItemDefinition::GetNumAttachedParticles( int iTeam ) const
  1588. {
  1589. #ifndef CSTRIKE_DLL
  1590. iTeam = GetBestVisualTeamData( iTeam );
  1591. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1592. return 0;
  1593. return GetPerTeamVisual(iTeam)->m_AttachedParticles.Count();
  1594. #else
  1595. return 0;
  1596. #endif
  1597. }
  1598. //-----------------------------------------------------------------------------
  1599. // Purpose:
  1600. //-----------------------------------------------------------------------------
  1601. inline attachedparticlesystem_t *CEconItemDefinition::GetAttachedParticleData( int iTeam, int iIdx ) const
  1602. {
  1603. #ifndef CSTRIKE_DLL
  1604. iTeam = GetBestVisualTeamData( iTeam );
  1605. Assert( GetPerTeamVisual(iTeam) );
  1606. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1607. return NULL;
  1608. Assert( iIdx < GetPerTeamVisual(iTeam)->m_AttachedParticles.Count() );
  1609. if ( iIdx >= GetPerTeamVisual(iTeam)->m_AttachedParticles.Count() )
  1610. return NULL;
  1611. return &GetPerTeamVisual(iTeam)->m_AttachedParticles[iIdx];
  1612. #else
  1613. return NULL;
  1614. #endif
  1615. }
  1616. //-----------------------------------------------------------------------------
  1617. // Purpose:
  1618. //-----------------------------------------------------------------------------
  1619. inline const char *CEconItemDefinition::GetMaterialOverride( int iTeam ) const
  1620. {
  1621. #ifndef CSTRIKE_DLL
  1622. iTeam = GetBestVisualTeamData( iTeam );
  1623. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1624. return NULL;
  1625. return GetPerTeamVisual(iTeam)->pszMaterialOverride;
  1626. #else
  1627. return NULL;
  1628. #endif
  1629. }
  1630. //-----------------------------------------------------------------------------
  1631. // Purpose:
  1632. //-----------------------------------------------------------------------------
  1633. inline const char *CEconItemDefinition::GetMuzzleFlash( int iTeam ) const
  1634. {
  1635. #ifndef CSTRIKE_DLL
  1636. iTeam = GetBestVisualTeamData( iTeam );
  1637. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1638. return NULL;
  1639. return GetPerTeamVisual(iTeam)->pszMuzzleFlash;
  1640. #else
  1641. return NULL;
  1642. #endif
  1643. }
  1644. //-----------------------------------------------------------------------------
  1645. // Purpose:
  1646. //-----------------------------------------------------------------------------
  1647. inline const char *CEconItemDefinition::GetTracerEffect( int iTeam ) const
  1648. {
  1649. #ifndef CSTRIKE_DLL
  1650. iTeam = GetBestVisualTeamData( iTeam );
  1651. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1652. return NULL;
  1653. return GetPerTeamVisual(iTeam)->pszTracerEffect;
  1654. #else
  1655. return NULL;
  1656. #endif
  1657. }
  1658. //-----------------------------------------------------------------------------
  1659. // Purpose:
  1660. //-----------------------------------------------------------------------------
  1661. inline const char *CEconItemDefinition::GetParticleEffect( int iTeam ) const
  1662. {
  1663. #ifndef CSTRIKE_DLL
  1664. iTeam = GetBestVisualTeamData( iTeam );
  1665. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1666. return NULL;
  1667. return GetPerTeamVisual(iTeam)->pszParticleEffect;
  1668. #else
  1669. return NULL;
  1670. #endif
  1671. }
  1672. //-----------------------------------------------------------------------------
  1673. // Purpose:
  1674. //-----------------------------------------------------------------------------
  1675. inline int CEconItemDefinition::GetHiddenParentBodygroup( int iTeam ) const
  1676. {
  1677. #ifndef CSTRIKE_DLL
  1678. iTeam = GetBestVisualTeamData( iTeam );
  1679. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1680. return -1;
  1681. return GetPerTeamVisual(iTeam)->iHideParentBodyGroup;
  1682. #else
  1683. return -1;
  1684. #endif
  1685. }
  1686. //-----------------------------------------------------------------------------
  1687. // Purpose:
  1688. //-----------------------------------------------------------------------------
  1689. inline int CEconItemDefinition::GetNumModifiedBodyGroups( int iTeam ) const
  1690. {
  1691. #ifndef CSTRIKE_DLL
  1692. iTeam = GetBestVisualTeamData( iTeam );
  1693. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1694. return -1;
  1695. return GetPerTeamVisual(iTeam)->m_Maps.m_ModifiedBodyGroupNames.Count();
  1696. #else
  1697. return -1;
  1698. #endif
  1699. }
  1700. //-----------------------------------------------------------------------------
  1701. // Purpose:
  1702. //-----------------------------------------------------------------------------
  1703. inline const char* CEconItemDefinition::GetModifiedBodyGroup( int iTeam, int i, int& body ) const
  1704. {
  1705. #ifndef CSTRIKE_DLL
  1706. iTeam = GetBestVisualTeamData( iTeam );
  1707. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1708. return NULL;
  1709. body = GetPerTeamVisual(iTeam)->m_Maps.m_ModifiedBodyGroupNames[i];
  1710. return GetPerTeamVisual(iTeam)->m_Maps.m_ModifiedBodyGroupNames.Key(i);
  1711. #else
  1712. return NULL;
  1713. #endif
  1714. }
  1715. //-----------------------------------------------------------------------------
  1716. // Purpose:
  1717. //-----------------------------------------------------------------------------
  1718. inline int CEconItemDefinition::GetNumCodeControlledBodyGroups( int iTeam ) const
  1719. {
  1720. #ifndef CSTRIKE_DLL
  1721. iTeam = GetBestVisualTeamData( iTeam );
  1722. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1723. return -1;
  1724. return GetPerTeamVisual(iTeam)->m_Maps.m_CodeControlledBodyGroupNames.Count();
  1725. #else
  1726. return -1;
  1727. #endif
  1728. }
  1729. //-----------------------------------------------------------------------------
  1730. // Purpose:
  1731. //-----------------------------------------------------------------------------
  1732. inline const char* CEconItemDefinition::GetCodeControlledBodyGroup( int iTeam, int i, codecontrolledbodygroupdata_t &ccbgd ) const
  1733. {
  1734. #ifndef CSTRIKE_DLL
  1735. iTeam = GetBestVisualTeamData( iTeam );
  1736. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1737. return NULL;
  1738. ccbgd = GetPerTeamVisual(iTeam)->m_Maps.m_CodeControlledBodyGroupNames[i];
  1739. return GetPerTeamVisual(iTeam)->m_Maps.m_CodeControlledBodyGroupNames.Key(i);
  1740. #else
  1741. return NULL;
  1742. #endif
  1743. }
  1744. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  1745. //-----------------------------------------------------------------------------
  1746. // Purpose:
  1747. //-----------------------------------------------------------------------------
  1748. inline int CEconItemDefinition::GetStyleSkin( style_index_t unStyle, int iTeam, bool bViewmodel ) const
  1749. {
  1750. const CEconStyleInfo *pStyle = GetStyleInfo( unStyle );
  1751. // Return our skin if we have a style or our default skin of -1 otherwise.
  1752. return pStyle
  1753. ? pStyle->GetSkin( iTeam, bViewmodel )
  1754. : GetDefaultSkin();
  1755. }
  1756. //-----------------------------------------------------------------------------
  1757. // Purpose:
  1758. //-----------------------------------------------------------------------------
  1759. inline const char* CEconItemDefinition::GetStyleInventoryImage( style_index_t unStyle ) const
  1760. {
  1761. const CEconStyleInfo *pStyle = GetStyleInfo( unStyle );
  1762. return pStyle ? pStyle->GetInventoryImage() : NULL;
  1763. }
  1764. #endif // defined(CLIENT_DLL) || defined(GAME_DLL)
  1765. //-----------------------------------------------------------------------------
  1766. // Purpose:
  1767. //-----------------------------------------------------------------------------
  1768. inline int CEconItemDefinition::GetViewmodelBodygroupOverride( int iTeam ) const
  1769. {
  1770. #ifndef CSTRIKE_DLL
  1771. iTeam = GetBestVisualTeamData( iTeam );
  1772. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1773. return 0;
  1774. return GetPerTeamVisual(iTeam)->m_iViewModelBodyGroupOverride;
  1775. #else
  1776. return 0;
  1777. #endif
  1778. }
  1779. //-----------------------------------------------------------------------------
  1780. // Purpose:
  1781. //-----------------------------------------------------------------------------
  1782. inline int CEconItemDefinition::GetViewmodelBodygroupStateOverride( int iTeam ) const
  1783. {
  1784. #ifndef CSTRIKE_DLL
  1785. iTeam = GetBestVisualTeamData( iTeam );
  1786. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1787. return 0;
  1788. return GetPerTeamVisual(iTeam)->m_iViewModelBodyGroupStateOverride;
  1789. #else
  1790. return 0;
  1791. #endif
  1792. }
  1793. //-----------------------------------------------------------------------------
  1794. // Purpose:
  1795. //-----------------------------------------------------------------------------
  1796. inline int CEconItemDefinition::GetWorldmodelBodygroupOverride( int iTeam ) const
  1797. {
  1798. #ifndef CSTRIKE_DLL
  1799. iTeam = GetBestVisualTeamData( iTeam );
  1800. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1801. return 0;
  1802. return GetPerTeamVisual(iTeam)->m_iWorldModelBodyGroupOverride;
  1803. #else
  1804. return 0;
  1805. #endif
  1806. }
  1807. //-----------------------------------------------------------------------------
  1808. // Purpose:
  1809. //-----------------------------------------------------------------------------
  1810. inline int CEconItemDefinition::GetWorldmodelBodygroupStateOverride( int iTeam ) const
  1811. {
  1812. #ifndef CSTRIKE_DLL
  1813. iTeam = GetBestVisualTeamData( iTeam );
  1814. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1815. return 0;
  1816. return GetPerTeamVisual(iTeam)->m_iWorldModelBodyGroupStateOverride;
  1817. #else
  1818. return 0;
  1819. #endif
  1820. }
  1821. //-----------------------------------------------------------------------------
  1822. // Purpose:
  1823. //-----------------------------------------------------------------------------
  1824. inline bool CEconItemDefinition::UsesPerClassBodygroups( int iTeam ) const
  1825. {
  1826. #ifndef CSTRIKE_DLL
  1827. iTeam = GetBestVisualTeamData( iTeam );
  1828. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1829. return false;
  1830. return GetPerTeamVisual(iTeam)->bUsePerClassBodygroups;
  1831. #else
  1832. return false;
  1833. #endif
  1834. }
  1835. //-----------------------------------------------------------------------------
  1836. // Purpose:
  1837. //-----------------------------------------------------------------------------
  1838. inline const char *CEconItemDefinition::GetCustomSound( int iTeam, int iSound ) const
  1839. {
  1840. #ifndef CSTRIKE_DLL
  1841. iTeam = GetBestVisualTeamData( iTeam );
  1842. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1843. return NULL;
  1844. if ( iSound < 0 || iSound >= MAX_VISUALS_CUSTOM_SOUNDS )
  1845. return NULL;
  1846. return GetPerTeamVisual(iTeam)->pszCustomSounds[iSound];
  1847. #else
  1848. return NULL;
  1849. #endif
  1850. }
  1851. //-----------------------------------------------------------------------------
  1852. // Purpose:
  1853. //-----------------------------------------------------------------------------
  1854. inline const char *CEconItemDefinition::GetWeaponReplacementSound( int iTeam, /* WeaponSound_t */ int iSound ) const
  1855. {
  1856. #ifndef CSTRIKE_DLL
  1857. iTeam = GetBestVisualTeamData( iTeam );
  1858. if ( iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS || !GetPerTeamVisual(iTeam) )
  1859. return NULL;
  1860. if ( iSound < 0 || iSound >= NUM_SHOOT_SOUND_TYPES )
  1861. return NULL;
  1862. return GetPerTeamVisual(iTeam)->pszWeaponSoundReplacements[iSound];
  1863. #else
  1864. return NULL;
  1865. #endif
  1866. }
  1867. //-----------------------------------------------------------------------------
  1868. // Purpose:
  1869. //-----------------------------------------------------------------------------
  1870. inline int CEconItemDefinition::GetBestVisualTeamData( int iTeam ) const
  1871. {
  1872. #ifndef CSTRIKE_DLL
  1873. Assert( iTeam >= 0 && iTeam < TEAM_VISUAL_SECTIONS );
  1874. // If we don't have data for the specified team, try to fall back to the base
  1875. // if ( !GetStaticData() )
  1876. // return 0;
  1877. if ( (iTeam < 0 || iTeam >= TEAM_VISUAL_SECTIONS) || (iTeam > 0 && !GetPerTeamVisual(iTeam)) )
  1878. return 0;
  1879. return iTeam;
  1880. #else
  1881. return 0;
  1882. #endif
  1883. }
  1884. #endif // defined(CLIENT_DLL) || defined(GAME_DLL)
  1885. //-----------------------------------------------------------------------------
  1886. // CTimedItemRewardDefinition
  1887. // Describes a periodic item reward
  1888. //-----------------------------------------------------------------------------
  1889. class CTimedItemRewardDefinition
  1890. {
  1891. public:
  1892. CTimedItemRewardDefinition( void );
  1893. CTimedItemRewardDefinition( const CTimedItemRewardDefinition &that );
  1894. CTimedItemRewardDefinition &operator=( const CTimedItemRewardDefinition& rhs );
  1895. ~CTimedItemRewardDefinition( void ) { }
  1896. bool BInitFromKV( KeyValues *pKVTimedReward, CUtlVector<CUtlString> *pVecErrors = NULL );
  1897. uint32 GetRandomFrequency( void ) const { return RandomFloat( m_unMinFreq, m_unMaxFreq ); }
  1898. uint32 GetMinFrequency( void ) const { return m_unMinFreq; }
  1899. uint32 GetMaxFrequency( void ) const { return m_unMaxFreq; }
  1900. float GetChance( void ) const { return m_flChance; }
  1901. const CItemSelectionCriteria &GetCriteria( void ) const { return m_criteria; }
  1902. const CEconLootListDefinition *GetLootList( void ) const { return m_pLootList; }
  1903. bool BHasRequiredItem() const { return m_iRequiredItemDef != INVALID_ITEM_DEF_INDEX; }
  1904. item_definition_index_t GetRequiredItem() const { return m_iRequiredItemDef; }
  1905. #ifdef DBGFLAG_VALIDATE
  1906. void Validate( CValidator &validator, const char *pchName )
  1907. {
  1908. VALIDATE_SCOPE();
  1909. ValidateObj( m_criteria );
  1910. }
  1911. #endif // DBGFLAG_VALIDATE
  1912. private:
  1913. // Frequency of how often the item is awarded
  1914. uint32 m_unMinFreq;
  1915. uint32 m_unMaxFreq;
  1916. // The chance, between 0 and 1, that the item is rewarded
  1917. float m_flChance;
  1918. // The criteria to use to select the item to reward
  1919. CItemSelectionCriteria m_criteria;
  1920. // Alternatively, the loot_list to use instead
  1921. const CEconLootListDefinition *m_pLootList;
  1922. item_definition_index_t m_iRequiredItemDef;
  1923. };
  1924. #ifdef GC_DLL
  1925. //-----------------------------------------------------------------------------
  1926. // CExperimentDefinition
  1927. //-----------------------------------------------------------------------------
  1928. struct experiment_group_t
  1929. {
  1930. const char* m_pName;
  1931. uint32 m_unNumParticipants;
  1932. uint32 m_unMaxParticipants;
  1933. KeyValues *m_pKeyValues;
  1934. };
  1935. class CExperimentDefinition
  1936. {
  1937. public:
  1938. CExperimentDefinition( void );
  1939. ~CExperimentDefinition( void );
  1940. bool BInitFromKV( KeyValues *pKVExperiment, CUtlVector<CUtlString> *pVecErrors = NULL );
  1941. CUtlVector< experiment_group_t > &GetGroups() { return m_vecGroups; }
  1942. uint32 GetID() const { return m_unExperimentID; }
  1943. const char *GetName( void ) const { return m_pKeyValues->GetString( "name", "unknown" ); }
  1944. const char *GetDescription( void ) const { return m_pKeyValues->GetString( "description", "unknown" ); }
  1945. bool IsEnabled() const { return m_bEnabled; }
  1946. bool IsFull() const { return m_unNumParticipants >= m_unMaxParticipants; }
  1947. uint32 GetNumParticipants() const { return m_unNumParticipants; }
  1948. void SetNumParticipants( uint32 unNumParticipants ) { m_unNumParticipants = unNumParticipants; }
  1949. uint32 GetMaxParticipants() const { return m_unMaxParticipants; }
  1950. bool ChooseGroup( uint32 &unGroup );
  1951. private:
  1952. bool m_bEnabled;
  1953. uint32 m_unExperimentID;
  1954. uint32 m_unNumParticipants;
  1955. uint32 m_unMaxParticipants;
  1956. KeyValues *m_pKeyValues;
  1957. CUtlVector< experiment_group_t > m_vecGroups;
  1958. };
  1959. #endif
  1960. //-----------------------------------------------------------------------------
  1961. // CItemLevelingDefinition
  1962. //-----------------------------------------------------------------------------
  1963. class CItemLevelingDefinition
  1964. {
  1965. public:
  1966. CItemLevelingDefinition( void );
  1967. CItemLevelingDefinition( const CItemLevelingDefinition &that );
  1968. CItemLevelingDefinition &operator=( const CItemLevelingDefinition& rhs );
  1969. ~CItemLevelingDefinition( void );
  1970. bool BInitFromKV( KeyValues *pKVItemLevel, const char *pszLevelBlockName, CUtlVector<CUtlString> *pVecErrors = NULL );
  1971. uint32 GetLevel( void ) const { return m_unLevel; }
  1972. uint32 GetRequiredScore( void ) const { return m_unRequiredScore; }
  1973. const char *GetNameLocalizationKey( void ) const { return m_pszLocalizedName_LocalStorage; }
  1974. private:
  1975. uint32 m_unLevel;
  1976. uint32 m_unRequiredScore;
  1977. char *m_pszLocalizedName_LocalStorage;
  1978. };
  1979. //-----------------------------------------------------------------------------
  1980. // AchievementAward_t
  1981. // Holds the item to give away and the Data value to audit it with ( for cross
  1982. // game achievements)
  1983. //-----------------------------------------------------------------------------
  1984. struct AchievementAward_t
  1985. {
  1986. AchievementAward_t( const AchievementAward_t & rhs )
  1987. : m_sNativeName( rhs.m_sNativeName ),
  1988. m_unSourceAppId( rhs.m_unSourceAppId ),
  1989. m_unAuditData( rhs.m_unAuditData )
  1990. {
  1991. m_vecDefIndex.CopyArray( rhs.m_vecDefIndex.Base(), rhs.m_vecDefIndex.Count() );
  1992. }
  1993. AchievementAward_t( ) {}
  1994. CUtlString m_sNativeName;
  1995. AppId_t m_unSourceAppId;
  1996. uint32 m_unAuditData;
  1997. CUtlVector<uint16> m_vecDefIndex;
  1998. };
  1999. enum eTimedRewardType
  2000. {
  2001. kTimedRewards_RegularDrop,
  2002. kTimedRewards_SupplyCrate,
  2003. kTimedRewards_FreeTrialDrop,
  2004. kTimedRewards_RecipeDrop,
  2005. kTimedRewards_EventDrop02,
  2006. kNumTimedRewards
  2007. };
  2008. struct kill_eater_score_type_t
  2009. {
  2010. const char *m_pszTypeString;
  2011. const char *m_pszLevelBlockName;
  2012. bool m_bAllowBotVictims; // if true, we don't check for a valid Steam ID on the client before sending or a valid session on the GC before incrementing
  2013. #ifdef GC_DLL
  2014. bool m_bGCUpdateOnly;
  2015. bool m_AllowIncrementValues; // if true, clients are allowed to send up the amount to increment by (ie., "did 100 damage") rather than implicitly assuming a value of 1
  2016. bool m_bIsBaseKillType; // if true, when clients send up a notification of this type we'll also look for other relevant things on the GC, like whether the victim was a friend, etc.
  2017. #endif
  2018. };
  2019. // Index-to-string table, currently used for attribute value string lookups.
  2020. struct schema_string_table_entry_t
  2021. {
  2022. int m_iIndex;
  2023. const char *m_pszStr;
  2024. };
  2025. //-----------------------------------------------------------------------------
  2026. // CForeignAppImports
  2027. // Defines the way a single foreign app's items are mapped into this app
  2028. //-----------------------------------------------------------------------------
  2029. class CForeignAppImports
  2030. {
  2031. public:
  2032. CForeignAppImports() : m_mapDefinitions( DefLessFunc( uint16 ) ) {}
  2033. void AddMapping( uint16 unForeignDefIndex, const CEconItemDefinition *pDefn );
  2034. const CEconItemDefinition *FindMapping( uint16 unForeignDefIndex ) const;
  2035. private:
  2036. CUtlMap< uint16, const CEconItemDefinition *> m_mapDefinitions;
  2037. };
  2038. //-----------------------------------------------------------------------------
  2039. // ISchemaAttributeType
  2040. //-----------------------------------------------------------------------------
  2041. #ifdef GC_DLL
  2042. namespace GCSDK
  2043. {
  2044. class CColumnSet;
  2045. class CRecordBase;
  2046. class CWebAPIValues;
  2047. };
  2048. #endif // GC_DLL
  2049. // ISchemaAttributeType is the base interface for a "type" of attribute, where "type" is defined as
  2050. // "something that describes the memory layout, the DB layout, how to convert between them, etc.".
  2051. // Most of the low-level work done with attributes, including DB reading/writing, packing/unpacking
  2052. // for wire traffic, and other leaf code works exclusively through this interface.
  2053. //
  2054. // The class hierarchy looks like:
  2055. //
  2056. // ISchemaAttributeTypeBase< TAttribInMemoryType >:
  2057. //
  2058. // This describes a specific in-memory format for an attribute, without any association to
  2059. // a particular DB, wire format, etc. We can't template the base class because it's an
  2060. // interface. This implements about half of ISchemaAttributeType and has its own mini
  2061. // interface consisting of ConvertTypedValueToByteStream() and ConvertByteStreamToTypedValue(),
  2062. // both of which do work on statically-typed values that don't exist at higher levels.
  2063. //
  2064. // CSchemaAttributeTypeBase< TAttribSchType, TAttribInMemoryType >:
  2065. //
  2066. // This handles the schema-related functions on ISchemaAttributeType. These exist at a lower
  2067. // inheritance level than ISchemaAttributeTypeBase to allow code that needs to work type-safely
  2068. // on attributes in memory, but that doesn't know or need to know anything about databases,
  2069. // to exist. Examples of this include code that calls CEconItem::SetDynamicAttributeValue<T>().
  2070. //
  2071. // Individual implementations of custom attribute type start making sense immediately as
  2072. // subclasses of CSchemaAttributeTypeBase, for example CSchemaAttributeType_Default, which
  2073. // implements all of the old, untyped attribute system logic.
  2074. //
  2075. // CSchemaAttributeTypeProtobufBase< TAttribSchType, TProtobufValueType >
  2076. //
  2077. // An easy way of automating most of the work for making a new attribute type is to have
  2078. // the in-memory format be a protobuf object, allowing reflection, automatic network support,
  2079. // etc.
  2080. //
  2081. // Creating a new custom protobuf attribute consists of three steps:
  2082. //
  2083. // - create a new DB table that will hold your attribute data. This needs an itemid_t-sized item ID
  2084. // column named "ItemID", an attrib_definition_index_t-sized definition index column named "AttrDefIndex",
  2085. // and then whatever data you want to store.
  2086. //
  2087. // - create a new protobuf message type that will hold your custom attribute contents. This exists
  2088. // on the client and the GC in the same format.
  2089. //
  2090. // - implement a subclass of CSchemaAttributeTypeProtobufBase<>, for example:
  2091. //
  2092. // class CSchemaAttributeType_StrangeScore : public CSchemaAttributeTypeProtobufBase< GC_SCH_REFERENCE( CSchItemAttributeStrangeScore ) CAttribute_StrangeScore >
  2093. // {
  2094. // virtual void ConvertEconAttributeValueToSch( itemid_t unItemId, const CEconItemAttributeDefinition *pAttrDef, const union attribute_data_union_t& value, GCSDK::CRecordBase *out_pSchRecord ) const OVERRIDE;
  2095. // virtual void LoadSchToEconAttributeValue( CEconItem *pTargetItem, const CEconItemAttributeDefinition *pAttrDef, const GCSDK::CRecordBase *pSchRecord ) const OVERRIDE;
  2096. // };
  2097. //
  2098. // Implement these two GC-only functions to convert from the in-memory format to the DB format and
  2099. // vice versa and you're good to go.
  2100. //
  2101. // - register the new type in CEconItemSchema::BInitAttributeTypes().
  2102. //
  2103. // If the attribute type can't be silently converted to an already-existing attribute value type, a few other
  2104. // places will also fail to compile -- things like typed iteration, or compile-time type checking.
  2105. //
  2106. // Functions that start with "Convert" change the format of an attribute value (in a type-safe way wherever
  2107. // possible), copying the value from one of the passed-in parameters to the other. Functions that start with
  2108. // "Load" do a format conversion, but also add the post-conversion value to the passed-in CEconItem. This
  2109. // comes up most often when generating new items, either from the DB (LoadSch), the network (LoadByteSteam),
  2110. // or creation of a new item on the GC (LoadOrGenerate).
  2111. class ISchemaAttributeType
  2112. {
  2113. public:
  2114. virtual ~ISchemaAttributeType() { }
  2115. // Returns a unique integer describing the C++-in-memory-layout type used by this attribute type.
  2116. // For example, something that stores "int" might return 0 and "CSomeFancyWideAttributeType" might
  2117. // return 1. The actual values don't matter and can even differ between different runs of the game/GC.
  2118. // The only important thing is that during a single run the value for a single type is consistent.
  2119. virtual unsigned int GetTypeUniqueIdentifier() const = 0;
  2120. #ifdef GC_DLL
  2121. // What's the whole column set (and associated DB table) that this attribute uses? Meant to be
  2122. // implemented by subclasses that have DB type information.
  2123. virtual const GCSDK::CColumnSet& GetFullColumnSet() const = 0;
  2124. // Create an instance of a schema row. Mananging the memory is the responsibility of the caller.
  2125. // Meant to be implemented by subclasses that have DB type information.
  2126. virtual GCSDK::CRecordBase *CreateTypedSchRecord() const = 0;
  2127. // ...
  2128. virtual bool BAssetClassExportedAttributeValue( const CEconItemAttributeDefinition *pAttrDef, const attribute_data_union_t& value ) const { return true; }
  2129. // Prepare a DB row describing an instance of this attribute for writing.
  2130. virtual void ConvertEconAttributeValueToSch( itemid_t unItemId, const CEconItemAttributeDefinition *pAttrDef, const union attribute_data_union_t& value, GCSDK::CRecordBase *out_pSchRecord ) const = 0;
  2131. // We have a row read from the database and an item to add it as an attribute for. This
  2132. // does the opposite work of ConvertEconAttributeValueToSch() and also adds it to the CEconItem.
  2133. virtual void LoadSchToEconAttributeValue( CEconItem *pTargetItem, const CEconItemAttributeDefinition *pAttrDef, const GCSDK::CRecordBase *pSchRecord ) const = 0;
  2134. // Have this attribute type either copy the data straight out of the value union, or run the logic
  2135. // described by pszCustomLogicDesc to generate a new value. Either way, some correctly-typed data
  2136. // will wind up in an attribute on the target item. This is intended to call through to LoadEconAttributeValue()
  2137. // to do the actual assignment. This is only accessible on the GC.
  2138. virtual void LoadOrGenerateEconAttributeValue( CEconItem *pTargetItem, const CEconItemAttributeDefinition *pAttrDef, const static_attrib_t& staticAttrib, const CEconGameAccount *pGameAccount ) const = 0;
  2139. virtual void GenerateEconAttributeValue( const CEconItemAttributeDefinition *pAttrDef, const static_attrib_t& staticAttrib, const CEconGameAccount *pGameAccount, attribute_data_union_t* out_pValue ) const = 0;
  2140. #endif // GC_DLL
  2141. // Have this attribute type copy the data out of the value union and type-copy it onto the item. This
  2142. // is accessible on clients as well as the GC.
  2143. virtual void LoadEconAttributeValue( CEconItem *pTargetItem, const CEconItemAttributeDefinition *pAttrDef, const union attribute_data_union_t& value ) const = 0;
  2144. // ...
  2145. virtual void ConvertEconAttributeValueToByteStream( const union attribute_data_union_t& value, std::string *out_psBytes ) const = 0;
  2146. // ...
  2147. virtual bool BConvertStringToEconAttributeValue( const CEconItemAttributeDefinition *pAttrDef, const char *pszValue, union attribute_data_union_t *out_pValue, bool bEnableTerribleBackwardsCompatibilitySchemaParsingCode = false ) const = 0;
  2148. // ...
  2149. virtual void ConvertEconAttributeValueToString( const CEconItemAttributeDefinition *pAttrDef, const attribute_data_union_t& value, std::string *out_ps ) const = 0;
  2150. // Used to deserialize a byte stream, probably from an on-wire protobuf message, instead an instance
  2151. // of the attribute in memory. See ConvertByteStreamToTypedValue() for example implementation, or
  2152. // ConvertTypedValueToByteStream() for an example of the byte-stream generator code.
  2153. virtual void LoadByteStreamToEconAttributeValue( CEconItem *pTargetItem, const CEconItemAttributeDefinition *pAttrDef, const std::string& sBytes ) const = 0;
  2154. // Give the subclass a chance to default-initialize a new value. For larger types, this may hit the
  2155. // heap. This must be called before otherwise manipulating [out_pValue] through Convert*() functions.
  2156. virtual void InitializeNewEconAttributeValue( attribute_data_union_t *out_pValue ) const = 0;
  2157. // Free any heap-allocated memory from this attribute value. Is not responsible for zeroing out
  2158. // pointers, etc.
  2159. virtual void UnloadEconAttributeValue( union attribute_data_union_t *out_pValue ) const = 0;
  2160. // ...
  2161. virtual bool OnIterateAttributeValue( class IEconItemAttributeIterator *pIterator, const CEconItemAttributeDefinition *pAttrDef, const attribute_data_union_t& value ) const = 0;
  2162. // This could also be called "BIsHackyMessyOldAttributeType()". This determines whether the attribute
  2163. // can be set at runtime on a CEconItemView instance, whether the gameserver can replicate the value to
  2164. // game clients, etc. It really only makes sense for value types 32 bits or smaller.
  2165. virtual bool BSupportsGameplayModificationAndNetworking() const { return false; }
  2166. };
  2167. //-----------------------------------------------------------------------------
  2168. // CEconItemSchema
  2169. // Defines the way econ items can be used in a game
  2170. //-----------------------------------------------------------------------------
  2171. typedef CUtlDict<CUtlConstString, int> ArmoryStringDict_t;
  2172. typedef CUtlDict< CUtlVector<CItemLevelingDefinition> * > LevelBlockDict_t;
  2173. typedef CUtlMap<unsigned int, kill_eater_score_type_t> KillEaterScoreMap_t;
  2174. typedef CUtlDict< CUtlVector< schema_string_table_entry_t > * > SchemaStringTableDict_t;
  2175. struct attr_type_t
  2176. {
  2177. CUtlConstString m_sName;
  2178. const ISchemaAttributeType *m_pAttrType;
  2179. attr_type_t( const char *pszName, const ISchemaAttributeType *pAttrType )
  2180. : m_sName( pszName )
  2181. , m_pAttrType( pAttrType )
  2182. {
  2183. }
  2184. };
  2185. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  2186. class IDelayedSchemaData
  2187. {
  2188. public:
  2189. virtual ~IDelayedSchemaData() {}
  2190. virtual bool InitializeSchema( CEconItemSchema *pItemSchema ) = 0;
  2191. protected:
  2192. // Passing '0' as the expected version means "we weren't expecting any version in particular" and will
  2193. // skip the sanity checking.
  2194. bool InitializeSchemaInternal( CEconItemSchema *pItemSchema, CUtlBuffer& bufRawData, bool bInitAsBinary, uint32 nExpectedVersion );
  2195. };
  2196. #endif // defined(CLIENT_DLL) || defined(GAME_DLL)
  2197. class CEconStorePriceSheet;
  2198. class CEconItemSchema
  2199. {
  2200. public:
  2201. CEconItemSchema( );
  2202. private:
  2203. CEconItemSchema( const CEconItemSchema & rhs );
  2204. CEconItemSchema &operator=( CEconItemSchema & rhs );
  2205. public:
  2206. virtual ~CEconItemSchema( void ) { Reset(); };
  2207. // Setup & parse in the item data files.
  2208. virtual bool BInit( const char *fileName, const char *pathID, CUtlVector<CUtlString> *pVecErrors = NULL );
  2209. bool BInitBinaryBuffer( CUtlBuffer &buffer, CUtlVector<CUtlString> *pVecErrors = NULL );
  2210. bool BInitTextBuffer( CUtlBuffer &buffer, CUtlVector<CUtlString> *pVecErrors = NULL );
  2211. #ifdef GC_DLL
  2212. virtual bool DoPostPriceSheetLoadInit( CEconStorePriceSheet *pPriceSheet ); // Called once the price sheet's been loaded
  2213. #endif
  2214. uint32 GetVersion() const { return m_unVersion; }
  2215. CSHA GetSchemaSHA() const { return m_schemaSHA; }
  2216. uint32 GetResetCount() const { return m_unResetCount; }
  2217. // Dump the schema for debug purposes
  2218. bool DumpItems ( const char *fileName, const char *pathID = NULL );
  2219. // Perform the computation used to calculate the schema version
  2220. static uint32 CalculateKeyValuesVersion( KeyValues *pKV );
  2221. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  2222. // This function will immediately reinitialize the schema if it's safe to do so, or store off the data
  2223. // if it isn't safe to update at the moment.
  2224. bool MaybeInitFromBuffer( IDelayedSchemaData *pDelayedSchemaData );
  2225. // If there is saved schema initialization data, initialize it now. If there is no saved data, this
  2226. // will return success.
  2227. bool BInitFromDelayedBuffer();
  2228. #endif // defined(CLIENT_DLL) || defined(GAME_DLL)
  2229. // Accessors to the base properties
  2230. EEquipType_t GetEquipTypeFromClassIndex( int iClass ) const;
  2231. equipped_class_t GetAccountIndex() const { return m_unAccoutClassIndex; }
  2232. equipped_class_t GetFirstValidClass() const { return m_unFirstValidClass; }
  2233. equipped_class_t GetLastValidClass() const { return m_unLastValidClass; }
  2234. bool IsValidClass( equipped_class_t unClass ) { return ( unClass >= m_unFirstValidClass && unClass <= m_unLastValidClass ) || unClass == GetAccountIndex(); }
  2235. bool IsValidItemSlot( equipped_slot_t unSlot, equipped_class_t unClass ) const { return IsValidItemSlot( unSlot, unClass == m_unAccoutClassIndex ? EQUIP_TYPE_ACCOUNT : EQUIP_TYPE_CLASS ); }
  2236. bool IsValidItemSlot( equipped_slot_t unSlot, EEquipType_t eType ) const
  2237. {
  2238. return eType == EQUIP_TYPE_ACCOUNT ? unSlot >= m_unFirstValidAccountItemSlot && unSlot <= m_unLastValidAccountItemSlot
  2239. : unSlot >= m_unFirstValidClassItemSlot && unSlot <= m_unLastValidClassItemSlot;
  2240. }
  2241. enum { kMaxItemPresetCount = 4 };
  2242. uint32 GetNumAllowedItemPresets() const { return kMaxItemPresetCount; }
  2243. bool IsValidPreset( equipped_preset_t unPreset ) const { return unPreset <= GetNumAllowedItemPresets(); }
  2244. uint32 GetMinLevel() const { return m_unMinLevel; }
  2245. uint32 GetMaxLevel() const { return m_unMaxLevel; }
  2246. // Accessors to the underlying sections
  2247. typedef CUtlHashMapLarge<int, CEconItemDefinition*> ItemDefinitionMap_t;
  2248. const ItemDefinitionMap_t &GetItemDefinitionMap() const { return m_mapItems; }
  2249. typedef CUtlMap<int, CEconItemDefinition*, int> SortedItemDefinitionMap_t;
  2250. const SortedItemDefinitionMap_t &GetSortedItemDefinitionMap() const { return m_mapItemsSorted; }
  2251. typedef CUtlMap<int, CEconItemDefinition*, int> ToolsItemDefinitionMap_t;
  2252. const ToolsItemDefinitionMap_t &GetToolsItemDefinitionMap() const { return m_mapToolsItems; }
  2253. typedef CUtlMap<int, CEconItemDefinition*, int> BaseItemDefinitionMap_t;
  2254. const BaseItemDefinitionMap_t &GetBaseItemDefinitionMap() const { return m_mapBaseItems; }
  2255. typedef CUtlMap<const char*, CEconLootListDefinition *, int> LootListDefinitionMap_t;
  2256. const LootListDefinitionMap_t &GetLootLists() const { return m_mapLootLists; }
  2257. typedef CUtlMap<int, const char*> RevolvingLootListDefinitionMap_t;
  2258. const RevolvingLootListDefinitionMap_t &GetRevolvingLootLists() const { return m_mapRevolvingLootLists; }
  2259. typedef CUtlMap<const char*, int> BodygroupStateMap_t;
  2260. const BodygroupStateMap_t &GetDefaultBodygroupStateMap() const { return m_mapDefaultBodygroupState; }
  2261. typedef CUtlVector<CEconColorDefinition *> ColorDefinitionsList_t;
  2262. typedef CUtlMap<const char *, KeyValues *, int> PrefabMap_t;
  2263. #ifdef GC_DLL
  2264. struct periodic_score_t
  2265. {
  2266. eEconPeriodicScoreEvents m_eEventType;
  2267. bool m_bGCUpdateOnly; // if set, only code that runs on the GC can initiate a change of this stat (ie., counting gifts -> true; bots killed -> false)
  2268. uint32 m_unTimePeriodLengthInSeconds;
  2269. CEconItemDefinition *m_pRewardItemDefinition;
  2270. };
  2271. typedef CUtlVector<periodic_score_t> PeriodicScoreTypeList_t;
  2272. #endif // GC_DLL
  2273. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  2274. CEconItemDefinition *GetDefaultItemDefinition() { return m_pDefaultItemDefinition; }
  2275. bool SetupPreviewItemDefinition( KeyValues *pKV );
  2276. #endif
  2277. const CUtlMap<int, CEconItemQualityDefinition, int > &GetQualityDefinitionMap() const { return m_mapQualities; }
  2278. const CUtlMap<int, CEconItemAttributeDefinition, int > &GetAttributeDefinitionMap() const { return m_mapAttributes; }
  2279. typedef CUtlMap<int, CEconCraftingRecipeDefinition*, int > RecipeDefinitionMap_t;
  2280. const RecipeDefinitionMap_t &GetRecipeDefinitionMap() const { return m_mapRecipes; }
  2281. typedef CUtlMap<const char*, CEconItemSetDefinition*, int > ItemSetMap_t;
  2282. const ItemSetMap_t &GetItemSets() const { return m_mapItemSets; }
  2283. typedef CUtlMap<const char*, CEconItemCollectionDefinition*, int > ItemCollectionMap_t;
  2284. const ItemCollectionMap_t &GetItemCollections() const { return m_mapItemCollections; }
  2285. typedef CUtlVector< int > ItemCollectionCrateMap_t;
  2286. const ItemCollectionCrateMap_t &GetItemCollectionCrates() const { return m_vecItemCollectionCrates; }
  2287. typedef CUtlMap<const char*, CEconItemPaintKitDefinition*, int > ItemPaintKitMap_t;
  2288. const ItemPaintKitMap_t &GetItemPaintKits() const { return m_mapItemPaintKits; }
  2289. typedef CUtlMap<const char*, CEconOperationDefinition*, int > OperationDefinitionMap_t;
  2290. const OperationDefinitionMap_t &GetOperationDefinitions() const { return m_mapOperationDefinitions; }
  2291. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  2292. const ArmoryStringDict_t &GetArmoryDataItemClasses() const { return m_dictArmoryItemClassesDataStrings; }
  2293. const ArmoryStringDict_t &GetArmoryDataItemTypes() const { return m_dictArmoryItemTypesDataStrings; }
  2294. const ArmoryStringDict_t &GetArmoryDataItems() const { return m_dictArmoryItemDataStrings; }
  2295. const ArmoryStringDict_t &GetArmoryDataAttributes() const { return m_dictArmoryAttributeDataStrings; }
  2296. #elif defined(GC_DLL)
  2297. CUtlVector< CExperimentDefinition > &GetExperiments() { return m_vecExperiments; }
  2298. const CUtlVector< AppId_t > & GetForeignApps() const { return m_vecForeignApps; }
  2299. const CEconItemDefinition *GetAppItemImport( AppId_t unAppID, uint16 usDefIndex ) const;
  2300. #endif
  2301. const CTimedItemRewardDefinition* GetTimedReward( eTimedRewardType type ) const;
  2302. const CEconLootListDefinition* GetLootListByName( const char* pListName, int *out_piIndex = NULL ) const;
  2303. const CEconLootListDefinition* GetLootListByIndex( int iIdx ) const { return m_mapLootLists.IsValidIndex(iIdx) ? m_mapLootLists[iIdx] : NULL; }
  2304. const CQuestObjectiveDefinition* GetQuestObjectiveByDefIndex( int iIdx ) const;
  2305. const CUtlMap<int, CQuestObjectiveDefinition*, int >& GetQuestObjectives() const { return m_mapQuestObjectives; }
  2306. uint8 GetDefaultQuality() const { return AE_UNIQUE; }
  2307. void AssignDefaultBodygroupState( const char *pszBodygroupName, int iValue );
  2308. equip_region_mask_t GetEquipRegionMaskByName( const char *pRegionName ) const;
  2309. struct EquipRegion
  2310. {
  2311. CUtlConstString m_sName;
  2312. unsigned int m_unBitIndex; // which bit are we claiming ownership over? there might be multiple equip regions with the same bit if we're in a "shared" block
  2313. equip_region_mask_t m_unMask; // full region conflict mask
  2314. };
  2315. typedef CUtlVector<EquipRegion> EquipRegionsList_t;
  2316. const EquipRegionsList_t& GetEquipRegionsList() const { return m_vecEquipRegionsList; }
  2317. equip_region_mask_t GetEquipRegionBitMaskByName( const char *pRegionName ) const;
  2318. KeyValues *FindDefinitionPrefabByName( const char *pszPrefabName ) const;
  2319. const PrefabMap_t& GetPrefabMap() const { return m_mapDefinitionPrefabs; }
  2320. CUtlVector< CEconItemDefinition * > &GetBundles() { return m_vecBundles; } // Retrieve a cached list of all bundles
  2321. const char *FindStringTableEntry( const char *pszTableName, int iIndex ) const;
  2322. private:
  2323. void SetEquipRegionConflict( int iRegion, unsigned int unBit );
  2324. int GetEquipRegionIndexByName( const char *pRegionName ) const;
  2325. public:
  2326. // Common lookup methods
  2327. bool BGetItemQualityFromName( const char *pchName, uint8 *nQuality ) const;
  2328. const CEconItemQualityDefinition *GetQualityDefinition( int nQuality ) const;
  2329. const CEconItemQualityDefinition *GetQualityDefinitionByName( const char *pszDefName ) const;
  2330. bool BGetItemRarityFromName( const char* pchName, uint8 *nRarity ) const;
  2331. const CEconItemRarityDefinition *GetRarityDefinitionByMapIndex( int nRarityIndex ) const;
  2332. const CEconItemRarityDefinition *GetRarityDefinition( int nRarity ) const;
  2333. const CEconItemRarityDefinition *GetRarityDefinitionByName( const char *pszDefName ) const;
  2334. virtual int GetRarityDefinitionCount( void ) const { return m_mapRarities.Count(); }
  2335. virtual const char* GetRarityName( uint8 iRarity );
  2336. virtual const char* GetRarityLocKey( uint8 iRarity );
  2337. virtual const char* GetRarityColor( uint8 iRarity );
  2338. virtual int GetRarityIndex( const char* pszRarity );
  2339. const CEconItemCollectionDefinition *GetCollectionByName( const char* pCollectionName );
  2340. virtual int GetItemSeriesDefinitionCount( void ) const { return m_mapItemSeries.Count(); }
  2341. bool BGetItemSeries( const char* pchName, uint8 *nItemSeries ) const;
  2342. const CEconItemSeriesDefinition *GetItemSeriesDefinition( int nRarity ) const;
  2343. CEconItemDefinition *GetItemDefinition( int iItemIndex );
  2344. const CEconItemDefinition *GetItemDefinition( int iItemIndex ) const;
  2345. CEconItemAttributeDefinition *GetAttributeDefinition( int iAttribIndex );
  2346. const CEconItemAttributeDefinition *GetAttributeDefinition( int iAttribIndex ) const;
  2347. CEconItemAttributeDefinition *GetAttributeDefinitionByName( const char *pszDefName );
  2348. const CEconItemAttributeDefinition *GetAttributeDefinitionByName( const char *pszDefName ) const;
  2349. CEconCraftingRecipeDefinition *GetRecipeDefinition( int iRecipeIndex );
  2350. CEconColorDefinition *GetColorDefinitionByName( const char *pszDefName );
  2351. const CEconColorDefinition *GetColorDefinitionByName( const char *pszDefName ) const;
  2352. #ifdef CLIENT_DLL
  2353. const char *GetSteamPackageLocalizationToken( uint32 unPackageId ) const;
  2354. #endif // CLIENT_DLL
  2355. bool BCanGSCreateItems( uint32 unIP ) const;
  2356. #ifdef GC_DLL
  2357. const AchievementAward_t *GetAchievementReward( const char *pchAchievementName, AppId_t unAppID ) const;
  2358. const AchievementAward_t *GetAchievementRewardByData( uint32 unData ) const;
  2359. #endif
  2360. const AchievementAward_t *GetAchievementRewardByDefIndex( uint16 usDefIndex ) const;
  2361. bool BHasAchievementRewards( void ) const { return (m_dictAchievementRewards.Count() > 0); }
  2362. static CUtlString ComputeAchievementName( AppId_t unAppID, const char *pchNativeAchievementName );
  2363. // Iterating over the item definitions. Game needs this to precache data.
  2364. CEconItemDefinition *GetItemDefinitionByName( const char *pszDefName );
  2365. const CEconItemDefinition *GetItemDefinitionByName( const char *pszDefName ) const;
  2366. #ifdef GC_DLL
  2367. random_attrib_t *GetRandomAttributeTemplateByName( const char *pszAttrTemplateName ) const;
  2368. #endif // GC_DLL
  2369. attachedparticlesystem_t* GetAttributeControlledParticleSystem( int id );
  2370. attachedparticlesystem_t* FindAttributeControlledParticleSystem( const char *pchSystemName );
  2371. typedef CUtlMap<int, attachedparticlesystem_t > ParticleDefinitionMap_t;
  2372. const ParticleDefinitionMap_t& GetAttributeControlledParticleSystems() const { return m_mapAttributeControlledParticleSystems; }
  2373. const CUtlVector< int > *GetWeaponUnusualParticleIndexes() const { return &m_vecAttributeControlledParticleSystemsWeapons; }
  2374. const CUtlVector< int > *GetCosmeticUnusualParticleIndexes() const { return &m_vecAttributeControlledParticleSystemsCosmetics; }
  2375. const CUtlVector< int > *GetTauntUnusualParticleIndexes() const { return &m_vecAttributeControlledParticleSystemsTaunts; }
  2376. #ifdef CLIENT_DLL
  2377. locchar_t *GetParticleSystemLocalizedName( int index ) const;
  2378. #endif // CLIENT_DLL
  2379. #ifdef GC_DLL
  2380. const PeriodicScoreTypeList_t& GetPeriodicScoreTypeList() const { return m_vecPeriodicScoreTypes; }
  2381. int GetPeriodicScoreTypeCount() const { return GetPeriodicScoreTypeList().Count(); } // how many types of events are we tracking? the range goes from 0 through this return value
  2382. const periodic_score_t& GetPeriodicScoreInfo( int iPeriodicScoreIndex ) const; // get the full info block for this periodic score -- event type, time period, etc.
  2383. // Only intended to be used for generating data for the WebAPI.
  2384. const KillEaterScoreMap_t& GetKillEaterScoreTypes() const { return m_mapKillEaterScoreTypes; }
  2385. const SchemaStringTableDict_t& GetStringTables() const { return m_dictStringTable; }
  2386. #endif // GC_DLL
  2387. item_definition_index_t GetCommunityMarketRemappedDefinitionIndex( item_definition_index_t unSearchItemDef ) const;
  2388. const CUtlVector<attr_type_t>& GetAttributeTypes() const { return m_vecAttributeTypes; }
  2389. const ISchemaAttributeType *GetAttributeType( const char *pszAttrTypeName ) const;
  2390. const LevelBlockDict_t& GetItemLevelingDataDict() const { return m_vecItemLevelingData; }
  2391. const CUtlVector<CItemLevelingDefinition> *GetItemLevelingData( const char *pszLevelBlockName ) const
  2392. {
  2393. LevelBlockDict_t::IndexType_t i = m_vecItemLevelingData.Find( pszLevelBlockName );
  2394. if ( i == LevelBlockDict_t::InvalidIndex() )
  2395. return NULL;
  2396. return m_vecItemLevelingData[i];
  2397. }
  2398. const CItemLevelingDefinition *GetItemLevelForScore( const char *pszLevelBlockName, uint32 unScore ) const;
  2399. const char *GetKillEaterScoreTypeLocString( uint32 unScoreType ) const;
  2400. const char *GetKillEaterScoreTypeLevelingDataName( uint32 unScoreType ) const;
  2401. bool GetKillEaterScoreTypeAllowsBotVictims( uint32 unScoreType ) const;
  2402. #ifdef GC_DLL
  2403. bool GetKillEaterScoreTypeGCOnlyUpdate( uint32 unScoreType ) const;
  2404. bool GetKillEaterScoreTypeAllowsIncrementValues( uint32 unScoreType ) const;
  2405. #endif
  2406. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  2407. void ItemTesting_CreateTestDefinition( int iCloneFromItemDef, int iNewDef, KeyValues *pNewKV );
  2408. void ItemTesting_DiscardTestDefinition( int iDef );
  2409. #endif
  2410. #ifdef DBGFLAG_VALIDATE
  2411. void Validate( CValidator &validator, const char *pchName );
  2412. #endif // DBGFLAG_VALIDATE
  2413. econ_tag_handle_t GetHandleForTag( const char *pszTagName ); // non-const because it may create a new tag handle
  2414. typedef CUtlDict<econ_tag_handle_t> EconTagDict_t;
  2415. #ifdef GC_DLL
  2416. const EconTagDict_t& GetEconTagDict() const { return m_dictTags; } // meant for internal/debug use only, not for runtime iteration
  2417. #endif // GC_DLL
  2418. virtual RTime32 GetCustomExpirationDate( const char *pszExpirationDate ) const { return k_RTime32Nil; }
  2419. public:
  2420. // Subclass interface.
  2421. virtual CEconItemDefinition *CreateEconItemDefinition() { return new CEconItemDefinition; }
  2422. virtual CEconCraftingRecipeDefinition *CreateCraftingRecipeDefinition() { return new CEconCraftingRecipeDefinition; }
  2423. virtual CEconStyleInfo *CreateEconStyleInfo() { return new CEconStyleInfo; }
  2424. virtual CQuestObjectiveDefinition *CreateQuestDefinition() { return new CQuestObjectiveDefinition; }
  2425. virtual IEconTool *CreateEconToolImpl( const char *pszToolType, const char *pszUseString, const char *pszUsageRestriction, item_capabilities_t unCapabilities, KeyValues *pUsageKV );
  2426. #ifdef GC_DLL
  2427. virtual random_attrib_t *CreateRandomAttribute( const char *pszContext, KeyValues *pRandomAttributesKV, CUtlVector<CUtlString> *pVecErrors = NULL );
  2428. #endif // GC_DLL
  2429. virtual bool BCanStrangeFilterApplyToStrangeSlotInItem( uint32 /*strange_event_restriction_t*/ unRestrictionType, uint32 unRestrictionValue, const IEconItemInterface *pItem, int iStrangeSlot, uint32 *out_pOptionalScoreType ) const;
  2430. bool AddQuestObjective( const CQuestObjectiveDefinition **ppQuestObjective, KeyValues *pKVObjective, CUtlVector<CUtlString> *pVecErrors );
  2431. bool BInsertLootlist( const char *pListName, KeyValues *pKVLootList, CUtlVector<CUtlString> *pVecErrors );
  2432. #ifdef GC_DLL
  2433. void PerformCaseBehaviorCheck();
  2434. #endif
  2435. protected:
  2436. virtual void Reset( void );
  2437. virtual bool BInitSchema( KeyValues *pKVRawDefinition, CUtlVector<CUtlString> *pVecErrors = NULL );
  2438. #ifdef TF_CLIENT_DLL
  2439. virtual int CalculateNumberOfConcreteItems( const CEconItemDefinition *pItemDef ); // Let derived classes handle custom item types
  2440. #endif // TF_CLIENT_DLL
  2441. private:
  2442. bool BInitGameInfo( KeyValues *pKVGameInfo, CUtlVector<CUtlString> *pVecErrors );
  2443. bool BInitAttributeTypes( CUtlVector<CUtlString> *pVecErrors );
  2444. #ifdef GC_DLL
  2445. bool BInitPeriodicScoring( KeyValues *pKVGameInfo, CUtlVector<CUtlString> *pVecErrors );
  2446. #endif // GC_DLL
  2447. bool BInitDefinitionPrefabs( KeyValues *pKVPrefabs, CUtlVector<CUtlString> *pVecErrors );
  2448. bool BInitItemSeries( KeyValues *pKVSeries, CUtlVector<CUtlString> *pVecErrors );
  2449. bool BVerifyBaseItemNames( CUtlVector<CUtlString> *pVecErrors );
  2450. bool BInitRarities( KeyValues *pKVRarities, KeyValues *pKVRarityWeights, CUtlVector<CUtlString> *pVecErrors );
  2451. bool BInitQualities( KeyValues *pKVAttributes, CUtlVector<CUtlString> *pVecErrors );
  2452. bool BInitColors( KeyValues *pKVColors, CUtlVector<CUtlString> *pVecErrors );
  2453. bool BInitAttributes( KeyValues *pKVAttributes, CUtlVector<CUtlString> *pVecErrors );
  2454. bool BInitEquipRegions( KeyValues *pKVEquipRegions, CUtlVector<CUtlString> *pVecErrors );
  2455. bool BInitEquipRegionConflicts( KeyValues *pKVEquipRegions, CUtlVector<CUtlString> *pVecErrors );
  2456. bool BInitItems( KeyValues *pKVAttributes, CUtlVector<CUtlString> *pVecErrors );
  2457. bool BInitItemSets( KeyValues *pKVItemSets, CUtlVector<CUtlString> *pVecErrors );
  2458. bool BInitTimedRewards( KeyValues *pKVTimeRewards, CUtlVector<CUtlString> *pVecErrors );
  2459. bool BInitAchievementRewards( KeyValues *pKVTimeRewards, CUtlVector<CUtlString> *pVecErrors );
  2460. #ifdef GC_DLL
  2461. bool BInitRandomAttributeTemplates( KeyValues *pKVRandomAttributeTemplates, CUtlVector<CUtlString> *pVecErrors );
  2462. #endif // GC_DLL
  2463. bool BInitRecipes( KeyValues *pKVRecipes, CUtlVector<CUtlString> *pVecErrors );
  2464. bool BInitLootLists( KeyValues *pKVLootLists, CUtlVector<CUtlString> *pVecErrors );
  2465. bool BInitRevolvingLootLists( KeyValues *pKVRevolvingLootLists, CUtlVector<CUtlString> *pVecErrors );
  2466. bool BInitItemCollections( KeyValues *pKVItemSets, CUtlVector<CUtlString> *pVecErrors );
  2467. bool BInitCollectionReferences( CUtlVector<CUtlString> *pVecErrors );
  2468. bool BInitItemPaintKitDefinitions( KeyValues *pKVPaintKits, CUtlVector<CUtlString> *pVecErrors );
  2469. bool BInitOperationDefinitions( KeyValues *pKVGameInfo, KeyValues *pOperations, CUtlVector<CUtlString> *pVecErrors );
  2470. #ifdef TF_CLIENT_DLL
  2471. bool BInitConcreteItemCounts( CUtlVector<CUtlString> *pVecErrors );
  2472. bool BInitSteamPackageLocalizationToken( KeyValues *pKVSteamPackages, CUtlVector<CUtlString> *pVecErrors );
  2473. #endif // TF_CLIENT_DLL
  2474. bool BInitItemLevels( KeyValues *pKVItemLevels, CUtlVector<CUtlString> *pVecErrors );
  2475. bool BInitKillEaterScoreTypes( KeyValues *pKVItemLevels, CUtlVector<CUtlString> *pVecErrors );
  2476. bool BInitStringTables( KeyValues *pKVStringTables, CUtlVector<CUtlString> *pVecErrors );
  2477. bool BInitCommunityMarketRemaps( KeyValues *pKVCommunityMarketRemaps, CUtlVector<CUtlString> *pVecErrors );
  2478. bool BPostSchemaInit( CUtlVector<CUtlString> *pVecErrors ) const;
  2479. bool BInitAttributeControlledParticleSystems( KeyValues *pKVParticleSystems, CUtlVector<CUtlString> *pVecErrors );
  2480. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  2481. bool BInitArmoryData( KeyValues *pKVArmoryData, CUtlVector<CUtlString> *pVecErrors );
  2482. #else
  2483. bool BInitExperiements( KeyValues *pKVExperiments, CUtlVector<CUtlString> *pVecErrors );
  2484. bool BInitForeignImports( CUtlVector<CUtlString> *pVecErrors );
  2485. CForeignAppImports *FindOrAddAppImports( AppId_t unAppID );
  2486. #endif
  2487. bool BVerifyLootListItemDropDates( const CEconLootListDefinition* pLootList, CUtlVector<CUtlString> *pVecErrors ) const;
  2488. bool BRecurseiveVerifyLootListItemDropDates( const CEconLootListDefinition* pLootList, const CEconLootListDefinition* pRootLootList, CUtlVector<CUtlString> *pVecErrors ) const;
  2489. // Note: this returns pointers to the inside of a vector and/or NULL. Pointers are not intended to be
  2490. // saved off and used later.
  2491. const kill_eater_score_type_t *FindKillEaterScoreType( uint32 unScoreType ) const;
  2492. uint32 m_unResetCount;
  2493. KeyValues *m_pKVRawDefinition;
  2494. uint32 m_unVersion;
  2495. CSHA m_schemaSHA;
  2496. // Class range
  2497. equipped_class_t m_unFirstValidClass;
  2498. equipped_class_t m_unLastValidClass;
  2499. equipped_class_t m_unAccoutClassIndex;
  2500. // Item slot range
  2501. equipped_slot_t m_unFirstValidClassItemSlot;
  2502. equipped_slot_t m_unLastValidClassItemSlot;
  2503. equipped_slot_t m_unFirstValidAccountItemSlot;
  2504. equipped_slot_t m_unLastValidAccountItemSlot;
  2505. // Number of allowed presets
  2506. uint32 m_unNumItemPresets;
  2507. // Allowable range of item levels for this app
  2508. uint32 m_unMinLevel;
  2509. uint32 m_unMaxLevel;
  2510. // Total value of all the weights of the qualities
  2511. uint32 m_unSumQualityWeights;
  2512. // Name-to-implementation list of all unique attribute types (ie., "wide strange score").
  2513. CUtlVector<attr_type_t> m_vecAttributeTypes;
  2514. // Contains the list of rarity definitions
  2515. CUtlMap<int, CEconItemSeriesDefinition, int > m_mapItemSeries;
  2516. // Contains the list of rarity definitions
  2517. CUtlMap<int, CEconItemRarityDefinition, int > m_mapRarities;
  2518. // Contains the list of item definitions read in from all data files.
  2519. CUtlMap<int, CEconItemQualityDefinition, int > m_mapQualities;
  2520. // Contains the list of item definitions read in from all data files.
  2521. ItemDefinitionMap_t m_mapItems;
  2522. CUtlMap<int, CQuestObjectiveDefinition*, int > m_mapQuestObjectives;
  2523. // A sorted version of the same map, for instances where we really want sorted data
  2524. SortedItemDefinitionMap_t m_mapItemsSorted;
  2525. // List of all the tool items, is a sublist of mapItems
  2526. ToolsItemDefinitionMap_t m_mapToolsItems;
  2527. // List of all base items, is a sublist of mapItems
  2528. BaseItemDefinitionMap_t m_mapBaseItems;
  2529. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  2530. // What is the default item definition we'll return in the client code if we can't find the correct one?
  2531. CEconItemDefinition *m_pDefaultItemDefinition;
  2532. #endif
  2533. // Contains the list of attribute definitions read in from all data files.
  2534. CUtlMap<int, CEconItemAttributeDefinition, int > m_mapAttributes;
  2535. // Contains the list of item recipes read in from all data files.
  2536. RecipeDefinitionMap_t m_mapRecipes;
  2537. // Contains the list of item sets.
  2538. ItemSetMap_t m_mapItemSets;
  2539. ItemCollectionMap_t m_mapItemCollections;
  2540. ItemCollectionCrateMap_t m_vecItemCollectionCrates;
  2541. OperationDefinitionMap_t m_mapOperationDefinitions;
  2542. // Paint Kit defintions
  2543. ItemPaintKitMap_t m_mapItemPaintKits;
  2544. // Revolving loot lists.
  2545. CUtlMap<int, const char*> m_mapRevolvingLootLists;
  2546. // Contains the list of loot lists.
  2547. LootListDefinitionMap_t m_mapLootLists;
  2548. // List of events that award items based on time played
  2549. CUtlVector<CTimedItemRewardDefinition> m_vecTimedRewards;
  2550. // list of items that will be awarded from achievements
  2551. CUtlDict< AchievementAward_t *, int > m_dictAchievementRewards;
  2552. CUtlMap< uint32, AchievementAward_t * > m_mapAchievementRewardsByData;
  2553. #ifdef GC_DLL
  2554. // list of random attribute templates
  2555. CUtlDict< random_attrib_t * > m_dictRandomAttributeTemplates;
  2556. #endif // GC_DLL
  2557. // Contains information for attribute attached particle systems
  2558. CUtlMap<int, attachedparticlesystem_t > m_mapAttributeControlledParticleSystems;
  2559. CUtlVector< int > m_vecAttributeControlledParticleSystemsCosmetics;
  2560. CUtlVector< int > m_vecAttributeControlledParticleSystemsWeapons;
  2561. CUtlVector< int > m_vecAttributeControlledParticleSystemsTaunts;
  2562. // Contains information on which equip regions conflict with each other regions and how to
  2563. // test for overlap.
  2564. EquipRegionsList_t m_vecEquipRegionsList;
  2565. // Contains information about prefab KeyValues blocks that be can referenced elsewhere
  2566. // in the schema.
  2567. PrefabMap_t m_mapDefinitionPrefabs;
  2568. // Contains runtime color information, looked-up by name.
  2569. ColorDefinitionsList_t m_vecColorDefs;
  2570. // Contains information about: a) every bodygroup that appears anywhere in the schema, and
  2571. // b) whether they default to on or off.
  2572. BodygroupStateMap_t m_mapDefaultBodygroupState;
  2573. // Various definitions can have any number of unique tags associated with them.
  2574. EconTagDict_t m_dictTags;
  2575. #ifdef GC_DLL
  2576. // Information about our periodic score accumulators.
  2577. PeriodicScoreTypeList_t m_vecPeriodicScoreTypes;
  2578. #endif // GC_DLL
  2579. // List of item leveling data.
  2580. KillEaterScoreMap_t m_mapKillEaterScoreTypes;
  2581. SchemaStringTableDict_t m_dictStringTable;
  2582. typedef CUtlMap< item_definition_index_t, item_definition_index_t, item_definition_index_t > CommunityMarketDefinitionRemapMap_t;
  2583. CommunityMarketDefinitionRemapMap_t m_mapCommunityMarketDefinitionIndexRemap;
  2584. #ifdef CLIENT_DLL
  2585. // Steam-package-ID-to-localization-token map, used for modifying tooltips in the store.
  2586. typedef CUtlMap< uint32, const char * > SteamPackageLocalizationTokenMap_t;
  2587. SteamPackageLocalizationTokenMap_t m_mapSteamPackageLocalizationTokens;
  2588. #endif // CLIENT_DLL
  2589. LevelBlockDict_t m_vecItemLevelingData;
  2590. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  2591. // Contains Armory data key->localization string mappings
  2592. ArmoryStringDict_t m_dictArmoryItemTypesDataStrings;
  2593. ArmoryStringDict_t m_dictArmoryItemClassesDataStrings;
  2594. ArmoryStringDict_t m_dictArmoryAttributeDataStrings;
  2595. ArmoryStringDict_t m_dictArmoryItemDataStrings;
  2596. // Used for delaying the parsing of the item schema until its safe to swap out the back end data.
  2597. IDelayedSchemaData *m_pDelayedSchemaData;
  2598. #elif defined(GC_DLL)
  2599. // GC only
  2600. CUtlVector< CExperimentDefinition > m_vecExperiments;
  2601. CUtlMap< AppId_t, CForeignAppImports *> m_mapForeignImports;
  2602. CUtlVector< AppId_t > m_vecForeignApps;
  2603. #endif
  2604. CUtlVector< CEconItemDefinition * > m_vecBundles; // A cached list of all bundles
  2605. };
  2606. #ifdef GC_DLL
  2607. void PerformIncrementKillEaterAttributeScore( CEconUserSession *pLockedOwnerSession, CEconItem *pItem, uint32 unEventType, uint32 unIncrementCount, bool bGCOrigination, GCSDK::CSharedObjectTransactionEx *pTransaction );
  2608. #endif // GC_DLL
  2609. extern CEconItemSchema & GEconItemSchema();
  2610. //-----------------------------------------------------------------------------
  2611. // CSchemaFieldHandle
  2612. //-----------------------------------------------------------------------------
  2613. template < class T >
  2614. class CSchemaFieldHandle
  2615. {
  2616. public:
  2617. explicit CSchemaFieldHandle( const char *szName )
  2618. : m_szName( szName )
  2619. {
  2620. m_pRef = GetTypedRef();
  2621. m_unSchemaGeneration = GEconItemSchema().GetResetCount();
  2622. #if _DEBUG
  2623. m_unVersion_Debug = GEconItemSchema().GetVersion();
  2624. #endif
  2625. }
  2626. operator const T *( void ) const
  2627. {
  2628. uint32 unSchemaGeneration = GEconItemSchema().GetResetCount();
  2629. if ( m_unSchemaGeneration != unSchemaGeneration )
  2630. {
  2631. m_pRef = GetTypedRef();
  2632. m_unSchemaGeneration = unSchemaGeneration;
  2633. #if _DEBUG
  2634. m_unVersion_Debug = GEconItemSchema().GetVersion();
  2635. #endif
  2636. }
  2637. #if _DEBUG
  2638. Assert( m_unVersion_Debug == GEconItemSchema().GetVersion() );
  2639. #endif
  2640. return m_pRef;
  2641. }
  2642. const T *operator->( void ) const
  2643. {
  2644. return static_cast<const T *>( *this );
  2645. }
  2646. const char *GetName( void ) const
  2647. {
  2648. return m_szName;
  2649. }
  2650. private:
  2651. const T *GetTypedRef() const;
  2652. private:
  2653. const char *m_szName;
  2654. mutable const T *m_pRef;
  2655. mutable uint32 m_unSchemaGeneration;
  2656. #if _DEBUG
  2657. mutable uint32 m_unVersion_Debug;
  2658. #endif
  2659. };
  2660. template < >
  2661. inline const CEconColorDefinition *CSchemaFieldHandle<CEconColorDefinition>::GetTypedRef( void ) const
  2662. {
  2663. return GEconItemSchema().GetColorDefinitionByName( m_szName );
  2664. }
  2665. template < >
  2666. inline const CEconItemAttributeDefinition *CSchemaFieldHandle<CEconItemAttributeDefinition>::GetTypedRef( void ) const
  2667. {
  2668. return GEconItemSchema().GetAttributeDefinitionByName( m_szName );
  2669. }
  2670. template < >
  2671. inline const CEconItemDefinition *CSchemaFieldHandle<CEconItemDefinition>::GetTypedRef( void ) const
  2672. {
  2673. return GEconItemSchema().GetItemDefinitionByName( m_szName );
  2674. }
  2675. template < >
  2676. inline const CEconLootListDefinition *CSchemaFieldHandle<CEconLootListDefinition>::GetTypedRef( void ) const
  2677. {
  2678. return GEconItemSchema().GetLootListByName( m_szName );
  2679. }
  2680. template < >
  2681. inline const attachedparticlesystem_t *CSchemaFieldHandle<attachedparticlesystem_t>::GetTypedRef( void ) const
  2682. {
  2683. return GEconItemSchema().FindAttributeControlledParticleSystem( m_szName );
  2684. }
  2685. typedef CSchemaFieldHandle<CEconColorDefinition> CSchemaColorDefHandle;
  2686. typedef CSchemaFieldHandle<CEconItemAttributeDefinition> CSchemaAttributeDefHandle;
  2687. typedef CSchemaFieldHandle<CEconItemDefinition> CSchemaItemDefHandle;
  2688. typedef CSchemaFieldHandle<CEconLootListDefinition> CSchemaLootListDefHandle;
  2689. typedef CSchemaFieldHandle<attachedparticlesystem_t> CSchemaParticleHandle;
  2690. struct steam_market_gc_identifier_t
  2691. {
  2692. item_definition_index_t m_unDefIndex;
  2693. uint8 m_unQuality;
  2694. bool operator<( const struct steam_market_gc_identifier_t& b ) const
  2695. {
  2696. return (m_unDefIndex < b.m_unDefIndex)
  2697. || ((m_unDefIndex == b.m_unDefIndex) && (m_unQuality < b.m_unQuality));
  2698. }
  2699. };
  2700. // Implementation reliant on earlier class content.
  2701. inline const CEconItemAttributeDefinition *static_attrib_t::GetAttributeDefinition() const
  2702. {
  2703. return GEconItemSchema().GetAttributeDefinition( iDefIndex );
  2704. }
  2705. inline const ISchemaAttributeType *static_attrib_t::GetAttributeType() const
  2706. {
  2707. const CEconItemAttributeDefinition *pAttrDef = GetAttributeDefinition();
  2708. if ( !pAttrDef )
  2709. return NULL;
  2710. return pAttrDef->GetAttributeType();
  2711. }
  2712. // Utility function to convert datafile strings to ints.
  2713. int StringFieldToInt( const char *szValue, const char **pValueStrings, int iNumStrings, bool bDontAssert = false );
  2714. int StringFieldToInt( const char *szValue, const CUtlVector<const char *>& vecValueStrings, bool bDontAssert = false );
  2715. #ifdef GC_DLL
  2716. // Global econ-level helper functionality.
  2717. EUniverse GetUniverse();
  2718. bool BYieldingGetChangedItemDefinitions( int iComparisonColumn, CUtlVector<item_definition_index_t>& out_vecChangedDefIndices );
  2719. bool BYieldingUpdateItemDefinitionStateHashValue( GCSDK::CSQLAccess& sqlAccess, item_definition_index_t unItemDef, int iUpdatedColumn );
  2720. #endif // GC_DLL
  2721. //-----------------------------------------------------------------------------
  2722. // Purpose:
  2723. //-----------------------------------------------------------------------------
  2724. class CAttributeLineItemLootList : public IEconLootList
  2725. {
  2726. public:
  2727. static CSchemaAttributeDefHandle s_pAttrDef_RandomDropLineItems[4];
  2728. #ifdef GC_DLL
  2729. static CSchemaAttributeDefHandle s_pAttrDef_RandomDropLineItemUnusualChance;
  2730. static CSchemaAttributeDefHandle s_pAttrDef_RandomDropLineItemUnusualList;
  2731. #endif // GC_DLL
  2732. static CSchemaAttributeDefHandle s_pAttrDef_RandomDropLineItemFooterDesc;
  2733. public:
  2734. CAttributeLineItemLootList( const IEconItemInterface *pEconItem )
  2735. : m_pEconItem( pEconItem )
  2736. {
  2737. //
  2738. }
  2739. virtual void EnumerateUserFacingPotentialDrops( IEconLootListIterator *pIt ) const OVERRIDE;
  2740. virtual bool BPublicListContents() const OVERRIDE { return true; } // any attribute data that clients have is public to them
  2741. virtual const char *GetLootListHeaderLocalizationKey() const OVERRIDE;
  2742. virtual const char *GetLootListFooterLocalizationKey() const OVERRIDE;
  2743. virtual const char *GetLootListCollectionReference() const OVERRIDE;
  2744. #ifdef GC_DLL
  2745. MUST_CHECK_RETURN virtual bool BGenerateSingleRollRandomItems( const CEconGameAccount *pGameAccount, bool bFreeAccount, CUtlVector<CEconItem *> *out_pvecItems, const CUtlVector< item_definition_index_t > *pVecAvoidItemDefs = NULL ) const OVERRIDE;
  2746. #endif // GC_DLL
  2747. private:
  2748. const IEconItemInterface *m_pEconItem;
  2749. };
  2750. void MergeDefinitionPrefab( KeyValues *pKVWriteItem, KeyValues *pKVSourceItem );
  2751. #endif //ECONITEMSCHEMA_H