Example #1
0
        private async Task <bool> Moving()
        {
            var distanceToDestination = AdvDia.MyPosition.Distance(_destination);

            if (_destination != Vector3.Zero)
            {
                if (_distance != 0 && distanceToDestination <= _distance)
                {
                    Navigator.PlayerMover.MoveStop();
                    MoveResult = MoveResult.ReachedDestination;
                }
                else
                {
                    if (_mover == Mover.StraightLine && PluginTime.ReadyToUse(_lastRaywalkCheck, 200))
                    {
                        if (!NavigationGrid.Instance.CanRayWalk(AdvDia.MyPosition, _destination))
                        {
                            _mover = Mover.Navigator;
                        }
                        _lastRaywalkCheck = PluginTime.CurrentMillisecond;
                    }
                    switch (_mover)
                    {
                    case Mover.StraightLine:
                        Navigator.PlayerMover.MoveTowards(_destination);
                        MoveResult = MoveResult.Moved;
                        return(false);

                    case Mover.Navigator:
                        MoveResult = await Navigator.MoveTo(_destination);

                        break;
                    }
                }
                switch (MoveResult)
                {
                case MoveResult.ReachedDestination:
                    if ((_distance != 0 && distanceToDestination <= _distance) || distanceToDestination <= 7f)
                    {
                        Logger.Debug("[Navigation] Completed (Distance to destination: {0})", distanceToDestination);
                        State = States.Completed;
                    }
                    else
                    {
                        _deathGate = ActorFinder.FindNearestDeathGate(_deathGateIgnoreList);
                        if (_deathGate != null)
                        {
                            State = States.MovingToDeathGate;
                        }
                        else
                        {
                            State      = States.Failed;
                            MoveResult = MoveResult.Failed;
                        }
                    }
                    return(false);

                case MoveResult.Failed:
                    break;

                case MoveResult.PathGenerationFailed:

                    var navProvider = Navigator.NavigationProvider as DefaultNavigationProvider;
                    if (navProvider != null)
                    {
                        Logger.Debug("[Navigation] Path generation failed.");
                        navProvider.Clear();
                    }
                    if (distanceToDestination < 100 &&
                        NavigationGrid.Instance.CanRayWalk(AdvDia.MyPosition, _destination))
                    {
                        _mover = Mover.StraightLine;
                        return(false);
                    }
                    State = States.Failed;
                    return(false);

                case MoveResult.UnstuckAttempt:
                    if (_unstuckAttemps > 1)
                    {
                        State = States.Failed;
                        return(false);
                    }
                    _unstuckAttemps++;
                    Logger.Debug("[Navigation] Unstuck attempt #{0}", _unstuckAttemps);
                    break;

                case MoveResult.PathGenerated:
                case MoveResult.Moved:
                    break;

                case MoveResult.PathGenerating:
                    if (_pathGenetionTimer.IsFinished)
                    {
                        Logger.Info("Patiently waiting for the Navigation Server");
                        _pathGenetionTimer.Reset();
                    }
                    break;
                }
                return(false);
            }
            State = States.Completed;
            return(false);
        }
Example #2
0
        private async Task <bool> MovingToDeathGate()
        {
            if (_deathGate != null && _deathGate.IsFullyValid())
            {
                if (AdvDia.MyPosition.Distance(_deathGate.Position) <= 7f)
                {
                    Navigator.PlayerMover.MoveStop();
                    MoveResult = MoveResult.ReachedDestination;
                }
                else
                {
                    _deathGate = ActorFinder.FindNearestDeathGate(_deathGateIgnoreList);
                    if (_deathGate == null)
                    {
                        MoveResult = MoveResult.Failed;
                        State      = States.Failed;
                        return(false);
                    }
                    MoveResult = await CommonCoroutines.MoveTo(_deathGate.Position);
                }
                switch (MoveResult)
                {
                case MoveResult.ReachedDestination:
                    var distance = AdvDia.MyPosition.Distance(_deathGate.Position);
                    if (distance <= 7f)
                    {
                        _interactionCoroutine = new InteractionCoroutine(_deathGate.ActorSnoId, new TimeSpan(0, 0, 1), new TimeSpan(0, 0, 3));
                        State = States.InteractingWithDeathGate;
                    }
                    else
                    {
                        _deathGateIgnoreList.Add(_deathGate.ACDId);
                        State = States.Moving;
                    }
                    break;

                case MoveResult.Failed:
                case MoveResult.PathGenerationFailed:
                    State = States.Failed;
                    break;

                case MoveResult.PathGenerated:
                    break;

                case MoveResult.UnstuckAttempt:
                    if (_unstuckAttemps > 1)
                    {
                        State = States.Failed;
                        return(false);
                    }
                    _unstuckAttemps++;
                    Logger.Debug("[Navigation] Unstuck attempt #{0}", _unstuckAttemps);
                    break;

                case MoveResult.Moved:
                case MoveResult.PathGenerating:
                    break;
                }
                return(false);
            }
            State = States.Failed;
            return(false);
        }
 private bool Failed()
 {
     Logger.Debug("[Navigation] Navigation Error (MoveResult: {0}, Distance: {1})", MoveResult, AdvDia.MyPosition.Distance2D(_destination));
     return(true);
 }