Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actiontakearrowtohands.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  EntityAI targetEntity = EntityAI.Cast(target.GetObject());
34  if (!targetEntity || (targetEntity && targetEntity.IsManagingArrows() && !targetEntity.IsDamageDestroyed()))
35  return false;
36 
37  ArrowManagerBase arrowManager = targetEntity.GetArrowManager();
38  if (arrowManager)
39  {
40  ItemBase arrow = ItemBase.Cast(arrowManager.GetFirstArrow());
41  if (arrow && !arrow.IsSetForDeletion())
42  {
43  if (player.GetInventory().CanAddEntityIntoHands(arrow))
44  return true;
45  }
46  }
47 
48  return false;
49  }
50 
51  override Object GetDisplayInteractObject(PlayerBase player, ActionTarget target)
52  {
53  EntityAI targetEntity = EntityAI.Cast(target.GetObject());
54  if (!targetEntity || (targetEntity && targetEntity.IsManagingArrows() && !targetEntity.IsDamageDestroyed()))
55  return null;
56 
57  ArrowManagerBase arrowManager = targetEntity.GetArrowManager();
58  if (arrowManager)
59  {
60  return arrowManager.GetFirstArrow();
61  }
62 
63  return null;
64  }
65 
66  override bool CanContinue(ActionData action_data)
67  {
68  return true;
69  }
70 
71  override bool InventoryReservation(ActionData action_data)
72  {
73  bool success = true;
74 
76 
77  EntityAI targetEntity;
78  if (EntityAI.CastTo(targetEntity, action_data.m_Target.GetObject()))
79  {
80  ArrowManagerBase arrowManager = targetEntity.GetArrowManager();
81  if (arrowManager)
82  {
83  ItemBase targetArrow = ItemBase.Cast(arrowManager.GetFirstArrow());
84  if (targetArrow)
85  {
86  il.SetHands(action_data.m_Player,targetArrow);
87  if (action_data.m_Player.GetInventory().HasInventoryReservation(targetArrow, il))
88  {
89  success = false;
90  }
91  else
92  {
93  action_data.m_Player.GetInventory().AddInventoryReservationEx(targetArrow, il, GameInventory.c_InventoryReservationTimeoutMS);
94  }
95  }
96  }
97  }
98 
99  if (success)
100  {
101  if (il)
102  action_data.m_ReservedInventoryLocations.Insert(il);
103  }
104 
105  return success;
106  }
107 
108 
109  override void OnExecute(ActionData action_data)
110  {
111  if (GetGame().IsMultiplayer() && GetGame().IsServer())
112  return;
113 
114  InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
115 
116  ItemBase arrow = ItemBase.Cast(il.GetItem());
117  ClearInventoryReservationEx(action_data);
118 
119  float stackable = arrow.GetTargetQuantityMax(-1);
120 
121  if (stackable == 0 || stackable >= arrow.GetQuantity())
122  {
123  action_data.m_Player.PredictiveTakeEntityToHands(arrow);
124  }
125  else
126  {
127  arrow.SplitIntoStackMaxToInventoryLocationClient(il);
128  }
129  }
130 
131  override void CreateAndSetupActionCallback(ActionData action_data)
132  {
133  EntityAI target = EntityAI.Cast(action_data.m_Target.GetObject());
134  if (!target)
135  return;
136 
137  ActionBaseCB callback;
138 
139  if (target.IsHeavyBehaviour())
140  {
141  Class.CastTo(callback, action_data.m_Player.StartCommand_Action(DayZPlayerConstants.CMD_ACTIONFB_PICKUP_HEAVY,GetCallbackClassTypename(), DayZPlayerConstants.STANCEMASK_ERECT));
142  }
143  else
144  {
145  if (action_data.m_Player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT))
146  {
147  Class.CastTo(callback, action_data.m_Player.AddCommandModifier_Action(m_CommandUID,GetCallbackClassTypename()));
148  }
149  else
150  {
151  Class.CastTo(callback, action_data.m_Player.StartCommand_Action(m_CommandUIDProne,GetCallbackClassTypename(),DayZPlayerConstants.STANCEMASK_PRONE));
152  }
153  }
154 
155  callback.SetActionData(action_data);
156  callback.InitActionComponent();
157  action_data.m_Callback = callback;
158  }
159 
160 
161  override bool CanBeUsedOnBack()
162  {
163  return true;
164  }
165 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
ContinuousInteractActionInput
Definition: actioninput.c:521
CCINone
Definition: ccinone.c:1
CCTObject
Definition: cctobject.c:1
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
UAMaxDistances
Definition: actionconstants.c:104
ClearInventoryReservationEx
void ClearInventoryReservationEx(ActionData action_data)
Definition: actionbase.c:862
ActionTakeArrowToHands
Definition: actiontakearrowtohands.c:1
ActionInteractBase
Definition: actioninteractbase.c:54
PlayerBase
Definition: playerbaseclient.c:1
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
Object
Definition: objecttyped.c:1
m_Text
protected string m_Text
Definition: actionbase.c:49
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
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
ArrowManagerBase
Definition: arrowmanagerbase.c:1
EntityAI
Definition: building.c:5
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78