Example #1
0
        public void AddItem(EquipLocation slot, EquipableItem item)
        {
            //Add the item to a slot
            Debug.Assert(item.GetAllowedEquipLocation() == slot);

            _equippedItems[slot] = item;

            EquipmentUpdated?.Invoke();
        }
        public void EquipItem()
        {
            //When currentSelectedSlot is -1 it means no slot is selected
            if (_currentSelectedSlot == -1)
            {
                return;
            }

            EquipableItem item = _slots[_currentSelectedSlot].item as EquipableItem;

            if (!item)
            {
                return;
            }

            Equipment equipment = GetComponent <Equipment>();

            int result = equipment.GetIndexOfType(item.GetAllowedEquipLocation());

            //Get the currently equipped item if it exists
            InventoryItem newItem = null;

            if (result > 0)
            {
                newItem = equipment.GetItemInSlot(item.GetAllowedEquipLocation());
            }

            equipment.AddItem(item.GetAllowedEquipLocation(), item);
            RemoveFromSlot(_currentSelectedSlot, 1);

            //Equip the old equipped item if there was a item equipped
            if (newItem != null)
            {
                AddToFirstEmptySlot(newItem, 1);
            }

            InventorySlotUI[] ui;

            //Change currentSelectedSlot back to non-selected
            _currentSelectedSlot = -1;
        }