19 protected float m_DrainThreshold
25 m_DrainThreshold = threshold2;
48 void RegisterConsumer(
EStaminaConsumers consumer,
float threshold,
float depletion_threshold = -1)
50 if (depletion_threshold == -1)
52 depletion_threshold = threshold;
63 bool HasEnoughStaminaFor(
EStaminaConsumers consumer,
float curStamina,
bool isDepleted,
float cap)
71 if ( (isDepleted || (curStamina < sc.GetDrainThreshold())) )
94 if ( curStamina > sc.GetDrainThreshold() || curStamina == cap )
104 bool HasEnoughStaminaToStart(
EStaminaConsumers consumer,
float curStamina,
bool isDepleted,
float cap)
110 if ( (isDepleted || (curStamina < sc.GetActivationThreshold() && curStamina < cap)) )
141 void StaminaModifier(
int type,
float min,
float max,
float cooldown,
float startTime = 0,
float duration = 0)
182 protected ref SMDataExponential m_SMDataEx;
184 float GetBaseValue() {
return m_SMDataEx.m_BaseValue; }
185 float GetExponent() {
return m_SMDataEx.m_Exponent; }
186 float GetMultiplier() {
return m_SMDataEx.m_Multiplier; }
187 override float GetCooldown() {
return m_SMDataEx.m_Cooldown; }
188 override float GetStartTimeAdjustment() {
return m_SMDataEx.m_StartTimeAdjustment; }
189 override float GetDuration() {
return m_SMDataEx.m_Duration; }
190 override float GetDurationAdjusted() {
return m_SMDataEx.m_Duration /
m_Tick; }
192 void SetData(SMDataExponential data) { m_SMDataEx = data; }
262 protected float m_PlayerLoad;
263 protected float m_StaminaDelta;
264 protected float m_Stamina;
265 protected float m_StaminaSynced;
266 protected float m_StaminaCap;
267 protected float m_StaminaDepletion;
268 protected float m_StaminaDepletionMultiplier;
269 protected float m_StaminaRecoveryMultiplier;
270 protected float m_Time;
276 protected bool m_Debug;
277 protected bool m_StaminaDepleted;
281 ref set<EStaminaMultiplierTypes> m_ActiveDepletionModifiers;
284 ref set<EStaminaMultiplierTypes> m_ActiveRecoveryModifiers;
286 protected bool m_IsInCooldown;
291 #ifdef DIAG_DEVELOPER
292 protected bool m_StaminaDisabled;
304 m_StaminaDepletion = 0;
305 m_StaminaDepletionMultiplier = 1;
306 m_StaminaRecoveryMultiplier = 1;
308 m_StaminaDepleted =
false;
309 m_IsInCooldown =
false;
310 m_HumanMoveSettings =
m_Player.GetDayZPlayerType().CommandMoveSettingsW();
312 RegisterStaminaConsumers();
313 RegisterStaminaModifiers();
319 m_ActiveDepletionModifiers =
new set<EStaminaMultiplierTypes>;
323 m_ActiveRecoveryModifiers =
new set<EStaminaMultiplierTypes>;
345 if (m_RegisteredDepletionModifiers.Contains(type))
347 m_ActiveDepletionModifiers.Insert(type);
348 RecalculateDepletionMultiplier();
352 Error(
"attempting to activate unregistered depletion modifier");
358 int index = m_ActiveDepletionModifiers.Find(type);
361 m_ActiveDepletionModifiers.Remove(index);
362 RecalculateDepletionMultiplier();
366 void RecalculateDepletionMultiplier()
370 foreach (
int multiplier: m_ActiveDepletionModifiers)
372 value *= m_RegisteredDepletionModifiers.Get(multiplier);
375 if (value != m_StaminaDepletionMultiplier)
376 SetDepletionMultiplier(value);
381 if (m_RegisteredRecoveryModifiers.Contains(type))
383 m_ActiveRecoveryModifiers.Insert(type);
384 RecalculateRecoveryMultiplier();
388 Error(
"attempting to activate unregistered recovery modifier");
395 int index = m_ActiveRecoveryModifiers.Find(type);
398 m_ActiveRecoveryModifiers.Remove(index);
399 RecalculateRecoveryMultiplier();
403 void RecalculateRecoveryMultiplier()
407 foreach (
int multiplier: m_ActiveRecoveryModifiers)
409 value *= m_RegisteredRecoveryModifiers.Get(multiplier);
412 if (value != m_StaminaRecoveryMultiplier)
414 SetRecoveryMultiplier(value);
418 void Update(
float deltaT,
int pCurrentCommandID)
420 #ifdef DIAG_DEVELOPER
421 if (m_StaminaDisabled)
430 m_PlayerLoad =
m_Player.GetWeightEx();
446 switch (
m_State.m_CommandTypeId)
449 StaminaProcessor_Move(
m_State);
452 StaminaProcessor_Ladder(
m_State);
455 StaminaProcessor_Swimming(
m_State);
470 float temp = m_StaminaDelta * deltaT;
473 temp *= m_StaminaDepletionMultiplier;
477 temp *= m_StaminaRecoveryMultiplier;
496 m_Player.SetStamina(m_StaminaSynced, m_StaminaCap);
503 m_StaminaDepletion = 0;
509 void OnRPC(
float stamina,
float stamina_cap,
bool cooldown)
516 switch ( pJunctureID )
523 if (!pCtx.Read(stamina) || !pCtx.Read(stamina_cap) || !pCtx.Read(cooldown))
529 m_StaminaSynced = stamina;
536 if ( stamina_cap != m_StaminaCap )
538 m_StaminaCap = stamina_cap;
541 m_IsInCooldown = cooldown;
546 ReadAdditionalStaminaInfo(pCtx);
553 switch (pHumanMovementState.m_iMovement)
573 if (
m_Player.GetCurrentWaterLevel() >= m_HumanMoveSettings.m_fWaterLevelSpeedRectrictionHigh)
581 m_StaminaDelta = (
GameConstants.STAMINA_GAIN_JOG_PER_SEC + CalcStaminaGainBonus());
588 m_StaminaDelta = (
GameConstants.STAMINA_GAIN_WALK_PER_SEC + CalcStaminaGainBonus());
601 m_StaminaDelta = (
GameConstants.STAMINA_GAIN_IDLE_PER_SEC + CalcStaminaGainBonus());
616 switch (pHumanMovementState.m_iMovement)
626 m_StaminaDelta = (
GameConstants.STAMINA_GAIN_LADDER_PER_SEC + CalcStaminaGainBonus());
633 m_StaminaDelta =
GameConstants.STAMINA_GAIN_IDLE_PER_SEC + CalcStaminaGainBonus();
641 switch (pHumanMovementState.m_iMovement)
652 m_StaminaDelta = (
GameConstants.STAMINA_GAIN_SWIM_PER_SEC + CalcStaminaGainBonus());
659 m_StaminaDelta =
GameConstants.STAMINA_GAIN_IDLE_PER_SEC + CalcStaminaGainBonus();
666 protected void SyncStamina(
float stamina,
float stamina_cap,
bool cooldown)
671 pCtx.Write(m_StaminaCap);
672 pCtx.Write(m_IsInCooldown);
677 protected void SyncAdditionalStaminaInfo(
Param par)
682 pCtx.Write(p.param1);
683 pCtx.Write(p.param2);
690 float depletionMultiplier;
691 float recoveryMultiplier;
692 if (!pCtx.Read(depletionMultiplier) || !pCtx.Read(recoveryMultiplier))
697 m_StaminaDepletionMultiplier = depletionMultiplier;
698 m_StaminaRecoveryMultiplier = recoveryMultiplier;
701 protected void RegisterStaminaConsumers()
742 protected void RegisterStaminaModifiers()
790 protected float CalcStaminaGainBonus()
792 if (m_StaminaDepletion > 0)
801 protected void ApplyExhaustion()
806 float exhaustion_value = 1;
807 if (m_StaminaCap != 0)
809 exhaustion_value = 1 - ((
m_Stamina / (m_StaminaCap * 0.01)) * 0.01);
812 exhaustion_value =
Math.Min(1, exhaustion_value);
818 ad.SetExhaustion(0,
true);
822 ad.SetExhaustion(exhaustion_value,
true);
828 protected void CheckStaminaState()
832 m_StaminaDepleted =
true;
837 SetCooldown(
GameConstants.STAMINA_REGEN_COOLDOWN_EXHAUSTION);
842 m_StaminaDepleted =
false;
847 protected void SetCooldown(
float time,
int modifier = -1)
849 if ( m_StaminaDepleted ||
m_Stamina <= 0.0 )
851 ResetCooldown(modifier);
855 m_IsInCooldown =
true;
858 if (m_TimerMap.Find(modifier, timer) && timer.IsRunning())
864 timer =
new ref
Timer;
865 m_TimerMap.Set(modifier,timer);
867 timer.Run(time,
this,
"ResetCooldown",
new Param1<int>( modifier ));
871 protected void ResetCooldown(
int modifier = -1)
882 m_IsInCooldown =
false;
885 Timer GetCooldownTimer(
int modifier)
901 void SetStamina(
float stamina_value)
904 SyncStamina(
m_Stamina, m_StaminaCap, m_IsInCooldown);
912 float GetStaminaNormalized()
917 float GetSyncedStamina()
919 return m_StaminaSynced;
922 float GetSyncedStaminaNormalized()
924 return GetSyncedStamina() / GetStaminaMax();
927 float GetStaminaCap()
932 float GetStaminaMax()
938 void SetDepletionMultiplier(
float val)
940 if (m_StaminaDepletionMultiplier < 0)
941 m_StaminaDepletionMultiplier = 0;
942 m_StaminaDepletionMultiplier = val;
943 SyncAdditionalStaminaInfo(
new Param2<float,float>(m_StaminaDepletionMultiplier,m_StaminaRecoveryMultiplier));
946 void SetRecoveryMultiplier(
float val)
948 if (m_StaminaRecoveryMultiplier < 0)
949 m_StaminaRecoveryMultiplier = 0;
950 m_StaminaRecoveryMultiplier = val;
951 SyncAdditionalStaminaInfo(
new Param2<float,float>(m_StaminaDepletionMultiplier,m_StaminaRecoveryMultiplier));
954 float GetDepletionMultiplier()
956 return m_StaminaDepletionMultiplier;
959 float GetRecoveryMultiplier()
961 return m_StaminaRecoveryMultiplier;
966 #ifdef DIAG_DEVELOPER
967 if (m_StaminaDisabled)
971 float current_time =
m_Player.GetSimulationTimeStamp();
976 switch (sm.GetType())
983 m_StaminaDepletion = m_StaminaDepletion + sm.GetMaxValue() * dT;
988 val =
Math.RandomFloat(sm.GetMinValue(), sm.GetMaxValue());
989 m_StaminaDepletion = m_StaminaDepletion + val;
996 sm.SetStartTime(current_time + sm.GetStartTimeAdjustment()/dT);
997 sm.SetRunTimeTick(dT);
1000 valueProgress =
Math.Clamp((current_time - sm.GetStartTime())/sm.GetDurationAdjusted(), 0, 1 );
1001 val =
Math.Lerp(sm.GetMinValue(), sm.GetMaxValue(), valueProgress);
1002 m_StaminaDepletion = m_StaminaDepletion + val;
1008 if (!
Class.CastTo(smex,sm))
1010 ErrorEx(
"StaminaModifierExponential not found for modifier type: " + sm.GetType());
1014 if (!smex.IsInUse())
1016 smex.SetStartTime(current_time + smex.GetStartTimeAdjustment()/dT);
1017 smex.SetRunTimeTick(dT);
1018 smex.SetInUse(
true);
1020 valueProgress =
Math.Clamp((current_time - smex.GetStartTime())/smex.GetDurationAdjusted(), 0, 1 );
1022 if (
Math.AbsFloat(smex.GetBaseValue()) < 1)
1024 exp = 1 -
Math.Lerp(0, smex.GetExponent(), valueProgress);
1025 val =
Math.Pow(smex.GetBaseValue(),exp);
1029 exp =
Math.Lerp(
Math.Min(0, smex.GetExponent()),
Math.Max(0, smex.GetExponent()), valueProgress);
1030 val =
Math.Pow(smex.GetBaseValue(),exp) + smex.GetBaseValue() - 1;
1033 m_StaminaDepletion = m_StaminaDepletion + val;
1034 m_StaminaDepletion *= smex.GetMultiplier();
1040 SetCooldown(sm.GetCooldown(),modifier);
1043 m_StaminaDepletion = m_StaminaDepletion * m_StaminaDepletionMultiplier;
1046 #ifdef DIAG_DEVELOPER
1047 void SetStaminaDisabled(
bool value)
1049 m_StaminaDisabled = value;