5 SetVisibleDuringDaylight(
true);
8 SetFlareVisible(
false);
9 SetAmbientColor(1.0, 1.0, 1.0);
10 SetDiffuseColor(1.0, 1.0, 1.0);
17 SetFlickerAmplitudeMax(3);
18 SetFlickerAmplitudeMin(0);
19 SetCastShadow(
false );
23 class FireworksLauncherClientEventBase
32 protected int m_Index;
33 protected vector m_ExplosionPos;
38 protected vector m_ShotDir;
41 protected string m_Color;
42 protected int m_RemainingExplosions = GetSecondaryExplosionCount();
45 Shape m_ShotTrajectory;
53 protected int GetSoundDelay()
58 protected int GetLightDelay()
63 protected float GetExplosionDistance()
65 return Math.RandomFloatInclusive(35,40);
68 protected float GetShotDispersionAngle()
70 return Math.RandomFloatInclusive(-25,25);
73 protected string GetExplosionSoundSet()
75 return "FireworksLauncher_Explosion_SoundSet";
78 protected float GetExplosionDelay()
80 return Math.RandomFloatInclusive(1.5,1.75);
93 int colorSequenceLastIndex =
m_Item.GetColorSequence().Length() - 1;
94 int coloreSequenceIndex = m_Index - 1;
96 if (colorSequenceLastIndex >= coloreSequenceIndex)
102 Debug.LogError(
"Failed to obtain color from color sequence");
111 if (m_ParticleAfterBurnEnd)
113 m_ParticleAfterBurnEnd.StopParticle();
117 override protected void OnFired()
119 m_Timer.Run(GetExplosionDelay(),
this,
"OnExplode",
null);
120 m_Item.PlaySoundSet( m_FireSound,
"FireworksLauncher_Shot_SoundSet", 0, 0 );
122 m_ParticleShot.SetYawPitchRoll(
Vector(
Math.RandomFloatInclusive(0,360),GetShotDispersionAngle(),0));
125 if (m_ParticleAfterBurnEnd)
126 m_ParticleAfterBurnEnd.SetOwner(
this);
127 m_ShotDir = m_ParticleShot.GetDirectionUp();
131 pts[0] = GetShotPos();
132 pts[1] = GetShotPos() + m_ShotDir * GetExplosionDistance();
137 protected vector GetShotPos()
140 string memName =
"Shot_" + m_Index;
142 if (
m_Item.MemoryPointExists(memName))
144 memPos =
m_Item.GetMemoryPointPos(memName);
145 memPos =
m_Item.ModelToWorld(memPos);
149 memPos =
m_Item.GetPosition();
150 Debug.LogError(
"Missing shot memory point on Fireworks");
155 protected void CalculateExplosionPosition()
157 m_ExplosionPos = GetShotPos() + m_ShotDir * GetExplosionDistance();
160 protected vector GetExplosionPosition()
164 CalculateExplosionPosition();
166 return m_ExplosionPos;
169 int GetSecondaryExplosionCount()
175 protected void OnExplode()
178 if (m_ShotTrajectory)
180 m_ShotTrajectory.Destroy();
181 m_ShotTrajectory =
null;
184 m_ParticleAfterBurnEnd.Stop();
190 RequestSecondaryExplosion();
194 protected void RequestSecondaryExplosion()
196 if (m_RemainingExplosions> 0)
198 m_RemainingExplosions--;
203 protected void SpawnSecondaryExplosion()
205 FireworksLauncherClientEventSecondary evnt =
new FireworksLauncherClientEventSecondary(
m_Item,m_Index);
206 evnt.Init(GetExplosionPosition());
208 m_Events.Insert(evnt);
209 RequestSecondaryExplosion();
212 protected int GetSecondaryExplosionDelay()
214 return Math.RandomIntInclusive(100,250);
217 protected int GetExplParticleFromSequence()
232 ErrorEx(
"Incorrect explosion particle color in the sequence");
242 light.SetDiffuseColor(255,51,51);
243 light.SetAmbientColor(255,51,51);
247 light.SetDiffuseColor(0,255,128);
248 light.SetAmbientColor(0,255,128);
251 light.SetDiffuseColor(51,153,255);
252 light.SetAmbientColor(51,153,255);
255 light.SetDiffuseColor(255,255,51);
256 light.SetAmbientColor(255,255,51);
259 light.SetDiffuseColor(255,102,255);
260 light.SetAmbientColor(255,102,255);
263 ErrorEx(
"Incorrect explosion particle color in the sequence");
267 protected void SpawnLight()
270 SetupLight(m_ExplosionLight);
273 protected void PlayExplosionSound()
279 m_Item.PlaySoundSet( m_ExplosionSound, GetExplosionSoundSet(), 0, 0 );
296 m_ShotDir[0] =
Math.RandomFloatInclusive(-1,1);
297 m_ShotDir[1] =
Math.RandomFloatInclusive(-1,1);
298 m_ShotDir[2] =
Math.RandomFloatInclusive(-1,1);
299 m_ShotDir.Normalize();
308 return Math.RandomFloatInclusive(10,15);
323 int m_ColorSequenceIndex;
324 ref
Timer m_TimerFuse;
335 SetupColorSequences();
337 RegisterNetSyncVariableInt(
"m_Index", 0, GetMaxShots());
338 RegisterNetSyncVariableInt(
"m_RandomSeed", 0, 1023);
339 int lastIndex = m_ColorSequence.Count() - 1;
340 RegisterNetSyncVariableInt(
"m_ColorSequenceIndex", 0, lastIndex);
342 m_ColorSequenceIndex =
Math.RandomIntInclusive(0, lastIndex);
351 override protected bool UsesGlobalDeploy()
356 override bool IsDeployable()
362 override float GetDeployTime()
367 protected void SetupColorSequences()
369 m_ColorSequence.Insert(
"RGBYPBRGBRGBYPBRGBRGBYPBRGBPBRGBRGBY");
370 m_ColorSequence.Insert(
"PGPYPBYPYPBYYPBRPYPBYYPBRGBPBRGRGBRB");
371 m_ColorSequence.Insert(
"YPBRPYPBYYPBRGBPBRGRGBRBGRPBRGBRYPBY");
372 m_ColorSequence.Insert(
"YRBGPRYPGRYBGRGRGBRBBYPYPBYRYPGRYGRP");
373 m_ColorSequence.Insert(
"BGRYPYRPBYYPYRBGPRYPGBYPBRGBPBRGBRGB");
374 m_ColorSequence.Insert(
"RYGRPBRGBYPBRRPBRGBBRBBYPYPRGBRGBRPY");
375 m_ColorSequence.Insert(
"GBRGBYRGBYPBRRPBRBYRYPGPYPRGBRGBRPYG");
376 m_ColorSequence.Insert(
"RYPBYYPBRGBYPBRGBRBGBPBRGRGBRBGRYPYR");
377 m_ColorSequence.Insert(
"PBRGBYPBRGBRBGBPBRGRGBRBGRYPYRRYPBYY");
378 m_ColorSequence.Insert(
"RGRGBRBBYPYPBYRYPGRYGRPYRBGPRYPGRYBG");
379 m_ColorSequence.Insert(
"RBYRYPGPYPRGBRGBRPYGGBRGBYRGBYPBRRPB");
380 m_ColorSequence.Insert(
"PRGBRGBRPYGGBRRBYRYPGPYGBYRGBYPBRRPB");
383 string GetColorSequence()
385 if (m_ColorSequence.IsValidIndex(m_ColorSequenceIndex))
387 return m_ColorSequence.Get(m_ColorSequenceIndex);
391 ErrorEx(
"Failed to obtain color sequence");
392 return "RYPBYYPBRGBYPBRGBRBGBPBRGRGBRBGRYPYR";
397 override protected void OnPlacementComplete(Man player,
vector position =
"0 0 0",
vector orientation =
"0 0 0")
399 super.OnPlacementComplete(player, position, orientation);
409 override protected float GetMaxAllowedWetness()
415 override protected float GetEventDelay()
417 return Math.RandomFloatInclusive(3,3.35);
420 protected string GetFuseSoundSet()
422 return "FireworksLauncher_Ignition_Loop_SoundSet";
425 protected int GetMaxShots()
430 protected float GetFuseDelay()
435 protected string GetAmmoType()
437 return "Fireworks_Ammo";
440 protected int GetDamageType()
446 override protected void OnStateChangedServer(
EFireworksState currentState)
448 switch (currentState)
453 OnFuseIgnitedServer();
456 HideSelection(
"cover");
457 OnFiringStartServer();
460 HideSelection(
"cover");
466 override protected void OnStateChangedClient(
EFireworksState currentState)
468 switch (currentState)
471 OnFuseIgnitedClient();
476 OnFiringStartClient();
483 override void OnIgnitedThis(
EntityAI fire_source)
485 super.OnIgnitedThis(fire_source);
498 override protected bool CanPutInCargo(
EntityAI parent )
503 override protected bool CanPutIntoHands(
EntityAI parent )
508 protected void OnFuseIgnitedServer()
514 protected void OnFuseIgnitedClient()
518 m_ParticleFuse.SetOwner(
this);
519 PlaySoundSet( m_FuseSoundStart,
"FireworksLauncher_Ignition_Start_SoundSet", 0, 0 );
523 if (MemoryPointExists(
"Fuse_Start"))
525 fuseStart = GetMemoryPointPos(
"Fuse_Start");
526 fuseStart = ModelToWorld(fuseStart);
528 if (MemoryPointExists(
"Fuse_End"))
530 fuseEnd = GetMemoryPointPos(
"Fuse_End");
531 fuseEnd = ModelToWorld(fuseEnd);
534 vector fuseDir = fuseEnd - fuseStart;
535 vector fuseOrientation[4];
536 vector ori = fuseDir.VectorToAngles();
537 m_ParticleFuse.SetOrientation(ori);
538 m_ParticleFuse.SetPosition(fuseStart);
540 PlaySoundSetLoop( m_FuseSound, GetFuseSoundSet(), 0, 0 );
543 protected void OnFiringStartServer()
548 protected void OnFiringStartClient()
552 m_ParticleFuse.StopParticle(StopParticleFlags.IMMEDIATE);
560 protected void OnFiringStop()
562 SetHealth01(
"",
"",0);
566 protected void RestartEventTimer()
572 m_TimerEvent.Run(GetEventDelay(),
this,
"OnEventServer",
new Param1<int>(0));
576 override protected bool IsIgnited()
581 override protected bool CanIgniteItem(
EntityAI ignite_target = NULL)
589 override protected void OnEventServer(
int type)
592 DamageSystem.ExplosionDamage(
this, NULL, GetAmmoType(),
GetPosition(), GetDamageType());
595 if (m_Index > GetMaxShots())
597 m_Index = GetMaxShots();
607 protected void OnIndexChangedClient()
615 FireworksLauncherClientEventBase fireEvent = SpawnEvent();
616 m_Events.Insert(fireEvent);
620 protected FireworksLauncherClientEventBase SpawnEvent()
627 override protected void OnVariablesSynchronized()
629 super.OnVariablesSynchronized();
631 if (m_Index != m_IndexPrev)
634 OnIndexChangedClient();
635 m_IndexPrev = m_Index;
641 super.OnStoreSave(ctx);
649 if (!super.OnStoreLoad(ctx, version))
656 if (!ctx.Read(m_Index))
671 override string GetDeploySoundset()
673 return "placeFireworks_SoundSet";
676 override string GetLoopDeploySoundset()
678 return "fireworks_deploy_SoundSet";
686 if(
GetGame().IsDedicatedServer())
689 debug_output+=
"m_Index:" + m_Index +
"\n";