Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
easteregg.c
Go to the documentation of this file.
2 {
3  CAPTURE = 0,
4  RELEASE = 1,
5  STASIS = 2,
6  CAPTUREFX = 3,
7  RELEASEFX = 4,
8 
9  //Keep this last value at the end, add any new states before
11 }
12 
14 {
15  //Capture parameters
16  private DayZCreatureAI m_StoredCreature = null;
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 
52  void ~EasterEgg()
53  {
54  if ( m_ParCapture )
55  m_ParCapture.Stop();
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
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  {
142  m_ParCapture.Stop();
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();
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
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  // ------------------------------
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 };
m_DangerSound
protected bool m_DangerSound
Definition: easteregg.c:30
DestroyEg
private void DestroyEg()
Definition: easteregg.c:405
GetGame
proto native CGame GetGame()
Release
private void Release(vector pos)
Definition: easteregg.c:185
m_CaptureSound
protected EffectSound m_CaptureSound
Definition: easteregg.c:28
SetQuantity
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:3159
SetVelocity
proto native void SetVelocity(notnull IEntity ent, vector vel)
Sets linear velocity (for Rigid bodies)
Particle
Legacy way of using particles in the game.
Definition: particle.c:6
EntityFlags
EntityFlags
Entity flags.
Definition: enentity.c:114
RELEASE
@ RELEASE
Definition: easteregg.c:4
m_CaptureState
private int m_CaptureState
Definition: easteregg.c:19
OnInventoryExit
override void OnInventoryExit(Man player)
Definition: easteregg.c:117
OnStoreSave
override void OnStoreSave(ParamsWriteContext ctx)
Definition: easteregg.c:366
CAPTUREFX
@ CAPTUREFX
Definition: easteregg.c:6
~EasterEgg
void ~EasterEgg()
Definition: easteregg.c:52
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
GetQuantityMax
override int GetQuantityMax()
Definition: itembase.c:3262
m_CaptureSoundHash
protected int m_CaptureSoundHash
Definition: easteregg.c:33
OnInventoryEnter
override void OnInventoryEnter(Man player)
Definition: easteregg.c:137
DayZCreatureAI
do not process rotations !
Definition: dayzanimal.c:606
EmitorParam
EmitorParam
Definition: envisual.c:113
IEntity
Definition: enentity.c:164
m_CreatureHash
private int m_CreatureHash
Definition: easteregg.c:18
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
PARTICLE_SCALE_MULT
const private float PARTICLE_SCALE_MULT
Definition: easteregg.c:25
EOnContact
override void EOnContact(IEntity other, Contact extra)
Definition: easteregg.c:112
OnStoreLoad
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition: easteregg.c:378
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
EffectSound
Wrapper class for managing sound through SEffectManager.
Definition: effectsound.c:4
ParticleList
Definition: particlelist.c:11
Capture
private void Capture(DayZCreatureAI capAnimal)
Definition: easteregg.c:157
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
vector
Definition: enconvert.c:105
PlayVFX
private void PlayVFX()
Definition: easteregg.c:212
RELEASEFX
@ RELEASEFX
Definition: easteregg.c:7
END
@ END
Definition: easteregg.c:10
EasterEgg
void EasterEgg()
Definition: easteregg.c:37
m_CreatureType
private string m_CreatureType
Definition: easteregg.c:17
m_CreatureSound
protected EffectSound m_CreatureSound
Definition: easteregg.c:29
Contact
Definition: enphysics.c:300
m_ParScale
private float m_ParScale
Definition: easteregg.c:24
SetFlags
proto native void SetFlags(ShapeFlags flags)
ContactEvent
void ContactEvent(IEntity other, vector pos)
Definition: easteregg.c:61
EEItemLocationChanged
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
Definition: easteregg.c:147
OnVariablesSynchronized
override void OnVariablesSynchronized()
Definition: easteregg.c:272
m_StoredCreature
enum eCaptureState m_StoredCreature
EOnTouch
override void EOnTouch(IEntity other, int extra)
Definition: easteregg.c:106
RegisterSoundSetMap
void RegisterSoundSetMap()
Definition: easteregg.c:289
CAPTURE
@ CAPTURE
Definition: easteregg.c:3
m_CreatureSoundMap
protected ref map< int, string > m_CreatureSoundMap
Definition: easteregg.c:32
m_ReleaseSoundHash
protected int m_ReleaseSoundHash
Definition: easteregg.c:34
Inventory_Base
Definition: barbedbaseballbat.c:1
eCaptureState
eCaptureState
Definition: easteregg.c:1
ParticleManager
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Definition: particlemanager.c:84
EntityEvent
EntityEvent
Entity events for event-mask, or throwing event from code.
Definition: enentity.c:44
GetQuantityMin
int GetQuantityMin()
Definition: itembase.c:3300
PlaySFX
private void PlaySFX(int releaseCase=eCaptureState.CAPTURE)
Definition: easteregg.c:239
ResizeParticle
private void ResizeParticle(DayZCreatureAI capAnimal)
Definition: easteregg.c:228
m_ParCapture
protected Particle m_ParCapture
Definition: easteregg.c:23
STASIS
@ STASIS
Definition: easteregg.c:5
CAPTURE_VELOCITY
const private vector CAPTURE_VELOCITY
Definition: easteregg.c:20