splititemutils.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. class SplitItemUtils
  2. {
  3. static void TakeOrSplitToInventory ( notnull PlayerBase player, notnull EntityAI target, notnull EntityAI item)
  4. {
  5. ItemBase item_base = ItemBase.Cast( item );
  6. if( !item.GetInventory().CanRemoveEntity() || !player.CanManipulateInventory() )
  7. return;
  8. InventoryLocation il = new InventoryLocation;
  9. if( target.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.ANY, il) )
  10. {
  11. if( item_base.GetTargetQuantityMax(il.GetSlot()) >= item_base.GetQuantity() )
  12. {
  13. if( il.GetType() == InventoryLocationType.ATTACHMENT )
  14. {
  15. player.PredictiveTakeEntityToTargetAttachmentEx(il.GetParent(), item, il.GetSlot());
  16. }
  17. else
  18. {
  19. InventoryLocation src = new InventoryLocation;
  20. if (item.GetInventory().GetCurrentInventoryLocation(src))
  21. player.PredictiveTakeToDst(src, il);
  22. }
  23. }
  24. else
  25. {
  26. item_base.SplitIntoStackMaxClient( il.GetParent(), il.GetSlot() );
  27. }
  28. }
  29. }
  30. static void TakeOrSplitToInventoryLocation ( notnull PlayerBase player, notnull InventoryLocation dst)
  31. {
  32. ItemBase item_base = ItemBase.Cast( dst.GetItem() );
  33. int slot = dst.GetSlot();
  34. if( !dst.GetItem().GetInventory().CanRemoveEntity() || !player.CanManipulateInventory() )
  35. return;
  36. float stack_max = item_base.GetTargetQuantityMax(slot);
  37. if( stack_max >= item_base.GetQuantity() )
  38. {
  39. InventoryLocation src = new InventoryLocation;
  40. if (dst.GetItem().GetInventory().GetCurrentInventoryLocation(src))
  41. {
  42. player.PredictiveTakeToDst(src, dst);
  43. }
  44. else
  45. Error("TakeIntoCargoEx cannot get src for dst=" + dst.DumpToString());
  46. }
  47. else
  48. {
  49. item_base.SplitIntoStackMaxToInventoryLocationClient( dst );
  50. }
  51. }
  52. }