Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
staminasoundhandler.c
Go to the documentation of this file.
1 const float TICK_INTERVAL = 1;
2 
3 const float STAMINA_SOUND_TR1 = 0.55;
4 const float STAMINA_SOUND_TR2 = 0.25;
5 
7 {
11 }
12 
13 enum eStaminaTendency
14 {
15  UP,
16  DOWN,
17 }
18 
19 enum eStaminaState
20 {
21  ZONE0_UP = 1,
22  ZONE0_DOWN,
23  ZONE1_UP,
24  ZONE1_DOWN,
25  ZONE2_UP,
26  ZONE2_DOWN,
27  //count bellow, add above
28  COUNT
29 }
30 
31 
32 class SoundHandlerBase
33 {
36 
37  void Update();
38 
40  {
41  return m_Id;
42  }
43 
45  {
46  m_Player = player;
47  Init();
48  }
49 
50  void Init();
51 }
52 
54 {
55 
56  override void Init()
57  {
58  m_Id = eSoundHandlers.STAMINA;
59  }
60 
61  eStaminaState GetStaminaState(eStaminaTendency tendency, eStaminaZones zone)
62  {
63  eStaminaState stamina_state;
64 
65  zone = Math.Clamp(zone, eStaminaZones.ZONE0, eStaminaZones.ZONE2);
66 
67  if(zone == eStaminaZones.ZONE1 && tendency == eStaminaTendency.DOWN)
68  {
69  stamina_state = eStaminaState.ZONE1_DOWN;
70  }
71 
72  if(zone == eStaminaZones.ZONE1 && tendency == eStaminaTendency.UP)
73  {
74  stamina_state = eStaminaState.ZONE1_UP;
75  }
76 
77  if(zone == eStaminaZones.ZONE2 && tendency == eStaminaTendency.DOWN)
78  {
79  stamina_state = eStaminaState.ZONE2_DOWN;
80  }
81 
82  if(zone == eStaminaZones.ZONE2 && tendency == eStaminaTendency.UP)
83  {
84  stamina_state = eStaminaState.ZONE2_UP;
85  }
86 
87  if(zone == eStaminaZones.ZONE0 && tendency == eStaminaTendency.UP)
88  {
89  stamina_state = eStaminaState.ZONE0_UP;
90  }
91 
92  if(zone == eStaminaZones.ZONE0 && tendency == eStaminaTendency.DOWN)
93  {
94  stamina_state = eStaminaState.ZONE0_DOWN;
95  }
96 
97  return stamina_state;
98  }
99 }
100 
101 
102 //---------------------------
103 // Server
104 //---------------------------
105 class StaminaSoundHandlerServer extends StaminaSoundHandlerBase
106 {
107  float m_Stamina;
111 
112  void SetStaminaZoneOffset(int zone_offset)
113  {
114  m_StaminaZoneOffset = zone_offset;
115  }
116 
117  // ! Called from command handler
118  override void Update()
119  {
120  m_Stamina = m_Player.GetStaminaHandler().GetStamina();
121  float stamina_delta = m_StaminaLastValue - m_Stamina;
122  eStaminaTendency stamina_tendency;
123  eStaminaZones stamina_zone;
124 
125  //if( stamina_delta == 0 ) return;
126 
127  if( stamina_delta > 0 )
128  {
129  stamina_tendency = eStaminaTendency.DOWN;
130  }
131  if( stamina_delta <= 0 )
132  {
133  stamina_tendency = eStaminaTendency.UP;
134  }
135 
137 
138  stamina_zone = GetZone(m_Stamina);
139  m_Player.SetStaminaState( GetStaminaState(stamina_tendency, stamina_zone + m_StaminaZoneOffset) );
140 
141  //EPlayerSoundEventID sound_event_id = GetPlayerSoundEventID();
142  /*
143  //PrintString("stamina delta " +stamina_delta.ToString());
144  //PrintString("stamina zone " +m_StaminaZone.ToString());
145  //PrintString("stamina tendency " +m_StaminaTendency.ToString());
146  */
147  //PrintString(" sound event id " +sound_event_id.ToString());
148 
149 
150  //if( sound_event_id !=0 ) m_Player.SendSoundEvent(sound_event_id);
151  }
152 
153  eStaminaZones GetZone(float stamina)
154  {
155  float stamina_normalized = Math.InverseLerp(0, m_Player.GetStaminaHandler().GetStaminaCap(), stamina);
156  stamina_normalized = Math.Clamp(stamina_normalized,0,1);
157  //PrintString(" stamina_normalized " +stamina_normalized.ToString());
158  eStaminaZones stamina_zone = eStaminaZones.ZONE0;
159 
160  if( stamina_normalized < STAMINA_SOUND_TR1)
161  {
162  stamina_zone = eStaminaZones.ZONE1;
163  }
164 
165  if( stamina_normalized < STAMINA_SOUND_TR2)
166  {
167  stamina_zone = eStaminaZones.ZONE2;
168  }
169 
170  return stamina_zone;
171  }
172 }
173 
174 
175 //---------------------------
176 // Client
177 //---------------------------
178 class StaminaSoundHandlerClient extends StaminaSoundHandlerBase
179 {
180  float m_PostponeTime = -1;
181 
182  float m_LastTick;
184  bool m_StaminaUpEndPlayed = true;
187 
188 
189  void PostponeStamina(float time)
190  {
191  m_PostponeTime = GetGame().GetTime() + time;
192  }
193 
194 
195  override void Update()
196  {
197  if( GetGame().GetTime() < m_PostponeTime || m_Player.GetPlayerSoundEventHandler().m_CurrentState )
198  {
199  return;
200  }
201  //Print(Math.RandomFloat01());
202  eStaminaState stamina_state = m_Player.GetStaminaState();
203  switch(stamina_state)
204  {
205  case eStaminaState.ZONE1_DOWN:
206  if(m_Player.PlaySoundEvent(EPlayerSoundEventID.STAMINA_DOWN_LIGHT))
207  {
208  m_StaminaUpEndPlayed = false;
209  }
210  break;
211 
212  case eStaminaState.ZONE1_UP:
213  if(m_Player.PlaySoundEvent(EPlayerSoundEventID.STAMINA_UP_LIGHT))
214  {
215  m_StaminaUpEndPlayed = false;
216  }
217  break;
218 
219  case eStaminaState.ZONE2_DOWN:
220  if(m_Player.PlaySoundEvent(EPlayerSoundEventID.STAMINA_DOWN_HEAVY))
221  {
222  m_StaminaUpEndPlayed = false;
223  }
224  break;
225 
226  case eStaminaState.ZONE2_UP:
227  if(m_Player.PlaySoundEvent(EPlayerSoundEventID.STAMINA_UP_HEAVY))
228  {
229  m_StaminaUpEndPlayed = false;
230  }
231  break;
232 
233  case eStaminaState.ZONE0_UP:
234  if(!m_StaminaUpEndPlayed && m_Player.PlaySoundEvent(EPlayerSoundEventID.STAMINA_UP_END))
235  {
236  m_StaminaUpEndPlayed = true;
237  }
238  else
239  {
240  m_Player.PlaySoundEvent(EPlayerSoundEventID.STAMINA_NORMAL_DUMMY);
241  }
242  break;
243 
244  case eStaminaState.ZONE0_DOWN:
245  m_Player.PlaySoundEvent(EPlayerSoundEventID.STAMINA_NORMAL_DUMMY);
246  break;
247  }
248  }
249 }
GetGame
proto native CGame GetGame()
m_StaminaLastValue
float m_StaminaLastValue
Definition: staminasoundhandler.c:109
m_StaminaHandler
StaminaHandler m_StaminaHandler
Definition: staminasoundhandler.c:108
ZONE2_UP
enum eStaminaZones ZONE2_UP
SetStaminaZoneOffset
void SetStaminaZoneOffset(int zone_offset)
Definition: staminasoundhandler.c:112
ZONE1_UP
enum eStaminaZones ZONE1_UP
GetZone
eStaminaZones GetZone(float stamina)
Definition: staminasoundhandler.c:153
ZONE0_UP
enum eStaminaZones ZONE0_UP
ZONE2
@ ZONE2
Definition: staminasoundhandler.c:10
m_LastTick
int m_LastTick
Definition: displaystatus.c:30
StaminaHandler
Definition: staminahandler.c:260
ZONE2_DOWN
enum eStaminaZones ZONE2_DOWN
m_ClientCharacterDistanceCheck
ref Timer m_ClientCharacterDistanceCheck
Definition: playersoundmanager.c:87
GetID
eSoundHandlers GetID()
Definition: staminasoundhandler.c:39
m_UpdateTimerRunning
bool m_UpdateTimerRunning
Definition: playersoundmanager.c:88
eStaminaZones
eStaminaZones
Definition: staminasoundhandler.c:6
COUNT
@ COUNT
Definition: egamestateicons.c:7
ZONE0_DOWN
enum eStaminaZones ZONE0_DOWN
PlayerBase
Definition: playerbaseclient.c:1
ZONE1_DOWN
enum eStaminaZones ZONE1_DOWN
m_Player
PlayerBase m_Player
Definition: staminasoundhandler.c:35
m_Id
enum eStaminaZones m_Id
StaminaSoundHandlerBase
Definition: staminasoundhandler.c:178
STAMINA_SOUND_TR1
const float STAMINA_SOUND_TR1
Definition: staminasoundhandler.c:3
UP
enum eStaminaZones UP
TICK_INTERVAL
const float TICK_INTERVAL
Definition: staminasoundhandler.c:1
Update
void Update()
Definition: staminasoundhandler.c:118
ZONE0
@ ZONE0
Definition: staminasoundhandler.c:8
eSoundHandlers
eSoundHandlers
Definition: playersoundmanager.c:4
m_Stamina
class StaminaSoundHandlerBase extends SoundHandlerBase m_Stamina
Init
void Init()
Launched from 'DayZGame.DeferredInit' to make earlier access, use, and updates impossible (downside o...
Definition: uihintpanel.c:46
STAMINA_SOUND_TR2
const float STAMINA_SOUND_TR2
Definition: staminasoundhandler.c:4
SoundHandlerBase
Definition: hungersoundhandler.c:1
Timer
Definition: dayzplayerimplement.c:62
ZONE1
@ ZONE1
Definition: staminasoundhandler.c:9
GetTime
float GetTime()
Definition: notificationsystem.c:35
SoundHandlerBase
void SoundHandlerBase(PlayerBase player)
Definition: staminasoundhandler.c:44
Math
Definition: enmath.c:6
EPlayerSoundEventID
EPlayerSoundEventID
Definition: playersoundeventhandler.c:1
m_StaminaZoneOffset
int m_StaminaZoneOffset
Definition: staminasoundhandler.c:110
DOWN
enum eStaminaZones DOWN
m_ClientCharacterTick
class PlayerSoundManagerServer extends PlayerSoundManagerBase m_ClientCharacterTick