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