11class FirearmActionAttachMagazine : FirearmActionBase
16 void FirearmActionAttachMagazine()
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 )
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 ( !
g_Game.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);
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);
225class FirearmActionAttachMagazineQuick : FirearmActionBase
227 void FirearmActionAttachMagazineQuick()
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 ) );
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 ( !
g_Game.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)
352 AttachMagazineActionData am_action_data = AttachMagazineActionData.Cast(action_data);
355 int muzzle_index = wpn.GetCurrentMuzzle();
357 Magazine new_mag = Magazine.Cast(action_data.m_Target.GetObject());
359 if (am_action_data.m_oldMagazine)
362 if ( action_data.m_Player.GetInventory().HasInventoryReservation( am_action_data.m_oldMagazine, am_action_data.m_ilOldMagazine) )
375 targetInventoryLocation.SetAttachment( wpn, new_mag,
InventorySlots.MAGAZINE);
376 if ( action_data.m_Player.GetInventory().HasInventoryReservation( new_mag, targetInventoryLocation) )
379 if (am_action_data.m_oldMagazine)
381 player.GetInventory().ClearInventoryReservation(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine);
393 handInventoryLocation.SetHands(action_data.m_Player, wpn);
395 if ( action_data.m_Player.GetInventory().HasInventoryReservation( wpn, handInventoryLocation) )
397 if (am_action_data.m_oldMagazine)
399 player.GetInventory().ClearInventoryReservation(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine);
401 player.GetInventory().ClearInventoryReservation(new_mag, targetInventoryLocation);
412 if (am_action_data.m_ilOldMagazine)
413 action_data.m_ReservedInventoryLocations.Insert(am_action_data.m_ilOldMagazine);
415 if (targetInventoryLocation)
416 action_data.m_ReservedInventoryLocations.Insert(targetInventoryLocation);
418 if (handInventoryLocation)
419 action_data.m_ReservedInventoryLocations.Insert(handInventoryLocation);
427 super.Start( action_data );
428 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
430 Magazine mag = Magazine.Cast(action_data.m_Target.GetObject());
432 if ( action_data.m_Player.GetWeaponManager().CanAttachMagazine(wpn,mag,
false) )
433 action_data.m_Player.GetWeaponManager().AttachMagazine(mag,
this);
435 action_data.m_Player.GetWeaponManager().SwapMagazineEx(mag, action_data_am.m_ilOldMagazine,
this);
436 InventoryReservation(action_data);