DayZ 1.24
Loading...
Searching...
No Matches
ShockHandler.c
Go to the documentation of this file.
2{
3 protected float m_Shock;
4 protected float m_ShockValueMax;
5 protected float m_ShockValueThreshold;
7
8 protected const float UPDATE_THRESHOLD = 3; //NOTE : The lower, the more precise but the more synchronization
9 const float VALUE_CHECK_INTERVAL = 0.95; //in seconds
10 protected float m_CumulatedShock;
12 private float m_ShockMultiplier = 1;
13 private float m_PrevVignette; //Previous vignette shock value
14 private float m_LerpRes; //Lerp result
15
16 private const int LIGHT_SHOCK_HIT = 33;
17 private const int MID_SHOCK_HIT = 67;
18 private const int HEAVY_SHOCK_HIT = 100;
19 private const int INTENSITY_FACTOR = 1; //How intense the vignette effect will be, the higher the value, the stronger the effect
20
21 //Pulsing effect
22 private const float PULSE_PERIOD = 0.5; //The time it takes for pulse to do a full cycle
23 private const float PULSE_AMPLITUDE = 0.05; //This is a multiplier, keep below 1 or expect the unexpected
24 private float m_PulseTimer;
25
27
29 {
31 m_Player.m_CurrentShock = m_Player.GetMaxHealth("", "Shock");
32 m_PrevVignette = m_Player.m_CurrentShock * 0.01; //Equivalent to divided by 100
33 m_ShockValueMax = m_Player.GetMaxHealth("", "Shock");
35 m_Param = new Param1<float>(0);
36 }
37
38 void Update(float deltaT)
39 {
41
43
44 if (GetGame().IsClient())
45 {
46 //Deactivate tunnel vignette when player falls unconscious
47 if (m_Player.IsUnconscious())
48 {
50 return;
51 }
52
53 //Deactivate if above visible threshold (also stops "zero bobbing" being sent all the time
54 if (m_Player.m_CurrentShock >= m_ShockValueThreshold)
55 {
57 return;
58 }
59
60 //Add bobbing to create pulsing effect
61 float val = 0.0;
62 if (m_Player.m_CurrentShock > m_ShockValueMax * 0.8)
64 float val_adjusted;
65
66 if (m_Player.m_CurrentShock != (m_PrevVignette * 100))
67 {
68 //Interpolate between previous level and currently synchronized shock level
70
72 }
73 else
75
76 m_Param.param1 = val_adjusted;
78 }
79
81 {
82 //Play the shock hit event (multiply prevVignette by 100 to "Un-Normalize" value)
83 if (GetGame().IsClient())
84 {
86 m_PrevVignette = m_Player.m_CurrentShock * 0.01;
87 }
88
89 CheckValue(false);
91 }
92 }
93
95 {
96 return m_Player.m_CurrentShock;
97 }
98
99 float GetShock()
100 {
101 return m_Shock;
102 }
103
105 {
107 CheckValue(false);
108 }
109
110 //Inflict shock damage
111 private void DealShock()
112 {
113 if (GetGame().IsServer())
114 m_Player.GiveShock(-m_CumulatedShock);
115 }
116
117 //Passing a value of FALSE will only check the values, a value of TRUE will force a synchronization (don't use too often)
119 {
120 m_CumulatedShock += m_Shock; // increment on both client and server
121
122 if (forceUpdate)
123 m_PrevVignette = NormalizeShockVal(m_Player.m_CurrentShock);
124
125 if (GetGame().IsServer())
126 {
127 m_Player.m_CurrentShock = m_Player.GetHealth("", "Shock");
128
129 /*
130 if (m_Player.m_CurrentShock <= 0)
131 m_Player.SetHealthMax("", "Shock");
132 */
134 {
136 DealShock();
138 m_Shock = 0;
139
140 Synchronize();
141 }
142 }
143 }
144
145 protected void Synchronize()
146 {
148 }
149
150 float SetMultiplier(float mult)
151 {
153 return m_ShockMultiplier;
154 }
155
156 private float NormalizeShockVal(float shock)
157 {
158 float base = m_Player.GetMaxHealth("", "Shock") * INTENSITY_FACTOR;
159 float normShock = shock / base;
160 return normShock;
161 }
162
163 private float LerpVignette(float x, float y, float deltaT)
164 {
165 float output;
166 output = Math.Lerp(x, y, deltaT);
167 return output;
168 }
169
170 //ONLY CLIENT SIDE
171 private void ShockHitEffect(float compareBase)
172 {
173 float shockDifference = compareBase - m_Player.m_CurrentShock;
174 //Print(shockDifference);
176 {
177 if (m_CumulatedShock < 25)
178 m_Player.SpawnShockEffect(MiscGameplayFunctions.Normalize(LIGHT_SHOCK_HIT, 100));
179 else if (m_CumulatedShock < 50)
180 m_Player.SpawnShockEffect(MiscGameplayFunctions.Normalize(MID_SHOCK_HIT, 100));
181 else
182 m_Player.SpawnShockEffect(MiscGameplayFunctions.Normalize(HEAVY_SHOCK_HIT, 100));
183 }
184 }
185};
Icon x
Icon y
static void SendShock(DayZPlayer pPlayer, float shockValue)
Input value between 0 and 1, returns value adjusted by easing, no automatic clamping of input(do your...
Definition Easing.c:3
static float EaseInQuart(float t)
Definition Easing.c:56
Definition EnMath.c:7
float m_ShockValueMax
Definition ShockHandler.c:4
const int HEAVY_SHOCK_HIT
float m_PulseTimer
const float PULSE_AMPLITUDE
void CheckValue(bool forceUpdate)
void ShockHitEffect(float compareBase)
void ShockHandler(PlayerBase player)
float m_ShockMultiplier
const int INTENSITY_FACTOR
float SetMultiplier(float mult)
float GetCurrentShock()
void Update(float deltaT)
ref Param1< float > m_Param
const int MID_SHOCK_HIT
void SetShock(float dealtShock)
float m_CumulatedShock
const float PULSE_PERIOD
float LerpVignette(float x, float y, float deltaT)
PlayerBase m_Player
Definition ShockHandler.c:6
float m_PrevVignette
float m_TimeSinceLastTick
const int LIGHT_SHOCK_HIT
const float UPDATE_THRESHOLD
Definition ShockHandler.c:8
float NormalizeShockVal(float shock)
float m_ShockValueThreshold
Definition ShockHandler.c:5
float GetShock()
void Synchronize()
const float VALUE_CHECK_INTERVAL
Definition ShockHandler.c:9
proto native CGame GetGame()
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.