Example #1
0
        public static MyInventoryAggregate FixInputOutputInventories(MyInventoryAggregate inventoryAggregate, MyInventoryConstraint inputInventoryConstraint, MyInventoryConstraint outputInventoryConstraint)
        {
            MyInventory objA      = null;
            MyInventory component = null;

            foreach (MyInventory inventory3 in inventoryAggregate.ChildList.Reader)
            {
                if (inventory3 == null)
                {
                    continue;
                }
                if (inventory3.GetItemsCount() > 0)
                {
                    if (objA == null)
                    {
                        bool flag = true;
                        if (inputInventoryConstraint != null)
                        {
                            foreach (MyPhysicalInventoryItem item in inventory3.GetItems())
                            {
                                flag &= inputInventoryConstraint.Check(item.GetDefinitionId());
                            }
                        }
                        if (flag)
                        {
                            objA = inventory3;
                        }
                    }
                    if ((component == null) && !ReferenceEquals(objA, inventory3))
                    {
                        bool flag2 = true;
                        if (outputInventoryConstraint != null)
                        {
                            foreach (MyPhysicalInventoryItem item2 in inventory3.GetItems())
                            {
                                flag2 &= outputInventoryConstraint.Check(item2.GetDefinitionId());
                            }
                        }
                        if (flag2)
                        {
                            component = inventory3;
                        }
                    }
                }
            }
            if ((objA == null) || (component == null))
            {
                foreach (MyInventory inventory4 in inventoryAggregate.ChildList.Reader)
                {
                    if (inventory4 != null)
                    {
                        if (objA == null)
                        {
                            objA = inventory4;
                            continue;
                        }
                        if (component != null)
                        {
                            break;
                        }
                        component = inventory4;
                    }
                }
            }
            inventoryAggregate.RemoveComponent(objA);
            inventoryAggregate.RemoveComponent(component);
            MyInventoryAggregate aggregate = new MyInventoryAggregate();

            aggregate.AddComponent(objA);
            aggregate.AddComponent(component);
            return(aggregate);
        }
Example #2
0
        /// <summary>
        /// Naive looking for inventories with some items..
        /// </summary>
        static public MyInventoryAggregate FixInputOutputInventories(MyInventoryAggregate inventoryAggregate, MyInventoryConstraint inputInventoryConstraint, MyInventoryConstraint outputInventoryConstraint)
        {
            MyInventory inputInventory  = null;
            MyInventory outputInventory = null;

            foreach (var inventory in inventoryAggregate.ChildList.Reader)
            {
                var myInventory = inventory as MyInventory;

                if (myInventory == null)
                {
                    continue;
                }

                if (myInventory.GetItemsCount() > 0)
                {
                    if (inputInventory == null)
                    {
                        bool check = true;
                        if (inputInventoryConstraint != null)
                        {
                            foreach (var item in myInventory.GetItems())
                            {
                                check &= inputInventoryConstraint.Check(item.GetDefinitionId());
                            }
                        }
                        if (check)
                        {
                            inputInventory = myInventory;
                        }
                    }
                    if (outputInventory == null && inputInventory != myInventory)
                    {
                        bool check = true;
                        if (outputInventoryConstraint != null)
                        {
                            foreach (var item in myInventory.GetItems())
                            {
                                check &= outputInventoryConstraint.Check(item.GetDefinitionId());
                            }
                        }
                        if (check)
                        {
                            outputInventory = myInventory;
                        }
                    }
                }
            }

            if (inputInventory == null || outputInventory == null)
            {
                foreach (var inventory in inventoryAggregate.ChildList.Reader)
                {
                    var myInventory = inventory as MyInventory;
                    if (myInventory == null)
                    {
                        continue;
                    }
                    if (inputInventory == null)
                    {
                        inputInventory = myInventory;
                    }
                    else if (outputInventory == null)
                    {
                        outputInventory = myInventory;
                    }
                    else
                    {
                        break;
                    }
                }
            }


            inventoryAggregate.RemoveComponent(inputInventory);
            inventoryAggregate.RemoveComponent(outputInventory);
            var fixedAggregate = new MyInventoryAggregate();

            fixedAggregate.AddComponent(inputInventory);
            fixedAggregate.AddComponent(outputInventory);
            return(fixedAggregate);
        }
        /// <summary>
        /// Naive looking for inventories with some items..
        /// </summary>
        static public MyInventoryAggregate FixInputOutputInventories(MyInventoryAggregate inventoryAggregate, MyInventoryConstraint inputInventoryConstraint, MyInventoryConstraint outputInventoryConstraint)
        {
            MyInventory inputInventory = null;
            MyInventory outputInventory = null;

            foreach (var inventory in inventoryAggregate.ChildList.Reader)
            {
                var myInventory = inventory as MyInventory;

                if (myInventory == null)
                    continue;

                if (myInventory.GetItemsCount() > 0)
                {
                    if (inputInventory == null)
                    {
                        bool check = true;
                        if (inputInventoryConstraint != null)
                        {
                            foreach (var item in myInventory.GetItems())
                            {
                                check &= inputInventoryConstraint.Check(item.GetDefinitionId());
                            }
                        }
                        if (check)
                        {
                            inputInventory = myInventory;
                        }
                    }
                    if (outputInventory == null && inputInventory != myInventory)
                    {
                        bool check = true;
                        if (outputInventoryConstraint != null)
                        {
                            foreach (var item in myInventory.GetItems())
                            {
                                check &= outputInventoryConstraint.Check(item.GetDefinitionId());
                            }
                        }
                        if (check)
                        {
                            outputInventory = myInventory;
                        }
                    }
                }
            }

            if (inputInventory == null || outputInventory == null)
            {
                foreach (var inventory in inventoryAggregate.ChildList.Reader)
                {
                    var myInventory = inventory as MyInventory;
                    if (myInventory == null)
                        continue;
                    if (inputInventory == null)
                    {
                        inputInventory = myInventory;
                    }
                    else if (outputInventory == null)
                    {
                        outputInventory = myInventory;
                    }
                    else
                    {
                        break;
                    }
                }
            }


            inventoryAggregate.RemoveComponent(inputInventory);
            inventoryAggregate.RemoveComponent(outputInventory);
            var fixedAggregate = new MyInventoryAggregate();
            fixedAggregate.AddComponent(inputInventory);
            fixedAggregate.AddComponent(outputInventory);
            return fixedAggregate;
        }