effecttrigger.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. // Base class for "Effect triggers"
  2. // Registers in TriggerEffectManager and handles parameter setting through cfgEffectArea.json file
  3. class EffectTrigger : CylinderTrigger
  4. {
  5. int m_AroundPartId; // The main particles spawned around player when in trigger
  6. int m_TinyPartId; // The smaller particles spawned around player when in trigger
  7. int m_PPERequester; // The Post Processing used when player is in trigger
  8. float m_DeltaTime;
  9. float m_TimeAccuStay;
  10. bool m_DealDamageFlag;
  11. TriggerEffectManager m_Manager;
  12. EffectArea m_EffectArea;
  13. int m_EffectsPriority;
  14. #ifdef DIAG_DEVELOPER
  15. Shape m_DbgShape;
  16. bool m_DebugShapeActive;
  17. #endif
  18. void EffectTrigger()
  19. {
  20. RegisterNetSyncVariableInt("m_AroundPartId");
  21. RegisterNetSyncVariableInt("m_TinyPartId");
  22. RegisterNetSyncVariableInt("m_PPERequester");
  23. RegisterNetSyncVariableInt("m_EffectsPriority");
  24. m_Manager = TriggerEffectManager.GetInstance();
  25. m_Manager.RegisterTriggerType( this );
  26. }
  27. // ----------------------------------------------
  28. // CUSTOM EVENTS
  29. // ----------------------------------------------
  30. void SetLocalEffects( int aroundPartId, int tinyPartId, int ppeRequesterIdx )
  31. {
  32. m_AroundPartId = aroundPartId;
  33. m_TinyPartId = tinyPartId;
  34. m_PPERequester = ppeRequesterIdx;
  35. SetSynchDirty();
  36. }
  37. EffectArea GetEffectArea()
  38. {
  39. return m_EffectArea;
  40. }
  41. void Init(EffectArea area, int priority)
  42. {
  43. m_EffectArea = area;
  44. m_EffectsPriority = priority;
  45. }
  46. int GetEffectsPriority()
  47. {
  48. return m_EffectsPriority;
  49. }
  50. string GetAmbientSoundsetName()
  51. {
  52. return "";
  53. }
  54. void SetupClientEffects(bool enable, notnull PlayerBase player)
  55. {
  56. if ( !m_Manager.IsPlayerInTriggerType( player, this ) )
  57. {
  58. if (enable)
  59. {
  60. player.SetContaminatedEffectEx( true, m_PPERequester, m_AroundPartId, m_TinyPartId, GetAmbientSoundsetName() );
  61. }
  62. else
  63. {
  64. player.SetContaminatedEffectEx( false, m_PPERequester );
  65. }
  66. }
  67. }
  68. // ----------------------------------------------
  69. // TRIGGER EVENTS
  70. // ----------------------------------------------
  71. override void EOnFrame(IEntity other, float timeSlice)
  72. {
  73. m_DeltaTime = timeSlice;
  74. }
  75. override bool CanAddObjectAsInsider(Object object)
  76. {
  77. #ifdef SERVER
  78. DayZCreatureAI creature = DayZCreatureAI.Cast( object );
  79. if(creature)
  80. {
  81. return !creature.ResistContaminatedEffect();
  82. }
  83. else
  84. {
  85. PlayerBase player = PlayerBase.Cast(object);
  86. return player != null;
  87. }
  88. #else
  89. PlayerBase player = PlayerBase.Cast(object);
  90. return (player && player.IsControlledPlayer());
  91. #endif
  92. }
  93. override protected void OnStayClientEvent(TriggerInsider insider, float deltaTime)
  94. {
  95. super.OnStayClientEvent(insider, deltaTime);
  96. PlayerBase player = PlayerBase.Cast(insider.GetObject());
  97. if (player)
  98. player.RequestTriggerEffect(this, m_PPERequester, m_AroundPartId, m_TinyPartId, GetAmbientSoundsetName() );
  99. }
  100. override void OnEnterServerEvent( TriggerInsider insider )
  101. {
  102. super.OnEnterServerEvent( insider );
  103. // We don't need to test the trigger count as Modifiers handle such cases already
  104. if ( insider )
  105. {
  106. PlayerBase playerInsider = PlayerBase.Cast( insider.GetObject() );
  107. if(playerInsider)
  108. {
  109. m_Manager.OnPlayerEnter( playerInsider, this );
  110. }
  111. }
  112. }
  113. override void OnEnterClientEvent( TriggerInsider insider )
  114. {
  115. super.OnEnterClientEvent( insider );
  116. if ( insider )
  117. {
  118. PlayerBase playerInsider = PlayerBase.Cast( insider.GetObject() );
  119. // We will only handle the controlled player, as effects are only relevant to this player instance
  120. if (playerInsider && playerInsider.IsControlledPlayer() )
  121. {
  122. //SetupClientEffects(true, playerInsider);
  123. // We then handle the update of player trigger state in manager
  124. m_Manager.OnPlayerEnter( playerInsider, this );
  125. }
  126. }
  127. }
  128. override void OnLeaveServerEvent( TriggerInsider insider )
  129. {
  130. super.OnLeaveServerEvent( insider );
  131. if ( insider )
  132. {
  133. PlayerBase playerInsider = PlayerBase.Cast( insider.GetObject() );
  134. if ( playerInsider )
  135. m_Manager.OnPlayerExit( playerInsider, this );
  136. }
  137. }
  138. override void OnLeaveClientEvent( TriggerInsider insider )
  139. {
  140. super.OnLeaveClientEvent( insider );
  141. if ( insider )
  142. {
  143. // Make sure you pass the set variable for PPE effect
  144. // It will not remove the correct one if START and STOP don't point to the same Requester
  145. PlayerBase playerInsider = PlayerBase.Cast( insider.GetObject() );
  146. // We will only handle the controlled player, as effects are only relevant to this player instance
  147. if ( playerInsider && playerInsider.IsControlledPlayer() )
  148. {
  149. // We first handle the update of player trigger state in manager
  150. m_Manager.OnPlayerExit( playerInsider, this );
  151. //SetupClientEffects(false, playerInsider);
  152. }
  153. }
  154. }
  155. // We remove from trigger update DEAD or RESISTANT entities to limit the amount of entities to update
  156. override bool ShouldRemoveInsider( TriggerInsider insider )
  157. {
  158. return !insider.GetObject().IsAlive();
  159. }
  160. // Used to apply the desired effect to all entities present in one trigger of the specified type
  161. // NOTE : This is really not optimal, if you want to add new trigger types, you will have to test for them...
  162. static void TriggerEffect( EntityAI insider, typename triggerType ) {}
  163. #ifdef DIAG_DEVELOPER
  164. // overriden so it doesnt refresh the shape every call while keeping the insider coloring functional
  165. override void DebugDmgTrigger( vector pos, vector orientation, vector min, vector max, float radius, string dmgType, array<ref TriggerInsider> insiders)
  166. {
  167. bool enableDebug = DiagMenu.GetBool(DiagMenuIDs.TRIGGER_DEBUG);
  168. if (enableDebug)
  169. {
  170. if (GetGame().IsMultiplayer() && GetGame().IsServer())
  171. return;
  172. if (!m_DebugShapeActive)
  173. {
  174. m_DbgShape = DrawDebugShape(pos, min, max, radius, COLOR_GREEN_A);
  175. m_DebugShapeActive = true;
  176. }
  177. if (GetGame().IsMultiplayer() || GetGame().IsServer())
  178. m_dbgInsiders = insiders;
  179. if (m_dbgInsiders.Count() > 0)
  180. m_DbgShape.SetColor(COLOR_YELLOW_A);
  181. else
  182. m_DbgShape.SetColor(COLOR_GREEN_A);
  183. }
  184. else if (m_DebugShapeActive)
  185. {
  186. CleanupDebugShapes(dbgTargets);
  187. m_DebugShapeActive = false;
  188. }
  189. }
  190. #endif
  191. }