Beispiel #1
0
        public InventoryItem Find(CatalogItemRef catalogItem)
        {
            InventoryItem item;

            if (!this.TryFind(catalogItem, out item))
            {
                throw new ArgumentException(string.Format("An item with the name {0} could not be found in the inventory", name));
            }

            return(item);
        }
Beispiel #2
0
        public int Check(CatalogItemRef catalogItem)
        {
            InventoryItem item;

            if (this.TryFind(catalogItem, out item))
            {
                return(item.amount);
            }

            return(0);
        }
Beispiel #3
0
        public int Take(CatalogItemRef catalogItem, int amount)
        {
            InventoryItem item;
            int           take = 0;

            if (this.TryFind(catalogItem, out item))
            {
                take         = Math.Min(amount, item.amount);
                item.amount -= take;
            }

            return(take);
        }
Beispiel #4
0
        public bool TryFind(CatalogItemRef catalogItem, out InventoryItem item)
        {
            for (int i = 0; i < this.items.Count; i++)
            {
                if (this.items[i].catalogItem == catalogItem)
                {
                    item = this.items[i];
                    return(true);
                }
            }

            item = default(InventoryItem);
            return(false);
        }
Beispiel #5
0
        public int Add(CatalogItemRef catalogItem, int amount)
        {
            InventoryItem item;

            if (!this.TryFind(catalogItem, out item))
            {
                item = new InventoryItem {
                    catalogItem = catalogItem
                };
                this.items.Add(item);
            }

            item.amount += amount;

            return(amount);
        }
Beispiel #6
0
        public void ActivateItem(CatalogItemRef item, GameObject owner)
        {
            for (int i = 0; i < itemHandlers.Length; i++)
            {
                var entry = itemHandlers[i];
                if (entry.enabled && entry.catalogItem == item)
                {
                    var handler = entry.itemHandler as ICatalogItemHandler;

                    if (handler != null)
                    {
                        handler.ActivateItem(item, owner);
                    }
                }
            }
        }