DayZ 1.30
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 (g_Game.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 (g_Game.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 //Add bobbing to create pulsing effect
75 valAdjusted = AddEffectBobbing(valAdjusted);
76
77 m_Param.param1 = valAdjusted;
78 m_Requester.Start(m_Param);
79 }
80 }
81
83 {
84 return m_Player.m_CurrentShock;
85 }
86
87 float GetShock()
88 {
89 return m_Shock;
90 }
91
92 void SetShock(float dealtShock)
93 {
94 m_Shock += dealtShock;
95 CheckValue(false);
96 }
97
98 //Inflict shock damage
99 private void DealShock()
100 {
101 if (g_Game.IsServer())
102 m_Player.GiveShock(-m_CumulatedShock);
103 }
104
105 //Passing a value of FALSE will only check the values, a value of TRUE will force a synchronization (don't use too often)
106 void CheckValue(bool forceUpdate)
107 {
108 m_CumulatedShock += m_Shock; // increment on both client and server
109
110 if (forceUpdate)
111 m_PrevVignette = NormalizeShockVal(m_Player.m_CurrentShock);
112
113 if (g_Game.IsServer())
114 {
115 if (m_CumulatedShock >= UPDATE_THRESHOLD || forceUpdate)
116 {
118 DealShock();
120 m_Shock = 0;
121
122 Synchronize();
123 }
124
125 m_Player.m_CurrentShock = m_Player.GetHealth("", "Shock");
126 }
127 }
128
129 protected void Synchronize()
130 {
132 }
133
134 protected float BaseEffectIntensityCalc()
135 {
136 float effectIntensity = 1 - Easing.EaseInQuart(NormalizeShockVal(m_Player.m_CurrentShock));
137
138 //smoothing
139 if (effectIntensity != m_LastEffectIntensityValue)
141
142 m_LastEffectIntensityValue = effectIntensity;
143
144 return effectIntensity;
145 }
146
148 protected float AddEffectBobbing(float baseVal)
149 {
150 float ret = baseVal;
151 float bobbingVal = 0.0;
152
153 if (m_Player.m_CurrentShock > m_ShockValueMax * 0.8)
154 bobbingVal = MiscGameplayFunctions.Bobbing(PULSE_PERIOD, PULSE_AMPLITUDE, m_PulseTimer);
155 ret += bobbingVal;
157
158 return ret;
159 }
160
161 float SetMultiplier(float mult)
162 {
163 m_ShockMultiplier = mult;
164 return m_ShockMultiplier;
165 }
166
167 private float NormalizeShockVal(float shock)
168 {
169 float base = m_ShockValueMax * INTENSITY_FACTOR;
170 float normShock = shock / base;
171 return normShock;
172 }
173
174 private float LerpVignette(float x, float y, float deltaT)
175 {
176 float output;
177 output = Math.Lerp(x, y, deltaT);
178 return output;
179 }
180
182 //Deprecated stuff below//
184 private const int LIGHT_SHOCK_HIT = 33;
185 private const int MID_SHOCK_HIT = 67;
186 private const int HEAVY_SHOCK_HIT = 100;
187 protected float m_ShockValueThreshold;
188 private float m_LerpRes;
189
191 private void ShockHitEffect(float compareBase)
192 {
193 float shockDifference = compareBase - m_Player.m_CurrentShock;
194 if (shockDifference >= UPDATE_THRESHOLD)
195 {
196 if (m_CumulatedShock < 25)
197 m_Player.SpawnShockEffect(MiscGameplayFunctions.Normalize(LIGHT_SHOCK_HIT, 100));
198 else if (m_CumulatedShock < 50)
199 m_Player.SpawnShockEffect(MiscGameplayFunctions.Normalize(MID_SHOCK_HIT, 100));
200 else
201 m_Player.SpawnShockEffect(MiscGameplayFunctions.Normalize(HEAVY_SHOCK_HIT, 100));
202 }
203 }
204};
DayZGame g_Game
Определения DayZGame.c:4074
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:186
float m_PulseTimer
Определения ShockHandler.c:23
const float PULSE_AMPLITUDE
Определения ShockHandler.c:12
void CheckValue(bool forceUpdate)
Определения ShockHandler.c:106
void ShockHitEffect(float compareBase)
Deprecated.
Определения ShockHandler.c:191
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:161
float GetCurrentShock()
Определения ShockHandler.c:82
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:185
void SetShock(float dealtShock)
Определения ShockHandler.c:92
float m_CumulatedShock
Определения ShockHandler.c:17
float m_Shock
Определения ShockHandler.c:14
PPERequester_TunnelVisionEffects m_Requester
Определения ShockHandler.c:26
void DealShock()
Определения ShockHandler.c:99
const float PULSE_PERIOD
Определения ShockHandler.c:11
float m_LastEffectIntensityValue
Определения ShockHandler.c:15
float LerpVignette(float x, float y, float deltaT)
Определения ShockHandler.c:174
const float SMOOTHING_MAX_DECR
Определения ShockHandler.c:9
float BaseEffectIntensityCalc()
Определения ShockHandler.c:134
PlayerBase m_Player
Определения ShockHandler.c:29
float AddEffectBobbing(float baseVal)
adds bobbing, also clamps to valid range
Определения ShockHandler.c:148
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:184
const float UPDATE_THRESHOLD
Определения ShockHandler.c:3
float NormalizeShockVal(float shock)
Определения ShockHandler.c:167
float m_ShockValueThreshold
Deprecated.
Определения ShockHandler.c:187
float GetShock()
Определения ShockHandler.c:87
void Synchronize()
Определения ShockHandler.c:129
const int VIGNETTE_INTENSITY_MAX_TOTAL
Определения ShockHandler.c:7
float m_LerpRes
Deprecated.
Определения ShockHandler.c:188
const float VALUE_CHECK_INTERVAL
Определения ShockHandler.c:4
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'.