Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_EffectModuleComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Editor/EffectsModule", description: "Holds and executes various effects such as artillery and smoke the editor can place")]
5
8typedef ScriptInvokerBase<EffectsModuleOnChangedMethod> EffectsModuleOnChanged;
9
11{
12 [Attribute("1", desc: "If true will execute as soon as it is placed. If false will only execute manually")]
13 protected bool m_bExecuteOnInit;
14
15 [Attribute(desc: "Holds the effect module config with all the required variables and logic to execute")]
17
18 protected bool m_bDoneExecuting;
19
23
24 //------------------------------------------------------------------------------------------------
32
33 //------------------------------------------------------------------------------------------------
38 {
39 return !m_EffectConfig || m_EffectConfig.GetType() != EEffectsModuleType.PARTICLE;
40 }
41
42 //------------------------------------------------------------------------------------------------
50
51 //------------------------------------------------------------------------------------------------
59
60 //------------------------------------------------------------------------------------------------
68
69 //======================================== TRANSFORM ========================================\\
70 void OnTransformChanged()
71 {
72 if (!m_EffectConfig)
73 return;
74
75 //~ Send out on transform changed event
77
80
81 while (child)
82 {
83 if (!child.FindComponent(SCR_EffectsModuleChildComponent))
84 {
85 child.OnTransformReset();
86 }
87 else
88 {
89 if (m_EffectConfig.m_bSnapToTerrain)
90 {
91 child.SetAngles(vector.Up);
92 vector transform[4];
93 Math3D.MatrixIdentity3(transform);
94
95 vector snapPosition;
96 vector normal;
97 vector pos = child.GetOrigin() + "0 3 0";
98
99 TraceParam trace = new TraceParam();
100 {
101 trace.Start = pos;
102
103 pos[1] = GetOwner().GetWorld().GetSurfaceY(pos[0], pos[2]);
104 pos[1] = SCR_TerrainHelper.GetTerrainY(pos, GetOwner().GetWorld(), true);
105 trace.End = pos;
106
107 trace.Exclude = child;
108 trace.TargetLayers = EPhysicsLayerDefs.FireGeometry;
109 trace.Flags = TraceFlags.ENTS | TraceFlags.WORLD;
110 }
111
112 SCR_TerrainHelper.SnapToGeometry(snapPosition, pos, null, GetOwner().GetWorld(), traceParam: trace, surfaceNormal: normal);
113 if (normal != vector.Zero)
114 Math3D.MatrixFromUpVec(normal, transform);
115
116 vector ownerTransform[3];
117 GetOwner().GetTransform(ownerTransform);
118 Math3D.MatrixInvMultiply3(ownerTransform, transform, transform);
119
120 transform[3] = snapPosition;
121 child.SetTransform(transform);
122 }
123 }
124
125 //~ Get next child
126 child = GenericEntity.Cast(child.GetSibling());
127 }
128 }
129
130 //======================================== CHILDREN ========================================\\
131 bool HasEffectsModuleChildren()
132 {
133 GenericEntity child = GenericEntity.Cast(GetOwner().GetChildren());
134
135 while (child)
136 {
137 if (!child.FindComponent(SCR_EffectsModuleChildComponent))
138 {
139 child = GenericEntity.Cast(child.GetSibling());
140 continue;
141 }
142
143 return true;
144 }
145
146 return false;
147 }
148
149 //------------------------------------------------------------------------------------------------
150 int GetEffectsModuleChildren(notnull out array<SCR_EffectsModuleChildComponent> effectModuleChildren)
151 {
152 effectModuleChildren.Clear();
153
155 SCR_EffectsModuleChildComponent effectModuleChild;
156
157 while (child)
158 {
159 effectModuleChild = SCR_EffectsModuleChildComponent.Cast(child.FindComponent(SCR_EffectsModuleChildComponent));
160 if (effectModuleChild)
161 effectModuleChildren.Insert(effectModuleChild);
162
163 child = GenericEntity.Cast(child.GetSibling());
164 }
165
166 return effectModuleChildren.Count();
167 }
168
169 //======================================== SPAWNING ========================================\\
170 //------------------------------------------------------------------------------------------------
172 {
173 if (!m_EffectConfig)
174 return;
175
176 //~ Create spawn params
177 EntitySpawnParams spawnParams = new EntitySpawnParams();
178 vector targetPosition;
179 m_EffectConfig.SetSpawnParams(spawnParams, targetPosition);
180
181 if (!spawnParams)
182 {
183 Print("SCR_EffectsModuleComponent.SpawnEffectEntity: Failed to create spawn params. Entity defined in Effect Config will not be spawned.", LogLevel.WARNING);
184 return;
185 }
186
187 //~ Spawn entity
188 IEntity spawnedEntity = GetGame().SpawnEntityPrefab(Resource.Load(m_EffectConfig.GetModuleEntityPrefab()), GetOwner().GetWorld(), spawnParams);
189 if (!spawnedEntity)
190 {
191 Print("'SCR_EffectsModuleComponent' failed to spawn entity", LogLevel.ERROR);
192 return;
193 }
194
195 if (spawnParams.Parent && m_EffectConfig.GetType() != EEffectsModuleType.PROJECTILE)
196 {
197 RplComponent spawnedRplComp = SCR_EntityHelper.GetEntityRplComponent(spawnedEntity);
198 RplComponent parentRplComp = SCR_EntityHelper.GetEntityRplComponent(spawnParams.Parent);
199 if (spawnedRplComp && parentRplComp)
200 {
201 RplNode spawnedNode = spawnedRplComp.GetNode();
202 RplNode parentNode = parentRplComp.GetNode();
203 if (spawnedNode && parentNode && spawnedNode.GetParent() != parentNode)
204 spawnedNode.SetParent(parentNode);
205 }
206 }
207
209 if (!effectModuleChild)
210 {
211 Debug.Error2("SCR_EffectsModuleComponent", "Spawned effect module entity does not have 'SCR_EffectsModuleChildComponent'!");
212 delete spawnedEntity;
213 return;
214 }
215
216 //~ Execute Post spawn logic after entity is spawned.
217 PostEntitySpawned(effectModuleChild, targetPosition);
218 }
219
220 //~ Called a frame after entity Is Spawned (Server Only)
221 protected void PostEntitySpawned(notnull SCR_EffectsModuleChildComponent spawnedEntity, vector targetPosition)
222 {
223 //~ Get rpl comp
224 RplComponent rplComp = RplComponent.Cast(spawnedEntity.GetOwner().FindComponent(RplComponent));
225 if (!rplComp)
226 {
227 Print("'SCR_EffectsModuleComponent' spawned entity has no 'RplComponent'!", LogLevel.ERROR);
228 delete spawnedEntity.GetOwner();
229 return;
230 }
231
232 spawnedEntity.InitChildServer(this, m_EffectConfig);
233 m_EffectConfig.OnEntitySpawned(spawnedEntity, targetPosition);
234
235 //~ On Spawn broadcast and logic
236 Rpc(OnEntitySpawnedBroadcast, rplComp.Id(), targetPosition);
237 }
238
239 //------------------------------------------------------------------------------------------------
240 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
241 protected void OnEntitySpawnedBroadcast(RplId id, vector targetPosition)
242 {
243 if (!m_EffectConfig)
244 return;
245
246 RplComponent rplComp = RplComponent.Cast(Replication.FindItem(id));
247 if (!rplComp)
248 return;
249
250 IEntity spawnedEntity = rplComp.GetEntity();
251 if (!spawnedEntity)
252 return;
253
255 if (!effectModuleChild)
256 return;
257
258 effectModuleChild.InitChild(this, GetEffectsModuleConfig());
259 m_EffectConfig.OnEntitySpawnedBroadcast(effectModuleChild, targetPosition);
260 }
261
262 //======================================== DONE EXECUTING ========================================\\
263 void DoneExecutingModule()
264 {
265 m_bDoneExecuting = true;
267 }
268
269 //------------------------------------------------------------------------------------------------
271 {
272 //~ Return if not done executing or if still has effect module children
273 if (!m_bDoneExecuting || HasEffectsModuleChildren())
274 return;
275
276 //~ Cancel module
277 CancelModuleServer();
278
279 IEntity owner = GetOwner();
280 if(owner != null && !owner.IsDeleted())
281 {
283 if(editableEffectsModule != null)
284 {
285 editableEffectsModule.Delete();
286 }
287 }
288 if (owner && !owner.IsDeleted())
289 delete owner;
290 }
291
292 //======================================== CANCEL ========================================\\
293 void CancelModuleServer()
294 {
295 if (!m_EffectConfig)
296 return;
297
298 m_EffectConfig.CancelModule();
299
300 m_EffectConfig.CancelModuleBroadcast();
302 }
303
304 //------------------------------------------------------------------------------------------------
305 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
306 protected void CancelModuleBroadcast()
307 {
308 if (!m_EffectConfig)
309 return;
310
311 m_EffectConfig.CancelModuleBroadcast();
312 }
313
314 //======================================== EFFECT ========================================\\
315 //---------------------------------------- Pause ----------------------------------------\\
316 bool CanPause()
317 {
318 return m_EffectConfig.CanPause();
319 }
320
321 //------------------------------------------------------------------------------------------------
322 bool IsPaused()
323 {
324 return m_EffectConfig.IsPaused();
325 }
326
327 //------------------------------------------------------------------------------------------------
328 void SetPausedServer(bool paused)
329 {
330 if (!CanPause() || IsPaused() == paused)
331 return;
332
333 SetPausedBroadcast(paused);
334 Rpc(SetPausedBroadcast, paused);
335 }
336
337 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
338 protected void SetPausedBroadcast(bool paused)
339 {
340 m_EffectConfig.SetPaused(paused);
341 }
342
343 //---------------------------------------- Looping ----------------------------------------\\
344 bool CanLoop()
345 {
346 return m_EffectConfig.CanLoop();
347 }
348
349 //------------------------------------------------------------------------------------------------
351 {
352 return m_EffectConfig.IsLooping();
353 }
354
355 //------------------------------------------------------------------------------------------------
356 void SetLoopingServer(bool loop)
357 {
358 if (!CanLoop() || IsLooping() == loop)
359 return;
360
363 }
364
365 //------------------------------------------------------------------------------------------------
366 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
367 protected void SetLoopingBroadcast(bool loop)
368 {
369 m_EffectConfig.SetLooping(loop);
370 }
371
372 //------------------------------------------------------------------------------------------------
373 override void EOnInit(IEntity owner)
374 {
376 return;
377
378 //~ Init on server and client
379 m_EffectConfig.Init(GetOwner(), this);
380
381 //~ Execution is Server only
383 if (!gameMode || !gameMode.IsMaster())
384 return;
385
386 if (!m_bExecuteOnInit)
387 return;
388
389 m_EffectConfig.OnModulePreExecute();
390 }
391
392 //------------------------------------------------------------------------------------------------
393 override void OnPostInit(IEntity owner)
394 {
395 if (!m_EffectConfig)
396 {
397 Print("'SCR_EffectsModuleComponent' has no effect config assigned!", LogLevel.ERROR);
398 return;
399 }
400 else if (SCR_StringHelper.IsEmptyOrWhiteSpace(m_EffectConfig.GetModuleEntityPrefab()))
401 {
402 Print("'SCR_EffectsModuleComponent' effect config is invalid as no prefab assigned!", LogLevel.ERROR);
403 return;
404 }
405 else if (m_EffectConfig.GetType() == EEffectsModuleType.NONE)
406 {
407 Print("'SCR_EffectsModuleComponent' effect config is invalid as type is NONE!", LogLevel.ERROR);
408 return;
409 }
410 else if (!m_EffectConfig.GetEffectsModuleZoneData())
411 {
412 Print("'SCR_EffectsModuleComponent' effect config has no Zone Data assigned!", LogLevel.ERROR);
413 return;
414 }
415
416 SetEventMask(owner, EntityEvent.INIT);
417 }
418
419 //------------------------------------------------------------------------------------------------
421 {
422 /*array<SCR_EffectsModuleChildComponent> effectModuleChildren = {};
423 GetEffectsModuleChildren(effectModuleChildren);
424
425 foreach (SCR_EffectsModuleChildComponent child : effectModuleChildren)
426 {
427 child.EditorOnParentRemoved(this, GetEffectsModuleConfig());
428 }*/
429
431 }
432
433 //------------------------------------------------------------------------------------------------
434 override void OnDelete(IEntity owner)
435 {
437 return;
438
439 m_bDoneExecuting = false;
440
441 //~ If editable Effect module then ignore as OnOwnerDeleted will already be executed
443 {
444 return;
445 }
446
447 //~ Execution is Server only
449 if (gameMode && gameMode.IsMaster())
450 CancelModuleServer();
451
452 m_OnDeleted.Invoke(this, GetEffectsModuleConfig());
453
454 }
455
456 //======================================== RPL ========================================\\
457 override bool RplSave(ScriptBitWriter writer)
458 {
459 if (!m_EffectConfig)
460 return false;
461
462 writer.WriteBool(IsPaused());
463 writer.WriteBool(IsLooping());
464
465 return true;
466 }
467
468 //------------------------------------------------------------------------------------------------
469 override bool RplLoad(ScriptBitReader reader)
470 {
471 if (!m_EffectConfig)
472 return false;
473
474 bool isPaused, isLooping;
475
476 reader.ReadBool(isPaused);
477 reader.ReadBool(isLooping);
478
479 SetPausedBroadcast(isPaused);
480 SetLoopingBroadcast(isLooping);
481
482 return true;
483 }
484};
485
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_BaseGameMode GetGameMode()
@ MODULE_ENTITY
Entities that are placed such as Mines.
@ PROJECTILE
Projectiles that fly in such as Mortars.
@ PARTICLE
Particles that are directly spawned.
func EffectsModuleOnChangedMethod
ScriptInvokerBase< EffectsModuleOnChangedMethod > EffectsModuleOnChanged
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void GetChildren(out array< SCR_ScenarioFrameworkLayerBase > children)
Definition Debug.c:13
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external Managed FindComponent(typename typeName)
proto external BaseWorld GetWorld()
proto external void GetTransform(out vector mat[])
proto external bool IsDeleted()
Main replication API.
Definition Replication.c:14
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
Replication item identifier.
Definition RplId.c:14
sealed bool IsMaster()
override bool Delete(bool changedByUser=false, bool updateNavmesh=true)
void InitChild(notnull SCR_EffectsModuleComponent effectModule, notnull SCR_EffectsModule effectConfig)
override void EOnInit(IEntity owner)
ref EffectsModuleOnChanged m_OnEditorOnRemovedFromParent
Rpc(CancelModuleBroadcast)
EffectsModuleOnChanged GetOnEditorOnRemovedFromParent()
void PostEntitySpawned(notnull SCR_EffectsModuleChildComponent spawnedEntity, vector targetPosition)
int GetEffectsModuleChildren(notnull out array< SCR_EffectsModuleChildComponent > effectModuleChildren)
void OnEntitySpawnedBroadcast(RplId id, vector targetPosition)
EffectsModuleOnChanged GetOnTransformChanged()
override void OnPostInit(IEntity owner)
override bool RplLoad(ScriptBitReader reader)
ref EffectsModuleOnChanged m_OnDeleted
SCR_EffectsModuleChildComponent childComponent
ref EffectsModuleOnChanged m_OnTransformChanged
m_EffectConfig CancelModuleBroadcast()
override void OnDelete(IEntity owner)
EffectsModuleOnChanged GetOnDelete()
static RplComponent GetEntityRplComponent(notnull IEntity entity)
static bool IsEditMode()
Definition Functions.c:1566
static bool IsEmptyOrWhiteSpace(string input)
static float GetTerrainY(vector pos, BaseWorld world=null, bool noUnderwater=false, TraceParam trace=null)
static void SnapToGeometry(out vector newPosition, vector currentPosition, array< IEntity > excludedEntities, BaseWorld world=null, TraceParam traceParam=null, out vector surfaceNormal=vector.Zero)
proto external GenericEntity GetOwner()
Get owner entity.
void EntitySpawnParams()
Definition gameLib.c:130
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
@ NONE
When Shape is created and not initialized yet.
Definition ShapeType.c:15
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14
TraceFlags
Definition TraceFlags.c:13