Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
areadamagelooped.c
Go to the documentation of this file.
2 {
4  protected float m_CurrentTime = 0.0;
6  protected float m_PreviousTime = 0.0;
8  protected float m_AccumulatedTime = 0.0;
10  protected float m_LoopInterval = 1.0;
11 
13  protected int m_AmountOfLoops = 0;
14 
16  protected bool m_LoopByObject = true;
17 
18  void AreaDamageLooped(EntityAI parent, bool loopByObject = true)
19  {
20  m_LoopByObject = loopByObject;
21  }
22 
24  override void OnTriggerCreated()
25  {
26  super.OnTriggerCreated();
27 
28  m_PreviousTime = g_Game.GetTickTime();
29  m_AccumulatedTime = 0.0;
30  }
31 
32  override void SetLoopInterval( float time )
33  {
34  m_LoopInterval = time;
35  }
36 
37  override void OnEnterServerEvent(TriggerInsider insider)
38  {
39  super.OnEnterServerEvent(insider);
40 
41  // Do direct damaging first time on entering
42  if (m_LoopByObject)
43  OnEvaluateDamageEx(insider, 1);
44  }
45 
46  override void OnStayStartServerEvent(int nrOfInsiders)
47  {
48  super.OnStayStartServerEvent(nrOfInsiders);
49 
50  m_CurrentTime = g_Game.GetTickTime();
51  m_AccumulatedTime += m_CurrentTime - m_PreviousTime;
52  m_PreviousTime = m_CurrentTime;
53 
54  m_AmountOfLoops = m_AccumulatedTime / m_LoopInterval;
55  }
56 
57  override void OnStayServerEvent(TriggerInsider insider, float deltaTime)
58  {
59  super.OnStayServerEvent(insider, deltaTime);
60 
61  // As we are using the Ex variant, we can put the logic in CalculateDamageScale
62  OnEvaluateDamageEx(insider, deltaTime);
63  }
64 
65  override void OnStayFinishServerEvent()
66  {
67  super.OnStayFinishServerEvent();
68 
69  m_AccumulatedTime -= m_AmountOfLoops * m_LoopInterval;
70  }
71 
72  // TODO: EMH: OnLeaveServerEvent -> perform the remaining buffered damage to be done?
73 
74  override protected float CalculateDamageScale(TriggerInsider insider, float deltaTime)
75  {
76  // If we want the LoopInterval to be dependant on the Object, we will need their lastDamaged time
77  if (m_LoopByObject)
78  {
79  float lastDamaged = 0;
80 
81  AreaDamageTriggerInsider dInsider;
82  if ( CastTo( dInsider, insider ) )
83  lastDamaged = dInsider.lastDamaged;
84 
85  // First time it is damaged, do full damage
86  if (lastDamaged == 0)
87  return 1;
88 
89  // This way, in case the server lags, it will scale the damage to catch up if necessary
90  // We want to wait until it is at least above 1, to not spam the network with hit messages
91  float damageCoeff = (m_CurrentTime - lastDamaged) / m_LoopInterval;
92  if ( damageCoeff >= 1 )
93  return damageCoeff;
94 
95  return 0;
96  }
97  else
98  {
99  return m_AmountOfLoops;
100  }
101  }
102 }
TriggerInsider
The object which is in a trigger and its metadata.
Definition: trigger.c:2
AreaDamageTriggerInsider
Extended TriggerInsider for AreaDamageTriggerBase.
Definition: areadamagetriggerbase.c:2
OnEvaluateDamageEx
bool OnEvaluateDamageEx(TriggerInsider insider, float deltaTime)
Definition: areadamagemanager.c:218
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
AreaDamageManager
void AreaDamageManager(EntityAI parent)
Definition: areadamagemanager.c:22
AreaDamageLooped
Definition: areadamagelooped.c:1
EntityAI
Definition: building.c:5