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); }
public int Check(CatalogItemRef catalogItem) { InventoryItem item; if (this.TryFind(catalogItem, out item)) { return(item.amount); } return(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); }
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); }
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); }
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); } } } }