예제 #1
0
    private Item GetItem(ItemData itemData)
    {
        string name = itemData.name;

        ItemData.Type type = itemData.type;

        switch (type)
        {
        case ItemData.Type.Active:
            foreach (ActiveItem item in activeItemsList)
            {
                if (name.Equals(item.name))
                {
                    return(item);
                }
            }
            Debug.LogError("Item not found");
            return(null);

        case ItemData.Type.Passive:
            foreach (PassiveItem item in passiveItemsList)
            {
                if (name.Equals(item.name))
                {
                    return(item);
                }
            }
            Debug.LogError("Item not found");
            return(null);

        default:
            Debug.LogError("No items of type " + type.ToString());
            return(null);
        }
    }
예제 #2
0
    public bool SellItem(ItemData.Type itemType)
    {
        var slotContainingItem = _sellSlots.FirstOrDefault(s => {
            if (s.Content == null)
            {
                return(false);
            }
            return(s.Content.Type == itemType);
        });

        if (slotContainingItem == null)
        {
            Debug.LogWarningFormat("Cannot sell item of type '{0}' because it is not in the sell slots.", itemType.ToString());
            return(false);
        }

        slotContainingItem.Clear();
        return(true);
    }