Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
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//-------------------------------------------------------------
21class 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//-------------------------------------------------------------
51class 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
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 {
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);
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{
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 {
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
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_TemperatureItemCap = -20;
342 m_UTSSettings.m_TemperatureCap = -20;
343 m_UTSSettings.m_RangeFull = 2;
344 m_UTSSettings.m_RangeMax = 2;
345 m_UTSSettings.m_ManualUpdate = false;
346 m_UTSSettings.m_IsWorldOverriden = false;
347
348 m_UTSLConstant = new UniversalTemperatureSourceLambdaConstant();
350 m_UTSource.SetActive(true);
351 }
352
353 }
354
355}
proto float SurfaceGetType3D(float x, float y, float z, out string type)
Y input: Maximum Y to trace down from; Returns: Y position the surface was found.
proto int GetTime()
returns mission time in milliseconds
Definition colors.c:4
Definition debug.c:2
Wrapper class for managing sound through SEffectManager.
Definition effectsound.c:5
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
Definition enmath.c:7
Manager class for managing Effect (EffectParticle, EffectSound)
static EffectSound PlaySound(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound.
bool CanDo(PlayerBase player, TStringVectorMap surfaceTypes)
bool CanPerform(PlayerBase player, float currentTime, TStringVectorMap surfaceTypes)
void Do(PlayerBase player)
ref TStringArray m_Surfaces
vector GetSoundPos(PlayerBase player)
vector m_MatchingSurfacePos
vector GetMatchingSurfacePos(TStringArray surfaces, TStringVectorMap gatheredSurfaces)
void SetCoolDown(float secs)
void Perform(PlayerBase player, float currentTime, TStringVectorMap gatheredSurfaces)
void Do(PlayerBase player)
bool CanDo(PlayerBase player, TStringVectorMap surfaceTypes)
void Do(PlayerBase player)
this entity gets attached to each player while present in the spooky area
ref UniversalTemperatureSourceSettings m_UTSSettings
ref UniversalTemperatureSource m_UTSource
ref UniversalTemperatureSourceLambdaConstant m_UTSLConstant
override void EEInit()
original Timer deletes m_params which is unwanted
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DiagMenuIDs
Definition ediagmenuids.c:2
proto native CGame GetGame()
const int COLOR_BLUE
Definition constants.c:66
proto void Print(void var)
Prints content of variable to console/log.
ShapeFlags
Definition endebug.c:126
map< string, vector > TStringVectorMap
Definition enscript.c:989
array< vector > TVectorArray
Definition enscript.c:716
DayZPlayer m_Player
Definition hand_events.c:42
const float SURFACE_CHECK_POINT_DISTANCE
const float FIRST_EVENT_CHECK_DELAY
const float EVENT_CHECK_FREQUENCY
void GatherSurfaces(notnull TStringVectorMap gatheredGurfaces)
bool SelectEvent()
void RegisterEvents()
void ~SpookyTriggerEventsHandler()
class SpookyEventBase m_SoundEvents
float m_TimeAccu
float m_NextEventCheck
const float CONSECUTIVE_EVENTS_COOLDOWN
void SpookyTriggerEventsHandler(notnull PlayerBase player)