DayZ 1.24
Loading...
Searching...
No Matches
StaminaHandler Class Reference
Collaboration diagram for StaminaHandler:
[legend]

Protected Member Functions

void StaminaHandler (PlayerBase player)
 
void Init ()
 
void ActivateDepletionModifier (EStaminaMultiplierTypes type)
 
void DeactivateDepletionModifier (EStaminaMultiplierTypes type)
 
void RecalculateDepletionMultiplier ()
 
void ActivateRecoveryModifier (EStaminaMultiplierTypes type)
 
void DeactivateRecoveryModifier (EStaminaMultiplierTypes type)
 
void RecalculateRecoveryMultiplier ()
 
void Update (float deltaT, int pCurrentCommandID)
 
void OnRPC (float stamina, float stamina_cap, bool cooldown)
 deprecated use, StaminaHandler uses SyncJunctures now
 
void OnSyncJuncture (int pJunctureID, ParamsReadContext pCtx)
 called from PlayerBase - syncs stamina values on server with client AND sets the value to match on server and client both (m_StaminaSynced guarantees identical values)
 
void StaminaProcessor_Move (HumanMovementState pHumanMovementState)
 
void StaminaProcessor_Ladder (HumanMovementState pHumanMovementState)
 
void StaminaProcessor_Swimming (HumanMovementState pHumanMovementState)
 
void SyncStamina (float stamina, float stamina_cap, bool cooldown)
 stamina sync - server part
 
void SyncAdditionalStaminaInfo (Param par)
 Method to sync more info for stamina manager. Template parameter means it is very extendable for further use.
 
void ReadAdditionalStaminaInfo (ParamsReadContext pCtx)
 Order of read parameters must match the order of writing above.
 
void RegisterStaminaConsumers ()
 
void RegisterStaminaModifiers ()
 
float CalcStaminaGainBonus ()
 Calulates stamina regain bonus coef based on current stamina cap and level.
 
void ApplyExhaustion ()
 
void CheckStaminaState ()
 check if the stamina is completely depleted
 
void SetCooldown (float time, int modifier=-1)
 set cooldown timer between each consume of stamina
 
void ResetCooldown (int modifier=-1)
 
Timer GetCooldownTimer (int modifier)
 
bool HasEnoughStaminaFor (EStaminaConsumers consumer)
 
bool HasEnoughStaminaToStart (EStaminaConsumers consumer)
 
void SetStamina (float stamina_value)
 
float GetStamina ()
 
float GetStaminaNormalized ()
 
float GetSyncedStamina ()
 
float GetSyncedStaminaNormalized ()
 
float GetStaminaCap ()
 
float GetStaminaMax ()
 
void SetDepletionMultiplier (float val)
 
void SetRecoveryMultiplier (float val)
 
float GetDepletionMultiplier ()
 
float GetRecoveryMultiplier ()
 
void DepleteStamina (EStaminaModifiers modifier, float dT=-1)
 

Protected Attributes

float m_PlayerLoad
 
float m_StaminaDelta
 
float m_Stamina
 
float m_StaminaSynced
 
float m_StaminaCap
 
float m_StaminaDepletion
 
float m_StaminaDepletionMultiplier
 
float m_StaminaRecoveryMultiplier
 
float m_Time
 
ref Param3< float, float, boolm_StaminaParams
 
ref HumanMovementState m_State
 
SHumanCommandMoveSettings m_HumanMoveSettings
 
PlayerBase m_Player
 
bool m_Debug
 
bool m_StaminaDepleted
 DEPRECATED.
 
ref map< int, ref Timerm_TimerMap
 
ref map< EStaminaMultiplierTypes, floatm_RegisteredDepletionModifiers
 
ref set< EStaminaMultiplierTypesm_ActiveDepletionModifiers
 
ref map< EStaminaMultiplierTypes, floatm_RegisteredRecoveryModifiers
 
ref set< EStaminaMultiplierTypesm_ActiveRecoveryModifiers
 
bool m_IsInCooldown
 
ref StaminaConsumers m_StaminaConsumers
 
ref StaminaModifiers m_StaminaModifiers
 

Detailed Description

Definition at line 258 of file StaminaHandler.c.

Constructor & Destructor Documentation

◆ StaminaHandler()

void StaminaHandler::StaminaHandler ( PlayerBase player)
inlineprotected

Definition at line 293 of file StaminaHandler.c.

294 {
295 if (GetGame().IsServer() || !GetGame().IsMultiplayer())
297
305 m_Time = 0;
306 m_StaminaDepleted = false;
307 m_IsInCooldown = false;
308 m_HumanMoveSettings = m_Player.GetDayZPlayerType().CommandMoveSettingsW();
309
312
314
315 //----------------- depletion --------------------
318
319 //----------------- recovery --------------------
322
323 Init();
324 }
static float GetStaminaMax()
float m_StaminaDepletionMultiplier
void RegisterStaminaModifiers()
ref HumanMovementState m_State
float m_StaminaRecoveryMultiplier
ref set< EStaminaMultiplierTypes > m_ActiveDepletionModifiers
void RegisterStaminaConsumers()
ref map< int, ref Timer > m_TimerMap
ref Param3< float, float, bool > m_StaminaParams
PlayerBase m_Player
ref set< EStaminaMultiplierTypes > m_ActiveRecoveryModifiers
bool m_StaminaDepleted
DEPRECATED.
SHumanCommandMoveSettings m_HumanMoveSettings
ref map< EStaminaMultiplierTypes, float > m_RegisteredRecoveryModifiers
ref map< EStaminaMultiplierTypes, float > m_RegisteredDepletionModifiers
proto native CGame GetGame()

References GetGame(), CfgGameplayHandler::GetStaminaMax(), Init(), m_ActiveDepletionModifiers, m_ActiveRecoveryModifiers, m_HumanMoveSettings, m_IsInCooldown, m_Player, m_RegisteredDepletionModifiers, m_RegisteredRecoveryModifiers, m_Stamina, m_StaminaCap, m_StaminaDepleted, m_StaminaDepletion, m_StaminaDepletionMultiplier, m_StaminaParams, m_StaminaRecoveryMultiplier, m_State, m_Time, m_TimerMap, RegisterStaminaConsumers(), and RegisterStaminaModifiers().

Member Function Documentation

◆ ActivateDepletionModifier()

void StaminaHandler::ActivateDepletionModifier ( EStaminaMultiplierTypes type)
inlineprotected

Definition at line 341 of file StaminaHandler.c.

342 {
343 if (m_RegisteredDepletionModifiers.Contains(type))
344 {
345 m_ActiveDepletionModifiers.Insert(type);
347 }
348 else
349 Error("attempting to activate unregistered depletion modifier");
350 }
void RecalculateDepletionMultiplier()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90

References Error(), m_ActiveDepletionModifiers, m_RegisteredDepletionModifiers, and RecalculateDepletionMultiplier().

◆ ActivateRecoveryModifier()

void StaminaHandler::ActivateRecoveryModifier ( EStaminaMultiplierTypes type)
inlineprotected

Definition at line 373 of file StaminaHandler.c.

374 {
375 if (m_RegisteredRecoveryModifiers.Contains(type))
376 {
377 m_ActiveRecoveryModifiers.Insert(type);
379 }
380 else
381 Error("attempting to activate unregistered recovery modifier");
382 }
void RecalculateRecoveryMultiplier()

References Error(), m_ActiveRecoveryModifiers, m_RegisteredRecoveryModifiers, and RecalculateRecoveryMultiplier().

◆ ApplyExhaustion()

void StaminaHandler::ApplyExhaustion ( )
inlineprotected

sets exhaustion look of player based on stamina level

Definition at line 755 of file StaminaHandler.c.

756 {
758 HumanCommandAdditives ad = m_Player.GetCommandModifier_Additives();
759
760 float exhaustion_value = 1;
761 if (m_StaminaCap != 0)
762 exhaustion_value = 1 - ((m_Stamina / (m_StaminaCap * 0.01)) * 0.01);
763
765 if (ad)
766 {
767 // do not apply exhaustion on local client if player is in ADS/Optics (camera shakes)
768 if (m_Player.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT && (m_Player.IsInOptics() || m_Player.IsInIronsights()))
769 ad.SetExhaustion(0, true);
770 else
771 ad.SetExhaustion(exhaustion_value, true);
772 }
773 }
Definition EnMath.c:7
DayZPlayerInstanceType
defined in C++
static proto float Min(float x, float y)
Returns smaller of two given values.
class HumanCommandWeapons HumanCommandAdditives()
Definition human.c:1086

References HumanCommandAdditives(), m_Player, m_Stamina, m_StaminaCap, and Math::Min().

Referenced by Update().

◆ CalcStaminaGainBonus()

float StaminaHandler::CalcStaminaGainBonus ( )
inlineprotected

Calulates stamina regain bonus coef based on current stamina cap and level.

Definition at line 744 of file StaminaHandler.c.

745 {
746 if (m_StaminaDepletion > 0)
747 return 0;
748
749 if (m_Stamina > 25)
750 return Math.Min((m_Stamina / 10), GameConstants.STAMINA_GAIN_BONUS_CAP); // exp version
751 else
752 return GameConstants.STAMINA_GAIN_BONUS_CAP; // linear version
753 }
const float STAMINA_GAIN_BONUS_CAP
Definition constants.c:644

References m_Stamina, m_StaminaDepletion, Math::Min(), and GameConstants::STAMINA_GAIN_BONUS_CAP.

Referenced by StaminaProcessor_Ladder(), StaminaProcessor_Move(), and StaminaProcessor_Swimming().

◆ CheckStaminaState()

void StaminaHandler::CheckStaminaState ( )
inlineprotected

check if the stamina is completely depleted

in case of complete depletion - start a cooldown timer before the regeneration cycle start

Definition at line 776 of file StaminaHandler.c.

777 {
778 if (m_Stamina <= 0)
779 {
780 m_StaminaDepleted = true;
782 if (!m_IsInCooldown)
783 {
784 // set this only once
786 }
787 }
788 else
789 m_StaminaDepleted = false;
790 }
void SetCooldown(float time, int modifier=-1)
set cooldown timer between each consume of stamina
const float STAMINA_REGEN_COOLDOWN_EXHAUSTION
Definition constants.c:659

References m_IsInCooldown, m_Stamina, m_StaminaDepleted, SetCooldown(), and GameConstants::STAMINA_REGEN_COOLDOWN_EXHAUSTION.

Referenced by Update().

◆ DeactivateDepletionModifier()

void StaminaHandler::DeactivateDepletionModifier ( EStaminaMultiplierTypes type)
inlineprotected

Definition at line 352 of file StaminaHandler.c.

353 {
354 int index = m_ActiveDepletionModifiers.Find(type);
355 if (index != -1)
356 {
359 }
360 }

References m_ActiveDepletionModifiers, and RecalculateDepletionMultiplier().

◆ DeactivateRecoveryModifier()

void StaminaHandler::DeactivateRecoveryModifier ( EStaminaMultiplierTypes type)
inlineprotected

Definition at line 385 of file StaminaHandler.c.

386 {
387 int index = m_ActiveRecoveryModifiers.Find(type);
388 if (index != -1)
389 {
392 }
393 }

References m_ActiveRecoveryModifiers, and RecalculateRecoveryMultiplier().

◆ DepleteStamina()

void StaminaHandler::DepleteStamina ( EStaminaModifiers modifier,
float dT = -1 )
inlineprotected

run cooldown right after depletion

Definition at line 908 of file StaminaHandler.c.

909 {
910#ifdef DIAG_DEVELOPER
912 return;
913#endif
914 float val = 0.0;
915 float current_time = m_Player.GetSimulationTimeStamp();
916 float valueProgress;
917 StaminaModifier sm = m_StaminaModifiers.GetModifierData(modifier);
918
919 // select by modifier type and drain stamina
920 switch (sm.GetType())
921 {
922 case m_StaminaModifiers.FIXED:
923 if (dT == -1)
924 dT = 1;
925 m_StaminaDepletion = m_StaminaDepletion + sm.GetMaxValue() * dT;
926
927 break;
928
929 case m_StaminaModifiers.RANDOMIZED:
930 val = Math.RandomFloat(sm.GetMinValue(), sm.GetMaxValue());
932
933 break;
934
935 case m_StaminaModifiers.LINEAR:
936 if (!sm.IsInUse())
937 {
938 sm.SetStartTime(current_time + sm.GetStartTimeAdjustment() / dT);
939 sm.SetRunTimeTick(dT);
940 sm.SetInUse(true);
941 }
942 valueProgress = Math.Clamp((current_time - sm.GetStartTime()) / sm.GetDurationAdjusted(), 0, 1);
943 val = Math.Lerp(sm.GetMinValue(), sm.GetMaxValue(), valueProgress);
945
946 break;
947
948 case m_StaminaModifiers.EXPONENTIAL:
950 if (!Class.CastTo(smex, sm))
951 {
952 ErrorEx("StaminaModifierExponential not found for modifier type: " + sm.GetType());
953 break;
954 }
955
956 if (!smex.IsInUse())
957 {
958 smex.SetStartTime(current_time + smex.GetStartTimeAdjustment() / dT);
959 smex.SetRunTimeTick(dT);
960 smex.SetInUse(true);
961 }
962 valueProgress = Math.Clamp((current_time - smex.GetStartTime()) / smex.GetDurationAdjusted(), 0, 1);
963 float exp;
964 if (Math.AbsFloat(smex.GetBaseValue()) < 1)
965 {
966 exp = 1 - Math.Lerp(0, smex.GetExponent(), valueProgress);
967 val = Math.Pow(smex.GetBaseValue(), exp);
968 }
969 else
970 {
971 exp = Math.Lerp(Math.Min(0, smex.GetExponent()), Math.Max(0, smex.GetExponent()), valueProgress);
972 val = Math.Pow(smex.GetBaseValue(), exp) + smex.GetBaseValue() - 1;
973 }
974
976 m_StaminaDepletion *= smex.GetMultiplier();
977
978 break;
979 }
980
982 SetCooldown(sm.GetCooldown(), modifier);
984
986 }
Super root of all classes in Enforce script.
Definition EnScript.c:11
ref StaminaModifiers m_StaminaModifiers
enum ShapeType ErrorEx
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float Max(float x, float y)
Returns bigger of two given values.
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static proto float Pow(float v, float power)
Return power of v ^ power.
static proto float AbsFloat(float f)
Returns absolute value.

References Math::AbsFloat(), Class::CastTo(), Math::Clamp(), ErrorEx, CfgGameplayHandler::GetStaminaMax(), Math::Lerp(), m_Player, m_StaminaDepletion, m_StaminaDepletionMultiplier, m_StaminaModifiers, Math::Max(), Math::Min(), Math::Pow(), Math::RandomFloat(), and SetCooldown().

◆ GetCooldownTimer()

Timer StaminaHandler::GetCooldownTimer ( int modifier)
inlineprotected

Definition at line 829 of file StaminaHandler.c.

830 {
831
832 }

◆ GetDepletionMultiplier()

float StaminaHandler::GetDepletionMultiplier ( )
inlineprotected

Definition at line 898 of file StaminaHandler.c.

899 {
901 }

References m_StaminaDepletionMultiplier.

◆ GetRecoveryMultiplier()

float StaminaHandler::GetRecoveryMultiplier ( )
inlineprotected

Definition at line 903 of file StaminaHandler.c.

904 {
906 }

References m_StaminaRecoveryMultiplier.

◆ GetStamina()

float StaminaHandler::GetStamina ( )
inlineprotected

Definition at line 851 of file StaminaHandler.c.

852 {
853 return m_Stamina;
854 }

References m_Stamina.

◆ GetStaminaCap()

float StaminaHandler::GetStaminaCap ( )
inlineprotected

Definition at line 871 of file StaminaHandler.c.

872 {
873 return m_StaminaCap;
874 }

References m_StaminaCap.

◆ GetStaminaMax()

float StaminaHandler::GetStaminaMax ( )
inlineprotected

Definition at line 876 of file StaminaHandler.c.

877 {
879 }

References CfgGameplayHandler::GetStaminaMax().

Referenced by GetStaminaNormalized(), and GetSyncedStaminaNormalized().

◆ GetStaminaNormalized()

float StaminaHandler::GetStaminaNormalized ( )
inlineprotected

Definition at line 856 of file StaminaHandler.c.

857 {
858 return m_Stamina / GetStaminaMax();
859 }

References GetStaminaMax(), and m_Stamina.

◆ GetSyncedStamina()

float StaminaHandler::GetSyncedStamina ( )
inlineprotected

Definition at line 861 of file StaminaHandler.c.

862 {
863 return m_StaminaSynced;
864 }

References m_StaminaSynced.

Referenced by GetSyncedStaminaNormalized().

◆ GetSyncedStaminaNormalized()

float StaminaHandler::GetSyncedStaminaNormalized ( )
inlineprotected

Definition at line 866 of file StaminaHandler.c.

867 {
868 return GetSyncedStamina() / GetStaminaMax();
869 }
float GetSyncedStamina()

References GetStaminaMax(), and GetSyncedStamina().

◆ HasEnoughStaminaFor()

bool StaminaHandler::HasEnoughStaminaFor ( EStaminaConsumers consumer)
inlineprotected

Definition at line 835 of file StaminaHandler.c.

836 {
838 }
ref StaminaConsumers m_StaminaConsumers

References m_Stamina, m_StaminaCap, m_StaminaConsumers, and m_StaminaDepleted.

◆ HasEnoughStaminaToStart()

bool StaminaHandler::HasEnoughStaminaToStart ( EStaminaConsumers consumer)
inlineprotected

Definition at line 840 of file StaminaHandler.c.

841 {
842 return m_StaminaConsumers.HasEnoughStaminaToStart(consumer, m_Stamina, m_StaminaDepleted, m_StaminaCap);
843 }

References m_Stamina, m_StaminaCap, m_StaminaConsumers, and m_StaminaDepleted.

◆ Init()

void StaminaHandler::Init ( )
inlineprotected

Definition at line 327 of file StaminaHandler.c.

328 {
329 //----------------- depletion --------------------
333
334 //----------------- recovery --------------------
338
339 }
EStaminaMultiplierTypes
static const float STAMINA_RECOVERY_MULTIPLIER
Definition Drowning.c:4
const float STAMINA_DEPLETION_MULTIPLIER
static const float STAMINA_DEPLETION_MULTIPLIER
Definition Fatigue.c:9
static const float STAMINA_RECOVERY_MULTIPLIER
Definition Fatigue.c:8
Definition Mask.c:2
const float STAMINA_RECOVERY_MODIFIER
Definition Mask.c:6
const float STAMINA_DEPLETION_MODIFIER
Definition Mask.c:7

References m_RegisteredDepletionModifiers, m_RegisteredRecoveryModifiers, MaskMdfr::STAMINA_DEPLETION_MODIFIER, FatigueMdfr::STAMINA_DEPLETION_MULTIPLIER, EpinephrineMdfr::STAMINA_DEPLETION_MULTIPLIER, MaskMdfr::STAMINA_RECOVERY_MODIFIER, FatigueMdfr::STAMINA_RECOVERY_MULTIPLIER, and DrowningMdfr::STAMINA_RECOVERY_MULTIPLIER.

Referenced by StaminaHandler().

◆ OnRPC()

void StaminaHandler::OnRPC ( float stamina,
float stamina_cap,
bool cooldown )
inlineprotected

deprecated use, StaminaHandler uses SyncJunctures now

Definition at line 487 of file StaminaHandler.c.

488 {
489 }

◆ OnSyncJuncture()

void StaminaHandler::OnSyncJuncture ( int pJunctureID,
ParamsReadContext pCtx )
inlineprotected

called from PlayerBase - syncs stamina values on server with client AND sets the value to match on server and client both (m_StaminaSynced guarantees identical values)

Definition at line 492 of file StaminaHandler.c.

493 {
494 switch (pJunctureID)
495 {
497 float stamina;
498 float stamina_cap;
499 bool cooldown;
500
501 if (!pCtx.Read(stamina) || !pCtx.Read(stamina_cap) || !pCtx.Read(cooldown))
502 return;
503
504 m_Stamina = stamina; //?
506
507 if (m_Player.GetInstanceType() != DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
508 return;
509
512
514 m_Player.SetStamina(m_Stamina, m_StaminaCap);
515 break;
516
519 break;
520 }
521 }
void ReadAdditionalStaminaInfo(ParamsReadContext pCtx)
Order of read parameters must match the order of writing above.

References m_IsInCooldown, m_Player, m_Stamina, m_StaminaCap, m_StaminaSynced, ReadAdditionalStaminaInfo(), DayZPlayerSyncJunctures::SJ_STAMINA, and DayZPlayerSyncJunctures::SJ_STAMINA_MISC.

Referenced by ManBase::OnSyncJuncture().

◆ ReadAdditionalStaminaInfo()

void StaminaHandler::ReadAdditionalStaminaInfo ( ParamsReadContext pCtx)
inlineprotected

Order of read parameters must match the order of writing above.

Definition at line 644 of file StaminaHandler.c.

References m_StaminaDepletionMultiplier, and m_StaminaRecoveryMultiplier.

Referenced by OnSyncJuncture().

◆ RecalculateDepletionMultiplier()

void StaminaHandler::RecalculateDepletionMultiplier ( )
inlineprotected

◆ RecalculateRecoveryMultiplier()

void StaminaHandler::RecalculateRecoveryMultiplier ( )
inlineprotected

◆ RegisterStaminaConsumers()

void StaminaHandler::RegisterStaminaConsumers ( )
inlineprotected

Definition at line 655 of file StaminaHandler.c.

656 {
658
659 m_StaminaConsumers.RegisterConsumer(
660 EStaminaConsumers.HOLD_BREATH,
663 );
664 m_StaminaConsumers.RegisterConsumer(
665 EStaminaConsumers.SPRINT,
667 );
668 m_StaminaConsumers.RegisterConsumer(
671 );
672 m_StaminaConsumers.RegisterConsumer(
673 EStaminaConsumers.VAULT,
675 );
676 m_StaminaConsumers.RegisterConsumer(
677 EStaminaConsumers.CLIMB,
679 );
680 m_StaminaConsumers.RegisterConsumer(
681 EStaminaConsumers.MELEE_HEAVY,
683 );
684 m_StaminaConsumers.RegisterConsumer(
685 EStaminaConsumers.MELEE_EVADE,
687 );
688 m_StaminaConsumers.RegisterConsumer(
691 );
692 m_StaminaConsumers.RegisterConsumer(EStaminaConsumers.DROWN, 0);
693 m_StaminaConsumers.RegisterConsumer(EStaminaConsumers.PUSH, 0);
694 }
EStaminaConsumers
void StaminaConsumers()
static float GetStaminaMinCap()
const float STAMINA_HOLD_BREATH_THRESHOLD_DRAIN
Definition constants.c:649
const float STAMINA_ROLL_THRESHOLD
Definition constants.c:653
const float STAMINA_CLIMB_THRESHOLD
Definition constants.c:652
const float STAMINA_JUMP_THRESHOLD
Definition constants.c:650
const float STAMINA_VAULT_THRESHOLD
Definition constants.c:651
const float STAMINA_MELEE_EVADE_THRESHOLD
Definition constants.c:657
const float STAMINA_HOLD_BREATH_THRESHOLD_ACTIVATE
Definition constants.c:648
const float STAMINA_MELEE_HEAVY_THRESHOLD
Definition constants.c:656

References CfgGameplayHandler::GetStaminaMinCap(), m_StaminaConsumers, GameConstants::STAMINA_CLIMB_THRESHOLD, GameConstants::STAMINA_HOLD_BREATH_THRESHOLD_ACTIVATE, GameConstants::STAMINA_HOLD_BREATH_THRESHOLD_DRAIN, GameConstants::STAMINA_JUMP_THRESHOLD, GameConstants::STAMINA_MELEE_EVADE_THRESHOLD, GameConstants::STAMINA_MELEE_HEAVY_THRESHOLD, GameConstants::STAMINA_ROLL_THRESHOLD, GameConstants::STAMINA_VAULT_THRESHOLD, and StaminaConsumers().

Referenced by StaminaHandler().

◆ RegisterStaminaModifiers()

void StaminaHandler::RegisterStaminaModifiers ( )
inlineprotected

Definition at line 696 of file StaminaHandler.c.

697 {
699
701 m_StaminaModifiers.RegisterExponentialEx(
702 EStaminaModifiers.HOLD_BREATH,
703 data,
704 );
705 m_StaminaModifiers.RegisterExponentialEx(
706 EStaminaModifiers.PUSH_CAR,
707 data,
708 );
709 m_StaminaModifiers.RegisterFixed(EStaminaModifiers.DROWN, 10);
710 m_StaminaModifiers.RegisterFixed(
713 );
714 m_StaminaModifiers.RegisterFixed(
715 EStaminaModifiers.VAULT,
717 );
718 m_StaminaModifiers.RegisterFixed(
719 EStaminaModifiers.CLIMB,
721 );
722 m_StaminaModifiers.RegisterFixed(
723 EStaminaModifiers.MELEE_LIGHT,
725 );
726 m_StaminaModifiers.RegisterFixed(
727 EStaminaModifiers.MELEE_HEAVY,
729 );
730 m_StaminaModifiers.RegisterFixed(
731 EStaminaModifiers.OVERALL_DRAIN,
733 5.0,
734 );
735 m_StaminaModifiers.RegisterRandomized(
736 EStaminaModifiers.MELEE_EVADE,
739 );
741 }
EStaminaModifiers
void StaminaModifiers()
static float GetObstacleTraversalStaminaModifier()
static float GetMeleeStaminaModifier()
const float STAMINA_DRAIN_CLIMB
Definition constants.c:629
const float STAMINA_DRAIN_MELEE_LIGHT
Definition constants.c:630
const float STAMINA_DRAIN_MELEE_HEAVY
Definition constants.c:631
const float STAMINA_DRAIN_JUMP
Definition constants.c:627
const float STAMINA_DRAIN_ROLL
Definition constants.c:633
const float STAMINA_DRAIN_MELEE_EVADE
Definition constants.c:632
const float STAMINA_DRAIN_VAULT
Definition constants.c:628

References CfgGameplayHandler::GetMeleeStaminaModifier(), CfgGameplayHandler::GetObstacleTraversalStaminaModifier(), CfgGameplayHandler::GetStaminaMax(), m_StaminaModifiers, GameConstants::STAMINA_DRAIN_CLIMB, GameConstants::STAMINA_DRAIN_JUMP, GameConstants::STAMINA_DRAIN_MELEE_EVADE, GameConstants::STAMINA_DRAIN_MELEE_HEAVY, GameConstants::STAMINA_DRAIN_MELEE_LIGHT, GameConstants::STAMINA_DRAIN_ROLL, GameConstants::STAMINA_DRAIN_VAULT, and StaminaModifiers().

Referenced by StaminaHandler().

◆ ResetCooldown()

void StaminaHandler::ResetCooldown ( int modifier = -1)
inlineprotected

Definition at line 815 of file StaminaHandler.c.

816 {
817 StaminaModifier sm = m_StaminaModifiers.GetModifierData(modifier);
818 if (sm)
819 {
820 //Print(modifier);
821 //Error("Error: No StaminaModifier found! | StaminaHandler | ResetCooldown");
822 sm.SetStartTime(-1);
823 sm.ResetRunTime();
824 sm.SetInUse(false);
825 }
826 m_IsInCooldown = false;
827 }

References m_IsInCooldown, and m_StaminaModifiers.

Referenced by SetCooldown().

◆ SetCooldown()

void StaminaHandler::SetCooldown ( float time,
int modifier = -1 )
inlineprotected

set cooldown timer between each consume of stamina

Definition at line 793 of file StaminaHandler.c.

794 {
795 if (m_StaminaDepleted || m_Stamina <= 0.0)
796 {
798 return;
799 }
800
801 m_IsInCooldown = true;
802
803 Timer timer;
804 if (m_TimerMap.Find(modifier, timer) && timer.IsRunning())
805 timer.Stop();
806 else
807 {
808 timer = new ref Timer;
810 }
811 timer.Run(time, this, "ResetCooldown", new Param1<int>(modifier));
812 //Print(m_TimerMap.Count());
813 }
void ResetCooldown(int modifier=-1)

References m_IsInCooldown, m_Stamina, m_StaminaDepleted, m_TimerMap, and ResetCooldown().

Referenced by CheckStaminaState(), DepleteStamina(), StaminaProcessor_Ladder(), StaminaProcessor_Move(), and StaminaProcessor_Swimming().

◆ SetDepletionMultiplier()

void StaminaHandler::SetDepletionMultiplier ( float val)
inlineprotected

Definition at line 882 of file StaminaHandler.c.

883 {
888 }
void SyncAdditionalStaminaInfo(Param par)
Method to sync more info for stamina manager. Template parameter means it is very extendable for furt...

References m_StaminaDepletionMultiplier, m_StaminaRecoveryMultiplier, and SyncAdditionalStaminaInfo().

Referenced by RecalculateDepletionMultiplier().

◆ SetRecoveryMultiplier()

◆ SetStamina()

void StaminaHandler::SetStamina ( float stamina_value)
inlineprotected

Definition at line 845 of file StaminaHandler.c.

846 {
849 }
void SyncStamina(float stamina, float stamina_cap, bool cooldown)
stamina sync - server part

References Math::Clamp(), CfgGameplayHandler::GetStaminaMax(), m_IsInCooldown, m_Stamina, m_StaminaCap, and SyncStamina().

Referenced by ManBase::EEHitBy(), ManBase::ResetPlayer(), and Update().

◆ StaminaProcessor_Ladder()

void StaminaHandler::StaminaProcessor_Ladder ( HumanMovementState pHumanMovementState)
inlineprotected

Definition at line 578 of file StaminaHandler.c.

579 {
580 switch (pHumanMovementState.m_iMovement)
581 {
582 case 2: //climb up (fast)
585 break;
586
587 case 1: //climb up (slow)
588 if (!m_IsInCooldown)
590 break;
591
592 default:
593 if (!m_IsInCooldown)
595 break;
596 }
597 }
static float GetSprintLadderStaminaModifier()
float CalcStaminaGainBonus()
Calulates stamina regain bonus coef based on current stamina cap and level.
const int STAMINA_GAIN_IDLE_PER_SEC
Definition constants.c:640
const float STAMINA_REGEN_COOLDOWN_DEPLETION
Definition constants.c:658
const int STAMINA_DRAIN_LADDER_FAST_PER_SEC
Definition constants.c:623
const int STAMINA_GAIN_LADDER_PER_SEC
Definition constants.c:642

References CalcStaminaGainBonus(), CfgGameplayHandler::GetSprintLadderStaminaModifier(), m_IsInCooldown, m_StaminaDelta, SetCooldown(), GameConstants::STAMINA_DRAIN_LADDER_FAST_PER_SEC, GameConstants::STAMINA_GAIN_IDLE_PER_SEC, GameConstants::STAMINA_GAIN_LADDER_PER_SEC, and GameConstants::STAMINA_REGEN_COOLDOWN_DEPLETION.

Referenced by Update().

◆ StaminaProcessor_Move()

void StaminaHandler::StaminaProcessor_Move ( HumanMovementState pHumanMovementState)
inlineprotected

Definition at line 523 of file StaminaHandler.c.

524 {
525 switch (pHumanMovementState.m_iMovement)
526 {
527 case DayZPlayerConstants.MOVEMENTIDX_SPRINT: //sprint
528 if (pHumanMovementState.m_iStanceIdx == DayZPlayerConstants.STANCEIDX_ERECT)
529 {
532 break;
533 }
534 else if (pHumanMovementState.m_iStanceIdx == DayZPlayerConstants.STANCEIDX_CROUCH)
535 {
538 break;
539 }
540
542 break;
543
544 case DayZPlayerConstants.MOVEMENTIDX_RUN: //jog
545 if (m_Player.GetCurrentWaterLevel() >= m_HumanMoveSettings.m_fWaterLevelSpeedRectrictionHigh)
546 {
548 break;
549 }
550
551 if (!m_IsInCooldown)
553 break;
554
555 case DayZPlayerConstants.MOVEMENTIDX_WALK: //walk
556 if (!m_IsInCooldown)
558 break;
559
560 case DayZPlayerConstants.MOVEMENTIDX_IDLE: //idle
561 if (m_Player.IsRolling())
562 {
564 break;
565 }
566
567 if (!m_IsInCooldown)
569 break;
570
571 default:
572 if (!m_IsInCooldown)
574 break;
575 }
576 }
static float GetSprintStaminaModifierCro()
static float GetSprintStaminaModifierErc()
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:597
const int STAMINA_GAIN_WALK_PER_SEC
Definition constants.c:639
const int STAMINA_GAIN_JOG_PER_SEC
Definition constants.c:638
const int STAMINA_GAIN_ROLL_PER_SEC
Definition constants.c:643
const int STAMINA_DRAIN_STANDING_SPRINT_PER_SEC
Definition constants.c:619
const int STAMINA_DRAIN_CROUCHED_SPRINT_PER_SEC
Definition constants.c:620

References CalcStaminaGainBonus(), CfgGameplayHandler::GetSprintStaminaModifierCro(), CfgGameplayHandler::GetSprintStaminaModifierErc(), m_HumanMoveSettings, m_IsInCooldown, m_Player, m_StaminaDelta, SetCooldown(), GameConstants::STAMINA_DRAIN_CROUCHED_SPRINT_PER_SEC, GameConstants::STAMINA_DRAIN_STANDING_SPRINT_PER_SEC, GameConstants::STAMINA_GAIN_IDLE_PER_SEC, GameConstants::STAMINA_GAIN_JOG_PER_SEC, GameConstants::STAMINA_GAIN_ROLL_PER_SEC, GameConstants::STAMINA_GAIN_WALK_PER_SEC, and GameConstants::STAMINA_REGEN_COOLDOWN_DEPLETION.

Referenced by Update().

◆ StaminaProcessor_Swimming()

◆ SyncAdditionalStaminaInfo()

void StaminaHandler::SyncAdditionalStaminaInfo ( Param par)
inlineprotected

Method to sync more info for stamina manager. Template parameter means it is very extendable for further use.

Definition at line 633 of file StaminaHandler.c.

634 {
636
638 pCtx.Write(p.param1);
639 pCtx.Write(p.param2);
641 }

References m_Player, and DayZPlayerSyncJunctures::SJ_STAMINA_MISC.

Referenced by SetDepletionMultiplier(), and SetRecoveryMultiplier().

◆ SyncStamina()

void StaminaHandler::SyncStamina ( float stamina,
float stamina_cap,
bool cooldown )
inlineprotected

stamina sync - server part

Definition at line 622 of file StaminaHandler.c.

623 {
624 m_Player.GetStatStamina().Set(m_Stamina);
626 pCtx.Write(m_Stamina);
627 pCtx.Write(m_StaminaCap);
628 pCtx.Write(m_IsInCooldown);
630 }

References m_IsInCooldown, m_Player, m_Stamina, m_StaminaCap, and DayZPlayerSyncJunctures::SJ_STAMINA.

Referenced by SetStamina().

◆ Update()

void StaminaHandler::Update ( float deltaT,
int pCurrentCommandID )
inlineprotected

gets the actual players load

StaminaCap calculation starts when PlayerLoad exceeds STAMINA_WEIGHT_LIMIT_THRESHOLD

processed on event

processed on event

processed on event

Definition at line 406 of file StaminaHandler.c.

407 {
408#ifdef DIAG_DEVELOPER
410 return;
411#endif
412 if (m_Player)
413 {
414 // Calculates actual max stamina based on player's load
415 if (GetGame().IsServer() || !GetGame().IsMultiplayer())
416 {
418 m_PlayerLoad = m_Player.GetWeightEx();
419
423 else
425 }
426
427 // Calculates stamina gain/loss based on movement and load
428 m_Player.GetMovementState(m_State);
429
430 switch (m_State.m_CommandTypeId)
431 {
432 case DayZPlayerConstants.COMMANDID_MOVE:
434 break;
435 case DayZPlayerConstants.COMMANDID_LADDER:
437 break;
438 case DayZPlayerConstants.COMMANDID_SWIM:
440 break;
441 case DayZPlayerConstants.COMMANDID_FALL:
442 case DayZPlayerConstants.COMMANDID_MELEE2:
443 case DayZPlayerConstants.COMMANDID_CLIMB:
444 break;
445 default:
446 if (!m_IsInCooldown)
448 break;
449 }
450
451 //Sets current stamina & stores + syncs data with client
452 float temp = m_StaminaDelta * deltaT;
453 if (temp < 0)
455 else
457
460
461 if (GetGame().IsServer() || !GetGame().IsMultiplayer())
462 {
463 m_Player.GetStatStamina().Set(m_Stamina);
464 m_Time += deltaT;
465
467 {
468 m_Time = 0;
470 }
471 }
472
473#ifndef SERVER
475#endif
476
479
480 m_StaminaDelta = 0;
481 m_StaminaDepletion = 0; // resets depletion modifier
482
483 }
484 }
static float GetStaminaKgToStaminaPercentPenalty()
static float GetStaminaWeightLimitThreshold()
void StaminaProcessor_Ladder(HumanMovementState pHumanMovementState)
void StaminaProcessor_Swimming(HumanMovementState pHumanMovementState)
void CheckStaminaState()
check if the stamina is completely depleted
void StaminaProcessor_Move(HumanMovementState pHumanMovementState)
void SetStamina(float stamina_value)
const float STAMINA_KG_TO_GRAMS
in grams (weight where the player is not penalized by stamina)
Definition constants.c:661
const float STAMINA_SYNC_RATE
Definition constants.c:662

References ApplyExhaustion(), CheckStaminaState(), GetGame(), CfgGameplayHandler::GetStaminaKgToStaminaPercentPenalty(), CfgGameplayHandler::GetStaminaMax(), CfgGameplayHandler::GetStaminaMinCap(), CfgGameplayHandler::GetStaminaWeightLimitThreshold(), m_IsInCooldown, m_Player, m_PlayerLoad, m_Stamina, m_StaminaCap, m_StaminaDelta, m_StaminaDepletion, m_StaminaDepletionMultiplier, m_StaminaRecoveryMultiplier, m_StaminaSynced, m_State, m_Time, Math::Max(), Math::Min(), SetStamina(), GameConstants::STAMINA_GAIN_IDLE_PER_SEC, GameConstants::STAMINA_KG_TO_GRAMS, GameConstants::STAMINA_SYNC_RATE, StaminaProcessor_Ladder(), StaminaProcessor_Move(), and StaminaProcessor_Swimming().

Referenced by ManBase::CommandHandler().

Member Data Documentation

◆ m_ActiveDepletionModifiers

ref set<EStaminaMultiplierTypes> StaminaHandler::m_ActiveDepletionModifiers
protected

◆ m_ActiveRecoveryModifiers

ref set<EStaminaMultiplierTypes> StaminaHandler::m_ActiveRecoveryModifiers
protected

◆ m_Debug

bool StaminaHandler::m_Debug
protected

Definition at line 274 of file StaminaHandler.c.

◆ m_HumanMoveSettings

SHumanCommandMoveSettings StaminaHandler::m_HumanMoveSettings
protected

Definition at line 271 of file StaminaHandler.c.

Referenced by StaminaHandler(), and StaminaProcessor_Move().

◆ m_IsInCooldown

◆ m_Player

◆ m_PlayerLoad

float StaminaHandler::m_PlayerLoad
protected

Definition at line 260 of file StaminaHandler.c.

Referenced by Update().

◆ m_RegisteredDepletionModifiers

ref map<EStaminaMultiplierTypes, float> StaminaHandler::m_RegisteredDepletionModifiers
protected

◆ m_RegisteredRecoveryModifiers

ref map<EStaminaMultiplierTypes, float> StaminaHandler::m_RegisteredRecoveryModifiers
protected

◆ m_Stamina

◆ m_StaminaCap

◆ m_StaminaConsumers

ref StaminaConsumers StaminaHandler::m_StaminaConsumers
protected

◆ m_StaminaDelta

float StaminaHandler::m_StaminaDelta
protected

◆ m_StaminaDepleted

bool StaminaHandler::m_StaminaDepleted
protected

◆ m_StaminaDepletion

float StaminaHandler::m_StaminaDepletion
protected

Definition at line 265 of file StaminaHandler.c.

Referenced by CalcStaminaGainBonus(), DepleteStamina(), StaminaHandler(), and Update().

◆ m_StaminaDepletionMultiplier

◆ m_StaminaModifiers

ref StaminaModifiers StaminaHandler::m_StaminaModifiers
protected

Definition at line 287 of file StaminaHandler.c.

Referenced by DepleteStamina(), RegisterStaminaModifiers(), and ResetCooldown().

◆ m_StaminaParams

ref Param3<float, float, bool> StaminaHandler::m_StaminaParams
protected

Definition at line 269 of file StaminaHandler.c.

Referenced by StaminaHandler().

◆ m_StaminaRecoveryMultiplier

float StaminaHandler::m_StaminaRecoveryMultiplier
protected

◆ m_StaminaSynced

float StaminaHandler::m_StaminaSynced
protected

Definition at line 263 of file StaminaHandler.c.

Referenced by GetSyncedStamina(), OnSyncJuncture(), and Update().

◆ m_State

ref HumanMovementState StaminaHandler::m_State
protected

Definition at line 270 of file StaminaHandler.c.

Referenced by StaminaHandler(), and Update().

◆ m_Time

float StaminaHandler::m_Time
protected

Definition at line 268 of file StaminaHandler.c.

Referenced by StaminaHandler(), and Update().

◆ m_TimerMap

ref map<int, ref Timer> StaminaHandler::m_TimerMap
protected

Definition at line 277 of file StaminaHandler.c.

Referenced by SetCooldown(), and StaminaHandler().


The documentation for this class was generated from the following file: