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.

115 lines
3.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Weapon Knife Class
  4. //
  5. //=============================================================================
  6. #ifndef TF_WEAPON_KNIFE_H
  7. #define TF_WEAPON_KNIFE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tf_weaponbase_melee.h"
  12. #ifdef CLIENT_DLL
  13. #define CTFKnife C_TFKnife
  14. #endif
  15. // Knives use the "set_weapon_mode" attribute to define which type of knife they are
  16. // Keep this enum in sync with the values used for set_weapon_mode.
  17. enum knife_weapontypes_t
  18. {
  19. KNIFE_STANDARD = 0,
  20. KNIFE_DISGUISE_ONKILL = 1,
  21. KNIFE_MOVEMENT_CLOAK = 2, // The Cloak and Dagger
  22. KNIFE_ICICLE = 3,
  23. };
  24. //=============================================================================
  25. //
  26. // Knife class.
  27. //
  28. class CTFKnife : public CTFWeaponBaseMelee
  29. {
  30. public:
  31. DECLARE_CLASS( CTFKnife, CTFWeaponBaseMelee );
  32. DECLARE_NETWORKCLASS();
  33. DECLARE_PREDICTABLE();
  34. CTFKnife();
  35. virtual void PrimaryAttack( void ) OVERRIDE;
  36. virtual int GetWeaponID( void ) const OVERRIDE { return TF_WEAPON_KNIFE; }
  37. int GetKnifeType( void ) const { int iMode = 0; CALL_ATTRIB_HOOK_INT( iMode, set_weapon_mode ); return iMode; };
  38. virtual float GetMeleeDamage( CBaseEntity *pTarget, int* piDamageType, int* piCustomDamage ) OVERRIDE;
  39. virtual void SendPlayerAnimEvent( CTFPlayer *pPlayer ) OVERRIDE;
  40. virtual bool CanDeploy( void ) OVERRIDE;
  41. virtual bool Deploy( void ) OVERRIDE;
  42. void BackstabVMThink( void );
  43. bool SendWeaponAnim( int iActivity );
  44. bool CanPerformBackstabAgainstTarget( CTFPlayer *pTarget ); // "backstab" sometimes means "frontstab"
  45. bool IsBehindAndFacingTarget( CTFPlayer *pTarget );
  46. bool IsBackstab( void ) { return (m_hBackstabVictim.Get() != NULL); }
  47. void BackstabBlocked( void );
  48. bool ShouldDisguiseOnBackstab( void );
  49. void DisguiseOnKill();
  50. void ProcessDisguiseImpulse();
  51. virtual bool CanHolster( void ) const OVERRIDE;
  52. virtual void ItemPostFrame( void ) OVERRIDE;
  53. virtual void ItemPreFrame( void ) OVERRIDE;
  54. virtual void ItemBusyFrame( void ) OVERRIDE;
  55. virtual void ItemHolsterFrame( void ) OVERRIDE;
  56. virtual bool CalcIsAttackCriticalHelper( void ) OVERRIDE;
  57. virtual bool CalcIsAttackCriticalHelperNoCrits( void ) OVERRIDE;
  58. virtual bool DoSwingTrace( trace_t &trace ) OVERRIDE;
  59. virtual void WeaponRegenerate( void ) OVERRIDE;
  60. virtual void WeaponReset( void ) OVERRIDE;
  61. #ifdef GAME_DLL
  62. virtual void ApplyOnInjuredAttributes( CTFPlayer *pVictim, CTFPlayer *pAttacker, const CTakeDamageInfo &info ) OVERRIDE; // when owner of this weapon is hit
  63. bool DecreaseRegenerationTime( float value, bool bForce );
  64. #endif
  65. float GetProgress( void );
  66. const char* GetEffectLabelText( void ) { return "#TF_KNIFE"; }
  67. private:
  68. void ResetVars( void );
  69. private:
  70. float m_flBlockedTime;
  71. bool m_bAllowHolsterBecauseForced;
  72. CHandle<CTFPlayer> m_hBackstabVictim;
  73. CNetworkVar( bool, m_bReadyToBackstab );
  74. CNetworkVar( bool, m_bKnifeExists );
  75. CNetworkVar( float, m_flKnifeRegenerateDuration );
  76. CNetworkVar( float, m_flKnifeMeltTimestamp );
  77. bool m_bWasTaunting;
  78. CTFKnife( const CTFKnife & ) {}
  79. };
  80. inline float CTFKnife::GetProgress( void )
  81. {
  82. if ( m_bKnifeExists )
  83. {
  84. return 1.0f;
  85. }
  86. float meltedTime = gpGlobals->curtime - m_flKnifeMeltTimestamp;
  87. return meltedTime / m_flKnifeRegenerateDuration;
  88. }
  89. #endif // TF_WEAPON_KNIFE_H