Example #1
0
 private void Awake()
 {
     _rb         = GetComponent <Rigidbody>();
     State       = PatronState.IDLE;
     _animWalkId = Animator.StringToHash("walk");
     _animStopId = Animator.StringToHash("stop");
 }
Example #2
0
    private void Drinking()
    {
        if (_patronRigidbody.velocity != Vector3.zero)
        {
            _patronRigidbody.velocity = Vector3.zero;
        }

        if (_patronCurrentBeer._beerStateController != Beer.BeerState.Drink)
        {
            _patronCurrentBeer._beerStateController = Beer.BeerState.Drink;
        }

        if (_patronRigidbody.velocity == Vector3.zero)
        {
            _patronDrinkTimer += (1f * Time.deltaTime);
        }

        if (_patronDrinkTimer >= _patronDrinkTime)
        {
            _patronCurrentBeer.transform.parent     = null;
            _patronCurrentBeer._beerStateController = Beer.BeerState.ReturnToBartender;
            _patronCurrentBeer     = null;
            _patronDrinkTimer      = 0;
            _patronStateController = Patron.PatronState.Walking;
        }
    }
Example #3
0
    // Start is called before the first frame update
    void Start()
    {
        _patronStateController = Patron.PatronState.Walking;

        _patronRigidbody.velocity = Vector3.zero;

        StartCoroutine("PatronStateMachine");
    }
Example #4
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.name == "Beer(Clone)" && _patronCurrentBeer == null)
        {
            _patronCurrentBeer = other.GetComponent <Beer>();

            other.transform.parent = transform;

            _patronStateController = Patron.PatronState.Sliding;
        }
    }
Example #5
0
    public void SwitchState(PatronState state)
    {
        //Call the OnExit function of the current state.
        patronState?.OnStateExit();
        //Change our current state to the state we are swapping to.
        patronState = state;
        //Call the current states OnStateEnter function.
        patronState?.OnStateEnter();

        stateDebugText.text = patronState.stateName;
        Debug.Log(patronState.stateName);
    }
Example #6
0
    private void Sliding()
    {
        if (_patronRigidbody.velocity != (transform.right * -1) * _patronSlideSpeed)
        {
            _patronRigidbody.velocity = (transform.right * -1) * _patronSlideSpeed;
        }

        _patronSlideTimer += (1f * Time.deltaTime);

        if (_patronSlideTimer >= _patronSlideTime)
        {
            _patronStateController = Patron.PatronState.Drinking;
            _patronSlideTimer      = 0;
        }
    }
Example #7
0
    private void Idle()
    {
        if (_patronRigidbody.velocity != Vector3.zero)
        {
            _patronRigidbody.velocity = Vector3.zero;
        }

        _patronWalkingTimer += (1f * Time.deltaTime);

        if (_patronWalkingTimer >= _patronWalkingDelay)
        {
            _patronStateController = Patron.PatronState.Walking;
            _patronWalkingTimer    = 0;
        }
    }
Example #8
0
    private void Walking()
    {
        if (_patronRigidbody.velocity == Vector3.zero)
        {
            _patronRigidbody.velocity = transform.right * _patronWalkSpeed;
        }

        _patronWalkingTimer += (1f * Time.deltaTime);

        if (_patronWalkingTimer >= _patronWalkingDelay)
        {
            _patronStateController = Patron.PatronState.Idle;
            _patronWalkingTimer    = 0;
        }
    }
Example #9
0
    private IEnumerator PatronLoop()
    {
        while (_completedTasks < PatronSettings.DesiredTasks)
        {
            _fulfilled = false;

            // --- IDLE STATE ---

            State = PatronState.IDLE;
            for (int i = 0; i < PatronSettings.IdleLocations; i++)
            {
                var location = PickIdleLocation();
                Agent.enabled = true;
                Agent.SetDestination(location);
                Animator.SetTrigger("walk");
                yield return(new WaitUntil(ReachedDestination));

                Agent.enabled = false;
                Animator.SetTrigger("stop");
                yield return(new WaitForSeconds(Random.Range(PatronSettings.IdleTime.x, PatronSettings.IdleTime.y)));
            }

            // --- IDLE OVER ---

            _desiredTask  = PickTask2();
            State         = PatronState.WALKING;
            Agent.enabled = true;
            Agent.SetDestination(_desiredTask.Location.position);
            Animator.SetTrigger("walk");
            yield return(new WaitUntil(ReachedDestination));

            // --- WAIT STATE ---

            State = PatronState.WAITING;
            // play animation
            Agent.enabled   = false;
            _rb.velocity    = Vector3.zero;
            _rb.isKinematic = true;
            transform.SetPositionAndRotation(_desiredTask.Location.position, _desiredTask.Location.rotation);
            Animator.SetTrigger(_desiredTask.TaskLocation.Task.PatronString);
            // init variables for loop
            float patienceRemaining = PatronSettings.Patience;
            float fulfillment       = 0f;

            // reset Overhead UI
            PatronUI.SetPatienceActive(true);
            PatronUI.SetPatience(0f);
            PatronUI.SetFulfillmentActive(true);
            PatronUI.SetFulfillment(0f);

            while (patienceRemaining > 0f)
            {
                // set Overhead UI values
                PatronUI.SetPatience(Mathf.InverseLerp(PatronSettings.Patience, 0, patienceRemaining));
                PatronUI.SetFulfillment(Mathf.InverseLerp(0, _desiredTask.TaskLocation.Task.RequiredTime, fulfillment));

                bool fulfilling = _desiredTask.TaskLocation.Performing >= _desiredTask.TaskLocation.Task.RequiredPlayerCount &&
                                  (_desiredTask.TaskLocation.Task.RequiresPot ? _desiredTask.TaskLocation.UseLeft > 0f : true);
                if (fulfilling)
                {
                    fulfillment += Time.deltaTime;
                    if (fulfillment >= _desiredTask.TaskLocation.Task.RequiredTime)
                    {
                        _fulfilled = true;
                        _completedTasks++;
                        //play Sound
                        AudioSource.clip = HappyClips[Random.Range(0, HappyClips.Length)];
                        AudioSource.Play();

                        GameEvents.TaskFulfilled?.Invoke(this);
                        GameEvents.AddMoney(1);
                        break;
                    }
                }
                patienceRemaining -= Time.deltaTime;
                yield return(null);
            }

            // close Overhead UI
            PatronUI.SetPatienceActive(false);
            PatronUI.SetFulfillmentActive(false);

            // get off position
            if (_desiredTask.ExitLocation != null)
            {
                transform.SetPositionAndRotation(_desiredTask.ExitLocation.position, _desiredTask.ExitLocation.rotation);
            }
            _rb.isKinematic = false;

            _desiredTask.Reserved = false;
            _desiredTask          = null;

            // --- WAIT OVER ---

            if (!_fulfilled)
            {
                //play Sound
                AudioSource.clip = GrumpyClips[Random.Range(0, GrumpyClips.Length)];
                AudioSource.Play();
                break;
            }
        }
        Agent.enabled = true;
        Agent.SetDestination(_spawnLocation);
        Animator.SetTrigger("walk");
        yield return(new WaitUntil(ReachedDestination));

        if (_fulfilled)
        {
            // leave fulfilled
            GameEvents.AddMoney(1);
            //play Sound
            AudioSource.clip = HappyClips[Random.Range(0, HappyClips.Length)];
            AudioSource.Play();
        }
        else
        {
            //play Sound
            AudioSource.clip = GrumpyClips[Random.Range(0, GrumpyClips.Length)];
            AudioSource.Play();
        }

        GameEvents.PatronLeft?.Invoke(this, _fulfilled);
        Destroy(gameObject, .5f);
    }