Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DestructionDiagComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Destruction")]
5
6class SCR_DestructionDiagComponent : ScriptComponent
7{
8#ifdef ENABLE_DIAG
9 protected static const string DAMAGE_TYPE_NAMES[10] = { "TRUE", "COLLISION", "MELEE", "KINETIC", "FRAGMENTATION", "EXPLOSIVE", "INCENDIARY", "FIRE", "REGENERATION", "BLEEDING" };
10 protected ref array<IEntity> m_aToDamage = {};
11
12 //------------------------------------------------------------------------------------------------
13 override void EOnDiag(IEntity owner, float timeSlice)
14 {
15 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_DESTRUCTION_ENABLE_DIAG))
16 {
17 TraceParam params = new TraceParam();
19
20 DbgUI.Begin("Destruction");
21
22 float damageToDeal = 1000, range = 20;
23 EDamageType damageType;
24 DbgUI.InputFloat("Damage to deal", damageToDeal);
25
26 DbgUI.InputFloat("Range", range);
27
28 DbgUI.InputInt("Damage type", damageType);
29
30 DbgUI.Spacer(8);
31
32 DbgUI.Text("Damage types:");
33 DbgUI.Text("0 = TRUE");
34 DbgUI.Text("1 = COLLISION");
35 DbgUI.Text("2 = MELEE");
36 DbgUI.Text("3 = KINETIC");
37 DbgUI.Text("4 = FRAGMENTATION");
38 DbgUI.Text("5 = EXPLOSIVE");
39 DbgUI.Text("6 = INCENDIARY");
40 DbgUI.Text("7 = FIRE");
41 DbgUI.Text("8 = REGENERATION");
42 DbgUI.Text("9 = BLEEDING");
43
44 DbgUI.Spacer(8);
45
46 if (params.TraceEnt)
47 {
48 DbgUI.Text("Damage threshold: " + GetDamageThreshold(params));
49 DbgUI.Text("Damage reduction: " + GetDamageReduction(params));
50 ShowDamageTypeMultipliers(params);
51 }
52
53 if (DbgUI.Button("Deal damage in range"))
54 DealDamageRange(damageToDeal, range, damageType);
55
56 if (DbgUI.Button("Deal damage under cursor"))
57 DealDamageUnderCursor(damageToDeal, damageType, params);
58
59 if (DbgUI.Button("Set 1 HP in range"))
60 SetOneHitPoint(range);
61 DbgUI.End();
62 }
63 }
64
65 //------------------------------------------------------------------------------------------------
68 void ShowDamageTypeMultipliers(TraceParam params)
69 {
70 SCR_DestructibleEntity destructibleEntity = SCR_DestructibleEntity.Cast(params.TraceEnt);
71 if (destructibleEntity)
72 {
73 for (int i = 0; i < 10; i++)
74 {
75 DbgUI.Text(DAMAGE_TYPE_NAMES[i] + ": " + destructibleEntity.GetDamageMultiplier(i));
76 }
77 }
78
79 SCR_DestructionDamageManagerComponent destructionComponent = SCR_DestructionDamageManagerComponent.Cast(params.TraceEnt.FindComponent(SCR_DestructionDamageManagerComponent));
80 if (destructionComponent)
81 {
82 HitZone hitzone = destructionComponent.GetHitZone(params.ColliderName);
83 if (!hitzone)
84 hitzone = destructionComponent.GetDefaultHitZone();
85
86 for (int i = 0; i < 10; i++)
87 {
88 DbgUI.Text(DAMAGE_TYPE_NAMES[i] + ": " + hitzone.GetDamageMultiplier(i));
89 }
90 }
91 }
92
93 //------------------------------------------------------------------------------------------------
96 float GetDamageReduction(TraceParam params)
97 {
98 SCR_DestructibleEntity destructibleEntity = SCR_DestructibleEntity.Cast(params.TraceEnt);
99 if (destructibleEntity)
100 return destructibleEntity.GetDamageReduction();
101
102 SCR_DestructionDamageManagerComponent destructionComponent = SCR_DestructionDamageManagerComponent.Cast(params.TraceEnt.FindComponent(SCR_DestructionDamageManagerComponent));
103 if (destructionComponent)
104 {
105 HitZone hitZone = destructionComponent.GetHitZone(params.ColliderName);
106 if (!hitZone)
107 hitZone = destructionComponent.GetDefaultHitZone();
108
109 return hitZone.GetDamageReduction();
110 }
111
112 return 0;
113 }
114
115 //------------------------------------------------------------------------------------------------
118 float GetDamageThreshold(TraceParam params)
119 {
120 SCR_DestructibleEntity destructibleEntity = SCR_DestructibleEntity.Cast(params.TraceEnt);
121 if (destructibleEntity)
122 return destructibleEntity.GetDamageThreshold();
123
124 SCR_DestructionDamageManagerComponent destructionComponent = SCR_DestructionDamageManagerComponent.Cast(params.TraceEnt.FindComponent(SCR_DestructionDamageManagerComponent));
125 if (destructionComponent)
126 {
127 HitZone hitZone = destructionComponent.GetHitZone(params.ColliderName);
128 if (!hitZone)
129 hitZone = destructionComponent.GetDefaultHitZone();
130
131 return hitZone.GetDamageThreshold();
132 }
133
134 return 0;
135 }
136
137 //------------------------------------------------------------------------------------------------
139 void GetCameraMat(out vector mat[4])
140 {
141 CameraManager cameraManager = GetGame().GetCameraManager();
142 if (!cameraManager)
143 return;
144
145 CameraBase currentCamera = cameraManager.CurrentCamera();
146 if (!currentCamera)
147 return;
148
149 currentCamera.GetTransform(mat);
150 }
151
152 //------------------------------------------------------------------------------------------------
155 void TraceEntity(TraceParam params)
156 {
157 vector cameraMat[4];
158 GetCameraMat(cameraMat);
159
160 params.Start = cameraMat[3];
161 params.End = params.Start + cameraMat[2] * 10; // 10m trace
162 params.LayerMask = EPhysicsLayerDefs.Projectile;
163 params.Exclude = GetGame().GetPlayerController().GetControlledEntity();
164 params.Flags = TraceFlags.ENTS;
165
166 GetOwner().GetWorld().TraceMove(params, null);
167 }
168
169 //------------------------------------------------------------------------------------------------
174 void DealDamageUnderCursor(float damageToDeal, EDamageType damageType, notnull TraceParam params)
175 {
176 if (!params.TraceEnt)
177 return;
178
179 DealDamage(params.TraceEnt, damageToDeal, damageType, params.SurfaceProps);
180 }
181
182 //------------------------------------------------------------------------------------------------
185 float GetHealth(IEntity entity)
186 {
187 SCR_DestructibleEntity destructibleEntity = SCR_DestructibleEntity.Cast(entity);
188 if (destructibleEntity)
189 return destructibleEntity.GetCurrentHealth();
190
191 SCR_DestructionDamageManagerComponent destructionComponent = SCR_DestructionDamageManagerComponent.Cast(entity.FindComponent(SCR_DestructionDamageManagerComponent));
192 if (destructionComponent)
193 return destructionComponent.GetHealth();
194
195 return 1;
196 }
197
198 //------------------------------------------------------------------------------------------------
200 void SetOneHitPoint(float range)
201 {
202 vector cameraMat[4];
203 GetCameraMat(cameraMat);
204
205 GetGame().GetWorld().QueryEntitiesBySphere(cameraMat[3], range, AddEntity, FilterEntity);
206
207 for (int i = m_aToDamage.Count() - 1; i >= 0; i--)
208 {
209 DealDamage(m_aToDamage[i], GetHealth(m_aToDamage[i]) - 1, EDamageType.TRUE, null);
210 }
211
212 m_aToDamage.Clear();
213 }
214
215 //------------------------------------------------------------------------------------------------
221 void DealDamage(IEntity entity, float damageToDeal, EDamageType damageType, SurfaceProperties surfaceProperties)
222 {
223 vector hitPosDirNorm[3];
224
225 SCR_DestructibleEntity destructibleEntity = SCR_DestructibleEntity.Cast(entity);
226 if (destructibleEntity)
227 destructibleEntity.HandleDamage(damageType, damageToDeal, hitPosDirNorm);
228
229 SCR_DestructionDamageManagerComponent destructionComponent = SCR_DestructionDamageManagerComponent.Cast(entity.FindComponent(SCR_DestructionDamageManagerComponent));
230 if (destructionComponent)
231 {
232 SCR_DamageContext damageContext = new SCR_DamageContext(damageType, damageToDeal, hitPosDirNorm, entity, null, null, surfaceProperties, -1, -1);
233
234 destructionComponent.HandleDamage(damageContext);
235 }
236 }
237
238 //------------------------------------------------------------------------------------------------
243 void DealDamageRange(float damageToDeal, float range, EDamageType damageType)
244 {
245 vector cameraMat[4];
246 GetCameraMat(cameraMat);
247
248 GetGame().GetWorld().QueryEntitiesBySphere(cameraMat[3], range, AddEntity, FilterEntity);
249
250 foreach (IEntity toDamage : m_aToDamage)
251 {
252 DealDamage(toDamage, damageToDeal, damageType, null);
253 }
254
255 m_aToDamage.Clear();
256 }
257
258 //------------------------------------------------------------------------------------------------
262 bool AddEntity(IEntity e)
263 {
264 m_aToDamage.Insert(e);
265
266 return true;
267 }
268
269 //------------------------------------------------------------------------------------------------
273 bool FilterEntity(IEntity e)
274 {
275 if (SCR_DestructibleEntity.Cast(e) || e.FindComponent(SCR_DestructionDamageManagerComponent))
276 return true;
277
278 return false;
279 }
280
281 //------------------------------------------------------------------------------------------------
282 override void OnPostInit(IEntity owner)
283 {
284 super.OnPostInit(owner);
285
286 DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_DESTRUCTION_ENABLE_DIAG, "", "Enable destruction diag", "Destruction");
287
288 ConnectToDiagSystem(owner);
289 }
290
291 //------------------------------------------------------------------------------------------------
292 override void OnDelete(IEntity owner)
293 {
295
296 super.OnDelete(owner);
297 }
298#endif
299}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
ArmaReforgerScripted GetGame()
Definition game.c:1398
bool FilterEntity(IEntity ent)
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
SCR_EditableEntityComponent TraceEntity(vector cursorPos)
float GetDamageThreshold()
float GetDamageReduction()
void SCR_DestructibleEntity(IEntitySource src, IEntity parent)
float GetHealth()
enum EVehicleType IEntity
void DisconnectFromDiagSystem(IEntity owner)
void ConnectToDiagSystem(IEntity owner)
proto external Managed FindComponent(typename typeName)
proto external BaseWorld GetWorld()
void EOnDiag(IEntity owner, float timeSlice)
proto external GenericEntity GetOwner()
Get owner entity.
EDamageType
Definition EDamageType.c:13
TraceFlags
Definition TraceFlags.c:13