Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
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
4 {
5  protected AreaDamageBase m_AreaDamage;
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 
16  protected ref array<string> m_HitZones;
17  protected ref array<string> m_RaycastSources;
18  protected ref array<typename> m_DamageableTypes
19 
20  protected ref Timer m_LoopTimer;
21  protected ref Timer m_DeferTimer;
22 
23  void AreaDamageBase(EntityAI parent)
24  {
25  m_AreaDamage = this;
26 
27  m_PlayerDamage = 0.0;
28  m_OthersDamage = 0.0;
29 
30  m_AmmoName = "MeleeDamage";
31  m_DamageType = DT_CUSTOM;
32 
33  m_LoopInterval = 1.0;
34  m_DeferDuration = 1.0;
35 
36  m_HitZones = new array<string>;
37  m_RaycastSources = new array<string>;
38  m_DamageableTypes = new array<typename>;
39  m_DamageableTypes.Insert(DayZPlayer);
40 
41  m_LoopTimer = new Timer(CALL_CATEGORY_SYSTEM);
42  m_DeferTimer = new Timer(CALL_CATEGORY_SYSTEM);
43 
44  m_TriggerBaseClass = "AreaDamageTrigger";
45  }
46 
48  void OnEnter(Object object)
49  {
50  if ( GetGame().IsServer() )
51  {
52  OnEnterServer(object);
53  }
54  else
55  {
56  OnEnterClient(object);
57  }
58  }
59  void OnEnterClient(Object object) {}
60  void OnEnterServer(Object object) {}
61 
62  void OnLeave(Object object)
63  {
64  if ( GetGame().IsServer() )
65  {
66  OnLeaveServer(object);
67  }
68  else
69  {
70  OnLeaveClient(object);
71  }
72  }
73 
74  void OnLeaveClient(Object object) {}
75  void OnLeaveServer(Object object)
76  {
78  if ( m_DeferTimer && m_DeferTimer.IsRunning() )
79  {
80  m_DeferTimer.Stop();
81  }
82  if ( m_LoopTimer && m_LoopTimer.IsRunning() )
83  {
84  m_LoopTimer.Stop();
85  }
86  }
87 
88  protected void EvaluateDamage_Loop(Object object)
89  {
90  m_LoopTimer.Run(m_LoopInterval, this, "EvaluateDamage", new Param1<Object>(object), true);
91  }
92 
93  protected void EvaluateDamage_Defer(Object object)
94  {
95  m_DeferTimer.Run(m_DeferDuration, this, "EvaluateDamage", new Param1<Object>(object), false);
96  }
97 
98  protected void EvaluateDamage_DeferLoop(Object object)
99  {
100  m_DeferTimer.Run(m_DeferDuration, this, "EvaluateDamage_Loop", new Param1<Object>(object), false);
101  }
102 
103  protected void EvaluateDamage(Object object)
104  {
105  string hitzone;
106 
107  if ( m_RaycastSources.Count() )
108  {
109  hitzone = GetRaycastedHitZone(object, m_RaycastSources);
110  EvaluateDamage_Common(object, hitzone);
111  }
112  else
113  {
114  hitzone = GetRandomHitZone(m_HitZones);
115  EvaluateDamage_Common(object, hitzone);
116  }
117  }
118 
119  protected void EvaluateDamage_Common(Object object, string hitzone)
120  {
121  if ( object && object.IsAlive() )
122  {
123  if ( object.IsAnyInherited( m_DamageableTypes ) )
124  {
125  //If we are hitting an infected or animal, we increase the damage dealt as they do not bleed
126  //Change is multiplier
127  /*DayZInfected dayzInfected = DayZInfected.Cast(object);
128  DayZAnimal dayzAnimal = DayZAnimal.Cast(object);
129  EntityAI eai = EntityAI.Cast(object);
130  if ( dayzInfected || dayzAnimal )
131  {
132  //Agents should not take damage from fireplace, but just in case, keep multiplier relatively low
133  if ( hitzone )
134  {
135  eai.ProcessDirectDamage(m_DamageType, EntityAI.Cast(m_ParentObject), hitzone, m_AmmoName, "0.5 0.5 0.5", 8);
136  }
137  else
138  eai.ProcessDirectDamage(m_DamageType, EntityAI.Cast(m_ParentObject), "", m_AmmoName, "0.5 0.5 0.5", 8);
139  }
140  else*/
141  {
142  object.ProcessDirectDamage(m_DamageType, m_ParentObject, hitzone, m_AmmoName, "0.5 0.5 0.5", 1);
143  }
145  }
146  }
147  }
148 
149 
153 
154  protected string GetRandomHitZone(array<string> hitzones)
155  {
156  Math.Randomize(-1);
157  int idx = Math.RandomInt( 0, 100 ) % hitzones.Count();
158 
159  return hitzones[idx];
160  }
161 
162  protected string GetRaycastedHitZone(Object victim, array<string> raycast_sources_str)
163  {
164 
165  // Vertical raycast start positions: Center, North East, North West, South East, South West
166  //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"};
167 
168  string hitzone;
169  vector contact_pos;
170  vector contact_dir;
171  int contactComponent;
172  bool isSteppedOn = false;
173 
174  array<vector> raycast_sources = new array<vector>;
175  ref set<Object> victims = new set<Object>;
176 
177  // convert Array of string to array of Vectors
178  for ( int v = 0; v < raycast_sources_str.Count(); ++v)
179  {
180  raycast_sources.Insert(raycast_sources_str[v].ToVector());
181  }
182 
183  for ( int i = 0; i < raycast_sources.Count(); ++i )
184  {
185  vector raycast_start_pos = m_AreaDamageTrigger.ModelToWorld( raycast_sources.Get(i) );
186  vector raycast_end_pos = "0 0.5 0" + raycast_start_pos;
187 
188  //#ifdef DEVELOPER
189  //Debug.DrawArrow( raycast_start_pos, raycast_end_pos );
190  //#endif
191  DayZPhysics.RaycastRV( raycast_start_pos, raycast_end_pos, contact_pos, contact_dir, contactComponent, victims , null, m_AreaDamageTrigger, true, false, ObjIntersectIFire);
192 
193  for ( int j = 0; j < victims.Count(); ++j )
194  {
195  Object contact_obj = victims.Get(j);
196 
197  if ( contact_obj.IsAnyInherited(m_DamageableTypes) )
198  {
199  isSteppedOn = true;
200  break;
201  }
202  }
203 
204  if ( isSteppedOn )
205  {
206  EntityAI eai = EntityAI.Cast(victim);
207  if ( eai )
208  {
209  hitzone = eai.GetDamageZoneNameByComponentIndex(contactComponent);
210  break;
211  }
212  }
213  }
214 
215  if ( isSteppedOn )
216  {
217  return hitzone;
218  }
219  else
220  {
221  // Damage random leg since we don't know what part of player's body was caught in the trap.
222  string dmg_zone_rnd = "LeftFoot";
223  if ( Math.RandomIntInclusive(0, 1) == 1 )
224  dmg_zone_rnd = "RightFoot";
225  return dmg_zone_rnd;
226  }
227  }
228 
232 
233 #ifdef DEVELOPER
234  ref array<Shape> triggerAreaShapes = new array<Shape>();
235 
236  void EnableDebug(bool pState = false)
237  {
238  //if (GetGame() && (!GetGame().IsClient() || GetGame().IsMultiplayer()))
239  //return;
240 
241  if ( pState )
242  {
243  Debug_DrawArea();
244  }
245  else
246  {
247  Debug_CleanupShapes(triggerAreaShapes);
248  }
249  }
250 
251  protected void Debug_DrawArea()
252  {
255 
256  triggerAreaShapes.Insert(Debug.DrawBox(min, max));
257  }
258 
259  private void Debug_CleanupShapes(array<Shape> shapesArr)
260  {
261  for ( int it = 0; it < shapesArr.Count(); ++it )
262  {
263  Debug.RemoveShape( shapesArr[it] );
264  }
265 
266  shapesArr.Clear();
267  }
268 #endif
269 }
PostDamageActions
override void PostDamageActions()
Usually called from AreaDamageComponent.
Definition: areadamagemanager.c:206
GetGame
proto native CGame GetGame()
CALL_CATEGORY_SYSTEM
const int CALL_CATEGORY_SYSTEM
Definition: tools.c:8
m_ExtentMin
protected vector m_ExtentMin
Definition: areadamagemanager.c:15
m_ParentObject
protected Object m_ParentObject
Cached parent.
Definition: effect.c:39
m_AreaPosition
protected vector m_AreaPosition
Definition: areadamagemanager.c:17
DayZPlayer
Definition: dayzplayerimplement.c:72
m_AmmoName
string m_AmmoName
Definition: areadamagecomponent.c:12
vector
Definition: enconvert.c:105
EnableDebug
void EnableDebug(bool pEnabled)
Definition: pluginpresencenotifier.c:122
m_AreaDamageTrigger
protected AreaDamageTriggerBase m_AreaDamageTrigger
Definition: areadamagemanager.c:11
Object
Definition: objecttyped.c:1
m_TriggerBaseClass
protected string m_TriggerBaseClass
Definition: areadamagemanager.c:20
m_DeferDuration
AreaDamageOnce m_DeferDuration
Time the damage should be deferred in seconds.
m_ExtentMax
protected vector m_ExtentMax
Definition: areadamagemanager.c:16
array< string >
m_AreaDamage
protected ref AreaDamageManager m_AreaDamage
Definition: fireplacebase.c:214
Debug
Definition: debug.c:13
DayZPhysics
Definition: dayzphysics.c:123
AreaDamageManager
void AreaDamageManager(EntityAI parent)
Definition: areadamagemanager.c:22
Timer
Definition: dayzplayerimplement.c:62
Math
Definition: enmath.c:6
AreaDamageBase
Definition: areadamage.c:3
m_DamageType
int m_DamageType
Definition: areadamagecomponent.c:11
EntityAI
Definition: building.c:5