DayZ 1.24
Loading...
Searching...
No Matches
EasterEgg.c
Go to the documentation of this file.
2{
3 CAPTURE = 0,
4 RELEASE = 1,
5 STASIS = 2,
8
9 //Keep this last value at the end, add any new states before
10 END
12
14{
15 //Capture parameters
17 private string m_CreatureType;
18 private int m_CreatureHash = 0; //Used for sync
19 private int m_CaptureState = eCaptureState.STASIS;
20 private const vector CAPTURE_VELOCITY = { 0, 0, 0 };
21
22 //VFX
24 private float m_ParScale = 1;
25 private const float PARTICLE_SCALE_MULT = 0.1; //Used because we use DistanceSqr to get relevant scale
26
27 //SFX
28 protected EffectSound m_CaptureSound; //Egg SFX
29 protected EffectSound m_CreatureSound; //Creature specific SFX
30 protected bool m_DangerSound = false; //Used to determine if release animal is dangerous and play sound accordingly
31
32 protected ref map<int, string> m_CreatureSoundMap; //Store all possible creature sound sets mapped to their respective hash
33 protected int m_CaptureSoundHash; //Used to find capture sound set in map
34 protected int m_ReleaseSoundHash; //Used to find release sound set in map
35
36
37 void EasterEgg()
38 {
39 m_CreatureType = "";
40 SetEventMask(EntityEvent.CONTACT | EntityEvent.TOUCH);
41 SetFlags(EntityFlags.TRIGGER, false);
42 RegisterNetSyncVariableInt("m_CaptureState", 0, eCaptureState.END);
43 RegisterNetSyncVariableInt("m_CreatureHash", 0, 0);
44 RegisterNetSyncVariableFloat("m_ParScale", 0, 0, 0.1);
45 RegisterNetSyncVariableBool("m_DangerSound");
46 RegisterNetSyncVariableInt("m_CaptureSoundHash", 0, 0);
47 RegisterNetSyncVariableInt("m_ReleaseSoundHash", 0, 0);
48
50 }
51
53 {
54 if (m_ParCapture)
56 }
57
58 // ------------------------------
59 // CORE EXECUTION DEPENDING ON CURRENT STATE
60 // ------------------------------
62 {
63 switch (m_CaptureState)
64 {
65 case eCaptureState.CAPTURE:
67 if (capAnimal && capAnimal.IsAlive())
68 {
69 if (GetGame().IsServer())
71 }
72 else
73 m_CaptureState = eCaptureState.STASIS; //We did not capture anything, go back to stasis
74 break;
75
76 case eCaptureState.RELEASE:
77 Release(pos);
78 PlayVFX();
79 PlaySFX(eCaptureState.RELEASE);
80 break;
81
82 case eCaptureState.CAPTUREFX:
83 case eCaptureState.RELEASEFX:
84 //Intermediate state to play FX on next client side contact event
85 //Creates slight delay but saves network traffic
86 if (m_CreatureHash != 0)
87 {
88 //Make sure to go back in stasis
90 SetSynchDirty();
91 }
92 break;
93
94 case eCaptureState.STASIS:
95 //Do nothing here, feel free to add logic for fun fumble effects when nothing happens :)
96
97 break;
98
99 default: //default in case state is somehow not initialized
100
101 break;
102 }
103 }
104
105 //Used for capture
106 override void EOnTouch(IEntity other, int extra)
107 {
109 }
110
111 //Used for release
113 {
114 ContactEvent(other, extra.Position);
115 }
116
117 override void OnInventoryExit(Man player)
118 {
119 //Do not execute on simple drop as it may cause issues
121 if (player_PB && player_PB.GetThrowing().IsThrowingAnimationPlaying())
122 {
123 if (m_CreatureType != "")
125 else
127 }
128 else
130
131 //Make sure state is properly synchronized or VFX might bug out
132 SetSynchDirty();
133 }
134
135 override void OnInventoryEnter(Man player)
136 {
137 //Make sure to stop particles once in inventory
138 if (GetGame().IsClient() && m_ParCapture)
139 {
141 m_ParCapture.Delete();
142 }
143 }
144
146 {
147 super.EEItemLocationChanged(oldLoc, newLoc);
148
149 //DestroyEg();
150 }
151
152 // ------------------------------
153 // CAPTURE AND RELEASE LOGIC
154 // ------------------------------
156 {
157 if (!IsAlive())
158 {
159 if (m_ParCapture)
160 m_ParCapture.Delete();
161 Delete();
162 return;
163 }
164
168 m_CaptureState = eCaptureState.CAPTUREFX;
169 m_DangerSound = m_StoredCreature.IsDanger();
170 m_CaptureSoundHash = m_StoredCreature.CaptureSound().Hash();
171 m_ReleaseSoundHash = m_StoredCreature.ReleaseSound().Hash();
172
173 //Resize particle upon capture as there is enough delay to be sure value is synced
175
176 SetSynchDirty();
177
178 capAnimal.Delete();
181 }
182
183 private void Release(vector pos)
184 {
185 if (GetGame().IsServer())
186 {
187 m_CaptureState = eCaptureState.RELEASEFX;
188 m_CreatureHash = 0;
189 SetSynchDirty();
190
191 GetGame().CreateObject(m_CreatureType, pos, false, true);
192 m_CreatureType = "";
193
194 DecreaseHealth("", "", GetMaxHealth() * 0.4);
195 SetQuantity(GetQuantityMin(), false);
197
198 if (!IsAlive())
199 {
200 if (m_ParCapture)
201 m_ParCapture.Delete();
202 Delete();
203 }
204 }
205 }
206
207 // ------------------------------
208 // CAPTURE AND RELEASE EFFECTS
209 // ------------------------------
210 private void PlayVFX()
211 {
212 if (!GetGame().IsDedicatedServer())
213 {
214 if (!m_ParCapture && m_CaptureState != eCaptureState.STASIS)
215 {
216 //Ideally play a one time effect such as an explosion
218
219 //Resize, -1 signifies ALL emitors
221 m_ParCapture.SetWiggle(7, 0.3);
222 }
223 }
224 }
225
227 {
228 //Determine particle scale depending on captured animal scale
230 capAnimal.GetWorldBounds(mins, maxs);
232
233 //Multiply to rescale down as fed values can be really large
235 }
236
237 private void PlaySFX(int releaseCase = eCaptureState.CAPTURE)
238 {
239 if (!GetGame().IsDedicatedServer())
240 {
241 string soundSet = "";
242 if (releaseCase == eCaptureState.CAPTURE)
243 {
244 PlaySoundSet(m_CaptureSound, "EasterEgg_Catch_SoundSet", 0, 0);
245
247 PlaySoundSet(m_CreatureSound, soundSet, 0, 0);
248 }
249 else
250 {
251 if (!m_DangerSound)
252 {
253 PlaySoundSet(m_CaptureSound, "EasterEgg_Spawn_SoundSet", 0, 0);
254
256 PlaySoundSet(m_CreatureSound, soundSet, 0, 0);
257 }
258 else
259 {
260 PlaySoundSet(m_CaptureSound, "EasterEgg_Spawn_Danger_SoundSet", 0, 0);
261
263 PlaySoundSet(m_CreatureSound, soundSet, 0, 0);
264 }
265 }
266 }
267 }
268
269
271 {
272 if (m_CaptureState == eCaptureState.CAPTUREFX)
273 {
274 PlayVFX();
275 PlaySFX();
276 }
277 else if (m_CaptureState == eCaptureState.RELEASEFX)
278 {
279 PlayVFX();
280 PlaySFX(eCaptureState.RELEASE);
281 }
282 }
283
284 // ------------------------------
285 // SOUNDSET MAP REGISTRATION
286 // ------------------------------
288 {
289 //Register all possible creature sounds in map with their respective hash
290 string soundSet;
292
293 //Cow sounds
294 soundSet = "CattleMooA_SoundSet";
295 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
296 soundSet = "CattleBellow_SoundSet";
297 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
298
299 //Deer sounds
300 soundSet = "DeerRoar_SoundSet";
301 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
302 soundSet = "DeerBleat_SoundSet";
303 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
304
305 //Goat sounds
306 soundSet = "GoatBleat_A_SoundSet";
307 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
308 soundSet = "GoatBleat_B_SoundSet";
309 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
310
311 //Hare sounds
312 soundSet = "HareChirp_SoundSet";
313 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
314 soundSet = "HareSquawk_SoundSet";
315 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
316
317 //Hen sounds
318 soundSet = "HenCluck_X_SoundSet";
319 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
320 soundSet = "HenScream_SoundSet";
321 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
322
323 //Hog sounds
324 soundSet = "HogGrunt_G_SoundSet";
325 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
326 soundSet = "HogSqueal_SoundSet";
327 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
328
329 //Sheep sounds
330 soundSet = "SheepBleat_G_SoundSet";
331 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
332 soundSet = "SheepBleat_E_SoundSet";
333 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
334
335 //Wolf sounds
336 soundSet = "WolfBark_SoundSet";
337 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
338 soundSet = "WolfWhimper_SoundSet";
339 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
340
341 //Zmb F sounds
342 soundSet = "ZmbF_Normal_CallToArmsShort_Soundset";
343 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
344 soundSet = "ZmbF_Normal_HeavyHit_Soundset";
345 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
346
347 //Zmb M sounds
348 soundSet = "ZmbM_Normal_CallToArmsShort_Soundset";
349 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
350 soundSet = "ZmbM_Normal_HeavyHit_Soundset";
351 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
352
353 //Bear sounds
354 soundSet = "BearRoarShort_SoundSet";
355 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
356 soundSet = "BearSnarl_SoundSet";
357 m_CreatureSoundMap.Insert(soundSet.Hash(), soundSet);
358 }
359
360
361 // ------------------------------
362 // STORAGE SAVING AND LOADING
363 // ------------------------------
365 {
366 super.OnStoreSave(ctx);
367
368 ctx.Write(m_CaptureState);
369 ctx.Write(m_CreatureType);
370 ctx.Write(m_ParScale);
371 ctx.Write(m_DangerSound);
372 ctx.Write(m_CaptureSoundHash);
373 ctx.Write(m_ReleaseSoundHash);
374 }
375
376 override bool OnStoreLoad(ParamsReadContext ctx, int version)
377 {
378 if (!super.OnStoreLoad(ctx, version))
379 return false;
380
381 if (!ctx.Read(m_CaptureState))
382 return false;
383
384 if (!ctx.Read(m_CreatureType))
385 return false;
386
387 if (!ctx.Read(m_ParScale))
388 return false;
389
390 if (!ctx.Read(m_DangerSound))
391 return false;
392
393 if (!ctx.Read(m_CaptureSoundHash))
394 return false;
395
396 if (!ctx.Read(m_ReleaseSoundHash))
397 return false;
398
399 return true;
400 }
401
402 //Protection against dupers during 1.12
403 private void DestroyEg()
404 {
405 Delete();
406 }
407};
void RegisterSoundSetMap()
Definition EasterEgg.c:287
void ~EasterEgg()
Definition EasterEgg.c:52
eCaptureState
Definition EasterEgg.c:2
@ CAPTURE
Definition EasterEgg.c:3
@ RELEASEFX
Definition EasterEgg.c:7
@ STASIS
Definition EasterEgg.c:5
@ RELEASE
Definition EasterEgg.c:4
@ END
Definition EasterEgg.c:10
@ CAPTUREFX
Definition EasterEgg.c:6
EffectSound m_CreatureSound
Definition EasterEgg.c:29
string m_CreatureType
Definition EasterEgg.c:17
void PlayVFX()
Definition EasterEgg.c:210
void Release(vector pos)
Definition EasterEgg.c:183
void ResizeParticle(DayZCreatureAI capAnimal)
Definition EasterEgg.c:226
int m_CaptureState
Definition EasterEgg.c:19
float m_ParScale
Definition EasterEgg.c:24
override void EOnTouch(IEntity other, int extra)
Definition EasterEgg.c:106
void ContactEvent(IEntity other, vector pos)
Definition EasterEgg.c:61
int m_ReleaseSoundHash
Definition EasterEgg.c:34
void EasterEgg()
Definition EasterEgg.c:37
ref map< int, string > m_CreatureSoundMap
Definition EasterEgg.c:32
void Capture(DayZCreatureAI capAnimal)
Definition EasterEgg.c:155
void DestroyEg()
Definition EasterEgg.c:403
const vector CAPTURE_VELOCITY
Definition EasterEgg.c:20
void PlaySFX(int releaseCase=eCaptureState.CAPTURE)
Definition EasterEgg.c:237
bool m_DangerSound
Definition EasterEgg.c:30
Particle m_ParCapture
Definition EasterEgg.c:23
enum eCaptureState m_StoredCreature
const float PARTICLE_SCALE_MULT
Definition EasterEgg.c:25
EffectSound m_CaptureSound
Definition EasterEgg.c:28
int m_CaptureSoundHash
Definition EasterEgg.c:33
int m_CreatureHash
Definition EasterEgg.c:18
bool SetQuantity(float value, bool destroy_config=true, bool destroy_forced=false, bool allow_client=false, bool clamp_to_stack_max=true)
Set item quantity[related to varQuantity... config entry], destroy_config = true > if the quantity re...
Definition ItemBase.c:7838
int GetQuantityMin()
Definition ItemBase.c:7979
void OnInventoryEnter(Man player)
Event called on item when it is placed in the player(Man) inventory, passes the owner as a parameter.
Definition ItemBase.c:8449
void OnInventoryExit(Man player)
Event called on item when it is removed from the player(Man) inventory, passes the old owner as a par...
Definition ItemBase.c:8462
override void EOnContact(IEntity other, Contact extra)
Definition ItemBase.c:5827
override int GetQuantityMax()
Definition ItemBase.c:7941
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
class JsonUndergroundAreaTriggerData GetPosition
do not process rotations !
Definition DayZAnimal.c:573
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition HescoBox.c:191
override void OnVariablesSynchronized()
Definition HescoBox.c:45
override void OnStoreSave(ParamsWriteContext ctx)
Definition HescoBox.c:183
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
Definition HescoBox.c:128
InventoryLocation.
Legacy way of using particles in the game.
Definition Particle.c:7
void SetWiggle(float random_angle, float random_interval)
Makes the particle change direction by random_angle every random_interval seconds.
Definition Particle.c:742
void SetParameter(int emitter, int parameter, float value)
Set the value of a parameter of an emitor in the particle.
Definition Particle.c:603
void Stop()
Legacy function for backwards compatibility with 1.14 and below.
Definition Particle.c:262
static const int EASTER_EGG_ACTIVATE
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
proto native CGame GetGame()
proto native void SetFlags(ShapeFlags flags)
EntityEvent
Entity events for event-mask, or throwing event from code.
Definition EnEntity.c:44
EntityFlags
Entity flags.
Definition EnEntity.c:114
EmitorParam
Definition EnVisual.c:114
proto native void SetVelocity(notnull IEntity ent, vector vel)
Sets linear velocity (for Rigid bodies)
proto native int Hash()
Returns hash of string.