Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actiontakeitem.c
Go to the documentation of this file.
1 /*class ActionTakeItemReciveData : ActionReciveData
2 {
3  ref InventoryLocation m_InventoryLocation;
4 }*/
5 
7 {
8  string m_ItemName = "";
9 
10  void ActionTakeItem()
11  {
12  m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_PICKUP_INVENTORY;
13  m_CommandUIDProne = DayZPlayerConstants.CMD_ACTIONFB_PICKUP_INVENTORY;
14  m_Text = "#take";
15  }
16 
17  override void CreateConditionComponents()
18  {
21  }
22 
23  override bool HasProneException()
24  {
25  return true;
26  }
27 
28  override bool ActionConditionContinue( ActionData action_data )
29  {
30  return true;
31  }
32 
33  override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
34  {
35  ItemBase tgt_item = ItemBase.Cast( target.GetObject() );
36  if ( tgt_item && !tgt_item.IsTakeable() ) return false;
37  if ( tgt_item && tgt_item.IsBeingPlaced() ) return false;
38 
39  EntityAI tgt_parent = EntityAI.Cast( target.GetParent() );
40  EntityAI tgt_entity = EntityAI.Cast( target.GetObject() );
41 
42  if ( tgt_entity && (!tgt_parent || BaseBuildingBase.Cast(tgt_parent)) )
43  {
44  if ( tgt_entity && tgt_entity.IsItemBase() && player.GetInventory().CanAddEntityIntoInventory(tgt_entity) && tgt_entity.GetHierarchyRootPlayer() != player )
45  {
46  if ( tgt_parent && (!tgt_item.CanDetachAttachment(tgt_parent) || !tgt_parent.CanReleaseAttachment(tgt_item)) )
47  return false;
48 
49  return true;
50  }
51  }
52  return false;
53  }
54 
55  override bool CanBeUsedOnBack()
56  {
57  return true;
58  }
59 
60  /*override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
61  {
62  super.WriteToContext(ctx, action_data);
63  InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
64  il.WriteToContext(ctx);
65  }
66 
67  override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
68  {
69  if(!action_recive_data)
70  {
71  action_recive_data = new ActionTakeItemReciveData;
72  }
73 
74  if(super.ReadFromContext(ctx, action_recive_data))
75  {
76  ActionTakeItemReciveData recive_data_ti = ActionTakeItemReciveData.Cast(action_recive_data);
77  recive_data_ti.m_InventoryLocation = new InventoryLocation;
78  if(recive_data_ti.m_InventoryLocation.ReadFromContext(ctx))
79  {
80  return true;
81  }
82  }
83 
84  return false;
85  }
86 
87  override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
88  {
89  super.HandleReciveData(action_recive_data, action_data);
90  ActionTakeItemReciveData recive_data_ti = ActionTakeItemReciveData.Cast(action_recive_data);
91  action_data.m_ReservedInventoryLocations.Insert(recive_data_ti.m_InventoryLocation);
92  } */
93 
94 
95 
96  override bool InventoryReservation(ActionData action_data)
97  {
98  bool success = true;
99 
101 
102  ItemBase targetItem;
103  if ( ItemBase.CastTo(targetItem, action_data.m_Target.GetObject()) )
104  {
105  action_data.m_Player.GetInventory().FindFreeLocationFor( targetItem , FindInventoryLocationType.ANY, il );
106  if ( action_data.m_Player.GetInventory().HasInventoryReservation( targetItem, il) )
107  {
108  success = false;
109  }
110  else
111  {
112  action_data.m_Player.GetInventory().AddInventoryReservationEx( targetItem, il, GameInventory.c_InventoryReservationTimeoutMS);
113  }
114  }
115 
116  if ( success )
117  {
118  if( il )
119  action_data.m_ReservedInventoryLocations.Insert(il);
120  }
121 
122  return success;
123  }
124 
125  override void OnExecuteServer( ActionData action_data )
126  {
127  if (GetGame().IsMultiplayer())
128  return;
129 
130  //Debug.Log("[Action DEBUG] Start time stamp: " + action_data.m_Player.GetSimulationTimeStamp());
131  ItemBase ntarget = ItemBase.Cast(action_data.m_Target.GetObject());
132  InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
133  InventoryLocation targetInventoryLocation = new InventoryLocation;
134  ntarget.GetInventory().GetCurrentInventoryLocation(targetInventoryLocation);
135 
136  //SplitItemUtils.TakeOrSplitToInventoryLocation( action_data.m_Player, il );
137 
138  float stackable = ntarget.GetTargetQuantityMax(il.GetSlot());
139 
140  if( stackable == 0 || stackable >= ntarget.GetQuantity() )
141  {
142  action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
143  }
144  else
145  {
146  ClearInventoryReservationEx(action_data);
147  ntarget.SplitIntoStackMaxToInventoryLocationClient( il );
148  }
149 
150  //action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
151  }
152 
153  override void OnExecuteClient( ActionData action_data )
154  {
155  //Debug.Log("[Action DEBUG] Start time stamp: " + action_data.m_Player.GetSimulationTimeStamp());
156  ItemBase ntarget = ItemBase.Cast(action_data.m_Target.GetObject());
157  InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
158  InventoryLocation targetInventoryLocation = new InventoryLocation;
159  ntarget.GetInventory().GetCurrentInventoryLocation(targetInventoryLocation);
160 
161  //SplitItemUtils.TakeOrSplitToInventoryLocation( action_data.m_Player, il );
162  //action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
163  float stackable = ntarget.GetTargetQuantityMax(il.GetSlot());
164 
165  if( stackable == 0 || stackable >= ntarget.GetQuantity() )
166  {
167  action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
168  }
169  else
170  {
171  ntarget.SplitIntoStackMaxToInventoryLocationClient( il );
172  }
173  }
174 };
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
ClearInventoryReservationEx
void ClearInventoryReservationEx(ActionData action_data)
Definition: actionbase.c:862
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
BaseBuildingBase
Definition: fence.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
EntityAI
Definition: building.c:5
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78