Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
spookyareamisc.c
Go to the documentation of this file.
1 //-------------------------------------------------------------
3 {
4  override protected void Init()
5  {
6  SetCoolDown(65);
7  m_SoundSet = "SpookyArea_WhistlingWind_SoundSet";
8  }
9 
10  override protected bool CanDo(PlayerBase player, TStringVectorMap surfaceTypes)
11  {
12  return player.IsSoundInsideBuilding();
13  }
14 
15  override protected void Do(PlayerBase player)
16  {
17  //put additional code here
18  }
19 }
20 //-------------------------------------------------------------
21 class SpookyEventWhisper : SpookyEventBase
22 {
23  override protected void Init()
24  {
25  SetCoolDown(80);
26  m_SoundSet = "SpookyArea_Whispering_SoundSet";
27  }
28 
29  override protected void Do(PlayerBase player)
30  {
31  //put additional code here
32  }
33 
34 }
35 //-------------------------------------------------------------
37 {
38  override protected void Init()
39  {
40  SetCoolDown(40);
41  m_SoundSet = "SpookyArea_RunOnConcrete_SoundSet";
42  m_Surfaces = {"stone", "gravel", "concrete", "wood", "asphalt", "tiles", "textile"};
43  }
44 
45  override protected void Do(PlayerBase player)
46  {
47  //put additional code here
48  }
49 }
50 //-------------------------------------------------------------
51 class SpookyEventRustle : SpookyEventBase
52 {
53  override protected void Init()
54  {
55  SetCoolDown(60);
56  m_SoundSet = "SpookyArea_IntenseFoliageRustle_SoundSet";
57  m_Surfaces = {"grass", "dirt", "forest", "soil"};
58  }
59 
60  override protected bool CanDo(PlayerBase player, TStringVectorMap surfaceTypes)
61  {
62  return !player.IsSoundInsideBuilding();
63  }
64 
65  override protected void Do(PlayerBase player)
66  {
67  vector soundPos = GetSoundPos(player);
68 
69  string secondarySoundSet = "SpookyArea_Hedgehog_SoundSet";
70 
71  if (Math.RandomBool())
72  {
73  secondarySoundSet = "SpookyArea_Badger_Voice_SoundSet";
74  }
75 
76  EffectSound sound = SEffectManager.PlaySound(secondarySoundSet, soundPos);
77  sound.SetAutodestroy( true );
78  }
79 }
80 
81 
82 //-------------------------------------------------------------
83 //-------------------------------------------------------------
84 //-------------------------------------------------------------
85 
87 {
88  //internal params, do not set manually
89  protected float m_PerformedTimestamp;//internal, marks the time this event was last performed so that it can guruantee the cooldown period before playing it again
90  protected int m_Cooldown;//how much time needs to elapse between this event can be performed again in seconds
91  //the params bellow can be set in the 'Init' method
92  protected string m_SoundSet;//if set, will play this soundset when performing the event
93  protected ref TStringArray m_Surfaces;//if set, the player needs to detect this surface for the event to be considered valid
94  protected vector m_MatchingSurfacePos;//position of the first matching surface
95 
96  void SpookyEventBase()
97  {
98  Init();
99  }
100 
101  protected void Init();
102 
103 
104  protected vector GetMatchingSurfacePos(TStringArray surfaces, TStringVectorMap gatheredSurfaces)
105  {
106  for (int i = 0; i < gatheredSurfaces.Count(); i++)
107  {
108  string currSurface = gatheredSurfaces.GetKey(i);
109  foreach (string s:surfaces)
110  {
111  if (currSurface.Contains(s))
112  return gatheredSurfaces.Get(currSurface);
113  }
114  }
115 
116  return vector.Zero;
117  }
118 
119  protected void SetCoolDown(float secs)
120  {
121  m_Cooldown = secs * 1000;
122  }
123 
124  protected bool HasSurfaces()
125  {
126  return (m_Surfaces && m_Surfaces.Count() > 0);
127  }
128 
129  protected bool CanDo(PlayerBase player, TStringVectorMap surfaceTypes)
130  {
131  return true;
132  }
133 
134  protected void Do(PlayerBase player);
135 
136  //internal, do not override, use 'CanDo' instead
137  bool CanPerform(PlayerBase player, float currentTime, TStringVectorMap surfaceTypes)
138  {
139  bool surfaceCheckResult = 1;
140 
141  if (HasSurfaces())
142  {
143  m_MatchingSurfacePos = GetMatchingSurfacePos(m_Surfaces, surfaceTypes);
144  surfaceCheckResult = m_MatchingSurfacePos != vector.Zero;
145  }
146 
147 
148  return ( currentTime > (m_PerformedTimestamp + m_Cooldown) && surfaceCheckResult && CanDo(player, surfaceTypes) );
149  }
150 
151  //internal, do not override, use 'Do' instead
152  void Perform(PlayerBase player, float currentTime, TStringVectorMap gatheredSurfaces)
153  {
154  #ifdef DIAG_DEVELOPER
155  if (DiagMenu.GetBool(DiagMenuIDs.TRIGGER_DEBUG))
156  Print("Performing " + this);
157  #endif
158  m_PerformedTimestamp = currentTime;
159 
160  if (m_SoundSet)
161  {
162  vector soundPos = GetSoundPos(player);
163  EffectSound sound = SEffectManager.PlaySound(m_SoundSet, soundPos);
164  sound.SetAutodestroy( true );
165 
166  #ifdef DIAG_DEVELOPER
167  if (DiagMenu.GetBool(DiagMenuIDs.TRIGGER_DEBUG))
168  Debug.DrawSphere(soundPos , 0.15,Colors.YELLOW, ShapeFlags.NOZBUFFER);
169  #endif
170  }
171 
172  Do(player);
173  }
174 
175  protected vector GetSoundPos(PlayerBase player)
176  {
177  vector soundPos;
178 
179  if (HasSurfaces())
180  {
181  soundPos = m_MatchingSurfacePos;
182  }
183  else
184  {
185  float distance = Math.RandomFloatInclusive(5,15);
186  vector randomDir = vector.RandomDir2D() * distance;
187  vector playerPos = player.GetPosition();
188  soundPos = playerPos + randomDir;
189  }
190 
191  return soundPos;
192  }
193 }
194 
195 //----------------------------------------------------------------------------------------------------------
196 
198 {
200  protected PlayerBase m_Player;
201  protected float m_TimeAccu;
202  protected const float CONSECUTIVE_EVENTS_COOLDOWN = 20;//min delay in seconds before two events
203  protected const float EVENT_CHECK_FREQUENCY = 2;//when not in cooldown, the rate at which we query the events
204  protected const float FIRST_EVENT_CHECK_DELAY = 15;//the delay between the first event check when we first enter the contaminated area
205  protected const float SURFACE_CHECK_POINT_DISTANCE = 2;//additional checks for surface are performed at this distance from the player
207 
209  {
210  if (!m_SoundEvents)
211  {
213  RegisterEvents();
214  }
215 
216  m_Player = player;
217  }
218 
220  {
221  m_SoundEvents = null;
222  }
223 
224  protected void RegisterEvents()
225  {
226  m_SoundEvents.Insert(new SpookyEventWind());
227  m_SoundEvents.Insert(new SpookyEventWhisper());
228  m_SoundEvents.Insert(new SpookyEventSteps());
229  m_SoundEvents.Insert(new SpookyEventRustle());
230 
231  }
232 
233  void Update(float deltaTime)
234  {
235  m_TimeAccu += deltaTime;
237  {
238  if (SelectEvent())
240  else
242  m_TimeAccu = 0;
243  }
244  }
245 
246  protected void GatherSurfaces(notnull TStringVectorMap gatheredGurfaces)
247  {
248  gatheredGurfaces.Clear();
249 
250  vector playerPos = m_Player.GetPosition();
251  TVectorArray positions = new TVectorArray();
252 
253  positions.Insert(playerPos);
254  positions.Insert(playerPos + ("0 0 1" * SURFACE_CHECK_POINT_DISTANCE));
255  positions.Insert(playerPos + ("0 0 -1" * SURFACE_CHECK_POINT_DISTANCE));
256  positions.Insert(playerPos + ("1 0 0" * SURFACE_CHECK_POINT_DISTANCE));
257  positions.Insert(playerPos + ("-1 0 0" * SURFACE_CHECK_POINT_DISTANCE));
258 
259  foreach (vector pos : positions)
260  {
261  string surfaceType;
262  GetGame().SurfaceGetType3D(pos[0],pos[1], pos[2], surfaceType);
263 
264  if (!gatheredGurfaces.Contains(surfaceType))
265  gatheredGurfaces.Insert(surfaceType, pos);
266  }
267 
268  #ifdef DIAG_DEVELOPER
269  if (DiagMenu.GetBool(DiagMenuIDs.TRIGGER_DEBUG))
270  {
271  foreach (vector p:positions)
272  Debug.DrawLine(p, p + "0 10 0", COLOR_BLUE,ShapeFlags.NOZBUFFER);
273  }
274  #endif
275 
276  }
277 
278  protected bool SelectEvent()
279  {
280  TStringVectorMap gatheredSurfaces = new TStringVectorMap();
281  GatherSurfaces(gatheredSurfaces);//this can be optimized by calling this on demand from an event, as none events might be eligible at this point, so we might be doing this in vain
282 
283  #ifdef DIAG_DEVELOPER
284  if (DiagMenu.GetBool(DiagMenuIDs.TRIGGER_DEBUG))
285  {
286  for(int i = 0; i < gatheredSurfaces.Count(); i++)
287  {
288  Print(gatheredSurfaces.GetKey(i));
289  Print(gatheredSurfaces.Get(gatheredSurfaces.GetKey(i)));
290 
291  }
292  Print("--------------------------------------------------------------------");
293  }
294  #endif
295 
297  float currentTime = GetGame().GetTime();
298  foreach (SpookyEventBase spookyEvent:m_SoundEvents)
299  {
300  if (spookyEvent.CanPerform(m_Player, currentTime, gatheredSurfaces))
301  validEvents.Insert(spookyEvent);
302  }
303 
304  //validEvents.Debug();
305  SpookyEventBase selectedEvent;
306 
307  if (validEvents.Count() > 0)
308  {
309  int randIndex = Math.RandomIntInclusive(0, validEvents.Count() - 1);
310  selectedEvent = validEvents[randIndex];
311  }
312  if (selectedEvent)
313  {
314  selectedEvent.Perform(m_Player, currentTime, gatheredSurfaces);
315  return true;
316  }
317  return false;
318 
319  }
320 
321 }
322 
325 {
326 
327  protected ref UniversalTemperatureSource m_UTSource;
328  protected ref UniversalTemperatureSourceSettings m_UTSSettings;
329  protected ref UniversalTemperatureSourceLambdaConstant m_UTSLConstant;
330 
331 
332  override void EEInit()
333  {
334  super.EEInit();
335 
336  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
337  {
339  m_UTSSettings.m_Updateable = true;
340  m_UTSSettings.m_UpdateInterval = 3;
341  m_UTSSettings.m_TemperatureMin = -20;
342  m_UTSSettings.m_TemperatureMax = -20;
343  m_UTSSettings.m_RangeFull = 2;
344  m_UTSSettings.m_RangeMax = 2;
345  m_UTSSettings.m_TemperatureCap = -20;
346  m_UTSSettings.m_ManualUpdate = false;
347 
348  m_UTSLConstant = new UniversalTemperatureSourceLambdaConstant();
349  m_UTSource = new UniversalTemperatureSource(this, m_UTSSettings, m_UTSLConstant);
350  m_UTSource.SetActive(true);
351  }
352 
353  }
354 
355 }
SpookyEventBase
Definition: spookyareamisc.c:86
GetGame
proto native CGame GetGame()
Do
override protected void Do(PlayerBase player)
Definition: spookyareamisc.c:13
m_UTSource
protected ref UniversalTemperatureSource m_UTSource
Definition: fireplacebase.c:224
m_NextEventCheck
protected float m_NextEventCheck
Definition: spookyareamisc.c:206
TVectorArray
array< vector > TVectorArray
Definition: enscript.c:692
m_TimeAccu
protected float m_TimeAccu
Definition: spookyareamisc.c:201
GatherSurfaces
protected void GatherSurfaces(notnull TStringVectorMap gatheredGurfaces)
Definition: spookyareamisc.c:246
DiagMenu
Definition: endebug.c:232
SelectEvent
protected bool SelectEvent()
Definition: spookyareamisc.c:278
CONSECUTIVE_EVENTS_COOLDOWN
const protected float CONSECUTIVE_EVENTS_COOLDOWN
Definition: spookyareamisc.c:202
FIRST_EVENT_CHECK_DELAY
const protected float FIRST_EVENT_CHECK_DELAY
Definition: spookyareamisc.c:204
SpookyEventSteps
Definition: spookyareamisc.c:36
SURFACE_CHECK_POINT_DISTANCE
const protected float SURFACE_CHECK_POINT_DISTANCE
Definition: spookyareamisc.c:205
Print
proto void Print(void var)
Prints content of variable to console/log.
SpookyEventWind
Definition: spookyareamisc.c:2
m_SoundEvents
class SpookyEventBase m_SoundEvents
UniversalTemperatureSource
original Timer deletes m_params which is unwanted
Definition: universaltemperaturesource.c:25
Update
void Update(float deltaTime)
Definition: spookyareamisc.c:233
Init
SpookyEventWind SpookyEventBase Init()
Launched from 'DayZGame.DeferredInit' to make earlier access, use, and updates impossible (downside o...
Definition: spookyareamisc.c:23
m_UTSSettings
protected ref UniversalTemperatureSourceSettings m_UTSSettings
Definition: fireplacebase.c:225
Colors
Definition: colors.c:3
DiagMenuIDs
DiagMenuIDs
Definition: ediagmenuids.c:1
EffectSound
Wrapper class for managing sound through SEffectManager.
Definition: effectsound.c:4
ScriptedEntity
Definition: triggercarrierbase.c:1
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
UniversalTemperatureSourceSettings
Definition: universaltemperaturesource.c:1
ShapeFlags
ShapeFlags
Definition: endebug.c:125
~SpookyTriggerEventsHandler
void ~SpookyTriggerEventsHandler()
Definition: spookyareamisc.c:219
CanDo
override protected bool CanDo(PlayerBase player, TStringVectorMap surfaceTypes)
Definition: spookyareamisc.c:8
TStringVectorMap
map< string, vector > TStringVectorMap
Definition: enscript.c:965
array< string >
SpookyPlayerStalker
this entity gets attached to each player while present in the spooky area
Definition: spookyareamisc.c:324
EVENT_CHECK_FREQUENCY
const protected float EVENT_CHECK_FREQUENCY
Definition: spookyareamisc.c:203
Debug
Definition: debug.c:13
Math
Definition: enmath.c:6
m_Cooldown
float m_Cooldown
Definition: staminahandler.c:139
SEffectManager
Manager class for managing Effect (EffectParticle, EffectSound)
Definition: effectmanager.c:5
COLOR_BLUE
const int COLOR_BLUE
Definition: constants.c:66
RegisterEvents
protected void RegisterEvents()
Definition: spookyareamisc.c:224
SpookyTriggerEventsHandler
void SpookyTriggerEventsHandler(notnull PlayerBase player)
Definition: spookyareamisc.c:208
m_Player
protected PlayerBase m_Player
Definition: spookyareamisc.c:200