DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
SpookyAreaMisc.c
См. документацию.
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}
DiagMenuIDs
Определения EDiagMenuIDs.c:2
DayZPlayer m_Player
Определения Hand_Events.c:42
const float SURFACE_CHECK_POINT_DISTANCE
Определения SpookyAreaMisc.c:205
const float FIRST_EVENT_CHECK_DELAY
Определения SpookyAreaMisc.c:204
const float EVENT_CHECK_FREQUENCY
Определения SpookyAreaMisc.c:203
void GatherSurfaces(notnull TStringVectorMap gatheredGurfaces)
Определения SpookyAreaMisc.c:246
bool SelectEvent()
Определения SpookyAreaMisc.c:278
void RegisterEvents()
Определения SpookyAreaMisc.c:224
void ~SpookyTriggerEventsHandler()
Определения SpookyAreaMisc.c:219
class SpookyEventBase m_SoundEvents
float m_TimeAccu
Определения SpookyAreaMisc.c:201
float m_NextEventCheck
Определения SpookyAreaMisc.c:206
const float CONSECUTIVE_EVENTS_COOLDOWN
Определения SpookyAreaMisc.c:202
void SpookyTriggerEventsHandler(notnull PlayerBase player)
Определения SpookyAreaMisc.c:208
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
const int YELLOW
Определения Colors.c:10
Определения Colors.c:4
static Shape DrawSphere(vector pos, float size=1, int color=0x1fff7f7f, ShapeFlags flags=ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE)
Определения Debug.c:319
static Shape DrawLine(vector from, vector to, int color=0xFFFFFFFF, int flags=0)
Определения Debug.c:382
Определения Debug.c:2
Определения EnDebug.c:233
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
Определения EffectSound.c:603
Wrapper class for managing sound through SEffectManager.
Определения EffectSound.c:5
Определения EnMath.c:7
Определения PlayerBaseClient.c:2
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.
Определения EffectManager.c:169
Manager class for managing Effect (EffectParticle, EffectSound)
Определения EffectManager.c:6
bool CanDo(PlayerBase player, TStringVectorMap surfaceTypes)
Определения SpookyAreaMisc.c:129
bool CanPerform(PlayerBase player, float currentTime, TStringVectorMap surfaceTypes)
Определения SpookyAreaMisc.c:137
void Do(PlayerBase player)
ref TStringArray m_Surfaces
Определения SpookyAreaMisc.c:93
void SpookyEventBase()
Определения SpookyAreaMisc.c:96
vector GetSoundPos(PlayerBase player)
Определения SpookyAreaMisc.c:175
vector m_MatchingSurfacePos
Определения SpookyAreaMisc.c:94
int m_Cooldown
Определения SpookyAreaMisc.c:90
vector GetMatchingSurfacePos(TStringArray surfaces, TStringVectorMap gatheredSurfaces)
Определения SpookyAreaMisc.c:104
bool HasSurfaces()
Определения SpookyAreaMisc.c:124
void SetCoolDown(float secs)
Определения SpookyAreaMisc.c:119
string m_SoundSet
Определения SpookyAreaMisc.c:92
void Perform(PlayerBase player, float currentTime, TStringVectorMap gatheredSurfaces)
Определения SpookyAreaMisc.c:152
float m_PerformedTimestamp
Определения SpookyAreaMisc.c:89
Определения SpookyAreaMisc.c:87
void Init()
Определения SpookyAreaMisc.c:38
void Do(PlayerBase player)
Определения SpookyAreaMisc.c:45
bool CanDo(PlayerBase player, TStringVectorMap surfaceTypes)
Определения SpookyAreaMisc.c:10
void Do(PlayerBase player)
Определения SpookyAreaMisc.c:15
void Init()
Определения SpookyAreaMisc.c:4
Определения SpookyAreaMisc.c:3
ref UniversalTemperatureSourceSettings m_UTSSettings
Определения SpookyAreaMisc.c:328
ref UniversalTemperatureSource m_UTSource
Определения SpookyAreaMisc.c:327
ref UniversalTemperatureSourceLambdaConstant m_UTSLConstant
Определения SpookyAreaMisc.c:329
override void EEInit()
Определения SpookyAreaMisc.c:332
this entity gets attached to each player while present in the spooky area
Определения SpookyAreaMisc.c:325
original Timer deletes m_params which is unwanted
Определения UniversalTemperatureSource.c:38
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
static const vector Zero
Определения EnConvert.c:110
static vector RandomDir2D()
Returns randomly generated XZ unit vector with the Y(up) axis set to 0.
Определения EnConvert.c:260
Определения EnConvert.c:106
proto native CGame GetGame()
const int COLOR_BLUE
Определения constants.c:66
proto void Print(void var)
Prints content of variable to console/log.
ShapeFlags
Определения EnDebug.c:126
static proto bool GetBool(int id, bool reverse=false)
Get value as bool from the given script id.
array< string > TStringArray
Определения EnScript.c:685
map< string, vector > TStringVectorMap
Определения EnScript.c:965
array< vector > TVectorArray
Определения EnScript.c:692
static float RandomFloatInclusive(float min, float max)
Returns a random float number between and min [inclusive] and max [inclusive].
Определения EnMath.c:106
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Определения EnMath.c:54
bool Contains(string sample)
Returns true if sample is substring of string.
Определения EnString.c:286
proto native volatile void Update()
Определения PlayerSoundManager.c:125