Beispiel #1
0
        public Boolean ContainsItem(Item item, ItemQuantity quantity)
        {
            if (!Items.ContainsKey(item))
                return quantity == 0;

            return Items[item] >= quantity;
        }
Beispiel #2
0
        public Boolean AddItem(Item item, ItemQuantity quantity)
        {
            ItemQuantity validItemQuantity = GetValidQuantity(item, quantity);

            if (validItemQuantity == 0)
                return false;

            if (!Items.ContainsKey(item))
                Items.Add(item, validItemQuantity);
            else
                Items[item] += validItemQuantity;

            return true;
        }
Beispiel #3
0
 public ItemQuantity(ItemQuantity copy)
 {
     Value = copy.Value;
 }
Beispiel #4
0
 Boolean IsFull(Item item, ItemQuantity addQuantity)
 {
     return GetQuantity(item) + addQuantity > item.MaxQuantity;
 }
Beispiel #5
0
        ItemQuantity GetValidQuantity(Item item, ItemQuantity quantity)
        {
            if (IsFull(item, quantity))
                return item.MaxQuantity - GetQuantity(item);

            return quantity;
        }
Beispiel #6
0
        public Boolean RemoveItem(Item item, ItemQuantity quantity, Boolean forcing = false)
        {
            if (quantity == 0)
                return true;

            if (!ContainsItem(item, quantity))
            {
                if (!forcing)
                    return false;

                Items[item] = new ItemQuantity(0);

                return true;
            }

            Items[item] -= quantity;

            return true;
        }