Counter Strike : Global Offensive Source Code
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
5.4 KiB

  1. //====== Copyright Valve Corporation, All rights reserved. =================
  2. //
  3. // Achievements (aka Medals) are divided into categories. Progress towards
  4. // completing a category of medals gives the player a higher 'rank'. Player
  5. // rank is sent to the server for display on the scoreboard.
  6. //
  7. // Ranks, Medals and medal-relevant gamestats earned during a round are recorded
  8. // here for the purpose of displaying progress towards ranks to the player.
  9. //
  10. //=============================================================================
  11. #if !defined CS_PLAYER_RANK_MGR_H
  12. #define CS_PLAYER_RANK_MGR_H
  13. #if defined( COMPILER_MSVC )
  14. #pragma once
  15. #endif
  16. #include "matchmaking/imatchframework.h"
  17. #include "GameEventListener.h"
  18. #include "cs_player_rank_shared.h"
  19. #include "cs_gamestats_shared.h"
  20. #if defined ( _GAMECONSOLE )
  21. #include "matchmaking/cstrike15/imatchext_cstrike15.h"
  22. #include "cs_client_gamestats.h"
  23. #endif
  24. class KeyValues;
  25. class CBaseAchievement;
  26. class CAchievement_StatGoal;
  27. // Structs for recording rank-relevent events that occur during a round
  28. struct RankIncreasedEvent_t
  29. {
  30. RankIncreasedEvent_t( CBaseAchievement* pAch, MedalCategory_t cat )
  31. :m_pAchievement( pAch ), m_category( cat ) {}
  32. CBaseAchievement *m_pAchievement;
  33. MedalCategory_t m_category;
  34. };
  35. struct MedalEarnedEvent_t
  36. {
  37. MedalEarnedEvent_t( CBaseAchievement* pAch, MedalCategory_t cat )
  38. :m_pAchievement( pAch ), m_category( cat ) {}
  39. CBaseAchievement *m_pAchievement;
  40. MedalCategory_t m_category;
  41. };
  42. struct MedalStatEvent_t
  43. {
  44. MedalStatEvent_t( CBaseAchievement* pAch, MedalCategory_t category, CSStatType_t type )
  45. :m_pAchievement( pAch ), m_category( category ), m_StatType( type ) {}
  46. CBaseAchievement *m_pAchievement;
  47. MedalCategory_t m_category;
  48. CSStatType_t m_StatType;
  49. };
  50. class CPlayerRankManager : public CAutoGameSystem, public CGameEventListener, public IMatchEventsSink
  51. {
  52. public:
  53. CPlayerRankManager();
  54. ~CPlayerRankManager();
  55. virtual bool Init();
  56. virtual void Shutdown();
  57. virtual void LevelInitPostEntity();
  58. bool HasBuiltMedalCategories( void ) const;
  59. // Get rank ups and medals earned during the current round. These lists are reset on round start.
  60. const CUtlVector<MedalEarnedEvent_t>& GetMedalsEarnedThisRound( void ) const;
  61. const CUtlVector<RankIncreasedEvent_t>& GetRankIncreasesThisRound( void ) const;
  62. // Builds a list of progress based achievements (goal > 1) who had their dependant gamestat increased this round.
  63. void GetMedalStatsEarnedThisRound( CUtlVector<MedalStatEvent_t>& ) const;
  64. // Number of achievements compeleted by the local player in the given category.
  65. int CountAchievedInCategory( MedalCategory_t category ) const;
  66. // Total count of medals in a category
  67. int GetTotalMedalsInCategory( MedalCategory_t category ) const;
  68. // Number of medals required to be awarded a given rank
  69. int GetMinMedalsForRank( MedalCategory_t category, MedalRank_t rank ) const;
  70. // Blindly sets the rank for the given category
  71. void SetRankForCategory( MedalCategory_t category, int nRank ) { m_rank[category] = (MedalRank_t)nRank; }
  72. // Calculates the player's rank for a given category and returns it. Does not set the internal rank variable.
  73. MedalRank_t CalculateRankForCategory( MedalCategory_t category ) const;
  74. const char *GetMedalCatagoryName( MedalCategory_t category );
  75. const char *GetMedalCatagoryRankName( int nRank );
  76. void NoteEloBracketChanged( int iOldBracket, int iNewBracket );
  77. // Elo is special: UI display code will explicitly mark when we've shown the
  78. // 'elo changed' update to the user beacuse we don't want to miss displaying this update.
  79. int GetEloBracketChange( int &iOutNewEloBracket );
  80. void ResetRecordedEloBracketChange( void );
  81. #if defined( _GAMECONSOLE )
  82. // On consoles, this object holds the elo brackets instead of the GC.
  83. int Console_GetEloBracket( ELOGameType_t game_mode, PlayerELOBracketInfo_t *pOutBracket = NULL );
  84. bool Console_SetEloBracket( ELOGameType_t game_mode, uint8 display_bracket, uint8 prev_bracket, uint8 num_games_in_bracket );
  85. bool Console_SetEloBracket( ELOGameType_t game_mode, const PlayerELOBracketInfo_t& bracket );
  86. void ServerRequestBracketInfo( ELOGameType_t game_mode );
  87. #endif
  88. // Debug spew.
  89. void PrintRankProgressThisRound() const;
  90. // IMatchEventsSink functions
  91. public:
  92. virtual void OnEvent( KeyValues *pEvent ) OVERRIDE;
  93. private:
  94. struct MedalCategoryInfo_t
  95. {
  96. int m_totalInCategory;
  97. int m_minCountForRank[MEDAL_RANK_COUNT];
  98. };
  99. void FireGameEvent( IGameEvent *event );
  100. void SendRankDataToServer( void );
  101. void BuildMedalCategories( void );
  102. void RecalculateRanks( void );
  103. void OnRoundStart();
  104. void OnAchievementEarned( int achievementID );
  105. void OnSeasonCoinLeveledUp( int iCategory = MEDAL_CATEGORY_NONE, int iRank = MEDAL_RANK_NONE );
  106. bool CheckCategoryRankLevelUp( int iCategory, int iRank );
  107. void CheckForStatProgress();
  108. // Local player's rank data.
  109. MedalRank_t m_rank[MEDAL_CATEGORY_COUNT];
  110. // Info about each medal category.
  111. MedalCategoryInfo_t m_categoryInfo[MEDAL_CATEGORY_COUNT];
  112. // List of achievements assigned to each category.
  113. CUtlVector<CBaseAchievement*> m_medalCategoryList[MEDAL_CATEGORY_COUNT];
  114. // Per-round rank relevant events.
  115. CUtlVector<RankIncreasedEvent_t> m_RankIncreases;
  116. CUtlVector<MedalEarnedEvent_t> m_MedalsEarned;
  117. // List of stat based achievement
  118. CUtlVector<CAchievement_StatGoal*> m_StatBasedAchievements;
  119. int m_iEloBracketDelta;
  120. int m_iNewEloBracket;
  121. bool m_bMedalCategoriesBuilt;
  122. };
  123. extern CPlayerRankManager g_PlayerRankManager;
  124. const char* GetLocTokenForStatId( const CSStatType_t id );
  125. #endif