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.

156 lines
4.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef QUEST_OBJECTIVE_MANAGER_H
  8. #define QUEST_OBJECTIVE_MANAGER_H
  9. #include "GameEventListener.h"
  10. #include "econ_item_constants.h"
  11. #include "econ_item_inventory.h"
  12. #include "tf_quest_restriction.h"
  13. #include "econ_dynamic_recipe.h"
  14. #include "shared_object_tracker.h"
  15. #ifdef GAME_DLL
  16. #include "tf_player.h"
  17. #else
  18. #include "c_tf_player.h"
  19. #endif
  20. #if defined( _WIN32 )
  21. #pragma once
  22. #endif
  23. using namespace GCSDK;
  24. class CQuestItemTracker;
  25. class CBaseQuestObjectiveTracker : public CTFQuestEvaluator
  26. {
  27. public:
  28. DECLARE_CLASS( CBaseQuestObjectiveTracker, CBaseQuestObjectiveTracker )
  29. CBaseQuestObjectiveTracker( const CTFQuestObjectiveDefinition* pObjective, CQuestItemTracker* pParent );
  30. virtual ~CBaseQuestObjectiveTracker();
  31. uint32 GetObjectiveDefIndex() const { return m_nObjectiveDefIndex; }
  32. // CTFQuestConditionEvaluator specific
  33. virtual const char *GetConditionName() const OVERRIDE { return "tracker"; }
  34. virtual bool IsValidForPlayer( const CTFPlayer *pOwner, InvalidReasonsContainer_t& invalidReasons ) const;
  35. virtual const CTFPlayer *GetQuestOwner() const OVERRIDE;
  36. virtual void EvaluateCondition( CTFQuestEvaluator *pSender, int nScore ) OVERRIDE;
  37. virtual void ResetCondition() OVERRIDE;
  38. bool UpdateConditions();
  39. protected:
  40. const CTFPlayer* GetTrackedPlayer() const;
  41. void IncrementCount( int nIncrementValue );
  42. uint32 m_nObjectiveDefIndex;
  43. private:
  44. CTFQuestEvaluator *m_pEvaluator;
  45. CQuestItemTracker *m_pParent;
  46. };
  47. class CQuestItemTracker : public CBaseSOTracker
  48. {
  49. public:
  50. CQuestItemTracker( const CSharedObject* pItem, CSteamID SteamIDOwner, CSOTrackerManager* pManager );
  51. ~CQuestItemTracker();
  52. virtual void OnUpdate() OVERRIDE;
  53. virtual void OnRemove() OVERRIDE;
  54. void UpdatePointsFromSOItem();
  55. const CBaseQuestObjectiveTracker* FindTrackerForDefIndex( uint32 nDefIndex ) const;
  56. inline const CUtlVector< const CBaseQuestObjectiveTracker* >& GetTrackers() const { return m_vecObjectiveTrackers; }
  57. uint32 GetEarnedStandardPoints() const;
  58. uint32 GetEarnedBonusPoints() const;
  59. const CEconItem* GetItem() const { return static_cast< const CEconItem* >( m_pSObject ); }
  60. void IncrementCount( uint32 nIncrementValue, const CQuestObjectiveDefinition* pObjective );
  61. virtual void CommitChangesToDB() OVERRIDE;
  62. int IsValidForPlayer( const CTFPlayer *pOwner, InvalidReasonsContainer_t& invalidReasons ) const;
  63. #ifdef CLIENT_DLL
  64. void UpdateFromServer( uint32 nStandardPoints, uint32 nBonusPoints );
  65. #else
  66. void SendUpdateToClient( const CQuestObjectiveDefinition* pObjective );
  67. #endif
  68. #if defined( DEBUG ) || defined( STAGING_ONLY )
  69. void DBG_CompleteQuest();
  70. #endif
  71. virtual void Spew() const OVERRIDE;
  72. private:
  73. bool DoesObjectiveNeedToBeTracked( const CQuestObjectiveDefinition* pObjective ) const;
  74. #ifdef GAME_DLL
  75. uint32 m_nStartingStandardPoints;
  76. uint32 m_nStartingBonusPoints;
  77. #endif
  78. uint32 m_nStandardPoints;
  79. uint32 m_nBonusPoints;
  80. const CEconItem* m_pItem;
  81. CUtlVector< const CBaseQuestObjectiveTracker* > m_vecObjectiveTrackers;
  82. };
  83. // A class to handle the creation and deletion of quest objective trackers. Automatically
  84. // subscribes to the local player's SOCache and will subscribe to any connecting players'
  85. // SOCaches when they connect.
  86. class CQuestObjectiveManager : public CSOTrackerManager
  87. {
  88. public:
  89. DECLARE_CLASS( CQuestObjectiveManager, CSOTrackerManager )
  90. CQuestObjectiveManager();
  91. virtual ~CQuestObjectiveManager();
  92. virtual SOTrackerMap_t::KeyType_t GetKeyForObjectTracker( const CSharedObject* pItem, CSteamID steamIDOwner ) OVERRIDE;
  93. #ifdef CLIENT_DLL
  94. void UpdateFromServer( itemid_t nID, uint32 nStandardPoints, uint32 nBonusPoints );
  95. #endif
  96. #if defined( DEBUG ) || defined( STAGING_ONLY )
  97. void DBG_CompleteQuests();
  98. #endif
  99. private:
  100. #ifdef GAME_DLL
  101. void SendMessageForCommit( const ::google::protobuf::Message* pProtoMessage ) const;
  102. #endif
  103. virtual int GetType() const OVERRIDE { return CEconItem::k_nTypeID; }
  104. virtual const char* GetName() const { return "QuestObjectiveManager"; }
  105. virtual CFmtStr GetDebugObjectDescription( const CSharedObject* pItem ) const;
  106. virtual CBaseSOTracker* AllocateNewTracker( const CSharedObject* pItem, CSteamID steamIDOwner, CSOTrackerManager* pManager ) const OVERRIDE;
  107. virtual ::google::protobuf::Message* AllocateNewProtoMessage() const OVERRIDE;
  108. virtual void OnCommitRecieved( const ::google::protobuf::Message* pProtoMsg ) OVERRIDE;
  109. virtual bool ShouldTrackObject( const CSteamID & steamIDOwner, const CSharedObject *pObject ) const OVERRIDE;
  110. virtual int CompareRecords( const ::google::protobuf::Message* pNewProtoMsg, const ::google::protobuf::Message* pExistingProtoMsg ) const OVERRIDE;
  111. };
  112. CQuestObjectiveManager* QuestObjectiveManager();
  113. #endif // QUEST_OBJECTIVE_MANAGER_H