Guest User

TF2C pill streak

a guest
Jan 23rd, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.00 KB | None | 0 0
  1. //====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6.  
  7. #include "cbase.h"
  8. #include "tf_weapon_pillstreak.h"
  9. #include "tf_fx_shared.h"
  10. #ifdef GAME_DLL
  11. #include "tf_player.h"
  12. #else
  13. #include "c_tf_player.h"
  14. #endif
  15.  
  16. #ifdef TF2C_BETA
  17. //=============================================================================
  18. //
  19. // Weapon Pillstreak tables.
  20. //
  21. IMPLEMENT_NETWORKCLASS_ALIASED(TFPillstreak, DT_TFPillstreak);
  22. BEGIN_NETWORK_TABLE(CTFPillstreak, DT_TFPillstreak)
  23. #ifdef CLIENT_DLL
  24. RecvPropInt(RECVINFO(m_iStreakCount)),
  25. //RecvPropFloat( RECVINFO( m_flTimeDecrementStreak ) )
  26. RecvPropInt(RECVINFO(m_iMissCount))
  27. #else
  28. SendPropInt(SENDINFO(m_iStreakCount), 6, SPROP_UNSIGNED),
  29. //SendPropFloat(SENDINFO(m_flTimeDecrementStreak), -1, SPROP_NOSCALE | SPROP_CHANGES_OFTEN)
  30. SendPropInt(SENDINFO(m_iMissCount), 2, SPROP_UNSIGNED)
  31. #endif
  32. END_NETWORK_TABLE()
  33.  
  34. BEGIN_PREDICTION_DATA(CTFPillstreak)
  35. END_PREDICTION_DATA()
  36.  
  37. LINK_ENTITY_TO_CLASS(tf_weapon_pillstreak, CTFPillstreak);
  38. PRECACHE_WEAPON_REGISTER(tf_weapon_pillstreak);
  39.  
  40. #define PILLSTREAK_TF2C_MAX_VISUAL_STREAK 63
  41. #define PILLSTREAK_TF2C_MAX_DAMAGE_STREAK 6
  42. #define PILLSTREAK_TF2C_DAMAGE_GAIN_PER_STREAK 5.0
  43. #define PILLSTREAK_TF2C_STREAK_START_FIRE 6
  44. #define PILLSTREAK_TF2C_DECAY_TIME 10
  45. #define PILLSTREAK_TF2C_MISS_COUNT 4
  46.  
  47. //=============================================================================
  48. //
  49. // Weapon Pillstreak functions.
  50. //
  51.  
  52. void CTFPillstreak::Precache( void )
  53. {
  54.     PrecacheScriptSound( "ArrowLight" );
  55.  
  56.     PrecacheParticleSystem( "flaming_arrow" );
  57.     PrecacheParticleSystem( "v_flaming_arrow" );
  58.  
  59.     //PrecacheScriptSound( "Weapon_PillStreak.SingleComboLow" );
  60.     //PrecacheScriptSound( "Weapon_PillStreak.SingleComboMedium" );
  61.     //PrecacheScriptSound( "Weapon_PillStreak.SingleComboHigh" );
  62.     PrecacheScriptSound( "Weapon_PillStreak.Miss" );
  63.     PrecacheScriptSound( "Weapon_PillStreak.Reset" );
  64.     PrecacheScriptSound( "Weapon_Fist.MissCrit" );
  65.  
  66.     BaseClass::Precache();
  67. }
  68.  
  69. void CTFPillstreak::WeaponReset(void)
  70. {
  71.     BaseClass::WeaponReset();
  72.     m_iStreakCount = 0;
  73.     //m_flTimeDecrementStreak = -1;
  74.     m_iMissCount = 0;
  75. }
  76.  
  77. //-----------------------------------------------------------------------------
  78. // Purpose: Accessor for damage, so DEMOMAN IS VERY DRUNK
  79. //-----------------------------------------------------------------------------
  80. float CTFPillstreak::GetProjectileDamage(void)
  81. {
  82.     float flDamage = BaseClass::GetProjectileDamage();
  83.     flDamage += Min(GetPipeStreak(), PILLSTREAK_TF2C_MAX_DAMAGE_STREAK) * PILLSTREAK_TF2C_DAMAGE_GAIN_PER_STREAK;
  84.     return flDamage;
  85. }
  86.  
  87. //-----------------------------------------------------------------------------
  88. // Purpose: Base damage without the streak bonus
  89. //-----------------------------------------------------------------------------
  90. float CTFPillstreak::GetProjectileDamageNoStreak( void )
  91. {
  92.     return BaseClass::GetProjectileDamage();
  93. }
  94.  
  95.  
  96. void CTFPillstreak::IncrementPipeStreak(void)
  97. {
  98.     m_iMissCount = 0;
  99.     if (m_iStreakCount < PILLSTREAK_TF2C_MAX_VISUAL_STREAK)
  100.     {
  101.         ++m_iStreakCount;
  102.         if (m_iStreakCount == PILLSTREAK_TF2C_MAX_DAMAGE_STREAK)
  103.         {
  104. #ifdef GAME_DLL
  105.             CTFPlayer* pPlayer = GetTFPlayerOwner();
  106.             if (pPlayer)
  107.             {
  108.                 if (pPlayer->IsSpeaking())
  109.                 {
  110.                     CMultiplayer_Expresser *pExpresser = pPlayer->GetMultiplayerExpresser();
  111.                     if (pExpresser)
  112.                     {
  113.                         pExpresser->ForceNotSpeaking();
  114.                     }
  115.                 }
  116.                 pPlayer->SpeakConceptIfAllowed(MP_CONCEPT_PILLSTREAK_CHARGED);
  117.             }
  118. #endif
  119.         }
  120.     }
  121.  
  122.     //m_flTimeDecrementStreak = gpGlobals->curtime + PILLSTREAK_TF2C_DECAY_TIME;
  123. }
  124.  
  125.  
  126. // Currently doesn't do what you expect, rather on_miss alike
  127. void CTFPillstreak::DecrementPipeStreak(void)
  128. {
  129.     CTFPlayer *pPlayer = ToTFPlayer( GetOwner() );
  130.  
  131.     if (m_iStreakCount > 0)
  132.     {
  133.         m_iMissCount += 1;
  134.  
  135.         if (m_iMissCount >= PILLSTREAK_TF2C_MISS_COUNT)
  136.         {
  137.             ClearPipeStreak();
  138.  
  139.             if ( pPlayer )
  140.             {
  141.                 CSingleUserRecipientFilter filter( pPlayer );
  142.                 filter.UsePredictionRules();
  143.                 CBaseEntity::EmitSound( filter, pPlayer->entindex(), "Weapon_PillStreak.Reset" );
  144.             }
  145.         }
  146.         else
  147.         {
  148.             if ( pPlayer )
  149.             {
  150.                 CSingleUserRecipientFilter filter( pPlayer );
  151.                 filter.UsePredictionRules();
  152.                 CBaseEntity::EmitSound( filter, pPlayer->entindex(), "Weapon_PillStreak.Miss" );
  153.             }
  154.         }
  155.     }
  156.  
  157.     /*if (m_iStreakCount > 0)
  158.     {
  159.         --m_iStreakCount;
  160.     }*/
  161.  
  162.  
  163.     /*if (m_iStreakCount > 0)
  164.     {
  165.         m_flTimeDecrementStreak = gpGlobals->curtime + PILLSTREAK_TF2C_DECAY_TIME;
  166.     }
  167.     else
  168.     {
  169.         m_flTimeDecrementStreak = -1;
  170.     }*/
  171. }
  172.  
  173.  
  174. int CTFPillstreak::GetPipeStreak(void)
  175. {
  176.     return m_iStreakCount;
  177. }
  178.  
  179.  
  180. int CTFPillstreak::GetMaxDamagePipeStreak(void)
  181. {
  182.     return PILLSTREAK_TF2C_MAX_DAMAGE_STREAK;
  183. }
  184.  
  185.  
  186. void CTFPillstreak::ClearPipeStreak(void)
  187. {
  188.     m_iStreakCount = 0;
  189.     m_iMissCount = 0;
  190.     //m_flTimeDecrementStreak = -1;
  191. }
  192.  
  193. void CTFPillstreak::ItemPostFrame( void )
  194. {
  195.     BaseClass::ItemPostFrame();
  196.  
  197.     /*if ( gpGlobals->curtime > m_flTimeDecrementStreak && m_flTimeDecrementStreak > 0 )
  198.     {
  199.         DecrementPipeStreak();
  200.         //ClearPipeStreak();
  201.     }*/
  202. }
  203.  
  204. void CTFPillstreak::ItemHolsterFrame( void )
  205. {
  206.     BaseClass::ItemHolsterFrame();
  207.  
  208.     /*if ( gpGlobals->curtime > m_flTimeDecrementStreak && m_flTimeDecrementStreak > 0 )
  209.     {
  210.         DecrementPipeStreak();
  211.         //ClearPipeStreak();
  212.     }*/
  213. }
  214.  
  215. void CTFPillstreak::PlayWeaponShootSound( void )
  216. {
  217.     // Add a crit sound on top
  218.     if ( IsCurrentAttackACrit() )
  219.     {
  220.         CPASAttenuationFilter filter( this, SNDLVL_100dB );
  221.         if ( IsPredicted() && CBaseEntity::GetPredictionPlayer() )
  222.         {
  223.             filter.UsePredictionRules();
  224.         }
  225.         EmitSound( filter, entindex(), "Weapon_Fist.MissCrit" );
  226.     }
  227.  
  228.     if ( m_iStreakCount >= PILLSTREAK_TF2C_MAX_DAMAGE_STREAK )
  229.     {
  230.         WeaponSound( SPECIAL3 );
  231.     }
  232.     else if ( m_iStreakCount >= ceil( PILLSTREAK_TF2C_MAX_DAMAGE_STREAK * 0.5 ) )
  233.     {
  234.         WeaponSound( SPECIAL2 );
  235.     }
  236.     else if ( m_iStreakCount >= 1 )
  237.     {
  238.         WeaponSound( SPECIAL1 );
  239.     }
  240.     else
  241.     {
  242.         WeaponSound( SINGLE );
  243.     }
  244. }
  245.  
  246.  
  247. // everything below is hack and ugly copy paste
  248.  
  249.  
  250.  
  251.  
  252. #ifdef CLIENT_DLL
  253.  
  254. void CTFPillstreak::StartBurningEffect(void)
  255. {
  256.     // Clear any old effect before adding a new one.
  257.     if (m_pBurningArrowEffect)
  258.     {
  259.         StopBurningEffect();
  260.     }
  261.  
  262.     const char *pszEffect;
  263.     m_hParticleEffectOwner = GetWeaponForEffect();
  264.     if (m_hParticleEffectOwner)
  265.     {
  266.         if (m_hParticleEffectOwner != this)
  267.         {
  268.             // We're on the viewmodel.
  269.             pszEffect = "v_flaming_arrow";
  270.         }
  271.         else
  272.         {
  273.             pszEffect = "flaming_arrow";
  274.         }
  275.  
  276.         m_pBurningArrowEffect = m_hParticleEffectOwner->ParticleProp()->Create(pszEffect, PATTACH_POINT_FOLLOW, "muzzle");
  277.     }
  278. }
  279.  
  280.  
  281. void CTFPillstreak::StopBurningEffect(void)
  282. {
  283.     if (m_pBurningArrowEffect)
  284.     {
  285.         if (m_hParticleEffectOwner && m_hParticleEffectOwner->ParticleProp())
  286.         {
  287.             m_hParticleEffectOwner->ParticleProp()->StopEmissionAndDestroyImmediately(m_pBurningArrowEffect);
  288.         }
  289.  
  290.         m_pBurningArrowEffect = NULL;
  291.     }
  292. }
  293.  
  294.  
  295. void CTFPillstreak::ThirdPersonSwitch(bool bThirdperson)
  296. {
  297.     // Switch out the burning effects.
  298.     BaseClass::ThirdPersonSwitch(bThirdperson);
  299.     StopBurningEffect();
  300.     StartBurningEffect();
  301. }
  302.  
  303.  
  304. void CTFPillstreak::UpdateOnRemove(void)
  305. {
  306.     StopBurningEffect();
  307.     BaseClass::UpdateOnRemove();
  308. }
  309.  
  310.  
  311. void CTFPillstreak::OnDataChanged(DataUpdateType_t type)
  312. {
  313.     BaseClass::OnDataChanged(type);
  314.  
  315.     // Handle particle effect creation and destruction.
  316.     if ((!IsHolstered() && m_iStreakCount >= PILLSTREAK_TF2C_STREAK_START_FIRE) && !m_pBurningArrowEffect)
  317.     {
  318.         StartBurningEffect();
  319.         EmitSound("ArrowLight");
  320.     }
  321.     else if ((IsHolstered() || m_iStreakCount < PILLSTREAK_TF2C_STREAK_START_FIRE) && m_pBurningArrowEffect)
  322.     {
  323.         StopBurningEffect();
  324.     }
  325. }
  326.  
  327. // not ugly hack and copypaste
  328.  
  329. float CTFPillstreak::GetProgress()
  330. {
  331.     //return (m_flTimeDecrementStreak - gpGlobals->curtime) / PILLSTREAK_TF2C_DECAY_TIME;
  332.     if (m_iStreakCount > 0)
  333.         return 1.0f - (float(m_iMissCount) / PILLSTREAK_TF2C_MISS_COUNT);
  334.     else
  335.         return 0.0f;
  336. }
  337. #endif
  338.  
  339. #endif // TF2C_BETA
  340.  
Advertisement
Add Comment
Please, Sign In to add comment