/// <summary> /// Triggers the use and potential consumption of the item passed in parameter. You can also specify the item's slot (optional) and index. /// </summary> /// <param name="item">Item.</param> /// <param name="slot">Slot.</param> /// <param name="index">Index.</param> public virtual bool UseItem(InventoryItem item, int index, InventorySlot slot = null) { if (InventoryItem.IsNull(item)) { MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.Error, slot, this.name, null, 0, index)); return(false); } if (!item.Usable) { return(false); } item.Use(); // remove 1 from quantity RemoveItem(index, 1); MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.ItemUsed, slot, this.name, item, 0, index)); return(true); }
/// <summary> /// Triggers the use and potential consumption of the item passed in parameter. You can also specify the item's slot (optional) and index. /// </summary> /// <param name="item">Item.</param> /// <param name="slot">Slot.</param> /// <param name="index">Index.</param> public virtual bool UseItem(InventoryItem item, int index, InventorySlot slot = null) { if (InventoryItem.IsNull(item)) { MMInventoryEvent.Trigger(MMInventoryEventType.Error, slot, this.name, null, 0, index); return(false); } if (!item.IsUsable) { return(false); } if (item.Use()) { // remove 1 from quantity MMInventoryEvent.Trigger(MMInventoryEventType.ItemUsed, slot, this.name, item.Copy(), 0, index); RemoveItem(index, 1); } return(true); }