Exemplo n.º 1
0
        private bool Stack(Item item)
        {
            if (!item.IsStackable)
            {
                return(false);
            }

            var stackable = Items.OrderBy(element => element.StackCount)
                            .FirstOrDefault(element => element.Id == item.Id && element.StackCount < element.StackCountMax);

            if (stackable == null || stackable.StackCount + item.StackCount > stackable.StackCountMax)
            {
                return(false);
            }

            stackable.AddStack(item.StackCount);

            ItemStackCountChanged?.Invoke(new ItemStackCountChangedEventData(stackable, Items.IndexOf(stackable)));

            return(true);
        }
Exemplo n.º 2
0
        public void Remove(Item item, int stackCount)
        {
            var index = Items.IndexOf(item);

            if (index == -1)
            {
                return;
            }

            if (item.IsStackable && item.StackCount > stackCount)
            {
                item.RemoveStack(stackCount);
                ItemStackCountChanged?.Invoke(new ItemStackCountChangedEventData(item, index));
                return;
            }

            var empty = CreateEmptyItem();

            Items[index] = empty;

            ItemRemoved?.Invoke(new ItemRemovedEventData(item, empty, index));
        }