DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
EasterEgg.c
См. документацию.
2{
3 CAPTURE = 0,
4 RELEASE = 1,
5 STASIS = 2,
8
9 //Keep this last value at the end, add any new states before
11}
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 )
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 != "" )
125 else
127 }
128 else
129 {
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;
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();
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 );
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
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
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 );
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};
map
Определения ControlsXboxNew.c:4
void RegisterSoundSetMap()
Определения EasterEgg.c:289
void ~EasterEgg()
Определения EasterEgg.c:52
eCaptureState
Определения EasterEgg.c:2
@ CAPTURE
Определения EasterEgg.c:3
@ RELEASEFX
Определения EasterEgg.c:7
@ STASIS
Определения EasterEgg.c:5
@ RELEASE
Определения EasterEgg.c:4
@ CAPTUREFX
Определения EasterEgg.c:6
EffectSound m_CreatureSound
Определения EasterEgg.c:29
string m_CreatureType
Определения EasterEgg.c:17
void PlayVFX()
Определения EasterEgg.c:212
void Release(vector pos)
Определения EasterEgg.c:185
void ResizeParticle(DayZCreatureAI capAnimal)
Определения EasterEgg.c:228
int m_CaptureState
Определения EasterEgg.c:19
float m_ParScale
Определения EasterEgg.c:24
override void EOnTouch(IEntity other, int extra)
Определения EasterEgg.c:106
void ContactEvent(IEntity other, vector pos)
Определения EasterEgg.c:61
int m_ReleaseSoundHash
Определения EasterEgg.c:34
void EasterEgg()
Определения EasterEgg.c:37
ref map< int, string > m_CreatureSoundMap
Определения EasterEgg.c:32
void Capture(DayZCreatureAI capAnimal)
Определения EasterEgg.c:157
void DestroyEg()
Определения EasterEgg.c:405
const vector CAPTURE_VELOCITY
Определения EasterEgg.c:20
void PlaySFX(int releaseCase=eCaptureState.CAPTURE)
Определения EasterEgg.c:239
bool m_DangerSound
Определения EasterEgg.c:30
Particle m_ParCapture
Определения EasterEgg.c:23
enum eCaptureState m_StoredCreature
const float PARTICLE_SCALE_MULT
Определения EasterEgg.c:25
EffectSound m_CaptureSound
Определения EasterEgg.c:28
int m_CaptureSoundHash
Определения EasterEgg.c:33
int m_CreatureHash
Определения EasterEgg.c:18
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...
Определения ItemBase.c:8006
void OnInventoryEnter(Man player)
Event called on item when it is placed in the player(Man) inventory, passes the owner as a parameter.
Определения ItemBase.c:8566
override int GetQuantityMin()
Определения ItemBase.c:8138
void OnInventoryExit(Man player)
Event called on item when it is removed from the player(Man) inventory, passes the old owner as a par...
Определения ItemBase.c:8579
override void EOnContact(IEntity other, Contact extra)
Определения ItemBase.c:5943
override int GetQuantityMax()
Определения ItemBase.c:8106
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Определения ParticleManager.c:88
@ END
Определения SmokeGrenadeBase.c:6
proto native Object CreateObject(string type, vector pos, bool create_local=false, bool init_ai=false, bool create_physics=true)
Creates object of certain type.
Определения EnPhysics.c:305
do not process rotations !
Определения DayZAnimal.c:612
Wrapper class for managing sound through SEffectManager.
Определения EffectSound.c:5
Определения EnEntity.c:165
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Определения HescoBox.c:180
override void OnVariablesSynchronized()
Определения HescoBox.c:39
override void OnStoreSave(ParamsWriteContext ctx)
Определения HescoBox.c:172
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
Определения HescoBox.c:117
InventoryLocation.
Определения InventoryLocation.c:29
Legacy way of using particles in the game.
Определения Particle.c:7
static const int EASTER_EGG_ACTIVATE
Определения ParticleList.c:142
Определения ParticleList.c:12
Определения PlayerBaseClient.c:2
proto bool Write(void value_out)
proto bool Read(void value_in)
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
Определения EnConvert.c:106
Serializer ParamsReadContext
Определения gameplay.c:15
proto native CGame GetGame()
Serializer ParamsWriteContext
Определения gameplay.c:16
vector Position
Определения EnPhysics.c:323
proto native void SetFlags(ShapeFlags flags)
EntityEvent
Entity events for event-mask, or throwing event from code.
Определения EnEntity.c:45
EntityFlags
Entity flags.
Определения EnEntity.c:115
EmitorParam
Определения EnVisual.c:114
proto native void SetVelocity(notnull IEntity ent, vector vel)
Sets linear velocity (for Rigid bodies)
class JsonUndergroundAreaTriggerData GetPosition
Определения UndergroundAreaLoader.c:9
proto native int Hash()
Returns hash of string.