Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
shockhandler.c
Go to the documentation of this file.
2{
3 protected const float UPDATE_THRESHOLD = 3; //NOTE : The lower, the more precise but the more synchronization
4 const float VALUE_CHECK_INTERVAL = 0.95; //in seconds
5 private const int INTENSITY_FACTOR = 1; //How intense the vignette effect will be, the higher the value, the stronger the effect
6 private const int VIGNETTE_INTENSITY_MAX = 1; //Max BASE intensity of the vignette effect (w/o. bobbing). 0..2, where 2 is full screen coverage
7 private const int VIGNETTE_INTENSITY_MAX_TOTAL = 2; //Max TOTAL intensity of the vignette effect (w. bobbing). 0..2, where 2 is full screen coverage
8 private const float SMOOTHING_MAX_INCR = 0.05; //max smoothing change INCREASE per update
9 private const float SMOOTHING_MAX_DECR = 0.01; //max smoothing change DECREASE per update
10 //bobbing constants
11 private const float PULSE_PERIOD = 0.5; //The time it takes for pulse to do a full cycle
12 private const float PULSE_AMPLITUDE = 0.05; //This is a multiplier, keep below 1 or expect the unexpected
13
14 protected float m_Shock;
15 protected float m_LastEffectIntensityValue; //for interpolation only
16 protected float m_ShockValueMax;
17 protected float m_CumulatedShock;
18 private float m_TimeSinceLastTick = VALUE_CHECK_INTERVAL + 1;
19 private float m_ShockMultiplier = 1;
20 private float m_PrevVignette; //Previous shock-adjecent value (some normalization required). Client sets it only on regular ShockHandler update!
21
22 //bobbing effect
23 private float m_PulseTimer;
24
25 //PPE
26 PPERequester_TunnelVisionEffects m_Requester;
27 protected ref Param1<float> m_Param;
28
30
32 {
33 m_Player = player;
34 m_Player.m_CurrentShock = m_Player.GetMaxHealth("", "Shock");
35 m_ShockValueMax = m_Player.GetMaxHealth("", "Shock");
36 m_PrevVignette = m_Player.m_CurrentShock / m_ShockValueMax; //Equivalent to divided by 100
37 m_Requester = PPERequester_TunnelVisionEffects.Cast(PPERequesterBank.GetRequester(PPERequester_TunnelVisionEffects));
38 m_Param = new Param1<float>(0);
39
40 //loegacy stuff
42 }
43
44 void Update(float deltaT)
45 {
46 m_TimeSinceLastTick += deltaT;
47 m_PulseTimer += deltaT;
48
49 //periodical update, just in case
51 {
52 if (GetGame().IsClient())
53 {
54 //ShockHitEffect(m_PrevVignette * m_ShockValueMax);
55 m_PrevVignette = m_Player.m_CurrentShock / m_ShockValueMax;
56 }
57
58 CheckValue(false);
60 }
61
62 if (GetGame().IsClient())
63 {
64 float valAdjusted = BaseEffectIntensityCalc();
65
66 if (valAdjusted <= 0)
67 {
68 if (m_Requester.IsRequesterRunning())
69 m_Requester.Stop();
70
71 return;
72 }
73
74 //Print("dbgShock | valAdjusted: " + valAdjusted);
75
76 //Add bobbing to create pulsing effect
77 valAdjusted = AddEffectBobbing(valAdjusted);
78
79 m_Param.param1 = valAdjusted;
80 m_Requester.Start(m_Param);
81 }
82 }
83
85 {
86 return m_Player.m_CurrentShock;
87 }
88
89 float GetShock()
90 {
91 return m_Shock;
92 }
93
94 void SetShock(float dealtShock)
95 {
96 m_Shock += dealtShock;
97 CheckValue(false);
98 }
99
100 //Inflict shock damage
101 private void DealShock()
102 {
103 if (GetGame().IsServer())
104 m_Player.GiveShock(-m_CumulatedShock);
105 }
106
107 //Passing a value of FALSE will only check the values, a value of TRUE will force a synchronization (don't use too often)
108 void CheckValue(bool forceUpdate)
109 {
110 m_CumulatedShock += m_Shock; // increment on both client and server
111
112 if (forceUpdate)
113 m_PrevVignette = NormalizeShockVal(m_Player.m_CurrentShock);
114
115 if (GetGame().IsServer())
116 {
117 if (m_CumulatedShock >= UPDATE_THRESHOLD || forceUpdate)
118 {
119 m_CumulatedShock *= m_ShockMultiplier;
120 DealShock();
122 m_Shock = 0;
123
124 Synchronize();
125 }
126
127 m_Player.m_CurrentShock = m_Player.GetHealth("", "Shock");
128 }
129 }
130
131 protected void Synchronize()
132 {
133 DayZPlayerSyncJunctures.SendShock(m_Player, m_Player.m_CurrentShock);
134 }
135
136 protected float BaseEffectIntensityCalc()
137 {
138 float effectIntensity = 1 - Easing.EaseInQuart(NormalizeShockVal(m_Player.m_CurrentShock));
139
140 //smoothing
141 if (effectIntensity != m_LastEffectIntensityValue)
142 effectIntensity = Math.Clamp(effectIntensity,m_LastEffectIntensityValue - SMOOTHING_MAX_DECR, m_LastEffectIntensityValue + SMOOTHING_MAX_INCR);
143
144 m_LastEffectIntensityValue = effectIntensity;
145
146 return effectIntensity;
147 }
148
150 protected float AddEffectBobbing(float baseVal)
151 {
152 float ret = baseVal;
153 float bobbingVal = 0.0;
154
155 if (m_Player.m_CurrentShock > m_ShockValueMax * 0.8)
156 bobbingVal = MiscGameplayFunctions.Bobbing(PULSE_PERIOD, PULSE_AMPLITUDE, m_PulseTimer);
157 ret += bobbingVal;
158 ret = Math.Clamp(ret,0,VIGNETTE_INTENSITY_MAX_TOTAL);
159
160 return ret;
161 }
162
163 float SetMultiplier(float mult)
164 {
165 m_ShockMultiplier = mult;
166 return m_ShockMultiplier;
167 }
168
169 private float NormalizeShockVal(float shock)
170 {
171 float base = m_ShockValueMax * INTENSITY_FACTOR;
172 float normShock = shock / base;
173 return normShock;
174 }
175
176 private float LerpVignette(float x, float y, float deltaT)
177 {
178 float output;
179 output = Math.Lerp(x, y, deltaT);
180 return output;
181 }
182
184 //Deprecated stuff below//
186 private const int LIGHT_SHOCK_HIT = 33;
187 private const int MID_SHOCK_HIT = 67;
188 private const int HEAVY_SHOCK_HIT = 100;
189 protected float m_ShockValueThreshold;
190 private float m_LerpRes;
191
193 private void ShockHitEffect(float compareBase)
194 {
195 float shockDifference = compareBase - m_Player.m_CurrentShock;
196 if (shockDifference >= UPDATE_THRESHOLD)
197 {
198 if (m_CumulatedShock < 25)
199 m_Player.SpawnShockEffect(MiscGameplayFunctions.Normalize(LIGHT_SHOCK_HIT, 100));
200 else if (m_CumulatedShock < 50)
201 m_Player.SpawnShockEffect(MiscGameplayFunctions.Normalize(MID_SHOCK_HIT, 100));
202 else
203 m_Player.SpawnShockEffect(MiscGameplayFunctions.Normalize(HEAVY_SHOCK_HIT, 100));
204 }
205 }
206};
Input value between 0 and 1, returns value adjusted by easing, no automatic clamping of input(do your...
Definition easing.c:3
Definition enmath.c:7
float m_ShockValueMax
void ShockHandler(PlayerBase player)
float SetMultiplier(float mult)
float GetCurrentShock()
void Update(float deltaT)
ref Param1< float > m_Param
void SetShock(float dealtShock)
float m_CumulatedShock
float m_LastEffectIntensityValue
float BaseEffectIntensityCalc()
PlayerBase m_Player
float AddEffectBobbing(float baseVal)
adds bobbing, also clamps to valid range
const float UPDATE_THRESHOLD
Definition shockhandler.c:3
float m_ShockValueThreshold
Deprecated.
float GetShock()
void Synchronize()
const float VALUE_CHECK_INTERVAL
Definition shockhandler.c:4
proto native CGame GetGame()
Icon x
Icon y
float m_TimeSinceLastTick
PPERUndergroundAcco m_Requester