contaminatedarea_dynamicbase.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. enum eAreaDecayStage
  2. {
  3. INIT = 1, // The dynamic area is initializing
  4. START = 2, // The dynamic area is starting
  5. LIVE = 3, // The dynamic area is live
  6. DECAY_START = 4, // The dynamic area decay has started
  7. DECAY_END = 5, // The dynamic area will soon be deleted
  8. }
  9. class ContaminatedArea_DynamicBase : ContaminatedArea_Base
  10. {
  11. protected int m_DecayState = eAreaDecayStage.INIT; // The current state in which the area is
  12. // Constants used for dissapearing events
  13. const float DECAY_START_PART_SIZE = 32;
  14. const int DECAY_START_PART_BIRTH_RATE = 1;
  15. const float DECAY_END_PART_SIZE = 17;
  16. const int DECAY_END_PART_BIRTH_RATE = 1;
  17. const float START_DECAY_LIFETIME = 900;
  18. const float FINISH_DECAY_LIFETIME = 300;
  19. void ContaminatedArea_DynamicBase()
  20. {
  21. m_Type = eZoneType.DYNAMIC;
  22. RegisterNetSyncVariableInt("m_DecayState");
  23. }
  24. float GetRemainingTime()
  25. {
  26. return GetLifetime();
  27. }
  28. float GetStartDecayLifetime()
  29. {
  30. return START_DECAY_LIFETIME;
  31. }
  32. float GetFinishDecayLifetime()
  33. {
  34. return FINISH_DECAY_LIFETIME;
  35. }
  36. // Set the new state of the Area
  37. void SetDecayState(int newState)
  38. {
  39. if (m_DecayState != newState)
  40. {
  41. m_DecayState = newState;
  42. // We update the trigger state values as we also want to update player bound effects
  43. if ( m_Trigger )
  44. ContaminatedTrigger_Dynamic.Cast( m_Trigger ).SetAreaState( m_DecayState );
  45. SetSynchDirty();
  46. }
  47. }
  48. // We spawn particles and setup trigger
  49. override void InitZone()
  50. {
  51. SetDecayState(eAreaDecayStage.LIVE);
  52. super.InitZone();
  53. }
  54. override void InitZoneClient()
  55. {
  56. super.InitZoneClient();
  57. // We spawn VFX on client
  58. PlaceParticles(m_Position, m_Radius, m_InnerRings, m_InnerSpacing, m_OuterRingToggle, m_OuterSpacing, m_OuterRingOffset, m_ParticleID);
  59. }
  60. override void InitZoneServer()
  61. {
  62. super.InitZoneServer();
  63. // We create the trigger on server
  64. if (m_TriggerType != "")
  65. CreateTrigger(m_PositionTrigger, m_Radius);
  66. }
  67. override void OnParticleAllocation(ParticleManager pm, array<ParticleSource> particles)
  68. {
  69. super.OnParticleAllocation(pm, particles);
  70. if (m_DecayState > eAreaDecayStage.LIVE)
  71. {
  72. foreach (ParticleSource p : particles)
  73. {
  74. if (m_DecayState == eAreaDecayStage.DECAY_END)
  75. {
  76. p.SetParameter(0, EmitorParam.BIRTH_RATE, DECAY_END_PART_BIRTH_RATE);
  77. p.SetParameter(0, EmitorParam.SIZE, DECAY_END_PART_SIZE);
  78. }
  79. else
  80. {
  81. p.SetParameter(0, EmitorParam.BIRTH_RATE, DECAY_START_PART_BIRTH_RATE);
  82. p.SetParameter(0, EmitorParam.SIZE, DECAY_START_PART_SIZE);
  83. }
  84. }
  85. }
  86. }
  87. override void CreateTrigger(vector pos, int radius)
  88. {
  89. super.CreateTrigger(pos, radius);
  90. // This handles the specific case of dynamic triggers as some additionnal parameters are present
  91. ContaminatedTrigger_Dynamic dynaTrigger = ContaminatedTrigger_Dynamic.Cast( m_Trigger );
  92. if (dynaTrigger)
  93. {
  94. dynaTrigger.SetLocalEffects( m_AroundParticleID, m_TinyParticleID, m_PPERequesterIdx );
  95. dynaTrigger.SetAreaState( m_DecayState );
  96. }
  97. }
  98. override void OnVariablesSynchronized()
  99. {
  100. super.OnVariablesSynchronized();
  101. if (!m_ToxicClouds)
  102. m_ToxicClouds = new array<Particle>();
  103. switch ( m_DecayState )
  104. {
  105. case eAreaDecayStage.LIVE:
  106. InitZoneClient();
  107. break;
  108. case eAreaDecayStage.DECAY_START:
  109. {
  110. // We go through all the particles bound to this area and update relevant parameters
  111. //Debug.Log("We start decay");
  112. foreach ( Particle p : m_ToxicClouds )
  113. {
  114. p.SetParameter( 0, EmitorParam.BIRTH_RATE, DECAY_START_PART_BIRTH_RATE );
  115. p.SetParameter( 0, EmitorParam.SIZE, DECAY_START_PART_SIZE );
  116. }
  117. break;
  118. }
  119. case eAreaDecayStage.DECAY_END:
  120. {
  121. // We go through all the particles bound to this area and update relevant parameters
  122. //Debug.Log("We finish decay");
  123. foreach ( Particle prt : m_ToxicClouds )
  124. {
  125. prt.SetParameter( 0, EmitorParam.BIRTH_RATE, DECAY_END_PART_BIRTH_RATE );
  126. prt.SetParameter( 0, EmitorParam.SIZE, DECAY_END_PART_SIZE );
  127. }
  128. break;
  129. }
  130. default:
  131. break;
  132. }
  133. }
  134. }