DayZ 1.28
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
ShockHandler.c
См. документацию.
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;
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 {
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 {
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)
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;
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};
Icon x
Icon y
static void SendShock(DayZPlayer pPlayer, float shockValue)
Определения DayZPlayerSyncJunctures.c:413
static float EaseInQuart(float t)
Определения Easing.c:56
Input value between 0 and 1, returns value adjusted by easing, no automatic clamping of input(do your...
Определения Easing.c:3
Определения EnMath.c:7
Определения PlayerBaseClient.c:2
float m_ShockValueMax
Определения ShockHandler.c:16
const float SMOOTHING_MAX_INCR
Определения ShockHandler.c:8
const int HEAVY_SHOCK_HIT
Deprecated.
Определения ShockHandler.c:188
float m_PulseTimer
Определения ShockHandler.c:23
const float PULSE_AMPLITUDE
Определения ShockHandler.c:12
void CheckValue(bool forceUpdate)
Определения ShockHandler.c:108
void ShockHitEffect(float compareBase)
Deprecated.
Определения ShockHandler.c:193
void ShockHandler(PlayerBase player)
Определения ShockHandler.c:31
float m_ShockMultiplier
Определения ShockHandler.c:19
const int INTENSITY_FACTOR
Определения ShockHandler.c:5
float SetMultiplier(float mult)
Определения ShockHandler.c:163
float GetCurrentShock()
Определения ShockHandler.c:84
void Update(float deltaT)
Определения ShockHandler.c:44
const int VIGNETTE_INTENSITY_MAX
Определения ShockHandler.c:6
ref Param1< float > m_Param
Определения ShockHandler.c:27
const int MID_SHOCK_HIT
Deprecated.
Определения ShockHandler.c:187
void SetShock(float dealtShock)
Определения ShockHandler.c:94
float m_CumulatedShock
Определения ShockHandler.c:17
float m_Shock
Определения ShockHandler.c:14
PPERequester_TunnelVisionEffects m_Requester
Определения ShockHandler.c:26
void DealShock()
Определения ShockHandler.c:101
const float PULSE_PERIOD
Определения ShockHandler.c:11
float m_LastEffectIntensityValue
Определения ShockHandler.c:15
float LerpVignette(float x, float y, float deltaT)
Определения ShockHandler.c:176
const float SMOOTHING_MAX_DECR
Определения ShockHandler.c:9
float BaseEffectIntensityCalc()
Определения ShockHandler.c:136
PlayerBase m_Player
Определения ShockHandler.c:29
float AddEffectBobbing(float baseVal)
adds bobbing, also clamps to valid range
Определения ShockHandler.c:150
float m_PrevVignette
Определения ShockHandler.c:20
float m_TimeSinceLastTick
works ok on server, but does nothing for client. See deprecated stuff.
Определения ShockHandler.c:18
const int LIGHT_SHOCK_HIT
Определения ShockHandler.c:186
const float UPDATE_THRESHOLD
Определения ShockHandler.c:3
float NormalizeShockVal(float shock)
Определения ShockHandler.c:169
float m_ShockValueThreshold
Deprecated.
Определения ShockHandler.c:189
float GetShock()
Определения ShockHandler.c:89
void Synchronize()
Определения ShockHandler.c:131
const int VIGNETTE_INTENSITY_MAX_TOTAL
Определения ShockHandler.c:7
float m_LerpRes
Deprecated.
Определения ShockHandler.c:190
const float VALUE_CHECK_INTERVAL
Определения ShockHandler.c:4
proto native CGame GetGame()
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.