DayZ 1.24
Loading...
Searching...
No Matches
AreaDamageLooped.c
Go to the documentation of this file.
1class AreaDamageLooped : AreaDamageManager
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 {
21 }
22
24 override void OnTriggerCreated()
25 {
26 super.OnTriggerCreated();
27
28 m_PreviousTime = g_Game.GetTickTime();
30 }
31
32 override void SetLoopInterval(float time)
33 {
35 }
36
37 override void OnEnterServerEvent(TriggerInsider insider)
38 {
39 super.OnEnterServerEvent(insider);
40
41 // Do direct damaging first time on entering
43 OnEvaluateDamageEx(insider, 1);
44 }
45
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
63 }
64
66 {
67 super.OnStayFinishServerEvent();
68
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
78 {
79 float lastDamaged = 0;
80
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 return m_AmountOfLoops;
99 }
100}
bool OnEvaluateDamageEx(TriggerInsider insider, float deltaTime)
DayZGame g_Game
Definition DayZGame.c:3528
float CalculateDamageScale(TriggerInsider insider, float deltaTime)
override void OnStayServerEvent(TriggerInsider insider, float deltaTime)
float m_AccumulatedTime
How much time has accumulated.
float m_CurrentTime
Current start time in seconds.
override void SetLoopInterval(float time)
override void OnEnterServerEvent(TriggerInsider insider)
override void OnTriggerCreated()
Gets called when the trigger is spawned, so is the start and also a reset.
float m_PreviousTime
Previous start time in seconds.
override void OnStayFinishServerEvent()
int m_AmountOfLoops
Caching of the amount of loops that will be performed in this frame.
override void OnStayStartServerEvent(int nrOfInsiders)
bool m_LoopByObject
Decides if the looping will be using the Object as reference or the time since last update loop.
float m_LoopInterval
Loop interval in seconds.
void AreaDamageLooped(EntityAI parent, bool loopByObject=true)
Extended TriggerInsider for AreaDamageTriggerBase.
The object which is in a trigger and its metadata.
Definition Trigger.c:3