DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
ShockHandler.c
См. документацию.
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
26 protected ref Param1<float> m_Param;
27
29 {
30 m_Player = player;
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 {
40 m_TimeSinceLastTick += deltaT;
41
42 m_PulseTimer += deltaT;
43
44 if ( GetGame().IsClient() )
45 {
46 //Deactivate tunnel vignette when player falls unconscious
47 if ( m_Player.IsUnconscious() )
48 {
49 PPERequesterBank.GetRequester(PPERequester_TunnelVisionEffects).Stop();
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 {
56 PPERequesterBank.GetRequester(PPERequester_TunnelVisionEffects).Stop();
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)
63 val = MiscGameplayFunctions.Bobbing( PULSE_PERIOD, PULSE_AMPLITUDE, m_PulseTimer );
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
71 val_adjusted = 1 - Easing.EaseInQuart(m_LerpRes) + val;
72 }
73 else
74 {
75 val_adjusted = 1 - Easing.EaseInQuart( NormalizeShockVal(m_Player.m_CurrentShock)) + val;
76 }
77
78 m_Param.param1 = val_adjusted;
79 PPERequesterBank.GetRequester(PPERequester_TunnelVisionEffects).Start(m_Param);
80 }
81
83 {
84 //Play the shock hit event (multiply prevVignette by 100 to "Un-Normalize" value)
85 if ( GetGame().IsClient() )
86 {
88 m_PrevVignette = m_Player.m_CurrentShock * 0.01;
89 }
90
91 CheckValue( false );
93 }
94 }
95
97 {
98 return m_Player.m_CurrentShock;
99 }
100
101 float GetShock()
102 {
103 return m_Shock;
104 }
105
106 void SetShock( float dealtShock )
107 {
108 m_Shock += dealtShock;
109 CheckValue( false );
110 }
111
112 //Inflict shock damage
113 private void DealShock()
114 {
115 if ( GetGame().IsServer() )
116 m_Player.GiveShock( -m_CumulatedShock );
117 }
118
119 //Passing a value of FALSE will only check the values, a value of TRUE will force a synchronization (don't use too often)
120 void CheckValue(bool forceUpdate)
121 {
122 m_CumulatedShock += m_Shock; // increment on both client and server
123
124 if ( forceUpdate )
125 m_PrevVignette = NormalizeShockVal( m_Player.m_CurrentShock );
126
127 if ( GetGame().IsServer() )
128 {
129 m_Player.m_CurrentShock = m_Player.GetHealth("", "Shock");
130
131 /*
132 if (m_Player.m_CurrentShock <= 0)
133 m_Player.SetHealthMax("", "Shock");
134 */
135 if ( m_CumulatedShock >= UPDATE_THRESHOLD || forceUpdate )
136 {
138 DealShock();
140 m_Shock = 0;
141
142 Synchronize();
143 }
144 }
145 }
146
147 protected void Synchronize()
148 {
150 }
151
152 float SetMultiplier(float mult)
153 {
154 m_ShockMultiplier = mult;
155 return m_ShockMultiplier;
156 }
157
158 private float NormalizeShockVal( float shock )
159 {
160 float base = m_Player.GetMaxHealth("", "Shock") * INTENSITY_FACTOR;
161 float normShock = shock / base;
162 return normShock;
163 }
164
165 private float LerpVignette( float x, float y, float deltaT )
166 {
167 float output;
168 output = Math.Lerp( x, y, deltaT );
169 return output;
170 }
171
172 //ONLY CLIENT SIDE
173 private void ShockHitEffect( float compareBase )
174 {
175 float shockDifference = compareBase - m_Player.m_CurrentShock;
176 //Print(shockDifference);
177 if ( shockDifference >= UPDATE_THRESHOLD )
178 {
179 if ( m_CumulatedShock < 25 )
180 m_Player.SpawnShockEffect( MiscGameplayFunctions.Normalize( LIGHT_SHOCK_HIT, 100 ) );
181 else if ( m_CumulatedShock < 50 )
182 m_Player.SpawnShockEffect( MiscGameplayFunctions.Normalize( MID_SHOCK_HIT, 100 ) );
183 else
184 m_Player.SpawnShockEffect( MiscGameplayFunctions.Normalize( HEAVY_SHOCK_HIT, 100 ) );
185 }
186 }
187};
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:4
const int HEAVY_SHOCK_HIT
Определения ShockHandler.c:18
float m_PulseTimer
Определения ShockHandler.c:24
const float PULSE_AMPLITUDE
Определения ShockHandler.c:23
void CheckValue(bool forceUpdate)
Определения ShockHandler.c:120
void ShockHitEffect(float compareBase)
Определения ShockHandler.c:173
void ShockHandler(PlayerBase player)
Определения ShockHandler.c:28
float m_ShockMultiplier
Определения ShockHandler.c:12
const int INTENSITY_FACTOR
Определения ShockHandler.c:19
float SetMultiplier(float mult)
Определения ShockHandler.c:152
float GetCurrentShock()
Определения ShockHandler.c:96
void Update(float deltaT)
Определения ShockHandler.c:38
ref Param1< float > m_Param
Определения ShockHandler.c:26
const int MID_SHOCK_HIT
Определения ShockHandler.c:17
void SetShock(float dealtShock)
Определения ShockHandler.c:106
float m_CumulatedShock
Определения ShockHandler.c:10
float m_Shock
Определения ShockHandler.c:3
void DealShock()
Определения ShockHandler.c:113
const float PULSE_PERIOD
Определения ShockHandler.c:22
float LerpVignette(float x, float y, float deltaT)
Определения ShockHandler.c:165
PlayerBase m_Player
Определения ShockHandler.c:6
float m_PrevVignette
Определения ShockHandler.c:13
float m_TimeSinceLastTick
Определения ShockHandler.c:11
const int LIGHT_SHOCK_HIT
Определения ShockHandler.c:16
const float UPDATE_THRESHOLD
Определения ShockHandler.c:8
float NormalizeShockVal(float shock)
Определения ShockHandler.c:158
float m_ShockValueThreshold
Определения ShockHandler.c:5
float GetShock()
Определения ShockHandler.c:101
void Synchronize()
Определения ShockHandler.c:147
float m_LerpRes
Определения ShockHandler.c:14
const float VALUE_CHECK_INTERVAL
Определения 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'.