// Equips the item at the specified slot public virtual void EquipItem(InventoryItem item, int index, InventorySlot slot = null) { if (InventoryType == Inventory.InventoryTypes.Main) { InventoryItem oldItem = null; if (InventoryItem.IsNull(item)) { InventoryEvent.Trigger(InventoryEventType.Error, slot, this.name, null, 0, index); return; } // if the object is not equipable, we do nothing and exit if (!item.IsEquippable) { return; } // if a target equipment inventory is not set, we do nothing and exit if (item.TargetEquipmentInventory == null) { Debug.LogWarning("InventoryEngine Warning : " + Content[index].ItemName + "'s target equipment inventory couldn't be found."); return; } // if the object can't be moved, we play an error sound and exit if (!item.CanMoveObject) { InventoryEvent.Trigger(InventoryEventType.Error, slot, this.name, null, 0, index); return; } // Call the equip method of the item if (!item.Equip()) { return; } // if this is a mono slot inventory, we prepare to swap if (item.TargetEquipmentInventory.Content.Length == 1) { if (!InventoryItem.IsNull(item.TargetEquipmentInventory.Content[0])) { if ( (item.CanSwapObject) && (item.TargetEquipmentInventory.Content[0].CanMoveObject) && (item.TargetEquipmentInventory.Content[0].CanSwapObject) ) { // Store the item in the equipment inventory oldItem = item.TargetEquipmentInventory.Content[0].Copy(); item.TargetEquipmentInventory.EmptyInventory(); } } } // Add one to the target equipment inventory item.TargetEquipmentInventory.AddItem(item.Copy(), item.Quantity); // remove 1 from quantity RemoveItem(index, item.Quantity); if (oldItem != null) { oldItem.Swap(); AddItem(oldItem, oldItem.Quantity); } InventoryEvent.Trigger(InventoryEventType.ItemEquipped, slot, this.name, item, item.Quantity, index); } }
/// <summary> /// Sets the currently selected slot /// </summary> /// <param name="slot">Slot.</param> public virtual void SetCurrentlySelectedSlot(InventorySlot slot) { _currentlySelectedSlot = slot; }