/** * <summary>Transfer all counts of a given inventory item from another collection</summary> * <param name="invID">The ID of the inventory item (InvItem) to transfer</param> * <param name="fromCollection">The collection to transfer from</param> */ public void Transfer(int invID, InvCollection fromCollection) { if (fromCollection == null || !fromCollection.Contains(invID)) { return; } foreach (InvInstance invInstance in fromCollection.invInstances) { if (!InvInstance.IsValid(invInstance) || invInstance.ItemID != invID) { continue; } Add(invInstance); } }
/** * <summary>Transfer a set count of a given inventory item from another collection</summary> * <param name="invID">The ID of the inventory item (InvItem) to transfer</param> * <param name="fromCollection">The collection to transfer from</param> * <param name="amount">The amount of items to transfer</param> */ public void Transfer(int invID, InvCollection fromCollection, int amount) { if (fromCollection == null || !fromCollection.Contains(invID)) { return; } foreach (InvInstance invInstance in fromCollection.invInstances) { if (!InvInstance.IsValid(invInstance) || invInstance.ItemID != invID) { continue; } int thisItemCount = invInstance.Count; if (thisItemCount < amount) { // Will need more after this invInstance.TransferCount = thisItemCount; amount -= thisItemCount; } else { // All we need invInstance.TransferCount = amount; amount = 0; } Add(invInstance); if (amount == 0) { break; } } }