Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
remotedetonator.c
Go to the documentation of this file.
2 {
3  OFF = 0,
4  LIT,
5 }
6 
7 class RemoteDetonator : Inventory_Base
8 {
9  const string COLOR_LED_OFF = "#(argb,8,8,3)color(0,0,0,1.0,co)";
10  const string COLOR_LED_LIT = "#(argb,8,8,3)color(1,0,0,1.0,co)";
11  const string SELECTION_NAME_LED = "LED";
12 
14 
15  bool IsKit()
16  {
17  return true;
18  }
19 
20  void UpdateLED(ERemoteDetonatorLEDState pState, bool pForced = false)
21  {
22  int selectionIdx = GetHiddenSelectionIndex(SELECTION_NAME_LED);
23 
24  switch (pState)
25  {
26  case ERemoteDetonatorLEDState.LIT:
27  SetObjectTexture(selectionIdx, COLOR_LED_LIT);
28  break;
29  default:
30  SetObjectTexture(selectionIdx, COLOR_LED_OFF);
31  }
32 
33  m_LastLEDState = pState;
34  SetSynchDirty();
35  }
36 
37  override void SetActions()
38  {
39  super.SetActions();
40 
43  }
44 }
45 
46 class RemoteDetonatorTrigger : RemoteDetonator
47 {
48  protected const string ANIM_PHASE_TRIGGER = "trigger";
49 
50  protected bool m_LED;
51  protected ref RemotelyActivatedItemBehaviour m_RAIB;
52 
54  {
56  m_RAIB.SetTrigger();
57 
58  RegisterNetSyncVariableInt("m_RAIB.m_PairDeviceNetIdLow");
59  RegisterNetSyncVariableInt("m_RAIB.m_PairDeviceNetIdHigh");
60  RegisterNetSyncVariableInt("m_LastLEDState", 0, EnumTools.GetEnumSize(ERemoteDetonatorLEDState));
61 
63  }
64 
65  override bool IsKit()
66  {
67  return false;
68  }
69 
70  override void OnVariablesSynchronized()
71  {
72  super.OnVariablesSynchronized();
73 
74  if (m_RAIB)
75  {
76  m_RAIB.OnVariableSynchronized();
77  }
78 
80  }
81 
82  override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
83  {
84  super.EEItemLocationChanged(oldLoc, newLoc);
85 
86  if (m_RAIB)
87  {
88  m_RAIB.Pair();
89  }
90  }
91 
92  override RemotelyActivatedItemBehaviour GetRemotelyActivatedItemBehaviour()
93  {
94  return m_RAIB;
95  }
96 
97  override void OnCEUpdate()
98  {
99  super.OnCEUpdate();
100 
101  if (!IsRuined() && IsConnected() && GetControlledDevice())
102  {
103  if (vector.DistanceSq(GetPosition(), GetControlledDevice().GetPosition()) <= Math.SqrFloat(UAMaxDistances.EXPLOSIVE_REMOTE_ACTIVATION))
104  {
106 
107  return;
108  }
109  }
110 
112  }
113 
114  override void PairRemote(notnull EntityAI trigger)
115  {
116  m_RAIB.Pair(trigger);
117  }
118 
119  override void UnpairRemote()
120  {
122  m_RAIB.Unpair();
123  }
124 
125  override void OnActivatedByItem(notnull ItemBase item)
126  {
127  if (GetGame().IsServer())
128  {
129  if (m_RAIB.IsPaired() && !IsRuined())
130  {
131  ItemBase device = ItemBase.Cast(GetControlledDevice());
132  if (device && vector.DistanceSq(GetPosition(), device.GetPosition()) <= Math.SqrFloat(UAMaxDistances.EXPLOSIVE_REMOTE_ACTIVATION))
133  {
134  device.OnActivatedByItem(this);
135  }
136  }
137  }
138  }
139 
140  void SetControlledDevice(EntityAI pDevice)
141  {
142  m_RAIB.Pair(pDevice);
143  }
144 
145  bool IsConnected()
146  {
147  return m_RAIB.IsPaired();
148  }
149 
150  EntityAI GetControlledDevice()
151  {
152  return m_RAIB.GetPairDevice();
153  }
154 
155  static RemoteDetonatorTrigger SpawnInPlayerHands(notnull EntityAI pEntity, EntityAI deviceToPair = null)
156  {
157  string type = "RemoteDetonatorTrigger";
159  PlayerBase player = PlayerBase.Cast(pEntity);
160  if (player)
161  {
162  ItemBase inHandsItem = player.GetItemInHands();
163  if (inHandsItem)
164  {
165  if (deviceToPair)
166  {
167  ReplaceDetonatorItemOnArmLambda onArmLambda = new ReplaceDetonatorItemOnArmLambda(inHandsItem, type);
168  onArmLambda.SetPairDevice(deviceToPair);
169  MiscGameplayFunctions.TurnItemIntoItemEx(player, onArmLambda);
170  }
171  else
172  {
173  ReplaceDetonatorItemLambda lambda = new ReplaceDetonatorItemLambda(inHandsItem, type);
174  MiscGameplayFunctions.TurnItemIntoItemEx(player, lambda);
175  }
176 
177 
178  rdt = RemoteDetonatorTrigger.Cast(player.GetItemInHands());
179  }
180  else
181  rdt = RemoteDetonatorTrigger.Cast(player.GetHumanInventory().CreateInHands(type));
182 
184  if (player.GetItemInHands())
185  player.GetItemAccessor().OnItemInHandsChanged();
186  }
187 
188  return rdt;
189  }
190 
191  override void OnAnimationPhaseStarted(string animSource, float phase)
192  {
193  if (animSource == ANIM_PHASE_TRIGGER)
194  {
195  if (phase > 0.01)
196  {
198  }
199  }
200  }
201 
202  override void SetActions()
203  {
204  super.SetActions();
205 
207 
211  }
212 
213 #ifdef DIAG_DEVELOPER
214  override protected string GetDebugText()
215  {
216  string debug_output;
217  debug_output += string.Format("low net id: %1\n", m_RAIB.GetPairDeviceNetIdLow());
218  debug_output += string.Format("high net id: %1\n", m_RAIB.GetPairDeviceNetIdHigh());
219  debug_output += string.Format("pair device: %1\n", m_RAIB.GetPairDevice());
220  return debug_output;
221  }
222 #endif
223 }
224 
225 class RemoteDetonatorReceiver : RemoteDetonator
226 {
228  {
230  }
231 
232  override bool IsKit()
233  {
234  return false;
235  }
236 
237  override void OnWasDetached(EntityAI parent, int slot_id)
238  {
240  }
241 
242  override void EEKilled(Object killer)
243  {
244  super.EEKilled(killer);
245 
247  }
248 
249  override void SetActions()
250  {
251  super.SetActions();
252 
255  }
256 }
257 
259 {
260  override void CopyOldPropertiesToNew(notnull EntityAI old_item, EntityAI new_item)
261  {
262  super.CopyOldPropertiesToNew(old_item, new_item);
263 
264  MiscGameplayFunctions.TransferItemProperties(old_item, new_item);
265  }
266 }
267 
268 class ReplaceDetonatorItemOnArmLambda : ReplaceDetonatorItemLambda
269 {
270  EntityAI m_PairDevice
271 
272  void SetPairDevice(EntityAI device)
273  {
274  m_PairDevice = device;
275  }
276 
277  override void OnSuccess(EntityAI new_item)
278  {
279  super.OnSuccess(new_item);
280 
281  RemoteDetonator detonator = RemoteDetonator.Cast(new_item);
282  if (detonator)
283  {
284  ExplosivesBase explosive = ExplosivesBase.Cast(m_PairDevice);
285  if (explosive)
286  {
287  ItemBase receiver = ItemBase.Cast(explosive.GetInventory().CreateAttachment("RemoteDetonatorReceiver"));
288  if (receiver)
289  {
290  MiscGameplayFunctions.TransferItemProperties(detonator, receiver);
291  receiver.LockToParent();
292  explosive.SetTakeable(false);
293  explosive.PairWithDevice(detonator);
294  explosive.Arm();
295  }
296  }
297  }
298  }
299 
300  override void OnAbort()
301  {
302  ExplosivesBase explosive = ExplosivesBase.Cast(m_PairDevice);
303  if (explosive)
304  {
305  explosive.LockTriggerSlots();
306  explosive.SetTakeable(true);
307  }
308  }
309 }
310 
312 {
313  override void OnSuccess(EntityAI new_item)
314  {
315  super.OnSuccess(new_item);
316 
317  RemoteDetonator detonator = RemoteDetonator.Cast(m_OldItem);
318  if (detonator)
319  {
320  if (detonator.GetRemotelyActivatedItemBehaviour())
321  {
322  ExplosivesBase explosive = ExplosivesBase.Cast(detonator.GetRemotelyActivatedItemBehaviour().GetPairDevice());
323  if (explosive)
324  {
325  explosive.Disarm();
326  }
327  }
328  }
329  }
330 
331  override void OnAbort()
332  {
333  super.OnAbort();
334 
335  RemoteDetonator detonator = RemoteDetonator.Cast(m_OldItem);
336  if (detonator)
337  {
338  if (detonator.GetRemotelyActivatedItemBehaviour())
339  {
340  ExplosivesBase explosive = ExplosivesBase.Cast(detonator.GetRemotelyActivatedItemBehaviour().GetPairDevice());
341  if (explosive)
342  {
343  explosive.LockExplosivesSlots();
344  }
345  }
346  }
347  }
348 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
OnAbort
override void OnAbort()
Definition: remotedetonator.c:300
ERemoteDetonatorLEDState
ERemoteDetonatorLEDState
Definition: remotedetonator.c:1
LIT
@ LIT
Definition: remotedetonator.c:4
ActionTriggerRemotely
Definition: actiontriggerremotely.c:1
ActionAttachOnTrap
Definition: actionattachontrap.c:1
ReplaceDetonatorItemLambda
Definition: remotedetonator.c:258
ActionAttachExplosivesTrigger
ActionBreakLongWoodenStickCB ActionAttachExplosivesTrigger
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
RemoveAction
void RemoveAction(typename actionName)
Definition: advancedcommunication.c:118
m_LastLEDState
protected ERemoteDetonatorLEDState m_LastLEDState
Definition: remotedetonator.c:13
RemotelyActivatedItemBehaviour
Definition: remotelyactivateditembehaviour.c:1
ActionDisarmExplosiveWithRemoteDetonatorUnpaired
ActionDisarmExplosiveWithRemoteDetonatorUnpairedCB ActionDisarmExplosiveCB ActionDisarmExplosiveWithRemoteDetonatorUnpaired()
Definition: actiondisarmexplosivewithremotedetonatorunpaired.c:11
UAMaxDistances
Definition: actionconstants.c:104
COLOR_LED_LIT
const string COLOR_LED_LIT
Definition: remotedetonator.c:10
COLOR_LED_OFF
enum ERemoteDetonatorLEDState COLOR_LED_OFF
IsKit
bool IsKit()
Definition: remotedetonator.c:15
ExplosivesBase
void ExplosivesBase()
Definition: explosivesbase.c:40
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
EnumTools
Definition: enconvert.c:589
RemoteDetonatorReceiver
RemoteDetonatorTrigger RemoteDetonator RemoteDetonatorReceiver()
Definition: remotedetonator.c:227
GetDebugText
string GetDebugText()
Definition: modifierbase.c:68
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
SetPairDevice
ReplaceDetonatorItemLambda ReplaceItemWithNewLambdaBase SetPairDevice(EntityAI device)
Definition: remotedetonator.c:272
Object
Definition: objecttyped.c:1
EEKilled
override void EEKilled(Object killer)
Definition: remotedetonator.c:242
OnWasDetached
override void OnWasDetached(EntityAI parent, int slot_id)
Definition: remotedetonator.c:237
RemoteDetonatorTrigger
Definition: remotedetonator.c:46
OnSuccess
override void OnSuccess(EntityAI new_item)
Definition: remotedetonator.c:277
OFF
@ OFF
Definition: remotedetonator.c:3
ReplaceDetonatorItemOnDisarmLambda
Definition: remotedetonator.c:311
m_RAIB
protected ref RemotelyActivatedItemBehaviour m_RAIB
Definition: remotedetonator.c:41
SELECTION_NAME_LED
const string SELECTION_NAME_LED
Definition: remotedetonator.c:11
UpdateLED
void UpdateLED(ERemoteDetonatorLEDState pState, bool pForced=false)
Definition: remotedetonator.c:20
ANIM_PHASE_TRIGGER
const protected string ANIM_PHASE_TRIGGER
Definition: remotedetonator.c:38
ReplaceItemWithNewLambdaBase
base class for transformation operations (creating one item from another)
Definition: replaceitemwithnewlambdabase.c:4
Inventory_Base
Definition: barbedbaseballbat.c:1
SetActions
override void SetActions()
Definition: remotedetonator.c:37
Math
Definition: enmath.c:6
EntityAI
Definition: building.c:5
ActionDisarmExplosiveWithRemoteDetonator
ActionDisarmExplosiveWithRemoteDetonatorCB ActionDisarmExplosiveCB ActionDisarmExplosiveWithRemoteDetonator()
Definition: actiondisarmexplosivewithremotedetonator.c:11