Esempio n. 1
0
        /// <summary>
        /// Check if an item has at least a certain quantity
        /// </summary>
        /// <param name="amount">The amount to check</param>
        /// <returns>If the item has the required quantity</returns>
        /// <exception cref="ArgumentException">Thrown if the amount is less than one</exception>
        public bool HasQuantity(int amount)
        {
            if (amount < 1)
            {
                throw new ArgumentException("Amount must be at least 1", nameof(amount));
            }

            if (amount == 1)
            {
                return(true);
            }

            Stackable stackable = Stack;

            if (stackable == null)
            {
                return(false);
            }

            return(stackable.amountInStack >= amount);
        }
Esempio n. 2
0
        /// <summary>
        /// Consumes a certain amount of this item
        /// </summary>
        /// <param name="amount">The amount to consume</param>
        public void ConsumeQuantity(int amount)
        {
            if (!HasQuantity(amount))
            {
                return;
            }

            Stackable stackable = Stack;

            if (stackable != null)
            {
                stackable.amountInStack -= amount;
                if (stackable.amountInStack <= 0)
                {
                    Destroy();
                }
            }
            else
            {
                Destroy();
            }
        }