Esempio n. 1
0
    // When item looted by player, trigger this
    public bool AddItemToSlot(ItemDatabase item)
    {
        foreach (GameObject slot in AllInventorySlots)
        {
            // get all the slots
            SlotManager temp = slot.GetComponent <SlotManager>();

            // if the slot is occupied
            if (!temp.SlotStackIsEmpty)
            {
                // if the item in the slot is the same as looted
                if (temp.CurrentItemOnSlot.ItemName == item.ItemName)
                {
                    // and slot is not full yet
                    if (!temp.SlotNotStackable)
                    {
                        // add item into the slot
                        temp.AddItemToSlotStack(item);
                        return(true);
                    }
                }
            }
            else // slot is empty
            {
                // put item in new empty slot
                PlaceIntoEmptySlot(item);
                return(true);
            }
        }

        return(false);
    }
Esempio n. 2
0
    // Run through all the slots to check if it is empty
    // If so, add item into new empty slot
    private bool PlaceIntoEmptySlot(ItemDatabase item)
    {
        // if there is still empty slot left
        if (_emptySlots > 0)
        {
            foreach (GameObject slot in AllInventorySlots)
            {
                SlotManager temp = slot.GetComponent <SlotManager>();

                // if slot stack is empty
                if (temp.SlotStackIsEmpty)
                {
                    // add item into the new slot
                    temp.AddItemToSlotStack(item);
                    // minus away an empty slot
                    _emptySlots--;
                    return(true);
                }
            }
        }

        return(false);
    }