示例#1
0
        public void Continue()
        {
            if (_timeout > DateTime.Now)
            {
                // Core.Log($"WORLD PATHING REQUEST TIMED OUT Current State {_state}");
                return;
            }
            switch (_state.State)
            {
            case State.Pause:
            {
                var player = _client.GetLocalPlayerCharacterView();
                if (DateTime.Now > _stuckTimer)
                {
                    _state.Fire(Trigger.ReachedDestination);
                }


                //Core.Log($"Moving to RandomSpot {_randomSpot}");
                player.RequestMove(_randomSpot);

                break;
            }


            case State.Start:
            {
                if (_path.Count > 0)
                {
                    _state.Fire(Trigger.ApproachDestination);
                }
                else
                {
                    _state.Fire(Trigger.ReachedDestination);
                }

                break;
            }

            case State.Running:
            {
                var nextCluster    = _path[0];
                var currentCluster = _world.GetCurrentCluster();
                var player         = _client.GetLocalPlayerCharacterView();
                isMovingUpdate();
                //Core.Log($"{IsMoving}");
                if (!IsMoving)
                {
                    Core.Log("World pathing Request not moving");
                    _randomSpot = new Vector3(UnityEngine.Random.Range(-100f, 100f), 0, UnityEngine.Random.Range(-100f, 100f)) + player.transform.position;
                    _stuckTimer = DateTime.Now + TimeSpan.FromSeconds(2);
                    _state.Fire(Trigger.Stuck);
                    break;
                }

                // Core.Log("Beggining run world pathing request");
                if (currentCluster.GetIdent() != nextCluster.GetIdent())
                {
                    //Core.Log("Indent Not in next Cluster");
                    if (_exitPathingRequest != null)
                    {
                        if (_exitPathingRequest.IsRunning)
                        {
                            // Core.Log("Exit Pathing Request Running");
                            _exitPathingRequest.Continue();
                        }
                        else
                        {
                            //Core.Log("Exit Pathing Request Timed Out");
                            _timeout            = DateTime.Now + TimeSpan.FromSeconds(10);
                            _exitPathingRequest = null;
                        }

                        break;
                    }


                    player = _client.GetLocalPlayerCharacterView();
                    var exits = currentCluster.GetExits();


                    var exit         = exits.FirstOrDefault(e => e.GetDestination().GetIdent() == nextCluster.GetIdent());
                    var exitLocation = exit.GetPosition();

                    var destination = new Vector3(exitLocation.GetX(), 0, exitLocation.GetY());

                    var exitCollider = Physics.OverlapCapsule(destination - HeightDifference, destination + HeightDifference, 2f).FirstOrDefault(c => c.name.ToLowerInvariant().Equals("exit") || c.name.ToLowerInvariant().Contains("entrance"));
                    _destinationPosition = exitCollider?.transform?.position;
                    _destinationExtends  = exitCollider?.GetColliderExtents();
                    if (_destinationPosition.HasValue)
                    {
                        var temp = _destinationPosition.Value;
                        temp.y = 0;
                        _destinationPosition = temp;
                    }

                    _landscape = _client.GetLandscapeManager();
                    if (player.TryFindPath(new ClusterPathfinder(), destination, IsBlockedWithExitCheck, out List <Vector3> pathing))
                    {
                        // Core.Log("Beginning new position pathing request from world pathing request");
                        _exitPathingRequest = new PositionPathingRequest(_client.GetLocalPlayerCharacterView(), destination, pathing, false);
                    }
                }
                else
                {
                    //Core.Log("Path Point Removed");
                    _path.RemoveAt(0);
                    _exitPathingRequest = null;
                }

                if (_path.Count > 0)
                {
                    break;
                }



                _state.Fire(Trigger.ReachedDestination);
                break;
            }
            }
        }
示例#2
0
        public void Continue()
        {
            if (_timeout > DateTime.Now)
            {
                return;
            }

            switch (_state.State)
            {
            case State.Start:
            {
                if (_path.Count > 0)
                {
                    _state.Fire(Trigger.ApproachDestination);
                }
                else
                {
                    _state.Fire(Trigger.ReachedDestination);
                }

                break;
            }

            case State.Running:
            {
                var nextCluster    = _path[0];
                var currentCluster = _world.GetCurrentCluster();

                if (currentCluster.GetIdent() != nextCluster.GetIdent())
                {
                    if (_exitPathingRequest != null)
                    {
                        if (_exitPathingRequest.IsRunning)
                        {
                            _exitPathingRequest.Continue();
                        }
                        else
                        {
                            _timeout            = DateTime.Now + TimeSpan.FromSeconds(5);
                            _exitPathingRequest = null;
                        }

                        break;
                    }

                    var player = _client.GetLocalPlayerCharacterView();
                    var exits  = currentCluster.GetExits();

                    var exit         = exits.FirstOrDefault(e => e.GetDestination().GetIdent() == nextCluster.GetIdent());
                    var exitLocation = exit.GetPosition();

                    var destination = new Vector3(exitLocation.GetX(), 0, exitLocation.GetY());

                    var exitCollider = Physics.OverlapCapsule(destination - HeightDifference, destination + HeightDifference, 2f).FirstOrDefault(c => c.name.ToLowerInvariant().Equals("exit") || c.name.ToLowerInvariant().Contains("entrance"));
                    _destinationPosition = exitCollider?.transform?.position;
                    _destinationExtends  = exitCollider?.GetColliderExtents();
                    if (_destinationPosition.HasValue)
                    {
                        var temp = _destinationPosition.Value;
                        temp.y = 0;
                        _destinationPosition = temp;
                    }

                    _landscape = _client.GetLandscapeManager();
                    if (player.TryFindPath(new ClusterPathfinder(), destination, IsBlockedWithExitCheck, out List <Vector3> pathing))
                    {
                        _exitPathingRequest = new PositionPathingRequest(_client.GetLocalPlayerCharacterView(), destination, pathing, false);
                    }
                }
                else
                {
                    _path.RemoveAt(0);
                    _exitPathingRequest = null;
                }

                if (_path.Count > 0)
                {
                    break;
                }

                _state.Fire(Trigger.ReachedDestination);
                break;
            }
            }
        }