// Handles equipping via right click from inventory public int TryAddItem(InventoryItem item) { // Check if it's an equipable item EquipableItem equipableItem = item as EquipableItem; if (equipableItem == null) { return(-1); } // Get location and check number of slots. If 1, add or swap items EquipLocation equipLocation = equipableItem.GetAllowedEquipLocation(); if (!equippedItems.ContainsKey(equipLocation)) { return(-1); } if (equippedItems[equipLocation].Length == 1) { return(0); } // Otherwise check for empty slot. Don't swap if all slots for equip type are full int index = FindEmptySlot(equipLocation); if (index >= 0) { return(index); } return(-1); }
/// <summary> /// Add an item to the given equip location. Do not attempt to equip to /// an incompatible slot. /// </summary> public void AddItem(EquipLocation slot, EquipableItem item, int index, object state = null) { Debug.Assert(item.GetAllowedEquipLocation() == slot); equippedItems[slot][index] = item; AddEquipmentStats(item); if (state != null) { equippedItems[slot][index].SetModifiers(state); } if (equipmentUpdated != null) { equipmentUpdated(); equipmentEffectsUpdated.Invoke(); } }