示例#1
0
        internal void SetCurrentInventory(Inventory newInventory)
        {
            Inventory oldInventory = this.CurrentInventory;

            this.CurrentInventory = newInventory;

            if (newInventory != oldInventory && oldInventory != null)
            {
                RemovedFromInventory?.Invoke(oldInventory);
            }

            if (newInventory != oldInventory && newInventory != null)
            {
                AddedToInventory?.Invoke(newInventory);
            }
        }
示例#2
0
    /// <summary>
    /// If the inventory has the space for it, adds the item passed.
    /// </summary>
    /// <param name="item">The item passed.</param>
    /// <returns>True if the item was added, false otherwise.</returns>
    public bool Add(ItemInfo item)
    {
        if (infiniteSpace || items.Count < items.Capacity)
        {
            items.Add(item);

            // update the lists for the categories
            if (item.categories.Contains(Category.baseMaterial))
            {
                baseMaterials.Add(item);
            }

            if (item is IUsableItem)
            {
                usableItems.Add(item);
            }

            if (item.categories.Contains(Category.healing))
            {
                healingItems.Add(item);
            }

            if (item.categories.Contains(Category.ammo))
            {
                ammo.Add(item);
            }

            if (item.categories.Contains(Category.machine))
            {
                machineItems.Add(item);
            }

            AddedToInventory.Invoke(item);
            return(true);
        }

        return(false);
    }