28 if (!super.ActionCondition( player, target, item ))
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);
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);
60 if (!action_recive_data)
65 super.ReadFromContext(ctx, action_recive_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)
89 action_data.m_Target = action_recive_data.m_Target;
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;
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) )
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);
233 if (!super.ActionCondition( player, target, item ))
240 MagazineStorage mag = MagazineStorage.Cast(player.GetWeaponManager().GetPreparedMagazine());
246 bool isLoadedMag =
false;
248 for (
int i = 0, count = weapon.GetMuzzleCount(); i < count; ++i)
249 isLoadedMag |= ( mag == weapon.GetMagazine( i ) );
256 AttachMagazineActionData action_data =
new AttachMagazineActionData;
263 super.WriteToContext(ctx, action_data);
265 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
267 action_data_am.m_ilOldMagazine.WriteToContext(ctx);
272 if (!action_recive_data)
277 super.ReadFromContext(ctx, action_recive_data);
292 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
294 action_data.m_MainItem = action_recive_data.m_MainItem;
295 if (!action_recive_data.m_Target)
301 action_data.m_Target = action_recive_data.m_Target;
308 if ( !
GetGame().IsDedicatedServer() )
311 int muzzle_index = wpn.GetCurrentMuzzle();
313 AttachMagazineActionData am_action_data = AttachMagazineActionData.Cast(action_data);
314 am_action_data.m_oldMagazine = wpn.GetMagazine(muzzle_index);
317 action_data.m_Target = newTarget;
321 if (!action_data.m_Player.GetWeaponManager().PrepareInventoryLocationForMagazineSwap(wpn, Magazine.Cast(action_data.m_Target.GetObject()), new_il))
325 am_action_data.m_ilOldMagazine = new_il;
341 AttachMagazineActionData am_action_data = AttachMagazineActionData.Cast(action_data);
344 int muzzle_index = wpn.GetCurrentMuzzle();
346 Magazine new_mag = Magazine.Cast(action_data.m_Target.GetObject());
348 if (am_action_data.m_oldMagazine)
351 if ( action_data.m_Player.GetInventory().HasInventoryReservation( am_action_data.m_oldMagazine, am_action_data.m_ilOldMagazine) )
365 if ( action_data.m_Player.GetInventory().HasInventoryReservation( new_mag, targetInventoryLocation) )
368 if (am_action_data.m_oldMagazine)
370 player.GetInventory().ClearInventoryReservation(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine);
382 handInventoryLocation.
SetHands(action_data.m_Player, wpn);
384 if ( action_data.m_Player.GetInventory().HasInventoryReservation( wpn, handInventoryLocation) )
386 if (am_action_data.m_oldMagazine)
388 player.GetInventory().ClearInventoryReservation(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine);
390 player.GetInventory().ClearInventoryReservation(new_mag, targetInventoryLocation);
401 if (am_action_data.m_ilOldMagazine)
402 action_data.m_ReservedInventoryLocations.Insert(am_action_data.m_ilOldMagazine);
404 if (targetInventoryLocation)
405 action_data.m_ReservedInventoryLocations.Insert(targetInventoryLocation);
407 if (handInventoryLocation)
408 action_data.m_ReservedInventoryLocations.Insert(handInventoryLocation);
416 super.Start( action_data );
417 AttachMagazineActionData action_data_am = AttachMagazineActionData.Cast(action_data);
419 Magazine mag = Magazine.Cast(action_data.m_Target.GetObject());
421 if ( action_data.m_Player.GetWeaponManager().CanAttachMagazine(wpn,mag,
false) )
422 action_data.m_Player.GetWeaponManager().AttachMagazine(mag,
this);
424 action_data.m_Player.GetWeaponManager().SwapMagazineEx(mag, action_data_am.m_ilOldMagazine,
this);
class ActionTargets ActionTarget
AttachMagazineActionReciveData m_ilOldMagazine
ref CCIBase m_ConditionItem
void ClearInventoryReservationEx(ActionData action_data)
ref CCTBase m_ConditionTarget
ref InventoryLocation m_ilOldMagazine
override bool CanBePerformedFromInventory()
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 bool ActionConditionContinue(ActionData action_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
override int GetActionCategory()
override void Start(ActionData action_data)
override bool CanBePerformedFromQuickbar()
override bool Post_SetupAction(ActionData action_data)
void FirearmActionAttachMagazine()
override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
override ActionData CreateActionData()
override bool HasTarget()
override bool HasProgress()
override void Start(ActionData action_data)
override void CreateConditionComponents()
override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
override bool Post_SetupAction(ActionData action_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
override ActionData CreateActionData()
override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
void FirearmActionAttachMagazineQuick()
override bool InventoryReservation(ActionData action_data)
override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
const int c_InventoryReservationTimeoutMS
reservations
script counterpart to engine's class Inventory
proto native int GetRunningAction()
returns -1 when no action is running or RELOAD,MECHANISM, ....
proto native void SetHands(notnull EntityAI parent, EntityAI e)
sets current inventory location type to Hands
proto native void SetAttachment(notnull EntityAI parent, EntityAI e, int slotId)
sets current inventory location type to Attachment with slot id set to <slotId>
bool ReadFromContext(ParamsReadContext ctx)
provides access to slot configuration
script counterpart to engine's class Weapon
Serializer ParamsReadContext
proto native CGame GetGame()
Serializer ParamsWriteContext