Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
effecttrigger.c
Go to the documentation of this file.
1 // Base class for "Effect triggers"
2 // Registers in TriggerEffectManager and handles parameter setting through cfgEffectArea.json file
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 
15  void EffectTrigger()
16  {
17  RegisterNetSyncVariableInt("m_AroundPartId");
18  RegisterNetSyncVariableInt("m_TinyPartId");
19  RegisterNetSyncVariableInt("m_PPERequester");
20  RegisterNetSyncVariableInt("m_EffectsPriority");
21 
22  m_Manager = TriggerEffectManager.GetInstance();
23  m_Manager.RegisterTriggerType( this );
24  }
25 
26  // ----------------------------------------------
27  // CUSTOM EVENTS
28  // ----------------------------------------------
29 
30  void SetLocalEffects( int aroundPartId, int tinyPartId, int ppeRequesterIdx )
31  {
32  m_AroundPartId = aroundPartId;
33  m_TinyPartId = tinyPartId;
34  m_PPERequester = ppeRequesterIdx;
35 
36  SetSynchDirty();
37  }
38 
39  EffectArea GetEffectArea()
40  {
41  return m_EffectArea;
42  }
43 
44  void Init(EffectArea area, int priority)
45  {
46  m_EffectArea = area;
47  m_EffectsPriority = priority;
48  }
49 
50  int GetEffectsPriority()
51  {
52  return m_EffectsPriority;
53  }
54 
55  string GetAmbientSoundsetName()
56  {
57  return "";
58  }
59 
60  void SetupClientEffects(bool enable, notnull PlayerBase player)
61  {
62  if ( !m_Manager.IsPlayerInTriggerType( player, this ) )
63  {
64  if (enable)
65  {
66  player.SetContaminatedEffectEx( true, m_PPERequester, m_AroundPartId, m_TinyPartId, GetAmbientSoundsetName() );
67  }
68  else
69  {
70  player.SetContaminatedEffectEx( false, m_PPERequester );
71  }
72  }
73  }
74 
75 
76  // ----------------------------------------------
77  // TRIGGER EVENTS
78  // ----------------------------------------------
79 
80  override void EOnFrame(IEntity other, float timeSlice)
81  {
82  m_DeltaTime = timeSlice;
83  }
84 
85  override bool CanAddObjectAsInsider(Object object)
86  {
87  #ifdef SERVER
88  DayZCreatureAI creature = DayZCreatureAI.Cast( object );
89  if(creature)
90  {
91  return !creature.ResistContaminatedEffect();
92  }
93  else
94  {
95  PlayerBase player = PlayerBase.Cast(object);
96  return player != null;
97  }
98  #else
99  PlayerBase player = PlayerBase.Cast(object);
100  return (player && player.IsControlledPlayer());
101  #endif
102  }
103 
104  override protected void OnStayClientEvent(TriggerInsider insider, float deltaTime)
105  {
106  super.OnStayClientEvent(insider, deltaTime);
107  PlayerBase player = PlayerBase.Cast(insider.GetObject());
108  if (player)
109  player.RequestTriggerEffect(this, m_PPERequester, m_AroundPartId, m_TinyPartId, GetAmbientSoundsetName() );
110  }
111 
112  override void OnEnterServerEvent( TriggerInsider insider )
113  {
114  super.OnEnterServerEvent( insider );
115 
116  // We don't need to test the trigger count as Modifiers handle such cases already
117  if ( insider )
118  {
119  PlayerBase playerInsider = PlayerBase.Cast( insider.GetObject() );
120 
121  if(playerInsider)
122  {
123 
124  m_Manager.OnPlayerEnter( playerInsider, this );
125  }
126 
127  }
128 
129  }
130 
131  override void OnEnterClientEvent( TriggerInsider insider )
132  {
133  super.OnEnterClientEvent( insider );
134 
135  if ( insider )
136  {
137  PlayerBase playerInsider = PlayerBase.Cast( insider.GetObject() );
138 
139  // We will only handle the controlled player, as effects are only relevant to this player instance
140  if (playerInsider && playerInsider.IsControlledPlayer() )
141  {
142  //SetupClientEffects(true, playerInsider);
143  // We then handle the update of player trigger state in manager
144  m_Manager.OnPlayerEnter( playerInsider, this );
145  }
146  }
147  }
148 
149 
150  override void OnLeaveServerEvent( TriggerInsider insider )
151  {
152  super.OnLeaveServerEvent( insider );
153 
154  if ( insider )
155  {
156  PlayerBase playerInsider = PlayerBase.Cast( insider.GetObject() );
157 
158  if ( playerInsider )
159  m_Manager.OnPlayerExit( playerInsider, this );
160  }
161  }
162 
163 
164 
165  override void OnLeaveClientEvent( TriggerInsider insider )
166  {
167  super.OnLeaveClientEvent( insider );
168 
169  if ( insider )
170  {
171  // Make sure you pass the set variable for PPE effect
172  // It will not remove the correct one if START and STOP don't point to the same Requester
173  PlayerBase playerInsider = PlayerBase.Cast( insider.GetObject() );
174 
175  // We will only handle the controlled player, as effects are only relevant to this player instance
176  if ( playerInsider && playerInsider.IsControlledPlayer() )
177  {
178  // We first handle the update of player trigger state in manager
179  m_Manager.OnPlayerExit( playerInsider, this );
180  //SetupClientEffects(false, playerInsider);
181  }
182  }
183  }
184 
185  // We remove from trigger update DEAD or RESISTANT entities to limit the amount of entities to update
186  override bool ShouldRemoveInsider( TriggerInsider insider )
187  {
188  return !insider.GetObject().IsAlive();
189  }
190 
191  // Used to apply the desired effect to all entities present in one trigger of the specified type
192  // NOTE : This is really not optimal, if you want to add new trigger types, you will have to test for them...
193  static void TriggerEffect( EntityAI insider, typename triggerType ) {}
194 }
TriggerInsider
The object which is in a trigger and its metadata.
Definition: trigger.c:2
m_Manager
ModifiersManager m_Manager
Definition: modifierbase.c:12
DayZCreatureAI
do not process rotations !
Definition: dayzanimal.c:606
IEntity
Definition: enentity.c:164
EffectArea
Definition: effectarea.c:36
TriggerEffectManager
Definition: triggereffectmanager.c:3
PlayerBase
Definition: playerbaseclient.c:1
CylinderTrigger
Trigger with cylinder shape.
Definition: cylindertrigger.c:2
Object
Definition: objecttyped.c:1
EffectTrigger
Definition: contaminatedtrigger.c:2
m_PPERequester
PPERequester_PainBlur m_PPERequester
Definition: bullethitreaction.c:57
EntityAI
Definition: building.c:5