コード例 #1
0
    private int DropItemAtIndex(int index)
    {
        if (index < 0)
        {
            throw new System.IndexOutOfRangeException($"Tried to drop item " +
                                                      $"in inventory position {index}. This is illegal.");
        }
        if (m_Inventory.Length <= index)
        {
            throw new System.IndexOutOfRangeException($"Tried to drop item " +
                                                      $"in inventory position {index} but inventory only has a capacity of " +
                                                      $"{m_Inventory.Length}.");
        }

        // Get item ID
        int itemID = m_Inventory[index];

        // If no item at this index, error
        if (itemID == Consts.NULL_ITEM_ID)
        {
            throw new System.InvalidOperationException($"No item at index {index}.");
        }

        // Otherwise, remove the item at that index
        m_Inventory[index] = Consts.NULL_ITEM_ID;
        m_ItemCount       -= 1;
        switch (index)
        {
        case m_WeaponStartingIndex:
            m_UI.ClearWeaponOneImage();
            break;
        }

        // If the item was a passive, decrement the number of passives
        if (ItemManager.IsPassiveItem(itemID))
        {
            m_NumPassives--;
        }

        return(itemID);
    }