Ejemplo n.º 1
0
    public IEnumerator BurnProcessing(Resipe myResipe, MachineSlot mySlot)
    {
        float ttimer = myResipe.timeToConvert;

        mySlot.fillImage.fillAmount = 1;
        StartCoroutine(EcoEffect(myResipe.timeToConvert / 2));

        while (mySlot.fillImage.fillAmount >= 0.01f)
        {
            if (isTurnedOn == true)
            {
                EcoManager.instance.AddPollution(Mathf.RoundToInt(PollutionToAdd * (ttimer / myResipe.timeToConvert)));
                ttimer -= Time.deltaTime;
                EcoManager.instance.AddPollution(-Mathf.RoundToInt(PollutionToAdd * (ttimer / myResipe.timeToConvert)));
                if (Interactor.instance.myCraftingMachine == this)
                {
                    if (ttimer <= 0.01f)
                    {
                        mySlot.fillImage.fillAmount = 0;
                    }
                    else
                    {
                        mySlot.fillImage.fillAmount = ttimer / myResipe.timeToConvert;
                    }
                }
            }
            yield return(null);
        }

        for (int x = 0; x < productFuelSlots.Count; x++)
        {
            if (productFuelSlots[x] == null)
            {
                productFuelSlots[x] = Instantiate(burnSlotResipe.product);
                MachineSlot m = Interactor.instance.GetMachineSlot(true, x);
                if (Interactor.instance.myCraftingMachine == this)
                {
                    m.SetItem(burnSlotResipe.product);
                    Interactor.instance.burnSlot.RemoveItem();
                }
                StartCoroutine(Processing(m));
                burnSlot = null;
                mySlot.fillImage.fillAmount = 1;
                break;
            }
            else if (x == productFuelSlots.Count)
            {
                TurnOff();
            }
        }
        CheckResipe();
    }
Ejemplo n.º 2
0
    public void CheckResipe()
    {
        if (needsFuel == true && CheckFuelResipe() == false)
        {
            if (isTurnedOn == true)
            {
                TurnOff();
            }
            return;
        }
        else if (isTurnedOn == false)
        {
            return;
        }

        for (int i = 0; i < craftSlots.Count; i++)
        {
            for (int ii = 0; ii < validItems.Count; ii++)
            {
                if (craftSlots[i] != null && craftSlots[i].itemName == validItems[ii].ingredient.itemName)
                {
                    for (int x = 0; x < productSlots.Count; x++)
                    {
                        if (productSlots[x] == null)
                        {
                            productSlots[x] = Instantiate(validItems[ii].product);
                            MachineSlot r = Interactor.instance.GetMachineSlot(false, i);
                            r.RemoveItem();
                            craftSlots[i] = null;

                            MachineSlot m = Interactor.instance.GetMachineSlot(false, x);
                            StartCoroutine(Processing(validItems[ii], m));

                            if (Interactor.instance.myCraftingMachine == this)
                            {
                                m.SetItem(Instantiate(validItems[ii].product));
                                Interactor.instance.craftSlots[i].RemoveItem();
                            }
                            break;
                        }
                        else if (x == productSlots.Count - 1)
                        {
                            return;
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 3
0
 bool CheckFuelResipe()
 {
     if (burnSlot != null)
     {
         return(true);
     }
     for (int i = 0; i < craftFuelSlots.Count; i++)
     {
         for (int ii = 0; ii < validFuelItems.Count; ii++)
         {
             if (craftFuelSlots[i] != null && craftFuelSlots[i].itemName == validFuelItems[ii].ingredient.itemName)
             {
                 for (int z = 0; z < productFuelSlots.Count; z++)
                 {
                     if (productFuelSlots[z] == null && burnSlot == null)
                     {
                         if (burnSlot == null)
                         {
                             burnSlot          = Instantiate(craftFuelSlots[i]);
                             craftFuelSlots[i] = null;
                             burnSlotResipe    = validFuelItems[ii];
                             MachineSlot m = Interactor.instance.burnSlot;
                             StartCoroutine(BurnProcessing(burnSlotResipe, m));
                             if (Interactor.instance.myCraftingMachine == this)
                             {
                                 m.SetItem(Instantiate(validFuelItems[ii].ingredient));
                                 Interactor.instance.craftFuelSlots[i].RemoveItem();
                             }
                             return(true);
                         }
                     }
                 }
             }
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
    public void ChangeInteractor(Machine newMachine)
    {
        myMachine = newMachine;

        machineImage.sprite = myMachine.machineImage;
        machineName.text    = myMachine.machineName;

        Basic.SetActive(false);
        crafter.SetActive(false);
        storageUI.SetActive(false);

        if (myMachine.GetType() == typeof(CraftMachine))
        {
            myCraftingMachine = ((CraftMachine)newMachine);
            crafter.SetActive(true);
            crafterMachineUseImage.sprite = myMachine.machineImage;
            startText.text = myCraftingMachine.StartText;

            for (int i = 0; i < craftSlots.Count; i++)
            {
                if (myCraftingMachine.craftSlots[craftSlots[i].myIndex] != null)
                {
                    craftSlots[i].SetItem(myCraftingMachine.craftSlots[craftSlots[i].myIndex]);
                }
                else
                {
                    craftSlots[i].RemoveItem();
                }
            }

            for (int i = 0; i < productSlots.Count; i++)
            {
                if (myCraftingMachine.productSlots[productSlots[i].myIndex] != null)
                {
                    productSlots[i].SetItem(myCraftingMachine.productSlots[productSlots[i].myIndex]);
                    productSlots[i].fillImage.fillAmount = 1;
                }
                else
                {
                    productSlots[i].RemoveItem();
                    productSlots[i].fillImage.fillAmount = 0;
                }
            }

            if (myCraftingMachine.needsFuel == true)
            {
                for (int i = 0; i < craftFuelSlots.Count; i++)
                {
                    if (myCraftingMachine.craftFuelSlots[craftFuelSlots[i].myIndex] != null)
                    {
                        craftFuelSlots[i].SetItem(myCraftingMachine.craftFuelSlots[craftFuelSlots[i].myIndex]);
                    }
                    else
                    {
                        craftFuelSlots[i].RemoveItem();
                    }
                }

                burnSlot.SetItem(myCraftingMachine.burnSlot);
                burnSlot.fillImage.fillAmount = 1;

                for (int i = 0; i < productFuelSlots.Count; i++)
                {
                    if (myCraftingMachine.productFuelSlots[productFuelSlots[i].myIndex] != null)
                    {
                        productFuelSlots[i].SetItem(myCraftingMachine.productFuelSlots[productFuelSlots[i].myIndex]);
                        productFuelSlots[i].fillImage.fillAmount = 1;
                    }
                    else
                    {
                        productFuelSlots[i].RemoveItem();
                        productSlots[i].fillImage.fillAmount = 0;
                    }
                }
                fuelForCrafting.SetActive(true);
            }
            else
            {
                fuelForCrafting.SetActive(false);
            }
        }
        else if (myMachine.GetType() == typeof(Storage))
        {
            myStorage = ((Storage)newMachine);
            UpdateStorage();
            storageUI.SetActive(true);
        }
        else
        {
            Basic.SetActive(true);
            basicMachineUseImage.sprite = myMachine.machineImage;
        }
    }