21 override int GetActionCategory()
28 if (!super.ActionCondition( player, target, item ))
31 HumanCommandWeapons hcw = player.GetCommandModifier_Weapons();
32 Magazine mag = Magazine.Cast(target.GetObject());
34 return mag && (player.GetWeaponManager().CanAttachMagazine(wpn,mag) || player.GetWeaponManager().CanSwapMagazine(wpn,mag)) && (!hcw || hcw.GetRunningAction() != WeaponActions.RELOAD);
37 override bool ActionConditionContinue( ActionData action_data )
42 override ActionData CreateActionData()
44 AttachMagazineActionData action_data =
new AttachMagazineActionData;
51 super.WriteToContext(ctx, action_data);
53 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
55 action_data_am.m_ilOldMagazine.WriteToContext(ctx);
58 override bool ReadFromContext(
ParamsReadContext ctx, out ActionReciveData action_recive_data )
60 if (!action_recive_data)
65 super.ReadFromContext(ctx, action_recive_data);
68 if (!il.ReadFromContext(ctx))
72 recive_data_am.m_ilOldMagazine = il;
77 override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
80 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
82 action_data.m_MainItem = action_recive_data.m_MainItem;
83 if (!action_recive_data.m_Target)
85 action_data.m_Target =
new ActionTarget(NULL, NULL, -1,
vector.Zero, 0);
89 action_data.m_Target = action_recive_data.m_Target;
91 action_data_am.m_ilOldMagazine = recive_data_am.m_ilOldMagazine;
94 override bool Post_SetupAction( ActionData action_data )
96 if ( !
GetGame().IsDedicatedServer() )
99 int muzzle_index = wpn.GetCurrentMuzzle();
101 AttachMagazineActionData am_action_data = AttachMagazineActionData.Cast(action_data);
102 am_action_data.m_oldMagazine = wpn.GetMagazine(muzzle_index);
106 if (!action_data.m_Player.GetWeaponManager().PrepareInventoryLocationForMagazineSwap(wpn, Magazine.Cast(action_data.m_Target.GetObject()), new_il))
110 am_action_data.m_ilOldMagazine = new_il;
115 override bool InventoryReservation( ActionData action_data)
126 AttachMagazineActionData am_action_data = AttachMagazineActionData.Cast(action_data);
129 int muzzle_index = wpn.GetCurrentMuzzle();
131 Magazine new_mag = Magazine.Cast(action_data.m_Target.GetObject());
133 if (am_action_data.m_oldMagazine)
136 if ( action_data.m_Player.GetInventory().HasInventoryReservation( am_action_data.m_oldMagazine, am_action_data.m_ilOldMagazine) )
149 targetInventoryLocation.SetAttachment( wpn, new_mag,
InventorySlots.MAGAZINE);
150 if ( action_data.m_Player.GetInventory().HasInventoryReservation( new_mag, targetInventoryLocation) )
153 if (am_action_data.m_oldMagazine)
155 player.GetInventory().ClearInventoryReservation(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine);
167 handInventoryLocation.SetHands(action_data.m_Player, wpn);
169 if ( action_data.m_Player.GetInventory().HasInventoryReservation( wpn, handInventoryLocation) )
171 if (am_action_data.m_oldMagazine)
173 player.GetInventory().ClearInventoryReservation(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine);
175 player.GetInventory().ClearInventoryReservation(new_mag, targetInventoryLocation);
186 if (am_action_data.m_ilOldMagazine)
187 action_data.m_ReservedInventoryLocations.Insert(am_action_data.m_ilOldMagazine);
189 if (targetInventoryLocation)
190 action_data.m_ReservedInventoryLocations.Insert(targetInventoryLocation);
192 if (handInventoryLocation)
193 action_data.m_ReservedInventoryLocations.Insert(handInventoryLocation);
199 override void Start( ActionData action_data )
201 super.Start( action_data );
202 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
204 Magazine mag = Magazine.Cast(action_data.m_Target.GetObject());
206 if ( action_data.m_Player.GetWeaponManager().CanAttachMagazine(wpn,mag,
false) )
207 action_data.m_Player.GetWeaponManager().AttachMagazine(mag,
this);
209 action_data.m_Player.GetWeaponManager().SwapMagazineEx(mag, action_data_am.m_ilOldMagazine,
this);
210 InventoryReservation(action_data);
213 override bool CanBePerformedFromInventory()
218 override bool CanBePerformedFromQuickbar()
231 override bool ActionCondition(
PlayerBase player, ActionTarget target,
ItemBase item )
233 if (!super.ActionCondition( player, target, item ))
236 HumanCommandWeapons hcw = player.GetCommandModifier_Weapons();
237 if (hcw && hcw.GetRunningAction() == WeaponActions.RELOAD)
242 magazine = Magazine.Cast(target.GetObject());
244 magazine = Magazine.Cast(player.GetWeaponManager().GetPreparedMagazine());
249 MagazineStorage mag = MagazineStorage.Cast(magazine);
254 bool isLoadedMag =
false;
256 for (
int i = 0, count = weapon.GetMuzzleCount(); i < count; ++i)
257 isLoadedMag |= ( mag == weapon.GetMagazine( i ) );
262 override ActionData CreateActionData()
264 AttachMagazineActionData action_data =
new AttachMagazineActionData;
271 super.WriteToContext(ctx, action_data);
273 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
275 action_data_am.m_ilOldMagazine.WriteToContext(ctx);
278 override bool ReadFromContext(
ParamsReadContext ctx, out ActionReciveData action_recive_data )
280 if (!action_recive_data)
285 super.ReadFromContext(ctx, action_recive_data);
288 if (!il.ReadFromContext(ctx))
292 recive_data_am.m_ilOldMagazine = il;
297 override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
300 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
302 action_data.m_MainItem = action_recive_data.m_MainItem;
303 if (!action_recive_data.m_Target)
305 action_data.m_Target =
new ActionTarget(NULL, NULL, -1,
vector.Zero, 0);
309 action_data.m_Target = action_recive_data.m_Target;
311 action_data_am.m_ilOldMagazine = recive_data_am.m_ilOldMagazine;
314 override bool Post_SetupAction( ActionData action_data )
316 if ( !
GetGame().IsDedicatedServer() )
319 int muzzle_index = wpn.GetCurrentMuzzle();
321 AttachMagazineActionData am_action_data = AttachMagazineActionData.Cast(action_data);
322 am_action_data.m_oldMagazine = wpn.GetMagazine(muzzle_index);
324 ActionTarget newTarget =
new ActionTarget(action_data.m_Player.GetWeaponManager().GetPreparedMagazine(), null, -1,
vector.Zero, -1);
325 action_data.m_Target = newTarget;
329 if (!action_data.m_Player.GetWeaponManager().PrepareInventoryLocationForMagazineSwap(wpn, Magazine.Cast(action_data.m_Target.GetObject()), new_il))
333 am_action_data.m_ilOldMagazine = new_il;
338 override bool InventoryReservation( ActionData action_data)
349 AttachMagazineActionData am_action_data = AttachMagazineActionData.Cast(action_data);
352 int muzzle_index = wpn.GetCurrentMuzzle();
354 Magazine new_mag = Magazine.Cast(action_data.m_Target.GetObject());
356 if (am_action_data.m_oldMagazine)
359 if ( action_data.m_Player.GetInventory().HasInventoryReservation( am_action_data.m_oldMagazine, am_action_data.m_ilOldMagazine) )
372 targetInventoryLocation.SetAttachment( wpn, new_mag,
InventorySlots.MAGAZINE);
373 if ( action_data.m_Player.GetInventory().HasInventoryReservation( new_mag, targetInventoryLocation) )
376 if (am_action_data.m_oldMagazine)
378 player.GetInventory().ClearInventoryReservation(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine);
390 handInventoryLocation.SetHands(action_data.m_Player, wpn);
392 if ( action_data.m_Player.GetInventory().HasInventoryReservation( wpn, handInventoryLocation) )
394 if (am_action_data.m_oldMagazine)
396 player.GetInventory().ClearInventoryReservation(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine);
398 player.GetInventory().ClearInventoryReservation(new_mag, targetInventoryLocation);
409 if (am_action_data.m_ilOldMagazine)
410 action_data.m_ReservedInventoryLocations.Insert(am_action_data.m_ilOldMagazine);
412 if (targetInventoryLocation)
413 action_data.m_ReservedInventoryLocations.Insert(targetInventoryLocation);
415 if (handInventoryLocation)
416 action_data.m_ReservedInventoryLocations.Insert(handInventoryLocation);
422 override void Start( ActionData action_data )
424 super.Start( action_data );
425 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
427 Magazine mag = Magazine.Cast(action_data.m_Target.GetObject());
429 if ( action_data.m_Player.GetWeaponManager().CanAttachMagazine(wpn,mag,
false) )
430 action_data.m_Player.GetWeaponManager().AttachMagazine(mag,
this);
432 action_data.m_Player.GetWeaponManager().SwapMagazineEx(mag, action_data_am.m_ilOldMagazine,
this);
433 InventoryReservation(action_data);
436 override bool HasTarget()
441 override bool HasProgress()
446 override typename GetInputType()
451 override void CreateConditionComponents()