Dayz Explorer 1.28.160049
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
49 RegisterSoundSetMap();
50 }
51
53 {
54 if ( m_ParCapture )
56 }
57
58 // ------------------------------
59 // CORE EXECUTION DEPENDING ON CURRENT STATE
60 // ------------------------------
61 void ContactEvent( IEntity other, vector pos )
62 {
63 switch ( m_CaptureState )
64 {
65 case eCaptureState.CAPTURE:
66 DayZCreatureAI capAnimal = DayZCreatureAI.Cast( other );
67 if ( capAnimal && capAnimal.IsAlive() )
68 {
69 if ( GetGame().IsServer() )
70 Capture( capAnimal );
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
89 m_CaptureState = eCaptureState.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 {
108 ContactEvent( other, GetPosition() );
109 }
110
111 //Used for release
112 override void EOnContact( IEntity other, Contact extra )
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
120 PlayerBase player_PB = PlayerBase.Cast( player );
121 if ( player_PB && player_PB.GetThrowing().IsThrowingAnimationPlaying() )
122 {
123 if ( m_CreatureType != "" )
124 m_CaptureState = eCaptureState.RELEASE;
125 else
126 m_CaptureState = eCaptureState.CAPTURE;
127 }
128 else
129 {
130 m_CaptureState = eCaptureState.STASIS;
131 }
132
133 //Make sure state is properly synchronized or VFX might bug out
134 SetSynchDirty();
135 }
136
137 override void OnInventoryEnter( Man player )
138 {
139 //Make sure to stop particles once in inventory
140 if ( GetGame().IsClient() && m_ParCapture )
141 {
143 m_ParCapture.Delete();
144 }
145 }
146
147 override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
148 {
149 super.EEItemLocationChanged(oldLoc, newLoc);
150
151 //DestroyEg();
152 }
153
154 // ------------------------------
155 // CAPTURE AND RELEASE LOGIC
156 // ------------------------------
157 private void Capture( DayZCreatureAI capAnimal )
158 {
159 if ( !IsAlive() )
160 {
161 if ( m_ParCapture )
162 m_ParCapture.Delete();
163 Delete();
164 return;
165 }
166
167 m_StoredCreature = capAnimal;
168 m_CreatureType = m_StoredCreature.GetType();
169 m_CreatureHash = m_CreatureType.Hash();
170 m_CaptureState = eCaptureState.CAPTUREFX;
171 m_DangerSound = m_StoredCreature.IsDanger();
172 m_CaptureSoundHash = m_StoredCreature.CaptureSound().Hash();
173 m_ReleaseSoundHash = m_StoredCreature.ReleaseSound().Hash();
174
175 //Resize particle upon capture as there is enough delay to be sure value is synced
176 ResizeParticle( capAnimal );
177
178 SetSynchDirty();
179
180 capAnimal.Delete();
182 SetVelocity( this, CAPTURE_VELOCITY );
183 }
184
185 private void Release( vector pos )
186 {
187 if ( GetGame().IsServer() )
188 {
189 m_CaptureState = eCaptureState.RELEASEFX;
190 m_CreatureHash = 0;
191 SetSynchDirty();
192
193 GetGame().CreateObject( m_CreatureType, pos, false, true );
194 m_CreatureType = "";
195
196 DecreaseHealth( "", "", GetMaxHealth() * 0.4 );
197 SetQuantity( GetQuantityMin(), false );
198 SetVelocity( this, CAPTURE_VELOCITY );
199
200 if ( !IsAlive() )
201 {
202 if ( m_ParCapture )
203 m_ParCapture.Delete();
204 Delete();
205 }
206 }
207 }
208
209 // ------------------------------
210 // CAPTURE AND RELEASE EFFECTS
211 // ------------------------------
212 private void PlayVFX()
213 {
214 if ( !GetGame().IsDedicatedServer() )
215 {
216 if ( !m_ParCapture && m_CaptureState != eCaptureState.STASIS )
217 {
218 //Ideally play a one time effect such as an explosion
219 m_ParCapture = ParticleManager.GetInstance().PlayInWorld( ParticleList.EASTER_EGG_ACTIVATE, GetPosition() );
220
221 //Resize, -1 signifies ALL emitors
222 m_ParCapture.SetParameter( -1, EmitorParam.SIZE, m_ParScale );
223 m_ParCapture.SetWiggle( 7, 0.3 );
224 }
225 }
226 }
227
228 private void ResizeParticle( DayZCreatureAI capAnimal )
229 {
230 //Determine particle scale depending on captured animal scale
231 vector mins, maxs;
232 capAnimal.GetWorldBounds( mins, maxs );
233 m_ParScale = vector.DistanceSq( mins, maxs );
234
235 //Multiply to rescale down as fed values can be really large
236 m_ParScale *= PARTICLE_SCALE_MULT;
237 }
238
239 private void PlaySFX( int releaseCase = eCaptureState.CAPTURE )
240 {
241 if ( !GetGame().IsDedicatedServer() )
242 {
243 string soundSet = "";
244 if ( releaseCase == eCaptureState.CAPTURE )
245 {
246 PlaySoundSet( m_CaptureSound, "EasterEgg_Catch_SoundSet", 0, 0 );
247
248 m_CreatureSoundMap.Find( m_CaptureSoundHash, soundSet );
249 PlaySoundSet( m_CreatureSound, soundSet, 0, 0 );
250 }
251 else
252 {
253 if ( !m_DangerSound )
254 {
255 PlaySoundSet( m_CaptureSound, "EasterEgg_Spawn_SoundSet", 0, 0 );
256
257 m_CreatureSoundMap.Find( m_ReleaseSoundHash, soundSet );
258 PlaySoundSet( m_CreatureSound, soundSet, 0, 0 );
259 }
260 else
261 {
262 PlaySoundSet( m_CaptureSound, "EasterEgg_Spawn_Danger_SoundSet", 0, 0 );
263
264 m_CreatureSoundMap.Find( m_ReleaseSoundHash, soundSet );
265 PlaySoundSet( m_CreatureSound, soundSet, 0, 0 );
266 }
267 }
268 }
269 }
270
271
272 override void OnVariablesSynchronized()
273 {
274 if ( m_CaptureState == eCaptureState.CAPTUREFX )
275 {
276 PlayVFX();
277 PlaySFX();
278 }
279 else if ( m_CaptureState == eCaptureState.RELEASEFX )
280 {
281 PlayVFX();
282 PlaySFX( eCaptureState.RELEASE );
283 }
284 }
285
286 // ------------------------------
287 // SOUNDSET MAP REGISTRATION
288 // ------------------------------
289 void RegisterSoundSetMap()
290 {
291 //Register all possible creature sounds in map with their respective hash
292 string soundSet;
294
295 //Cow sounds
296 soundSet = "CattleMooA_SoundSet";
297 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
298 soundSet = "CattleBellow_SoundSet";
299 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
300
301 //Deer sounds
302 soundSet = "DeerRoar_SoundSet";
303 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
304 soundSet = "DeerBleat_SoundSet";
305 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
306
307 //Goat sounds
308 soundSet = "GoatBleat_A_SoundSet";
309 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
310 soundSet = "GoatBleat_B_SoundSet";
311 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
312
313 //Hare sounds
314 soundSet = "HareChirp_SoundSet";
315 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
316 soundSet = "HareSquawk_SoundSet";
317 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
318
319 //Hen sounds
320 soundSet = "HenCluck_X_SoundSet";
321 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
322 soundSet = "HenScream_SoundSet";
323 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
324
325 //Hog sounds
326 soundSet = "HogGrunt_G_SoundSet";
327 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
328 soundSet = "HogSqueal_SoundSet";
329 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
330
331 //Sheep sounds
332 soundSet = "SheepBleat_G_SoundSet";
333 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
334 soundSet = "SheepBleat_E_SoundSet";
335 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
336
337 //Wolf sounds
338 soundSet = "WolfBark_SoundSet";
339 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
340 soundSet = "WolfWhimper_SoundSet";
341 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
342
343 //Zmb F sounds
344 soundSet = "ZmbF_Normal_CallToArmsShort_Soundset";
345 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
346 soundSet = "ZmbF_Normal_HeavyHit_Soundset";
347 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
348
349 //Zmb M sounds
350 soundSet = "ZmbM_Normal_CallToArmsShort_Soundset";
351 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
352 soundSet = "ZmbM_Normal_HeavyHit_Soundset";
353 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
354
355 //Bear sounds
356 soundSet = "BearRoarShort_SoundSet";
357 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
358 soundSet = "BearSnarl_SoundSet";
359 m_CreatureSoundMap.Insert( soundSet.Hash(), soundSet );
360 }
361
362
363 // ------------------------------
364 // STORAGE SAVING AND LOADING
365 // ------------------------------
366 override void OnStoreSave( ParamsWriteContext ctx )
367 {
368 super.OnStoreSave( ctx );
369
370 ctx.Write( m_CaptureState );
371 ctx.Write( m_CreatureType );
372 ctx.Write( m_ParScale );
373 ctx.Write( m_DangerSound );
374 ctx.Write( m_CaptureSoundHash );
375 ctx.Write( m_ReleaseSoundHash );
376 }
377
378 override bool OnStoreLoad( ParamsReadContext ctx, int version )
379 {
380 if ( !super.OnStoreLoad( ctx, version ) )
381 return false;
382
383 if ( !ctx.Read( m_CaptureState ) )
384 return false;
385
386 if ( !ctx.Read( m_CreatureType ) )
387 return false;
388
389 if ( !ctx.Read( m_ParScale ) )
390 return false;
391
392 if ( !ctx.Read( m_DangerSound ) )
393 return false;
394
395 if ( !ctx.Read( m_CaptureSoundHash ) )
396 return false;
397
398 if ( !ctx.Read( m_ReleaseSoundHash ) )
399 return false;
400
401 return true;
402 }
403
404 //Protection against dupers during 1.12
405 private void DestroyEg()
406 {
407 Delete();
408 }
409};
do not process rotations !
Definition dayzanimal.c:654
Wrapper class for managing sound through SEffectManager.
Definition effectsound.c:5
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition hescobox.c:180
override void OnVariablesSynchronized()
Definition hescobox.c:39
override void OnStoreSave(ParamsWriteContext ctx)
Definition hescobox.c:172
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
Definition hescobox.c:117
InventoryLocation.
Legacy way of using particles in the game.
Definition particle.c:7
static Particle PlayInWorld(int particle_id, vector global_pos)
Creates a particle emitter on the given position and activates it.
Definition particle.c:174
void Stop()
Legacy function for backwards compatibility with 1.14 and below.
Definition particle.c:266
Serialization general interface. Serializer API works with:
Definition serializer.c:56
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
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
bool m_DangerSound
Definition easteregg.c:30
Particle m_ParCapture
Definition easteregg.c:23
enum eCaptureState m_StoredCreature
EffectSound m_CaptureSound
Definition easteregg.c:28
int m_CaptureSoundHash
Definition easteregg.c:33
proto native CGame GetGame()
proto native void SetFlags(ShapeFlags flags)
EntityEvent
Entity events for event-mask, or throwing event from code.
Definition enentity.c:45
EntityFlags
Entity flags.
Definition enentity.c:115
EmitorParam
Definition envisual.c:114
proto native void SetVelocity(notnull IEntity ent, vector vel)
Sets linear velocity (for Rigid bodies)
class JsonUndergroundAreaTriggerData GetPosition
override 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:8148
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:8708
override int GetQuantityMin()
Definition itembase.c:8280
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:8721
override int GetQuantityMax()
Definition itembase.c:8248
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)