Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DetonatorGadgetComponent.c
Go to the documentation of this file.
2{
3 [Attribute("100", UIWidgets.Auto, desc: "If connected charges are outside of this range then they will not detonate. -1 == unlimited", params: "-1 inf")]
4 protected float m_fMaxDetonationRange;
5
6 //------------------------------------------------------------------------------------------------
8 {
10 }
11}
12
13class SCR_DetonatorGadgetComponent : SCR_GadgetComponent
14{
15 [RplProp(onRplName: "OnNumberOfConnectedChargesChanged")]
16 protected int m_iNumberOfConnectedCharges;
18 [RplProp()]
19 protected ref array<RplId> m_aConnectedCharges = {};
21 protected float m_fVisibilityCheckDelay;
22 protected RplComponent m_RplComp;
25
26 protected const string TRIGGER_ANIMATION_EVENT_NAME = "DetonatorTriggered";
27 protected const string ANIMATION_BIND_COMMAND = "CMD_Item_Action";
28 protected const int UPDATE_WIRES_VISIBILITY_DELAY = 500;
29
30 //------------------------------------------------------------------------------------------------
35
36 //------------------------------------------------------------------------------------------------
39 {
40 return m_iNumberOfConnectedCharges;
41 }
42
43 //------------------------------------------------------------------------------------------------
45 array<RplId> GetConnectedCharges()
46 {
47 return m_aConnectedCharges;
48 }
49
50 //------------------------------------------------------------------------------------------------
54 {
55 return m_aConnectedCharges.Contains(Replication.FindItemId(explosiveChargeComp));
56 }
57
58 //------------------------------------------------------------------------------------------------
61 bool IsAttachedToTheDetonator(RplId explosiveChargeCompId)
62 {
63 return m_aConnectedCharges.Contains(explosiveChargeCompId);
64 }
65
66 //------------------------------------------------------------------------------------------------
72 {
73 IEntity owner = GetOwner();
75 if (!data)
76 return true;
77
78 if (data.GetmaxDetonationRange() == -1)//range is unlimited
79 return true;
80
81 if (!explosiveChargeComp)
82 return false;
83
84 if (pos == vector.Zero)
85 pos = GetOwner().GetOrigin();
86
87 vector chargePos = explosiveChargeComp.GetOwner().GetOrigin();
88 if (vector.Distance(pos, chargePos) > data.GetmaxDetonationRange())
89 return false;
90
91 return true;
92 }
93
94 //------------------------------------------------------------------------------------------------
99 bool IsChargeInRange(vector pos, RplId explosiveChargeCompId)
100 {
101 IEntity owner = GetOwner();
103 if (!data)
104 return true;
105
106 if (data.GetmaxDetonationRange() == -1)//range is unlimited
107 return true;
108
109 if (!m_aConnectedCharges.Contains(explosiveChargeCompId))
110 return false;
111
112 SCR_ExplosiveChargeComponent explosiveChargeComp = SCR_ExplosiveChargeComponent.Cast(Replication.FindItem(explosiveChargeCompId));
113 if (!explosiveChargeComp)
114 return false;
115
116 if (pos == vector.Zero)
117 pos = owner.GetOrigin();
118
119 return IsChargeInRange(pos, explosiveChargeComp);
120 }
121
122 //------------------------------------------------------------------------------------------------
123 override void ToggleActive(bool state, SCR_EUseContext context)
124 {
125 if (m_eUseMask == SCR_EUseContext.NONE || (m_eUseMask & context) == 0)
126 return;
127
128 if (m_iNumberOfConnectedCharges < 1)
129 return;
130
131 if (!m_User)
132 {
134
135 if (!m_User)
136 return;
137 }
138
140 if (character)
141 {
142 SCR_CharacterControllerComponent charController = SCR_CharacterControllerComponent.Cast(character.GetCharacterController());
143
144 if (!charController || charController.GetLifeState() != ECharacterLifeState.ALIVE)
145 return;
146
147 if (!charController.CanPlayItemGesture() && charController.GetInspectEntity() != GetOwner())
148 return;
149 }
150
151 RplComponent rplComponent = RplComponent.Cast(m_User.FindComponent(RplComponent));
152 if (!rplComponent || !rplComponent.IsOwner())
153 return; // NOT owner of the character in possession of this gadget
154
155 // Client side
156 rplComponent = RplComponent.Cast(GetOwner().FindComponent(RplComponent));
157 if (rplComponent && rplComponent.IsProxy())
158 OnToggleActive(state); // activate client side to avoid server delay
159
160 // Sync
162 }
163
164 //------------------------------------------------------------------------------------------------
165 override void OnToggleActive(bool state)
166 {
167 if (!m_User)
168 {
169 if (!m_CharacterOwner)
170 return;
171
173 if (!m_User)
174 return;
175 }
176
177 if (!m_CharacterOwner)
178 {
180 PlaySound(SCR_SoundEvent.SOUND_DETONATOR_DETONATE_CHARGES);
181 return;
182 }
183
184 SCR_CharacterControllerComponent charController = SCR_CharacterControllerComponent.Cast(m_User.GetCharacterController());
185 charController.GetOnAnimationEvent().Insert(OnAnimationEvent);
186 charController.m_OnItemUseEndedInvoker.Insert(OnAnimationEnded);
187
188 CharacterAnimationComponent pAnimationComponent = m_User.GetAnimationComponent();
189 int itemActionId = pAnimationComponent.BindCommand(ANIMATION_BIND_COMMAND);
190
191 ItemUseParameters animParams = new ItemUseParameters();
192 animParams.SetEntity(GetOwner());
193 animParams.SetAllowMovementDuringAction(true);
194 animParams.SetKeepInHandAfterSuccess(true);
195 animParams.SetCommandID(itemActionId);
196 animParams.SetCommandIntArg(1);
197
198 charController.TryUseItemOverrideParams(animParams);
199 }
200
201 //------------------------------------------------------------------------------------------------
208 protected void OnAnimationEvent(AnimationEventID animEventType, AnimationEventID animUserString, int intParam, float timeFromStart, float timeToEnd)
209 {
210 if (animEventType == m_iDetonatorTriggeredEventID)
212 }
213
214 //------------------------------------------------------------------------------------------------
219 protected void OnAnimationEnded(IEntity item, bool successful, ItemUseParameters animParams)
220 {
221 if (!m_User)
222 return;
223
224 SCR_CharacterControllerComponent charController = SCR_CharacterControllerComponent.Cast(m_User.GetCharacterController());
225 m_User = null;
226
227 charController.GetOnAnimationEvent().Remove(OnAnimationEvent);
228 charController.m_OnItemUseEndedInvoker.Remove(OnAnimationEnded);
229 }
230
231 //------------------------------------------------------------------------------------------------
233 protected void DetonateExplosiveCharge()
234 {
235 if (!m_User)
236 return;
237
238 vector myPos = GetOwner().GetOrigin();
239 SCR_ExplosiveTriggerComponent trigger;
240 SCR_ExplosiveChargeComponent explosiveChargeComp;
241 bool isAuthority = m_RplComp && m_RplComp.Role() == RplRole.Authority;
242 for (int i = m_iNumberOfConnectedCharges -1; i >= 0; i--)
243 {
244 explosiveChargeComp = SCR_ExplosiveChargeComponent.Cast(Replication.FindItem(m_aConnectedCharges[i]));
245 if (!explosiveChargeComp)
246 {
247 m_aConnectedCharges.Remove(i);
248 continue;
249 }
250
251 if (!IsChargeInRange(myPos, explosiveChargeComp))
252 continue;
253
254 trigger = explosiveChargeComp.GetTrigger();
255 if (!trigger)
256 continue;
257
258 trigger.SetUser(m_User);
259 if (isAuthority)
260 trigger.UseTrigger();
261
262 m_aConnectedCharges.Remove(i);
263 }
264
265 m_iNumberOfConnectedCharges = m_aConnectedCharges.Count();
267 if (isAuthority)
268 Replication.BumpMe();
269
270 SCR_CharacterControllerComponent charController = SCR_CharacterControllerComponent.Cast(m_User.GetCharacterController());
271 charController.GetOnAnimationEvent().Remove(OnAnimationEvent);
272 }
273
274 //------------------------------------------------------------------------------------------------
276 void ActivateAction(notnull IEntity pUserEntity)
277 {
278 m_User = ChimeraCharacter.Cast(pUserEntity);
280 }
281
282 //------------------------------------------------------------------------------------------------
284 protected override void ActivateAction()
285 {
286 ToggleActive(false, SCR_EUseContext.FROM_ACTION);
287 }
288
289 //------------------------------------------------------------------------------------------------
292 protected void PlaySound(string soundName)
293 {
294 SoundComponent soundComp = SoundComponent.Cast(GetOwner().FindComponent(SoundComponent));
295
296 if (soundComp)
297 {
298 soundComp.SoundEvent(soundName);
299 }
300 }
301
302 //------------------------------------------------------------------------------------------------
304 void ConnectNewCharge(RplId explosiveChargeCompId, bool shouldReplicate = true)
305 {
306 if (m_aConnectedCharges.Contains(explosiveChargeCompId))
307 return;
308
309 m_aConnectedCharges.Insert(explosiveChargeCompId);
310 m_iNumberOfConnectedCharges++;
312
313 if (shouldReplicate && m_RplComp && m_RplComp.Role() == RplRole.Authority)
314 Replication.BumpMe();
315 }
316
317 //------------------------------------------------------------------------------------------------
319 void RemoveChargeFromTheList(RplId chargeCompToDisconnect, bool shouldReplicate = true)
320 {
321 int index = m_aConnectedCharges.Find(chargeCompToDisconnect);
322 if (index == -1)
323 return;
324
325 m_aConnectedCharges.Remove(index);
326 m_iNumberOfConnectedCharges--;
327 UpdateWiresVisibility(m_iNumberOfConnectedCharges);
328
329 if (shouldReplicate && m_RplComp && m_RplComp.Role() == RplRole.Authority)
330 Replication.BumpMe();
331 }
332
333 //------------------------------------------------------------------------------------------------
336 void ReplaceChargeFromTheList(RplId chargeCompToReplace, RplId replaceWith = RplId.Invalid())
337 {
338 if (!m_aConnectedCharges.Contains(chargeCompToReplace))
339 return;
340
341 ConnectNewCharge(replaceWith, false);
342 RemoveChargeFromTheList(chargeCompToReplace, false);
343
344 if (m_RplComp && m_RplComp.Role() == RplRole.Authority)
345 Replication.BumpMe();
346 }
347
348 //------------------------------------------------------------------------------------------------
351 {
352 RplId detonatorId = Replication.FindItemId(this);
353 if (!detonatorId.IsValid())
354 return;
355
356 SCR_ExplosiveChargeComponent explosiveChargeComp;
357 foreach (RplId chargeCompId : m_aConnectedCharges)
358 {
359 if (!chargeCompId.IsValid())
360 continue;
361
362 explosiveChargeComp = SCR_ExplosiveChargeComponent.Cast(Replication.FindItem(chargeCompId));
363 if (!explosiveChargeComp)
364 continue;
365
366 explosiveChargeComp.ReplaceDetonatorFromTheList(detonatorId);
367 }
368
369 m_aConnectedCharges.Clear();
370 m_iNumberOfConnectedCharges = 0;
372
373 PlaySound(SCR_SoundEvent.SOUND_DETONATOR_DISCONNECT_WIRES);
374 }
375
376 //------------------------------------------------------------------------------------------------
378 protected void UpdateWiresVisibility(bool visible = false)
379 {
380 SlotManagerComponent slotManagerComp = SlotManagerComponent.Cast(GetOwner().FindComponent(SlotManagerComponent));
381 if (!slotManagerComp)
382 return;
383
384 array<EntitySlotInfo> slots = {};
385 if (slotManagerComp.GetSlotInfos(slots) < 1)
386 return;
387
388 IEntity wireEntity;
389 foreach (EntitySlotInfo slot : slots)
390 {
391 if (!slot)
392 continue;
393
394 wireEntity = slot.GetAttachedEntity();
395 if (!wireEntity)
396 return;
397
398 if (visible)
399 wireEntity.SetFlags(EntityFlags.VISIBLE);
400 else
401 wireEntity.ClearFlags(EntityFlags.VISIBLE);
402 }
403 }
404
405 //------------------------------------------------------------------------------------------------
408 {
409 bool shoudShowWires;
410 vector ownerPos = GetOwner().GetOrigin();
411 SCR_ExplosiveChargeComponent explosiveChargeComp;
412 foreach (RplId chargeCompId : m_aConnectedCharges)
413 {
414 if (!chargeCompId.IsValid())
415 continue;
416
417 explosiveChargeComp = SCR_ExplosiveChargeComponent.Cast(Replication.FindItem(chargeCompId));
418 if (!explosiveChargeComp)
419 continue;
420
421 if (IsChargeInRange(ownerPos, explosiveChargeComp))
422 {
423 shoudShowWires = true;
424 break;
425 }
426 }
427
428 UpdateWiresVisibility(shoudShowWires);
429 }
430
431 //------------------------------------------------------------------------------------------------
437
438 //------------------------------------------------------------------------------------------------
441 override EGadgetType GetType()
442 {
443 return EGadgetType.DETONATOR;
444 }
445
446 //------------------------------------------------------------------------------------------------
449 override bool CanBeRaised()
450 {
451 return true;
452 }
453
454 //------------------------------------------------------------------------------------------------
458 protected override void ModeSwitch(EGadgetMode mode, IEntity charOwner)
459 {
460 super.ModeSwitch(mode, charOwner);
461 if (mode == EGadgetMode.IN_HAND)
463 }
464
465 //------------------------------------------------------------------------------------------------
468 protected override void ModeClear(EGadgetMode mode)
469 {
470 super.ModeClear(mode, charOwner);
471 if (mode == EGadgetMode.IN_HAND)
473 }
474
475 //------------------------------------------------------------------------------------------------
476 override void ActivateGadgetUpdate()
477 {
479
481 {
482 m_fVisibilityCheckDelay = GetGame().GetWorld().GetWorldTime() + 500;
483 super.ActivateGadgetUpdate();
484 }
485 }
486
487 //------------------------------------------------------------------------------------------------
489 {
490 super.DeactivateGadgetUpdate();
491 UpdateWiresVisibility(m_iNumberOfConnectedCharges);
493 }
494
495 //------------------------------------------------------------------------------------------------
496 override void Update(float timeSlice)
497 {
498 super.Update(timeSlice);
499 if (GetGame().GetWorld().GetWorldTime() > m_fVisibilityCheckDelay)
500 {
501 m_fVisibilityCheckDelay = GetGame().GetWorld().GetWorldTime() + UPDATE_WIRES_VISIBILITY_DELAY;
503 }
504 }
505
506 //------------------------------------------------------------------------------------------------
507 override void EOnInit(IEntity owner)
508 {
509 super.EOnInit(owner);
510 m_RplComp = RplComponent.Cast(owner.FindComponent(RplComponent));
514 if (deployableComp)
515 deployableComp.GetOnDeployedStateChanged().Insert(OnDeployedStateChanged);
516 }
517
518 //------------------------------------------------------------------------------------------------
519 override void OnPostInit(IEntity owner)
520 {
521 super.OnPostInit(owner);
522 SetEventMask(owner, EntityEvent.INIT);
523 }
524
525 //------------------------------------------------------------------------------------------------
526 override bool RplSave(ScriptBitWriter writer)
527 {
528 writer.WriteInt(m_iNumberOfConnectedCharges);
529 foreach (RplId chargeCompId : m_aConnectedCharges)
530 {
531 writer.WriteRplId(chargeCompId);
532 }
533
534 return super.RplSave(writer);
535 }
536
537 //------------------------------------------------------------------------------------------------
538 override bool RplLoad(ScriptBitReader reader)
539 {
540 reader.ReadInt(m_iNumberOfConnectedCharges);
541 for (int i; i < m_iNumberOfConnectedCharges; i++)
542 {
543 RplId rplIdOutput;
544 reader.ReadRplId(rplIdOutput);
545 if (rplIdOutput.IsValid())
546 m_aConnectedCharges.Insert(rplIdOutput);
547 }
548
549 return super.RplLoad(reader);
550 }
551}
int AnimationEventID
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_RplTestComponentClass m_CharacterOwner
override bool RplLoad(ScriptBitReader reader)
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
override bool RplSave(ScriptBitWriter writer)
void ModeClear(EGadgetMode mode)
void ActivateAction()
Action listener callback.
override void ModeSwitch(EGadgetMode mode, IEntity charOwner)
override EGadgetType GetType()
override void OnToggleActive(bool state)
SCR_CharacterSoundComponentClass GetComponentData()
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
void OnNumberOfConnectedChargesChanged()
bool IsAttachedToTheDetonator(SCR_ExplosiveChargeComponent explosiveChargeComp)
void OnDeployedStateChanged(bool newState, SCR_BaseDeployableInventoryItemComponent component)
void ShowConnectedWiresForChargesInRange()
Checks if there are any charges in range and if so then will show connected wires.
void ConnectNewCharge(RplId explosiveChargeCompId, bool shouldReplicate=true)
Add new charge to the list of connected charges.
RplComponent m_RplComp
void OnAnimationEnded(IEntity item, bool successful, ItemUseParameters animParams)
void UpdateWiresVisibility(bool visible=false)
Change visibility of sloted wires.
override void ActivateGadgetUpdate()
const string TRIGGER_ANIMATION_EVENT_NAME
void DetonateExplosiveCharge()
Trigger detonation of explosive charge if there is some connected and in range.
void PlaySound(string soundName)
ChimeraCharacter m_User
override void DeactivateGadgetUpdate()
array< RplId > GetConnectedCharges()
void RemoveChargeFromTheList(RplId chargeCompToDisconnect, bool shouldReplicate=true)
Remove provided charge from the listed of connected charges.
bool IsChargeInRange(vector pos, SCR_ExplosiveChargeComponent explosiveChargeComp)
const string ANIMATION_BIND_COMMAND
override bool CanBeRaised()
void ReplaceChargeFromTheList(RplId chargeCompToReplace, RplId replaceWith=RplId.Invalid())
void RemoveAllChargesFromTheList()
Remove all charges from the listed of connected charges.
float m_fVisibilityCheckDelay
int GetNumberOfConnectedCharges()
const int UPDATE_WIRES_VISIBILITY_DELAY
AnimationEventID m_iDetonatorTriggeredEventID
SCR_EUseContext
Get all prefabs that have the spawner data
void ToggleActive()
Toggle map light.
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Adds ability to attach an object to a slot.
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
proto external EntityFlags ClearFlags(EntityFlags flags, bool recursively=false)
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
Base class which all deployable inventory items inherit from.
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 AskToggleGadget(SCR_GadgetComponent gadgetComp, bool state)
static SCR_GadgetManagerComponent GetGadgetManager(IEntity entity)
static IEntity GetLocalControlledEntity()
IEntity GetOwner()
Owner entity of the fuel tank.
override void EOnInit(IEntity owner)
ECharacterLifeState
event void OnAnimationEvent(AnimationEventID animEventType, AnimationEventID animUserString, int intParam, float timeFromStart, float timeToEnd)
SCR_FieldOfViewSettings Attribute
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