Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
mask.c
Go to the documentation of this file.
2 {
3  const float IN_AREA_CONSUME_FILTER_QUANTITY_PER_SEC = 0.3;
4  const float OUT_AREA_CONSUME_FILTER_QUANTITY_PER_SEC = 0.03;
5 
6  const float STAMINA_RECOVERY_MODIFIER = 0.5;
7  const float STAMINA_DEPLETION_MODIFIER = 1.25;
8 
9  const float LOW_FILTER_SOUND_EVENT_MIN = 3;
10  const float LOW_FILTER_SOUND_EVENT_MAX = 9;
11 
12  const float LOW_FILTER_SOUND_THRESHOLD = 0.2;//[0..1] , what's the filter quantity between 0 and 1 at which low filter sounds begin playing ?
13 
14  float m_SoundTimeAccu1;
15  float m_NextSoundEventTime;
16 
17  override void Init()
18  {
19  m_TrackActivatedTime = false;
20  m_ID = eModifiers.MDF_MASK;
23  }
24 
25  override bool ActivateCondition(PlayerBase player)
26  {
27  return MaskBase.Cast(player.GetInventory().FindAttachment(InventorySlots.MASK)) != null;
28  }
29 
30  override bool DeactivateCondition(PlayerBase player)
31  {
32  return !ActivateCondition( player);
33  }
34 
35  override void OnTick(PlayerBase player, float deltaT)
36  {
37  MaskBase mask = MaskBase.Cast(player.GetInventory().FindAttachment(InventorySlots.MASK));
38 
39  float consume_quantity = OUT_AREA_CONSUME_FILTER_QUANTITY_PER_SEC;
40 
41  bool inside_area = m_Manager.IsModifierActive(eModifiers.MDF_AREAEXPOSURE);
42 
43  if(inside_area)
44  {
45  consume_quantity = IN_AREA_CONSUME_FILTER_QUANTITY_PER_SEC;
46  }
47 
48  if ( mask && !mask.IsDamageDestroyed())
49  {
50  bool consuming_filter = mask.ConsumeQuantity(consume_quantity * deltaT, player);
51  StaminaSoundHandlerServer.Cast(player.GetPlayerSoundManagerServer().GetHandler(eSoundHandlers.STAMINA)).SetStaminaZoneOffset(1);
52 
53  if (mask.HasValidFilter())
54  {
55  player.GetStaminaHandler().ActivateRecoveryModifier(EStaminaMultiplierTypes.MASK);
56  player.GetStaminaHandler().ActivateDepletionModifier(EStaminaMultiplierTypes.MASK);
57 
58  }
59  else
60  {
61  player.GetStaminaHandler().DeactivateRecoveryModifier(EStaminaMultiplierTypes.MASK);
62  player.GetStaminaHandler().DeactivateDepletionModifier(EStaminaMultiplierTypes.MASK);
63  }
64  HandleSounds(player, deltaT, mask);
65  }
66  }
67 
68  void HandleSounds(PlayerBase player, float deltaT, MaskBase mask)
69  {
70  float filter_quantity_01 = mask.GetFilterQuantity01();
71 
72  if(mask.CanHaveExternalFilter() && !mask.IsExternalFilterAttached())
73  return;
74 
75  if(filter_quantity_01 > LOW_FILTER_SOUND_THRESHOLD)
76  return;
77 
78  float low_quantity_norm = Math.InverseLerp(0, LOW_FILTER_SOUND_THRESHOLD, filter_quantity_01);//should give us 0..1 based on normalized quantity between 0 and LOW_FILTER_SOUND_THRESHOLD
79 
80  m_SoundTimeAccu1 += deltaT;
81  if( m_SoundTimeAccu1 >= m_NextSoundEventTime)
82  {
83  m_NextSoundEventTime = Math.Lerp(LOW_FILTER_SOUND_EVENT_MIN, LOW_FILTER_SOUND_EVENT_MAX,low_quantity_norm);
84 
85  EPlayerSoundEventID event_type = EPlayerSoundEventID.STAMINA_LOW_FILTER_UPPER;
86  //under 50% of low filter quantity (not overall filter quantity!!)
87  if (low_quantity_norm < 0.5)
88  {
89  event_type = EPlayerSoundEventID.STAMINA_LOW_FILTER_MID;
90  }
91  if (low_quantity_norm < 0.25)
92  {
93  event_type = EPlayerSoundEventID.STAMINA_LOW_FILTER_LOWER;
94  }
95  player.RequestSoundEventEx(event_type, false, EPlayerSoundEventParam.HIGHEST_PRIORITY);
96  m_SoundTimeAccu1 = 0;
97  }
98  }
99 
100  override void OnReconnect(PlayerBase player)
101  {
102  OnActivate(player);
103  }
104 
105  override void OnActivate(PlayerBase player)
106  {
107  //m_NextSoundEventTime = Math.RandomFloat(LOW_FILTER_SOUND_EVENT_MIN, LOW_FILTER_SOUND_EVENT_MAX);
108  }
109 
110  override void OnDeactivate(PlayerBase player)
111  {
112  StaminaSoundHandlerServer.Cast(player.GetPlayerSoundManagerServer().GetHandler(eSoundHandlers.STAMINA)).SetStaminaZoneOffset(0);
113  player.GetStaminaHandler().DeactivateRecoveryModifier(EStaminaMultiplierTypes.MASK);
114  player.GetStaminaHandler().DeactivateDepletionModifier(EStaminaMultiplierTypes.MASK);
115  }
116 
117 
118 
119 };
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
MaskMdfr
Definition: mask.c:1
m_Manager
ModifiersManager m_Manager
Definition: modifierbase.c:12
m_TickIntervalActive
float m_TickIntervalActive
Definition: modifierbase.c:19
m_TrackActivatedTime
bool m_TrackActivatedTime
Definition: modifierbase.c:15
EStaminaMultiplierTypes
EStaminaMultiplierTypes
Definition: staminahandler.c:1
PlayerBase
Definition: playerbaseclient.c:1
MaskBase
Definition: airbornemask.c:1
DEFAULT_TICK_TIME_ACTIVE_SHORT
const int DEFAULT_TICK_TIME_ACTIVE_SHORT
Definition: modifiersmanager.c:32
m_TickIntervalInactive
float m_TickIntervalInactive
Definition: modifierbase.c:18
eModifiers
eModifiers
Definition: emodifiers.c:1
ModifierBase
Definition: breathvapourmdfr.c:3
eSoundHandlers
eSoundHandlers
Definition: playersoundmanager.c:4
Math
Definition: enmath.c:6
EPlayerSoundEventID
EPlayerSoundEventID
Definition: playersoundeventhandler.c:1
m_ID
protected int m_ID
ID of effect, given by SEffectManager when registered (automatically done when playing through it)
Definition: effect.c:49
DEFAULT_TICK_TIME_INACTIVE
const int DEFAULT_TICK_TIME_INACTIVE
Definition: modifiersmanager.c:33