Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
injuryhandler.c
Go to the documentation of this file.
2 {
3  const float WORN = 0.5;
4  const float DAMAGED = 0.3;
5  const float BADLY_DAMAGED = 0.2;
6  const float RUINED = 0.1;
7 };
8 
10 {
11  const float LVL0 = 0;
12  const float LVL1 = 0.3;
13  const float LVL2 = 0.6;
14  const float LVL3 = 0.8;
15  const float LVL4 = 1;
16 };
17 
19 {
25 }
26 
27 enum eInjuryOverrides
28 {
30  NONE = 0,
31  MORPHINE = 1,
34  BROKEN_LEGS = 8, //New
35  BROKEN_LEGS_SPLINT = 16, //New
36  PRONE_ANIM_OVERRIDE = 32, //Prevent non pristine animation when prone
37 }
38 
40 {
41 
42  const float VALUE_CHECK_INTERVAL = 5;
43  const float SENSITIVTY_PERCENTAGE = 1; //how much the value needs to change up/down from previous update to trigger a new update(in percent)
44 
46 
48  float m_LastUpdate;
51 
52 
53  private PlayerBase m_Player;
54  private bool m_AnimationChange = false;
55  private bool m_InjuryAnimEnabled = false;
56  private float m_InjuryAnimDamageValue = 0;
58 
60  {
61  m_Player = player;
62  m_HealthMaxValue = m_Player.GetMaxHealth("", "Health");
63  }
64 
66  {
67  return m_InjuryAnimEnabled;
68  }
69 
71  {
73  }
74 
76  {
77  return m_ChangedStateInvoker;
78  }
79 
80  void Update(float deltaT)
81  {
82  if ( m_AnimationChange )
83  {
84  m_Player.GetCommandModifier_Additives().SetInjured(m_InjuryAnimDamageValue, m_InjuryAnimEnabled);
85  m_AnimationChange = false;
86  }
87 
88  if ( GetGame().IsClient() )
89  return;
90 
91  m_TimeSinceLastTick += deltaT;
92 
94  {
95  CheckValue();
97  }
98  }
99 
101  {
102  eInjuryHandlerLevels override_level = unchanged_level;
103 
104  //Whatever the case, prone will always use PRISTINE anim level as alternative anim level(s) are not interesting gameplaywise
105  if ( m_ForceInjuryAnimMask & eInjuryOverrides.PRONE_ANIM_OVERRIDE && override_level > eInjuryHandlerLevels.PRISTINE )
106  {
107  override_level = eInjuryHandlerLevels.PRISTINE;
108  return override_level;
109  }
110 
111  if ( m_ForceInjuryAnimMask & eInjuryOverrides.MORPHINE && override_level > eInjuryHandlerLevels.PRISTINE )
112  {
113  override_level = eInjuryHandlerLevels.PRISTINE;
114  }
115 
116  if ( m_ForceInjuryAnimMask & eInjuryOverrides.PAIN_KILLERS_LVL1 && override_level > eInjuryHandlerLevels.WORN )
117  {
118  override_level = eInjuryHandlerLevels.WORN;
119  }
120 
121  if ( m_ForceInjuryAnimMask & eInjuryOverrides.PAIN_KILLERS_LVL0 && override_level > eInjuryHandlerLevels.DAMAGED )
122  {
123  override_level = eInjuryHandlerLevels.DAMAGED;
124  }
125 
126  if ( m_ForceInjuryAnimMask && override_level > eInjuryHandlerLevels.DAMAGED )
127  {
128  override_level = eInjuryHandlerLevels.RUINED;
129  }
130 
131  //Broken leg overrides
132  if ( m_ForceInjuryAnimMask & eInjuryOverrides.BROKEN_LEGS_SPLINT && override_level < eInjuryHandlerLevels.DAMAGED )
133  {
134  override_level = eInjuryHandlerLevels.DAMAGED;
135  }
136 
137  if ( m_ForceInjuryAnimMask & eInjuryOverrides.BROKEN_LEGS && override_level < eInjuryHandlerLevels.RUINED )
138  {
139  //Average leg health used to determine which animation to use
140  float avgLegHealth = m_Player.GetHealth("RightLeg","") + m_Player.GetHealth("LeftLeg","") + m_Player.GetHealth("RightFoot","") + m_Player.GetHealth("LeftFoot","");
141  avgLegHealth *= 0.25; //divide by 4 to make the average leg health;
142  if (avgLegHealth <= PlayerConstants.BROKEN_LEGS_LOW_HEALTH_THRESHOLD)
143  override_level = eInjuryHandlerLevels.RUINED;
144  else if (avgLegHealth >= PlayerConstants.BROKEN_LEGS_HIGH_HEALTH_THRESHOLD)
145  override_level = eInjuryHandlerLevels.WORN;
146  else
147  override_level = eInjuryHandlerLevels.DAMAGED;
148  }
149 
150  return override_level;
151 
152  }
153 
154  void CheckValue(bool forceUpdate = false)
155  {
156  float health_current_normalized = m_Player.GetHealth("","Health") / m_HealthMaxValue;
157  eInjuryHandlerLevels injury_level = GetInjuryLevel(health_current_normalized);
158 
159  if ( m_ForceInjuryAnimMask )
160  {
161  injury_level = GetOverrideLevel(injury_level);
162  }
163 
164  if ( m_LastHealthUpdate != injury_level || forceUpdate )
165  {
166  SendValue(injury_level);
167  m_ChangedStateInvoker.Invoke(injury_level);
168  m_LastHealthUpdate = injury_level;
169  Synchronize(injury_level);
170  }
171  }
172 
174  {
175  m_Player.m_HealthLevel = level;
176  //Print("m_Player.m_HealthLevel:" + m_Player.m_HealthLevel);
177  m_Player.SetSynchDirty();
178  }
179 
181  {
182  DayZPlayerSyncJunctures.SendInjury(m_Player, true, level);
183  }
184 
186  {
187  m_AnimationChange = true;
188  m_InjuryAnimEnabled = enable;
190  }
191 
193  {
194  if ( health < InjuryHandlerThresholds.RUINED )
195  {
196  return eInjuryHandlerLevels.RUINED;
197  }
198 
199  if ( health < InjuryHandlerThresholds.BADLY_DAMAGED )
200  {
201  return eInjuryHandlerLevels.BADLY_DAMAGED;
202  }
203 
204  if ( health < InjuryHandlerThresholds.DAMAGED )
205  {
206  return eInjuryHandlerLevels.DAMAGED;
207  }
208 
209  if ( health < InjuryHandlerThresholds.WORN )
210  {
211  return eInjuryHandlerLevels.WORN;
212  }
213 
214  return eInjuryHandlerLevels.PRISTINE;
215  }
216 
217 
219  {
220  switch ( level )
221  {
222  case eInjuryHandlerLevels.RUINED:
223  {
224  return InjuryAnimValues.LVL4;
225  }
226  case eInjuryHandlerLevels.BADLY_DAMAGED:
227  {
228  return InjuryAnimValues.LVL3;
229  }
230  case eInjuryHandlerLevels.DAMAGED:
231  {
232  return InjuryAnimValues.LVL2;
233  }
234  case eInjuryHandlerLevels.WORN:
235  {
236  return InjuryAnimValues.LVL1;
237  }
238  case eInjuryHandlerLevels.PRISTINE:
239  {
240  return InjuryAnimValues.LVL0;
241  }
242  default:
243  Error("Undefined Injury level");
244  }
245  return 0;
246  }
247 }
GetGame
proto native CGame GetGame()
Update
void Update(float deltaT)
Definition: injuryhandler.c:80
BROKEN_LEGS_SPLINT
enum eInjuryHandlerLevels BROKEN_LEGS_SPLINT
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
PAIN_KILLERS_LVL1
enum eInjuryHandlerLevels PAIN_KILLERS_LVL1
m_TimeSinceLastTick
float m_TimeSinceLastTick
Definition: injuryhandler.c:47
m_InjuryAnimEnabled
private bool m_InjuryAnimEnabled
Definition: injuryhandler.c:55
Synchronize
void Synchronize(eInjuryHandlerLevels level)
Definition: injuryhandler.c:173
GetInjuryValue
float GetInjuryValue(eInjuryHandlerLevels level)
Definition: injuryhandler.c:218
m_AnimationChange
private bool m_AnimationChange
owner
Definition: injuryhandler.c:54
VALUE_CHECK_INTERVAL
enum eInjuryHandlerLevels VALUE_CHECK_INTERVAL
m_HealthMaxValue
float m_HealthMaxValue
Definition: injuryhandler.c:50
m_ChangedStateInvoker
ref ScriptInvoker m_ChangedStateInvoker
Definition: injuryhandler.c:45
PRONE_ANIM_OVERRIDE
enum eInjuryHandlerLevels PRONE_ANIM_OVERRIDE
NONE
enum eInjuryHandlerLevels NONE
MUST BE POW2.
PAIN_KILLERS_LVL0
enum eInjuryHandlerLevels PAIN_KILLERS_LVL0
SendValue
void SendValue(eInjuryHandlerLevels level)
Definition: injuryhandler.c:180
PlayerBase
Definition: playerbaseclient.c:1
PlayerConstants
Definition: playerconstants.c:1
SENSITIVTY_PERCENTAGE
const float SENSITIVTY_PERCENTAGE
Definition: injuryhandler.c:43
m_Player
private PlayerBase m_Player
Definition: injuryhandler.c:53
SetInjuryCommandParams
void SetInjuryCommandParams(bool enable, eInjuryHandlerLevels level)
Definition: injuryhandler.c:185
DAMAGED
@ DAMAGED
Definition: injuryhandler.c:22
DayZPlayerSyncJunctures
Definition: dayzplayersyncjunctures.c:4
InjuryHandlerThresholds
Definition: injuryhandler.c:1
InjuryAnimationHandler
void InjuryAnimationHandler(PlayerBase player)
Definition: injuryhandler.c:59
m_ForceInjuryAnimMask
int m_ForceInjuryAnimMask
Definition: injuryhandler.c:57
m_LastHealthUpdate
eInjuryHandlerLevels m_LastHealthUpdate
Definition: injuryhandler.c:49
eInjuryHandlerLevels
eInjuryHandlerLevels
Definition: injuryhandler.c:18
m_InjuryAnimDamageValue
private float m_InjuryAnimDamageValue
Definition: injuryhandler.c:56
PRISTINE
@ PRISTINE
Definition: injuryhandler.c:20
WORN
@ WORN
Definition: injuryhandler.c:21
CheckValue
void CheckValue(bool forceUpdate=false)
Definition: injuryhandler.c:154
MORPHINE
enum eInjuryHandlerLevels MORPHINE
GetInjuryAnimValue
float GetInjuryAnimValue()
Definition: injuryhandler.c:70
GetInvoker
ScriptInvoker GetInvoker()
Definition: injuryhandler.c:75
GetOverrideLevel
eInjuryHandlerLevels GetOverrideLevel(eInjuryHandlerLevels unchanged_level)
Definition: injuryhandler.c:100
BADLY_DAMAGED
@ BADLY_DAMAGED
Definition: injuryhandler.c:23
IsInjuryAnimEnabled
bool IsInjuryAnimEnabled()
Definition: injuryhandler.c:65
m_LastUpdate
float m_LastUpdate
Definition: injuryhandler.c:48
GetInjuryLevel
eInjuryHandlerLevels GetInjuryLevel(float health)
Definition: injuryhandler.c:192
BROKEN_LEGS
enum eInjuryHandlerLevels BROKEN_LEGS
InjuryAnimValues
Definition: injuryhandler.c:9
ScriptInvoker
ScriptInvoker Class provide list of callbacks usage:
Definition: tools.c:115
RUINED
@ RUINED
Definition: injuryhandler.c:24