private static void TransferOrRemove(MyInventory src, MyFixedPoint?amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, MyInventory dst = null, bool spawn = false)
        {
            //Debug.Assert(!amount.HasValue || amount.Value > 0, "Transfering 0 amount of item.");
            if (src.ContainItems(amount, contentId, flags))
            {
                bool         transferAll     = !amount.HasValue;
                MyFixedPoint remainingAmount = transferAll ? 0 : amount.Value;

                int i = 0;
                while (i < src.m_items.Count)
                {
                    if (!transferAll && remainingAmount == 0)
                    {
                        break;
                    }

                    MyInventoryItem item = src.m_items[i];

                    //TODO(AF) Remove oxygen specific code from inventory.
                    //Will be fixed once MyInventory will support Entities.
                    var oxygenBottle = item.Content as MyObjectBuilder_OxygenContainerObject;
                    if (oxygenBottle != null && oxygenBottle.OxygenLevel == 1f)
                    {
                        i++;
                        continue;
                    }
                    // End of oxygen specific code


                    if (item.Content.GetObjectId() != contentId)
                    {
                        i++;
                        continue;
                    }

                    if (transferAll || remainingAmount >= item.Amount)
                    {
                        remainingAmount -= item.Amount;
                        Transfer(src, dst, item.ItemId, -1, spawn: spawn);
                    }
                    else
                    {
                        Transfer(src, dst, item.ItemId, -1, remainingAmount, spawn);
                        remainingAmount = 0;
                    }
                }
            }
        }
示例#2
0
        private static MyFixedPoint TransferOrRemove(MyInventory src, MyFixedPoint? amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, MyInventory dst = null, bool spawn = false, bool onlyWhole = true)
        {
            MyFixedPoint removedAmount = 0;

            if (!onlyWhole)
            {
                amount = MyFixedPoint.Min(amount.Value, src.GetItemAmount(contentId, flags));
            }

            //Debug.Assert(!amount.HasValue || amount.Value > 0, "Transfering 0 amount of item.");
            if (!onlyWhole || src.ContainItems(amount, contentId, flags))
            {
                bool transferAll = !amount.HasValue;
                MyFixedPoint remainingAmount = transferAll ? 0 : amount.Value;

                //TODO(AF) Remove oxygen specific code from inventory.
                //Will be fixed once MyInventory will support Entities.
                // If the requested item is an oxygen container, do a preliminary loop to pull any non-full items first.
                if (contentId.TypeId == typeof(MyObjectBuilder_OxygenContainerObject) || contentId.TypeId == typeof(MyObjectBuilder_GasContainerObject))
                {
                    int k = 0;
                    while (k < src.m_items.Count)
                    {
                        if (!transferAll && remainingAmount == 0)
                            break;

                        MyPhysicalInventoryItem item = src.m_items[k];

                        // Skip full oxygen bottles in this loop.  They will not be skipped in the next one.
                        var oxygenBottle = item.Content as MyObjectBuilder_GasContainerObject;
                        if (oxygenBottle != null && oxygenBottle.GasLevel == 1f)
                        {
                            k++;
                            continue;
                        }

                        if (item.Content.GetObjectId() != contentId)
                        {
                            k++;
                            continue;
                        }

                        if (transferAll || remainingAmount >= item.Amount)
                        {
                            removedAmount += item.Amount;
                            remainingAmount -= item.Amount;
                            Transfer(src, dst, item.ItemId, -1, spawn: spawn);
                        }
                        else
                        {
                            removedAmount += item.Amount;
                            Transfer(src, dst, item.ItemId, -1, remainingAmount, spawn);
                            remainingAmount = 0;
                        }
                    }
                }
                // End of oxygen specific code

                int i = 0;
                while (i < src.m_items.Count)
                {
                    if (!transferAll && remainingAmount == 0)
                        break;

                    MyPhysicalInventoryItem item = src.m_items[i];

                    var objectId = item.Content.GetId();
                    if (objectId != contentId && item.Content.TypeId == typeof(MyObjectBuilder_BlockItem))
                    {
                        //objectId = MyDefinitionManager.Static.GetComponentId(item.Content.GetObjectId());
                        objectId = item.Content.GetObjectId();
                    }

                    if (objectId != contentId)
                    {
                        i++;
                        continue;
                    }

                    if (transferAll || remainingAmount >= item.Amount)
                    {
                        removedAmount += item.Amount;
                        remainingAmount -= item.Amount;
                        Transfer(src, dst, item.ItemId, -1, spawn: spawn);
                    }
                    else
                    {
                        removedAmount += remainingAmount;
                        Transfer(src, dst, item.ItemId, -1, remainingAmount, spawn);
                        remainingAmount = 0;
                    }
                }
            }

            return removedAmount;
        }
        private static void TransferOrRemove(MyInventory src, MyFixedPoint?amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, MyInventory dst = null, bool spawn = false)
        {
            //Debug.Assert(!amount.HasValue || amount.Value > 0, "Transfering 0 amount of item.");
            if (src.ContainItems(amount, contentId, flags))
            {
                bool         transferAll     = !amount.HasValue;
                MyFixedPoint remainingAmount = transferAll ? 0 : amount.Value;

                //TODO(AF) Remove oxygen specific code from inventory.
                //Will be fixed once MyInventory will support Entities.
                // If the requested item is an oxygen container, do a preliminary loop to pull any non-full items first.
                if (contentId.TypeId == typeof(MyObjectBuilder_OxygenContainerObject))
                {
                    int k = 0;
                    while (k < src.m_items.Count)
                    {
                        if (!transferAll && remainingAmount == 0)
                        {
                            break;
                        }

                        MyPhysicalInventoryItem item = src.m_items[k];

                        // Skip full oxygen bottles in this loop.  They will not be skipped in the next one.
                        var oxygenBottle = item.Content as MyObjectBuilder_OxygenContainerObject;
                        if (oxygenBottle != null && oxygenBottle.OxygenLevel == 1f)
                        {
                            k++;
                            continue;
                        }

                        if (item.Content.GetObjectId() != contentId)
                        {
                            k++;
                            continue;
                        }

                        if (transferAll || remainingAmount >= item.Amount)
                        {
                            remainingAmount -= item.Amount;
                            Transfer(src, dst, item.ItemId, -1, spawn: spawn);
                        }
                        else
                        {
                            Transfer(src, dst, item.ItemId, -1, remainingAmount, spawn);
                            remainingAmount = 0;
                        }
                    }
                }
                // End of oxygen specific code

                int i = 0;
                while (i < src.m_items.Count)
                {
                    if (!transferAll && remainingAmount == 0)
                    {
                        break;
                    }

                    MyPhysicalInventoryItem item = src.m_items[i];

                    if (item.Content.GetObjectId() != contentId)
                    {
                        i++;
                        continue;
                    }

                    if (transferAll || remainingAmount >= item.Amount)
                    {
                        remainingAmount -= item.Amount;
                        Transfer(src, dst, item.ItemId, -1, spawn: spawn);
                    }
                    else
                    {
                        Transfer(src, dst, item.ItemId, -1, remainingAmount, spawn);
                        remainingAmount = 0;
                    }
                }
            }
        }
示例#4
0
        private static void TransferOrRemove(MyInventory src, MyFixedPoint? amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, MyInventory dst = null, bool spawn = false)
        {
            //Debug.Assert(!amount.HasValue || amount.Value > 0, "Transfering 0 amount of item.");
            if (src.ContainItems(amount, contentId, flags))
            {
                bool transferAll = !amount.HasValue;
                MyFixedPoint remainingAmount = transferAll ? 0 : amount.Value;

                int i = 0;
                while (i < src.m_items.Count)
                {
                    if (!transferAll && remainingAmount == 0)
                        break;

                    MyInventoryItem item = src.m_items[i];

                    //TODO(AF) Remove oxygen specific code from inventory.
                    //Will be fixed once MyInventory will support Entities.
                    var oxygenBottle = item.Content as MyObjectBuilder_OxygenContainerObject;
                    if (oxygenBottle != null && oxygenBottle.OxygenLevel == 1f)
                    {
                        i++;
                        continue;
                    }
                    // End of oxygen specific code


                    if (item.Content.GetObjectId() != contentId)
                    {
                        i++;
                        continue;
                    }

                    if (transferAll || remainingAmount >= item.Amount)
                    {
                        remainingAmount -= item.Amount;
                        Transfer(src, dst, item.ItemId, -1, spawn: spawn);
                    }
                    else
                    {
                        Transfer(src, dst, item.ItemId, -1, remainingAmount, spawn);
                        remainingAmount = 0;
                    }
                }
            }
        }