Exemplo n.º 1
0
    /// <summary>
    /// Add Consume in inventory extension method
    /// </summary>
    protected bool AddConsInInvExtension(int id, int quantity)
    {
        bool           createNew       = false;
        XmlStorageItem xmlStorage      = new XmlStorageItem();
        List <int>     freeSlotsIndex  = GetAllFreeIndexInInventory();
        ItemConsume    tempItemConsume = GetItemConsumeById(id, false);

        //else add from xml storage item
        if (tempItemConsume == null)
        {
            if (freeSlotsIndex.Count == 0)
            {
                return(false);
            }

            tempItemConsume = xmlStorage.GetItemConsumeById(id);
            if (tempItemConsume == null)
            {
                return(false);
            }
            createNew = true;
        }

        int maxInStack = xmlStorage.GetConsumeMaxInStackById(id);

        return(AddConsInInvExtension(tempItemConsume, quantity, maxInStack, createNew, freeSlotsIndex));
    }
Exemplo n.º 2
0
    public ItemConsume GetItemConsumeById(int id, bool elseLoadFromXml)
    {
        //if item has already in inventory
        foreach (ItemConsume itemConsumeInInv in itemsConsumeInInv)
        {
            if (itemConsumeInInv.id == id)
            {
                return(itemConsumeInInv);
            }
        }

        //else add from xml storage item
        if (elseLoadFromXml)
        {
            XmlStorageItem xmlStorage = new XmlStorageItem();
            return(xmlStorage.GetItemConsumeById(id));
        }

        return(null);
    }