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.

82 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Handle stats game events and route them to the appropriate place
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "KeyValues.h"
  10. #include "dod_statmgr.h"
  11. #include "dod_player.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. CDODStatManager::CDODStatManager()
  15. {
  16. }
  17. bool CDODStatManager::Init()
  18. {
  19. ListenForGameEvent( "player_death" );
  20. ListenForGameEvent( "dod_stats_weapon_attack" );
  21. ListenForGameEvent( "dod_stats_player_damage" );
  22. ListenForGameEvent( "dod_stats_player_killed" );
  23. return BaseClass::Init();
  24. }
  25. void CDODStatManager::FireGameEvent( IGameEvent *event )
  26. {
  27. const char *eventName = event->GetName();
  28. if ( FStrEq( eventName, "dod_stats_weapon_attack" ) )
  29. {
  30. CDODPlayer *pAttacker = ToDODPlayer( UTIL_PlayerByUserId( event->GetInt("attacker") ) );
  31. Assert( pAttacker );
  32. if ( pAttacker )
  33. pAttacker->Stats_WeaponFired( event->GetInt("weapon") );
  34. }
  35. else if ( FStrEq( eventName, "dod_stats_player_damage" ) )
  36. {
  37. CDODPlayer *pAttacker = ToDODPlayer( UTIL_PlayerByUserId( event->GetInt("attacker") ) );
  38. int iVictimID = event->GetInt("victim");
  39. CDODPlayer *pVictim = ToDODPlayer( UTIL_PlayerByUserId( iVictimID ) );
  40. // discard damage to teammates or to yourself
  41. if ( ( pAttacker == NULL ) || ( pVictim->GetTeamNumber() == pAttacker->GetTeamNumber() ) )
  42. return;
  43. int weaponID = event->GetInt("weapon");
  44. int iDamage = event->GetInt("damage");
  45. int iDamageGiven = event->GetInt("damage_given");
  46. float flDistance = event->GetFloat("distance");
  47. int hitgroup = event->GetInt("hitgroup");
  48. pAttacker->Stats_WeaponHit( pVictim, weaponID, iDamage, iDamageGiven, hitgroup, flDistance );
  49. pVictim->Stats_HitByWeapon( pAttacker, weaponID, iDamage, iDamageGiven, hitgroup );
  50. }
  51. else if ( FStrEq( eventName, "dod_stats_player_killed" ) )
  52. {
  53. int iVictimID = event->GetInt("victim");
  54. CDODPlayer *pVictim = ToDODPlayer( UTIL_PlayerByUserId( iVictimID ) );
  55. CDODPlayer *pAttacker = ToDODPlayer( UTIL_PlayerByUserId( event->GetInt("attacker") ) );
  56. // discard kills to teammates or to yourself
  57. if ( ( pAttacker == NULL ) || ( pVictim->GetTeamNumber() == pAttacker->GetTeamNumber() ) )
  58. return;
  59. int weaponID = event->GetInt("weapon");
  60. pAttacker->Stats_KilledPlayer( pVictim, weaponID );
  61. pVictim->Stats_KilledByPlayer( pAttacker, weaponID );
  62. }
  63. }
  64. CDODStatManager g_DODStatMgr;