Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actiontakearrow.c
Go to the documentation of this file.
1 /*class TakeArrowActionReciveData : ActionReciveData
2 {
3  EntityAI m_Arrow;
4 }
5 
6 class TakeArrowActionData : ActionData
7 {
8  EntityAI m_Arrow;
9 }*/
10 
12 {
13  void ActionTakeArrow()
14  {
15  m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_PICKUP_HANDS;
16  m_Text = "#take";
17  }
18 
19  override void CreateConditionComponents()
20  {
21  m_ConditionItem = new CCINone();
23  }
24 
25  override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
26  {
27  EntityAI targetEntity = EntityAI.Cast(target.GetObject());
28  if (!targetEntity || (targetEntity && targetEntity.IsManagingArrows() && !targetEntity.IsDamageDestroyed()))
29  return false;
30 
31  ArrowManagerBase arrowManager = targetEntity.GetArrowManager();
32  if (arrowManager)
33  {
34  ItemBase arrow = ItemBase.Cast(arrowManager.GetFirstArrow());
35  if (arrow)
36  {
37  if (player.GetInventory().CanAddEntityIntoInventory(arrow))
38  return true;
39  }
40  }
41 
42  return false;
43  }
44 
45  override Object GetDisplayInteractObject(PlayerBase player, ActionTarget target)
46  {
47  EntityAI targetEntity = EntityAI.Cast(target.GetObject());
48  if (!targetEntity || (targetEntity && targetEntity.IsManagingArrows() && !targetEntity.IsDamageDestroyed()))
49  return null;
50 
51  ArrowManagerBase arrowManager = targetEntity.GetArrowManager();
52  if (arrowManager)
53  {
54  return arrowManager.GetFirstArrow();
55  }
56 
57  return null;
58  }
59 
60  override bool CanBeUsedOnBack()
61  {
62  return false;
63  }
64 
65  override bool InventoryReservation(ActionData action_data)
66  {
67  bool success = true;
68 
70 
71  EntityAI targetEntity;
72  if (EntityAI.CastTo(targetEntity, action_data.m_Target.GetObject()))
73  {
74  ArrowManagerBase arrowManager = targetEntity.GetArrowManager();
75  if (arrowManager)
76  {
77  ItemBase targetArrow = ItemBase.Cast(arrowManager.GetFirstArrow());
78  if (targetArrow)
79  {
80  action_data.m_Player.GetInventory().FindFreeLocationFor(targetArrow , FindInventoryLocationType.ANY, il);
81  if (action_data.m_Player.GetInventory().HasInventoryReservation(targetArrow, il))
82  {
83  success = false;
84  }
85  else
86  {
87  action_data.m_Player.GetInventory().AddInventoryReservationEx(targetArrow, il, GameInventory.c_InventoryReservationTimeoutMS);
88  }
89  }
90  }
91  }
92 
93  if (success)
94  {
95  if (il)
96  action_data.m_ReservedInventoryLocations.Insert(il);
97  }
98 
99  return success;
100  }
101 
102  /*override ActionData CreateActionData()
103  {
104  ActionData action_data = new TakeArrowActionData;
105  return action_data;
106  }
107 
108  override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
109  {
110  super.WriteToContext(ctx, action_data);
111  TakeArrowActionData ad = TakeArrowActionData.Cast(action_data);
112  ctx.Write(ad.m_Arrow);
113  }
114 
115  override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
116  {
117  if (!action_recive_data)
118  {
119  action_recive_data = new TakeArrowActionReciveData;
120  }
121 
122  if (!super.ReadFromContext( ctx, action_recive_data ))
123  return false;
124 
125  TakeArrowActionReciveData recive_data_ta = TakeArrowActionReciveData.Cast( action_recive_data );
126 
127  if (!ctx.Read(recive_data_ta.m_Arrow))
128  return false;
129 
130  return true;
131  }
132 
133  override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
134  {
135  super.HandleReciveData(action_recive_data, action_data);
136 
137  TakeArrowActionReciveData recive_data_ta = TakeArrowActionReciveData.Cast(action_recive_data);
138  TakeArrowActionData action_data_ta = TakeArrowActionData.Cast(action_data);
139 
140  action_data_ta.m_Arrow = recive_data_ta.m_Arrow;
141  }*/
142 
143  override void OnExecuteClient(ActionData action_data)
144  {
145 
146  InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
147 
148  ItemBase arrow = ItemBase.Cast(il.GetItem());
149  InventoryLocation arrowInventoryLocation = new InventoryLocation;
150  arrow.GetInventory().GetCurrentInventoryLocation(arrowInventoryLocation);
151 
152  float stackable = arrow.GetTargetQuantityMax(il.GetSlot());
153 
154  if ( stackable == 0 || stackable >= arrow.GetQuantity() )
155  {
156  action_data.m_Player.PredictiveTakeToDst(arrowInventoryLocation, il);
157  }
158  else
159  {
160  arrow.SplitIntoStackMaxToInventoryLocationClient( il );
161  }
162  }
163 
164  /*override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = null)
165  {
166  if (super.SetupAction(player, target, item, action_data, extra_data))
167  {
168  #ifndef SERVER
169  TakeArrowActionData action_data_ta = TakeArrowActionData.Cast(action_data);
170  InventoryLocation il = action_data_ta.m_ReservedInventoryLocations.Get(0);
171  action_data_ta.m_Arrow = il.GetItem();
172  #endif
173 
174  return true;
175  }
176 
177  return false;
178  }*/
179 
180  /*override void OnStartServer(ActionData action_data)
181  {
182  TakeArrowActionData action_data_ta = TakeArrowActionData.Cast(action_data);
183  action_data.m_Target.GetObject().RemoveChild(action_data_ta.m_Arrow);
184  }*/
185 
186  override void OnExecuteServer(ActionData action_data)
187  {
188  //TakeArrowActionData action_data_ta = TakeArrowActionData.Cast(action_data);
189  //action_data.m_Target.GetObject().RemoveChild(action_data_ta.m_Arrow);
190 
191  if (GetGame().IsMultiplayer())
192  return;
193 
194  InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
195  ItemBase arrow = ItemBase.Cast(il.GetItem());
196  InventoryLocation arrowInventoryLocation = new InventoryLocation;
197  arrow.GetInventory().GetCurrentInventoryLocation(arrowInventoryLocation);
198 
199  EntityAI targetEntity = EntityAI.Cast(action_data.m_Target.GetObject());
200  if (targetEntity)
201  {
202  targetEntity.RemoveChild(arrow);
203  }
204 
205  //float ammoMax = arrow.GetAmmoMax();
206 
207  //if ( stackable == 0 || ammoMax >= arrow.GetAmmoCount() )
208  //{
209  action_data.m_Player.PredictiveTakeToDst(arrowInventoryLocation, il);
210  /*}
211  else
212  {
213  arrow.SplitIntoStackMaxToInventoryLocationClient( il );
214  }*/
215  }
216 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
ActionTakeItem
Definition: actiontakeitem.c:6
CCINone
Definition: ccinone.c:1
CCTObject
Definition: cctobject.c:1
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
UAMaxDistances
Definition: actionconstants.c:104
ActionTakeArrow
Definition: actiontakearrow.c:11
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
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
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
ArrowManagerBase
Definition: arrowmanagerbase.c:1
EntityAI
Definition: building.c:5
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78