Example #1
0
        public RunStatus Execute()
        {           
            if (!IsQueuedMovement) 
                return RunStatus.Failure;

            if (CurrentMovement == null)
            {                
                CurrentMovement = _internalQueue.Dequeue();
                CurrentMovement.StartPosition = ZetaDia.Me.Position;
                CurrentMovement.LastStartedTime = DateTime.UtcNow;
                Stuck.Reset();
            }

            _options = CurrentMovement.Options;

            if (CurrentMovement.OnUpdate != null)
                CurrentMovement.OnUpdate.Invoke(CurrentMovement);

            _status.LastStatus = PlayerMover.NavigateTo(CurrentMovement.Destination, CurrentMovement.Name);
            _status.DistanceToObjective = ZetaDia.Me.Position.Distance(CurrentMovement.Destination);
            _status.ChangeInDistance = _status.LastPosition.Distance(CurrentMovement.Destination) - _status.DistanceToObjective;
            _status.LastPosition = ZetaDia.Me.Position;

            CurrentMovement.Status = _status;

            if (CurrentMovement.StopCondition != null &&
                CurrentMovement.StopCondition.Invoke(CurrentMovement))
            {
                FailedHandler("StopWhen");
                return RunStatus.Failure;
            }

            if (Stuck.IsStuck(_options.ChangeInDistanceLimit,_options.TimeBeforeBlocked))
            {
                FailedHandler("Blocked " + Stuck.LastLogMessage);
                return RunStatus.Failure;
            }

            if (_status.DistanceToObjective < _options.AcceptableDistance)
            {
                SuccessHandler(string.Format("AcceptableDistance: {0}", _options.AcceptableDistance));
                return RunStatus.Success;
            }

            if (IsBlacklisted(CurrentMovement))
            {
                FailedHandler("RecentlyFailed");
                return RunStatus.Success;
            }

            if (_status.DistanceToObjective > _options.MaxDistance)
            {
                FailedHandler(string.Format("MaxDistance: {0}", _options.MaxDistance));
                return RunStatus.Success;
            }

            switch (_status.LastStatus)
            {
                case MoveResult.ReachedDestination:
                    SuccessHandler();
                    return RunStatus.Success;
                case MoveResult.PathGenerationFailed:
                case MoveResult.Moved:
                    MovedHandler();
                    return RunStatus.Running;
                case MoveResult.Failed:
                    FailedHandler("Navigation");
                    return RunStatus.Failure;
                default:
                    return RunStatus.Success;
            }

        }
Example #2
0
        public RunStatus Execute()
        {
            if (!IsQueuedMovement)
            {
                return(RunStatus.Failure);
            }

            if (CurrentMovement == null)
            {
                CurrentMovement = _internalQueue.Dequeue();
                CurrentMovement.StartPosition   = ZetaDia.Me.Position;
                CurrentMovement.LastStartedTime = DateTime.UtcNow;
                Stuck.Reset();
            }

            _options = CurrentMovement.Options;

            if (CurrentMovement.OnUpdate != null)
            {
                CurrentMovement.OnUpdate.Invoke(CurrentMovement);
            }

            _status.LastStatus          = PlayerMover.NavigateTo(CurrentMovement.Destination, CurrentMovement.Name);
            _status.DistanceToObjective = ZetaDia.Me.Position.Distance(CurrentMovement.Destination);
            _status.ChangeInDistance    = _status.LastPosition.Distance(CurrentMovement.Destination) - _status.DistanceToObjective;
            _status.LastPosition        = ZetaDia.Me.Position;

            CurrentMovement.Status = _status;

            if (CurrentMovement.StopCondition != null &&
                CurrentMovement.StopCondition.Invoke(CurrentMovement))
            {
                FailedHandler("StopWhen");
                return(RunStatus.Failure);
            }

            if (Stuck.IsStuck(_options.ChangeInDistanceLimit, _options.TimeBeforeBlocked))
            {
                FailedHandler("Blocked " + Stuck.LastLogMessage);
                return(RunStatus.Failure);
            }

            if (_status.DistanceToObjective < _options.AcceptableDistance)
            {
                SuccessHandler(string.Format("AcceptableDistance: {0}", _options.AcceptableDistance));
                return(RunStatus.Success);
            }

            if (IsBlacklisted(CurrentMovement))
            {
                FailedHandler("RecentlyFailed");
                return(RunStatus.Success);
            }

            if (_status.DistanceToObjective > _options.MaxDistance)
            {
                FailedHandler(string.Format("MaxDistance: {0}", _options.MaxDistance));
                return(RunStatus.Success);
            }

            switch (_status.LastStatus)
            {
            case MoveResult.ReachedDestination:
                SuccessHandler();
                return(RunStatus.Success);

            case MoveResult.PathGenerationFailed:
            case MoveResult.Moved:
                MovedHandler();
                return(RunStatus.Running);

            case MoveResult.Failed:
                FailedHandler("Navigation");
                return(RunStatus.Failure);

            default:
                return(RunStatus.Success);
            }
        }