public virtual void UnEquipItem(InventoryItem item, int index, InventorySlot slot = null) { // if there's no item at this slot, we trigger an error if (InventoryItem.IsNull(item)) { MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.Error, slot, this.name, null, 0, index)); return; } // if we're not in an equipment inventory, we trigger an error if (InventoryType != InventoryTypes.Equipment) { MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.Error, slot, this.name, null, 0, index)); return; } // we trigger the unequip effect of the item item.UnEquip(); MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.ItemUnEquipped, slot, this.name, item, item.Quantity, index)); // if there's a target inventory, we'll try to add the item back to it if (item.TargetInventory != null) { // if we managed to add the item if (item.TargetInventory.AddItem(item, item.Quantity)) { DestroyItem(index); } else { // if we couldn't (inventory full for example), we drop it to the ground MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.Drop, slot, this.name, item, item.Quantity, index)); } } }
/// <summary> /// Drops the item, removing it from the inventory and potentially spawning an item on the ground near the character /// </summary> /// <param name="item">Item.</param> /// <param name="index">Index.</param> /// <param name="slot">Slot.</param> public virtual void DropItem(InventoryItem item, int index, InventorySlot slot = null) { if (InventoryItem.IsNull(item)) { MMEventManager.TriggerEvent(new MMInventoryEvent(MMInventoryEventType.Error, slot, this.name, null, 0, index)); return; } item.SpawnPrefab(); item.UnEquip(); DestroyItem(index); }
/// <summary> /// Drops the item, removing it from the inventory and potentially spawning an item on the ground near the character /// </summary> /// <param name="item">Item.</param> /// <param name="index">Index.</param> /// <param name="slot">Slot.</param> public virtual void DropItem(InventoryItem item, int index, InventorySlot slot = null) { if (InventoryItem.IsNull(item)) { MMInventoryEvent.Trigger(MMInventoryEventType.Error, slot, this.name, null, 0, index); return; } item.SpawnPrefab(); if (this.name == item.TargetEquipmentInventoryName) { if (item.UnEquip()) { DestroyItem(index); } } else { DestroyItem(index); } }