331 {
333 return true;
334
335 bool success = true;
336 InventoryLocation oldMagTargetInventoryLocation = NULL;
337 InventoryLocation targetInventoryLocation = NULL;
338 InventoryLocation handInventoryLocation = NULL;
339
340 PlayerBase player = action_data.m_Player;
341 AttachMagazineActionData am_action_data = AttachMagazineActionData.Cast(action_data);
342
343 Weapon_Base wpn = Weapon_Base.Cast(action_data.m_MainItem);
344 int muzzle_index = wpn.GetCurrentMuzzle();
345
346 Magazine new_mag = Magazine.Cast(action_data.m_Target.GetObject());
347
348 if (am_action_data.m_oldMagazine)
349 {
350 oldMagTargetInventoryLocation = new InventoryLocation;
351 if ( action_data.m_Player.GetInventory().HasInventoryReservation( am_action_data.m_oldMagazine, am_action_data.m_ilOldMagazine) )
352 {
353 success = false;
354 }
355 else
356 {
357 player.GetInventory().AddInventoryReservationEx(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine,GameInventory.c_InventoryReservationTimeoutMS);
358 }
359 }
360
361 if (success)
362 {
363 targetInventoryLocation = new InventoryLocation;
364 targetInventoryLocation.
SetAttachment( wpn, new_mag, InventorySlots.MAGAZINE);
365 if ( action_data.m_Player.GetInventory().HasInventoryReservation( new_mag, targetInventoryLocation) )
366 {
367 success = false;
368 if (am_action_data.m_oldMagazine)
369 {
370 player.GetInventory().ClearInventoryReservation(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine);
371 }
372 }
373 else
374 {
375 action_data.m_Player.GetInventory().AddInventoryReservationEx( new_mag, targetInventoryLocation, GameInventory.c_InventoryReservationTimeoutMS);
376 }
377 }
378
379 if (success)
380 {
381 handInventoryLocation = new InventoryLocation;
382 handInventoryLocation.
SetHands(action_data.m_Player, wpn);
383
384 if ( action_data.m_Player.GetInventory().HasInventoryReservation( wpn, handInventoryLocation) )
385 {
386 if (am_action_data.m_oldMagazine)
387 {
388 player.GetInventory().ClearInventoryReservation(am_action_data.m_oldMagazine,am_action_data.m_ilOldMagazine);
389 }
390 player.GetInventory().ClearInventoryReservation(new_mag, targetInventoryLocation);
391 success = false;
392 }
393 else
394 {
395 action_data.m_Player.GetInventory().AddInventoryReservationEx( wpn, handInventoryLocation, GameInventory.c_InventoryReservationTimeoutMS);
396 }
397 }
398
399 if ( success )
400 {
401 if (am_action_data.m_ilOldMagazine)
402 action_data.m_ReservedInventoryLocations.Insert(am_action_data.m_ilOldMagazine);
403
404 if (targetInventoryLocation)
405 action_data.m_ReservedInventoryLocations.Insert(targetInventoryLocation);
406
407 if (handInventoryLocation)
408 action_data.m_ReservedInventoryLocations.Insert(handInventoryLocation);
409 }
410
411 return success;
412 }
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>