Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
plastic_explosive.c
Go to the documentation of this file.
2 {
3  protected const string SLOT_TRIGGER = "TriggerRemoteDetonator_Receiver";
4  protected const string ANIM_PHASE_TRIGGER_REMOTE = "TriggerRemote";
5 
6  protected bool m_UsedAsCharge;
7 
8  protected ref RemotelyActivatedItemBehaviour m_RAIB;
9 
10  void Plastic_Explosive()
11  {
13 
14  SetAmmoType("Plastic_Explosive_Ammo");
15  SetParticleExplosion(ParticleList.PLASTIC_EXPLOSION);
16 
17  RegisterNetSyncVariableInt("m_RAIB.m_PairDeviceNetIdLow");
18  RegisterNetSyncVariableInt("m_RAIB.m_PairDeviceNetIdHigh");
19  }
20 
21  override void EOnInit(IEntity other, int extra)
22  {
23  if (!g_Game.IsMultiplayer())
24  LockTriggerSlots();
25  }
26 
28  override void EEKilled(Object killer)
29  {
30  //analytics (behaviour from EntityAI)
31  GetGame().GetAnalyticsServer().OnEntityKilled(killer, this);
32  }
33 
34  override bool HasLockedTriggerSlots()
35  {
36  return GetInventory().GetSlotLock(InventorySlots.GetSlotIdFromString(SLOT_TRIGGER));
37  }
38 
39  override void LockTriggerSlots()
40  {
41  GetInventory().SetSlotLock(InventorySlots.GetSlotIdFromString(SLOT_TRIGGER), true);
42  }
43 
44  override void UnlockTriggerSlots()
45  {
46  GetInventory().SetSlotLock(InventorySlots.GetSlotIdFromString(SLOT_TRIGGER), false);
47  }
48 
49  override bool OnStoreLoad(ParamsReadContext ctx, int version)
50  {
51  if (!super.OnStoreLoad(ctx, version))
52  return false;
53 
54  if (version <= 134) // up to 1.21
55  {
56  int slotId = InventorySlots.GetSlotIdFromString(SLOT_TRIGGER);
57  bool locked = GetInventory().GetSlotLock(slotId);
58  while (locked)
59  {
60  GetInventory().SetSlotLock(slotId, false);
61  locked = GetInventory().GetSlotLock(slotId);
62  }
63  }
64 
65  return true;
66  }
67 
68  override void OnStoreSave(ParamsWriteContext ctx)
69  {
70  super.OnStoreSave(ctx);
71 
72  LockTriggerSlots();
73  }
74 
75  override void OnVariablesSynchronized()
76  {
77  super.OnVariablesSynchronized();
78 
79  if (m_RAIB)
80  {
81  m_RAIB.OnVariableSynchronized();
82  }
83 
84  int slotId = InventorySlots.GetSlotIdFromString(SLOT_TRIGGER);
85  UpdateVisuals(GetInventory().FindAttachment(slotId));
86  }
87 
88  override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
89  {
90  super.EEItemLocationChanged(oldLoc, newLoc);
91 
92  if (m_RAIB)
93  {
94  m_RAIB.Pair();
95  }
96  }
97 
98  override bool CanReceiveAttachment(EntityAI attachment, int slotId)
99  {
101  GetInventory().GetCurrentInventoryLocation(il);
102  if (il.GetType() == InventoryLocationType.HANDS)
103  {
104  return false;
105  }
106 
107  ClockBase timer = ClockBase.Cast(attachment);
108  if (timer && !timer.IsAlarmOn())
109  {
110  return false;
111  }
112 
113  return !GetArmed();
114  }
115 
116  override bool CanDisplayAttachmentSlot(int slot_id)
117  {
118  string slotName = InventorySlots.GetSlotName(slot_id);
119 
120  switch (slotName)
121  {
122  case SLOT_TRIGGER:
123  return FindAttachmentBySlotName(slotName) != null;
124  break;
125  }
126 
127  return true;
128  }
129 
130  override bool IsTakeable()
131  {
132  return !GetArmed() && super.IsTakeable();
133  }
134 
135  override bool IsDeployable()
136  {
137  return !GetArmed();
138  }
139 
140  override void SetActions()
141  {
142  super.SetActions();
143 
146  }
147 
148  override void OnWasAttached(EntityAI parent, int slot_id)
149  {
150  super.OnWasAttached(parent, slot_id);
151 
152  m_UsedAsCharge = false;
153 
154  if (parent && parent.IsInherited(ExplosivesBase))
155  {
156  m_UsedAsCharge = true;
157  }
158  }
159 
160  override void OnWasDetached(EntityAI parent, int slot_id)
161  {
162  super.OnWasDetached(parent, slot_id);
163 
164  if (parent && !parent.IsInherited(ExplosivesBase))
165  {
166  m_UsedAsCharge = false;
167  }
168  }
169 
170  override bool EEOnDamageCalculated(TotalDamageResult damageResult, int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos, float speedCoef)
171  {
173  if (damageType == DamageType.EXPLOSION)
174  {
175  return !m_UsedAsCharge;
176  }
177 
178  return true;
179  }
180 
181  override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
182  {
183  super.EEHealthLevelChanged(oldLevel, newLevel, zone);
184 
185  if (GetGame().IsServer())
186  {
187  if (newLevel == GameConstants.STATE_RUINED)
188  {
189  for (int attachmentIdx = 0; attachmentIdx < GetInventory().AttachmentCount(); attachmentIdx++)
190  {
191  ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(attachmentIdx));
192  if (attachment)
193  {
194  attachment.UnlockFromParent();
195  attachment.SetHealth("", "", 0.0);
196  }
197  }
198 
199  SetArmed(false);
200  SetTakeable(true);
201  }
202  }
203  }
204 
205  override RemotelyActivatedItemBehaviour GetRemotelyActivatedItemBehaviour()
206  {
207  return m_RAIB;
208  }
209 
210  override void PairRemote(notnull EntityAI trigger)
211  {
212  m_RAIB.Pair(trigger);
213  }
214 
215 
216  override EntityAI GetPairDevice()
217  {
218  return m_RAIB.GetPairDevice();
219  }
220 
221  override bool CanBeArmed()
222  {
223  if (!super.CanBeArmed())
224  {
225  return false;
226  }
227 
228  return HasLockedTriggerSlots() && !GetArmed();
229  }
230 
231  override bool CanBeDisarmed()
232  {
233  return GetArmed();
234  }
235 
236  override void OnActivatedByItem(notnull ItemBase item)
237  {
238  if (GetGame().IsServer())
239  {
240  if (GetHealthLevel("") == GameConstants.STATE_RUINED)
241  {
242  return;
243  }
244 
245  if (item == this)
246  {
247  SetHealth("", "", 0.0);
249  return;
250  }
251 
252  if (m_RAIB.IsPaired() && GetArmed())
253  {
254  if (GetPairDevice() == item)
255  {
256  SetHealth("", "", 0.0);
258  }
259  }
260  }
261  }
262 
263  override void OnDisarmed(bool pWithTool)
264  {
265  super.OnDisarmed(pWithTool);
266 
267  UnpairRemote();
268  UpdateVisuals(null);
269 
270  for (int att = 0; att < GetInventory().AttachmentCount(); att++)
271  {
272  ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(att));
273  if (attachment)
274  {
275  attachment.UnlockFromParent();
276  if (attachment.IsInherited(RemoteDetonator))
277  {
278  if (pWithTool)
279  {
280  GetInventory().DropEntity(InventoryMode.SERVER, this, attachment);
281  attachment.SetHealth("", "", 0.0);
282  }
283  else
284  {
285  attachment.Delete();
286  }
287  }
288  }
289  }
290 
291  LockTriggerSlots();
292  SetTakeable(true);
293  }
294 
295  override void EEItemAttached(EntityAI item, string slot_name)
296  {
297  super.EEItemAttached(item, slot_name);
298 
299  if (slot_name == SLOT_TRIGGER)
300  OnTriggerAttached(item);
301  }
302 
303  override void EEItemDetached(EntityAI item, string slot_name)
304  {
305  super.EEItemDetached(item, slot_name);
306 
307  if (slot_name == SLOT_TRIGGER)
308  OnTriggerDetached(item);
309  }
310 
311  override void UpdateLED(int pState)
312  {
313  RemoteDetonatorReceiver receiver = RemoteDetonatorReceiver.Cast(FindAttachmentBySlotName(SLOT_TRIGGER));
314  if (receiver)
315  {
316  receiver.UpdateLED(pState, true);
317  }
318  }
319 
320  protected void OnTriggerAttached(EntityAI entity)
321  {
322  Arm();
323  UpdateVisuals(entity);
324  UpdateLED(ERemoteDetonatorLEDState.LIT);
325 
326  for (int att = 0; att < GetInventory().AttachmentCount(); att++)
327  {
328  ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(att));
329  if (attachment)
330  {
331  attachment.LockToParent();
332  }
333  }
334  }
335 
336  protected void OnTriggerDetached(EntityAI entity)
337  {
338  UpdateVisuals(null);
339  UpdateLED(ERemoteDetonatorLEDState.OFF);
340  }
341 
342  protected void UpdateVisuals(EntityAI entity)
343  {
344  if (entity)
345  {
346  SetAnimationPhase(ANIM_PHASE_TRIGGER_REMOTE, 0.0);
347  }
348  else
349  {
350  SetAnimationPhase(ANIM_PHASE_TRIGGER_REMOTE, 1.0);
351  }
352  }
353 
354 
355  override string GetDeploySoundset()
356  {
357  return "placeImprovisedExplosive_SoundSet";
358  }
359 
360  override string GetLoopDeploySoundset()
361  {
362  return "improvisedexplosive_deploy_SoundSet";
363  }
364 
365  override protected bool UsesGlobalDeploy()
366  {
367  return true;
368  }
369 }
370 
371 class Plastic_Explosive_Placing : Plastic_Explosive {}
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
SetParticleExplosion
void SetParticleExplosion(int particle)
Definition: explosivesbase.c:294
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
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
component
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
InitiateExplosion
protected void InitiateExplosion()
Definition: explosivesbase.c:160
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
ParticleList
Definition: particlelist.c:11
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
TotalDamageResult
Definition: damagesystem.c:1
RemoteDetonatorReceiver
RemoteDetonatorTrigger RemoteDetonator RemoteDetonatorReceiver()
Definition: remotedetonator.c:227
InventoryLocationType
InventoryLocationType
types of Inventory Location
Definition: inventorylocation.c:3
DamageType
DamageType
exposed from C++ (do not change)
Definition: damagesystem.c:10
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
Object
Definition: objecttyped.c:1
slotName
PlayerSpawnPreset slotName
m_RAIB
protected ref RemotelyActivatedItemBehaviour m_RAIB
Definition: remotedetonator.c:41
GameConstants
Definition: constants.c:612
SetAmmoType
void SetAmmoType(string pAmmoType)
Definition: explosivesbase.c:283
Plastic_Explosive
Definition: plastic_explosive.c:1
EntityAI
Definition: building.c:5
SetArmed
protected void SetArmed(bool state)
Definition: explosivesbase.c:241