Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ExplosiveChargeComponent.c
Go to the documentation of this file.
5
8typedef ScriptInvokerBase<ScriptInvokerFuzeChangedMethod> ScriptInvokerFuzeChanged;
9
10class SCR_ExplosiveChargeComponent : ScriptGameComponent
11{
12 protected RplId m_RplID;
13 protected RplComponent m_RplComp;
14 protected SCR_ExplosiveTriggerComponent m_Trigger;
15 protected float m_fFuzeTime = 20;
16
17 [RplProp()]
18 protected float m_fTimer;
19
20 [RplProp(onRplName: "OnFuzeTypeChanged")]
22
23 [RplProp(onRplName: "OnArrayOfConnectedDetonatorsChanged")]
24 protected ref array<RplId> m_aConnectedDetonators = {};
25
27
28 //------------------------------------------------------------------------------------------------
39
40 //------------------------------------------------------------------------------------------------
42 protected void OnFuzeChanged(SCR_EFuzeType oldFuzeType, SCR_EFuzeType newFuzeType)
43 {
44 if (!m_OnFuzeChanged)
45 return;
46
47 m_OnFuzeChanged.Invoke(oldFuzeType, newFuzeType);
48 }
49
50 //------------------------------------------------------------------------------------------------
55
56 //------------------------------------------------------------------------------------------------
61
62 //------------------------------------------------------------------------------------------------
64 {
65 return m_fTimer;
66 }
67
68 //------------------------------------------------------------------------------------------------
73
74 //------------------------------------------------------------------------------------------------
75 SCR_ExplosiveTriggerComponent GetTrigger()
76 {
77 return m_Trigger;
78 }
79
80 //------------------------------------------------------------------------------------------------
82 {
84 }
85
86 //------------------------------------------------------------------------------------------------
88 {
89 return m_aConnectedDetonators.Count();
90 }
91
92 //------------------------------------------------------------------------------------------------
93 bool IsDetonatorConnected(RplId detonatorId)
94 {
95 return m_aConnectedDetonators.Contains(detonatorId);
96 }
97
98 //------------------------------------------------------------------------------------------------
100 {
101 return m_fFuzeTime;
102 }
103
104 //------------------------------------------------------------------------------------------------
106 void SetFuzeTime(float fuzeDelay, bool silent = false)
107 {
108 if (float.AlmostEqual(fuzeDelay, m_fFuzeTime))
109 return;
110
111 m_fFuzeTime = fuzeDelay;
112
113 if (silent)
114 return;
115
116 SCR_SoundManagerModule.CreateAndPlayAudioSource(GetOwner(), SCR_SoundEvent.SOUND_EXPLOSIVE_ADJUST_TIMER);
117 }
118
119 //------------------------------------------------------------------------------------------------
122 protected void SetGarbageCollectable(bool garbageCollectable)
123 {
125 if (!garbageManager)
126 return;
127
128 garbageCollectable = garbageCollectable && !GetOwner().GetParent();
129
130 garbageManager.UpdateBlacklist(GetOwner(), !garbageCollectable);
131 }
132
133 //------------------------------------------------------------------------------------------------
135 void ArmWithTimedFuze(bool silent = false)
136 {
137 SCR_EFuzeType oldFuzeType = m_eUsedFuzeType;
140 ChangeLockState(true);
141 OnFuzeChanged(oldFuzeType, m_eUsedFuzeType);
142
143 if (m_RplComp && m_RplComp.Role() == RplRole.Authority)
144 {
145//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
146 ChimeraWorld world = ChimeraWorld.CastFrom(GetGame().GetWorld());
147 if (!world)
148 return;
149
150 TimeAndWeatherManagerEntity timeAndWeatherManager = world.GetTimeAndWeatherManager();
151 if (!timeAndWeatherManager)
152 return;
153
154 m_fTimer = timeAndWeatherManager.GetEngineTime() + m_fFuzeTime;
155 SetEventMask(GetOwner(), EntityEvent.FRAME);
156//---- REFACTOR NOTE END ----
158 Replication.BumpMe();
159 }
160
161 if (!silent)
162 SCR_SoundManagerModule.CreateAndPlayAudioSource(GetOwner(), SCR_SoundEvent.SOUND_EXPLOSIVE_ARM);
163 }
164
165 //------------------------------------------------------------------------------------------------
168 void ConnectDetonator(SCR_EFuzeType fuzeType, RplId detonatorId = RplId.Invalid(), bool shouldReplicate = true, bool silent = false)
169 {
170 if (fuzeType != m_eUsedFuzeType && m_eUsedFuzeType != SCR_EFuzeType.NONE)
171 return;
172
173 if (!m_aConnectedDetonators.Contains(detonatorId))
174 m_aConnectedDetonators.Insert(detonatorId);
175
176 SCR_EFuzeType oldFuzeType = m_eUsedFuzeType;
177 m_eUsedFuzeType = fuzeType;
179 ChangeLockState(true);
180 if (shouldReplicate && m_RplComp && m_RplComp.Role() == RplRole.Authority)
181 {
183 Replication.BumpMe();
184 }
185
186 OnFuzeChanged(oldFuzeType, m_eUsedFuzeType);
187 if (silent)
188 return;
189
190 if (m_eUsedFuzeType == SCR_EFuzeType.REMOTE)
191 SCR_SoundManagerModule.CreateAndPlayAudioSource(GetOwner(), SCR_SoundEvent.SOUND_EXPLOSIVE_CONNECT_WIRES);
192 else
193 SCR_SoundManagerModule.CreateAndPlayAudioSource(GetOwner(), SCR_SoundEvent.SOUND_EXPLOSIVE_ARM);
194 }
195
196 //------------------------------------------------------------------------------------------------
198 void RemoveDetonatorFromTheList(RplId detonatorId, bool shouldReplicate = true)
199 {
200 int index = m_aConnectedDetonators.Find(detonatorId);
201 if (index == -1)
202 return;
203
205 if (m_aConnectedDetonators.Count() < 1)
206 {
207 SCR_EFuzeType oldFuzeType = m_eUsedFuzeType;
211 OnFuzeChanged(oldFuzeType, m_eUsedFuzeType);
212 }
213
214 if (shouldReplicate && m_RplComp && m_RplComp.Role() == RplRole.Authority)
215 {
217 Replication.BumpMe();
218 }
219 }
220
221 //------------------------------------------------------------------------------------------------
223 void ReplaceDetonatorFromTheList(RplId detonatorIdToReplace, RplId replaceWith = RplId.Invalid())
224 {
225 ConnectDetonator(m_eUsedFuzeType, replaceWith, false, true);
226 RemoveDetonatorFromTheList(detonatorIdToReplace, false);
227
228 if (m_RplComp && m_RplComp.Role() == RplRole.Authority)
229 Replication.BumpMe();
230 }
231
232 //------------------------------------------------------------------------------------------------
234 protected void UpdateFuzeVisibility()
235 {
236 SlotManagerComponent slotManagerComp = SlotManagerComponent.Cast(GetOwner().FindComponent(SlotManagerComponent));
237 if (!slotManagerComp)
238 return;
239
240 array<EntitySlotInfo> slots = {};
241 if (!slotManagerComp.GetSlotInfos(slots))
242 return;
243
244 FuzeSlotInfo fuzeSlot;
245 IEntity fuzeEntity;
246 foreach (EntitySlotInfo slot : slots)
247 {
248 fuzeSlot = FuzeSlotInfo.Cast(slot);
249 if (!fuzeSlot)
250 continue;
251
252 fuzeEntity = fuzeSlot.GetAttachedEntity();
253 if (!fuzeEntity)
254 continue;
255
256 if (fuzeSlot.GetFuzeType() == m_eUsedFuzeType)
257 fuzeEntity.SetFlags(EntityFlags.VISIBLE);
258 else
259 fuzeEntity.ClearFlags(EntityFlags.VISIBLE);
260 }
261 }
262
263 //------------------------------------------------------------------------------------------------
266 {
267 DisarmCharge(false);
268 }
269
270 //------------------------------------------------------------------------------------------------
274 void DisarmCharge(bool playSound = true)
275 {
276 if (m_eUsedFuzeType == SCR_EFuzeType.REMOTE)
277 {
278 if (!m_aConnectedDetonators.Count())
279 return;
280
281 RplId triggerId = Replication.FindItemId(this);
282 if (!triggerId.IsValid())
283 return;
284
285 SCR_DetonatorGadgetComponent detonatorComp;
286 foreach (RplId detonatorId : m_aConnectedDetonators)
287 {
288 if (!detonatorId.IsValid())
289 continue;
290
291 detonatorComp = SCR_DetonatorGadgetComponent.Cast(Replication.FindItem(detonatorId));
292 if (!detonatorComp)
293 continue;
294
295 detonatorComp.ReplaceChargeFromTheList(triggerId, RplId.Invalid());
296 }
297 }
298 else if (m_eUsedFuzeType == SCR_EFuzeType.TIMED)
299 {
300 ClearEventMask(GetOwner(), EntityEvent.FRAME);
301 m_fTimer = -1;
302 }
303
305 SCR_EFuzeType oldFuzeType = m_eUsedFuzeType;
309 if (m_RplComp && m_RplComp.Role() == RplRole.Authority)
310 {
312 Replication.BumpMe();
313 }
314
315 OnFuzeChanged(oldFuzeType, m_eUsedFuzeType);
316 if (playSound)
317 SCR_SoundManagerModule.CreateAndPlayAudioSource(GetOwner(), SCR_SoundEvent.SOUND_EXPLOSIVE_DISARM);
318 }
319
320 //------------------------------------------------------------------------------------------------
322 protected void ChangeLockState(bool locked = false)
323 {
325 if (!iic)
326 return;
327
328 iic.RequestUserLock(GetOwner(), locked);
329 }
330
331 //------------------------------------------------------------------------------------------------
334 {
335 if (CheckRplId())
336 return m_RplID;
337
338 return RplId.Invalid();
339 }
340
341 //------------------------------------------------------------------------------------------------
343 protected bool CheckRplId()
344 {
345 if (!m_RplID.IsValid())
346 {
347 m_RplID = Replication.FindItemId(this);
348 if (!m_RplID.IsValid())
349 return false;
350 }
351
352 return true;
353 }
354
355//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
356 //------------------------------------------------------------------------------------------------
357 override void EOnFrame(IEntity owner, float timeSlice)
358 {
360 if (!gameMode)
361 return;
362
363 ChimeraWorld world = ChimeraWorld.CastFrom(GetGame().GetWorld());
364 if (!world)
365 return;
366
367 TimeAndWeatherManagerEntity timeAndWeatherManager = world.GetTimeAndWeatherManager();
368 if (!timeAndWeatherManager)
369 return;
370
371 if (timeAndWeatherManager.GetEngineTime() > m_fTimer)
372 {
373 ClearEventMask(owner, EntityEvent.FRAME);
374 m_Trigger.UseTrigger();
375 }
376 }
377//---- REFACTOR NOTE END ----
378
379 //------------------------------------------------------------------------------------------------
380 override void EOnInit(IEntity owner)
381 {
382 super.EOnInit(owner);
383 m_RplID = Replication.FindItemId(this);
384 m_RplComp = RplComponent.Cast(owner.FindComponent(RplComponent));
385 m_Trigger = SCR_ExplosiveTriggerComponent.Cast(owner.FindComponent(SCR_ExplosiveTriggerComponent));
387 if (iic)
388 iic.m_OnParentSlotChangedInvoker.Insert(DisarmChargeSilent);
389
391 }
392
393 //------------------------------------------------------------------------------------------------
394 override void OnPostInit(IEntity owner)
395 {
396 super.OnPostInit(owner);
397
398 SetEventMask(owner, EntityEvent.INIT);
399 }
400
401 //------------------------------------------------------------------------------------------------
402 override void OnDelete(IEntity owner)
403 {
404 DisarmCharge(false);
405 }
406
407 //------------------------------------------------------------------------------------------------
408 override bool RplSave(ScriptBitWriter writer)
409 {
410 writer.WriteInt(m_eUsedFuzeType);
411 writer.WriteInt(m_aConnectedDetonators.Count());
412 foreach (RplId detonatorId : m_aConnectedDetonators)
413 {
414 writer.WriteRplId(detonatorId);
415 }
416 writer.WriteFloat(m_fTimer);
417
418 return super.RplSave(writer);
419 }
420
421 //------------------------------------------------------------------------------------------------
422 override bool RplLoad(ScriptBitReader reader)
423 {
424 reader.ReadInt(m_eUsedFuzeType);
425 int numberOfConnectedDetonators;
426 reader.ReadInt(numberOfConnectedDetonators);
427 for (int i; i < numberOfConnectedDetonators; i++)
428 {
429 RplId rplIdOutput;
430 reader.ReadRplId(rplIdOutput);
431 if (rplIdOutput.IsValid())
432 m_aConnectedDetonators.Insert(rplIdOutput);
433 }
435 reader.ReadFloat(m_fTimer);
436
437 return super.RplLoad(reader);
438 }
439}
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_BaseGameMode GetGameMode()
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
SCR_EFuzeType
Enum with all types of fuzes.
ScriptInvokerBase< ScriptInvokerFuzeChangedMethod > ScriptInvokerFuzeChanged
func ScriptInvokerFuzeChangedMethod
Adds ability to attach an object to a slot.
Slot that is meant to be used for excplosive charge fuze.
Definition FuzeSlotInfo.c:3
SCR_EFuzeType GetFuzeType()
Definition FuzeSlotInfo.c:8
proto external Managed FindComponent(typename typeName)
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
proto external IEntity GetParent()
proto external EntityFlags ClearFlags(EntityFlags flags, bool recursively=false)
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
RplId GetRplId()
Checks validity and returns RplId of this component.
void UpdateFuzeVisibility()
Change visibility of sloted fuze.
void DisarmChargeSilent()
Callback method to ensure that charge is disarmed when transferred but with no sound.
override void EOnFrame(IEntity owner, float timeSlice)
override void OnPostInit(IEntity owner)
void ConnectDetonator(SCR_EFuzeType fuzeType, RplId detonatorId=RplId.Invalid(), bool shouldReplicate=true, bool silent=false)
ScriptInvokerFuzeChanged GetOnFuzeChanged()
void ChangeLockState(bool locked=false)
When item is locked then players wont be able to pick it up.
bool CheckRplId()
Checks validaty of RplId and if that fails then tries to find correct RplId for that trigger.
void SetGarbageCollectable(bool garbageCollectable)
void ArmWithTimedFuze(bool silent=false)
Arms the charge and starts the timer for the detonation.
void OnFuzeChanged(SCR_EFuzeType oldFuzeType, SCR_EFuzeType newFuzeType)
Triggers m_OnFuzeChanged when such exists with information about old and new fuze type.
void RemoveDetonatorFromTheList(RplId detonatorId, bool shouldReplicate=true)
Removes provided detonator RplId unless its not there in the first place.
override void OnDelete(IEntity owner)
SCR_ExplosiveTriggerComponent GetTrigger()
void ReplaceDetonatorFromTheList(RplId detonatorIdToReplace, RplId replaceWith=RplId.Invalid())
Replaces connected detonator RplId with provided id which by default will be invalid.
void SetFuzeTime(float fuzeDelay, bool silent=false)
Change the time which will be used for timed fuze.
SCR_ExplosiveTriggerComponent m_Trigger
override bool RplLoad(ScriptBitReader reader)
ref ScriptInvokerFuzeChanged m_OnFuzeChanged
override bool RplSave(ScriptBitWriter writer)
Script entry for garbage system modding.
static SCR_GarbageSystem GetByEntityWorld(IEntity entity)
IEntity GetOwner()
Owner entity of the fuel tank.
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
RplRole
Role of replicated node (and all items in it) within the replication system.
Definition RplRole.c:14