DayZ 1.24
Loading...
Searching...
No Matches
FireworksLauncher.c
Go to the documentation of this file.
2{
4 {
5 SetVisibleDuringDaylight(true);
6 SetRadiusTo(60);
7 SetBrightnessTo(0.05);
8 SetFlareVisible(false);
9 SetAmbientColor(1.0, 1.0, 1.0);
10 SetDiffuseColor(1.0, 1.0, 1.0);
11 SetLifetime(2.1);
12 //SetDisableShadowsWithinRadius(-1);
13 SetFadeOutTime(1);
14 m_FadeInTime = 0.25;
15 SetFlickerSpeed(7);
16 //SetFlickerAmplitude(0.5);
17 SetFlickerAmplitudeMax(3);
18 SetFlickerAmplitudeMin(0);
19 SetCastShadow(false);
20 }
21}
22//-----------------------------------------------------------------------------------------------
23class FireworksLauncherClientEventBase
24{
25 void OnFired();
26}
27//-----------------------------------------------------------------------------------------------
28class FireworksLauncherClientEvent : FireworksLauncherClientEventBase
29{
30 protected ref Timer m_Timer = new Timer();
32 protected int m_Index;
38 protected vector m_ShotDir;
41 protected string m_Color;
44#ifdef DEVELOPER
46#endif
47
48
49 // -----------------------------
50 // ------- Tweaking Start-------
51 // -----------------------------
52
53 protected int GetSoundDelay()
54 {
55 return 0;
56 }
57
58 protected int GetLightDelay()
59 {
60 return 0;
61 }
62
63 protected float GetExplosionDistance()
64 {
65 return Math.RandomFloatInclusive(35, 40);
66 }
67
68 protected float GetShotDispersionAngle()
69 {
70 return Math.RandomFloatInclusive(-25, 25); //this is rotated 360 degrees around the UP vector too
71 }
72
73 protected string GetExplosionSoundSet()
74 {
75 return "FireworksLauncher_Explosion_SoundSet";
76 }
77
78 protected float GetExplosionDelay()
79 {
80 return Math.RandomFloatInclusive(1.5, 1.75);
81 }
82
83 // -----------------------------
84 // ------- Tweaking End --------
85 // -----------------------------
86
87
89 {
90 m_Item = item;
91 m_Index = index;
92
94 int coloreSequenceIndex = m_Index - 1;//shot index(m_Index) starts at 1
95
98 else
99 {
100 Debug.LogError("Failed to obtain color from color sequence");
101 m_Color = "B";
102 }
103 }
104
112
113 override protected void OnFired()
114 {
115 m_Timer.Run(GetExplosionDelay(), this, "OnExplode", null);
116 m_Item.PlaySoundSet(m_FireSound, "FireworksLauncher_Shot_SoundSet", 0, 0);
119
123 m_ShotDir = m_ParticleShot.GetDirectionUp();
124
125#ifdef DEVELOPER
126 vector pts[2];
127 pts[0] = GetShotPos();
129 //m_ShotTrajectory = Shape.CreateLines(COLOR_RED, ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE|ShapeFlags.NOZBUFFER, pts, 2);
130#endif
131 }
132
133 protected vector GetShotPos()
134 {
136 string memName = "Shot_" + m_Index;
137
138 if (m_Item.MemoryPointExists(memName))
139 {
140 memPos = m_Item.GetMemoryPointPos(memName);
141 memPos = m_Item.ModelToWorld(memPos);
142 }
143 else
144 {
145 memPos = m_Item.GetPosition();//fallback to item's location
146 Debug.LogError("Missing shot memory point on Fireworks");
147 }
148 return memPos;
149 }
150
155
157 {
158 if (!m_ExplosionPos)
160 return m_ExplosionPos;
161 }
162
164 {
165 return 4;
166 }
167
168
169 protected void OnExplode()
170 {
171#ifdef DEVELOPER
173 {
174 m_ShotTrajectory.Destroy();
176 }
177#endif
179
180 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(PlayExplosionSound, GetSoundDelay(), false);
181 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(SpawnLight, GetLightDelay(), false);
183
185
186 }
187
189 {
190 if (m_RemainingExplosions > 0)
191 {
194 }
195 }
196
205
207 {
208 return Math.RandomIntInclusive(100, 250);
209 }
210
212 {
213 switch (m_Color)
214 {
215 case "R":
217 case "G":
219 case "B":
221 case "Y":
223 case "P":
225 default:
226 ErrorEx("Incorrect explosion particle color in the sequence");
227 }
229 }
230
232 {
233 switch (m_Color)
234 {
235 case "R":
236 light.SetDiffuseColor(255, 51, 51);
237 light.SetAmbientColor(255, 51, 51);
238
239 break;
240 case "G":
241 light.SetDiffuseColor(0, 255, 128);
242 light.SetAmbientColor(0, 255, 128);
243 break;
244 case "B":
245 light.SetDiffuseColor(51, 153, 255);
246 light.SetAmbientColor(51, 153, 255);
247 break;
248 case "Y":
249 light.SetDiffuseColor(255, 255, 51);
250 light.SetAmbientColor(255, 255, 51);
251 break;
252 case "P":
253 light.SetDiffuseColor(255, 102, 255);
254 light.SetAmbientColor(255, 102, 255);
255 break;
256 default:
257 ErrorEx("Incorrect explosion particle color in the sequence");
258 }
259 }
260
266
267 protected void PlayExplosionSound()
268 {
269 if (m_FireSound)
271 m_Item.PlaySoundSet(m_ExplosionSound, GetExplosionSoundSet(), 0, 0);
272 }
273}
274//------------------------------------------------------------------------------------
275
277{
278 protected vector m_ShotPos;
279
280 override protected vector GetExplosionPosition()
281 {
282 return GetShotPos() + m_ShotDir * GetExplosionDistance();
283 }
284
285 void Init(vector pos)
286 {
287 m_ShotPos = pos;
288 m_ShotDir[0] = Math.RandomFloatInclusive(-1, 1);
289 m_ShotDir[1] = Math.RandomFloatInclusive(-1, 1);
290 m_ShotDir[2] = Math.RandomFloatInclusive(-1, 1);
291 m_ShotDir.Normalize();
292 }
293 override protected vector GetShotPos()
294 {
295 return m_ShotPos;
296 }
297
298 override protected float GetExplosionDistance()
299 {
300 return Math.RandomFloatInclusive(10, 15);
301 }
302
303 override void OnExplode()
304 {
305 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(PlayExplosionSound, GetSoundDelay(), false);
306 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(SpawnLight, GetLightDelay(), false);
307 m_ParticleExplosion = ParticleManager.GetInstance().PlayInWorld(GetExplParticleFromSequence(), GetExplosionPosition());
308 }
309}
310
311class FireworksLauncher: FireworksBase
312{
313 int m_Index;//counts the shots
314 int m_IndexPrev;//counts the shots
323
325 {
328 RegisterNetSyncVariableInt("m_State", 0, EnumTools.GetLastEnumValue(EFireworksState));
329 RegisterNetSyncVariableInt("m_Index", 0, GetMaxShots());
330 RegisterNetSyncVariableInt("m_RandomSeed", 0, 1023);
331 int lastIndex = m_ColorSequence.Count() - 1;
332 RegisterNetSyncVariableInt("m_ColorSequenceIndex", 0, lastIndex);
333 m_RandomSeed = Math.RandomInt(0, 1023);
335 }
336
342
343 override protected bool UsesGlobalDeploy()
344 {
345 return true;
346 }
347
348 override bool IsDeployable()
349 {
350 return true;
351 }
352
354 override float GetDeployTime()
355 {
356 return 2;
357 }
358
359 protected void SetupColorSequences()
360 {
361 m_ColorSequence.Insert("RGBYPBRGBRGBYPBRGBRGBYPBRGBPBRGBRGBY");
362 m_ColorSequence.Insert("PGPYPBYPYPBYYPBRPYPBYYPBRGBPBRGRGBRB");
363 m_ColorSequence.Insert("YPBRPYPBYYPBRGBPBRGRGBRBGRPBRGBRYPBY");
364 m_ColorSequence.Insert("YRBGPRYPGRYBGRGRGBRBBYPYPBYRYPGRYGRP");
365 m_ColorSequence.Insert("BGRYPYRPBYYPYRBGPRYPGBYPBRGBPBRGBRGB");
366 m_ColorSequence.Insert("RYGRPBRGBYPBRRPBRGBBRBBYPYPRGBRGBRPY");
367 m_ColorSequence.Insert("GBRGBYRGBYPBRRPBRBYRYPGPYPRGBRGBRPYG");
368 m_ColorSequence.Insert("RYPBYYPBRGBYPBRGBRBGBPBRGRGBRBGRYPYR");
369 m_ColorSequence.Insert("PBRGBYPBRGBRBGBPBRGRGBRBGRYPYRRYPBYY");
370 m_ColorSequence.Insert("RGRGBRBBYPYPBYRYPGRYGRPYRBGPRYPGRYBG");
371 m_ColorSequence.Insert("RBYRYPGPYPRGBRGBRPYGGBRGBYRGBYPBRRPB");
372 m_ColorSequence.Insert("PRGBRGBRPYGGBRRBYRYPGPYGBYRGBYPBRRPB");
373 }
374
376 {
377 if (m_ColorSequence.IsValidIndex(m_ColorSequenceIndex))
379 else
380 {
381 ErrorEx("Failed to obtain color sequence");
382 return "RYPBYYPBRGBYPBRGBRBGBPBRGRGBRBGRYPYR";
383 }
384 }
385
386
387 override protected void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
388 {
389 super.OnPlacementComplete(player, position, orientation);
390 if (GetGame().IsServer())
391 {
392 if (GetState() == EFireworksState.DEFAULT)
394 }
395 }
396
397 override protected float GetMaxAllowedWetness()
398 {
400 }
401
402
403 override protected float GetEventDelay()
404 {
405 return Math.RandomFloatInclusive(3, 3.35);
406 }
407
408 protected string GetFuseSoundSet()
409 {
410 return "FireworksLauncher_Ignition_Loop_SoundSet";
411 }
412
413 protected int GetMaxShots()
414 {
415 return 16;
416 }
417
418 protected float GetFuseDelay()
419 {
420 return 3;
421 }
422
423 protected string GetAmmoType()
424 {
425 return "Fireworks_Ammo";
426 }
427
428 protected int GetDamageType()
429 {
430 return DamageType.EXPLOSION;
431 }
432
433
434 override protected void OnStateChangedServer(EFireworksState currentState)
435 {
436 switch (currentState)
437 {
438 case EFireworksState.PLACED:
439 break
440 case EFireworksState.IGNITED:
442 break
443 case EFireworksState.FIRING:
444 HideSelection("cover");
446 break
447 case EFireworksState.FINISHED:
448 HideSelection("cover");//when loading from storage
449 break
450 default: {};
451 }
452 }
453
454 override protected void OnStateChangedClient(EFireworksState currentState)
455 {
456 switch (currentState)
457 {
458 case EFireworksState.IGNITED:
460 break
461 case EFireworksState.PLACED:
462 break
463 case EFireworksState.FIRING:
465 break
466 default: {};
467 }
468 }
469
472 {
473 super.OnIgnitedThis(fire_source);
474 if (m_Events)
475 m_Events.Clear();
476 m_Index = 0;
477
478 if (m_TimerEvent)
479 m_TimerEvent.Stop();
480 }
481
482 override protected bool CanPutInCargo(EntityAI parent)
483 {
484 return (GetState() == EFireworksState.DEFAULT || (GetState() == EFireworksState.PLACED) || (GetState() == EFireworksState.FINISHED);
485 }
486
487 override protected bool CanPutIntoHands(EntityAI parent)
488 {
489 return (GetState() == EFireworksState.DEFAULT || (GetState() == EFireworksState.PLACED) || (GetState() == EFireworksState.FINISHED);
490 }
491
492 protected void OnFuseIgnitedServer()
493 {
494 int state = EFireworksState.FIRING;
495 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(SetState, GetFuseDelay() * 1000, false, state);
496 }
497
498 protected void OnFuseIgnitedClient()
499 {
500 m_ParticleFuse = ParticleManager.GetInstance().PlayInWorld(ParticleList.FIREWORKS_FUSE, GetPosition() + "0 0.15 0");
501 if (m_ParticleFuse)
503 PlaySoundSet(m_FuseSoundStart, "FireworksLauncher_Ignition_Start_SoundSet", 0, 0);
506
507 if (MemoryPointExists("Fuse_Start"))
508 {
509 fuseStart = GetMemoryPointPos("Fuse_Start");
510 fuseStart = ModelToWorld(fuseStart);
511 }
512 if (MemoryPointExists("Fuse_End"))
513 {
514 fuseEnd = GetMemoryPointPos("Fuse_End");
515 fuseEnd = ModelToWorld(fuseEnd);
516 }
517
520 vector ori = fuseDir.VectorToAngles();
521 m_ParticleFuse.SetOrientation(ori);
522 m_ParticleFuse.SetPosition(fuseStart);
523
524 PlaySoundSetLoop(m_FuseSound, GetFuseSoundSet(), 0, 0);
525 }
526
527 protected void OnFiringStartServer()
528 {
529 OnEventServer(0);
530 }
531
532 protected void OnFiringStartClient()
533 {
534 if (m_ParticleFuse)
536 if (m_FuseSound)
538 }
539
540 protected void OnFiringStop()
541 {
542 SetHealth01("", "", 0);
543 }
544
546 protected void RestartEventTimer()
547 {
548 if (!m_TimerEvent)
549 m_TimerEvent = new Timer();
550 m_TimerEvent.Run(GetEventDelay(), this, "OnEventServer", new Param1<int>(0));
551 }
552
553
554 override protected bool IsIgnited()
555 {
556 return GetState() == EFireworksState.IGNITED;
557 }
558
559 override protected bool CanIgniteItem(EntityAI ignite_target = NULL)
560 {
561 return false;
562 }
563
564
566 override protected void OnEventServer(int type)
567 {
568 m_Index++;
569 DamageSystem.ExplosionDamage(this, NULL, GetAmmoType(), GetPosition(), GetDamageType());
570
571 SetSynchDirty();
572 if (m_Index > GetMaxShots())
573 {
576 SetState(EFireworksState.FINISHED);
577 }
578 else
580 }
581
582 protected void OnIndexChangedClient()
583 {
584 if (!m_Events)
586 if (m_Index != 0 && m_State == EFireworksState.FIRING)//can only be true when restarting the device during debug calls
587 {
588 FireworksLauncherClientEventBase fireEvent = SpawnEvent();
589 m_Events.Insert(fireEvent);
590 }
591 }
592
593 protected FireworksLauncherClientEventBase SpawnEvent()
594 {
595 FireworksLauncherClientEventBase evnt = new FireworksLauncherClientEvent(this, m_Index);
596 evnt.OnFired();
597 return evnt;
598 }
599
600 override protected void OnVariablesSynchronized()
601 {
602 super.OnVariablesSynchronized();
603 //Print("index: " + m_Index);
604 if (m_Index != m_IndexPrev)
605 {
609 }
610 }
611
612 override protected void OnStoreSave(ParamsWriteContext ctx)
613 {
614 super.OnStoreSave(ctx);
615 ctx.Write(m_Index);
616 ctx.Write(m_State);
617 }
618
619
620 override protected bool OnStoreLoad(ParamsReadContext ctx, int version)
621 {
622 if (!super.OnStoreLoad(ctx, version))
623 return false;
624
625 if (version >= 130)
626 {
627 if (!ctx.Read(m_Index))
628 return false;
629
630 if (!ctx.Read(m_State))
631 return false;
632
634 }
635 return true;
636 }
637
638 override string GetDeploySoundset()
639 {
640 return "placeFireworks_SoundSet";
641 }
642
643 override string GetLoopDeploySoundset()
644 {
645 return "fireworks_deploy_SoundSet";
646 }
647
648#ifdef DEVELOPER
649 override protected string GetDebugText()
650 {
651 string debug_output;
652
653 if (GetGame().IsDedicatedServer())
654 {
656 debug_output += "m_Index:" + m_Index + "\n";
657 }
658 else
659 {
660
661 }
662 return debug_output;
663 }
664
665#endif
666}
DamageType
exposed from C++ (do not change)
override Widget Init()
Definition DayZGame.c:120
void OnExplode()
Particle m_ParticleExplosion
particle
ref Timer m_TimerEvent
EFireworksState
int m_RandomSeed
ExplosionLight PointLightBase OnFired()
vector GetExplosionPosition()
float GetExplosionDistance()
vector GetShotPos()
FireworksLauncherClientEvent m_ShotPos
string GetDebugText()
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
void SetState(bool state)
bool m_State
class JsonUndergroundAreaTriggerData GetPosition
Definition Debug.c:14
static void LogError(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message as error message.
Definition Debug.c:341
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
override void Stop()
Stops sound.
static int GetLastEnumValue(typename e)
Return amount of values in enum.
Definition EnConvert.c:644
static string EnumToString(typename e, int enumValue)
Return string name of enum value.
Definition EnConvert.c:598
void FireworksLauncherClientEvent(FireworksLauncher item, int index)
ref array< ref FireworksLauncherClientEventBase > m_Events
void SetupLight(PointLightBase light)
void RestartEventTimer()
Starts event timer.
void OnStateChangedServer(EFireworksState currentState)
override string GetLoopDeploySoundset()
ref array< ref FireworksLauncherClientEventBase > m_Events
override string GetDeploySoundset()
void OnEventServer(int type)
Called periodically but only after the entity gets ignited.
FireworksLauncherClientEventBase SpawnEvent()
bool CanIgniteItem(EntityAI ignite_target=NULL)
void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
override float GetDeployTime()
how long it takes to deploy this item in seconds
void OnStoreSave(ParamsWriteContext ctx)
bool OnStoreLoad(ParamsReadContext ctx, int version)
bool CanPutInCargo(EntityAI parent)
EffectSound m_FuseSoundStart
bool CanPutIntoHands(EntityAI parent)
ParticleSource m_ParticleFuse
ParticleSource m_ParticleAfterBurnEnd
override bool IsDeployable()
ref array< string > m_ColorSequence
override void OnIgnitedThis(EntityAI fire_source)
Executed on Server when some item ignited this one.
void OnStateChangedClient(EFireworksState currentState)
Definition EnMath.c:7
void Stop()
Legacy function for backwards compatibility with 1.14 and below.
Definition Particle.c:262
static const int FIREWORKS_AFTERBURN_END
static const int FIREWORKS_EXPLOSION_YELLOW
static const int FIREWORKS_EXPLOSION_BLUE
static const int FIREWORKS_EXPLOSION_RED
static const int FIREWORKS_FUSE
static const int FIREWORKS_EXPLOSION_GREEN
static const int FIREWORKS_SHOT
static const int FIREWORKS_EXPLOSION_PINK
Entity which has the particle instance as an ObjectComponent.
override bool StopParticle(int flags=0)
Method to tell the particle to stop playing.
proto native void SetOwner(Class owner)
Set the owner of this ParticleSource.
Manager class for managing Effect (EffectParticle, EffectSound)
static void DestroyEffect(Effect effect)
Unregisters, stops and frees the Effect.
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto native CGame GetGame()
enum ShapeType ErrorEx
class DiagMenu Shape
don't call destructor directly. Use Destroy() instead
const float STATE_WET
Definition constants.c:783
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto int Randomize(int seed)
Sets the seed for the random number generator.
static float RandomFloatInclusive(float min, float max)
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:106
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Definition EnMath.c:54
proto native int Length()
Returns length of string.
proto string Get(int index)
Gets n-th character from string.
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8
proto native int GetState()
returns one of STATE_...