fireworkslauncheranniversary.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. class AnniversaryFireworksLauncherClientEvent: FireworksLauncherClientEvent
  2. {
  3. override protected int GetExplParticleFromSequence()
  4. {
  5. switch (m_Color)
  6. {
  7. case "1":
  8. return ParticleList.FIREWORKS_EXPLOSION_THANKS1;
  9. case "2":
  10. return ParticleList.FIREWORKS_EXPLOSION_THANKS2;
  11. case "3":
  12. return ParticleList.FIREWORKS_EXPLOSION_THANKS3;
  13. case "4":
  14. return ParticleList.FIREWORKS_EXPLOSION_THANKS4;
  15. case "5":
  16. return ParticleList.FIREWORKS_EXPLOSION_THANKS5;
  17. default:
  18. ErrorEx("Incorrect explosion particle color in the sequence");
  19. }
  20. return ParticleList.FIREWORKS_EXPLOSION_RED;
  21. }
  22. override protected void SetupLight(PointLightBase light)
  23. {
  24. switch (m_Color)
  25. {
  26. case "1":
  27. light.SetDiffuseColor(255,51,51);
  28. light.SetAmbientColor(255,51,51);
  29. break;
  30. case "2":
  31. light.SetDiffuseColor(0,255,128);
  32. light.SetAmbientColor(0,255,128);
  33. break;
  34. case "3":
  35. light.SetDiffuseColor(51,153,255);
  36. light.SetAmbientColor(51,153,255);
  37. break;
  38. case "4":
  39. light.SetDiffuseColor(255,255,51);
  40. light.SetAmbientColor(255,255,51);
  41. break;
  42. case "5":
  43. light.SetDiffuseColor(255,102,255);
  44. light.SetAmbientColor(255,102,255);
  45. break;
  46. default:
  47. ErrorEx("Incorrect explosion particle color in the sequence");
  48. }
  49. }
  50. override protected void SpawnSecondaryExplosion()
  51. {
  52. AnniversaryFireworksLauncherClientEventSecondary evnt = new AnniversaryFireworksLauncherClientEventSecondary(m_Item,m_Index);
  53. evnt.Init(GetExplosionPosition());
  54. evnt.OnExplode();
  55. m_Events.Insert(evnt);
  56. RequestSecondaryExplosion();
  57. }
  58. }
  59. //--------------------------------------------------------------------------------------
  60. class AnniversaryFireworksLauncherClientEventSecondary : AnniversaryFireworksLauncherClientEvent
  61. {
  62. protected vector m_ShotPos;
  63. override protected vector GetExplosionPosition()
  64. {
  65. return GetShotPos() + m_ShotDir * GetExplosionDistance();
  66. }
  67. void Init(vector pos)
  68. {
  69. m_ShotPos = pos;
  70. m_ShotDir[0] = Math.RandomFloatInclusive(-1,1);
  71. m_ShotDir[1] = Math.RandomFloatInclusive(-1,1);
  72. m_ShotDir[2] = Math.RandomFloatInclusive(-1,1);
  73. m_ShotDir.Normalize();
  74. }
  75. override protected vector GetShotPos()
  76. {
  77. return m_ShotPos;
  78. }
  79. override protected float GetExplosionDistance()
  80. {
  81. return Math.RandomFloatInclusive(10,15);
  82. }
  83. override void OnExplode()
  84. {
  85. GetGame().GetCallQueue( CALL_CATEGORY_SYSTEM ).CallLater( PlayExplosionSound, GetSoundDelay(), false);
  86. GetGame().GetCallQueue( CALL_CATEGORY_SYSTEM ).CallLater( SpawnLight, GetLightDelay(), false);
  87. m_ParticleExplosion = ParticleManager.GetInstance().PlayInWorld(GetExplParticleFromSequence(), GetExplosionPosition());
  88. }
  89. }
  90. //--------------------------------------------------------------------------------------
  91. class Anniversary_FireworksLauncher: FireworksLauncher
  92. {
  93. int sequence = 0;
  94. override protected void SetupColorSequences()
  95. {
  96. m_ColorSequence.Insert("1234512345123451234512345");
  97. }
  98. override protected FireworksLauncherClientEventBase SpawnEvent()
  99. {
  100. FireworksLauncherClientEventBase evnt = new AnniversaryFireworksLauncherClientEvent(this,m_Index);
  101. evnt.OnFired();
  102. return evnt;
  103. }
  104. override bool IsTakeable()
  105. {
  106. return false;
  107. }
  108. override bool CanSwapEntities(EntityAI otherItem, InventoryLocation otherDestination, InventoryLocation destination)
  109. {
  110. return false;
  111. }
  112. override bool DisableVicinityIcon()
  113. {
  114. return true;
  115. }
  116. override protected int GetMaxShots()
  117. {
  118. return 25;
  119. }
  120. override protected float GetFuseDelay()
  121. {
  122. return 1;
  123. }
  124. //!Called periodically but only after the entity gets ignited
  125. override protected void OnEventServer(int type)
  126. {
  127. m_Index++;
  128. DamageSystem.ExplosionDamage(this, NULL, GetAmmoType(), GetPosition(), GetDamageType());
  129. if(m_Index > 16)
  130. {
  131. sequence++;
  132. m_Index = 1;
  133. }
  134. SetSynchDirty();
  135. if (m_Index + (sequence*16)> GetMaxShots())
  136. {
  137. m_Index = GetMaxShots();
  138. m_TimerEvent = null;
  139. SetState(EFireworksState.FINISHED);
  140. }
  141. else
  142. {
  143. RestartEventTimer();
  144. }
  145. }
  146. }