Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
improvisedexplosive.c
Go to the documentation of this file.
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;
15  protected const string SLOT_EXPLOSIVES[SLOT_EXPLOSIVE_COUNT] = {
16  SLOT_EXPLOSIVE_A,
17  SLOT_EXPLOSIVE_B
18  };
19 
20  protected const int SLOT_TRIGGERS_COUNT = 3;
21  protected const string SLOT_TRIGGERS[SLOT_TRIGGERS_COUNT] = {
22  SLOT_TRIGGER_ALARM_CLOCK,
23  SLOT_TRIGGER_KITCHEN_TIMER,
24  SLOT_TRIGGER_REMOTE
25  };
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 
32  protected ref RemotelyActivatedItemBehaviour m_RAIB;
33 
34  void ImprovisedExplosive()
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())
45  LockTriggerSlots();
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 
102  override void OnStoreSave(ParamsWriteContext ctx)
103  {
104  super.OnStoreSave(ctx);
105 
106  LockTriggerSlots();
107  }
108 
109  override void OnVariablesSynchronized()
110  {
111  super.OnVariablesSynchronized();
112 
113  if (m_RAIB)
114  {
115  m_RAIB.OnVariableSynchronized();
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 
150  override RemotelyActivatedItemBehaviour GetRemotelyActivatedItemBehaviour()
151  {
152  return m_RAIB;
153  }
154 
155  override void PairRemote(notnull EntityAI trigger)
156  {
157  m_RAIB.Pair(trigger);
158  }
159 
160  override EntityAI GetPairDevice()
161  {
162  return m_RAIB.GetPairDevice();
163  }
164 
165  override bool CanBeArmed()
166  {
167  if (GetArmed())
168  return false;
169 
170  if (!HasLockedTriggerSlots())
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  {
212  case SLOT_TRIGGER_ALARM_CLOCK:
213  case SLOT_TRIGGER_KITCHEN_TIMER:
214  case SLOT_TRIGGER_REMOTE:
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  {
314  delayFor = TIME_TRIGGER_INITIAL_DELAY_SECS + TIME_TRIGGER_TIMER_BASED_DELAY_SECS;
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  {
351  case SLOT_TRIGGER_ALARM_CLOCK:
352  case SLOT_TRIGGER_KITCHEN_TIMER:
353  case SLOT_TRIGGER_REMOTE:
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  {
365  case SLOT_TRIGGER_ALARM_CLOCK:
366  case SLOT_TRIGGER_KITCHEN_TIMER:
367  case SLOT_TRIGGER_REMOTE:
368  OnTriggerDetached(FindAttachmentBySlotName(slot_name));
369  break;
370  }
371  }
372 
373  override void OnBeforeDisarm()
374  {
375  UnlockExplosivesSlots();
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 
420  LockTriggerSlots();
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);
434  UpdateLED(ERemoteDetonatorLEDState.LIT);
435 
436  if (entity.IsInherited(ClockBase))
437  Arm();
438 
439  LockTriggerSlots();
440  LockExplosivesSlots();
441  }
442 
443  protected void OnTriggerDetached(EntityAI entity)
444  {
445  UpdateVisuals(null);
446  UpdateLED(ERemoteDetonatorLEDState.OFF);
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 protected bool UsesGlobalDeploy()
495  {
496  return true;
497  }
498 
499 #ifdef DEVELOPER
500  override protected string GetDebugText()
501  {
502  string debug_output;
503  debug_output += string.Format("low net id: %1\n", m_RAIB.GetPairDeviceNetIdLow());
504  debug_output += string.Format("high net id: %1\n", m_RAIB.GetPairDeviceNetIdHigh());
505  debug_output += string.Format("pair device: %1\n", m_RAIB.GetPairDevice());
506 
507  return debug_output;
508  }
509 #endif
510 }
511 
512 class ImprovisedExplosivePlacing : ImprovisedExplosive {}
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
CALL_CATEGORY_SYSTEM
const int CALL_CATEGORY_SYSTEM
Definition: tools.c:8
ActionDeployObject
PlaceObjectActionReciveData ActionReciveData ActionDeployObject()
Definition: actiondeployobject.c:9
ERemoteDetonatorLEDState
ERemoteDetonatorLEDState
Definition: remotedetonator.c:1
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
GetArmed
bool GetArmed()
Definition: explosivesbase.c:236
KitchenTimer
Definition: kitchentimer.c:1
Arm
void Arm()
Definition: explosivesbase.c:207
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
ClockBase
void ClockBase()
Definition: clockbase.c:27
RemotelyActivatedItemBehaviour
Definition: remotelyactivateditembehaviour.c:1
IEntity
Definition: enentity.c:164
SetTakeable
override void SetTakeable(bool pState)
Definition: itembase.c:4226
ActionTogglePlaceObject
Definition: actiontoggleplaceobject.c:1
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
ExplosivesBase
void ExplosivesBase()
Definition: explosivesbase.c:40
vector
Definition: enconvert.c:105
InventoryMode
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition: inventory.c:21
UnpairRemote
override void UnpairRemote()
Definition: remotedetonator.c:109
RemoteDetonatorReceiver
RemoteDetonatorTrigger RemoteDetonator RemoteDetonatorReceiver()
Definition: remotedetonator.c:227
InventoryLocationType
InventoryLocationType
types of Inventory Location
Definition: inventorylocation.c:3
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
GetDebugText
string GetDebugText()
Definition: modifierbase.c:68
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
slotName
PlayerSpawnPreset slotName
array< ItemBase >
m_RAIB
protected ref RemotelyActivatedItemBehaviour m_RAIB
Definition: remotedetonator.c:41
GameConstants
Definition: constants.c:612
ImprovisedExplosive
Definition: improvisedexplosive.c:1
ANIM_PHASE_VISIBILITY
const protected string ANIM_PHASE_VISIBILITY
Definition: explosivesbase.c:22
AlarmClock_ColorBase
Definition: alarmclock.c:1
EntityAI
Definition: building.c:5
SetArmed
protected void SetArmed(bool state)
Definition: explosivesbase.c:241