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.

3001 lines
86 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: The Medic's Medikit weapon
  4. //
  5. //
  6. // $Workfile: $
  7. // $Date: $
  8. // $NoKeywords: $
  9. //=============================================================================//
  10. #include "cbase.h"
  11. #include "in_buttons.h"
  12. #include "engine/IEngineSound.h"
  13. #include "tf_gamerules.h"
  14. #include "tf_item.h"
  15. #include "entity_capture_flag.h"
  16. #if defined( CLIENT_DLL )
  17. #include <vgui_controls/Panel.h>
  18. #include <vgui/ISurface.h>
  19. #include "particles_simple.h"
  20. #include "c_tf_player.h"
  21. #include "soundenvelope.h"
  22. #include "tf_hud_mediccallers.h"
  23. #include "c_tf_playerresource.h"
  24. #include "prediction.h"
  25. #else
  26. #include "ndebugoverlay.h"
  27. #include "tf_player.h"
  28. #include "tf_team.h"
  29. #include "tf_gamestats.h"
  30. #include "ilagcompensationmanager.h"
  31. #include "tf_obj.h"
  32. #include "inetchannel.h"
  33. #include "IEffects.h"
  34. #include "baseprojectile.h"
  35. #include "soundenvelope.h"
  36. #include "effect_dispatch_data.h"
  37. #include "func_respawnroom.h"
  38. #endif
  39. #include "tf_revive.h"
  40. #include "tf_weapon_medigun.h"
  41. #include "tf_weapon_shovel.h"
  42. // memdbgon must be the last include file in a .cpp file!!!
  43. #include "tier0/memdbgon.h"
  44. MedigunEffects_t g_MedigunEffects[MEDIGUN_NUM_CHARGE_TYPES] =
  45. {
  46. { TF_COND_INVULNERABLE, TF_COND_INVULNERABLE_WEARINGOFF, "TFPlayer.InvulnerableOn", "TFPlayer.InvulnerableOff" }, // MEDIGUN_CHARGE_INVULN = 0,
  47. { TF_COND_CRITBOOSTED, TF_COND_LAST, "TFPlayer.CritBoostOn", "TFPlayer.CritBoostOff" }, // MEDIGUN_CHARGE_CRITICALBOOST,
  48. { TF_COND_MEGAHEAL, TF_COND_LAST, "TFPlayer.QuickFixInvulnerableOn", "TFPlayer.MegaHealOff" }, // MEDIGUN_CHARGE_MEGAHEAL,
  49. { TF_COND_MEDIGUN_UBER_BULLET_RESIST, TF_COND_LAST, "WeaponMedigun_Vaccinator.InvulnerableOn", "WeaponMedigun_Vaccinator.InvulnerableOff" }, // TF_COND_MEDIGUN_UBER_BULLET_RESIST,
  50. { TF_COND_MEDIGUN_UBER_BLAST_RESIST, TF_COND_LAST, "WeaponMedigun_Vaccinator.InvulnerableOn", "WeaponMedigun_Vaccinator.InvulnerableOff" }, // TF_COND_MEDIGUN_UBER_BLAST_RESIST,
  51. { TF_COND_MEDIGUN_UBER_FIRE_RESIST, TF_COND_LAST, "WeaponMedigun_Vaccinator.InvulnerableOn", "WeaponMedigun_Vaccinator.InvulnerableOff" }, // TF_COND_MEDIGUN_UBER_FIRE_RESIST,
  52. };
  53. struct MedigunResistConditions_t
  54. {
  55. medigun_resist_types_t eResistType;
  56. ETFCond passiveCond;
  57. ETFCond uberCond;
  58. };
  59. MedigunResistConditions_t g_MedigunResistConditions[MEDIGUN_NUM_RESISTS] =
  60. {
  61. { MEDIGUN_BULLET_RESIST, TF_COND_MEDIGUN_SMALL_BULLET_RESIST, TF_COND_MEDIGUN_UBER_BULLET_RESIST },
  62. { MEDIGUN_BLAST_RESIST, TF_COND_MEDIGUN_SMALL_BLAST_RESIST, TF_COND_MEDIGUN_UBER_BLAST_RESIST },
  63. { MEDIGUN_FIRE_RESIST, TF_COND_MEDIGUN_SMALL_FIRE_RESIST, TF_COND_MEDIGUN_UBER_FIRE_RESIST }
  64. };
  65. // Buff ranges
  66. ConVar weapon_medigun_damage_modifier( "weapon_medigun_damage_modifier", "1.5", FCVAR_CHEAT | FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY, "Scales the damage a player does while being healed with the medigun." );
  67. ConVar weapon_medigun_construction_rate( "weapon_medigun_construction_rate", "10", FCVAR_CHEAT | FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY, "Constructing object health healed per second by the medigun." );
  68. ConVar weapon_medigun_charge_rate( "weapon_medigun_charge_rate", "40", FCVAR_CHEAT | FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY, "Amount of time healing it takes to fully charge the medigun." );
  69. ConVar weapon_medigun_chargerelease_rate( "weapon_medigun_chargerelease_rate", "8", FCVAR_CHEAT | FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY, "Amount of time it takes the a full charge of the medigun to be released." );
  70. ConVar weapon_medigun_resist_num_chunks( "weapon_medigun_resist_num_chunks", "4", FCVAR_CHEAT | FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY, "How many uber bar chunks the vaccinator has." );
  71. ConVar tf_vaccinator_uber_charge_rate_modifier( "tf_vaccinator_uber_charge_rate_modifier", "1.0", FCVAR_CHEAT | FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY , "Vaccinator uber charge rate." );
  72. #if defined (CLIENT_DLL)
  73. ConVar tf_medigun_autoheal( "tf_medigun_autoheal", "0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_USERINFO, "Setting this to 1 will cause the Medigun's primary attack to be a toggle instead of needing to be held down." );
  74. #endif
  75. #if !defined (CLIENT_DLL)
  76. ConVar tf_medigun_lagcomp( "tf_medigun_lagcomp", "1", FCVAR_DEVELOPMENTONLY );
  77. #endif
  78. static const char *s_pszMedigunHealTargetThink = "MedigunHealTargetThink";
  79. extern ConVar tf_invuln_time;
  80. #ifdef CLIENT_DLL
  81. //-----------------------------------------------------------------------------
  82. // Purpose:
  83. //-----------------------------------------------------------------------------
  84. void RecvProxy_HealingTarget( const CRecvProxyData *pData, void *pStruct, void *pOut )
  85. {
  86. CWeaponMedigun *pMedigun = ((CWeaponMedigun*)(pStruct));
  87. if ( pMedigun != NULL )
  88. {
  89. pMedigun->ForceHealingTargetUpdate();
  90. }
  91. RecvProxy_IntToEHandle( pData, pStruct, pOut );
  92. }
  93. #endif
  94. LINK_ENTITY_TO_CLASS( tf_weapon_medigun, CWeaponMedigun );
  95. PRECACHE_WEAPON_REGISTER( tf_weapon_medigun );
  96. IMPLEMENT_NETWORKCLASS_ALIASED( WeaponMedigun, DT_WeaponMedigun )
  97. #ifdef GAME_DLL
  98. void* SendProxy_SendActiveLocalWeaponDataTable( const SendProp *pProp, const void *pStruct, const void *pVarData, CSendProxyRecipients *pRecipients, int objectID );
  99. void* SendProxy_SendNonLocalWeaponDataTable( const SendProp *pProp, const void *pStruct, const void *pVarData, CSendProxyRecipients *pRecipients, int objectID );
  100. #endif
  101. //-----------------------------------------------------------------------------
  102. // Purpose: Only sent when a player's holding it.
  103. //-----------------------------------------------------------------------------
  104. BEGIN_NETWORK_TABLE_NOBASE( CWeaponMedigun, DT_LocalTFWeaponMedigunData )
  105. #if defined( CLIENT_DLL )
  106. RecvPropFloat( RECVINFO(m_flChargeLevel) ),
  107. #else
  108. SendPropFloat( SENDINFO(m_flChargeLevel), 0, SPROP_NOSCALE | SPROP_CHANGES_OFTEN ),
  109. #endif
  110. END_NETWORK_TABLE()
  111. //-----------------------------------------------------------------------------
  112. // Purpose: Variables sent at low precision to non-holding observers.
  113. //-----------------------------------------------------------------------------
  114. BEGIN_NETWORK_TABLE_NOBASE( CWeaponMedigun, DT_TFWeaponMedigunDataNonLocal )
  115. #if defined( CLIENT_DLL )
  116. RecvPropFloat( RECVINFO(m_flChargeLevel) ),
  117. #else
  118. SendPropFloat( SENDINFO(m_flChargeLevel), 12, SPROP_NOSCALE | SPROP_CHANGES_OFTEN, 0.0, 100.0f ),
  119. #endif
  120. END_NETWORK_TABLE()
  121. //-----------------------------------------------------------------------------
  122. // Purpose: Variables always sent
  123. //-----------------------------------------------------------------------------
  124. BEGIN_NETWORK_TABLE( CWeaponMedigun, DT_WeaponMedigun )
  125. #if !defined( CLIENT_DLL )
  126. // SendPropFloat( SENDINFO(m_flChargeLevel), 0, SPROP_NOSCALE | SPROP_CHANGES_OFTEN ),
  127. SendPropEHandle( SENDINFO( m_hHealingTarget ) ),
  128. SendPropBool( SENDINFO( m_bHealing ) ),
  129. SendPropBool( SENDINFO( m_bAttacking ) ),
  130. SendPropBool( SENDINFO( m_bChargeRelease ) ),
  131. SendPropBool( SENDINFO( m_bHolstered ) ),
  132. SendPropInt( SENDINFO( m_nChargeResistType ) ),
  133. SendPropDataTable("LocalTFWeaponMedigunData", 0, &REFERENCE_SEND_TABLE(DT_LocalTFWeaponMedigunData), SendProxy_SendLocalWeaponDataTable ),
  134. SendPropDataTable("NonLocalTFWeaponMedigunData", 0, &REFERENCE_SEND_TABLE(DT_TFWeaponMedigunDataNonLocal), SendProxy_SendNonLocalWeaponDataTable ),
  135. #else
  136. // RecvPropFloat( RECVINFO(m_flChargeLevel) ),
  137. RecvPropEHandle( RECVINFO( m_hHealingTarget ), RecvProxy_HealingTarget ),
  138. RecvPropBool( RECVINFO( m_bHealing ) ),
  139. RecvPropBool( RECVINFO( m_bAttacking ) ),
  140. RecvPropBool( RECVINFO( m_bChargeRelease ) ),
  141. RecvPropBool( RECVINFO( m_bHolstered ) ),
  142. RecvPropInt( RECVINFO( m_nChargeResistType ) ),
  143. RecvPropDataTable("LocalTFWeaponMedigunData", 0, 0, &REFERENCE_RECV_TABLE(DT_LocalTFWeaponMedigunData)),
  144. RecvPropDataTable("NonLocalTFWeaponMedigunData", 0, 0, &REFERENCE_RECV_TABLE(DT_TFWeaponMedigunDataNonLocal)),
  145. #endif
  146. END_NETWORK_TABLE()
  147. #ifdef CLIENT_DLL
  148. BEGIN_PREDICTION_DATA( CWeaponMedigun )
  149. DEFINE_PRED_FIELD( m_bHealing, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
  150. DEFINE_PRED_FIELD( m_bAttacking, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
  151. DEFINE_PRED_FIELD( m_bHolstered, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
  152. DEFINE_PRED_FIELD( m_hHealingTarget, FIELD_EHANDLE, FTYPEDESC_INSENDTABLE ),
  153. DEFINE_FIELD( m_bCanChangeTarget, FIELD_BOOLEAN ),
  154. DEFINE_FIELD( m_flHealEffectLifetime, FIELD_FLOAT ),
  155. DEFINE_PRED_FIELD( m_flChargeLevel, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
  156. DEFINE_PRED_FIELD( m_bChargeRelease, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
  157. // DEFINE_PRED_FIELD( m_bPlayingSound, FIELD_BOOLEAN ),
  158. // DEFINE_PRED_FIELD( m_bUpdateHealingTargets, FIELD_BOOLEAN ),
  159. END_PREDICTION_DATA()
  160. #endif
  161. #define PARTICLE_PATH_VEL 140.0
  162. #define NUM_PATH_PARTICLES_PER_SEC 300.0f
  163. #define NUM_MEDIGUN_PATH_POINTS 8
  164. extern ConVar tf_max_health_boost;
  165. //-----------------------------------------------------------------------------
  166. // Purpose: For HUD auto medic callers
  167. //-----------------------------------------------------------------------------
  168. #ifdef CLIENT_DLL
  169. ConVar hud_medicautocallers( "hud_medicautocallers", "0", FCVAR_ARCHIVE | FCVAR_ARCHIVE_XBOX );
  170. ConVar hud_medicautocallersthreshold( "hud_medicautocallersthreshold", "75", FCVAR_ARCHIVE | FCVAR_ARCHIVE_XBOX );
  171. ConVar hud_medichealtargetmarker ( "hud_medichealtargetmarker", "0", FCVAR_ARCHIVE | FCVAR_ARCHIVE_XBOX );
  172. #endif
  173. const char *g_pszMedigunHealSounds[MEDIGUN_NUM_CHARGE_TYPES] =
  174. {
  175. "WeaponMedigun.Healing", // MEDIGUN_CHARGE_INVULN = 0,
  176. "WeaponMedigun.Healing", // MEDIGUN_CHARGE_CRITICALBOOST,
  177. "Weapon_Quick_Fix.Healing", // MEDIGUN_CHARGE_MEGAHEAL,
  178. "WeaponMedigun_Vaccinator.Healing", // MEDIGUN_CHARGE_RESIST,
  179. };
  180. //-----------------------------------------------------------------------------
  181. // Purpose:
  182. //-----------------------------------------------------------------------------
  183. CWeaponMedigun::CWeaponMedigun( void )
  184. {
  185. WeaponReset();
  186. SetPredictionEligible( true );
  187. }
  188. CWeaponMedigun::~CWeaponMedigun()
  189. {
  190. #ifdef CLIENT_DLL
  191. StopChargeEffect( true );
  192. if ( m_pChargedSound )
  193. {
  194. CSoundEnvelopeController::GetController().SoundDestroy( m_pChargedSound );
  195. }
  196. if ( m_pDisruptSound )
  197. {
  198. CSoundEnvelopeController::GetController().SoundDestroy( m_pDisruptSound );
  199. }
  200. m_flAutoCallerCheckTime = 0.0f;
  201. #endif
  202. }
  203. //-----------------------------------------------------------------------------
  204. // Purpose:
  205. //-----------------------------------------------------------------------------
  206. void CWeaponMedigun::WeaponReset( void )
  207. {
  208. BaseClass::WeaponReset();
  209. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  210. if ( m_bHealing && pOwner && pOwner->m_Shared.InState( TF_STATE_DYING ) )
  211. {
  212. m_bWasHealingBeforeDeath = true;
  213. }
  214. else
  215. {
  216. m_bWasHealingBeforeDeath = false;
  217. }
  218. m_flHealEffectLifetime = 0;
  219. m_bHealing = false;
  220. m_bAttacking = false;
  221. m_bChargeRelease = false;
  222. m_DetachedTargets.Purge();
  223. m_flEndResistCharge = 0.f;
  224. m_bCanChangeTarget = true;
  225. m_flNextBuzzTime = 0;
  226. m_flReleaseStartedAt = 0;
  227. int iPreserveUber = 0;
  228. if ( TFGameRules()->State_Get() == GR_STATE_RND_RUNNING )
  229. {
  230. CALL_ATTRIB_HOOK_INT_ON_OTHER( pOwner, iPreserveUber, preserve_ubercharge );
  231. m_flChargeLevel = MIN( m_flChargeLevel, iPreserveUber / 100.f );
  232. }
  233. else
  234. {
  235. m_flChargeLevel = 0;
  236. }
  237. RemoveHealingTarget( true );
  238. m_bAttack2Down = false;
  239. m_bAttack3Down = false;
  240. m_bReloadDown = false;
  241. m_nChargeResistType = 0;
  242. #if defined( GAME_DLL )
  243. StopHealingOwner();
  244. m_hLastHealingTarget = NULL;
  245. RecalcEffectOnTarget( ToTFPlayer( GetOwnerEntity() ), true );
  246. m_nHealTargetClass = 0;
  247. m_nChargesReleased = 0;
  248. #endif
  249. #if defined( CLIENT_DLL )
  250. m_nOldChargeResistType = 0;
  251. m_bPlayingSound = false;
  252. m_bUpdateHealingTargets = false;
  253. m_bOldChargeRelease = false;
  254. UpdateEffects();
  255. StopChargeEffect( true );
  256. m_pChargeEffectOwner = NULL;
  257. m_pChargeEffect = NULL;
  258. m_pChargedSound = NULL;
  259. m_pDisruptSound = NULL;
  260. m_flDenySecondary = 0.f;
  261. #endif
  262. }
  263. //-----------------------------------------------------------------------------
  264. // Purpose:
  265. //-----------------------------------------------------------------------------
  266. void CWeaponMedigun::Precache()
  267. {
  268. BaseClass::Precache();
  269. PrecacheModel( "models/weapons/c_models/c_proto_backpack/c_proto_backpack.mdl" );
  270. PrecacheScriptSound( "WeaponMedigun.NoTarget" );
  271. PrecacheScriptSound( "WeaponMedigun.Healing" );
  272. PrecacheScriptSound( "Weapon_Quick_Fix.Healing" );
  273. PrecacheScriptSound( "WeaponMedigun.Charged" );
  274. PrecacheParticleSystem( "medicgun_invulnstatus_fullcharge_blue" );
  275. PrecacheParticleSystem( "medicgun_invulnstatus_fullcharge_red" );
  276. PrecacheParticleSystem( "medicgun_beam_red_invun" );
  277. PrecacheParticleSystem( "medicgun_beam_red" );
  278. PrecacheParticleSystem( "medicgun_beam_red_targeted" );
  279. PrecacheParticleSystem( "medicgun_beam_blue_invun" );
  280. PrecacheParticleSystem( "medicgun_beam_blue" );
  281. PrecacheParticleSystem( "medicgun_beam_blue_targeted" );
  282. PrecacheParticleSystem( "vaccinator_red_buff1" );
  283. PrecacheParticleSystem( "vaccinator_red_buff2" );
  284. PrecacheParticleSystem( "vaccinator_red_buff3" );
  285. PrecacheParticleSystem( "vaccinator_blue_buff1" );
  286. PrecacheParticleSystem( "vaccinator_blue_buff2" );
  287. PrecacheParticleSystem( "vaccinator_blue_buff3" );
  288. PrecacheParticleSystem( "drain_effect" );
  289. PrecacheScriptSound( "WeaponMedigun_Vaccinator.Charged_tier_01");
  290. PrecacheScriptSound( "WeaponMedigun_Vaccinator.Charged_tier_02");
  291. PrecacheScriptSound( "WeaponMedigun_Vaccinator.Charged_tier_03");
  292. PrecacheScriptSound( "WeaponMedigun_Vaccinator.Charged_tier_04");
  293. PrecacheScriptSound( "WeaponMedigun.HealingDisrupt" );
  294. // PrecacheParticleSystem( "medicgun_beam_machinery" );
  295. for( int i=0; i<ARRAYSIZE(g_MedigunEffects); ++i )
  296. {
  297. if( g_MedigunEffects[i].pszChargeOnSound[0] )
  298. PrecacheScriptSound( g_MedigunEffects[i].pszChargeOnSound );
  299. if( g_MedigunEffects[i].pszChargeOffSound[0] )
  300. PrecacheScriptSound( g_MedigunEffects[i].pszChargeOffSound );
  301. }
  302. }
  303. //-----------------------------------------------------------------------------
  304. // Purpose:
  305. //-----------------------------------------------------------------------------
  306. bool CWeaponMedigun::Deploy( void )
  307. {
  308. if ( BaseClass::Deploy() )
  309. {
  310. m_bHolstered = false;
  311. m_bWasHealingBeforeDeath = false;
  312. #ifdef GAME_DLL
  313. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  314. if ( m_bChargeRelease )
  315. {
  316. RecalcEffectOnTarget( pOwner );
  317. }
  318. if ( pOwner && pOwner->m_Shared.IsRageDraining() )
  319. {
  320. CreateMedigunShield();
  321. }
  322. // Resume healing self for Quick-Fix if we're still ubering and switch back to the Quick-Fix.
  323. if ( ( GetMedigunType() == MEDIGUN_QUICKFIX ) && m_bChargeRelease && !m_bHealingSelf )
  324. {
  325. StartHealingTarget( pOwner );
  326. m_bHealingSelf = true;
  327. }
  328. #endif
  329. #ifdef CLIENT_DLL
  330. ManageChargeEffect();
  331. #endif
  332. m_flNextTargetCheckTime = gpGlobals->curtime;
  333. return true;
  334. }
  335. return false;
  336. }
  337. //-----------------------------------------------------------------------------
  338. // Purpose:
  339. //-----------------------------------------------------------------------------
  340. bool CWeaponMedigun::Holster( CBaseCombatWeapon *pSwitchingTo )
  341. {
  342. RemoveHealingTarget( true );
  343. m_bAttacking = false;
  344. m_bHolstered = true;
  345. #ifdef GAME_DLL
  346. RecalcEffectOnTarget( ToTFPlayer( GetOwnerEntity() ), true );
  347. StopHealingOwner();
  348. #endif
  349. RemoveMedigunShield();
  350. #ifdef CLIENT_DLL
  351. UpdateEffects();
  352. ManageChargeEffect();
  353. #endif
  354. return BaseClass::Holster( pSwitchingTo );
  355. }
  356. //-----------------------------------------------------------------------------
  357. // Purpose:
  358. //-----------------------------------------------------------------------------
  359. void CWeaponMedigun::UpdateOnRemove( void )
  360. {
  361. RemoveHealingTarget( true );
  362. m_bAttacking = false;
  363. m_bChargeRelease = false;
  364. #ifdef GAME_DLL
  365. RecalcEffectOnTarget( ToTFPlayer( GetOwnerEntity() ), true );
  366. StopHealingOwner();
  367. #endif
  368. #ifdef CLIENT_DLL
  369. if ( m_bPlayingSound )
  370. {
  371. m_bPlayingSound = false;
  372. StopHealSound();
  373. }
  374. UpdateEffects();
  375. #endif
  376. RemoveMedigunShield();
  377. BaseClass::UpdateOnRemove();
  378. }
  379. //-----------------------------------------------------------------------------
  380. // Purpose:
  381. //-----------------------------------------------------------------------------
  382. float CWeaponMedigun::GetTargetRange( void )
  383. {
  384. return (float)m_pWeaponInfo->GetWeaponData( m_iWeaponMode ).m_flRange;
  385. }
  386. //-----------------------------------------------------------------------------
  387. // Purpose:
  388. //-----------------------------------------------------------------------------
  389. float CWeaponMedigun::GetStickRange( void )
  390. {
  391. return (GetTargetRange() * 1.2);
  392. }
  393. //-----------------------------------------------------------------------------
  394. // Purpose:
  395. //-----------------------------------------------------------------------------
  396. float CWeaponMedigun::GetHealRate( void )
  397. {
  398. float flHealRate = m_pWeaponInfo->GetWeaponData( m_iWeaponMode ).m_nDamage;
  399. CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( GetOwnerEntity(), flHealRate, mult_medigun_healrate );
  400. // This attribute represents a bucket of attributes.
  401. int iHealingMastery = 0;
  402. CALL_ATTRIB_HOOK_INT_ON_OTHER( GetOwnerEntity(), iHealingMastery, healing_mastery );
  403. if ( iHealingMastery )
  404. {
  405. float flPerc = RemapValClamped( (float)iHealingMastery, 1.f, 4.f, 1.25f, 2.f );
  406. flHealRate *= flPerc;
  407. }
  408. if ( TFGameRules() && TFGameRules()->IsPowerupMode() )
  409. {
  410. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  411. if ( pOwner && pOwner->m_Shared.GetCarryingRuneType() == RUNE_HASTE )
  412. {
  413. flHealRate *= 2.f;
  414. }
  415. else if ( pOwner && ( pOwner->m_Shared.GetCarryingRuneType() == RUNE_KING || pOwner->m_Shared.InCond( TF_COND_KING_BUFFED ) ) )
  416. {
  417. flHealRate *= 1.5f;
  418. }
  419. }
  420. return flHealRate;
  421. }
  422. //-----------------------------------------------------------------------------
  423. // Purpose:
  424. //-----------------------------------------------------------------------------
  425. bool CWeaponMedigun::HealingTarget( CBaseEntity *pTarget )
  426. {
  427. if ( pTarget == m_hHealingTarget )
  428. return true;
  429. return false;
  430. }
  431. //-----------------------------------------------------------------------------
  432. // Purpose:
  433. //-----------------------------------------------------------------------------
  434. bool CWeaponMedigun::AllowedToHealTarget( CBaseEntity *pTarget )
  435. {
  436. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  437. if ( !pOwner )
  438. return false;
  439. if ( !pTarget )
  440. return false;
  441. if ( pTarget->IsPlayer() )
  442. {
  443. CTFPlayer *pTFPlayer = ToTFPlayer( pTarget );
  444. if ( !pTFPlayer )
  445. return false;
  446. if ( !pTFPlayer->IsAlive() )
  447. return false;
  448. // We cannot heal teammates who are using the Equalizer.
  449. CTFWeaponBase *pTFWeapon = pTFPlayer->GetActiveTFWeapon();
  450. int iWeaponBlocksHealing = 0;
  451. CALL_ATTRIB_HOOK_INT_ON_OTHER( pTFWeapon, iWeaponBlocksHealing, weapon_blocks_healing );
  452. if ( iWeaponBlocksHealing == 1 )
  453. {
  454. return false;
  455. }
  456. bool bStealthed = pTFPlayer->m_Shared.IsStealthed() && !pOwner->m_Shared.IsStealthed(); // Allow stealthed medics to heal stealthed targets
  457. bool bDisguised = pTFPlayer->m_Shared.InCond( TF_COND_DISGUISED );
  458. // We can heal teammates and enemies that are disguised as teammates
  459. if ( !bStealthed &&
  460. ( pTFPlayer->InSameTeam( pOwner ) ||
  461. ( bDisguised && pTFPlayer->m_Shared.GetDisguiseTeam() == pOwner->GetTeamNumber() ) ) )
  462. {
  463. return true;
  464. }
  465. }
  466. else
  467. {
  468. if ( !pTarget->InSameTeam( pOwner ) )
  469. return false;
  470. #ifdef STAGING_ONLY
  471. if ( pTarget->IsBaseObject() && IsAllowedToTargetBuildings() )
  472. return true;
  473. #else
  474. if ( pTarget->IsBaseObject() )
  475. return false;
  476. #endif // STAGING_ONLY
  477. CTFReviveMarker *pReviveMarker = dynamic_cast< CTFReviveMarker* >( pTarget );
  478. if ( pReviveMarker )
  479. {
  480. m_hReviveMarker = pReviveMarker; // Store last marker we touched
  481. return true;
  482. }
  483. }
  484. return false;
  485. }
  486. // Now make sure there isn't something other than team players in the way.
  487. class CMedigunFilter : public CTraceFilterSimple
  488. {
  489. public:
  490. CMedigunFilter( CBaseEntity *pShooter ) : CTraceFilterSimple( pShooter, COLLISION_GROUP_WEAPON )
  491. {
  492. m_pShooter = pShooter;
  493. }
  494. virtual bool ShouldHitEntity( IHandleEntity *pHandleEntity, int contentsMask )
  495. {
  496. // If it hit an edict that isn't the target and is on our team, then the ray is blocked.
  497. CBaseEntity *pEnt = static_cast<CBaseEntity*>(pHandleEntity);
  498. // Ignore collisions with the shooter
  499. if ( pEnt == m_pShooter )
  500. return false;
  501. if ( pEnt->GetTeam() == m_pShooter->GetTeam() )
  502. return false;
  503. return CTraceFilterSimple::ShouldHitEntity( pHandleEntity, contentsMask );
  504. }
  505. CBaseEntity *m_pShooter;
  506. };
  507. //-----------------------------------------------------------------------------
  508. // Purpose:
  509. //-----------------------------------------------------------------------------
  510. void CWeaponMedigun::MaintainTargetInSlot()
  511. {
  512. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  513. if ( !pOwner )
  514. return;
  515. CBaseEntity *pTarget = m_hHealingTarget;
  516. Assert( pTarget );
  517. // Make sure the guy didn't go out of range.
  518. bool bLostTarget = true;
  519. Vector vecSrc = pOwner->Weapon_ShootPosition( );
  520. Vector vecTargetPoint = pTarget->WorldSpaceCenter();
  521. Vector vecPoint;
  522. // If it's brush built, use absmins/absmaxs
  523. pTarget->CollisionProp()->CalcNearestPoint( vecSrc, &vecPoint );
  524. float flDistance = (vecPoint - vecSrc).Length();
  525. if ( flDistance < GetStickRange() )
  526. {
  527. if ( m_flNextTargetCheckTime > gpGlobals->curtime )
  528. return;
  529. m_flNextTargetCheckTime = gpGlobals->curtime + 1.0f;
  530. CheckAchievementsOnHealTarget();
  531. trace_t tr;
  532. CMedigunFilter drainFilter( pOwner );
  533. Vector vecAiming;
  534. pOwner->EyeVectors( &vecAiming );
  535. Vector vecEnd = vecSrc + vecAiming * GetTargetRange();
  536. UTIL_TraceLine( vecSrc, vecEnd, (MASK_SHOT & ~CONTENTS_HITBOX), pOwner, DMG_GENERIC, &tr );
  537. // Still visible?
  538. if ( tr.m_pEnt == pTarget )
  539. return;
  540. UTIL_TraceLine( vecSrc, vecTargetPoint, MASK_SHOT, &drainFilter, &tr );
  541. // Still visible?
  542. if (( tr.fraction == 1.0f) || (tr.m_pEnt == pTarget))
  543. return;
  544. // If we failed, try the target's eye point as well
  545. UTIL_TraceLine( vecSrc, pTarget->EyePosition(), MASK_SHOT, &drainFilter, &tr );
  546. if (( tr.fraction == 1.0f) || (tr.m_pEnt == pTarget))
  547. return;
  548. }
  549. // We've lost this guy
  550. if ( bLostTarget )
  551. {
  552. RemoveHealingTarget();
  553. }
  554. }
  555. //-----------------------------------------------------------------------------
  556. // Purpose:
  557. //-----------------------------------------------------------------------------
  558. void CWeaponMedigun::FindNewTargetForSlot()
  559. {
  560. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  561. if ( !pOwner )
  562. return;
  563. Vector vecSrc = pOwner->Weapon_ShootPosition( );
  564. if ( m_hHealingTarget )
  565. {
  566. RemoveHealingTarget();
  567. }
  568. // In Normal mode, we heal players under our crosshair
  569. Vector vecAiming;
  570. pOwner->EyeVectors( &vecAiming );
  571. // Find a player in range of this player, and make sure they're healable.
  572. Vector vecEnd = vecSrc + vecAiming * GetTargetRange();
  573. trace_t tr;
  574. UTIL_TraceLine( vecSrc, vecEnd, (MASK_SHOT & ~CONTENTS_HITBOX), pOwner, DMG_GENERIC, &tr );
  575. if ( tr.fraction != 1.0 && tr.m_pEnt )
  576. {
  577. if ( !HealingTarget( tr.m_pEnt ) && AllowedToHealTarget( tr.m_pEnt ) )
  578. {
  579. #ifdef GAME_DLL
  580. pOwner->SpeakConceptIfAllowed( MP_CONCEPT_MEDIC_STARTEDHEALING );
  581. if ( tr.m_pEnt->IsPlayer() )
  582. {
  583. CTFPlayer *pTarget = ToTFPlayer( tr.m_pEnt );
  584. pTarget->SpeakConceptIfAllowed( MP_CONCEPT_HEALTARGET_STARTEDHEALING );
  585. }
  586. // Start the heal target thinking.
  587. SetContextThink( &CWeaponMedigun::HealTargetThink, gpGlobals->curtime, s_pszMedigunHealTargetThink );
  588. m_hLastHealingTarget = tr.m_pEnt;
  589. #endif
  590. m_hHealingTarget.Set( tr.m_pEnt );
  591. m_flNextTargetCheckTime = gpGlobals->curtime + 1.0f;
  592. }
  593. }
  594. }
  595. bool CWeaponMedigun::IsReleasingCharge( void ) const
  596. {
  597. return (m_bChargeRelease && !m_bHolstered);
  598. }
  599. int CWeaponMedigun::GetMedigunType( void ) const
  600. {
  601. int iMode = 0;
  602. CALL_ATTRIB_HOOK_INT( iMode, set_weapon_mode );
  603. return iMode;
  604. }
  605. float CWeaponMedigun::GetMinChargeAmount( void ) const
  606. {
  607. if( GetMedigunType() == MEDIGUN_RESIST )
  608. {
  609. return 1.f / weapon_medigun_resist_num_chunks.GetInt();
  610. }
  611. else
  612. {
  613. return 1.f;
  614. }
  615. }
  616. medigun_charge_types CWeaponMedigun::GetChargeType( void ) const
  617. {
  618. int iTmp = MEDIGUN_CHARGE_INVULN;
  619. CALL_ATTRIB_HOOK_INT( iTmp, set_charge_type );
  620. if( GetMedigunType() == MEDIGUN_RESIST )
  621. {
  622. // If this is a resist-medigun, then the charge type needs to be within the resist types
  623. Assert( iTmp >= MEDIGUN_CHARGE_BULLET_RESIST && iTmp <= MEDIGUN_CHARGE_FIRE_RESIST );
  624. Assert( m_nChargeResistType < MEDIGUN_NUM_RESISTS );
  625. iTmp += m_nChargeResistType;
  626. }
  627. return (medigun_charge_types)iTmp;
  628. }
  629. void CWeaponMedigun::CycleResistType()
  630. {
  631. // Resist medigun only!
  632. if( GetMedigunType() != MEDIGUN_RESIST )
  633. return;
  634. if( IsReleasingCharge() )
  635. return;
  636. #ifdef GAME_DLL
  637. // When cycling resist we have to remove the current resist, then add the new resist.
  638. CTFPlayer *pTFHealingTarget = ToTFPlayer( m_hHealingTarget );
  639. CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
  640. ETFCond cond = g_MedigunResistConditions[ GetResistType() ].passiveCond;
  641. // Remove from out healing target
  642. if( pTFHealingTarget)
  643. {
  644. CBaseEntity* pProvider = pTFHealingTarget->m_Shared.GetConditionProvider( cond );
  645. // Remove from our healing target if we're the provider
  646. if( pProvider == pOwner || pProvider == NULL )
  647. {
  648. pTFHealingTarget->m_Shared.RemoveCond( cond );
  649. }
  650. }
  651. // Remove from ourselves
  652. if( pOwner )
  653. {
  654. // Remove from ourselves if we're the provider
  655. CBaseEntity* pProvider = pOwner->m_Shared.GetConditionProvider( cond );
  656. if( pProvider == pOwner || pProvider == NULL )
  657. {
  658. pOwner->m_Shared.RemoveCond( cond );
  659. }
  660. }
  661. #endif
  662. m_nChargeResistType += 1;
  663. m_nChargeResistType = m_nChargeResistType % MEDIGUN_NUM_RESISTS;
  664. #ifdef GAME_DLL
  665. CTFPlayer *pTFOwner = ToTFPlayer( GetOwnerEntity() );
  666. if( pTFOwner )
  667. {
  668. RecalcEffectOnTarget( pTFOwner );
  669. }
  670. if( pTFHealingTarget )
  671. {
  672. // Now add the new resist
  673. RecalcEffectOnTarget( pTFHealingTarget );
  674. pTFHealingTarget->m_Shared.AddCond( g_MedigunResistConditions[ GetResistType() ].passiveCond, PERMANENT_CONDITION, pTFOwner );
  675. pTFOwner->m_Shared.AddCond( g_MedigunResistConditions[ GetResistType() ].passiveCond, PERMANENT_CONDITION, pTFOwner );
  676. }
  677. #else
  678. // Updates our particles
  679. ForceHealingTargetUpdate();
  680. #endif
  681. }
  682. medigun_resist_types_t CWeaponMedigun::GetResistType() const
  683. {
  684. Assert( GetMedigunType() == MEDIGUN_RESIST );
  685. int nCurrentActiveResist = ( GetChargeType() - MEDIGUN_CHARGE_BULLET_RESIST );
  686. Assert( nCurrentActiveResist >= 0 && nCurrentActiveResist < MEDIGUN_NUM_RESISTS );
  687. nCurrentActiveResist = nCurrentActiveResist % MEDIGUN_NUM_RESISTS;
  688. return medigun_resist_types_t(nCurrentActiveResist);
  689. }
  690. //-----------------------------------------------------------------------------
  691. // Purpose:
  692. //-----------------------------------------------------------------------------
  693. bool CWeaponMedigun::IsAllowedToTargetBuildings( void )
  694. {
  695. #ifdef STAGING_ONLY
  696. if ( !TFGameRules() || !TFGameRules()->GameModeUsesUpgrades() )
  697. return false;
  698. // See if we have the upgrade to heal buildings
  699. int iHealBuildings = 0;
  700. CALL_ATTRIB_HOOK_INT( iHealBuildings, medic_machinery_beam );
  701. return iHealBuildings ? true : false;
  702. #else
  703. return false;
  704. #endif // STAGING_ONLY
  705. }
  706. //-----------------------------------------------------------------------------
  707. // Purpose:
  708. //-----------------------------------------------------------------------------
  709. bool CWeaponMedigun::IsAttachedToBuilding( void )
  710. {
  711. if ( !m_hHealingTarget )
  712. return false;
  713. return m_hHealingTarget->IsBaseObject();
  714. }
  715. #ifdef GAME_DLL
  716. //-----------------------------------------------------------------------------
  717. // Purpose:
  718. //-----------------------------------------------------------------------------
  719. void CWeaponMedigun::HealTargetThink( void )
  720. {
  721. // Verify that we still have a valid heal target.
  722. CBaseEntity *pTarget = m_hHealingTarget;
  723. if ( !pTarget || !pTarget->IsAlive() )
  724. {
  725. SetContextThink( NULL, 0, s_pszMedigunHealTargetThink );
  726. return;
  727. }
  728. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  729. if ( !pOwner )
  730. return;
  731. float flTime = gpGlobals->curtime - pOwner->GetTimeBase();
  732. if ( flTime > 5.0f || !AllowedToHealTarget(pTarget) )
  733. {
  734. RemoveHealingTarget( true );
  735. }
  736. // Make sure our heal target hasn't changed classes while being healed
  737. CTFPlayer *pTFTarget = ToTFPlayer( pTarget );
  738. if ( pTFTarget )
  739. {
  740. int nPrevClass = m_nHealTargetClass;
  741. m_nHealTargetClass = pTFTarget->GetPlayerClass()->GetClassIndex();
  742. if ( m_nHealTargetClass != nPrevClass )
  743. {
  744. pOwner->TeamFortress_SetSpeed();
  745. }
  746. }
  747. if ( !pTarget->IsPlayer() )
  748. {
  749. #ifdef STAGING_ONLY
  750. if ( TFGameRules() && TFGameRules()->GameModeUsesUpgrades() )
  751. {
  752. if ( IsAttachedToBuilding() )
  753. {
  754. // Heal building
  755. if ( m_hHealingTarget->GetHealth() < m_hHealingTarget->GetMaxHealth() )
  756. {
  757. CBaseEntity *pEntity = m_hHealingTarget;
  758. CBaseObject *pObject = dynamic_cast<CBaseObject*>( pEntity );
  759. if ( pObject )
  760. {
  761. pObject->SetHealth( m_hHealingTarget->GetHealth() + ( GetHealRate() / 10.f ) );
  762. }
  763. }
  764. }
  765. }
  766. #endif // STAGING_ONLY
  767. CTFReviveMarker *pReviveMarker = dynamic_cast< CTFReviveMarker* >( pTarget );
  768. if ( pReviveMarker )
  769. {
  770. CTFPlayer *pDeadPlayer = pReviveMarker->GetOwner();
  771. if ( pDeadPlayer )
  772. {
  773. pReviveMarker->SetReviver( pOwner );
  774. // Instantly revive players when deploying uber
  775. float flHealRate = GetHealRate();
  776. float flReviveRate = m_bChargeRelease ? flHealRate / 2.f : flHealRate / 8.f;
  777. pReviveMarker->AddMarkerHealth( flReviveRate );
  778. // Set observer target to reviver so they know they're being revived
  779. if ( pDeadPlayer->GetObserverMode() > OBS_MODE_FREEZECAM )
  780. {
  781. if ( pReviveMarker->GetReviver() && pDeadPlayer->GetObserverTarget() != pReviveMarker->GetReviver() )
  782. {
  783. pDeadPlayer->SetObserverTarget( pReviveMarker->GetReviver() );
  784. }
  785. }
  786. if ( !pReviveMarker->HasOwnerBeenPrompted() )
  787. {
  788. // This will give them a messagebox that has a Cancel button
  789. pReviveMarker->PromptOwner();
  790. }
  791. }
  792. }
  793. }
  794. SetNextThink( gpGlobals->curtime + 0.2f, s_pszMedigunHealTargetThink );
  795. }
  796. //-----------------------------------------------------------------------------
  797. // Purpose:
  798. //-----------------------------------------------------------------------------
  799. void CWeaponMedigun::StartHealingTarget( CBaseEntity *pTarget )
  800. {
  801. CTFPlayer *pTFTarget = ToTFPlayer( pTarget );
  802. if ( !pTFTarget )
  803. return;
  804. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  805. if ( !pOwner )
  806. return;
  807. // Handle bonuses as additive, penalties as percentage...
  808. float flOverhealBonus = tf_max_health_boost.GetFloat() - 1.0f;
  809. float flMod = 1.0f;
  810. CALL_ATTRIB_HOOK_FLOAT( flMod, mult_medigun_overheal_amount );
  811. if ( flMod >= 1.0f )
  812. {
  813. flOverhealBonus += flMod;
  814. }
  815. else if ( flMod < 1.0f && flOverhealBonus > 0.0f )
  816. {
  817. flOverhealBonus *= flMod;
  818. flOverhealBonus += 1.0f;
  819. }
  820. // Safety net
  821. if ( flOverhealBonus <= 1.0f )
  822. {
  823. flOverhealBonus = 1.0f;
  824. }
  825. float flOverhealDecayMult = 1.0;
  826. CALL_ATTRIB_HOOK_FLOAT( flOverhealDecayMult, mult_medigun_overheal_decay );
  827. float flOverhealExpert = 0.f;
  828. CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( pOwner, flOverhealExpert, overheal_expert );
  829. flOverhealBonus = Max( flOverhealBonus, flOverhealBonus + ( flOverhealExpert / 4 ) );
  830. flOverhealDecayMult = Max( flOverhealDecayMult, flOverhealDecayMult + ( flOverhealExpert / 2 ) );
  831. pTFTarget->m_Shared.Heal( pOwner, GetHealRate(), flOverhealBonus, flOverhealDecayMult );
  832. // If target is grappling, set ourselves as grappling them
  833. if ( pTFTarget->GetGrapplingHookTarget() )
  834. {
  835. pOwner->SetGrapplingHookTarget( pTFTarget );
  836. }
  837. // Add on the small passive resist when we attach onto a target
  838. if( GetMedigunType() == MEDIGUN_RESIST )
  839. {
  840. pTFTarget->m_Shared.AddCond( g_MedigunResistConditions[ GetResistType() ].passiveCond, PERMANENT_CONDITION, pOwner );
  841. pOwner->m_Shared.AddCond( g_MedigunResistConditions[ GetResistType() ].passiveCond, PERMANENT_CONDITION, pOwner );
  842. }
  843. }
  844. //-----------------------------------------------------------------------------
  845. // Purpose: QuickFix uber heals the target and medic
  846. //-----------------------------------------------------------------------------
  847. void CWeaponMedigun::StopHealingOwner( void )
  848. {
  849. if ( !m_bHealingSelf )
  850. return;
  851. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  852. if ( !pOwner )
  853. return;
  854. pOwner->m_Shared.StopHealing( pOwner );
  855. m_bHealingSelf = false;
  856. }
  857. //-----------------------------------------------------------------------------
  858. // Purpose:
  859. //-----------------------------------------------------------------------------
  860. void CWeaponMedigun::AddCharge( float flPercentage )
  861. {
  862. m_flChargeLevel = MIN( m_flChargeLevel + flPercentage, 1.0 );
  863. }
  864. //-----------------------------------------------------------------------------
  865. // Purpose:
  866. //-----------------------------------------------------------------------------
  867. void CWeaponMedigun::SubtractCharge( float flPercentage )
  868. {
  869. float flSubtractAmount = Max( flPercentage, 0.0f );
  870. SubtractChargeAndUpdateDeployState( flSubtractAmount, true );
  871. }
  872. //-----------------------------------------------------------------------------
  873. // Purpose:
  874. //-----------------------------------------------------------------------------
  875. void CWeaponMedigun::RecalcEffectOnTarget( CTFPlayer *pPlayer, bool bInstantRemove )
  876. {
  877. if ( !pPlayer )
  878. return;
  879. pPlayer->m_Shared.RecalculateChargeEffects( bInstantRemove );
  880. }
  881. #endif
  882. //-----------------------------------------------------------------------------
  883. // Purpose:
  884. //-----------------------------------------------------------------------------
  885. const char *CWeaponMedigun::GetHealSound( void ) const
  886. {
  887. COMPILE_TIME_ASSERT( ARRAYSIZE(g_pszMedigunHealSounds) == MEDIGUN_NUM_CHARGE_TYPES );
  888. return g_pszMedigunHealSounds[ GetMedigunType() ];
  889. }
  890. #ifdef GAME_DLL
  891. void CWeaponMedigun::UberchargeChunkDeployed()
  892. {
  893. m_nChargesReleased++;
  894. if( m_nChargesReleased % weapon_medigun_resist_num_chunks.GetInt() == 0 )
  895. {
  896. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  897. if ( !pOwner )
  898. return;
  899. CTF_GameStats.Event_PlayerInvulnerable( pOwner );
  900. EconEntity_OnOwnerKillEaterEvent( this, pOwner, ToTFPlayer( m_hHealingTarget ), kKillEaterEvent_UberActivated );
  901. }
  902. }
  903. #endif
  904. //-----------------------------------------------------------------------------
  905. // Purpose:
  906. //-----------------------------------------------------------------------------
  907. void CWeaponMedigun::CreateMedigunShield( void )
  908. {
  909. #ifdef GAME_DLL
  910. if ( m_hMedigunShield )
  911. return;
  912. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  913. if ( !pOwner )
  914. return;
  915. #ifdef STAGING_ONLY
  916. bool bHasPermanentShield = HasPermanentShield();
  917. if ( !bHasPermanentShield )
  918. #endif // STAGING_ONLY
  919. {
  920. // check if we can activate the shield
  921. if ( ( pOwner->m_Shared.GetRageMeter() < 100.f ) && !pOwner->m_Shared.IsRageDraining() )
  922. return;
  923. }
  924. pOwner->SpeakConceptIfAllowed( MP_CONCEPT_MEDIC_HEAL_SHIELD );
  925. m_hMedigunShield = CTFMedigunShield::Create( pOwner );
  926. if ( m_hMedigunShield )
  927. {
  928. pOwner->m_Shared.StartRageDrain();
  929. #ifdef STAGING_ONLY
  930. m_hMedigunShield->SetPermanentShield( bHasPermanentShield );
  931. #endif // STAGING_ONLY
  932. }
  933. #endif // GAME_DLL
  934. }
  935. //-----------------------------------------------------------------------------
  936. // Purpose:
  937. //-----------------------------------------------------------------------------
  938. void CWeaponMedigun::RemoveMedigunShield( void )
  939. {
  940. #ifdef GAME_DLL
  941. if ( m_hMedigunShield )
  942. {
  943. m_hMedigunShield->RemoveShield();
  944. m_hMedigunShield.Set( NULL );
  945. }
  946. #endif // GAME_DLL
  947. }
  948. #ifdef STAGING_ONLY
  949. //-----------------------------------------------------------------------------
  950. // Purpose:
  951. //-----------------------------------------------------------------------------
  952. bool CWeaponMedigun::HasPermanentShield() const
  953. {
  954. if ( !TFGameRules()->IsMannVsMachineMode() )
  955. return false;
  956. int iPermanentShield = 0;
  957. CALL_ATTRIB_HOOK_INT( iPermanentShield, permanent_medic_shield );
  958. return iPermanentShield != 0;
  959. }
  960. #endif // STAGING_ONLY
  961. //-----------------------------------------------------------------------------
  962. // Purpose: Returns a pointer to a healable target
  963. //-----------------------------------------------------------------------------
  964. bool CWeaponMedigun::FindAndHealTargets( void )
  965. {
  966. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  967. if ( !pOwner )
  968. return false;
  969. #ifdef GAME_DLL
  970. if ( !pOwner->IsBot() )
  971. {
  972. INetChannelInfo *pNetChanInfo = engine->GetPlayerNetInfo( pOwner->entindex() );
  973. if ( !pNetChanInfo || pNetChanInfo->IsTimingOut() )
  974. return false;
  975. }
  976. #endif // GAME_DLL
  977. bool bFound = false;
  978. // Maintaining beam to existing target?
  979. CBaseEntity *pTarget = m_hHealingTarget;
  980. if ( pTarget && pTarget->IsAlive() )
  981. {
  982. MaintainTargetInSlot();
  983. }
  984. else
  985. {
  986. FindNewTargetForSlot();
  987. }
  988. CBaseEntity *pNewTarget = m_hHealingTarget;
  989. if ( pNewTarget && pNewTarget->IsAlive() )
  990. {
  991. CTFPlayer *pTFPlayer = ToTFPlayer( pNewTarget );
  992. #ifdef GAME_DLL
  993. // HACK: For now, just deal with players
  994. if ( pTFPlayer )
  995. {
  996. if ( pTarget != pNewTarget )
  997. {
  998. StartHealingTarget( pNewTarget );
  999. }
  1000. RecalcEffectOnTarget( pTFPlayer );
  1001. }
  1002. #endif
  1003. bFound = true;
  1004. // Charge up our power if we're not releasing it, and our target
  1005. // isn't receiving any benefit from our healing.
  1006. if ( !m_bChargeRelease )
  1007. {
  1008. float flChargeRate = weapon_medigun_charge_rate.GetFloat();
  1009. float flChargeAmount = gpGlobals->frametime / flChargeRate;
  1010. if ( pTFPlayer && weapon_medigun_charge_rate.GetFloat() )
  1011. {
  1012. #ifdef GAME_DLL
  1013. int iBoostMax = floor( pTFPlayer->m_Shared.GetMaxBuffedHealth() * 0.95);
  1014. float flChargeModifier = 1.f;
  1015. // Reduced charge for healing fully healed guys
  1016. if ( pNewTarget->GetHealth() >= iBoostMax && ( TFGameRules() && !(TFGameRules()->InSetup() && TFGameRules()->GetActiveRoundTimer() ) ) )
  1017. {
  1018. flChargeModifier *= 0.5;
  1019. }
  1020. int iTotalHealers = pTFPlayer->m_Shared.GetNumHealers();
  1021. if ( iTotalHealers > 1 )
  1022. {
  1023. flChargeModifier /= (float)iTotalHealers;
  1024. }
  1025. // The resist medigun has a uber charge rate
  1026. flChargeAmount *= flChargeModifier;
  1027. if ( pOwner->m_Shared.GetCarryingRuneType() == RUNE_HASTE )
  1028. {
  1029. flChargeAmount *= 2.f;
  1030. }
  1031. else if ( pOwner->m_Shared.GetCarryingRuneType() == RUNE_KING || pOwner->m_Shared.InCond( TF_COND_KING_BUFFED ) )
  1032. {
  1033. flChargeAmount *= 1.5f;
  1034. }
  1035. if ( pNewTarget->GetHealth() >= pNewTarget->GetMaxHealth() && ( TFGameRules() && !(TFGameRules()->InSetup() && TFGameRules()->GetActiveRoundTimer() ) ) )
  1036. {
  1037. CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( pOwner, flChargeAmount, mult_medigun_overheal_uberchargerate );
  1038. }
  1039. CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( pOwner, flChargeAmount, mult_medigun_uberchargerate );
  1040. // Apply any bonus our target gives us.
  1041. if ( pTarget )
  1042. {
  1043. bool bInRespawnRoom =
  1044. PointInRespawnRoom( pTarget, WorldSpaceCenter() ) ||
  1045. PointInRespawnRoom( pOwner, WorldSpaceCenter() );
  1046. if ( !bInRespawnRoom )
  1047. {
  1048. CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( pTarget, flChargeAmount, mult_uberchargerate_for_healer );
  1049. }
  1050. }
  1051. if ( TFGameRules() )
  1052. {
  1053. if ( TFGameRules()->IsQuickBuildTime() )
  1054. {
  1055. flChargeAmount *= 4.f;
  1056. }
  1057. else if ( TFGameRules()->InSetup() && TFGameRules()->GetActiveRoundTimer() )
  1058. {
  1059. flChargeAmount *= 3.f;
  1060. }
  1061. }
  1062. #endif
  1063. float flNewLevel = MIN( m_flChargeLevel + flChargeAmount, 1.0 );
  1064. float flMinChargeAmount = GetMinChargeAmount();
  1065. if ( flNewLevel >= flMinChargeAmount && m_flChargeLevel < flMinChargeAmount )
  1066. {
  1067. #ifdef GAME_DLL
  1068. pOwner->SpeakConceptIfAllowed( MP_CONCEPT_MEDIC_CHARGEREADY );
  1069. pTFPlayer->SpeakConceptIfAllowed( MP_CONCEPT_HEALTARGET_CHARGEREADY );
  1070. #else
  1071. // send a message that we've got charge
  1072. // if you change this from being a client-side only event, you have to
  1073. // fix ACHIEVEMENT_TF_MEDIC_KILL_WHILE_CHARGED to check the medic userid.
  1074. IGameEvent *event = gameeventmanager->CreateEvent( "localplayer_chargeready" );
  1075. if ( event )
  1076. {
  1077. gameeventmanager->FireEventClientSide( event );
  1078. }
  1079. #endif
  1080. }
  1081. #ifdef CLIENT_DLL
  1082. if ( GetMedigunType() == MEDIGUN_RESIST )
  1083. {
  1084. // Play a sound when we tick over to a new charge level
  1085. int nChargeLevel = int(floor(flNewLevel/flMinChargeAmount));
  1086. float flNextChargeLevelAmount = nChargeLevel * flMinChargeAmount;
  1087. if( flNewLevel >= flNextChargeLevelAmount && m_flChargeLevel < flNextChargeLevelAmount )
  1088. {
  1089. const char* pzsSoundName = CFmtStr( "WeaponMedigun_Vaccinator.Charged_tier_0%d", nChargeLevel );
  1090. if ( nChargeLevel == 1 )
  1091. {
  1092. if ( m_pChargedSound != NULL )
  1093. {
  1094. CSoundEnvelopeController::GetController().SoundDestroy( m_pChargedSound );
  1095. m_pChargedSound = NULL;
  1096. }
  1097. CLocalPlayerFilter filter;
  1098. CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController();
  1099. m_pChargedSound = controller.SoundCreate( filter, entindex(), pzsSoundName );
  1100. controller.Play( m_pChargedSound, 1.0, 100 );
  1101. }
  1102. else
  1103. {
  1104. pOwner->EmitSound( pzsSoundName );
  1105. }
  1106. }
  1107. }
  1108. #endif
  1109. SetChargeLevel( flNewLevel );
  1110. }
  1111. else if ( IsAttachedToBuilding() )
  1112. {
  1113. m_flChargeLevel = MIN( m_flChargeLevel + flChargeAmount, 1.0 );
  1114. }
  1115. }
  1116. }
  1117. return bFound;
  1118. }
  1119. //-----------------------------------------------------------------------------
  1120. // Purpose:
  1121. //-----------------------------------------------------------------------------
  1122. void CWeaponMedigun::ItemHolsterFrame( void )
  1123. {
  1124. BaseClass::ItemHolsterFrame();
  1125. DrainCharge();
  1126. }
  1127. //-----------------------------------------------------------------------------
  1128. // Purpose:
  1129. //-----------------------------------------------------------------------------
  1130. void CWeaponMedigun::DrainCharge( void )
  1131. {
  1132. // If we're in charge release mode, drain our charge
  1133. if ( m_bChargeRelease )
  1134. {
  1135. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  1136. if ( !pOwner )
  1137. return;
  1138. int flUberTime = weapon_medigun_chargerelease_rate.GetFloat();
  1139. CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( pOwner, flUberTime, add_uber_time );
  1140. float flChargeAmount = gpGlobals->frametime / flUberTime;
  1141. float flExtraPlayerCost = flChargeAmount * 0.5;
  1142. // Drain faster the more targets we're applying to. Extra targets count for 50% drain to still reward juggling somewhat.
  1143. for ( int i = m_DetachedTargets.Count()-1; i >= 0; i-- )
  1144. {
  1145. if ( m_DetachedTargets[i].hTarget == NULL || m_DetachedTargets[i].hTarget.Get() == m_hHealingTarget.Get() ||
  1146. !m_DetachedTargets[i].hTarget->IsAlive() || m_DetachedTargets[i].flTime < (gpGlobals->curtime - tf_invuln_time.GetFloat()) )
  1147. {
  1148. m_DetachedTargets.Remove(i);
  1149. }
  1150. else
  1151. {
  1152. flChargeAmount += flExtraPlayerCost;
  1153. }
  1154. }
  1155. SubtractChargeAndUpdateDeployState( flChargeAmount, false );
  1156. }
  1157. }
  1158. void CWeaponMedigun::SubtractChargeAndUpdateDeployState( float flSubtractAmount, bool bForceDrain )
  1159. {
  1160. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  1161. if ( !pOwner )
  1162. return;
  1163. float flNewCharge = Max( m_flChargeLevel - flSubtractAmount, 0.0f );
  1164. if( GetMedigunType() == MEDIGUN_RESIST )
  1165. {
  1166. if( flNewCharge <= m_flEndResistCharge )
  1167. {
  1168. // If the player is holding down ATTACK2 and they have a bar of Uber left,
  1169. // let them burn straight into the next bar
  1170. if( (m_flEndResistCharge > 0) && m_bAttack2Down )
  1171. {
  1172. float flChunkSize = GetMinChargeAmount();
  1173. int nCurrentChunk = floor(m_flChargeLevel / flChunkSize);
  1174. m_flEndResistCharge = flChunkSize * Max( 0, (nCurrentChunk - 1) );
  1175. #ifdef GAME_DLL
  1176. UberchargeChunkDeployed();
  1177. #endif
  1178. }
  1179. else
  1180. {
  1181. // Make sure we don't cross over too far if this is a natural drain
  1182. if( !bForceDrain )
  1183. {
  1184. flNewCharge = m_flEndResistCharge;
  1185. }
  1186. m_flEndResistCharge = 0.f;
  1187. // Stop deploying
  1188. m_bChargeRelease = false;
  1189. m_flReleaseStartedAt = 0;
  1190. m_DetachedTargets.Purge();
  1191. #ifdef GAME_DLL
  1192. pOwner->ClearPunchVictims();
  1193. RecalcEffectOnTarget( pOwner );
  1194. #endif
  1195. }
  1196. }
  1197. }
  1198. m_flChargeLevel = flNewCharge;
  1199. if ( !m_flChargeLevel )
  1200. {
  1201. m_bChargeRelease = false;
  1202. m_flReleaseStartedAt = 0;
  1203. m_DetachedTargets.Purge();
  1204. #ifdef GAME_DLL
  1205. pOwner->ClearPunchVictims();
  1206. RecalcEffectOnTarget( pOwner );
  1207. StopHealingOwner(); // QuickFix uber heals the target and medic
  1208. #endif
  1209. }
  1210. }
  1211. //-----------------------------------------------------------------------------
  1212. // Purpose: Overloaded to handle the hold-down healing
  1213. //-----------------------------------------------------------------------------
  1214. void CWeaponMedigun::ItemPostFrame( void )
  1215. {
  1216. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  1217. if ( !pOwner )
  1218. return;
  1219. // If we're lowered, we're not allowed to fire
  1220. if ( CanAttack() == false )
  1221. {
  1222. RemoveHealingTarget( true );
  1223. return;
  1224. }
  1225. #if !defined( CLIENT_DLL )
  1226. if ( AppliesModifier() )
  1227. {
  1228. m_DamageModifier.SetModifier( weapon_medigun_damage_modifier.GetFloat() );
  1229. }
  1230. #endif
  1231. // Try to start healing
  1232. m_bAttacking = false;
  1233. if ( pOwner->GetMedigunAutoHeal() )
  1234. {
  1235. if ( pOwner->m_nButtons & IN_ATTACK )
  1236. {
  1237. if ( m_bCanChangeTarget )
  1238. {
  1239. RemoveHealingTarget();
  1240. #if defined( CLIENT_DLL )
  1241. if (prediction->IsFirstTimePredicted() ) {
  1242. m_bPlayingSound = false;
  1243. StopHealSound();
  1244. }
  1245. #endif
  1246. // can't change again until we release the attack button
  1247. m_bCanChangeTarget = false;
  1248. }
  1249. }
  1250. else
  1251. {
  1252. m_bCanChangeTarget = true;
  1253. }
  1254. if ( m_bHealing && ( m_iState != WEAPON_IS_ACTIVE || pOwner->IsTaunting() ) )
  1255. {
  1256. RemoveHealingTarget();
  1257. }
  1258. else if ( m_bHealing || ( pOwner->m_nButtons & IN_ATTACK ) )
  1259. {
  1260. PrimaryAttack();
  1261. m_bAttacking = true;
  1262. }
  1263. }
  1264. else
  1265. {
  1266. if ( /*m_bChargeRelease || */ pOwner->m_nButtons & IN_ATTACK )
  1267. {
  1268. PrimaryAttack();
  1269. m_bAttacking = true;
  1270. }
  1271. else if ( m_bHealing )
  1272. {
  1273. // Detach from the player if they release the attack button.
  1274. RemoveHealingTarget();
  1275. }
  1276. }
  1277. if ( pOwner->m_nButtons & IN_ATTACK2 )
  1278. {
  1279. SecondaryAttack();
  1280. }
  1281. else
  1282. {
  1283. m_bAttack2Down = false;
  1284. }
  1285. if( (pOwner->m_nButtons & IN_ATTACK3) && !m_bAttack3Down )
  1286. {
  1287. CreateMedigunShield();
  1288. m_bAttack3Down = true;
  1289. }
  1290. else if( !(pOwner->m_nButtons & IN_ATTACK3) && m_bAttack3Down )
  1291. {
  1292. m_bAttack3Down = false;
  1293. }
  1294. if ( pOwner->m_nButtons & IN_RELOAD && !m_bReloadDown )
  1295. {
  1296. #ifdef GAME_DLL
  1297. CycleResistType();
  1298. #endif
  1299. m_bReloadDown = true;
  1300. }
  1301. else if ( !(pOwner->m_nButtons & IN_RELOAD) && m_bReloadDown )
  1302. {
  1303. m_bReloadDown = false;
  1304. }
  1305. WeaponIdle();
  1306. }
  1307. //-----------------------------------------------------------------------------
  1308. // Purpose:
  1309. //-----------------------------------------------------------------------------
  1310. bool CWeaponMedigun::Lower( void )
  1311. {
  1312. // Stop healing if we are
  1313. if ( m_bHealing )
  1314. {
  1315. RemoveHealingTarget( true );
  1316. m_bAttacking = false;
  1317. #ifdef CLIENT_DLL
  1318. UpdateEffects();
  1319. #endif
  1320. }
  1321. return BaseClass::Lower();
  1322. }
  1323. //-----------------------------------------------------------------------------
  1324. // Purpose:
  1325. //-----------------------------------------------------------------------------
  1326. void CWeaponMedigun::RemoveHealingTarget( bool bStopHealingSelf )
  1327. {
  1328. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  1329. if ( !pOwner )
  1330. return;
  1331. // If this guy is already in our detached target list, update the time. Otherwise, add him.
  1332. if ( m_bChargeRelease )
  1333. {
  1334. int i = 0;
  1335. for ( i = 0; i < m_DetachedTargets.Count(); i++ )
  1336. {
  1337. if ( m_DetachedTargets[i].hTarget == m_hHealingTarget )
  1338. {
  1339. m_DetachedTargets[i].flTime = gpGlobals->curtime;
  1340. break;
  1341. }
  1342. }
  1343. if ( i == m_DetachedTargets.Count() )
  1344. {
  1345. int iIdx = m_DetachedTargets.AddToTail();
  1346. m_DetachedTargets[iIdx].hTarget = m_hHealingTarget;
  1347. m_DetachedTargets[iIdx].flTime = gpGlobals->curtime;
  1348. }
  1349. }
  1350. #ifdef GAME_DLL
  1351. int nMedigunType = GetMedigunType();
  1352. if ( m_hHealingTarget )
  1353. {
  1354. // HACK: For now, just deal with players
  1355. if ( m_hHealingTarget->IsPlayer() )
  1356. {
  1357. CTFPlayer *pTFPlayer = ToTFPlayer( m_hHealingTarget );
  1358. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  1359. if ( pTFPlayer && pOwner )
  1360. {
  1361. pTFPlayer->m_Shared.StopHealing( pOwner );
  1362. pOwner->SpeakConceptIfAllowed( MP_CONCEPT_MEDIC_STOPPEDHEALING, pTFPlayer->IsAlive() ? "healtarget:alive" : "healtarget:dead" );
  1363. pTFPlayer->SpeakConceptIfAllowed( MP_CONCEPT_HEALTARGET_STOPPEDHEALING );
  1364. // If we're grappled to this player, drop
  1365. if ( pOwner->GetGrapplingHookTarget() == pTFPlayer )
  1366. {
  1367. pOwner->SetGrapplingHookTarget( NULL );
  1368. }
  1369. // Remove our passive resist
  1370. if( nMedigunType == MEDIGUN_RESIST )
  1371. {
  1372. ETFCond cond = g_MedigunResistConditions[ GetResistType() ].passiveCond;
  1373. CBaseEntity* pProvider = pTFPlayer->m_Shared.GetConditionProvider( cond );
  1374. // Remove from our healing target if we're the provider
  1375. if( pProvider == pOwner || pProvider == NULL )
  1376. {
  1377. pTFPlayer->m_Shared.RemoveCond( cond );
  1378. }
  1379. // Remove from ourselves if we're the provider
  1380. pProvider = pOwner->m_Shared.GetConditionProvider( cond );
  1381. if( pProvider == pOwner || pProvider == NULL )
  1382. {
  1383. pOwner->m_Shared.RemoveCond( cond );
  1384. }
  1385. }
  1386. }
  1387. }
  1388. }
  1389. // Stop thinking - we no longer have a heal target.
  1390. SetContextThink( NULL, 0, s_pszMedigunHealTargetThink );
  1391. #endif
  1392. m_hHealingTarget.Set( NULL );
  1393. #ifdef GAME_DLL
  1394. // See if we have The QuickFix, which adjusts our move speed based on heal target
  1395. pOwner->TeamFortress_SetSpeed();
  1396. #endif
  1397. // Stop the welding animation
  1398. if ( m_bHealing )
  1399. {
  1400. SendWeaponAnim( ACT_MP_ATTACK_STAND_POSTFIRE );
  1401. pOwner->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_POST );
  1402. }
  1403. #ifndef CLIENT_DLL
  1404. m_DamageModifier.RemoveModifier();
  1405. #endif
  1406. m_bHealing = false;
  1407. }
  1408. //-----------------------------------------------------------------------------
  1409. // Purpose: Attempt to heal any player within range of the medikit
  1410. //-----------------------------------------------------------------------------
  1411. void CWeaponMedigun::PrimaryAttack( void )
  1412. {
  1413. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  1414. if ( !pOwner )
  1415. return;
  1416. if ( !CanAttack() )
  1417. return;
  1418. #ifdef GAME_DLL
  1419. /*
  1420. // Start boosting ourself if we're not
  1421. if ( m_bChargeRelease && !m_bHealingSelf )
  1422. {
  1423. pOwner->m_Shared.Heal( pOwner, GetHealRate() * 2 );
  1424. m_bHealingSelf = true;
  1425. }
  1426. */
  1427. #endif
  1428. #if !defined (CLIENT_DLL)
  1429. if ( tf_medigun_lagcomp.GetBool() )
  1430. lagcompensation->StartLagCompensation( pOwner, pOwner->GetCurrentCommand() );
  1431. #endif
  1432. if ( FindAndHealTargets() )
  1433. {
  1434. // Start the animation
  1435. if ( !m_bHealing )
  1436. {
  1437. #ifdef GAME_DLL
  1438. pOwner->SpeakWeaponFire();
  1439. #endif
  1440. SendWeaponAnim( ACT_MP_ATTACK_STAND_PREFIRE );
  1441. pOwner->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRE );
  1442. }
  1443. m_bHealing = true;
  1444. }
  1445. else
  1446. {
  1447. RemoveHealingTarget();
  1448. }
  1449. #if !defined (CLIENT_DLL)
  1450. if ( tf_medigun_lagcomp.GetBool() )
  1451. lagcompensation->FinishLagCompensation( pOwner );
  1452. #endif
  1453. }
  1454. //-----------------------------------------------------------------------------
  1455. // Purpose: Burn charge level to generate invulnerability
  1456. //-----------------------------------------------------------------------------
  1457. void CWeaponMedigun::SecondaryAttack( void )
  1458. {
  1459. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  1460. if ( !pOwner )
  1461. return;
  1462. if ( !CanAttack() )
  1463. return;
  1464. CTFPlayer *pTFPlayerPatient = NULL;
  1465. if ( m_hHealingTarget && m_hHealingTarget->IsPlayer() )
  1466. {
  1467. pTFPlayerPatient = ToTFPlayer( m_hHealingTarget );
  1468. }
  1469. // STAGING_MEDIC
  1470. // Resist gun early outs if the patient and medic both have the condition (or medic with no patient has condition)
  1471. if ( GetMedigunType() == MEDIGUN_RESIST )
  1472. {
  1473. ETFCond uberCond = g_MedigunResistConditions[GetResistType()].uberCond;
  1474. if ( pOwner->m_Shared.InCond( uberCond ) )
  1475. {
  1476. if ( !pTFPlayerPatient || pTFPlayerPatient->m_Shared.InCond( uberCond ) )
  1477. {
  1478. return;
  1479. }
  1480. }
  1481. }
  1482. m_bAttack2Down = true;
  1483. // If using standard-uber-model-medigun, ensure they have a full charge and are not already in charge release mode
  1484. bool bDenyUse = GetMedigunType() != MEDIGUN_RESIST && (m_flChargeLevel < 1.0);
  1485. // If using the resist-medigun, they can shoot sooner
  1486. float flChunkSize = GetMinChargeAmount();
  1487. bDenyUse |= GetMedigunType() == MEDIGUN_RESIST && m_flChargeLevel < flChunkSize;
  1488. if ( bDenyUse || m_bChargeRelease )
  1489. {
  1490. #ifdef CLIENT_DLL
  1491. // Deny, flash
  1492. if ( !m_bChargeRelease && gpGlobals->curtime >= m_flDenySecondary )
  1493. {
  1494. m_flDenySecondary = gpGlobals->curtime + 0.5f;
  1495. pOwner->EmitSound( "Player.DenyWeaponSelection" );
  1496. }
  1497. #endif
  1498. return;
  1499. }
  1500. if ( !pOwner->m_Shared.CanRecieveMedigunChargeEffect( GetChargeType() ) )
  1501. {
  1502. if ( pOwner->m_afButtonPressed & IN_ATTACK2
  1503. #ifdef CLIENT_DLL
  1504. && prediction->IsFirstTimePredicted()
  1505. #endif
  1506. )
  1507. {
  1508. #ifdef GAME_DLL
  1509. CSingleUserRecipientFilter filter( pOwner );
  1510. TFGameRules()->SendHudNotification( filter, HUD_NOTIFY_NO_INVULN_WITH_FLAG );
  1511. #else
  1512. pOwner->EmitSound( "Player.DenyWeaponSelection" );
  1513. #endif
  1514. }
  1515. return;
  1516. }
  1517. // Toggle super charge state
  1518. m_bChargeRelease = true;
  1519. m_flReleaseStartedAt = gpGlobals->curtime;
  1520. #ifdef GAME_DLL
  1521. if( GetMedigunType() == MEDIGUN_RESIST )
  1522. {
  1523. // We dont want to give the user a point every time they deploy an uber with the resist medigun.
  1524. // Instead we give them a point for every 4 deploys
  1525. UberchargeChunkDeployed();
  1526. int nCurrentChunk = floor( m_flChargeLevel / flChunkSize );
  1527. Assert( nCurrentChunk >= 1 );
  1528. CPVSFilter filter( pOwner->WorldSpaceCenter() );
  1529. pOwner->EmitSound( filter, pOwner->entindex(), CFmtStr( "WeaponMedigun_Vaccinator.Charged_tier_0%d", nCurrentChunk ) );
  1530. pOwner->EmitSound( filter, pOwner->entindex(), g_MedigunEffects[MEDIGUN_CHARGE_BULLET_RESIST].pszChargeOnSound );
  1531. }
  1532. else
  1533. {
  1534. // Award assist point
  1535. CTF_GameStats.Event_PlayerInvulnerable( pOwner );
  1536. // Award strange assist score
  1537. EconEntity_OnOwnerKillEaterEvent( this, pOwner, ToTFPlayer( m_hHealingTarget ), kKillEaterEvent_UberActivated );
  1538. }
  1539. // STAGING_MEDIC
  1540. if ( GetMedigunType() != MEDIGUN_RESIST )
  1541. {
  1542. RecalcEffectOnTarget( pOwner );
  1543. }
  1544. pOwner->SpeakConceptIfAllowed( MP_CONCEPT_MEDIC_CHARGEDEPLOYED );
  1545. if ( pTFPlayerPatient )
  1546. {
  1547. // STAGING_MEDIC
  1548. if ( GetMedigunType() != MEDIGUN_RESIST )
  1549. {
  1550. RecalcEffectOnTarget( pTFPlayerPatient );
  1551. }
  1552. pTFPlayerPatient->SpeakConceptIfAllowed( MP_CONCEPT_HEALTARGET_CHARGEDEPLOYED );
  1553. }
  1554. IGameEvent * event = gameeventmanager->CreateEvent( "player_chargedeployed" );
  1555. if ( event )
  1556. {
  1557. event->SetInt( "userid", pOwner->GetUserID() );
  1558. if ( m_hHealingTarget && m_hHealingTarget->IsPlayer() )
  1559. {
  1560. event->SetInt( "targetid", ToTFPlayer(m_hHealingTarget)->GetUserID() );
  1561. }
  1562. gameeventmanager->FireEvent( event );
  1563. }
  1564. // Check for achievements
  1565. // Simultaneous uber charge with teammates.
  1566. CTeam *pTeam = pOwner->GetTeam();
  1567. if ( pTeam )
  1568. {
  1569. CUtlVector<CTFPlayer*> aChargingMedics;
  1570. aChargingMedics.AddToTail( pOwner );
  1571. for ( int i = 0; i < pTeam->GetNumPlayers(); i++ )
  1572. {
  1573. CTFPlayer *pTeamPlayer = ToTFPlayer( pTeam->GetPlayer(i) );
  1574. if ( pTeamPlayer && pTeamPlayer->IsPlayerClass( TF_CLASS_MEDIC ) && pTeamPlayer != pOwner )
  1575. {
  1576. CWeaponMedigun *pWeapon = dynamic_cast <CWeaponMedigun*>( pTeamPlayer->GetActiveWeapon() );
  1577. if ( pWeapon && pWeapon->IsReleasingCharge() )
  1578. {
  1579. aChargingMedics.AddToTail( pTeamPlayer );
  1580. }
  1581. }
  1582. }
  1583. if ( aChargingMedics.Count() >= 3 )
  1584. {
  1585. // Give the achievement to all the Medics
  1586. for ( int i = 0; i < aChargingMedics.Count(); i++ )
  1587. {
  1588. if ( aChargingMedics[i] )
  1589. {
  1590. aChargingMedics[i]->AwardAchievement( ACHIEVEMENT_TF_MEDIC_SIMUL_CHARGE );
  1591. }
  1592. }
  1593. }
  1594. }
  1595. // reset this count
  1596. pOwner->HandleAchievement_Medic_AssistHeavy( NULL );
  1597. // If using the QuickFix, heal the medic
  1598. if ( GetMedigunType() == MEDIGUN_QUICKFIX )
  1599. {
  1600. if ( IsReleasingCharge() && !m_bHealingSelf )
  1601. {
  1602. StartHealingTarget( pOwner );
  1603. m_bHealingSelf = true;
  1604. }
  1605. }
  1606. #endif // GAME_DLL
  1607. // STAGING_MEDIC
  1608. if ( GetMedigunType() == MEDIGUN_RESIST )
  1609. {
  1610. // Remove charge immediately and just give target and yourself the conditions
  1611. m_bChargeRelease = false;
  1612. #ifdef GAME_DLL
  1613. int iResistDuration = 3.0f;
  1614. pOwner->m_Shared.AddCond( g_MedigunResistConditions[GetResistType()].uberCond, iResistDuration, pOwner );
  1615. m_flChargeLevel -= flChunkSize;
  1616. if ( pTFPlayerPatient )
  1617. {
  1618. pTFPlayerPatient->m_Shared.AddCond( g_MedigunResistConditions[GetResistType()].uberCond, iResistDuration, pOwner );
  1619. }
  1620. if ( TFGameRules() && TFGameRules()->IsMannVsMachineMode() )
  1621. {
  1622. CBaseEntity *pTarget = m_hHealingTarget;
  1623. CTFReviveMarker *pReviveMarker = dynamic_cast<CTFReviveMarker*>( pTarget );
  1624. if ( pReviveMarker )
  1625. {
  1626. CTFPlayer *pDeadPlayer = pReviveMarker->GetOwner();
  1627. if ( pDeadPlayer )
  1628. {
  1629. pReviveMarker->SetReviver( pOwner );
  1630. // fill almost to max, give a small time period so patient has time to see notifications from regular revive code
  1631. pReviveMarker->AddMarkerHealth( pReviveMarker->GetMaxHealth() * 0.9f );
  1632. }
  1633. }
  1634. }
  1635. #endif
  1636. }
  1637. }
  1638. //-----------------------------------------------------------------------------
  1639. // Purpose: Idle tests to see if we're facing a valid target for the medikit
  1640. // If so, move into the "heal-able" animation.
  1641. // Otherwise, move into the "not-heal-able" animation.
  1642. //-----------------------------------------------------------------------------
  1643. void CWeaponMedigun::WeaponIdle( void )
  1644. {
  1645. if ( HasWeaponIdleTimeElapsed() )
  1646. {
  1647. // Loop the welding animation
  1648. if ( m_bHealing )
  1649. {
  1650. SendWeaponAnim( ACT_VM_PRIMARYATTACK );
  1651. return;
  1652. }
  1653. return BaseClass::WeaponIdle();
  1654. }
  1655. }
  1656. #if defined( CLIENT_DLL )
  1657. //-----------------------------------------------------------------------------
  1658. // Purpose:
  1659. //-----------------------------------------------------------------------------
  1660. void CWeaponMedigun::StopHealSound( bool bStopHealingSound, bool bStopNoTargetSound )
  1661. {
  1662. if ( bStopHealingSound )
  1663. {
  1664. StopSound( GetHealSound() );
  1665. }
  1666. if ( bStopNoTargetSound )
  1667. {
  1668. StopSound( "WeaponMedigun.NoTarget" );
  1669. }
  1670. if ( m_pDisruptSound )
  1671. {
  1672. CSoundEnvelopeController::GetController().SoundDestroy( m_pDisruptSound );
  1673. m_pDisruptSound = NULL;
  1674. }
  1675. }
  1676. void CWeaponMedigun::StopChargeEffect( bool bImmediately )
  1677. {
  1678. // Either these should both be NULL or neither NULL
  1679. Assert( ( m_pChargeEffect != NULL && m_pChargeEffectOwner != NULL ) || ( m_pChargeEffect == NULL && m_pChargeEffectOwner == NULL ) );
  1680. if ( m_pChargeEffect != NULL && m_pChargeEffectOwner != NULL )
  1681. {
  1682. if( bImmediately )
  1683. {
  1684. m_pChargeEffectOwner->ParticleProp()->StopEmissionAndDestroyImmediately( m_pChargeEffect );
  1685. }
  1686. else
  1687. {
  1688. m_pChargeEffectOwner->ParticleProp()->StopEmission( m_pChargeEffect );
  1689. }
  1690. m_pChargeEffect = NULL;
  1691. m_pChargeEffectOwner = NULL;
  1692. }
  1693. if ( m_pChargedSound != NULL )
  1694. {
  1695. CSoundEnvelopeController::GetController().SoundDestroy( m_pChargedSound );
  1696. m_pChargedSound = NULL;
  1697. }
  1698. }
  1699. //-----------------------------------------------------------------------------
  1700. // Purpose:
  1701. //-----------------------------------------------------------------------------
  1702. void CWeaponMedigun::ManageChargeEffect( void )
  1703. {
  1704. C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
  1705. C_BaseEntity *pEffectOwner = this;
  1706. if ( pLocalPlayer == NULL )
  1707. return;
  1708. if ( pLocalPlayer == GetTFPlayerOwner() )
  1709. {
  1710. pEffectOwner = pLocalPlayer->GetRenderedWeaponModel();
  1711. if ( !pEffectOwner )
  1712. {
  1713. return;
  1714. }
  1715. }
  1716. bool bOwnerTaunting = false;
  1717. if ( GetTFPlayerOwner() && GetTFPlayerOwner()->m_Shared.InCond( TF_COND_TAUNTING ) == true )
  1718. {
  1719. bOwnerTaunting = true;
  1720. }
  1721. float flMinChargeToDeploy = GetMinChargeAmount();
  1722. if ( GetTFPlayerOwner() && bOwnerTaunting == false && m_bHolstered == false && ( m_flChargeLevel >= flMinChargeToDeploy || m_bChargeRelease == true ) )
  1723. {
  1724. // Did we switch from 1st to 3rd or 3rd to 1st? Taunting does this.
  1725. if( pEffectOwner != m_pChargeEffectOwner )
  1726. {
  1727. // Stop the current effect so we can make a new one
  1728. StopChargeEffect( m_bHolstered );
  1729. }
  1730. if ( m_pChargeEffect == NULL )
  1731. {
  1732. const char *pszEffectName = NULL;
  1733. switch( GetTFPlayerOwner()->GetTeamNumber() )
  1734. {
  1735. case TF_TEAM_BLUE:
  1736. pszEffectName = "medicgun_invulnstatus_fullcharge_blue";
  1737. break;
  1738. case TF_TEAM_RED:
  1739. pszEffectName = "medicgun_invulnstatus_fullcharge_red";
  1740. break;
  1741. default:
  1742. pszEffectName = "";
  1743. break;
  1744. }
  1745. m_pChargeEffect = pEffectOwner->ParticleProp()->Create( pszEffectName, PATTACH_POINT_FOLLOW, "muzzle" );
  1746. m_pChargeEffectOwner = pEffectOwner;
  1747. }
  1748. if ( m_pChargedSound == NULL )
  1749. {
  1750. CLocalPlayerFilter filter;
  1751. CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController();
  1752. m_pChargedSound = controller.SoundCreate( filter, entindex(), "WeaponMedigun.Charged" );
  1753. controller.Play( m_pChargedSound, 1.0, 100 );
  1754. }
  1755. }
  1756. else
  1757. {
  1758. StopChargeEffect( m_bHolstered );
  1759. }
  1760. }
  1761. //-----------------------------------------------------------------------------
  1762. // Purpose:
  1763. // Input : updateType -
  1764. //-----------------------------------------------------------------------------
  1765. void CWeaponMedigun::OnDataChanged( DataUpdateType_t updateType )
  1766. {
  1767. BaseClass::OnDataChanged( updateType );
  1768. if ( m_bUpdateHealingTargets )
  1769. {
  1770. UpdateEffects();
  1771. m_bUpdateHealingTargets = false;
  1772. }
  1773. if ( m_nOldChargeResistType != m_nChargeResistType )
  1774. {
  1775. m_nOldChargeResistType = m_nChargeResistType;
  1776. C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
  1777. if( GetOwner() == pLocalPlayer && pLocalPlayer )
  1778. {
  1779. // Sound effect
  1780. pLocalPlayer->EmitSound( "WeaponMedigun_Vaccinator.Toggle" );
  1781. }
  1782. }
  1783. if ( m_bHealing )
  1784. {
  1785. CTFPlayer *pTarget = ToTFPlayer( m_hHealingTarget );
  1786. if ( !m_pDisruptSound && pTarget && pTarget->m_Shared.InCond( TF_COND_HEALING_DEBUFF ) )
  1787. {
  1788. CLocalPlayerFilter filter;
  1789. CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController();
  1790. m_pDisruptSound = controller.SoundCreate( filter, entindex(), "WeaponMedigun.HealingDisrupt" );
  1791. controller.Play( m_pDisruptSound, 1.f, 100.f );
  1792. }
  1793. else if ( m_pDisruptSound )
  1794. {
  1795. CSoundEnvelopeController::GetController().SoundDestroy( m_pDisruptSound );
  1796. m_pDisruptSound = NULL;
  1797. }
  1798. }
  1799. else
  1800. {
  1801. ClientThinkList()->SetNextClientThink( GetClientHandle(), CLIENT_THINK_NEVER );
  1802. m_bPlayingSound = false;
  1803. StopHealSound( true, false );
  1804. // Are they holding the attack button but not healing anyone? Give feedback.
  1805. if ( IsActiveByLocalPlayer() && GetOwner() && GetOwner()->IsAlive() && m_bAttacking && GetOwner() == C_BasePlayer::GetLocalPlayer() && CanAttack() == true )
  1806. {
  1807. if ( gpGlobals->curtime >= m_flNextBuzzTime )
  1808. {
  1809. CLocalPlayerFilter filter;
  1810. EmitSound( filter, entindex(), "WeaponMedigun.NoTarget" );
  1811. m_flNextBuzzTime = gpGlobals->curtime + 0.5f; // only buzz every so often.
  1812. }
  1813. }
  1814. else
  1815. {
  1816. StopHealSound( false, true ); // Stop the "no target" sound.
  1817. }
  1818. }
  1819. // Think?
  1820. if ( m_bHealing || IsCarriedByLocalPlayer() )
  1821. {
  1822. ClientThinkList()->SetNextClientThink( GetClientHandle(), CLIENT_THINK_ALWAYS );
  1823. }
  1824. ManageChargeEffect();
  1825. // Find teammates that need healing
  1826. if ( IsCarriedByLocalPlayer() )
  1827. {
  1828. C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
  1829. if ( !pLocalPlayer || !pLocalPlayer->IsPlayerClass( TF_CLASS_MEDIC ) )
  1830. {
  1831. return;
  1832. }
  1833. if ( pLocalPlayer == GetOwner() && hud_medicautocallers.GetBool() )
  1834. {
  1835. UpdateMedicAutoCallers();
  1836. }
  1837. }
  1838. }
  1839. //-----------------------------------------------------------------------------
  1840. // Purpose:
  1841. //-----------------------------------------------------------------------------
  1842. void CWeaponMedigun::ClientThink()
  1843. {
  1844. C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
  1845. if ( !pLocalPlayer )
  1846. {
  1847. return;
  1848. }
  1849. // Don't show it while the player is dead. Ideally, we'd respond to m_bHealing in OnDataChanged,
  1850. // but it stops sending the weapon when it's holstered, and it gets holstered when the player dies.
  1851. CTFPlayer *pFiringPlayer = ToTFPlayer( GetOwnerEntity() );
  1852. if ( !pFiringPlayer || pFiringPlayer->IsPlayerDead() || pFiringPlayer->IsDormant() )
  1853. {
  1854. ClientThinkList()->SetNextClientThink( GetClientHandle(), CLIENT_THINK_NEVER );
  1855. m_bPlayingSound = false;
  1856. StopHealSound();
  1857. return;
  1858. }
  1859. // If the local player is the guy getting healed, let him know
  1860. // who's healing him, and their charge level.
  1861. if( m_hHealingTarget != NULL )
  1862. {
  1863. if ( pLocalPlayer == m_hHealingTarget )
  1864. {
  1865. pLocalPlayer->SetHealer( pFiringPlayer, m_flChargeLevel );
  1866. }
  1867. // Setup whether we were last healed by the local player or by someone else (used by replay system)
  1868. // since GetHealer() gets cleared out every frame before player_death events get fired. See tf_replay.cpp.
  1869. C_BaseEntity *pHealingTargetEnt = m_hHealingTarget;
  1870. if ( pHealingTargetEnt && pHealingTargetEnt->IsPlayer() )
  1871. {
  1872. C_TFPlayer *pHealingTargetPlayer = ToTFPlayer( pHealingTargetEnt );
  1873. pHealingTargetPlayer->SetWasHealedByLocalPlayer( pFiringPlayer == pLocalPlayer );
  1874. }
  1875. if ( !m_bPlayingSound )
  1876. {
  1877. m_bPlayingSound = true;
  1878. CLocalPlayerFilter filter;
  1879. EmitSound( filter, entindex(), GetHealSound() );
  1880. }
  1881. }
  1882. if ( m_bOldChargeRelease != m_bChargeRelease )
  1883. {
  1884. m_bOldChargeRelease = m_bChargeRelease;
  1885. ForceHealingTargetUpdate();
  1886. }
  1887. // If the rendered weapon has changed, we need to update our particles
  1888. if ( m_hHealingTargetEffect.pOwner && pFiringPlayer->GetRenderedWeaponModel() != m_hHealingTargetEffect.pOwner )
  1889. {
  1890. ForceHealingTargetUpdate();
  1891. }
  1892. if ( pFiringPlayer->m_Shared.IsEnteringOrExitingFullyInvisible() )
  1893. {
  1894. UpdateEffects();
  1895. }
  1896. }
  1897. //-----------------------------------------------------------------------------
  1898. // Purpose:
  1899. //-----------------------------------------------------------------------------
  1900. void CWeaponMedigun::UpdateEffects( void )
  1901. {
  1902. CTFPlayer *pFiringPlayer = ToTFPlayer( GetOwnerEntity() );
  1903. if ( !pFiringPlayer )
  1904. return;
  1905. C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
  1906. C_BaseEntity *pEffectOwner = this;
  1907. if ( pLocalPlayer == pFiringPlayer )
  1908. {
  1909. pEffectOwner = pLocalPlayer->GetRenderedWeaponModel();
  1910. }
  1911. // If we're still healing and our owner changed, then we did something
  1912. // like changed
  1913. bool bImmediate = pEffectOwner != m_hHealingTargetEffect.pOwner && m_bHealing;
  1914. // Remove all the effects
  1915. if ( m_hHealingTargetEffect.pOwner )
  1916. {
  1917. if ( m_hHealingTargetEffect.pEffect )
  1918. {
  1919. bImmediate ? m_hHealingTargetEffect.pOwner->ParticleProp()->StopEmissionAndDestroyImmediately( m_hHealingTargetEffect.pEffect )
  1920. : m_hHealingTargetEffect.pOwner->ParticleProp()->StopEmission( m_hHealingTargetEffect.pEffect );
  1921. }
  1922. if ( m_hHealingTargetEffect.pCustomEffect )
  1923. {
  1924. bImmediate ? m_hHealingTargetEffect.pOwner->ParticleProp()->StopEmissionAndDestroyImmediately( m_hHealingTargetEffect.pCustomEffect )
  1925. : m_hHealingTargetEffect.pOwner->ParticleProp()->StopEmission( m_hHealingTargetEffect.pCustomEffect );
  1926. }
  1927. }
  1928. else
  1929. {
  1930. if ( m_hHealingTargetEffect.pEffect )
  1931. {
  1932. m_hHealingTargetEffect.pEffect->StopEmission();
  1933. }
  1934. if ( m_hHealingTargetEffect.pCustomEffect )
  1935. {
  1936. m_hHealingTargetEffect.pCustomEffect->StopEmission();
  1937. }
  1938. }
  1939. m_hHealingTargetEffect.pOwner = NULL;
  1940. m_hHealingTargetEffect.pTarget = NULL;
  1941. m_hHealingTargetEffect.pEffect = NULL;
  1942. m_hHealingTargetEffect.pCustomEffect = NULL;
  1943. // Don't add targets if the medic is dead
  1944. if ( !pEffectOwner || pFiringPlayer->IsPlayerDead() || !pFiringPlayer->IsPlayerClass( TF_CLASS_MEDIC ) || pFiringPlayer->m_Shared.IsFullyInvisible() )
  1945. return;
  1946. // Add our targets
  1947. // Loops through the healing targets, and make sure we have an effect for each of them
  1948. if ( m_hHealingTarget )
  1949. {
  1950. if ( m_hHealingTargetEffect.pTarget == m_hHealingTarget )
  1951. return;
  1952. bool bReviveMarker = m_hReviveMarker && m_hReviveMarker == m_hHealingTarget; // Hack to avoid another dynamic_cast here
  1953. bool bHealTargetMarker = hud_medichealtargetmarker.GetBool() && !bReviveMarker;
  1954. const char *pszEffectName;
  1955. if ( IsAttachedToBuilding() )
  1956. {
  1957. pszEffectName = "medicgun_beam_machinery";
  1958. }
  1959. else if ( pFiringPlayer->GetTeamNumber() == TF_TEAM_RED )
  1960. {
  1961. if ( m_bChargeRelease )
  1962. {
  1963. pszEffectName = "medicgun_beam_red_invun";
  1964. }
  1965. else
  1966. {
  1967. if ( bHealTargetMarker && pFiringPlayer == pLocalPlayer )
  1968. {
  1969. pszEffectName = "medicgun_beam_red_targeted";
  1970. }
  1971. else
  1972. {
  1973. pszEffectName = "medicgun_beam_red";
  1974. }
  1975. }
  1976. }
  1977. else
  1978. {
  1979. if ( m_bChargeRelease )
  1980. {
  1981. pszEffectName = "medicgun_beam_blue_invun";
  1982. }
  1983. else
  1984. {
  1985. if ( bHealTargetMarker && pFiringPlayer == pLocalPlayer )
  1986. {
  1987. pszEffectName = "medicgun_beam_blue_targeted";
  1988. }
  1989. else
  1990. {
  1991. pszEffectName = "medicgun_beam_blue";
  1992. }
  1993. }
  1994. }
  1995. // Attach differently if targeting a revive marker
  1996. float flVecHeightOffset = bReviveMarker ? 0.f : 50.f;
  1997. ParticleAttachment_t attachType = bReviveMarker ? PATTACH_POINT_FOLLOW : PATTACH_ABSORIGIN_FOLLOW;
  1998. const char *pszAttachName = bReviveMarker ? "healbeam" : NULL;
  1999. CNewParticleEffect *pEffect = pEffectOwner->ParticleProp()->Create( pszEffectName, PATTACH_POINT_FOLLOW, "muzzle" );
  2000. pEffectOwner->ParticleProp()->AddControlPoint( pEffect, 1, m_hHealingTarget, attachType, pszAttachName, Vector(0.f,0.f,flVecHeightOffset) );
  2001. m_hHealingTargetEffect.pTarget = m_hHealingTarget;
  2002. m_hHealingTargetEffect.pEffect = pEffect;
  2003. m_hHealingTargetEffect.pOwner = pEffectOwner;
  2004. // See if we have a custom particle effect that wants to add to the beam
  2005. CEconItemView *pItem = m_AttributeManager.GetItem();
  2006. int iSystems = pItem->GetStaticData()->GetNumAttachedParticles( GetTeamNumber() );
  2007. for ( int i = 0; i < iSystems; i++ )
  2008. {
  2009. attachedparticlesystem_t *pSystem = pItem->GetStaticData()->GetAttachedParticleData( GetTeamNumber(),i );
  2010. if ( pSystem->iCustomType == 1 )
  2011. {
  2012. pEffect = pEffectOwner->ParticleProp()->Create( pSystem->pszSystemName, PATTACH_POINT_FOLLOW, "muzzle" );
  2013. pEffectOwner->ParticleProp()->AddControlPoint( pEffect, 1, m_hHealingTarget, attachType, pszAttachName, Vector(0.f,0.f,flVecHeightOffset) );
  2014. m_hHealingTargetEffect.pCustomEffect = pEffect;
  2015. }
  2016. }
  2017. }
  2018. }
  2019. //-----------------------------------------------------------------------------
  2020. // Purpose: Look for teammates that need healing
  2021. //-----------------------------------------------------------------------------
  2022. void CWeaponMedigun::UpdateMedicAutoCallers( void )
  2023. {
  2024. // Find teammates that need healing
  2025. if ( gpGlobals->curtime > m_flAutoCallerCheckTime )
  2026. {
  2027. if ( !g_TF_PR )
  2028. {
  2029. return;
  2030. }
  2031. C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
  2032. for( int playerIndex = 1; playerIndex <= MAX_PLAYERS; playerIndex++ )
  2033. {
  2034. if ( g_TF_PR->GetTeam( playerIndex ) == GetLocalPlayerTeam() )
  2035. {
  2036. C_TFPlayer *pPlayer = ToTFPlayer( UTIL_PlayerByIndex( playerIndex ) );
  2037. // Don't do this for the local player
  2038. if ( pPlayer == NULL || pPlayer == pLocalPlayer )
  2039. continue;
  2040. if( m_hHealingTarget != NULL )
  2041. {
  2042. // Don't do this for players the medic is healing
  2043. if ( pPlayer == m_hHealingTarget )
  2044. continue;
  2045. }
  2046. if ( pPlayer->IsAlive() )
  2047. {
  2048. int iHealth = float( pPlayer->GetHealth() ) / float( pPlayer->GetMaxHealth() ) * 100;
  2049. int iHealthThreshold = hud_medicautocallersthreshold.GetInt();
  2050. // If it's a healthy teammate....
  2051. if ( iHealth > iHealthThreshold )
  2052. {
  2053. // Make sure we don't have them in our list if previously hurt
  2054. if ( m_iAutoCallers.Find( playerIndex ) != m_iAutoCallers.InvalidIndex() )
  2055. {
  2056. m_iAutoCallers.FindAndRemove( playerIndex );
  2057. continue;
  2058. }
  2059. }
  2060. // If it's a hurt teammate....
  2061. if ( iHealth <= iHealthThreshold )
  2062. {
  2063. // Make sure we're not already tracking this
  2064. if ( m_iAutoCallers.Find( playerIndex ) != m_iAutoCallers.InvalidIndex())
  2065. continue;
  2066. // Distance check
  2067. float flDistSq = pPlayer->GetAbsOrigin().DistToSqr( pLocalPlayer->GetAbsOrigin() );
  2068. if ( flDistSq >= 1000000 )
  2069. {
  2070. continue;
  2071. }
  2072. // Now add auto-caller
  2073. pPlayer->CreateSaveMeEffect( CALLER_TYPE_AUTO );
  2074. // And track the player so we don't re-add them
  2075. m_iAutoCallers.AddToTail( playerIndex );
  2076. }
  2077. }
  2078. }
  2079. }
  2080. // Throttle this check
  2081. m_flAutoCallerCheckTime = gpGlobals->curtime + 0.25f;
  2082. }
  2083. }
  2084. #endif
  2085. //-----------------------------------------------------------------------------
  2086. // Purpose:
  2087. //-----------------------------------------------------------------------------
  2088. void CWeaponMedigun::CheckAchievementsOnHealTarget( void )
  2089. {
  2090. CTFPlayer *pTFPlayer = ToTFPlayer( m_hHealingTarget );
  2091. if ( !pTFPlayer )
  2092. return;
  2093. #ifdef GAME_DLL
  2094. // Check for "target under fire" achievement
  2095. if ( pTFPlayer->m_AchievementData.CountDamagersWithinTime(3.0) >= 4 )
  2096. {
  2097. if ( GetTFPlayerOwner() )
  2098. {
  2099. GetTFPlayerOwner()->AwardAchievement( ACHIEVEMENT_TF_MEDIC_HEAL_UNDER_FIRE );
  2100. }
  2101. }
  2102. // Check for "Engineer repairing sentrygun" achievement
  2103. if ( pTFPlayer->IsPlayerClass( TF_CLASS_ENGINEER ) )
  2104. {
  2105. // Has Engineer worked on his sentrygun recently?
  2106. CBaseObject *pSentry = pTFPlayer->GetObjectOfType( OBJ_SENTRYGUN );
  2107. if ( pSentry && pTFPlayer->m_AchievementData.IsTargetInHistory( pSentry, 4.0 ) )
  2108. {
  2109. if ( pSentry->m_AchievementData.CountDamagersWithinTime(3.0) > 0 )
  2110. {
  2111. CTFPlayer *pOwner = GetTFPlayerOwner();
  2112. if ( pOwner )
  2113. {
  2114. // give to medic
  2115. pOwner->AwardAchievement( ACHIEVEMENT_TF_MEDIC_HEAL_ENGINEER );
  2116. // give to the engineer!
  2117. pTFPlayer->AwardAchievement( ACHIEVEMENT_TF_ENGINEER_REPAIR_SENTRY_W_MEDIC );
  2118. }
  2119. }
  2120. }
  2121. }
  2122. #else
  2123. // check for ACHIEVEMENT_TF_MEDIC_HEAL_CALLERS
  2124. if ( pTFPlayer->m_flSaveMeExpireTime > gpGlobals->curtime )
  2125. {
  2126. IGameEvent *event = gameeventmanager->CreateEvent( "player_healedmediccall" );
  2127. if ( event )
  2128. {
  2129. event->SetInt( "userid", pTFPlayer->GetUserID() );
  2130. gameeventmanager->FireEventClientSide( event );
  2131. }
  2132. }
  2133. #endif
  2134. }
  2135. //-----------------------------------------------------------------------------
  2136. // Purpose: Our owner has become stunned.
  2137. //-----------------------------------------------------------------------------
  2138. void CWeaponMedigun::OnControlStunned( void )
  2139. {
  2140. BaseClass::OnControlStunned();
  2141. // Interrupt auto healing.
  2142. RemoveHealingTarget( true );
  2143. }
  2144. //-----------------------------------------------------------------------------
  2145. // Purpose:
  2146. //-----------------------------------------------------------------------------
  2147. bool CWeaponMedigun::EffectMeterShouldFlash( void )
  2148. {
  2149. CTFPlayer *pPlayer = GetTFPlayerOwner();
  2150. if ( !pPlayer )
  2151. return false;
  2152. if ( pPlayer && ( pPlayer->m_Shared.GetRageMeter() >= 100.0f || pPlayer->m_Shared.IsRageDraining() ) )
  2153. return true;
  2154. else
  2155. return false;
  2156. }
  2157. //-----------------------------------------------------------------------------
  2158. // Purpose: UI Progress
  2159. //-----------------------------------------------------------------------------
  2160. float CWeaponMedigun::GetProgress( void )
  2161. {
  2162. CTFPlayer *pPlayer = GetTFPlayerOwner();
  2163. if ( !pPlayer )
  2164. return 0.f;
  2165. return pPlayer->m_Shared.GetRageMeter() / 100.0f;
  2166. }
  2167. //-----------------------------------------------------------------------------
  2168. // entity_medigun_shield
  2169. //-----------------------------------------------------------------------------
  2170. #define MEDIGUNSHIELD_THINK_CONTEXT "CTFMedigunShield_ShieldThink"
  2171. LINK_ENTITY_TO_CLASS( entity_medigun_shield, CTFMedigunShield );
  2172. PRECACHE_WEAPON_REGISTER( entity_medigun_shield );
  2173. // Network
  2174. IMPLEMENT_NETWORKCLASS_ALIASED( TFMedigunShield, DT_TFMedigunShield )
  2175. BEGIN_NETWORK_TABLE( CTFMedigunShield, DT_TFMedigunShield )
  2176. END_NETWORK_TABLE()
  2177. BEGIN_PREDICTION_DATA( CTFMedigunShield )
  2178. END_PREDICTION_DATA()
  2179. // Data
  2180. BEGIN_DATADESC( CTFMedigunShield )
  2181. #ifdef GAME_DLL
  2182. DEFINE_FUNCTION( ShieldTouch ),
  2183. DEFINE_THINKFUNC( ShieldThink ),
  2184. #endif // GAME_DLL
  2185. END_DATADESC()
  2186. #ifdef GAME_DLL
  2187. static const float PROJECTILE_SHIELD_ALPHA_BASE = 150.f;
  2188. static const float PROJECTILE_SHIELD_ENERGY_REFILL_PULSE = 10.f;
  2189. static const float PROJECTILE_SHIELD_ENERGY_MAX = 1000.f;
  2190. #endif // GAME_DLL
  2191. //-----------------------------------------------------------------------------
  2192. //
  2193. //-----------------------------------------------------------------------------
  2194. CTFMedigunShield::CTFMedigunShield()
  2195. {
  2196. m_nBlinkCount = 0;
  2197. #ifdef GAME_DLL
  2198. m_pTouchLoop = NULL;
  2199. #ifdef STAGING_ONLY
  2200. m_bPermanentShield = false;
  2201. #endif // STAGING_ONLY
  2202. #endif // GAME_DLL
  2203. }
  2204. //-----------------------------------------------------------------------------
  2205. //
  2206. //-----------------------------------------------------------------------------
  2207. CTFMedigunShield::~CTFMedigunShield()
  2208. {
  2209. #ifdef GAME_DLL
  2210. if ( m_pTouchLoop )
  2211. {
  2212. CSoundEnvelopeController::GetController().SoundDestroy( m_pTouchLoop );
  2213. m_pTouchLoop = NULL;
  2214. }
  2215. #endif // GAME_DLL
  2216. }
  2217. //-----------------------------------------------------------------------------
  2218. // Purpose:
  2219. //-----------------------------------------------------------------------------
  2220. void CTFMedigunShield::Spawn()
  2221. {
  2222. BaseClass::Spawn();
  2223. SetModel( "models/props_mvm/mvm_player_shield.mdl" );
  2224. SetSolid( SOLID_VPHYSICS );
  2225. SetSolidFlags( FSOLID_TRIGGER );
  2226. SetCollisionGroup( TFCOLLISION_GROUP_COMBATOBJECT );
  2227. SetBlocksLOS( false );
  2228. AddEffects( EF_NOSHADOW );
  2229. m_takedamage = DAMAGE_EVENTS_ONLY;
  2230. #ifdef GAME_DLL
  2231. m_flShieldEnergyLevel = PROJECTILE_SHIELD_ENERGY_MAX;
  2232. SetTouch( &CTFMedigunShield::ShieldTouch );
  2233. SetContextThink( &CTFMedigunShield::ShieldThink, gpGlobals->curtime, MEDIGUNSHIELD_THINK_CONTEXT );
  2234. #else
  2235. SetNextClientThink( CLIENT_THINK_ALWAYS );
  2236. #endif // GAME_DLL
  2237. }
  2238. //-----------------------------------------------------------------------------
  2239. // Purpose:
  2240. //-----------------------------------------------------------------------------
  2241. void CTFMedigunShield::Precache()
  2242. {
  2243. PrecacheScriptSound( "WeaponMedi_Shield.Deploy" );
  2244. PrecacheScriptSound( "WeaponMedi_Shield.Protection" );
  2245. PrecacheScriptSound( "WeaponMedi_Shield.Retract" );
  2246. PrecacheScriptSound( "WeaponMedi_Shield.Burn" );
  2247. PrecacheScriptSound( "WeaponMedi_Shield.Burn_lp" );
  2248. PrecacheModel( "models/props_mvm/mvm_player_shield.mdl" );
  2249. PrecacheModel( "models/props_mvm/mvm_player_shield2.mdl" );
  2250. BaseClass::Precache();
  2251. }
  2252. #ifdef CLIENT_DLL
  2253. //-----------------------------------------------------------------------------
  2254. // Purpose:
  2255. //-----------------------------------------------------------------------------
  2256. void CTFMedigunShield::ClientThink()
  2257. {
  2258. UpdateShieldPosition();
  2259. }
  2260. #endif // CLIENT_DLL
  2261. //-----------------------------------------------------------------------------
  2262. // Purpose:
  2263. //-----------------------------------------------------------------------------
  2264. void CTFMedigunShield::UpdateShieldPosition( void )
  2265. {
  2266. CBaseEntity *pOwner = GetOwnerEntity();
  2267. if ( !pOwner )
  2268. return;
  2269. // Positioning logic
  2270. Vector vecForward;
  2271. AngleVectors( pOwner->EyeAngles(), &vecForward );
  2272. vecForward.z = 0.f;
  2273. Vector vecShieldOrigin = pOwner->GetAbsOrigin() + vecForward * 145.f;
  2274. SetAbsOrigin( vecShieldOrigin );
  2275. SetAbsAngles( QAngle( 0.f, pOwner->EyeAngles().y, 0.f ) ); // Ignore pitch
  2276. }
  2277. #ifdef GAME_DLL
  2278. //-----------------------------------------------------------------------------
  2279. // Purpose:
  2280. //-----------------------------------------------------------------------------
  2281. CTFMedigunShield *CTFMedigunShield::Create( CTFPlayer *pOwner )
  2282. {
  2283. if ( pOwner )
  2284. {
  2285. CTFMedigunShield *pShield = static_cast< CTFMedigunShield* >( CBaseEntity::Create( "entity_medigun_shield", pOwner->GetAbsOrigin() + Vector( 0, 0, 60 ), pOwner->GetAbsAngles() ) );
  2286. if ( pShield )
  2287. {
  2288. pShield->SetOwnerEntity( pOwner );
  2289. pShield->ChangeTeam( pOwner->GetTeamNumber() );
  2290. int nShieldLevel = 0;
  2291. CALL_ATTRIB_HOOK_INT_ON_OTHER( pOwner, nShieldLevel, generate_rage_on_heal );
  2292. if ( nShieldLevel > 1 )
  2293. {
  2294. pShield->SetModel( "models/props_mvm/mvm_player_shield2.mdl" );
  2295. }
  2296. pShield->m_nSkin = pShield->GetTeamNumber() == TF_TEAM_RED ? 0 : 1;
  2297. CPVSFilter filter( pOwner->WorldSpaceCenter() );
  2298. pOwner->EmitSound( filter, pOwner->entindex(), "WeaponMedi_Shield.Deploy" );
  2299. return pShield;
  2300. }
  2301. }
  2302. return NULL;
  2303. }
  2304. //------------------------------------------------------------------------------
  2305. // Purpose:
  2306. //------------------------------------------------------------------------------
  2307. // bool CTFMedigunShield::TestCollision( const Ray_t &ray, unsigned int mask, trace_t& trace )
  2308. // {
  2309. // switch( GetTeamNumber() )
  2310. // {
  2311. // case TF_TEAM_RED:
  2312. // if ( ( mask & CONTENTS_REDTEAM ) )
  2313. // return false;
  2314. // break;
  2315. //
  2316. // case TF_TEAM_BLUE:
  2317. // if ( ( mask & CONTENTS_BLUETEAM ) )
  2318. // return false;
  2319. // break;
  2320. // }
  2321. //
  2322. // vcollide_t *pCollide = modelinfo->GetVCollide( GetModelIndex() );
  2323. //
  2324. // UTIL_ClearTrace( trace );
  2325. //
  2326. // physcollision->TraceBox( ray, pCollide->solids[0], GetAbsOrigin(), GetAbsAngles(), &trace );
  2327. //
  2328. // if ( trace.fraction >= 1 )
  2329. // return false;
  2330. //
  2331. // // return owner as trace hit
  2332. // trace.m_pEnt = this;
  2333. // return true;
  2334. // }
  2335. //-----------------------------------------------------------------------------
  2336. // Purpose:
  2337. //-----------------------------------------------------------------------------
  2338. bool CTFMedigunShield::ShouldCollide( int collisionGroup, int contentsMask ) const
  2339. {
  2340. if ( collisionGroup == COLLISION_GROUP_PROJECTILE ||
  2341. collisionGroup == TFCOLLISION_GROUP_ROCKETS ||
  2342. collisionGroup == TFCOLLISION_GROUP_ROCKET_BUT_NOT_WITH_OTHER_ROCKETS )
  2343. {
  2344. switch( GetTeamNumber() )
  2345. {
  2346. case TF_TEAM_RED:
  2347. if ( ( contentsMask & CONTENTS_BLUETEAM ) )
  2348. return false;
  2349. break;
  2350. case TF_TEAM_BLUE:
  2351. if ( ( contentsMask & CONTENTS_REDTEAM ) )
  2352. return false;
  2353. break;
  2354. }
  2355. }
  2356. return BaseClass::ShouldCollide( collisionGroup, contentsMask );
  2357. }
  2358. //-----------------------------------------------------------------------------
  2359. //
  2360. //-----------------------------------------------------------------------------
  2361. void CTFMedigunShield::StartTouch( CBaseEntity *pOther )
  2362. {
  2363. BaseClass::StartTouch( pOther );
  2364. CBaseEntity *pOwner = GetOwnerEntity();
  2365. if ( !pOwner )
  2366. return;
  2367. if ( !InSameTeam( pOther ) )
  2368. {
  2369. CPVSFilter filter( WorldSpaceCenter() );
  2370. pOwner->EmitSound( filter, entindex(), "WeaponMedi_Shield.Burn" );
  2371. }
  2372. }
  2373. //-----------------------------------------------------------------------------
  2374. // Purpose:
  2375. //-----------------------------------------------------------------------------
  2376. void CTFMedigunShield::ShieldTouch( CBaseEntity *pOther )
  2377. {
  2378. if ( !pOther )
  2379. return;
  2380. if ( !InSameTeam( pOther ) )
  2381. {
  2382. // Drip pan for unknown projectiles
  2383. if ( !pOther->IsDeflectable() && pOther->GetCollisionGroup() == COLLISION_GROUP_PROJECTILE )
  2384. {
  2385. UTIL_Remove( pOther );
  2386. return;
  2387. }
  2388. CTFPlayer *pTFOwner = ToTFPlayer( GetOwnerEntity() );
  2389. if ( !pTFOwner )
  2390. return;
  2391. if ( TFGameRules() && TFGameRules()->IsMannVsMachineMode() && ( pTFOwner->GetTeamNumber() == TF_TEAM_PVE_INVADERS ) )
  2392. return;
  2393. int nShieldLevel = 0;
  2394. CALL_ATTRIB_HOOK_INT_ON_OTHER( pTFOwner, nShieldLevel, generate_rage_on_heal );
  2395. // Damage it
  2396. float flDamage = ( nShieldLevel > 1 ) ? 2.f : 1.f;
  2397. CTakeDamageInfo info;
  2398. info.SetAttacker( pTFOwner );
  2399. info.SetInflictor( this );
  2400. info.SetWeapon( pTFOwner->GetActiveTFWeapon() );
  2401. info.SetDamage( flDamage );
  2402. info.SetDamageType( DMG_ENERGYBEAM );
  2403. info.SetDamageCustom( TF_DMG_CUSTOM_PLASMA );
  2404. info.SetDamagePosition( pOther->EyePosition() );
  2405. pOther->TakeDamage( info );
  2406. // Slow enemy players
  2407. if ( pOther->IsPlayer() )
  2408. {
  2409. CTFPlayer *pTFVictim = ToTFPlayer( pOther );
  2410. if ( !pTFVictim )
  2411. return;
  2412. float flStun = ( nShieldLevel > 1 ) ? 0.5f : 0.3f;
  2413. pTFVictim->m_Shared.StunPlayer( 0.5f, flStun, TF_STUN_MOVEMENT, pTFOwner );
  2414. }
  2415. // Sound
  2416. if ( !m_pTouchLoop )
  2417. {
  2418. CPVSFilter filter( GetAbsOrigin() );
  2419. CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController();
  2420. m_pTouchLoop = controller.SoundCreate( filter, entindex(), "WeaponMedi_Shield.Burn_lp" );
  2421. controller.Play( m_pTouchLoop, 1.0, 100 );
  2422. }
  2423. }
  2424. }
  2425. //-----------------------------------------------------------------------------
  2426. //
  2427. //-----------------------------------------------------------------------------
  2428. void CTFMedigunShield::EndTouch( CBaseEntity *pOther )
  2429. {
  2430. BaseClass::EndTouch( pOther );
  2431. if ( m_pTouchLoop )
  2432. {
  2433. CSoundEnvelopeController::GetController().SoundDestroy( m_pTouchLoop );
  2434. m_pTouchLoop = NULL;
  2435. }
  2436. }
  2437. //-----------------------------------------------------------------------------
  2438. //
  2439. //-----------------------------------------------------------------------------
  2440. void CTFMedigunShield::ShieldThink( void )
  2441. {
  2442. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  2443. #ifdef STAGING_ONLY
  2444. if ( !pOwner || ( !pOwner->m_Shared.IsRageDraining() && !m_bPermanentShield ) )
  2445. #else
  2446. if ( !pOwner || !pOwner->m_Shared.IsRageDraining() )
  2447. #endif
  2448. {
  2449. RemoveShield();
  2450. return;
  2451. }
  2452. UpdateShieldPosition();
  2453. // Regen shield
  2454. if ( m_flShieldEnergyLevel < PROJECTILE_SHIELD_ENERGY_MAX )
  2455. {
  2456. m_flShieldEnergyLevel += PROJECTILE_SHIELD_ENERGY_REFILL_PULSE;
  2457. m_flShieldEnergyLevel = Min( m_flShieldEnergyLevel, PROJECTILE_SHIELD_ENERGY_MAX );
  2458. }
  2459. // Visuals
  2460. SetRenderMode( kRenderTransAlpha );
  2461. int nShieldOpacity = PROJECTILE_SHIELD_ALPHA_BASE;
  2462. // Determine alpha
  2463. float flFadePoint = PROJECTILE_SHIELD_ENERGY_MAX / 2.f;
  2464. if ( m_flShieldEnergyLevel <= flFadePoint )
  2465. {
  2466. nShieldOpacity = (int)RemapValClamped( m_flShieldEnergyLevel, 0.f, flFadePoint, 255.f, PROJECTILE_SHIELD_ALPHA_BASE );
  2467. }
  2468. // Blink when we're about to expire
  2469. #ifdef STAGING_ONLY
  2470. if ( pOwner->m_Shared.GetRageMeter() <= 25.f && !m_bPermanentShield )
  2471. #else
  2472. if ( pOwner->m_Shared.GetRageMeter() <= 25.f )
  2473. #endif
  2474. {
  2475. ++m_nBlinkCount;
  2476. if ( m_nBlinkCount & 0x2 )
  2477. {
  2478. SetRenderColorA( PROJECTILE_SHIELD_ALPHA_BASE - 100 );
  2479. }
  2480. else
  2481. {
  2482. SetRenderColorA( nShieldOpacity );
  2483. }
  2484. // Play a retract sound
  2485. if ( m_nBlinkCount == 1 )
  2486. {
  2487. CPVSFilter filter( pOwner->WorldSpaceCenter() );
  2488. pOwner->EmitSound( filter, entindex(), "WeaponMedi_Shield.Retract" );
  2489. }
  2490. }
  2491. else
  2492. {
  2493. SetRenderColorA( nShieldOpacity );
  2494. }
  2495. SetContextThink( &CTFMedigunShield::ShieldThink, gpGlobals->curtime + 0.1f, MEDIGUNSHIELD_THINK_CONTEXT );
  2496. }
  2497. //-----------------------------------------------------------------------------
  2498. //
  2499. //-----------------------------------------------------------------------------
  2500. void CTFMedigunShield::RemoveShield( void )
  2501. {
  2502. SetTouch( NULL );
  2503. AddEffects( EF_NODRAW );
  2504. UTIL_Remove( this );
  2505. }
  2506. //-----------------------------------------------------------------------------
  2507. //
  2508. //-----------------------------------------------------------------------------
  2509. void CTFMedigunShield::TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator )
  2510. {
  2511. if ( !InSameTeam( info.GetAttacker() ) )
  2512. {
  2513. CEffectData data;
  2514. data.m_vOrigin = ptr->endpos - (vecDir * 8);
  2515. data.m_vNormal = -vecDir;
  2516. data.m_flMagnitude = RemapValClamped( info.GetDamage(), 1.f, 50.f, 0.5f, 2.f );
  2517. CPVSFilter filter( GetAbsOrigin() );
  2518. te->DispatchEffect( filter, 0.f, data.m_vOrigin, "EnergyShieldImpact", data );
  2519. // g_pEffects->EnergySplash( ptr->endpos - (vecDir * 8), -vecDir, false );
  2520. }
  2521. BaseClass::TraceAttack( info, vecDir, ptr, pAccumulator );
  2522. }
  2523. //-----------------------------------------------------------------------------
  2524. //
  2525. //-----------------------------------------------------------------------------
  2526. int CTFMedigunShield::OnTakeDamage( const CTakeDamageInfo &info )
  2527. {
  2528. if ( !InSameTeam( info.GetAttacker() ) )
  2529. {
  2530. CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
  2531. if ( pOwner )
  2532. {
  2533. float flDamage = info.GetDamage();
  2534. m_flShieldEnergyLevel -= flDamage;
  2535. m_flShieldEnergyLevel = Max( m_flShieldEnergyLevel, 0.f );
  2536. // Add to blocked damage stat
  2537. CTF_GameStats.Event_PlayerBlockedDamage( pOwner, flDamage );
  2538. // CPVSFilter filter( pOwner->WorldSpaceCenter() );
  2539. // pOwner->EmitSound( filter, entindex(), "WeaponMedi_Shield.Protection" );
  2540. pOwner->PlayDamageResistSound( 100.f, RandomFloat( 0.85f, 1.f ) );
  2541. IGameEvent *event = gameeventmanager->CreateEvent( "medigun_shield_blocked_damage" );
  2542. if ( event )
  2543. {
  2544. event->SetInt( "userid", pOwner->GetUserID() );
  2545. event->SetFloat( "damage", flDamage );
  2546. gameeventmanager->FireEvent( event );
  2547. }
  2548. }
  2549. }
  2550. return 0;
  2551. }
  2552. #endif // GAME_DLL