Guest User

TF2C leap knife

a guest
Jan 23rd, 2025
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.26 KB | None | 0 0
  1. //====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: Weapon Knife.
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "tf_gamerules.h"
  8.  
  9. #include <in_buttons.h>
  10. #include "tf_weapon_leapknife.h"
  11. #include "decals.h"
  12. #include "tf_lagcompensation.h"
  13.  
  14. // Client specific.
  15. #ifdef CLIENT_DLL
  16. #include "c_tf_player.h"
  17. // Server specific.
  18. #else
  19. #include "tf_player.h"
  20. #include "tf_gamestats.h"
  21. #endif
  22.  
  23. #ifdef TF2C_BETA
  24.  
  25. //=============================================================================
  26. //
  27. // Weapon Knife tables.
  28. //
  29. IMPLEMENT_NETWORKCLASS_ALIASED( TFLeapKnife, DT_TFWeaponLeapKnife );
  30.  
  31. BEGIN_NETWORK_TABLE( CTFLeapKnife, DT_TFWeaponLeapKnife )
  32. #ifdef CLIENT_DLL
  33.     RecvPropBool( RECVINFO( m_bReadyToBackstab ) ),
  34.     RecvPropFloat( RECVINFO( m_flLeapCooldown ) ),
  35. #else
  36.     SendPropBool( SENDINFO( m_bReadyToBackstab ) ),
  37.     SendPropFloat( SENDINFO( m_flLeapCooldown ) ),
  38. #endif
  39. END_NETWORK_TABLE()
  40.  
  41. BEGIN_PREDICTION_DATA( CTFLeapKnife )
  42. #ifdef CLIENT_DLL
  43.     DEFINE_PRED_FIELD( m_bReadyToBackstab, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
  44.     DEFINE_PRED_FIELD( m_flLeapCooldown, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
  45. #endif
  46. END_PREDICTION_DATA()
  47.  
  48. LINK_ENTITY_TO_CLASS( tf_weapon_leapknife, CTFLeapKnife );
  49. PRECACHE_WEAPON_REGISTER( tf_weapon_leapknife );
  50.  
  51. //=============================================================================
  52. //
  53. // Weapon Knife functions.
  54. //
  55.  
  56. ConVar tf2c_spy_leap_distance           ("tf2c_spy_leap_distance",              "220.0",    FCVAR_NOTIFY | FCVAR_REPLICATED);
  57. ConVar tf2c_spy_leap_distance_vertical  ("tf2c_spy_leap_distance_vertical",     "128.0",    FCVAR_NOTIFY | FCVAR_REPLICATED);
  58. ConVar tf2c_spy_leap_cooldown           ("tf2c_spy_leap_cooldown",              "4.0",      FCVAR_NOTIFY | FCVAR_REPLICATED);
  59. ConVar tf2c_spy_leap_cloak_drain_percent("tf2c_spy_leap_cloak_drain_percent",   "25.0",     FCVAR_NOTIFY | FCVAR_REPLICATED);
  60.  
  61.  
  62. CTFLeapKnife::CTFLeapKnife()
  63. {
  64.     m_flLeapCooldown = 0.0f;
  65.     m_flNextErrorBuzzTime = 0.0f;
  66. }
  67.  
  68. void CTFLeapKnife::Precache()
  69. {
  70.     BaseClass::Precache();
  71.     PrecacheScriptSound("Weapon_Grenade_Mirv.Throw");
  72. }
  73.  
  74. void CTFLeapKnife::ItemPostFrame( void )
  75. {
  76.     BaseClass::ItemPostFrame();
  77.  
  78.     LeapThink();
  79. }
  80.  
  81. float CTFLeapKnife::GetProgress()
  82. {
  83.     float flTime = tf2c_spy_leap_cooldown.GetFloat();
  84.     return (flTime - (m_flLeapCooldown - gpGlobals->curtime)) / flTime;
  85. }
  86.  
  87. void CTFLeapKnife::ItemBusyFrame()
  88. {
  89.     BaseClass::ItemBusyFrame();
  90.  
  91.     LeapThink();
  92. }
  93.  
  94. void CTFLeapKnife::ItemHolsterFrame()
  95. {
  96.     BaseClass::ItemHolsterFrame();
  97.  
  98.     LeapThink();
  99. }
  100.  
  101. void CTFLeapKnife::PlayErrorSoundIfWeShould()
  102. {
  103. #ifdef CLIENT_DLL
  104.     if (gpGlobals->curtime >= m_flNextErrorBuzzTime)
  105.     {
  106.         CLocalPlayerFilter filter;
  107.         EmitSound( filter, entindex(), "Player.DenyWeaponSelection" );
  108.         m_flNextErrorBuzzTime = gpGlobals->curtime + 0.5f; // Only buzz every so often.
  109.     }
  110. #endif
  111. }
  112.  
  113. void CTFLeapKnife::LeapThink()
  114. {
  115.     // TODO: item effect meter thing
  116.     // TODO: check this math
  117.     // TODO: impl m_flLastLeapTime
  118.     // TODO: 8 second long cooldown
  119.     CTFPlayer *pPlayerOwner = GetTFPlayerOwner();
  120.  
  121.     // Gone.
  122.     if ( !pPlayerOwner )
  123.         return;
  124.  
  125.     if ( pPlayerOwner->m_nButtons & IN_DUCK && pPlayerOwner->m_nButtons & IN_JUMP )
  126.     {
  127.         if ( !((pPlayerOwner->m_Shared.IsStealthed() || pPlayerOwner->m_Shared.InCond(TF_COND_STEALTHED_BLINK))) )
  128.         {
  129.             PlayErrorSoundIfWeShould();
  130.             return;
  131.         }
  132.  
  133.         float cloakAmt = pPlayerOwner->m_Shared.GetSpyCloakMeter();
  134.  
  135.         if (cloakAmt < tf2c_spy_leap_cloak_drain_percent.GetFloat())
  136.         {
  137.             // we dont have enough cloak!
  138.             PlayErrorSoundIfWeShould();
  139.             return;
  140.         }
  141.  
  142.         if (m_flLeapCooldown >= gpGlobals->curtime)
  143.         {
  144.             PlayErrorSoundIfWeShould();
  145.             return;
  146.         }
  147.  
  148.         m_flLeapCooldown = gpGlobals->curtime + tf2c_spy_leap_cooldown.GetFloat();
  149.  
  150.         pPlayerOwner->m_Shared.SetSpyCloakMeter(cloakAmt - tf2c_spy_leap_cloak_drain_percent.GetFloat());
  151.  
  152.         QAngle angles = pPlayerOwner->EyeAngles();
  153.         Vector forward = vec3_origin;
  154.         Vector velocity = vec3_origin;
  155.  
  156.         AngleVectors(angles, &forward);
  157.  
  158.         forward.z = 1.0f;
  159.  
  160.         // make it usable
  161.         float flDistance = tf2c_spy_leap_distance.GetFloat();
  162.         Vector forwardScaled = vec3_origin;
  163.         VectorMultiply(forward, flDistance, forwardScaled);
  164.  
  165.         // add it to the current velocity to avoid just being able to do full 180s
  166.         velocity = pPlayerOwner->GetLocalVelocity();
  167.  
  168.         Vector newVelocity;
  169.         VectorAdd(velocity, forwardScaled, newVelocity);
  170.  
  171.         float flDistanceVertical = tf2c_spy_leap_distance_vertical.GetFloat();
  172.  
  173.         newVelocity[2] += flDistanceVertical; // we always want to go a bit up
  174.  
  175.         EmitSound("Weapon_Grenade_Mirv.Throw");
  176.  
  177.         pPlayerOwner->SetAbsVelocity(newVelocity);
  178.         pPlayerOwner->SetBaseVelocity(vec3_origin);
  179.  
  180. #ifdef GAME_DLL
  181.         pPlayerOwner->m_bSelfKnockback = true;
  182. #endif
  183.  
  184.         pPlayerOwner->m_Shared.AddCond(TF_COND_TELEPORTED_ALWAYS_SHOW, 5.0);
  185.     }
  186. }
  187.  
  188. #endif
  189.  
Advertisement
Add Comment
Please, Sign In to add comment