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.

75 lines
2.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: EconItemFactory: Manages rolling for items requested by the game server
  4. //
  5. //=============================================================================
  6. #ifndef ECONITEMFACTORY_H
  7. #define ECONITEMFACTORY_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. class CEconItem;
  12. class CEconGameAccount;
  13. namespace GCSDK
  14. {
  15. class CGCSharedObjectCache;
  16. }
  17. #include "game_item_schema.h"
  18. //-----------------------------------------------------------------------------
  19. // CEconItemFactory
  20. // Factory responsible for rolling random items
  21. //-----------------------------------------------------------------------------
  22. class CEconItemFactory
  23. {
  24. public:
  25. CEconItemFactory( );
  26. // Gets a pointer to the underlying item schema the factory is using
  27. GameItemSchema_t &GetSchema() { return m_schema; }
  28. // Create a random item based on the incoming item selection criteria
  29. CEconItem *CreateRandomItem( const CEconGameAccount *pGameAccount, const CItemSelectionCriteria &criteria );
  30. // Create an item from a specific definition index
  31. CEconItem *CreateSpecificItem( const CEconGameAccount *pGameAccount, item_definition_index_t unDefinitionIndex );
  32. CEconItem *CreateSpecificItem( GCSDK::CGCSharedObjectCache *pUserSOCache, item_definition_index_t unDefinitionIndex )
  33. {
  34. return CreateSpecificItem( pUserSOCache->GetSingleton<CEconGameAccount>(), unDefinitionIndex );
  35. }
  36. uint64 GetNextID() { Assert( m_bIsInitialized ); return m_ulNextObjID++; }
  37. bool BYieldingInit();
  38. bool BIsInitialized() { return m_bIsInitialized; }
  39. #ifdef DBGFLAG_VALIDATE
  40. virtual void Validate( CValidator &validator, const char *pchName )
  41. {
  42. VALIDATE_SCOPE();
  43. ValidateObj( m_schema );
  44. }
  45. #endif // DBGFLAG_VALIDATE
  46. void ApplyStaticAttributeToItem( CEconItem *pItem, const static_attrib_t& staticAttrib, const CEconGameAccount *pGameAccount ) const;
  47. const CEconItemDefinition *RollItemDefinition( const CItemSelectionCriteria &criteria ) const;
  48. private:
  49. bool BAddGCGeneratedAttributesToItem( const CEconGameAccount *pGameAccount, CEconItem *pItem ) const;
  50. private:
  51. // The schema this factory uses to create items
  52. GameItemSchema_t m_schema;
  53. // the next item ID to give out
  54. itemid_t m_ulNextObjID;
  55. bool m_bIsInitialized;
  56. };
  57. #endif //ECONITEMFACTORY_H