Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actiontakeitemtohands.c
Go to the documentation of this file.
2 {
4  {
5  m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_PICKUP_HANDS;
6  m_CommandUIDProne = DayZPlayerConstants.CMD_ACTIONFB_PICKUP_HANDS;
7  m_Text = "#take_to_hands";
8  }
9 
10  override void CreateConditionComponents()
11  {
12  m_ConditionItem = new CCINone();
14  }
15 
16  override bool HasProneException()
17  {
18  return true;
19  }
20 
21  override typename GetInputType()
22  {
24  }
25 
26  override bool HasProgress()
27  {
28  return false;
29  }
30 
31  override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
32  {
33  ItemBase targetItem = ItemBase.Cast(target.GetObject());
34  if (!targetItem)
35  return false;
36 
37  EntityAI targetParent = EntityAI.Cast(targetItem.GetHierarchyParent());
38  if (!targetItem.IsTakeable() || targetItem.IsBeingPlaced() || targetItem.IsSetForDeletion() || ( targetItem.GetHierarchyParent() && !BaseBuildingBase.Cast(targetParent) ) || ((targetParent && !targetItem.CanDetachAttachment(targetParent)) || (targetParent && !targetParent.CanReleaseAttachment(targetItem))))
39  return false;
40 
41  return player.GetInventory().CanAddEntityIntoHands(targetItem);
42  }
43 
44  override bool CanContinue(ActionData action_data)
45  {
46  return true;
47  }
48 
49  override void OnEndServer(ActionData action_data)
50  {
51  super.OnEndServer(action_data);
52 
53  EntityAI takenEntity = EntityAI.Cast(action_data.m_Target.GetObject());
54  if (takenEntity && takenEntity.GetCompEM() && takenEntity.IsElectricAppliance())
55  takenEntity.GetCompEM().UnplugThis();
56  }
57 
58  override void OnExecute(ActionData action_data)
59  {
60  if (GetGame().IsDedicatedServer())
61  return;
62 
63  ItemBase ntarget = ItemBase.Cast(action_data.m_Target.GetObject());
64  ClearInventoryReservationEx(action_data);
65 
66  float stackable = ntarget.GetTargetQuantityMax(-1);
67 
68  if (stackable == 0 || stackable >= ntarget.GetQuantity())
69  {
70  action_data.m_Player.PredictiveTakeEntityToHands(ntarget);
71  }
72  else
73  {
75  il.SetHands(action_data.m_Player, ntarget);
76  ntarget.SplitIntoStackMaxToInventoryLocationClient(il);
77  }
78  }
79 
80  override void CreateAndSetupActionCallback(ActionData action_data)
81  {
82  EntityAI target = EntityAI.Cast(action_data.m_Target.GetObject());
83  if (!target)
84  return;
85 
86  ActionBaseCB callback;
87 
88  if (target.IsHeavyBehaviour())
89  {
90  Class.CastTo(callback, action_data.m_Player.StartCommand_Action(DayZPlayerConstants.CMD_ACTIONFB_PICKUP_HEAVY,GetCallbackClassTypename(), DayZPlayerConstants.STANCEMASK_ERECT));
91  }
92  else
93  {
94  if (action_data.m_Player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT))
95  {
96  Class.CastTo(callback, action_data.m_Player.AddCommandModifier_Action(m_CommandUID,GetCallbackClassTypename()));
97  }
98  else
99  {
100  Class.CastTo(callback, action_data.m_Player.StartCommand_Action(m_CommandUIDProne,GetCallbackClassTypename(),DayZPlayerConstants.STANCEMASK_PRONE));
101  }
102  }
103 
104  callback.SetActionData(action_data);
105  callback.InitActionComponent();
106  action_data.m_Callback = callback;
107  }
108 
109 
110  override bool CanBeUsedOnBack()
111  {
112  return true;
113  }
114 }
115 
116 class ActionSwapItemToHands: ActionTakeItemToHands
117 {
118  bool m_Executable;
119 
120  override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
121  {
122  ItemBase targetItem = ItemBase.Cast(target.GetObject());
123  if (!targetItem || !targetItem.IsTakeable() || targetItem.IsBeingPlaced())
124  return false;
125 
126  return player.GetInventory().CanSwapEntitiesEx(targetItem,item);
127  }
128 
129  override bool UseMainItem()
130  {
131  return true;
132  }
133 
134  override bool MainItemAlwaysInHands()
135  {
136  return true;
137  }
138 
139  override void CreateAndSetupActionCallback(ActionData action_data)
140  {
141  EntityAI target = EntityAI.Cast(action_data.m_Target.GetObject());
142  if (!target)
143  return;
144 
145  ActionBaseCB callback;
146 
147  if (target.IsHeavyBehaviour())
148  {
149  Class.CastTo(callback, action_data.m_Player.StartCommand_Action(DayZPlayerConstants.CMD_ACTIONFB_PICKUP_HEAVY,GetCallbackClassTypename(),DayZPlayerConstants.STANCEMASK_ERECT));
150  }
151  else
152  {
153  return;
154  }
155 
156  callback.SetActionData(action_data);
157  callback.InitActionComponent();
158  action_data.m_Callback = callback;
159  }
160 
161  override void Start(ActionData action_data)
162  {
163  super.Start(action_data);
164 
165  bool b1 = action_data.m_MainItem.ConfigGetString("physLayer") == "item_large";
166  action_data.m_MainItem.m_ThrowItemOnDrop = b1;
167 
168  EntityAI object = EntityAI.Cast(action_data.m_Target.GetObject());
169  if (!object || !object.IsHeavyBehaviour())
170  {
171  action_data.m_Player.GetActionManager().Interrupt();
172  }
173  else
174  m_Executable = true;
175  }
176 
177  override void OnExecuteServer(ActionData action_data)
178  {
179  if (!m_Executable)
180  return;
181 
182  if (GetGame().IsMultiplayer())
183  return;
184 
185  PerformSwap(action_data);
186  }
187 
188  override void OnExecuteClient( ActionData action_data )
189  {
190  if (!m_Executable)
191  return;
192 
193  PerformSwap(action_data);
194  }
195 
196  override void OnEndServer( ActionData action_data )
197  {
198  if (m_Executable)
199  {
200  m_Executable = false;
201  return;
202  }
203 
204  if (GetGame().IsMultiplayer())
205  return;
206 
207  PerformSwap(action_data);
208  }
209 
210  override void OnEndClient( ActionData action_data )
211  {
212  if (m_Executable)
213  {
214  m_Executable = false;
215  return;
216  }
217 
218  PerformSwap(action_data);
219  }
220 
221  void PerformSwap( ActionData action_data )
222  {
223  EntityAI ntarget = EntityAI.Cast(action_data.m_Target.GetObject());
224  if (action_data.m_Player)
225  {
226  InventoryMode invMode = InventoryMode.PREDICTIVE;
227  if (action_data.m_Player.NeedInventoryJunctureFromServer(ntarget, ntarget.GetHierarchyParent(), action_data.m_Player))
228  invMode = InventoryMode.JUNCTURE;
229 
230  action_data.m_Player.TakeEntityToHandsImpl(invMode, ntarget);
231  }
232  }
233 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
ActionTakeItemToHands
Definition: actiontakeitemtohands.c:1
m_Executable
ActionTakeItemToHands m_Executable
ContinuousInteractActionInput
Definition: actioninput.c:521
CCINone
Definition: ccinone.c:1
OnExecuteClient
override void OnExecuteClient(ActionData action_data)
Definition: actiontakeitemtohands.c:188
CCTObject
Definition: cctobject.c:1
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
PerformSwap
void PerformSwap(ActionData action_data)
Definition: actiontakeitemtohands.c:221
UAMaxDistances
Definition: actionconstants.c:104
OnExecuteServer
override void OnExecuteServer(ActionData action_data)
Definition: actiontakeitemtohands.c:177
ClearInventoryReservationEx
void ClearInventoryReservationEx(ActionData action_data)
Definition: actionbase.c:862
MainItemAlwaysInHands
override bool MainItemAlwaysInHands()
Definition: actiontakeitemtohands.c:134
OnEndServer
override void OnEndServer(ActionData action_data)
Definition: actiontakeitemtohands.c:196
ActionCondition
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
Definition: actiontakeitemtohands.c:120
ActionInteractBase
Definition: actioninteractbase.c:54
OnEndClient
override void OnEndClient(ActionData action_data)
Definition: actiontakeitemtohands.c:210
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
IsHeavyBehaviour
override bool IsHeavyBehaviour()
Definition: itembase.c:4182
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
BaseBuildingBase
Definition: fence.c:1
Start
override void Start(ActionData action_data)
Definition: actiontakeitemtohands.c:161
m_Text
protected string m_Text
Definition: actionbase.c:49
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
CreateAndSetupActionCallback
override void CreateAndSetupActionCallback(ActionData action_data)
Definition: actiontakeitemtohands.c:139
UseMainItem
override bool UseMainItem()
Definition: actiontakeitemtohands.c:129
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
ActionBaseCB
Definition: animatedactionbase.c:1
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
EntityAI
Definition: building.c:5