Exemple #1
0
    public void NextDay()
    {
        int orderRev   = 0;
        int veggieCost = GameObject.FindObjectOfType <BuyMenu2>().TotalOrderCost;

        var orderSupplyMenu = GameObject.Find("OrderSupplyMenu").gameObject.GetComponent <BuyMenu2>();

        _supplyTotalOrder = orderSupplyMenu._totalOrder;



        // BuyMoreSupply(_supplyTotalOrder);

        int active = -1;

        for (int j = 0; j < Orders.Count; j++)
        {
            Order o = Orders[j];
            if (o.active)
            {
                active = j;
                //if the player has hit fulfill and has enough inventory
                if (o.Fulfilled)
                {
                    Money    += o.value;
                    orderRev += o.value;
                    GenerateNewOrder(o);
                }
                else
                {
                    o.FulfillFail = false;
                    if (o.daysRemaining == 0)
                    {
                        GameObject.Find("FailedOrder").GetComponent <AudioSource>().Play();
                        failed += 1;
                        GenerateNewOrder(o);
                    }
                    else
                    {
                        o.decrementDays();
                    }
                }
            }
        }

        orderSupplyMenu.NextDayReset();

        // I stuck UpdateInventoryReceipt logic in here for now
        foreach (string s in SupportedProducts)
        {
            // sets some variables
            var stageVal  = _supply.StagedItems[s];
            var boughtVal = _supplyTotalOrder[s];

            // removes the staged order(s) from supply
            _inventoryRecap = GameObject.Find(s + "Shipped");
            _inventoryRecap.GetComponent <Text>().text = stageVal.ToString();
            _supply.RemoveStaged(s);

            // removes the spoiled items from remaining supply
            var spoiledVal = _supply.Spoil(s, Day);
            _inventoryRecap = GameObject.Find(s + "Spoiled");
            _inventoryRecap.GetComponent <Text>().text = spoiledVal.ToString();
            _supply.RemoveStorage(s, spoiledVal);

            // adds bought items to supply
            _inventoryRecap = GameObject.Find(s + "Bought");
            _inventoryRecap.GetComponent <Text>().text = boughtVal.ToString();
            //_supply.RemoveOrdered(s);
            BuyMoreSupply(_supplyTotalOrder, s);

            _supplyTotalOrder[s] = 0;

            // updates net totals
            var totalVeg = boughtVal - stageVal - spoiledVal;
            _storage.UpdateInventoryReceiptNet(s, totalVeg.ToString());
        }

        Day += 1;
        if (Day > 0)
        {
            _supply.spoilRate = .2;
        }
        if (OrderCount < 5)
        {
            int v = Money;
            foreach (string s in SupportedProducts)
            {
                v += _supply.StoredItems[s] * buyPrices[s];
            }
            float calculatedOrderCount = (Day * 60 + v) / 730;
            if (calculatedOrderCount > OrderCount)
            {
                OrderCount = (int)calculatedOrderCount;
            }
            if (OrderCount > 5)
            {
                OrderCount = 5;
            }
        }

        int i = 1;

        while (OrderCount > active + i)
        {
            GenerateNewOrder(Orders[active + i]);
            i++;
        }


        RandomEventGenerator();
        _panels.UpdateDay();
        _panels.UpdateReceipt(orderRev, veggieCost);
        _panels.UpdateMoney();
        _panels.UpdateSupply();
        _panels.UpdateLives();
        _panels.UpdateProjected();
        UpdateAllSliders();

        GameObject.Find("ChachingSound").GetComponent <AudioSource>().Play();

        if (Day > 15)
        {
            WinGame();
        }

        if (failed > 2)
        {
            LoseGame();
        }
    }