geysertrigger.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. class GeyserTrigger : EffectTrigger
  2. {
  3. const float MOUTH_ADJUST_RADIUS = 0.2; // maxium radius geyser effect can move when using randomized position adjustment
  4. const string SOUND_BUBBLING = "Geyser_bubbling_loop_SoundSet";
  5. const string SOUND_ERUPTION = "Geyser_eruption_loop_SoundSet";
  6. const string SOUND_ERUPTION_START = "Geyser_eruption_start_SoundSet";
  7. const string SOUND_ERUPTION_TALL = "Geyser_eruption_tall_loop_SoundSet";
  8. const string SOUND_ERUPTION_TALL_START = "Geyser_eruption_tall_start_SoundSet";
  9. const string SOUND_ERUPTION_TALL_END = "Geyser_eruption_tall_splash_SoundSet";
  10. protected bool m_bIsDormant;
  11. protected bool m_bIsEruptingSoon;
  12. protected bool m_bIsErupting;
  13. protected bool m_bIsEruptingTall;
  14. protected float m_AdjustedX; //deprecated
  15. protected float m_AdjustedY; //deprecated
  16. protected vector m_DefaultPosition;
  17. protected EGeyserState m_GeyserState = EGeyserState.DORMANT; // synchronized state
  18. protected ParticleSource m_GeyserBubblesParticle;
  19. protected ParticleSource m_GeyserParticle;
  20. protected ParticleSource m_GeyserTallParticle;
  21. protected ParticleSource m_GeyserSplashParticle;
  22. protected EffectSound m_SoundBubbling;
  23. protected EffectSound m_SoundEruption;
  24. protected EffectSound m_SoundEruptionStart;
  25. protected EffectSound m_SoundEruptionSecondary;
  26. protected EffectSound m_SoundEruptionSecondaryStart;
  27. protected EffectSound m_SoundEruptionSecondaryEnd;
  28. void GeyserTrigger()
  29. {
  30. RegisterNetSyncVariableInt("m_GeyserState", 0, 32);
  31. }
  32. override void DeferredInit()
  33. {
  34. super.DeferredInit();
  35. m_DefaultPosition = GetAdjustedPosition();
  36. if (IsSubmerged())
  37. RandomizeMouthPos();
  38. if (!GetGame().IsDedicatedServer())
  39. UpdateGeyserState();
  40. }
  41. override string GetDisplayName()
  42. {
  43. return "#STR_geyser";
  44. }
  45. override void EEDelete( EntityAI parent )
  46. {
  47. StopEffects();
  48. super.EEDelete(parent);
  49. }
  50. override void OnEnterServerEvent( TriggerInsider insider )
  51. {
  52. super.OnEnterServerEvent(insider);
  53. if (insider && (m_GeyserState & EGeyserState.ERUPTING_PRIMARY))
  54. {
  55. EntityAI entity = EntityAI.Cast(insider.GetObject());
  56. if (entity)
  57. entity.ProcessDirectDamage(DamageType.CUSTOM, this, "", "HeatDamage", "0 0 0", 1000);
  58. }
  59. }
  60. override void OnLeaveServerEvent( TriggerInsider insider )
  61. {
  62. super.OnLeaveServerEvent(insider);
  63. }
  64. override void OnEnterClientEvent( TriggerInsider insider )
  65. {
  66. super.OnEnterClientEvent(insider);
  67. }
  68. override void OnLeaveClientEvent( TriggerInsider insider )
  69. {
  70. super.OnLeaveClientEvent(insider);
  71. }
  72. override void OnVariablesSynchronized()
  73. {
  74. super.OnVariablesSynchronized();
  75. if (IsInitialized())
  76. UpdateGeyserState();
  77. }
  78. // Updated from OnVariablesSynchronized
  79. protected void UpdateGeyserState()
  80. {
  81. // Debug.Log("UpdateGeyserState, state: " + m_GeyserState);
  82. if (CheckGeyserState(EGeyserState.DORMANT) && !m_bIsDormant)
  83. {
  84. m_bIsDormant = true;
  85. }
  86. else if (!CheckGeyserState(EGeyserState.DORMANT) && m_bIsDormant)
  87. {
  88. m_bIsDormant = false;
  89. }
  90. if (CheckGeyserState(EGeyserState.ERUPTION_SOON) && !m_bIsEruptingSoon)
  91. {
  92. m_GeyserBubblesParticle = ParticleManager.GetInstance().PlayInWorld(ParticleList.GEYSER_BUBBLES, m_DefaultPosition);
  93. m_SoundBubbling = SEffectManager.PlaySound(SOUND_BUBBLING, m_DefaultPosition, 2, 2, true);
  94. m_bIsEruptingSoon = true;
  95. }
  96. else if (!CheckGeyserState(EGeyserState.ERUPTION_SOON) && m_bIsEruptingSoon)
  97. {
  98. m_GeyserBubblesParticle.StopParticle();
  99. m_SoundBubbling.Stop();
  100. m_bIsEruptingSoon = false;
  101. }
  102. if (CheckGeyserState(EGeyserState.ERUPTING_PRIMARY) && !m_bIsErupting)
  103. {
  104. m_GeyserParticle = ParticleManager.GetInstance().PlayInWorld(ParticleList.GEYSER_NORMAL, m_DefaultPosition);
  105. m_SoundEruptionStart = SEffectManager.PlaySound(SOUND_ERUPTION_START, m_DefaultPosition, 0, 0, false);
  106. m_SoundEruption = SEffectManager.PlaySound(SOUND_ERUPTION, m_DefaultPosition, 2, 2, true);
  107. m_bIsErupting = true;
  108. }
  109. else if (!CheckGeyserState(EGeyserState.ERUPTING_PRIMARY) && m_bIsErupting)
  110. {
  111. m_GeyserParticle.StopParticle();
  112. m_SoundEruptionStart.Stop();
  113. m_SoundEruption.Stop();
  114. m_bIsErupting = false;
  115. }
  116. if (CheckGeyserState(EGeyserState.ERUPTING_SECONDARY) && !m_bIsEruptingTall)
  117. {
  118. m_GeyserTallParticle = ParticleManager.GetInstance().PlayInWorld(ParticleList.GEYSER_STRONG, m_DefaultPosition);
  119. m_SoundEruptionSecondaryStart = SEffectManager.PlaySound(SOUND_ERUPTION_TALL_START, m_DefaultPosition, 0, 0, false);
  120. m_SoundEruptionSecondary = SEffectManager.PlaySound(SOUND_ERUPTION_TALL, m_DefaultPosition, 0, 0, false);
  121. m_bIsEruptingTall = true;
  122. }
  123. else if (!CheckGeyserState(EGeyserState.ERUPTING_SECONDARY) && m_bIsEruptingTall)
  124. {
  125. m_GeyserSplashParticle = ParticleManager.GetInstance().PlayInWorld(ParticleList.GEYSER_SPLASH, m_DefaultPosition);
  126. m_SoundEruptionSecondaryEnd = SEffectManager.PlaySound(SOUND_ERUPTION_TALL_END, m_DefaultPosition, 0, 0, false);
  127. m_GeyserTallParticle.StopParticle();
  128. m_SoundEruptionSecondaryStart.Stop();
  129. m_SoundEruptionSecondary.Stop();
  130. m_bIsEruptingTall = false;
  131. }
  132. }
  133. // Slightly adjust position of geyser particles
  134. protected void RandomizeMouthPos()
  135. {
  136. m_DefaultPosition[0] = m_DefaultPosition[0] + Math.RandomFloat( -MOUTH_ADJUST_RADIUS, MOUTH_ADJUST_RADIUS);
  137. m_DefaultPosition[2] = m_DefaultPosition[2] + Math.RandomFloat( -MOUTH_ADJUST_RADIUS, MOUTH_ADJUST_RADIUS);
  138. //for backwards compatibility
  139. m_AdjustedX = m_DefaultPosition[0];
  140. m_AdjustedY = m_DefaultPosition[2]; //typo, should be Z
  141. }
  142. // Get position on surface of water volume or terrain, add height offset
  143. protected vector GetAdjustedPosition(float height = 0)
  144. {
  145. vector pos = GetPosition();
  146. pos[1] = GetGame().SurfaceRoadY(pos[0], pos[2], RoadSurfaceDetection.UNDER) + height;
  147. return pos;
  148. }
  149. void StopEffects()
  150. {
  151. if (m_bIsEruptingSoon)
  152. {
  153. m_GeyserBubblesParticle.StopParticle();
  154. m_SoundBubbling.Stop();
  155. m_bIsEruptingSoon = false;
  156. }
  157. if (m_bIsErupting)
  158. {
  159. m_GeyserParticle.StopParticle();
  160. m_SoundEruption.Stop();
  161. m_bIsErupting = false;
  162. }
  163. if (m_bIsEruptingTall)
  164. {
  165. m_GeyserTallParticle.StopParticle();
  166. m_SoundEruptionSecondary.Stop();
  167. m_bIsEruptingTall = false;
  168. }
  169. }
  170. void AddGeyserState(EGeyserState state)
  171. {
  172. m_GeyserState |= state;
  173. SetSynchDirty();
  174. }
  175. void RemoveGeyserState(EGeyserState state)
  176. {
  177. m_GeyserState &= ~state;
  178. SetSynchDirty();
  179. }
  180. bool CheckGeyserState(EGeyserState state)
  181. {
  182. if (state == EGeyserState.DORMANT)
  183. return (m_GeyserState == state);
  184. else
  185. return (m_GeyserState & state);
  186. }
  187. EGeyserState GetGeyserState()
  188. {
  189. return m_GeyserState;
  190. }
  191. // override for differences in logic between land & submerged geysers
  192. bool IsSubmerged()
  193. {
  194. return true;
  195. }
  196. }