DayZ 1.24
Loading...
Searching...
No Matches
AreaDamage.c
Go to the documentation of this file.
1// DEPRECATED: Backwards compatibility class to prevent existing mods breaking
2// I wish I could rename this to AreaDamageTimer, but can't, because of backwards compatibility with mods
3class AreaDamageBase : AreaDamageManager
4{
6
7 protected float m_PlayerDamage;
8 protected float m_OthersDamage;
9
10 protected string m_AmmoName;
11 protected int m_DamageType;
12
13 protected float m_LoopInterval;
14 protected float m_DeferDuration;
15
19
22
24 {
25 m_AreaDamage = this;
26
27 m_PlayerDamage = 0.0;
28 m_OthersDamage = 0.0;
29
30 m_AmmoName = "MeleeDamage";
32
33 m_LoopInterval = 1.0;
34 m_DeferDuration = 1.0;
35
40
43
44 m_TriggerBaseClass = "AreaDamageTrigger";
45 }
46
48 void OnEnter(Object object)
49 {
50 if (GetGame().IsServer())
51 OnEnterServer(object);
52 else
53 OnEnterClient(object);
54 }
55 void OnEnterClient(Object object) {}
56 void OnEnterServer(Object object) {}
57
58 void OnLeave(Object object)
59 {
60 if (GetGame().IsServer())
61 OnLeaveServer(object);
62 else
63 OnLeaveClient(object);
64 }
65
66 void OnLeaveClient(Object object) {}
67 void OnLeaveServer(Object object)
68 {
70 if (m_DeferTimer && m_DeferTimer.IsRunning())
71 m_DeferTimer.Stop();
72 if (m_LoopTimer && m_LoopTimer.IsRunning())
73 m_LoopTimer.Stop();
74 }
75
76 protected void EvaluateDamage_Loop(Object object)
77 {
78 m_LoopTimer.Run(m_LoopInterval, this, "EvaluateDamage", new Param1<Object>(object), true);
79 }
80
81 protected void EvaluateDamage_Defer(Object object)
82 {
83 m_DeferTimer.Run(m_DeferDuration, this, "EvaluateDamage", new Param1<Object>(object), false);
84 }
85
86 protected void EvaluateDamage_DeferLoop(Object object)
87 {
88 m_DeferTimer.Run(m_DeferDuration, this, "EvaluateDamage_Loop", new Param1<Object>(object), false);
89 }
90
91 protected void EvaluateDamage(Object object)
92 {
93 string hitzone;
94
95 if (m_RaycastSources.Count())
96 {
99 }
100 else
101 {
104 }
105 }
106
107 protected void EvaluateDamage_Common(Object object, string hitzone)
108 {
109 if (object && object.IsAlive())
110 {
111 if (object.IsAnyInherited(m_DamageableTypes))
112 {
113 //If we are hitting an infected or animal, we increase the damage dealt as they do not bleed
114 //Change is multiplier
115 /*DayZInfected dayzInfected = DayZInfected.Cast(object);
116 DayZAnimal dayzAnimal = DayZAnimal.Cast(object);
117 EntityAI eai = EntityAI.Cast(object);
118 if ( dayzInfected || dayzAnimal )
119 {
120 //Agents should not take damage from fireplace, but just in case, keep multiplier relatively low
121 if ( hitzone )
122 {
123 eai.ProcessDirectDamage(m_DamageType, EntityAI.Cast(m_ParentObject), hitzone, m_AmmoName, "0.5 0.5 0.5", 8);
124 }
125 else
126 eai.ProcessDirectDamage(m_DamageType, EntityAI.Cast(m_ParentObject), "", m_AmmoName, "0.5 0.5 0.5", 8);
127 }
128 else*/
129 {
130 object.ProcessDirectDamage(m_DamageType, m_ParentObject, hitzone, m_AmmoName, "0.5 0.5 0.5", 1);
131 }
133 }
134 }
135 }
136
137
141
143 {
144 Math.Randomize(-1);
145 int idx = Math.RandomInt(0, 100) % hitzones.Count();
146
147 return hitzones[idx];
148 }
149
151 {
152
153 // Vertical raycast start positions: Center, North East, North West, South East, South West
154 //vector raycast_sources[5] = {"0.0 0.1 0.0", "0.2 0.1 0.2", "-.2 0.1 0.2", "0.2 0.1 -.2", "-.2 0.1 -.2"};
155
156 string hitzone;
160 bool isSteppedOn = false;
161
164
165 // convert Array of string to array of Vectors
166 for (int v = 0; v < raycast_sources_str.Count(); ++v)
167 raycast_sources.Insert(raycast_sources_str[v].ToVector());
168
169 for (int i = 0; i < raycast_sources.Count(); ++i)
170 {
173
174 //#ifdef DEVELOPER
175 //Debug.DrawArrow( raycast_start_pos, raycast_end_pos );
176 //#endif
178
179 for (int j = 0; j < victims.Count(); ++j)
180 {
182
183 if (contact_obj.IsAnyInherited(m_DamageableTypes))
184 {
185 isSteppedOn = true;
186 break;
187 }
188 }
189
190 if (isSteppedOn)
191 {
192 EntityAI eai = EntityAI.Cast(victim);
193 if (eai)
194 {
195 hitzone = eai.GetDamageZoneNameByComponentIndex(contactComponent);
196 break;
197 }
198 }
199 }
200
201 if (isSteppedOn)
202 return hitzone;
203 else
204 {
205 // Damage random leg since we don't know what part of player's body was caught in the trap.
206 string dmg_zone_rnd = "LeftFoot";
207 if (Math.RandomIntInclusive(0, 1) == 1)
208 dmg_zone_rnd = "RightFoot";
209 return dmg_zone_rnd;
210 }
211 }
212
216
217#ifdef DEVELOPER
219
220 void EnableDebug(bool pState = false)
221 {
222 //if (GetGame() && (!GetGame().IsClient() || GetGame().IsMultiplayer()))
223 //return;
224
225 if (pState)
227 else
229 }
230
231 protected void Debug_DrawArea()
232 {
235
237 }
238
240 {
241 for (int it = 0; it < shapesArr.Count(); ++it)
243
244 shapesArr.Clear();
245 }
246#endif
247}
vector m_AreaPosition
vector m_ExtentMin
vector m_ExtentMax
string m_TriggerBaseClass
override void PostDamageActions()
Usually called from AreaDamageComponent.
AreaDamageTriggerBase m_AreaDamageTrigger
Object m_ParentObject
Cached parent.
Definition Effect.c:39
void EnableDebug(bool pEnabled)
string GetRaycastedHitZone(Object victim, array< string > raycast_sources_str)
Definition AreaDamage.c:150
void EvaluateDamage_Loop(Object object)
Definition AreaDamage.c:76
void OnEnterClient(Object object)
Definition AreaDamage.c:55
AreaDamageBase m_AreaDamage
Definition AreaDamage.c:5
ref Timer m_DeferTimer
Definition AreaDamage.c:21
void EvaluateDamage_Common(Object object, string hitzone)
Definition AreaDamage.c:107
void OnLeave(Object object)
Definition AreaDamage.c:58
float m_PlayerDamage
Definition AreaDamage.c:7
void EvaluateDamage_Defer(Object object)
Definition AreaDamage.c:81
float m_OthersDamage
Definition AreaDamage.c:8
void OnLeaveServer(Object object)
Definition AreaDamage.c:67
string m_AmmoName
Definition AreaDamage.c:10
void EvaluateDamage_DeferLoop(Object object)
Definition AreaDamage.c:86
void AreaDamageBase(EntityAI parent)
Definition AreaDamage.c:23
float m_LoopInterval
Definition AreaDamage.c:13
ref Timer m_LoopTimer
Definition AreaDamage.c:20
void OnLeaveClient(Object object)
Definition AreaDamage.c:66
void OnEnterServer(Object object)
Definition AreaDamage.c:56
float m_DeferDuration
Definition AreaDamage.c:14
void EvaluateDamage(Object object)
Definition AreaDamage.c:91
ref array< string > m_RaycastSources
Definition AreaDamage.c:17
void OnEnter(Object object)
events
Definition AreaDamage.c:48
string GetRandomHitZone(array< string > hitzones)
Definition AreaDamage.c:142
ref array< string > m_HitZones
Definition AreaDamage.c:16
static proto bool RaycastRV(vector begPos, vector endPos, out vector contactPos, out vector contactDir, out int contactComponent, set< Object > results=NULL, Object with=NULL, Object ignore=NULL, bool sorted=false, bool ground_only=false, int iType=ObjIntersectView, float radius=0.0, CollisionFlags flags=CollisionFlags.NEARESTCONTACT)
Raycasts world by given parameters.
Definition Debug.c:14
static Shape DrawBox(vector pos1, vector pos2, int color=0x1fff7f7f)
Definition Debug.c:401
static void RemoveShape(out Shape shape)
Definition Debug.c:107
Definition EnMath.c:7
proto native CGame GetGame()
static proto int Randomize(int seed)
Sets the seed for the random number generator.
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Definition EnMath.c:54
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8