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); }
/// <summary> /// Common tidy-up after finishing /// </summary> public void FinishedHandler() { CurrentMovement.LastFinishedTime = DateTime.UtcNow; if (CurrentMovement.OnFinished != null) { CurrentMovement.OnFinished.Invoke(CurrentMovement); } CurrentMovement = null; }
public void Queue(CombatMovement movement) { if (movement != null && !IsBlacklisted(movement)) { _internalQueue.Enqueue(movement); if (movement.Options.Logging >= LogLevel.Info) { LogLocation("Queueing", movement); } } }
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); }
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); }
/// <summary> /// Common tidy-up after finishing /// </summary> public void FinishedHandler() { CurrentMovement.LastFinishedTime = DateTime.UtcNow; if (CurrentMovement.OnFinished != null) CurrentMovement.OnFinished.Invoke(CurrentMovement); CurrentMovement = null; }
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; } }
public void Queue(CombatMovement movement) { if (movement != null && !IsBlacklisted(movement)) { _internalQueue.Enqueue(movement); if (movement.Options.Logging >= LogLevel.Info) LogLocation("Queueing", movement); } }
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)); }
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); } }