Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
firearmactiondetachmagazine.c
Go to the documentation of this file.
1 class DetachMagActionReciveData : ActionReciveData
2 {
3  ref InventoryLocation m_ilMagazine;
4 }
5 class DetachMagActionData : ActionData
6 {
8 }
9 
11 {
13  {
14  }
15 
16  override bool HasTarget()
17  {
18  return true;
19  }
20 
21  override typename GetInputType()
22  {
23  return QuickaBarActionInput;
24  }
25 
26  override bool CanBePerformedFromQuickbar()
27  {
28  return true;
29  }
30 
31  override void CreateConditionComponents()
32  {
35  }
36 
37  override bool HasProgress()
38  {
39  return false;
40  }
41 
42  override bool InventoryReservation( ActionData action_data)
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 
52  DetachMagActionData action_data_dm = DetachMagActionData.Cast(action_data);
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 
62  override ActionData CreateActionData()
63  {
64  ActionData action_data = new DetachMagActionData;
65  return action_data;
66  }
67 
68  override void WriteToContext (ParamsWriteContext ctx, ActionData action_data)
69  {
70  super.WriteToContext(ctx, action_data);
71 
72  DetachMagActionData action_data_dm;
73  DetachMagActionData.CastTo(action_data_dm, action_data);
74 
75  action_data_dm.m_ilMagazine.WriteToContext(ctx);
76  }
77 
78  override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
79  {
80  if(!action_recive_data)
81  {
82  action_recive_data = new DetachMagActionReciveData;
83  }
84 
85  if(!super.ReadFromContext( ctx, action_recive_data ))
86  return false;
87 
88  DetachMagActionReciveData recive_data_dm;
89  recive_data_dm = DetachMagActionReciveData.Cast( action_recive_data );
90 
91  recive_data_dm.m_ilMagazine = new InventoryLocation;
92 
93  if(!recive_data_dm.m_ilMagazine.ReadFromContext(ctx))
94  return false;
95 
96  return true;
97  }
98 
99  override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
100  {
101  super.HandleReciveData(action_recive_data, action_data);
102 
103  DetachMagActionReciveData recive_data_dm = DetachMagActionReciveData.Cast(action_recive_data);
104  DetachMagActionData action_data_dm = DetachMagActionData.Cast(action_data);
105 
106  action_data_dm.m_ilMagazine = recive_data_dm.m_ilMagazine;
107  }
108 
109 
110  override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item ) //condition for action
111  {
112  if (!super.ActionCondition( player, target, item ))
113  return false;
114 
115  Magazine mag = Magazine.Cast(target.GetObject());
116  Weapon_Base wpn = Weapon_Base.Cast(item);
117  return mag && player.GetWeaponManager().CanDetachMagazine(wpn,mag);
118  }
119 
120  override bool ActionConditionContinue( ActionData action_data)
121  {
122  return true;
123  }
124 
125  override void Start( ActionData action_data )
126  {
127  super.Start( action_data );
128  DetachMagActionData action_data_dm = DetachMagActionData.Cast(action_data);
129 
130  Weapon_Base wpn = Weapon_Base.Cast( action_data.m_MainItem );
131 
132  action_data.m_Player.GetWeaponManager().DetachMagazine(action_data_dm.m_ilMagazine,this);
133  }
134 };
135 
136 class AdvDetachMagActionReciveData : ActionReciveData
137 {
138  ref InventoryLocation m_ilWeapon;
139  ref InventoryLocation m_ilMagazine;
140 }
141 class AdvDetachMagActionData : SequentialActionData
142 {
145 }
146 
147 class FirearmActionDetachMagazine : ActionSequentialBase
148 {
150  {
151  }
152 
153  override ActionData CreateActionData()
154  {
155  ActionData action_data = new AdvDetachMagActionData;
156  return action_data;
157  }
158 
159 
160  override bool InventoryReservation( ActionData action_data)
161  {
162  Weapon_Base wpn = Weapon_Base.Cast(action_data.m_MainItem);
163  Magazine mag = Magazine.Cast(action_data.m_Target.GetObject());
164 
165  InventoryLocation ilWpn = new InventoryLocation();
166  InventoryLocation ilMag = new InventoryLocation();
167 
168 
169  int ur_index = action_data.m_Player.GetHumanInventory().FindUserReservedLocationIndex(wpn);
170 
171  if(ur_index > -1)
172  action_data.m_Player.GetHumanInventory().GetUserReservedLocation(ur_index,ilWpn);
173  else
174  {
175  action_data.m_Player.GetInventory().FindFreeLocationFor(wpn, FindInventoryLocationType.ANY_CARGO | FindInventoryLocationType.ATTACHMENT, ilWpn);
176 
177 
178  //return false;
179  }
180 
181  if( !action_data.m_Player.GetInventory().FindFreeLocationFor(mag, FindInventoryLocationType.ANY_CARGO, ilMag) )
182  return false;
183 
184  if( !super.InventoryReservation( action_data ) )
185  return false;
186 
187  AdvDetachMagActionData action_data_dm = AdvDetachMagActionData.Cast(action_data);
188  if( !action_data.m_Player.GetInventory().AddInventoryReservationEx(wpn,ilWpn,10000) )
189  return false;
190 
191  if( !action_data.m_Player.GetInventory().AddInventoryReservationEx(mag,ilMag,10000) )
192  return false;
193 
194  action_data_dm.m_ReservedInventoryLocations.Insert(ilWpn);
195  action_data_dm.m_ReservedInventoryLocations.Insert(ilMag);
196  action_data_dm.m_ilWeapon = ilWpn;
197  action_data_dm.m_ilMagazine = ilMag;
198 
199  return true;
200  }
201 
202  override void WriteToContext (ParamsWriteContext ctx, ActionData action_data)
203  {
204  super.WriteToContext(ctx, action_data);
205 
206  AdvDetachMagActionData action_data_dm;
207  AdvDetachMagActionData.CastTo(action_data_dm, action_data);
208 
209  action_data_dm.m_ilWeapon.WriteToContext(ctx);
210  action_data_dm.m_ilMagazine.WriteToContext(ctx);
211  }
212 
213  override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
214  {
215  if(!action_recive_data)
216  {
217  action_recive_data = new AdvDetachMagActionReciveData;
218  }
219 
220  if(!super.ReadFromContext( ctx, action_recive_data ))
221  return false;
222 
223  AdvDetachMagActionReciveData recive_data_dm;
224  recive_data_dm = AdvDetachMagActionReciveData.Cast( action_recive_data );
225 
226  recive_data_dm.m_ilWeapon = new InventoryLocation;
227  recive_data_dm.m_ilMagazine = new InventoryLocation;
228 
229  if(!recive_data_dm.m_ilWeapon.ReadFromContext(ctx))
230  return false;
231 
232  if(!recive_data_dm.m_ilMagazine.ReadFromContext(ctx))
233  return false;
234 
235  return true;
236  }
237 
238  override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
239  {
240  super.HandleReciveData(action_recive_data, action_data);
241 
242  AdvDetachMagActionReciveData recive_data_dm = AdvDetachMagActionReciveData.Cast(action_recive_data);
243  AdvDetachMagActionData action_data_dm = AdvDetachMagActionData.Cast(action_data);
244 
245  action_data_dm.m_ilWeapon.Copy(recive_data_dm.m_ilWeapon);
246  action_data_dm.m_ilMagazine.Copy(recive_data_dm.m_ilMagazine);
247  }
248 
249 
250  override typename GetInputType()
251  {
252  return QuickaBarActionInput;
253  }
254 
255  override void CreateConditionComponents() //Instantiates components, called once from ActionManager on actions construction
256  {
259  }
260 
261  override bool CanBePerformedFromQuickbar()
262  {
263  return true;
264  }
265 
266  override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
267  {
268  if (!super.ActionCondition( player, target, item ))
269  return false;
270 
271  Weapon_Base wpn = Weapon_Base.Cast( item );
272  int mi = wpn.GetCurrentMuzzle();
273  return wpn && wpn.GetMagazine(mi) == target.GetObject();
274  }
275 
276  override bool ActionConditionContinue( ActionData action_data )
277  {
278  return true;
279  }
280 
281  override void OnStageStart(SequentialActionData action_data)
282  {
283  if( action_data.m_ReciveEndInput )
284  {
285  End( action_data );
286  return;
287  }
288  super.OnStageStart(action_data);
289  Weapon_Base wpn;
290  Magazine mag;
291  //InventoryLocation il = new InventoryLocation();
292  AdvDetachMagActionData action_data_dm = AdvDetachMagActionData.Cast(action_data);
293 
294  switch (action_data.m_Stage)
295  {
296  case 0:
297  action_data.m_Player.GetWeaponManager().DetachMagazine(action_data_dm.m_ilMagazine,this);
298  break;
299 
300  case 1:
301  if ( !action_data_dm.m_ilWeapon.IsValid() )
302  {
303  End( action_data );
304  break;
305  }
306 
307  wpn = Weapon_Base.Cast(action_data.m_MainItem);
308  mag = Magazine.Cast(action_data.m_Target.GetObject());
309 
310  action_data.m_Player.GetHumanInventory().ClearUserReservedLocation(wpn);
311  if ( ( !GetGame().IsDedicatedServer() ) && !mag.GetHierarchyParent() )
312  {
313  InventoryMode invMode = InventoryMode.PREDICTIVE;
314 
315  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) )
316  invMode = InventoryMode.JUNCTURE;
317 
318  action_data.m_Player.GetInventory().ForceSwapEntities(invMode, mag, wpn, action_data_dm.m_ilWeapon);
319  }
320 
321  End( action_data );
322  break;
323  default:
324  End( action_data );
325  break;
326  }
327  }
328 
329  override void OnUpdate( ActionData action_data )
330  {
331  super.OnUpdate( action_data );
332 
333  SequentialActionData ad = SequentialActionData.Cast(action_data);
334  if(ad)
335  {
336  switch (ad.m_Stage)
337  {
338  case 0:
339  Weapon_Base wpn = Weapon_Base.Cast(action_data.m_MainItem);
340 
341  if ( (!wpn || ad.m_Player.GetItemInHands()!=wpn || !ad.m_Player.GetWeaponManager().IsRunning()) && !ad.m_Player.IsJumpInProgress() )
342  {
343  SetStage(1, ad);
344  }
345  break;
346  case 1:
347  //action_data.m_Player.GetHandFs
348 
349  break;
350  default:
351  break;
352  }
353  }
354  }
355 
356  override void OnStartServer( ActionData action_data )
357  {
358  AdvDetachMagActionData action_data_dm = AdvDetachMagActionData.Cast(action_data);
359  GetGame().AddInventoryJunctureEx(action_data.m_Player, EntityAI.Cast(action_data.m_Target.GetObject()),action_data_dm.m_ilMagazine, true, 10000);
360  }
361 
362  override void OnEndServer( ActionData action_data )
363  {
364  GetGame().ClearJuncture(action_data.m_Player, EntityAI.Cast(action_data.m_Target.GetObject()));
365  }
366 }
ItemBase
Definition: inventoryitem.c:730
End
void End()
called on surrender end request end
GetGame
proto native CGame GetGame()
DetachMagActionReciveData
Definition: firearmactiondetachmagazine.c:1
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
CCTNone
Definition: cctnone.c:1
CCIDummy
Definition: ccidummy.c:1
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
PlayerBase
Definition: playerbaseclient.c:1
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
InventoryMode
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition: inventory.c:21
m_ilMagazine
DetachMagActionReciveData m_ilMagazine
Definition: firearmactiondetachmagazine.c:144
CCTSelf
Definition: cctself.c:1
SetStage
void SetStage(int stage, SequentialActionData action_data)
Definition: actionsequentialbase.c:60
SequentialActionData
Definition: actionsequentialbase.c:1
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
FirearmActionDetachMagazine
Definition: firearmactiondetachmagazine.c:147
QuickaBarActionInput
Definition: actioninput.c:943
FirearmActionDetachMagazine_Old
Definition: firearmactiondetachmagazine.c:10
Weapon_Base
shorthand
Definition: boltactionrifle_base.c:5
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
CCINonRuined
Definition: ccinonruined.c:1
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
FirearmActionBase
Definition: firearmactionbase.c:1
EntityAI
Definition: building.c:5
AdvDetachMagActionReciveData
Definition: firearmactiondetachmagazine.c:136
m_ilWeapon
AdvDetachMagActionReciveData m_ilWeapon