Example #1
0
        public void Add(Item item)
        {
            if (item.IsStackable)
            {
                var stacks = items.Where(i => i.GetType().IsSubclassOf(typeof(ItemStack)));

                ItemStack currStack;
                int       ix = 0;
                do
                {
                    currStack = (ItemStack)stacks.ElementAtOrDefault(ix);
                    ix++;
                }while (currStack != null && item.HasStackLimit && currStack.Count == item.MaxPerStack);

                if (currStack == null)
                {
                    // No stacks of given type already exist
                    // or all are full
                    var stack = ItemStack.CreateByType(item.GetType());
                    this.items.Add(stack);
                    currStack = stack;
                }

                currStack.Add(item);
            }
            else
            {
                this.items.Add(item);
            }

            NotifyAddRemoval();
        }