Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DestructionDiagComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Destruction")]
2 class SCR_DestructionDiagComponentClass : ScriptComponentClass
3 {
4 }
5 
6 class SCR_DestructionDiagComponent : ScriptComponent
7 {
8 #ifdef ENABLE_DIAG
9  protected 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 
84  if (!hitzone)
85  hitzone = destructionComponent.GetDefaultHitZone();
86 
87  if (!hitzone)
88  return; // No hitzone found
89 
90  for (int i = 0; i < 10; i++)
91  {
92  DbgUI.Text(DAMAGE_TYPE_NAMES[i] + ": " + hitzone.GetDamageMultiplier(i));
93  }
94  }
95  }
96 
97  //------------------------------------------------------------------------------------------------
100  float GetDamageReduction(TraceParam params)
101  {
102  SCR_DestructibleEntity destructibleEntity = SCR_DestructibleEntity.Cast(params.TraceEnt);
103  if (destructibleEntity)
104  return destructibleEntity.GetDamageReduction();
105 
106  SCR_DestructionDamageManagerComponent destructionComponent = SCR_DestructionDamageManagerComponent.Cast(params.TraceEnt.FindComponent(SCR_DestructionDamageManagerComponent));
107  if (destructionComponent)
108  {
109  HitZone hitZone = destructionComponent.GetHitZone(params.ColliderName);
110  if (!hitZone)
111  hitZone = destructionComponent.GetDefaultHitZone();
112 
113  if (!hitZone)
114  return -1; // No hitzone found!
115 
116  return hitZone.GetDamageReduction();
117  }
118 
119  return 0;
120  }
121 
122  //------------------------------------------------------------------------------------------------
125  float GetDamageThreshold(TraceParam params)
126  {
127  SCR_DestructibleEntity destructibleEntity = SCR_DestructibleEntity.Cast(params.TraceEnt);
128  if (destructibleEntity)
129  return destructibleEntity.GetDamageThreshold();
130 
131  SCR_DestructionDamageManagerComponent destructionComponent = SCR_DestructionDamageManagerComponent.Cast(params.TraceEnt.FindComponent(SCR_DestructionDamageManagerComponent));
132  if (destructionComponent)
133  {
134  HitZone hitZone = destructionComponent.GetHitZone(params.ColliderName);
135  if (!hitZone)
136  hitZone = destructionComponent.GetDefaultHitZone();
137 
138  if (!hitZone)
139  return -1; // No hitzone found!
140 
141  return hitZone.GetDamageThreshold();
142  }
143 
144  return 0;
145  }
146 
147  //------------------------------------------------------------------------------------------------
149  void GetCameraMat(out vector mat[4])
150  {
151  CameraManager cameraManager = GetGame().GetCameraManager();
152  if (!cameraManager)
153  return;
154 
155  CameraBase currentCamera = cameraManager.CurrentCamera();
156  if (!currentCamera)
157  return;
158 
159  currentCamera.GetTransform(mat);
160  }
161 
162  //------------------------------------------------------------------------------------------------
165  void TraceEntity(TraceParam params)
166  {
167  vector cameraMat[4];
168  GetCameraMat(cameraMat);
169 
170  params.Start = cameraMat[3];
171  params.End = params.Start + cameraMat[2] * 10; // 10m trace
172  params.LayerMask = EPhysicsLayerDefs.Projectile;
173  params.Exclude = GetGame().GetPlayerController().GetControlledEntity();
174  params.Flags = TraceFlags.ENTS;
175 
176  GetOwner().GetWorld().TraceMove(params, null);
177  }
178 
179  //------------------------------------------------------------------------------------------------
184  void DealDamageUnderCursor(float damageToDeal, EDamageType damageType, notnull TraceParam params)
185  {
186  if (!params.TraceEnt)
187  return;
188 
189  DealDamage(params.TraceEnt, damageToDeal, damageType, params.SurfaceProps);
190  }
191 
192  //------------------------------------------------------------------------------------------------
195  float GetHealth(IEntity entity)
196  {
197  SCR_DestructibleEntity destructibleEntity = SCR_DestructibleEntity.Cast(entity);
198  if (destructibleEntity)
199  return destructibleEntity.GetCurrentHealth();
200 
201  SCR_DestructionDamageManagerComponent destructionComponent = SCR_DestructionDamageManagerComponent.Cast(entity.FindComponent(SCR_DestructionDamageManagerComponent));
202  if (destructionComponent)
203  return destructionComponent.GetHealth();
204 
205  return 1;
206  }
207 
208  //------------------------------------------------------------------------------------------------
210  void SetOneHitPoint(float range)
211  {
212  vector cameraMat[4];
213  GetCameraMat(cameraMat);
214 
215  GetGame().GetWorld().QueryEntitiesBySphere(cameraMat[3], range, AddEntity, FilterEntity);
216 
217  for (int i = m_aToDamage.Count() - 1; i >= 0; i--)
218  {
219  DealDamage(m_aToDamage[i], GetHealth(m_aToDamage[i]) - 1, EDamageType.TRUE, null);
220  }
221 
222  m_aToDamage.Clear();
223  }
224 
225  //------------------------------------------------------------------------------------------------
231  void DealDamage(IEntity entity, float damageToDeal, EDamageType damageType, SurfaceProperties surfaceProperties)
232  {
233  vector hitPosDirNorm[3];
234 
235  SCR_DestructibleEntity destructibleEntity = SCR_DestructibleEntity.Cast(entity);
236  if (destructibleEntity)
237  destructibleEntity.HandleDamage(damageType, damageToDeal, hitPosDirNorm);
238 
239  SCR_DestructionDamageManagerComponent destructionComponent = SCR_DestructionDamageManagerComponent.Cast(entity.FindComponent(SCR_DestructionDamageManagerComponent));
240  if (destructionComponent)
241  {
242  SCR_DamageContext damageContext = new SCR_DamageContext(damageType, damageToDeal, hitPosDirNorm, entity, null, null, surfaceProperties, -1, -1);
243 
244  destructionComponent.HandleDamage(damageContext);
245  }
246  }
247 
248  //------------------------------------------------------------------------------------------------
253  void DealDamageRange(float damageToDeal, float range, EDamageType damageType)
254  {
255  vector cameraMat[4];
256  GetCameraMat(cameraMat);
257 
258  GetGame().GetWorld().QueryEntitiesBySphere(cameraMat[3], range, AddEntity, FilterEntity);
259 
260  foreach (IEntity toDamage : m_aToDamage)
261  {
262  DealDamage(toDamage, damageToDeal, damageType, null);
263  }
264 
265  m_aToDamage.Clear();
266  }
267 
268  //------------------------------------------------------------------------------------------------
272  bool AddEntity(IEntity e)
273  {
274  m_aToDamage.Insert(e);
275 
276  return true;
277  }
278 
279  //------------------------------------------------------------------------------------------------
283  bool FilterEntity(IEntity e)
284  {
285  if (SCR_DestructibleEntity.Cast(e) || e.FindComponent(SCR_DestructionDamageManagerComponent))
286  return true;
287 
288  return false;
289  }
290 
291  //------------------------------------------------------------------------------------------------
292  override void OnPostInit(IEntity owner)
293  {
294  super.OnPostInit(owner);
295 
296  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_DESTRUCTION_ENABLE_DIAG, "", "Enable destruction diag", "Destruction");
297 
298  ConnectToDiagSystem(owner);
299  }
300 
301  //------------------------------------------------------------------------------------------------
302  override void OnDelete(IEntity owner)
303  {
304  DisconnectFromDiagSystem(owner);
305 
306  super.OnDelete(owner);
307  }
308 #endif
309 }
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
HitZone
Definition: HitZone.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
OnDelete
override void OnDelete(IEntity owner)
Definition: SCR_CampaignBuildingCompositionComponent.c:538
SCR_DestructibleEntity
void SCR_DestructibleEntity(IEntitySource src, IEntity parent)
Definition: SCR_DestructibleEntity.c:464
TraceEntity
protected SCR_EditableEntityComponent TraceEntity(vector cursorPos)
Definition: SCR_CursorEditorUIComponent.c:385
SCR_DestructionDiagComponentClass
Definition: SCR_DestructionDiagComponent.c:2
GetDamageThreshold
float GetDamageThreshold()
Definition: SCR_DestructibleEntity.c:112
GetHealth
float GetHealth()
Definition: SCR_FuelNode.c:196
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_AIConfigComponent.c:72
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
EOnDiag
override void EOnDiag(IEntity owner, float timeSlice)
Definition: SCR_AIGroupUtilityComponent.c:426
FilterEntity
protected bool FilterEntity(IEntity ent)
Definition: SCR_CampaignFastTravelComponent.c:146
SCR_DamageContext
Definition: SCR_DamageContext.c:7
EDamageType
EDamageType
Definition: EDamageType.c:12
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
GetDamageReduction
float GetDamageReduction()
Definition: SCR_DestructibleEntity.c:102
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180