Beispiel #1
0
        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 > 5)
                {
                    strafeDuration = 5;
                }

                if (actionDurationSeconds > 60)
                {
                    // back up a bit
                    wowProcess.SetKeyState(ConsoleKey.DownArrow, true, false, "StuckDetector");
                    await Task.Delay(strafeDuration);

                    wowProcess.SetKeyState(ConsoleKey.DownArrow, false, false, "StuckDetector");
                }
                this.stopMoving?.Stop();

                // stuck for 30 seconds
                var r = random.Next(0, 100);
                if (r < 50)
                {
                    logger.LogInformation($"Trying to unstick by strafing left for {strafeDuration}ms");
                    wowProcess.SetKeyState(ConsoleKey.Q, true, false, "StuckDetector");
                    await Task.Delay(strafeDuration);

                    wowProcess.SetKeyState(ConsoleKey.Q, false, false, "StuckDetector");
                }
                else
                {
                    logger.LogInformation($"Trying to unstick by strafing right for {strafeDuration}ms");
                    wowProcess.SetKeyState(ConsoleKey.E, true, false, "StuckDetector");
                    await Task.Delay(strafeDuration);

                    wowProcess.SetKeyState(ConsoleKey.E, 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);
            }
        }