DayZ 1.24
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 {
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 m_RAIB.OnVariableSynchronized();
115
116
117 foreach (string slotName : SLOT_TRIGGERS)
118 {
119 EntityAI trigger = GetInventory().FindAttachmentByName(slotName);
120 if (trigger)
121 {
123 break;
124 }
125 }
126 }
127
128 override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
129 {
130 super.OnPlacementComplete(player, position, orientation);
131
132 if (GetGame().IsServer())
133 SetOrientation(vector.Up);
134 }
135
137 {
138 super.EEItemLocationChanged(oldLoc, newLoc);
139
140 if (m_RAIB)
141 m_RAIB.Pair();
142 }
143
148
150 {
151 m_RAIB.Pair(trigger);
152 }
153
155 {
156 return m_RAIB.GetPairDevice();
157 }
158
159 override bool CanBeArmed()
160 {
161 if (GetArmed())
162 return false;
163
165 return false;
166
167 foreach (string slotName : SLOT_EXPLOSIVES)
168 {
169 EntityAI explosive = GetInventory().FindAttachmentByName(slotName);
170 if (explosive)
171 return true;
172 }
173
174 return false;
175 }
176
177 override bool CanBeDisarmed()
178 {
179 return true;
180 }
181
182
184 {
186 GetInventory().GetCurrentInventoryLocation(il);
187
188 foreach (string slotName : SLOT_TRIGGERS)
189 {
191 {
192 if (il.GetType() == InventoryLocationType.HANDS)
193 return false;
194 }
195 }
196
197 return !GetArmed();
198 }
199
201 {
203
204 switch (slotName)
205 {
209 return FindAttachmentBySlotName(slotName) != null;
210 break;
211 }
212
213 return true;
214 }
215
216 override bool IsTimerDetonable()
217 {
218 return true;
219 }
220
221 override bool IsTakeable()
222 {
223 return !GetArmed() && super.IsTakeable();
224 }
225
226 override bool IsDeployable()
227 {
228 return !GetArmed();
229 }
230
231 override void SetActions()
232 {
233 super.SetActions();
234
236 AddAction(ActionDeployObject);
237 }
238
239 override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
240 {
241 super.EEHealthLevelChanged(oldLevel, newLevel, zone);
242
243 if (GetGame().IsServer())
244 {
246 {
247 for (int attachmentIdx = 0; attachmentIdx < GetInventory().AttachmentCount(); attachmentIdx++)
248 {
249 ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(attachmentIdx));
250 if (attachment)
251 {
252 attachment.UnlockFromParent();
253 attachment.SetHealth("", "", 0.0);
254 }
255 }
256
257 SetArmed(false);
258 SetTakeable(true);
259 }
260 }
261 }
262
264 {
265 if (GetGame().IsServer() && GetArmed())
266 {
267 bool isTimeTriggered = false;
268
270 for (int attachmentIdx = 0; attachmentIdx < GetInventory().AttachmentCount(); attachmentIdx++)
271 {
272 ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(attachmentIdx));
273 if (attachment)
275 }
276
278 attachment1.UnlockFromParent();
279
282 {
283 if (attachment2.IsInherited(ClockBase))
284 {
285 isTimeTriggered = true;
286 break;
287 }
288 }
289
292 {
293 if (attachment3)
294 {
295 vector dropExtents = "0.5 0.0 0.5";
296 if (isTimeTriggered)
297 dropExtents[1] = 0.15;
298
299 GetInventory().DropEntityInBounds(InventoryMode.SERVER, this, attachment3, dropExtents, 0, 0, 0);
300 attachment3.SetAnimationPhase(ANIM_PHASE_VISIBILITY, 1.0);
301 attachment3.SetTakeable(false);
302 }
303 }
304
306 if (isTimeTriggered)
307 {
310 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(DeleteSafe, delayFor * 1000, false);
311 }
312 else
313 DeleteSafe();
314
317 {
318 if (attachment4.IsAnyInherited({RemoteDetonator, ClockBase}))
319 {
321 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(attachment4.DeleteSafe, delayFor * 1000, false);
322 }
323
324 if (attachment4 && !attachment4.IsAnyInherited({RemoteDetonator, ClockBase}))
325 {
327 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLaterByName(attachment4, "OnActivatedByItem", delayFor * 1000, false, params);
329 }
330 }
331 }
332 }
333
335 override protected void InitiateExplosion();
336
337 override void EEItemAttached(EntityAI item, string slot_name)
338 {
339 super.EEItemAttached(item, slot_name);
340
341 switch (slot_name)
342 {
346 OnTriggerAttached(FindAttachmentBySlotName(slot_name));
347 break;
348 }
349 }
350
351 override void EEItemDetached(EntityAI item, string slot_name)
352 {
353 super.EEItemDetached(item, slot_name);
354
355 switch (slot_name)
356 {
360 OnTriggerDetached(FindAttachmentBySlotName(slot_name));
361 break;
362 }
363 }
364
365 override void OnBeforeDisarm()
366 {
368 }
369
370 override void OnDisarmed(bool pWithTool)
371 {
372 super.OnDisarmed(pWithTool);
373
374 UnpairRemote();
375
377 for (int attachmentIdx = 0; attachmentIdx < GetInventory().AttachmentCount(); attachmentIdx++)
378 {
379 ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(attachmentIdx));
380 if (attachment)
382 }
383
385 attachment1.UnlockFromParent();
386
389 {
390 if (attachment2.IsInherited(ClockBase))
391 {
392 if (pWithTool)
393 GetInventory().DropEntity(InventoryMode.SERVER, this, attachment2);
394 }
395
396 if (attachment2.IsInherited(RemoteDetonator))
397 {
398 if (pWithTool)
399 {
400 GetInventory().DropEntity(InventoryMode.SERVER, this, attachment2);
401 attachment2.SetHealth("", "", 0.0);
402 }
403 else
404 attachment2.Delete();
405 }
406 }
407
409 SetTakeable(true);
410 }
411
412 override void UpdateLED(int pState)
413 {
415 if (receiver)
416 receiver.UpdateLED(pState, true);
417 }
418
420 {
423
424 if (entity.IsInherited(ClockBase))
425 Arm();
426
429 }
430
436
438 {
439 if (entity)
440 {
441 if (entity.IsInherited(RemoteDetonator))
442 {
443 SetAnimationPhase(ANIM_PHASE_TRIGGER_EMPTY, 1.0);
444 SetAnimationPhase(ANIM_PHASE_TRIGGER_TIMER, 1.0);
445 SetAnimationPhase(ANIM_PHASE_TRIGGER_CLOCK, 1.0);
446 SetAnimationPhase(ANIM_PHASE_TRIGGER_REMOTE, 0.0);
447 }
448 else if (entity.IsInherited(AlarmClock_ColorBase))
449 {
450 SetAnimationPhase(ANIM_PHASE_TRIGGER_EMPTY, 1.0);
451 SetAnimationPhase(ANIM_PHASE_TRIGGER_TIMER, 1.0);
452 SetAnimationPhase(ANIM_PHASE_TRIGGER_CLOCK, 0.0);
453 SetAnimationPhase(ANIM_PHASE_TRIGGER_REMOTE, 1.0);
454 }
455 else if (entity.IsInherited(KitchenTimer))
456 {
457 SetAnimationPhase(ANIM_PHASE_TRIGGER_EMPTY, 1.0);
458 SetAnimationPhase(ANIM_PHASE_TRIGGER_TIMER, 0.0);
459 SetAnimationPhase(ANIM_PHASE_TRIGGER_CLOCK, 1.0);
460 SetAnimationPhase(ANIM_PHASE_TRIGGER_REMOTE, 1.0);
461 }
462 }
463 else
464 {
465 SetAnimationPhase(ANIM_PHASE_TRIGGER_EMPTY, 0.0);
466 SetAnimationPhase(ANIM_PHASE_TRIGGER_TIMER, 1.0);
467 SetAnimationPhase(ANIM_PHASE_TRIGGER_CLOCK, 1.0);
468 SetAnimationPhase(ANIM_PHASE_TRIGGER_REMOTE, 1.0);
469 }
470 }
471
472 override string GetDeploySoundset()
473 {
474 return "placeImprovisedExplosive_SoundSet";
475 }
476
477 override string GetLoopDeploySoundset()
478 {
479 return "improvisedexplosive_deploy_SoundSet";
480 }
481
482 override protected bool UsesGlobalDeploy()
483 {
484 return true;
485 }
486
487#ifdef DEVELOPER
488 override protected string GetDebugText()
489 {
490 string debug_output;
491 debug_output += string.Format("low net id: %1\n", m_RAIB.GetPairDeviceNetIdLow());
492 debug_output += string.Format("high net id: %1\n", m_RAIB.GetPairDeviceNetIdHigh());
493 debug_output += string.Format("pair device: %1\n", m_RAIB.GetPairDevice());
494
495 return debug_output;
496 }
497#endif
498}
499
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition Inventory.c:22
void AddAction(typename actionName)
PlayerSpawnPreset slotName
void UpdateVisuals()
DayZGame g_Game
Definition DayZGame.c:3528
void SetArmed(bool state)
bool GetArmed()
const string ANIM_PHASE_VISIBILITY
override void UnpairRemote()
void Arm()
InventoryLocationType
types of Inventory Location
override void SetTakeable(bool pState)
Definition ItemBase.c:8905
string GetDebugText()
RemoteDetonatorTrigger RemoteDetonator RemoteDetonatorReceiver()
ERemoteDetonatorLEDState
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
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 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
static proto native owned string GetSlotName(int id)
converts slot_id to string
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
static const vector Up
Definition EnConvert.c:107
proto native CGame GetGame()
const int STATE_RUINED
Definition constants.c:757
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8