Esempio n. 1
0
        public static ItemAmountRow[] ItemsToRows(IList <InventoryItemBase> itemsToAdd)
        {
            var list = new List <ItemAmountRow>(itemsToAdd.Count);

            for (int i = 0; i < itemsToAdd.Count; i++)
            {
                if (itemsToAdd[i] == null)
                {
                    continue;
                }

                uint stackCount = itemsToAdd[i].currentStackSize;
                while (stackCount > 0)
                {
                    var row = new ItemAmountRow(itemsToAdd[i], stackCount);
                    if (stackCount > itemsToAdd[i].maxStackSize)
                    {
                        stackCount -= itemsToAdd[i].maxStackSize;
                        row.SetAmount(itemsToAdd[i].maxStackSize);
                    }
                    else
                    {
                        stackCount = 0;
                    }

                    list.Add(row);
                }
            }

            return(list.ToArray());
        }
Esempio n. 2
0
        public static ItemAmountRow[] EnforceMaxStackSize(IEnumerable <ItemAmountRow> itemRows)
        {
            var list = new List <ItemAmountRow>();

            foreach (var row in itemRows)
            {
                uint stackCount = row.amount;
                while (stackCount > 0)
                {
                    var row2 = new ItemAmountRow(row.item, stackCount);
                    if (stackCount > row.item.maxStackSize)
                    {
                        stackCount -= row.item.maxStackSize;
                        row2.SetAmount(row.item.maxStackSize);
                    }
                    else
                    {
                        stackCount = 0;
                    }

                    list.Add(row2);
                }
            }

            return(list.ToArray());
        }