DayZ 1.24
Loading...
Searching...
No Matches
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
11 {
12 m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_PICKUP_INVENTORY;
13 m_CommandUIDProne = DayZPlayerConstants.CMD_ACTIONFB_PICKUP_INVENTORY;
14 m_Text = "#take";
15 }
16
22
23 override bool HasProneException()
24 {
25 return true;
26 }
27
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
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
96 {
97 bool success = true;
98
100
102 if (ItemBase.CastTo(targetItem, action_data.m_Target.GetObject()))
103 {
104 action_data.m_Player.GetInventory().FindFreeLocationFor(targetItem, FindInventoryLocationType.ANY, il);
105 if (action_data.m_Player.GetInventory().HasInventoryReservation(targetItem, il))
106 success = false;
107 else
108 action_data.m_Player.GetInventory().AddInventoryReservationEx(targetItem, il, GameInventory.c_InventoryReservationTimeoutMS);
109 }
110
111 if (success)
112 {
113 if (il)
114 action_data.m_ReservedInventoryLocations.Insert(il);
115 }
116
117 return success;
118 }
119
121 {
122 if (GetGame().IsMultiplayer())
123 return;
124
125 //Debug.Log("[Action DEBUG] Start time stamp: " + action_data.m_Player.GetSimulationTimeStamp());
126 ItemBase ntarget = ItemBase.Cast(action_data.m_Target.GetObject());
127 InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
129 ntarget.GetInventory().GetCurrentInventoryLocation(targetInventoryLocation);
130
131 //SplitItemUtils.TakeOrSplitToInventoryLocation( action_data.m_Player, il );
132
133 float stackable = ntarget.GetTargetQuantityMax(il.GetSlot());
134
135 if (stackable == 0 || stackable >= ntarget.GetQuantity())
136 action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
137 else
138 {
140 ntarget.SplitIntoStackMaxToInventoryLocationClient(il);
141 }
142
143 //action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
144 }
145
147 {
148 //Debug.Log("[Action DEBUG] Start time stamp: " + action_data.m_Player.GetSimulationTimeStamp());
149 ItemBase ntarget = ItemBase.Cast(action_data.m_Target.GetObject());
150 InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
152 ntarget.GetInventory().GetCurrentInventoryLocation(targetInventoryLocation);
153
154 //SplitItemUtils.TakeOrSplitToInventoryLocation( action_data.m_Player, il );
155 //action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
156 float stackable = ntarget.GetTargetQuantityMax(il.GetSlot());
157
158 if (stackable == 0 || stackable >= ntarget.GetQuantity())
159 action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
160 else
161 ntarget.SplitIntoStackMaxToInventoryLocationClient(il);
162 }
163};
string m_Text
Definition ActionBase.c:49
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
void ClearInventoryReservationEx(ActionData action_data)
Definition ActionBase.c:790
FindInventoryLocationType
flags for searching locations in inventory
override bool HasProneException()
override void OnExecuteClient(ActionData action_data)
override void OnExecuteServer(ActionData action_data)
override void CreateConditionComponents()
override bool CanBeUsedOnBack()
override bool ActionConditionContinue(ActionData action_data)
override bool InventoryReservation(ActionData action_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
script counterpart to engine's class Inventory
Definition Inventory.c:79
const int c_InventoryReservationTimeoutMS
reservations
Definition Inventory.c:687
InventoryLocation.
const float DEFAULT
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:597
proto native CGame GetGame()