DayZ 1.24
Loading...
Searching...
No Matches
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{
14 {
15 m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_PICKUP_HANDS;
16 m_Text = "#take";
17 }
18
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
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 return arrowManager.GetFirstArrow();
54
55 return null;
56 }
57
58 override bool CanBeUsedOnBack()
59 {
60 return false;
61 }
62
64 {
65 bool success = true;
66
68
70 if (EntityAI.CastTo(targetEntity, action_data.m_Target.GetObject()))
71 {
72 ArrowManagerBase arrowManager = targetEntity.GetArrowManager();
73 if (arrowManager)
74 {
75 ItemBase targetArrow = ItemBase.Cast(arrowManager.GetFirstArrow());
76 if (targetArrow)
77 {
78 action_data.m_Player.GetInventory().FindFreeLocationFor(targetArrow, FindInventoryLocationType.ANY, il);
79 if (action_data.m_Player.GetInventory().HasInventoryReservation(targetArrow, il))
80 success = false;
81 else
82 action_data.m_Player.GetInventory().AddInventoryReservationEx(targetArrow, il, GameInventory.c_InventoryReservationTimeoutMS);
83 }
84 }
85 }
86
87 if (success)
88 {
89 if (il)
90 action_data.m_ReservedInventoryLocations.Insert(il);
91 }
92
93 return success;
94 }
95
96 /*override ActionData CreateActionData()
97 {
98 ActionData action_data = new TakeArrowActionData;
99 return action_data;
100 }
101
102 override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
103 {
104 super.WriteToContext(ctx, action_data);
105 TakeArrowActionData ad = TakeArrowActionData.Cast(action_data);
106 ctx.Write(ad.m_Arrow);
107 }
108
109 override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
110 {
111 if (!action_recive_data)
112 {
113 action_recive_data = new TakeArrowActionReciveData;
114 }
115
116 if (!super.ReadFromContext( ctx, action_recive_data ))
117 return false;
118
119 TakeArrowActionReciveData recive_data_ta = TakeArrowActionReciveData.Cast( action_recive_data );
120
121 if (!ctx.Read(recive_data_ta.m_Arrow))
122 return false;
123
124 return true;
125 }
126
127 override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
128 {
129 super.HandleReciveData(action_recive_data, action_data);
130
131 TakeArrowActionReciveData recive_data_ta = TakeArrowActionReciveData.Cast(action_recive_data);
132 TakeArrowActionData action_data_ta = TakeArrowActionData.Cast(action_data);
133
134 action_data_ta.m_Arrow = recive_data_ta.m_Arrow;
135 }*/
136
138 {
139
140 InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
141
142 ItemBase arrow = ItemBase.Cast(il.GetItem());
144 arrow.GetInventory().GetCurrentInventoryLocation(arrowInventoryLocation);
145
146 float stackable = arrow.GetTargetQuantityMax(il.GetSlot());
147
148 if (stackable == 0 || stackable >= arrow.GetQuantity())
149 action_data.m_Player.PredictiveTakeToDst(arrowInventoryLocation, il);
150 else
151 arrow.SplitIntoStackMaxToInventoryLocationClient(il);
152 }
153
154 /*override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = null)
155 {
156 if (super.SetupAction(player, target, item, action_data, extra_data))
157 {
158 #ifndef SERVER
159 TakeArrowActionData action_data_ta = TakeArrowActionData.Cast(action_data);
160 InventoryLocation il = action_data_ta.m_ReservedInventoryLocations.Get(0);
161 action_data_ta.m_Arrow = il.GetItem();
162 #endif
163
164 return true;
165 }
166
167 return false;
168 }*/
169
170 /*override void OnStartServer(ActionData action_data)
171 {
172 TakeArrowActionData action_data_ta = TakeArrowActionData.Cast(action_data);
173 action_data.m_Target.GetObject().RemoveChild(action_data_ta.m_Arrow);
174 }*/
175
177 {
178 //TakeArrowActionData action_data_ta = TakeArrowActionData.Cast(action_data);
179 //action_data.m_Target.GetObject().RemoveChild(action_data_ta.m_Arrow);
180
181 if (GetGame().IsMultiplayer())
182 return;
183
184 InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
185 ItemBase arrow = ItemBase.Cast(il.GetItem());
187 arrow.GetInventory().GetCurrentInventoryLocation(arrowInventoryLocation);
188
189 EntityAI targetEntity = EntityAI.Cast(action_data.m_Target.GetObject());
190 if (targetEntity)
191 targetEntity.RemoveChild(arrow);
192
193 //float ammoMax = arrow.GetAmmoMax();
194
195 //if ( stackable == 0 || ammoMax >= arrow.GetAmmoCount() )
196 //{
197 action_data.m_Player.PredictiveTakeToDst(arrowInventoryLocation, il);
198 /*}
199 else
200 {
201 arrow.SplitIntoStackMaxToInventoryLocationClient( il );
202 }*/
203 }
204}
string m_Text
Definition ActionBase.c:49
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
FindInventoryLocationType
flags for searching locations in inventory
override bool CanBeUsedOnBack()
override void OnExecuteServer(ActionData action_data)
override bool InventoryReservation(ActionData action_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
override Object GetDisplayInteractObject(PlayerBase player, ActionTarget target)
override void CreateConditionComponents()
override void OnExecuteClient(ActionData action_data)
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()