Ejemplo n.º 1
0
        public void DropSelected()
        {
            if (_currentlySelectedLocation == EquipLocation.None)
            {
                return;
            }

            //Gets the item
            EquipableItem item = GetItemInSlot(_currentlySelectedLocation);

            //Drops the item
            GameObject.FindGameObjectWithTag("Player").GetComponent <ItemDropper>().DropItem(item, 1);

            //Closes the tooltip
            ItemTooltip tooltip = GameObject.FindObjectOfType <ItemTooltip>();

            if (tooltip)
            {
                tooltip.Close();
            }

            //Removes the item
            RemoveItem(_currentlySelectedLocation);

            //Sets the selected to none
            _currentlySelectedLocation = EquipLocation.None;
        }
Ejemplo n.º 2
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 override void Use(GameObject user, int index)
        {
            //Gets the equipment
            Equipment equipment = user.GetComponent <Equipment>();

            //Gets the item in the slot
            EquipableItem item = equipment.GetItemInSlot(_allowedEquipLocation);

            //Adds the item to an empty slot (if applicable)
            if (item != null)
            {
                user.GetComponent <Inventory>().AddToFirstEmptySlot(item, 1);
            }

            //Adds this item to the equipment slot
            equipment.AddItem(_allowedEquipLocation, this);
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        //Unequips an item
        public void Unequip()
        {
            if (_currentlySelectedLocation == EquipLocation.None)
            {
                return;
            }

            //Gets the item in the slot
            EquipableItem item = GetItemInSlot(_currentlySelectedLocation);

            //Removes the item
            RemoveItem(_currentlySelectedLocation);

            //Adds to first empty slot of the inventory
            GetComponent <Inventory>().AddToFirstEmptySlot(item, 1);

            //Closes the tooltip
            FindObjectOfType <ItemTooltip>().Close();

            //Sets the seleected location to none
            _currentlySelectedLocation = EquipLocation.None;
        }