DayZ 1.24
Loading...
Searching...
No Matches
FirearmActionDetachMagazine.c
Go to the documentation of this file.
6{
8}
9
11{
15
16 override bool HasTarget()
17 {
18 return true;
19 }
20
21 override typename GetInputType()
22 {
24 }
25
27 {
28 return true;
29 }
30
32 {
35 }
36
37 override bool HasProgress()
38 {
39 return false;
40 }
41
43 {
44 Magazine mag = Magazine.Cast(action_data.m_Target.GetObject());
46 if (!action_data.m_Player.GetInventory().FindFreeLocationFor(mag, FindInventoryLocationType.ANY_CARGO, il))
47 return false;
48
49 if (!super.InventoryReservation(action_data))
50 return false;
51
53 if (!action_data.m_Player.GetInventory().AddInventoryReservationEx(mag, il, 10000))
54 return false;
55
56 action_data_dm.m_ReservedInventoryLocations.Insert(il);
57 action_data_dm.m_ilMagazine = il;
58
59 return true;
60 }
61
67
69 {
70 super.WriteToContext(ctx, action_data);
71
74
75 action_data_dm.m_ilMagazine.WriteToContext(ctx);
76 }
77
79 {
82
83 if (!super.ReadFromContext(ctx, action_recive_data))
84 return false;
85
88
89 recive_data_dm.m_ilMagazine = new InventoryLocation;
90
91 if (!recive_data_dm.m_ilMagazine.ReadFromContext(ctx))
92 return false;
93
94 return true;
95 }
96
106
107
108 override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item) //condition for action
109 {
110 if (!super.ActionCondition(player, target, item))
111 return false;
112
113 Magazine mag = Magazine.Cast(target.GetObject());
115 return mag && player.GetWeaponManager().CanDetachMagazine(wpn, mag);
116 }
117
119 {
120 return true;
121 }
122
124 {
125 super.Start(action_data);
127
128 Weapon_Base wpn = Weapon_Base.Cast(action_data.m_MainItem);
129
130 action_data.m_Player.GetWeaponManager().DetachMagazine(action_data_dm.m_ilMagazine, this);
131 }
132};
133
140{
143}
144
145class FirearmActionDetachMagazine : ActionSequentialBase
146{
148 {
149 }
150
156
157
159 {
160 Weapon_Base wpn = Weapon_Base.Cast(action_data.m_MainItem);
161 Magazine mag = Magazine.Cast(action_data.m_Target.GetObject());
162
165
166
167 int ur_index = action_data.m_Player.GetHumanInventory().FindUserReservedLocationIndex(wpn);
168
169 if (ur_index > -1)
170 action_data.m_Player.GetHumanInventory().GetUserReservedLocation(ur_index, ilWpn);
171 else
172 {
173 action_data.m_Player.GetInventory().FindFreeLocationFor(wpn, FindInventoryLocationType.ANY_CARGO | FindInventoryLocationType.ATTACHMENT, ilWpn);
174
175
176 //return false;
177 }
178
179 if (!action_data.m_Player.GetInventory().FindFreeLocationFor(mag, FindInventoryLocationType.ANY_CARGO, ilMag))
180 return false;
181
182 if (!super.InventoryReservation(action_data))
183 return false;
184
186 if (!action_data.m_Player.GetInventory().AddInventoryReservationEx(wpn, ilWpn, 10000))
187 return false;
188
189 if (!action_data.m_Player.GetInventory().AddInventoryReservationEx(mag, ilMag, 10000))
190 return false;
191
192 action_data_dm.m_ReservedInventoryLocations.Insert(ilWpn);
193 action_data_dm.m_ReservedInventoryLocations.Insert(ilMag);
194 action_data_dm.m_ilWeapon = ilWpn;
195 action_data_dm.m_ilMagazine = ilMag;
196
197 return true;
198 }
199
201 {
202 super.WriteToContext(ctx, action_data);
203
206
207 action_data_dm.m_ilWeapon.WriteToContext(ctx);
208 action_data_dm.m_ilMagazine.WriteToContext(ctx);
209 }
210
212 {
215
216 if (!super.ReadFromContext(ctx, action_recive_data))
217 return false;
218
221
222 recive_data_dm.m_ilWeapon = new InventoryLocation;
223 recive_data_dm.m_ilMagazine = new InventoryLocation;
224
225 if (!recive_data_dm.m_ilWeapon.ReadFromContext(ctx))
226 return false;
227
228 if (!recive_data_dm.m_ilMagazine.ReadFromContext(ctx))
229 return false;
230
231 return true;
232 }
233
244
245
246 override typename GetInputType()
247 {
249 }
250
251 override void CreateConditionComponents() //Instantiates components, called once from ActionManager on actions construction
252 {
255 }
256
258 {
259 return true;
260 }
261
262 override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
263 {
264 if (!super.ActionCondition(player, target, item))
265 return false;
266
268 int mi = wpn.GetCurrentMuzzle();
269 return wpn && wpn.GetMagazine(mi) == target.GetObject();
270 }
271
273 {
274 return true;
275 }
276
278 {
279 if (action_data.m_ReciveEndInput)
280 {
282 return;
283 }
284 super.OnStageStart(action_data);
287 //InventoryLocation il = new InventoryLocation();
289
290 switch (action_data.m_Stage)
291 {
292 case 0:
293 action_data.m_Player.GetWeaponManager().DetachMagazine(action_data_dm.m_ilMagazine, this);
294 break;
295
296 case 1:
297 if (!action_data_dm.m_ilWeapon.IsValid())
298 {
300 break;
301 }
302
303 wpn = Weapon_Base.Cast(action_data.m_MainItem);
304 mag = Magazine.Cast(action_data.m_Target.GetObject());
305
306 action_data.m_Player.GetHumanInventory().ClearUserReservedLocation(wpn);
307 if ((!GetGame().IsDedicatedServer()) && !mag.GetHierarchyParent())
308 {
310
311 if (action_data.m_Player.NeedInventoryJunctureFromServer(mag, action_data.m_Player, action_data.m_Player) || action_data.m_Player.NeedInventoryJunctureFromServer(wpn, action_data.m_Player, action_data.m_Player))
312 invMode = InventoryMode.JUNCTURE;
313
314 action_data.m_Player.GetInventory().ForceSwapEntities(invMode, mag, wpn, action_data_dm.m_ilWeapon);
315 }
316
318 break;
319 default:
321 break;
322 }
323 }
324
326 {
327 super.OnUpdate(action_data);
328
330 if (ad)
331 {
332 switch (ad.m_Stage)
333 {
334 case 0:
335 Weapon_Base wpn = Weapon_Base.Cast(action_data.m_MainItem);
336
337 if ((!wpn || ad.m_Player.GetItemInHands() != wpn || !ad.m_Player.GetWeaponManager().IsRunning()) && !ad.m_Player.IsJumpInProgress())
338 SetStage(1, ad);
339 break;
340 case 1:
341 //action_data.m_Player.GetHandFs
342
343 break;
344 default:
345 break;
346 }
347 }
348 }
349
351 {
353 GetGame().AddInventoryJunctureEx(action_data.m_Player, EntityAI.Cast(action_data.m_Target.GetObject()), action_data_dm.m_ilMagazine, true, 10000);
354 }
355
357 {
358 GetGame().ClearJuncture(action_data.m_Player, EntityAI.Cast(action_data.m_Target.GetObject()));
359 }
360}
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition Inventory.c:22
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
void SetStage(int stage, SequentialActionData action_data)
void End()
called on surrender end request end
DetachMagActionReciveData m_ilMagazine
AdvDetachMagActionReciveData m_ilWeapon
FindInventoryLocationType
flags for searching locations in inventory
override bool ActionConditionContinue(ActionData action_data)
override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
override bool InventoryReservation(ActionData action_data)
override void Start(ActionData action_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
override void OnEndServer(ActionData action_data)
override void OnUpdate(ActionData action_data)
override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
override void OnStartServer(ActionData action_data)
override bool ActionConditionContinue(ActionData action_data)
override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
override bool InventoryReservation(ActionData action_data)
override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
override void OnStageStart(SequentialActionData action_data)
InventoryLocation.
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto native CGame GetGame()