Пример #1
0
        public virtual bool AddStackToInventory(InventoryStack stack)
        {
            int i = 0;
            foreach (InventoryStack invStack in inventoryContents)
            {
                if (invStack == null)
                {
                    inventoryContents[i] = stack;
                    return true;
                }
                else if (invStack.stackType == InventoryStack.InventoryStackTypes.Block && stack.stackType == InventoryStack.InventoryStackTypes.Block)
                {
                    if (Type.GetType("Mine2D.Blocks+" + invStack.GetBlock().name) == Type.GetType("Mine2D.Blocks+" + stack.GetBlock().name))
                    {
                        if (invStack.AddAmount(stack.count))
                            return true;
                        else
                        {
                            i++;
                            continue;
                        }
                    }

                    i++;
                }
                else if (invStack.stackType == InventoryStack.InventoryStackTypes.Item && stack.stackType == InventoryStack.InventoryStackTypes.Item)
                {
                    if (Type.GetType("Mine2D.Items+" + invStack.GetItem().name) == Type.GetType("Mine2D.Items+" + stack.GetItem().name))
                    {
                        if (invStack.AddAmount(stack.count))
                            return true;
                        else
                        {
                            i++;
                            continue;
                        }
                    }

                    i++;
                }
                else
                    i++;
            }

            return false;
        }
Пример #2
0
        public static bool CanSumTwoStacks(InventoryStack stack1, InventoryStack stack2)
        {
            if (stack1 != null && stack2 != null)
            {
                if (stack1.stackType == InventoryStack.InventoryStackTypes.Block && stack2.stackType == InventoryStack.InventoryStackTypes.Block)
                {
                    if (stack1.GetBlock().name == stack2.GetBlock().name)
                    {
                        if ((stack1.count + stack2.count <= stack1.maxCount) && (stack1.count + stack2.count <= stack2.maxCount))
                            return true;
                    }
                }
                else if (stack1.stackType == InventoryStack.InventoryStackTypes.Item && stack2.stackType == InventoryStack.InventoryStackTypes.Item)
                {
                    if (stack1.GetItem().name == stack2.GetItem().name)
                    {
                        if ((stack1.count + stack2.count <= stack1.maxCount) && (stack1.count + stack2.count <= stack2.maxCount))
                            return true;
                    }
                }
            }

            return false;
        }