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.

97 lines
2.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "c_tf_buff_banner.h"
  8. #include "c_tf_player.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. IMPLEMENT_NETWORKCLASS_ALIASED( TFBuffBanner, DT_TFBuffBanner )
  12. BEGIN_NETWORK_TABLE( C_TFBuffBanner, DT_TFBuffBanner )
  13. END_NETWORK_TABLE()
  14. C_TFBuffBanner::C_TFBuffBanner()
  15. {
  16. m_flDetachTime = 0.f;
  17. m_iBuffType = 0;
  18. }
  19. // -----------------------------------------------------------------------------
  20. // Purpose:
  21. // -----------------------------------------------------------------------------
  22. void CTFBuffBanner::NotifyBoneAttached( C_BaseAnimating* attachTarget )
  23. {
  24. if ( m_hBuffItem )
  25. {
  26. if ( attachTarget != m_hBuffItem->GetOwner() )
  27. {
  28. // We are being moved to a corpse. Let our associated buff item know.
  29. m_hBuffItem->SetBanner( NULL );
  30. }
  31. else
  32. {
  33. float flDuration = 10.f; // 10 is default
  34. CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( attachTarget, flDuration, mod_buff_duration );
  35. m_flDetachTime = gpGlobals->curtime + flDuration;
  36. SetNextClientThink( CLIENT_THINK_ALWAYS );
  37. }
  38. }
  39. BaseClass::NotifyBoneAttached( attachTarget );
  40. }
  41. //-----------------------------------------------------------------------------
  42. // Purpose:
  43. //-----------------------------------------------------------------------------
  44. void CTFBuffBanner::ClientThink( void )
  45. {
  46. BaseClass::ClientThink();
  47. // DO THIS AFTER BASECLASS::CLIENTTHINK
  48. if ( !m_pAttachedTo || !m_hBuffItem )
  49. {
  50. if ( m_hBuffItem )
  51. {
  52. m_hBuffItem->SetBanner( NULL );
  53. }
  54. Release();
  55. return;
  56. }
  57. // Parachute's never expire
  58. if ( m_iBuffType == EParachute )
  59. {
  60. m_flDetachTime = gpGlobals->curtime + 10.0f;
  61. }
  62. // Normal Banners
  63. if ( m_pAttachedTo )
  64. {
  65. if ( gpGlobals->curtime > m_flDetachTime || !m_hBuffItem )
  66. {
  67. // Destroy us automatically after a period of time.
  68. if ( m_hBuffItem )
  69. {
  70. m_hBuffItem->SetBanner( NULL );
  71. }
  72. Release();
  73. }
  74. else if ( m_pAttachedTo->IsEffectActive( EF_NODRAW ) && !IsEffectActive( EF_NODRAW ) )
  75. {
  76. AddEffects( EF_NODRAW );
  77. UpdateVisibility();
  78. }
  79. else if ( !m_pAttachedTo->IsEffectActive( EF_NODRAW ) && IsEffectActive( EF_NODRAW ) && (m_pAttachedTo != C_BasePlayer::GetLocalPlayer()) )
  80. {
  81. RemoveEffects( EF_NODRAW );
  82. UpdateVisibility();
  83. }
  84. }
  85. }