Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
flashbangeffect.c
Go to the documentation of this file.
2 {
3  protected const float ALPHA_MIN = 0.0;
4  protected const float ALPHA_MAX = 1.0;
5 
6  protected const float SOUND_DEFER_TIME = 0.4;
7 
8  protected float m_HitDuration;
9  protected float m_BreakPoint;
10  protected float m_TimeActive;
11  protected float m_DayTimeToggle;
12 
13  protected float m_AlphaMaxActual; //actual max alpha of the effect
14  protected float m_SoundMaxActual; //actual max volume of the sound
15  protected float m_ProgressMultiplier;
16 
17  protected bool m_Visual;
18  protected bool m_Initialized;
19 
20  protected PlayerBase m_Player;
21  protected EffectSound m_FlashbangEffectSound;
22  protected float m_SoundStopTime;
23 
24  protected ref Timer m_DeferAttenuation;
25 
26  protected PPERequester_FlashbangEffects m_Requester;
27 
28  void FlashbangEffect(PlayerBase player, bool visual = true)
29  {
30  m_Player = player;
31  m_Visual = visual;
32  m_Initialized = false;
33 
34  m_HitDuration = 8.0;
35  m_BreakPoint = 2.5;
36  m_AlphaMaxActual = ALPHA_MAX;
37  m_SoundMaxActual = 1.0;
38  m_ProgressMultiplier = 1.0;
39 
40  m_FlashbangEffectSound = null;
41 
42  if (m_Visual)
43  {
44  Class.CastTo(m_Requester,PPERequesterBank.GetRequester(PPERequester_FlashbangEffects));
45  m_Requester.Start();
46  }
47 
48  m_DeferAttenuation = new ref Timer();
49  m_DeferAttenuation.Run(SOUND_DEFER_TIME, this, "PlaySound", null, false);
50 
52  m_DayTimeToggle = 5;
53  if ( g_Game.GetDayTime() >= 22.0 || g_Game.GetDayTime() < 7.0 )
54  {
55  m_DayTimeToggle = 10;
56  }
57  }
58 
59  void ~FlashbangEffect()
60  {
61  if ( m_Visual )
62  {
63  ClearVisual();
64  }
65 
66  if ( m_Player )
67  {
68  m_Player.OnPlayerReceiveFlashbangHitEnd();
69  }
70 
71  if ( m_DeferAttenuation.IsRunning() )
72  {
73  m_DeferAttenuation.Stop();
74  }
75 
76  m_DeferAttenuation = null;
77  SEffectManager.DestroyEffect(m_FlashbangEffectSound);
78  }
79 
80  void SetupFlashbangValues(float progress_mult = 1.0, float visual_value_max = 1.0, float sound_value_max = 1.0)
81  {
82  if ( !m_Initialized )
83  {
84  m_Initialized = true;
85  m_ProgressMultiplier = progress_mult;
86  m_AlphaMaxActual = visual_value_max;
87  m_SoundMaxActual = sound_value_max;
88 
89  m_HitDuration *= m_ProgressMultiplier;
90  m_BreakPoint *= m_ProgressMultiplier;
91  }
92  }
93 
94  protected void PlaySound()
95  {
96  if ( !m_Initialized )
97  {
98  Error("" + this + " not initialized");
99  return;
100  }
101 
102  vector pos;
103  MiscGameplayFunctions.GetHeadBonePos(m_Player, pos);
104 
105  if (!m_FlashbangEffectSound)
106  {
107  m_FlashbangEffectSound = SEffectManager.CreateSound("Tinnitus_SoundSet", pos);
108  }
109 
110  if (!m_FlashbangEffectSound.IsPlaying())
111  {
112  m_FlashbangEffectSound.SetParent(m_Player);
113  m_FlashbangEffectSound.SetAttachedLocalPos(m_Player.WorldToModel(pos));
114  m_FlashbangEffectSound.SetSoundWaveKind(WaveKind.WAVEEFFECTEX);
115  m_FlashbangEffectSound.SetSoundFadeIn(4 * Math.Clamp(m_ProgressMultiplier,0.5,1.0)); //TODO
116  m_SoundStopTime = 2 * Math.Clamp(m_ProgressMultiplier,0.5,1.0);
117  m_FlashbangEffectSound.SetSoundFadeOut(m_SoundStopTime); //TODO
118  m_FlashbangEffectSound.SetSoundMaxVolume(Math.Clamp(m_SoundMaxActual,0.1,1.0)); //TODO
119  m_FlashbangEffectSound.SetSoundLoop(true);
120  m_FlashbangEffectSound.SoundPlay();
121  m_FlashbangEffectSound.SetAutodestroy(true);
122 
123  SetAttenuationFilter();
124  }
125  }
126 
127  protected void SetAttenuationFilter()
128  {
129  if ( !m_DeferAttenuation.IsRunning() || m_Player.GetMasterAttenuation() != "FlashbangAttenuation" )
130  {
131  m_Player.SetMasterAttenuation("FlashbangAttenuation");
132  }
133  }
134 
135  protected void ResetAttenuationFilter()
136  {
137  m_Player.SetMasterAttenuation("");
138  }
139 
140  protected void StopSound()
141  {
142  if (m_FlashbangEffectSound)
143  {
144  m_FlashbangEffectSound.SoundStop();
145  SEffectManager.DestroyEffect(m_FlashbangEffectSound);
146  }
147  }
148 
149  protected void ClearVisual()
150  {
151  if (m_Requester)
152  {
153  m_Requester.Stop();
154  }
155  }
156 
157  protected void SetVisual(float val)
158  {
159  if (m_Requester && m_Requester.IsRequesterRunning())
160  {
161  m_Requester.SetFlashbangIntensity(val, m_DayTimeToggle);
162  }
163  }
164 
165  void Stop()
166  {
167  StopSound();
168  }
169 
170  void Update(float deltatime)
171  {
172  if ( !m_Initialized )
173  {
174  Error("" + this + " not initialized");
175  }
176  else if ( m_Visual )
177  {
178  float value;
179 
180  if ( m_TimeActive <= m_BreakPoint )
181  {
182  value = m_AlphaMaxActual;
183  //Print("Flashbango | m_AlphaMaxActual: " + value);
184  }
185  else
186  {
187  value = Math.InverseLerp(m_HitDuration - m_BreakPoint, m_HitDuration, m_TimeActive);
188  value = Math.Clamp(value,0.0,1.0);
189  value = m_AlphaMaxActual - value * m_AlphaMaxActual;
190  //Print("Flashbango | tmp_value: " + value);
191  }
192  SetVisual(value);
193  }
194 
195  m_TimeActive += deltatime;
196 
197  if (m_TimeActive >= m_HitDuration - m_SoundStopTime)
198  {
199  StopSound();
200  }
201 
202  if (m_TimeActive >= m_HitDuration)
203  {
204  ResetAttenuationFilter();
205  delete this;
206  }
207  }
208 }
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
m_Requester
protected PPERUndergroundAcco m_Requester
Definition: undergroundhandlerclient.c:22
EffectSound
Wrapper class for managing sound through SEffectManager.
Definition: effectsound.c:4
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
FlashbangEffect
Definition: flashbangeffect.c:1
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
WaveKind
WaveKind
Definition: sound.c:1
m_Initialized
protected bool m_Initialized
Definition: uihintpanel.c:23
Timer
Definition: dayzplayerimplement.c:62
m_TimeActive
class DamageDealtEffect m_TimeActive
Math
Definition: enmath.c:6
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
SEffectManager
Manager class for managing Effect (EffectParticle, EffectSound)
Definition: effectmanager.c:5