示例#1
0
        /// <summary>
        /// Remove items from the inventory.
        /// </summary>
        /// <param name="itemType">The type of item to remove.</param>
        /// <param name="amount">The amount of the type of item to remove.</param>
        /// <returns>If the item has been removed.</returns>
        public bool RemoveItem(ItemType itemType, int amount)
        {
            //Check if inventory has the items
            if (CountItem(itemType) < amount)
            {
                return(false);
            }

            //Remove items from the inventory
            items[itemType] -= amount;

            //Remove weight from the inventory
            Volume -= ItemLibrary.GetVolume(itemType) * amount;

            return(true);
        }
示例#2
0
        /// <summary>
        /// Add items to the inventory.
        /// </summary>
        /// <param name="itemType">The type of item to add.</param>
        /// <param name="amount">The amount of the type of item to add.</param>
        /// <returns>If the item has been added.</returns>
        public bool AddItem(ItemType itemType, int amount)
        {
            float addedWeight = ItemLibrary.GetVolume(itemType) * amount;

            //Check if there is enough space
            if (addedWeight + Volume > MaxVolume)
            {
                return(false);
            }

            //Add items to the inventory
            if (!items.ContainsKey(itemType))
            {
                items.Add(itemType, 0);
            }
            items[itemType] += amount;

            //Add weight to the inventory
            Volume += addedWeight;

            return(true);
        }