Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
contaminatedtrigger.c
Go to the documentation of this file.
1 // In this file you will find both Static and Dynamic contaminated area triggers
2 class ContaminatedTrigger extends EffectTrigger
3 {
4  const float DAMAGE_TICK_RATE = 10;//deal damage every n-th second
5 
6  // ----------------------------------------------
7  // TRIGGER EVENTS
8  // ----------------------------------------------
9 
10  override void OnEnterServerEvent( TriggerInsider insider )
11  {
12  super.OnEnterServerEvent( insider );
13  //Print("Entered A " + GetType());
14  if ( insider )
15  {
16  DayZCreatureAI creature = DayZCreatureAI.Cast( insider.GetObject() );
17 
18  if (creature)
19  creature.IncreaseEffectTriggerCount();
20  }
21 
22  }
23 
24  override void OnLeaveServerEvent( TriggerInsider insider )
25  {
26  super.OnLeaveServerEvent( insider );
27  //Print("Left A " + GetType());
28  if ( insider )
29  {
30  DayZCreatureAI creature = DayZCreatureAI.Cast( insider.GetObject() );
31 
32  if (creature)
33  creature.DecreaseEffectTriggerCount();
34 
35  }
36  }
37 
38  override void OnEnterClientEvent( TriggerInsider insider )
39  {
40  super.OnEnterClientEvent( insider );
41  }
42 
43  override void OnLeaveClientEvent( TriggerInsider insider )
44  {
45  super.OnLeaveClientEvent( insider );
46  }
47 
48 
49  override void OnStayStartServerEvent(int nrOfInsiders)
50  {
51  m_TimeAccuStay += m_DeltaTime;
52  if (m_TimeAccuStay > DAMAGE_TICK_RATE)
53  {
54  m_DealDamageFlag = true;
55  //this is where we would normally reset the m_TimeAccuStay, but we need the value as deltaT when dealing damage to the insiders, so we reset it only after the insider update in OnStayFinishServerEvent
56  }
57 
58  }
59 
60  override void OnStayFinishServerEvent()
61  {
62  if(m_DealDamageFlag)//the flag was previously set to true, the insiders have been updated at this point, reset the flag and the timer as well
63  {
64  m_TimeAccuStay = 0;
65  m_DealDamageFlag = false;
66  }
67  }
68 
69  override void OnStayServerEvent(TriggerInsider insider, float deltaTime)
70  {
71  if ( m_DealDamageFlag )
72  {
73  DayZCreatureAI creature = DayZCreatureAI.Cast( insider.GetObject());
74  if(creature && creature.m_EffectTriggerCount != 0)
75  creature.DecreaseHealth("", "", GameConstants.AI_CONTAMINATION_DMG_PER_SEC * m_TimeAccuStay / creature.m_EffectTriggerCount);// we devide by m_EffectTriggerCount for multiple trigger presence(overlapping triggers)
76  }
77  }
78 
79  override string GetAmbientSoundsetName()
80  {
81  return "ContaminatedArea_SoundSet";
82  }
83 
84 
85 }
86 
87 class ContaminatedTrigger_Dynamic : ContaminatedTrigger
88 {
89  protected int m_AreaState; // Used to get the state from linked area and update effects
90 
92  {
93  RegisterNetSyncVariableInt("m_AreaState");
94 
95  // Register in the trigger effect manager
96  m_Manager = TriggerEffectManager.GetInstance();
97  m_Manager.RegisterTriggerType( this );
98  }
99 
100  void SetAreaState( int state )
101  {
102  m_AreaState = state;
103  SetSynchDirty();
104  }
105 
106 
107  override protected void OnStayClientEvent(TriggerInsider insider, float deltaTime)
108  {
109  //no super, overriding parent behaviour
110  if ( insider.GetObject().IsMan() )
111  {
112  PlayerBase playerInsider = PlayerBase.Cast( insider.GetObject() );
113 
114  // We will only handle the controlled player, as effects are only relevant to this player instance
115  if ( playerInsider.IsControlledPlayer() )
116  {
117  // We check if we are not in the standard LIVE state
118  bool nonDefaultState = m_AreaState > eAreaDecayStage.LIVE;
119  if ( nonDefaultState )
120  {
121  // if not we check the specific state and update local effect values
122  int localPartBirthRate;
123  if ( m_AreaState == eAreaDecayStage.DECAY_START )
124  localPartBirthRate = 20;
125  else
126  localPartBirthRate = 10;
127 
128  playerInsider.RequestTriggerEffect(this, m_PPERequester, m_AroundPartId, m_TinyPartId, GetAmbientSoundsetName(), nonDefaultState, localPartBirthRate );
129  }
130  else
131  playerInsider.RequestTriggerEffect(this, m_PPERequester, m_AroundPartId, m_TinyPartId, GetAmbientSoundsetName() );
132  }
133  }
134  }
135 
136 
137 
138  override void OnVariablesSynchronized()
139  {
140  super.OnVariablesSynchronized();
141 
142  // Is the controlled player inside when trigger is synchronized
143  for ( int i = 0; i < GetInsiders().Count(); i++ )
144  {
145  PlayerBase playerInsider = PlayerBase.Cast( m_insiders.Get( i ).GetObject() );
146  if ( playerInsider )
147  {
148  if ( playerInsider.IsControlledPlayer() )
149  {
150  // Update Local particle effects
151  bool nonDefaultState = m_AreaState > eAreaDecayStage.LIVE;
152  if ( nonDefaultState )
153  {
154  int localPartBirthRate;
155  if ( m_AreaState == eAreaDecayStage.DECAY_START )
156  localPartBirthRate = 20;
157  else
158  localPartBirthRate = 10;
159 
160  //Update the local effects
161  playerInsider.RequestTriggerEffect(this, m_PPERequester, m_AroundPartId, m_TinyPartId, GetAmbientSoundsetName(), nonDefaultState, localPartBirthRate, true );
162  }
163  return;
164  }
165  }
166  }
167  }
168 }
169 
170 
171 class ContaminatedTrigger_Local : ContaminatedTrigger
172 {
173  override string GetAmbientSoundsetName()
174  {
175  return "";
176  }
177 
178 }
OnEnterClientEvent
override void OnEnterClientEvent(TriggerInsider insider)
Definition: areadamagemanager.c:111
ContaminatedTrigger_Local
Definition: contaminatedtrigger.c:171
TriggerInsider
The object which is in a trigger and its metadata.
Definition: trigger.c:2
m_Manager
ModifiersManager m_Manager
Definition: modifierbase.c:12
OnEnterServerEvent
class TriggerInsider OnEnterServerEvent
Definition: traptrigger.c:29
ContaminatedTrigger_Dynamic
void ContaminatedTrigger_Dynamic()
Definition: contaminatedtrigger.c:91
SetAreaState
void SetAreaState(int state)
Definition: contaminatedtrigger.c:100
DayZCreatureAI
do not process rotations !
Definition: dayzanimal.c:606
eAreaDecayStage
eAreaDecayStage
Definition: contaminatedarea_dynamic.c:1
OnVariablesSynchronized
override void OnVariablesSynchronized()
Definition: contaminatedtrigger.c:138
OnStayStartServerEvent
override void OnStayStartServerEvent(int nrOfInsiders)
Definition: areadamagemanager.c:125
OnStayFinishServerEvent
override void OnStayFinishServerEvent()
Definition: areadamagemanager.c:161
TriggerEffectManager
Definition: triggereffectmanager.c:3
PlayerBase
Definition: playerbaseclient.c:1
OnStayClientEvent
override protected void OnStayClientEvent(TriggerInsider insider, float deltaTime)
Definition: contaminatedtrigger.c:107
OnLeaveClientEvent
override void OnLeaveClientEvent(TriggerInsider insider)
Definition: areadamagemanager.c:183
GameConstants
Definition: constants.c:612
EffectTrigger
Definition: contaminatedtrigger.c:2
OnLeaveServerEvent
override void OnLeaveServerEvent(TriggerInsider insider)
Definition: areadamagemanager.c:179
m_PPERequester
PPERequester_PainBlur m_PPERequester
Definition: bullethitreaction.c:57
m_AreaState
class ContaminatedTrigger extends EffectTrigger m_AreaState
OnStayServerEvent
override void OnStayServerEvent(TriggerInsider insider, float deltaTime)
Definition: areadamagemanager.c:143