Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionplugin.c
Go to the documentation of this file.
2 {
3  void ActionPlugIn()
4  {
5  m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_INTERACTONCE;
6  m_Text = "#plug_in";
7  }
8 
9  override void CreateConditionComponents()
10  {
13  }
14 
15  override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
16  {
17  if (player.IsPlacingLocal())
18  return false;
19 
20  ItemBase targetIB = ItemBase.Cast(target.GetObject());
21 
22  //Prevent plugging to items in inventory
23  if (targetIB && targetIB.GetHierarchyRoot() == targetIB && item)
24  {
25  if (item.HasEnergyManager() && !item.GetCompEM().IsPlugged() && targetIB.HasEnergyManager() && targetIB.GetCompEM().CanReceivePlugFrom(item))
26  {
27  return true;
28  }
29 
30  ItemBase attachedDevice = GetAttachedDevice(targetIB);
31  //Will only ever affect batteries
32  if (attachedDevice)
33  {
34  return attachedDevice.GetCompEM().HasFreeSocket();
35  }
36  }
37 
38  return false;
39  }
40 
41  override void OnExecuteServer(ActionData action_data)
42  {
43  ItemBase targetIB = ItemBase.Cast(action_data.m_Target.GetObject());
44 
45  if (targetIB.HasEnergyManager())
46  {
47  ItemBase attachedDevice = GetAttachedDevice(targetIB);
48  if (attachedDevice)
49  targetIB = attachedDevice;
50 
51  action_data.m_MainItem.GetCompEM().PlugThisInto(targetIB);
52 
53  if (!action_data.m_Player.IsPlacingServer())
54  {
55  action_data.m_Player.PlacingStartServer(action_data.m_MainItem);
56 
57  Process(action_data);
58  }
59  }
60  }
61 
62  void Process(ActionData action_data)
63  {
64  ItemBase targetIB = ItemBase.Cast(action_data.m_Target.GetObject());
65 
66  targetIB.GetInventory().TakeEntityAsAttachment(InventoryMode.LOCAL, action_data.m_MainItem);
67  }
68 
69  override void OnExecuteClient(ActionData action_data)
70  {
71  if (!action_data.m_Player.IsPlacingLocal())
72  action_data.m_Player.TogglePlacingLocal();
73  else
74  Process(action_data);
75  }
76 
77  ItemBase GetAttachedDevice(ItemBase parent)
78  {
79  if (parent.IsInherited(CarBattery) || parent.IsInherited(TruckBattery))
80  {
81  ItemBase parentAttachment = ItemBase.Cast(parent.GetAttachmentByType(MetalWire));
82  if (!parentAttachment)
83  parentAttachment = ItemBase.Cast(parent.GetAttachmentByType(BarbedWire));
84 
85  return parentAttachment;
86  }
87 
88  return null;
89  }
90 };
ItemBase
Definition: inventoryitem.c:730
ActionPlugIn
Definition: actionplugin.c:1
UAMaxDistances
Definition: actionconstants.c:104
PlayerBase
Definition: playerbaseclient.c:1
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
InventoryMode
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition: inventory.c:21
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
CCTNonRuined
Definition: cctnonruined.c:1
CarBattery
Definition: carbattery.c:1
TruckBattery
Definition: truckbattery.c:1
m_Text
protected string m_Text
Definition: actionbase.c:49
ActionSingleUseBase
Definition: actionsingleusebase.c:41
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
CCINonRuined
Definition: ccinonruined.c:1
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56