Ejemplo n.º 1
0
    private bool Output(Recipies recipie)
    {
        int freeSlots = 4;
        //int outputSlots = 0;

        List <ItemObject> listOutput = new List <ItemObject>();

        if (recipie.output0 != null)
        {
            listOutput.Add(recipie.output0);
        }
        if (recipie.output1 != null)
        {
            listOutput.Add(recipie.output1);
        }
        if (recipie.output2 != null)
        {
            listOutput.Add(recipie.output2);
        }
        if (recipie.output3 != null)
        {
            listOutput.Add(recipie.output3);
        }

        List <ItemObject> listInv2 = new List <ItemObject>();
        List <ItemObject> listInv  = new List <ItemObject>();

        for (int i = 0; i < 4; i++)
        {
            if (inventoryOutput.GetSlots[i].item.Id != -1)
            {
                freeSlots--;
            }
            listInv.Add(inventoryOutput.GetSlots[i].ItemObject);
            listInv2.Add(inventory.GetSlots[i].ItemObject);
        }

        if (!listInv2.Contains(recipie.input0))
        {
            return(false);
        }
        if (!listInv2.Contains(recipie.input1))
        {
            return(false);
        }
        if (!listInv2.Contains(recipie.flaskSlot))
        {
            return(false);
        }



        //Debug.Log(freeSlots);

        foreach (var i in listOutput)
        {
            if (listInv.Contains(i))
            {
                //Debug.Log("id: " + i.Id);
                freeSlots++;
            }
        }



        //Debug.Log("free slots= " +freeSlots);

        if (listOutput.Count <= freeSlots)
        {
            if (recipie.input0 != null)
            {
                inventory.ConsumeFromInventory(recipie.input0.createItem(), 1);
                inventory.GetSlots[0].UpdateSlot();
            }
            if (recipie.input1 != null)
            {
                inventory.ConsumeFromInventory(recipie.input1.createItem(), 1);
                inventory.GetSlots[1].UpdateSlot();
            }
            if (recipie.flaskSlot != null)
            {
                inventory.ConsumeFromInventory(recipie.flaskSlot.createItem(), 1);
                inventory.GetSlots[2].UpdateSlot();
            }
            AddOutput(recipie);
            return(true);
        }
        return(false);
    }