Beispiel #1
0
    /// <summary>
    /// Removes the item from the inventory
    /// </summary>
    /// <param name="itemToRemove">desired item to be removed</param>
    /// <returns>If removal was successful</returns>
    public bool RemoveItem(ItemBase itemToRemove)
    {
        ItemSlot slot = _itemSlotsMap[itemToRemove];

        // did not find the item
        if (slot == null)
        {
            return(false);
        }

        // unequiping from owner
        if (itemToRemove.properties.IsTypeEquipment())
        {
            ItemEquipment equip = (ItemEquipment)itemToRemove;
            equip.Unequip();
        }

        // remove owner reference
        itemToRemove.owner = null;

        // remove item reference
        itemRows[slot.row].items[slot.col] = null;

        // remove from map
        _itemSlotsMap.Remove(itemToRemove);

        itemToRemove.OnDisposal -= DisposeItemEventListener;

        if (OnItemRemoved != null)
        {
            OnItemRemoved(slot);
        }

        return(true);
    }
Beispiel #2
0
    /// <summary>
    /// Removes the item at the slot
    /// </summary>
    /// <param name="row"></param>
    /// <param name="col"></param>
    /// <returns>null if removal was unsuccessful</returns>
    public ItemBase RemoveItemAt(int row, int col)
    {
        // check row
        if (row >= itemRows.Length || row < 0)
        {
            return(null);
        }

        // check col
        if (col >= itemRows[row].items.Length || col < 0)
        {
            return(null);
        }

        ItemBase item = GetItem(row, col);

        // no item to remove
        if (item == null)
        {
            return(null);
        }

        // unequiping from owner
        if (item.properties.IsTypeEquipment())
        {
            ItemEquipment equip = (ItemEquipment)item;
            equip.Unequip();
        }

        // remove owner reference
        item.owner = null;

        // remove item reference
        itemRows[row].items[col] = null;

        // remove from map
        _itemSlotsMap.Remove(item);

        item.OnDisposal -= DisposeItemEventListener;

        if (OnItemRemoved != null)
        {
            OnItemRemoved(new ItemSlot(row, col));
        }

        return(item);
    }