Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
areadamagecomponentraycasted.c
Go to the documentation of this file.
1
2class AreaDamageComponentRaycasted : AreaDamageComponent
3{
4 // Defined in local space of the trigger
5 ref array<vector> m_RaycastSources;
6 vector m_RaycastEndOffset;
7
8 ref array<ref RaycastRVResult> m_RaycastCache;
9 int m_RaycastCachedIndex;
10
11 void AreaDamageComponentRaycasted(AreaDamageManager parent)
12 {
13 m_RaycastSources = new array<vector>;
14 m_RaycastEndOffset = "0 0.5 0";
15
16 m_RaycastCache = new array<ref RaycastRVResult>;
17 m_RaycastCachedIndex = -1;
18 }
19
20 override void OnTriggerCreated()
21 {
22 super.OnTriggerCreated();
23
24 ClearCache();
25 }
26
27 void SetRaycastSources( array<string> raycast_sources )
28 {
29 m_RaycastSources.Clear();
30
31 // convert Array of string to array of Vectors
32 int nrOfSources = raycast_sources.Count();
33 for ( int v = 0; v < nrOfSources; ++v)
34 {
35 m_RaycastSources.Insert(raycast_sources[v].ToVector());
36 }
37 }
38
39 void SetRaycastSourcesVector( array<vector> raycast_sources )
40 {
41 m_RaycastSources = raycast_sources;
42 }
43
44 void SetRaycastLength(float length)
45 {
46 m_RaycastEndOffset = Vector(0, length, 0);
47 }
48
49 override void OnStayFinishServerEvent()
50 {
51 super.OnStayFinishServerEvent();
52
53 ClearCache();
54 }
55
57 {
59 data.Hitzone = GetRaycastedHitZone(object);
60
61 return data;
62 }
63
64 protected void ClearCache()
65 {
66 m_RaycastCache.Clear();
67 m_RaycastCachedIndex = -1;
68 }
69
70 protected string GetRaycastedHitZone(Object victim)
71 {
72 int nrOfCachedResults = m_RaycastSources.Count();
73 for ( int c = 0; c < nrOfCachedResults; ++c )
74 {
75 RaycastRVResult cachedRes = m_RaycastCache[c];
76 if ( cachedRes.obj == victim )
77 return victim.GetDamageZoneNameByComponentIndex(cachedRes.component);
78 }
79
80 int nrOfSources = m_RaycastSources.Count();
82
83 string hitzone = "";
84
85 AreaDamageTriggerBase trigger = m_Parent.GetTrigger();
86
87 RaycastRVParams params = new RaycastRVParams( vector.Zero, vector.Zero, trigger, 0.0 );
88 params.type = ObjIntersectIFire;
89 params.flags = CollisionFlags.ONLYDYNAMIC;
90
91 for ( int i = m_RaycastCachedIndex + 1; i < nrOfSources; ++i )
92 {
93 m_RaycastCachedIndex = i;
94
95 params.begPos = trigger.ModelToWorld( m_RaycastSources[i] );
96 params.endPos = params.begPos + m_RaycastEndOffset;
97
98 if ( DayZPhysics.RaycastRVProxy(params, victims) )
99 {
100 for ( int j = 0; j < victims.Count(); ++j )
101 {
102 RaycastRVResult res = victims[j];
103
104 if (res.obj == victim)
105 hitzone = victim.GetDamageZoneNameByComponentIndex(res.component);
106
107 if (res.obj.IsAnyInherited(m_DamageableTypes))
108 m_RaycastCache.Insert(res);
109 }
110
111 if ( !( hitzone == "") )
112 return hitzone;
113
114 victims.Clear();
115 }
116 }
117
118 return GetFallbackHitZone(victim);
119 }
120
121 protected string GetFallbackHitZone(Object victim)
122 {
123 Error(string.Format("[WARNING] :: [%1] :: [AreaDamageComponentRaycasted] :: No proper HitZone found for damaging %2, using fallback.",
124 m_Parent, Object.GetDebugName(victim)));
125
126 // Fallbacks, currently are implemented assuming that foot/leg damagezones would be desired to damage
127 if ( victim.IsInherited(DayZPlayer) || victim.IsInherited(DayZInfected) )
128 {
129 // Damage random leg since we don't know what part of player's body was caught in the trap.
130 if ( Math.RandomIntInclusive(0, 1) == 1 )
131 return "RightFoot";
132 return "LeftFoot";
133 }
134 else
135 {
136 array<string> damageZones = new array<string>;
137 victim.GetDamageZones(damageZones);
138
139 int nrOfDmgZones = damageZones.Count();
140
141 if (nrOfDmgZones > 0)
142 {
143 for (int z = 0; z < nrOfDmgZones; ++z)
144 {
145 if ( damageZones[z].Contains("Foot") || damageZones[z].Contains("Leg") )
146 return damageZones[z];
147 }
148
149 return damageZones.GetRandomElement();
150 }
151 else
152 return "";
153 }
154 }
155}
Newer implementation equivalent of "AreaDamageRegularRaycasted", hitzone selection only.
AreaDamageComponentData GetAreaDamageComponentData(Object object)
Definition enmath.c:7
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
void Error(string err)
Messagebox with error message.
Definition endebug.c:90
CollisionFlags
Definition endebug.c:141
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
Widget m_Parent
Definition sizetochild.c:92