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.

164 lines
4.2 KiB

  1. //========= Copyright � 1996-2009, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Healthshot Item, belt item
  4. //
  5. // $NoKeywords: $
  6. //=====================================================================================//
  7. #include "cbase.h"
  8. #include "item_healthshot.h"
  9. #include "cs_gamerules.h"
  10. #include "econ_entity_creation.h"
  11. #if defined( CLIENT_DLL )
  12. #include "c_cs_player.h"
  13. #else
  14. #include "cs_player.h"
  15. #endif // CLIENT_DLL
  16. // NOTE: This has to be the last file included!
  17. #include "tier0/memdbgon.h"
  18. #define HEALTHSHOT_INJECT_TIME 1.65f
  19. IMPLEMENT_NETWORKCLASS_ALIASED( Item_Healthshot, DT_Item_Healthshot )
  20. BEGIN_NETWORK_TABLE( CItem_Healthshot, DT_Item_Healthshot )
  21. END_NETWORK_TABLE()
  22. BEGIN_PREDICTION_DATA( CItem_Healthshot )
  23. END_PREDICTION_DATA()
  24. LINK_ENTITY_TO_CLASS_ALIASED( weapon_healthshot, Item_Healthshot );
  25. PRECACHE_WEAPON_REGISTER( weapon_healthshot );
  26. // #ifndef CLIENT_DLL
  27. // BEGIN_DATADESC( CItem_Healthshot )
  28. // END_DATADESC()
  29. // #endif
  30. ConVar healthshot_health( "healthshot_health", "50", FCVAR_CHEAT | FCVAR_REPLICATED );
  31. void CItem_Healthshot::WeaponIdle()
  32. {
  33. if (m_flTimeWeaponIdle > gpGlobals->curtime)
  34. return;
  35. SendWeaponAnim( ACT_VM_IDLE );
  36. SetWeaponIdleTime( gpGlobals->curtime + 20 );
  37. }
  38. void CItem_Healthshot::Precache( void )
  39. {
  40. //PrecacheScriptSound( "Healthshot.Shot" );
  41. BaseClass::Precache();
  42. }
  43. bool CItem_Healthshot::CanPrimaryAttack( void )
  44. {
  45. CCSPlayer *pPlayer = ToCSPlayer( GetPlayerOwner() );
  46. if ( pPlayer == NULL )
  47. return false;
  48. return CanUseOnSelf( pPlayer );
  49. }
  50. bool CItem_Healthshot::CanUseOnSelf( CCSPlayer *pPlayer )
  51. {
  52. if ( !pPlayer )
  53. return false;
  54. if ( pPlayer->GetHealth() >= pPlayer->GetMaxHealth() )
  55. {
  56. #ifndef CLIENT_DLL
  57. ClientPrint( pPlayer, HUD_PRINTCENTER, "#SFUI_Healthshot_AlreadyAtMax" );
  58. #endif
  59. return false;
  60. }
  61. return true;
  62. }
  63. void CItem_Healthshot::DropHealthshot( void )
  64. {
  65. #ifndef CLIENT_DLL
  66. CCSPlayer *pPlayer = ToCSPlayer( GetPlayerOwner() );
  67. if ( !pPlayer )
  68. return;
  69. int iAmount = pPlayer->GetAmmoCount( GetPrimaryAmmoType() );
  70. if ( iAmount <= 1 )
  71. {
  72. pPlayer->CSWeaponDrop( this, false, true );
  73. return;
  74. }
  75. else
  76. {
  77. pPlayer->RemoveAmmo( 1, AMMO_TYPE_HEALTHSHOT );
  78. CItem_Healthshot *pHealth = static_cast< CItem_Healthshot * >( CreateEntityByName( "weapon_healthshot" ) );
  79. if ( pHealth )
  80. {
  81. Vector vecWeaponThrowFromPos = pPlayer->EyePosition();
  82. QAngle angWeaponThrowFromAngle = pPlayer->EyeAngles();
  83. Vector vForward;
  84. AngleVectors(angWeaponThrowFromAngle, &vForward, NULL, NULL);
  85. vecWeaponThrowFromPos = vecWeaponThrowFromPos + (vForward * 100);
  86. //NDebugOverlay::Box( vecWeaponThrowFromPos, Vector( 10, 10, 10 ), Vector( -10, -10, -10 ), 255, 0, 0, 200, 3 );
  87. DispatchSpawn( pHealth );
  88. // set it non-solid because it hits itself during the trace when trying to throw it
  89. pHealth->SetSolidFlags( FSOLID_NOT_SOLID );
  90. pHealth->SetMoveCollide( MOVECOLLIDE_FLY_BOUNCE );
  91. pPlayer->Weapon_Drop( pHealth, &vecWeaponThrowFromPos, NULL );
  92. pHealth->SetSolidFlags( FSOLID_NOT_STANDABLE | FSOLID_TRIGGER | FSOLID_USE_TRIGGER_BOUNDS );
  93. pHealth->SetPreviousOwner( pPlayer );
  94. pHealth->m_flDroppedAtTime = gpGlobals->curtime;
  95. pHealth->AddPriorOwner( pPlayer );
  96. }
  97. }
  98. #endif
  99. }
  100. //--------------------------------------------------------------------------------------------------------
  101. void CItem_Healthshot::OnStartUse( CCSPlayer *pPlayer )
  102. {
  103. SetWeaponIdleTime( gpGlobals->curtime + 20 ); // don't fidget for a bit
  104. BaseClass::OnStartUse( pPlayer );
  105. }
  106. #ifndef CLIENT_DLL
  107. //--------------------------------------------------------------------------------------------------------
  108. void CItem_Healthshot::CompleteUse( CCSPlayer *pPlayer )
  109. {
  110. pPlayer->OnHealthshotUsed();
  111. // Give half health buffer
  112. pPlayer->SetHealth( Min( pPlayer->GetHealth() + healthshot_health.GetInt(), pPlayer->GetMaxHealth() ) );
  113. // emit event
  114. // IGameEvent *event = gameeventmanager->CreateEvent( "healthshot_used" );
  115. // if( event )
  116. // {
  117. // int userID = pPlayer->GetUserID();
  118. // event->SetInt( "userid", userID );
  119. // event->SetInt( "subject", userID );
  120. // gameeventmanager->FireEvent( event );
  121. // }
  122. BaseClass::CompleteUse( pPlayer );
  123. }
  124. #endif //CLIENT_DLL
  125. float CItem_Healthshot::GetUseTimerDuration( void )
  126. {
  127. return HEALTHSHOT_INJECT_TIME;
  128. }