Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
improvisedexplosive.c
Go to the documentation of this file.
1class ImprovisedExplosive : ExplosivesBase
2{
3 protected const float TIME_TRIGGER_INITIAL_DELAY_SECS = 0.1;
4 protected const float TIME_TRIGGER_TIMER_BASED_DELAY_SECS = 1.0;
5 protected const float TIME_TRIGGER_DELAY_SECS = 0.3;
6
7 protected static const string SLOT_TRIGGER_ALARM_CLOCK = "TriggerAlarmClock";
8 protected static const string SLOT_TRIGGER_KITCHEN_TIMER = "TriggerKitchenTimer";
9 protected static const string SLOT_TRIGGER_REMOTE = "TriggerRemoteDetonator_Receiver";
10
11 protected static const string SLOT_EXPLOSIVE_A = "IEDExplosiveA";
12 protected static const string SLOT_EXPLOSIVE_B = "IEDExplosiveB";
13
14 protected const int SLOT_EXPLOSIVE_COUNT = 2;
19
20 protected const int SLOT_TRIGGERS_COUNT = 3;
26
27 protected const string ANIM_PHASE_TRIGGER_EMPTY = "TriggerEmpty";
28 protected const string ANIM_PHASE_TRIGGER_TIMER = "TriggerTimer";
29 protected const string ANIM_PHASE_TRIGGER_CLOCK = "TriggerClock";
30 protected const string ANIM_PHASE_TRIGGER_REMOTE = "TriggerRemote";
31
33
35 {
37
38 RegisterNetSyncVariableInt("m_RAIB.m_PairDeviceNetIdLow");
39 RegisterNetSyncVariableInt("m_RAIB.m_PairDeviceNetIdHigh");
40 }
41
42 override void EOnInit(IEntity other, int extra)
43 {
44 if (!g_Game.IsMultiplayer())
46 }
47
48 override bool HasLockedTriggerSlots()
49 {
50 foreach (string triggerSlot : SLOT_TRIGGERS)
51 return GetInventory().GetSlotLock(InventorySlots.GetSlotIdFromString(triggerSlot));
52
53 return false;
54 }
55
56 override void LockTriggerSlots()
57 {
58 foreach (string triggerSlotName : SLOT_TRIGGERS)
59 GetInventory().SetSlotLock(InventorySlots.GetSlotIdFromString(triggerSlotName), true);
60 }
61
62 override void UnlockTriggerSlots()
63 {
64 foreach (string triggerSlotName : SLOT_TRIGGERS)
65 GetInventory().SetSlotLock(InventorySlots.GetSlotIdFromString(triggerSlotName), false);
66 }
67
68 override void LockExplosivesSlots()
69 {
70 foreach (string explosiveSlotName : SLOT_EXPLOSIVES)
71 GetInventory().SetSlotLock(InventorySlots.GetSlotIdFromString(explosiveSlotName), true);
72 }
73
74 override void UnlockExplosivesSlots()
75 {
76 foreach (string explosiveSlotName : SLOT_EXPLOSIVES)
77 GetInventory().SetSlotLock(InventorySlots.GetSlotIdFromString(explosiveSlotName), false);
78 }
79
80 override bool OnStoreLoad(ParamsReadContext ctx, int version)
81 {
82 if (!super.OnStoreLoad(ctx, version))
83 return false;
84
85 if (version <= 134) // up to 1.21
86 {
87 foreach (string triggerSlotName : SLOT_TRIGGERS)
88 {
89 int slotId = InventorySlots.GetSlotIdFromString(triggerSlotName);
90 bool locked = GetInventory().GetSlotLock(slotId);
91 while (locked)
92 {
93 GetInventory().SetSlotLock(slotId, false);
94 locked = GetInventory().GetSlotLock(slotId);
95 }
96 }
97 }
98
99 return true;
100 }
101
103 {
104 super.OnStoreSave(ctx);
105
107 }
108
110 {
111 super.OnVariablesSynchronized();
112
113 if (m_RAIB)
114 {
116 }
117
118
119 foreach (string slotName : SLOT_TRIGGERS)
120 {
121 EntityAI trigger = GetInventory().FindAttachmentByName(slotName);
122 if (trigger)
123 {
124 UpdateVisuals(trigger);
125 break;
126 }
127 }
128 }
129
130 override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
131 {
132 super.OnPlacementComplete(player, position, orientation);
133
134 if (GetGame().IsServer())
135 {
136 SetOrientation(vector.Up);
137 }
138 }
139
140 override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
141 {
142 super.EEItemLocationChanged(oldLoc, newLoc);
143
144 if (m_RAIB)
145 {
146 m_RAIB.Pair();
147 }
148 }
149
154
155 override void PairRemote(notnull EntityAI trigger)
156 {
157 m_RAIB.Pair(trigger);
158 }
159
161 {
162 return m_RAIB.GetPairDevice();
163 }
164
165 override bool CanBeArmed()
166 {
167 if (GetArmed())
168 return false;
169
171 return false;
172
173 foreach (string slotName : SLOT_EXPLOSIVES)
174 {
175 EntityAI explosive = GetInventory().FindAttachmentByName(slotName);
176 if (explosive)
177 return true;
178 }
179
180 return false;
181 }
182
183 override bool CanBeDisarmed()
184 {
185 return true;
186 }
187
188
189 override bool CanReceiveAttachment(EntityAI attachment, int slotId)
190 {
192 GetInventory().GetCurrentInventoryLocation(il);
193
194 foreach (string slotName : SLOT_TRIGGERS)
195 {
196 if (slotId == InventorySlots.GetSlotIdFromString(slotName))
197 {
198 if (il.GetType() == InventoryLocationType.HANDS)
199 return false;
200 }
201 }
202
203 return !GetArmed();
204 }
205
206 override bool CanDisplayAttachmentSlot(int slot_id)
207 {
208 string slotName = InventorySlots.GetSlotName(slot_id);
209
210 switch (slotName)
211 {
215 return FindAttachmentBySlotName(slotName) != null;
216 break;
217 }
218
219 return true;
220 }
221
222 override bool IsTimerDetonable()
223 {
224 return true;
225 }
226
227 override bool IsTakeable()
228 {
229 return !GetArmed() && super.IsTakeable();
230 }
231
232 override bool IsDeployable()
233 {
234 return !GetArmed();
235 }
236
237 override void SetActions()
238 {
239 super.SetActions();
240
243 }
244
245 override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
246 {
247 super.EEHealthLevelChanged(oldLevel, newLevel, zone);
248
249 if (GetGame().IsServer())
250 {
251 if (newLevel == GameConstants.STATE_RUINED)
252 {
253 for (int attachmentIdx = 0; attachmentIdx < GetInventory().AttachmentCount(); attachmentIdx++)
254 {
255 ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(attachmentIdx));
256 if (attachment)
257 {
258 attachment.UnlockFromParent();
259 attachment.SetHealth("", "", 0.0);
260 }
261 }
262
263 SetArmed(false);
264 SetTakeable(true);
265 }
266 }
267 }
268
269 override void OnActivatedByItem(notnull ItemBase item)
270 {
271 if (GetGame().IsServer() && GetArmed())
272 {
273 bool isTimeTriggered = false;
274
275 array<ItemBase> attachmentsCache = new array<ItemBase>();
276 for (int attachmentIdx = 0; attachmentIdx < GetInventory().AttachmentCount(); attachmentIdx++)
277 {
278 ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(attachmentIdx));
279 if (attachment)
280 attachmentsCache.Insert(attachment);
281 }
282
283 foreach (ItemBase attachment1 : attachmentsCache)
284 attachment1.UnlockFromParent();
285
287 foreach (ItemBase attachment2 : attachmentsCache)
288 {
289 if (attachment2.IsInherited(ClockBase))
290 {
291 isTimeTriggered = true;
292 break;
293 }
294 }
295
297 foreach (ItemBase attachment3 : attachmentsCache)
298 {
299 if (attachment3)
300 {
301 vector dropExtents = "0.5 0.0 0.5";
302 if (isTimeTriggered)
303 dropExtents[1] = 0.15;
304
305 GetInventory().DropEntityInBounds(InventoryMode.SERVER, this, attachment3, dropExtents, 0, 0, 0);
306 attachment3.SetAnimationPhase(ANIM_PHASE_VISIBILITY, 1.0);
307 attachment3.SetTakeable(false);
308 }
309 }
310
311 float delayFor = TIME_TRIGGER_INITIAL_DELAY_SECS;
312 if (isTimeTriggered)
313 {
316 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(DeleteSafe, delayFor * 1000, false);
317 }
318 else
319 {
320 DeleteSafe();
321 }
322
324 foreach (ItemBase attachment4 : attachmentsCache)
325 {
326 if (attachment4.IsAnyInherited({RemoteDetonator, ClockBase}))
327 {
329 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(attachment4.DeleteSafe, delayFor * 1000, false);
330 }
331
332 if (attachment4 && !attachment4.IsAnyInherited({RemoteDetonator, ClockBase}))
333 {
334 Param1<ItemBase> params = new Param1<ItemBase>(attachment4);
335 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLaterByName(attachment4, "OnActivatedByItem", delayFor * 1000, false, params);
336 delayFor += TIME_TRIGGER_DELAY_SECS;
337 }
338 }
339 }
340 }
341
343 override protected void InitiateExplosion();
344
345 override void EEItemAttached(EntityAI item, string slot_name)
346 {
347 super.EEItemAttached(item, slot_name);
348
349 switch (slot_name)
350 {
354 OnTriggerAttached(FindAttachmentBySlotName(slot_name));
355 break;
356 }
357 }
358
359 override void EEItemDetached(EntityAI item, string slot_name)
360 {
361 super.EEItemDetached(item, slot_name);
362
363 switch (slot_name)
364 {
368 OnTriggerDetached(FindAttachmentBySlotName(slot_name));
369 break;
370 }
371 }
372
373 override void OnBeforeDisarm()
374 {
376 }
377
378 override void OnDisarmed(bool pWithTool)
379 {
380 super.OnDisarmed(pWithTool);
381
382 UnpairRemote();
383
384 array<ItemBase> attachmentsCache = new array<ItemBase>();
385 for (int attachmentIdx = 0; attachmentIdx < GetInventory().AttachmentCount(); attachmentIdx++)
386 {
387 ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(attachmentIdx));
388 if (attachment)
389 {
390 attachmentsCache.Insert(attachment);
391 }
392 }
393
394 foreach (ItemBase attachment1 : attachmentsCache)
395 attachment1.UnlockFromParent();
396
398 foreach (ItemBase attachment2 : attachmentsCache)
399 {
400 if (attachment2.IsInherited(ClockBase))
401 {
402 if (pWithTool)
403 GetInventory().DropEntity(InventoryMode.SERVER, this, attachment2);
404 }
405
406 if (attachment2.IsInherited(RemoteDetonator))
407 {
408 if (pWithTool)
409 {
410 GetInventory().DropEntity(InventoryMode.SERVER, this, attachment2);
411 attachment2.SetHealth("", "", 0.0);
412 }
413 else
414 {
415 attachment2.Delete();
416 }
417 }
418 }
419
421 SetTakeable(true);
422 }
423
424 override void UpdateLED(int pState)
425 {
426 RemoteDetonatorReceiver receiver = RemoteDetonatorReceiver.Cast(FindAttachmentBySlotName(SLOT_TRIGGER_REMOTE));
427 if (receiver)
428 receiver.UpdateLED(pState, true);
429 }
430
431 protected void OnTriggerAttached(EntityAI entity)
432 {
433 UpdateVisuals(entity);
435
436 if (entity.IsInherited(ClockBase))
437 Arm();
438
441 }
442
443 protected void OnTriggerDetached(EntityAI entity)
444 {
445 UpdateVisuals(null);
447 }
448
449 protected void UpdateVisuals(EntityAI entity)
450 {
451 if (entity)
452 {
453 if (entity.IsInherited(RemoteDetonator))
454 {
455 SetAnimationPhase(ANIM_PHASE_TRIGGER_EMPTY, 1.0);
456 SetAnimationPhase(ANIM_PHASE_TRIGGER_TIMER, 1.0);
457 SetAnimationPhase(ANIM_PHASE_TRIGGER_CLOCK, 1.0);
458 SetAnimationPhase(ANIM_PHASE_TRIGGER_REMOTE, 0.0);
459 }
460 else if (entity.IsInherited(AlarmClock_ColorBase))
461 {
462 SetAnimationPhase(ANIM_PHASE_TRIGGER_EMPTY, 1.0);
463 SetAnimationPhase(ANIM_PHASE_TRIGGER_TIMER, 1.0);
464 SetAnimationPhase(ANIM_PHASE_TRIGGER_CLOCK, 0.0);
465 SetAnimationPhase(ANIM_PHASE_TRIGGER_REMOTE, 1.0);
466 }
467 else if (entity.IsInherited(KitchenTimer))
468 {
469 SetAnimationPhase(ANIM_PHASE_TRIGGER_EMPTY, 1.0);
470 SetAnimationPhase(ANIM_PHASE_TRIGGER_TIMER, 0.0);
471 SetAnimationPhase(ANIM_PHASE_TRIGGER_CLOCK, 1.0);
472 SetAnimationPhase(ANIM_PHASE_TRIGGER_REMOTE, 1.0);
473 }
474 }
475 else
476 {
477 SetAnimationPhase(ANIM_PHASE_TRIGGER_EMPTY, 0.0);
478 SetAnimationPhase(ANIM_PHASE_TRIGGER_TIMER, 1.0);
479 SetAnimationPhase(ANIM_PHASE_TRIGGER_CLOCK, 1.0);
480 SetAnimationPhase(ANIM_PHASE_TRIGGER_REMOTE, 1.0);
481 }
482 }
483
484 override string GetDeploySoundset()
485 {
486 return "placeImprovisedExplosive_SoundSet";
487 }
488
489 override string GetLoopDeploySoundset()
490 {
491 return "improvisedexplosive_deploy_SoundSet";
492 }
493
494 override string GetArmSoundset()
495 {
496 return "ImprovisedExplosive_disarm_SoundSet";
497 }
498
499 override string GetDisarmSoundset()
500 {
501 return "ImprovisedExplosive_disarm_SoundSet";
502 }
503
504
505#ifdef DEVELOPER
506 override protected string GetDebugText()
507 {
508 string debug_output;
509 debug_output += string.Format("low net id: %1\n", m_RAIB.GetPairDeviceNetIdLow());
510 debug_output += string.Format("high net id: %1\n", m_RAIB.GetPairDeviceNetIdHigh());
511 debug_output += string.Format("pair device: %1\n", m_RAIB.GetPairDevice());
512
513 return debug_output;
514 }
515#endif
516}
517
518class ImprovisedExplosivePlacing : ImprovisedExplosive {}
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition inventory.c:22
void AddAction(typename actionName)
PlayerSpawnPreset slotName
const string ANIM_PHASE_TRIGGER_REMOTE
override void OnBeforeDisarm()
override void UnlockExplosivesSlots()
const float TIME_TRIGGER_DELAY_SECS
override void LockExplosivesSlots()
void OnTriggerDetached(EntityAI entity)
const string ANIM_PHASE_TRIGGER_CLOCK
override string GetDisarmSoundset()
static const string SLOT_TRIGGER_ALARM_CLOCK
override bool HasLockedTriggerSlots()
static const string SLOT_EXPLOSIVE_A
static const string SLOT_TRIGGER_KITCHEN_TIMER
void UpdateVisuals(EntityAI entity)
const float TIME_TRIGGER_INITIAL_DELAY_SECS
override void OnVariablesSynchronized()
override bool IsDeployable()
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
const float TIME_TRIGGER_TIMER_BASED_DELAY_SECS
const string SLOT_EXPLOSIVES[SLOT_EXPLOSIVE_COUNT]
override void PairRemote(notnull EntityAI trigger)
const string SLOT_TRIGGERS[SLOT_TRIGGERS_COUNT]
override void EEItemDetached(EntityAI item, string slot_name)
override void EEItemAttached(EntityAI item, string slot_name)
override bool CanReceiveAttachment(EntityAI attachment, int slotId)
const string ANIM_PHASE_TRIGGER_EMPTY
override void UnlockTriggerSlots()
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
override string GetLoopDeploySoundset()
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
override void EOnInit(IEntity other, int extra)
static const string SLOT_EXPLOSIVE_B
const string ANIM_PHASE_TRIGGER_TIMER
static const string SLOT_TRIGGER_REMOTE
ref RemotelyActivatedItemBehaviour m_RAIB
override bool IsTimerDetonable()
void InitiateExplosion()
not exploding itself, rely on attached explosives
override void LockTriggerSlots()
override bool CanDisplayAttachmentSlot(int slot_id)
override RemotelyActivatedItemBehaviour GetRemotelyActivatedItemBehaviour()
override void OnStoreSave(ParamsWriteContext ctx)
override string GetArmSoundset()
override string GetDeploySoundset()
void OnTriggerAttached(EntityAI entity)
override void OnDisarmed(bool pWithTool)
override void UpdateLED(int pState)
override bool OnStoreLoad(ParamsReadContext ctx, int version)
override void OnActivatedByItem(notnull ItemBase item)
override bool CanBeDisarmed()
override EntityAI GetPairDevice()
InventoryLocation.
provides access to slot configuration
Serialization general interface. Serializer API works with:
Definition serializer.c:56
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
void UpdateVisuals()
DayZGame g_Game
Definition dayzgame.c:3868
void SetArmed(bool state)
bool GetArmed()
const string ANIM_PHASE_VISIBILITY
override void UnpairRemote()
void Arm()
proto native CGame GetGame()
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8
InventoryLocationType
types of Inventory Location
override void SetTakeable(bool pState)
Definition itembase.c:9184
string GetDebugText()
RemoteDetonatorTrigger RemoteDetonator RemoteDetonatorReceiver()
ERemoteDetonatorLEDState