public async Task BotThread() { if (this.actionThread != null) { await wowProcess.KeyPress(ConsoleKey.F3, 400); // clear target while (this.actionThread.Active) { await actionThread.GoapPerformAction(); } } await this.wowProcess.KeyPress(ConsoleKey.UpArrow, 500); logger.LogInformation("Stopped!"); }
public BotController(ILogger logger, IPPather pather) { wowProcess = new WowProcess(logger); wowProcess.KeyPress(ConsoleKey.F3, 400).Wait(); // clear target this.WowScreen = new WowScreen(logger); this.logger = logger; this.pather = pather; var frames = DataFrameConfiguration.ConfigurationExists() ? DataFrameConfiguration.LoadConfiguration() : new List <DataFrame>(); //config.CreateConfiguration(WowScreen.GetAddonBitmap()); AddonReader = new AddonReader(WowScreen, frames, logger); minimapNodeFinder = new MinimapNodeFinder(new PixelClassifier()); MinimapImageFinder = minimapNodeFinder as IImageProvider; addonThread = new Thread(AddonRefreshThread); addonThread.Start(); // wait for addon to read the wow state var sw = new Stopwatch(); sw.Start(); while (AddonReader.PlayerReader.Sequence == 0 || !Enum.GetValues(typeof(PlayerClassEnum)).Cast <PlayerClassEnum>().Contains(AddonReader.PlayerReader.PlayerClass)) { if (sw.ElapsedMilliseconds > 5000) { logger.LogWarning("There is a problem with the addon, I have been unable to read the player class. Is it running ?"); sw.Restart(); } Thread.Sleep(100); } logger.LogDebug($"Woohoo, I have read the player class. You are a {AddonReader.PlayerReader.PlayerClass}."); npcNameFinder = new NpcNameFinder(wowProcess, AddonReader.PlayerReader, logger); //ActionFactory = new GoalFactory(AddonReader, logger, wowProcess, npcNameFinder); screenshotThread = new Thread(ScreenshotRefreshThread); screenshotThread.Start(); }
public async Task Unstick() { await wowProcess.KeyPress(ConsoleKey.Spacebar, 500); logger.LogInformation($"Stuck for {actionDurationSeconds}s, last tried to unstick {unstickSeconds}s ago. Unstick seconds={unstickSeconds}."); if (actionDurationSeconds > 240) { // stuck for 4 minutes logger.LogInformation("Stuck for 4 minutes"); SendActionEvent(new ActionEventArgs(GoapKey.abort, true)); await Task.Delay(120000); } if (unstickSeconds > 5) { int strafeDuration = (int)(1000 + (((double)actionDurationSeconds * 1000) / 12)); if (strafeDuration > 20000) { strafeDuration = 20000; } if (actionDurationSeconds > 20) { // back up a bit, added "remove" move forward wowProcess.SetKeyState(ConsoleKey.DownArrow, true, false, "StuckDetector_back_up"); wowProcess.SetKeyState(ConsoleKey.UpArrow, false, false, "StuckDetector"); await Task.Delay(strafeDuration); wowProcess.SetKeyState(ConsoleKey.DownArrow, false, false, "StuckDetector"); } this.stopMoving?.Stop(); // stuck for 20 seconds var r = random.Next(0, 100); if (r < 50) { logger.LogInformation($"Trying to unstick by strafing left for {strafeDuration}ms"); wowProcess.SetKeyState(ConsoleKey.A, true, false, "StuckDetector"); await Task.Delay(strafeDuration); wowProcess.SetKeyState(ConsoleKey.A, false, false, "StuckDetector"); } else { logger.LogInformation($"Trying to unstick by strafing right for {strafeDuration}ms"); wowProcess.SetKeyState(ConsoleKey.D, true, false, "StuckDetector"); await Task.Delay(strafeDuration); wowProcess.SetKeyState(ConsoleKey.D, false, false, "StuckDetector"); } await wowProcess.TapStopKey(); wowProcess.SetKeyState(ConsoleKey.UpArrow, true, false, "StuckDetector"); var heading = DirectionCalculator.CalculateHeading(this.playerReader.PlayerLocation, targetLocation); await playerDirection.SetDirection(heading, targetLocation, "Move to next point"); LastUnstickAttemptTimer.Reset(); LastUnstickAttemptTimer.Start(); } else { await wowProcess.KeyPress(ConsoleKey.Spacebar, 500); } }
public async Task Unstick() { await wowProcess.KeyPress(ConsoleKey.Spacebar, 500); logger.LogInformation($"Stuck for {actionDurationSeconds}s, last tried to unstick {unstickSeconds}s ago. Unstick seconds={unstickSeconds}."); if (actionDurationSeconds > 240) { // stuck for 4 minutes logger.LogInformation("Stuck for 4 minutes"); SendActionEvent(new ActionEventArgs(GoapKey.abort, true)); await Task.Delay(120000); } if (unstickSeconds > 2) { int actionDuration = (int)(1000 + (((double)actionDurationSeconds * 1000) / 8)); if (actionDuration > 20000) { actionDuration = 20000; } if (actionDurationSeconds > 10) { // back up a bit, added "remove" move forward logger.LogInformation($"Trying to unstick by backing up for {actionDuration}ms"); wowProcess.SetKeyState(ConsoleKey.DownArrow, true, false, "StuckDetector_back_up"); wowProcess.SetKeyState(ConsoleKey.UpArrow, false, false, "StuckDetector"); await Task.Delay(actionDuration); wowProcess.SetKeyState(ConsoleKey.DownArrow, false, false, "StuckDetector"); } this.stopMoving?.Stop(); // Turn var r = random.Next(0, 2); var key = r == 0 ? ConsoleKey.A : ConsoleKey.D; var turnDuration = random.Next(0, 800) + 200; logger.LogInformation($"Trying to unstick by turning for {turnDuration}ms"); wowProcess.SetKeyState(key, true, false, "StuckDetector"); await Task.Delay(turnDuration); wowProcess.SetKeyState(key, false, false, "StuckDetector"); // Move forward var strafeDuration = random.Next(0, 2000) + actionDurationSeconds; logger.LogInformation($"Trying to unstick by moving forward after turning for {strafeDuration}ms"); wowProcess.SetKeyState(ConsoleKey.UpArrow, true, false, "StuckDetector"); await Task.Delay(strafeDuration); await wowProcess.KeyPress(ConsoleKey.Spacebar, 500); var heading = DirectionCalculator.CalculateHeading(this.playerReader.PlayerLocation, targetLocation); await playerDirection.SetDirection(heading, targetLocation, "Move to next point"); LastUnstickAttemptTimer.Reset(); LastUnstickAttemptTimer.Start(); } else { await wowProcess.KeyPress(ConsoleKey.Spacebar, 500); } }