예제 #1
0
 public void LogLocation(string pre, CombatMovement movement, string post = "", TrinityLogLevel level = TrinityLogLevel.Info)
 {
     Logger.Log(level, LogCategory.Movement, pre + " {0} Distance={4:0.#} ({1:0.#},{2:0.#},{3:0.#}) {5}",
                movement.Name,
                movement.Destination.X,
                movement.Destination.Y,
                movement.Destination.Z,
                ZetaDia.Me.Position.Distance(movement.Destination),
                post);
 }
예제 #2
0
        /// <summary>
        /// Common tidy-up after finishing
        /// </summary>
        public void FinishedHandler()
        {
            CurrentMovement.LastFinishedTime = DateTime.UtcNow;

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

            CurrentMovement = null;
        }
예제 #3
0
        public void Queue(CombatMovement movement)
        {
            if (movement != null && !IsBlacklisted(movement))
            {
                _internalQueue.Enqueue(movement);

                if (movement.Options.Logging >= LogLevel.Info)
                {
                    LogLocation("Queueing", movement);
                }
            }
        }
예제 #4
0
 public bool IsBlacklisted(CombatMovement movement)
 {
     _blacklist.RemoveAll(m => DateTime.UtcNow.Subtract(m.LastFinishedTime).TotalSeconds > m.Options.FailureBlacklistSeconds);
     return _blacklist.Any(m => m.Name == movement.Name);
 }
예제 #5
0
 public void LogLocation(string pre, CombatMovement movement, string post = "", TrinityLogLevel level = TrinityLogLevel.Info)
 {
     Logger.Log(level, LogCategory.Movement, pre + " {0} Distance={4:0.#} ({1:0.#},{2:0.#},{3:0.#}) {5}",
         movement.Name,
         movement.Destination.X,
         movement.Destination.Y,
         movement.Destination.Z,
         ZetaDia.Me.Position.Distance(movement.Destination),
         post);
 }
예제 #6
0
        /// <summary>
        /// Common tidy-up after finishing
        /// </summary>
        public void FinishedHandler()
        {
            CurrentMovement.LastFinishedTime = DateTime.UtcNow;

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

            CurrentMovement = null;
        }
예제 #7
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;
            }

        }
예제 #8
0
        public void Queue(CombatMovement movement)
        {
            if (movement != null && !IsBlacklisted(movement))
            {
                _internalQueue.Enqueue(movement);

                if (movement.Options.Logging >= LogLevel.Info)
                    LogLocation("Queueing", movement);
            }
        }
예제 #9
0
 public bool IsBlacklisted(CombatMovement movement)
 {
     _blacklist.RemoveAll(m => DateTime.UtcNow.Subtract(m.LastFinishedTime).TotalSeconds > m.Options.FailureBlacklistSeconds);
     return(_blacklist.Any(m => m.Name == movement.Name));
 }
예제 #10
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);
            }
        }