Пример #1
0
    void Update()
    {
        popupSystem.UpdateCustomerHappiness(happiness);

        if (isWaiting)
        {
            if (waitingTimer < waitingMaximum)
            {
                waitingTimer += Time.deltaTime;
                if (waitingTimer >= 0.5 * waitingMaximum)
                {
                    happiness -= happinessLossRate * Time.deltaTime;
                }
            }
            else
            {
                if (currentState != CustomerState.SEATING)
                {
                    // Debug.Log("Kunde hat zu lang gewartet");
                    happiness    = Random.Range(0f, 33f);
                    currentState = CustomerState.LEAVE;
                    GamePlaySystem.Instance.LeavingCustomer(gameObject);
                    isWaiting   = false;
                    destination = null;
                    popupSystem.CreatePopup(1);
                    CalculateHappiness();
                }
                else
                {
                    NextState();
                    atDestination = false;
                    destination   = null;
                    isWaiting     = false;
                }
            }
        }

        if (drinkTimer > 0)
        {
            if (currentState == CustomerState.CONSUMING)
            {
                if (actionTimer > 0)
                {
                    actionTimer -= Time.deltaTime;
                }
                else
                {
                    if (!atDestination)
                    {
                        if (destination == null)
                        {
                            SetNewDestination();
                        }
                        else
                        {
                            GoToDestination();
                        }
                    }
                }

                if (!atDestination)
                {
                    if (destination == null)
                    {
                        drinkTimer -= Time.deltaTime;
                        happiness  -= happinessLossRate * Time.deltaTime;
                    }
                    else
                    {
                        if (pathTries >= 1)
                        {
                            drinkTimer -= Time.deltaTime;
                            happiness  -= happinessLossRate * Time.deltaTime;
                        }
                    }
                }
                else
                {
                    drinkTimer -= Time.deltaTime;
                }
            }
        }
        else
        {
            if (actionTimer > 0)
            {
                actionTimer -= Time.deltaTime;
            }
            else
            {
                if (currentState == CustomerState.CONSUMING)
                {
                    atDestination = true;
                }
                if (atDestination)
                {
                    NextState();
                }
                else
                {
                    if (destination == null)
                    {
                        SetNewDestination();
                    }
                    else
                    {
                        GoToDestination();
                    }
                }
            }
        }
    }