Ejemplo n.º 1
0
        internal async Task RunNormalMode(CancellationToken token)
        {
            if (await StartContentBoardMission(MissionName) == null)
            {
                Logger.LogError($"Failed to go to {MissionName}");
                return;
            }
            await WaitUntilVisible(UIds.ALLIANCE_BATTLE_MODE_HEADER, token);

            if (!await WaitUntilVisible(UIds.ALLIANCE_BATTLE_NORMAL_MODE_READY, token))
            {
                Logger.LogError("Normal mode not available.");
                return;
            }

            await Task.Delay(1000, token);

            Game.Click(UIds.ALLIANCE_BATTLE_NORMAL_MODE_READY);


            if (!await WaitUntilVisible(UIds.ALLIANCE_BATTLE_NORMAL_MODE_START, token))
            {
                Logger.LogError("Normal mode start button not available.");
                return;
            }

            await SelectHeroes();

            Game.Click(UIds.ALLIANCE_BATTLE_NORMAL_MODE_START);

            await Task.Delay(1000, token);

            if (Game.IsVisible(UIds.ALLIANCE_BATTLE_NOTICE_THREE_CHARACTERS_REQUIRED))
            {
                Game.Click(UIds.GENERIC_MISSION_NOTICE_DISCONNECTED_OK);
                await Task.Delay(1000, token);
                await SelectHeroes();

                await Task.Delay(1000, token);

                Game.Click(UIds.ALLIANCE_BATTLE_NORMAL_MODE_START);
            }

            if (!await HandleStartNotices())
            {
                Logger.LogError("Failed to start mission...");
                return;
            }

            var autoFight = new AutoFight(Game, Repository, Settings);
            await autoFight.Run(token);

            await Task.Delay(1000, token);

            Game.Click(UIds.ALLIANCE_BATTLE_END_SCREEN_HOME);

            await Task.Delay(1000, token);

            await HandleHeroicQuestNotice();
        }
Ejemplo n.º 2
0
        private async Task <bool> RunAutoFight(CancellationToken token)
        {
            Func <bool> died               = () => Game.IsVisible(UIds.ALLIANCE_BATTLE_SELECT_NEW_CHARACTER_AND_CONTINUE);
            Func <bool> battleEnded        = () => Game.IsVisible(UIds.ALLIANCE_BATTLE_ENDED_MESSAGE);
            Func <bool> cleared            = () => Game.IsVisible(UIds.ALLIANCE_BATTLE_CLEAR_MESSAGE);
            Func <bool> threeCharsRequired = () => Game.IsVisible(UIds.ALLIANCE_BATTLE_NOTICE_THREE_CHARACTERS_REQUIRED);

            var autoFight     = new AutoFight(Game, Repository, Settings, died, battleEnded, cleared, threeCharsRequired);
            var autoFightTask = autoFight.Run(token);

            // TODO: is timeout fallback even necessary?
            if (await Task.WhenAny(autoFightTask, Task.Delay(300 * 1000, token)) == autoFightTask)
            {
                await autoFightTask; // catch exception if thrown...

                if (Game.IsVisible(UIds.ALLIANCE_BATTLE_SELECT_NEW_CHARACTER_AND_CONTINUE))
                {
                    Game.Click(UIds.ALLIANCE_BATTLE_SELECT_NEW_CHARACTER_AND_CONTINUE_CANCEL);
                    await Task.Delay(2000, token);
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        private async Task Fight(CancellationToken token, bool useCoopSkill)
        {
            Func <bool> chestDropped = () => { return(Game.IsVisible(UIds.WBI_SUPPLY_CHEST)); };
            Func <bool> disconnected = () => { return(Game.IsVisible(UIds.GENERIC_MISSION_NOTICE_DISCONNECTED)); };

            var fightBot = new AutoFight(Game, Repository, Settings, 90, chestDropped, disconnected);

            fightBot.UseCoopSkill = useCoopSkill;
            await fightBot.Run(token);

            if (Game.IsVisible(UIds.GENERIC_MISSION_NOTICE_DISCONNECTED))
            {
                Game.Click(UIds.GENERIC_MISSION_NOTICE_DISCONNECTED_OK);
                await Task.Delay(4000, token);

                Logger.LogInformation("Restarting because of disconnect");

                Game.Click(UIds.WBI_HERO_START_MISSION);

                await Fight(token, useCoopSkill);
            }
            else
            {
                await Task.Delay(2000, token);

                Game.Click(UIds.WBI_NEXT_RUN);
            }
        }
Ejemplo n.º 4
0
        protected async Task <bool> RunMissionCore(CancellationToken token)
        {
            if (!await WaitUntilVisible(UIds.GENERIC_MISSION_START, token))
            {
                return(false);
            }

            await Task.Delay(1000, token);

            Game.Click(UIds.GENERIC_MISSION_START);
            await Task.Delay(1000, token);

            if (Game.IsVisible(UIds.GENERIC_MISSION_ITEM_LIMIT_REACHED_NOTICE))
            {
                Game.Click(UIds.GENERIC_MISSION_ITEM_LIMIT_REACHED_NOTICE_OK_BUTTON);
            }


            if (!await OnGameStart())
            {
                await RunCore(token);

                return(true);
            }

            var autoFight = new AutoFight(Game, Repository, Settings, () => Game.IsVisible(UIds.EPIC_QUEST_ENDSCREEN_HOME_BUTTON_IMAGE));
            await autoFight.Run(token);

            if (!await WaitUntilVisible(UIds.EPIC_QUEST_ENDSCREEN_HOME_BUTTON_IMAGE, token, 20, 0.5f))
            {
                Game.OnError(new ElementNotFoundError(Repository[UIds.EPIC_QUEST_ENDSCREEN_HOME_BUTTON_IMAGE]));
                Logger.LogError("Button to navigate to home screen did not appear.");
                return(false);
            }

            await Task.Delay(3000, token);

            if (Game.IsVisible(UIds.EPIC_QUEST_ENDSCREEN_NOTICE_ALL_ENTRIES_USED))
            {
                Game.Click(UIds.EPIC_QUEST_ENDSCREEN_NOTICE_ALL_ENTRIES_USED_OK_BUTTON);
                await Task.Delay(1000, token);
            }

            if (!await ClickWhenVisible(UIds.EPIC_QUEST_ENDSCREEN_HOME_BUTTON_IMAGE))
            {
                Logger.LogError("Home button did not appear.");
                return(false);
            }

            await Task.Delay(3000, token);

            return(true);
        }
Ejemplo n.º 5
0
        private async Task <bool> RunAutoFight(CancellationToken token)
        {
            var autoFight     = new AutoFight(Game, Repository, Settings, () => Game.IsVisible(UIds.DANGER_ROOM_HIGHEST_EXCLUSIV_SKILL_COUNT));
            var autoFightTask = autoFight.Run(token);

            if (await Task.WhenAny(autoFightTask, Task.Delay(300 * 1000, token)) == autoFightTask)
            {
                await autoFightTask; // catch exception if thrown...
                return(true);
            }

            return(false);
        }
Ejemplo n.º 6
0
        private async Task HandleHeroicQuestEndFight(CancellationToken token)
        {
            await ClickWhenVisible(UIds.HEROIC_QUEST_QUEST_INFO_GOTO);

            await Task.Delay(2000);

            await ClickWhenVisible(UIds.HEROIC_QUEST_END_QUEST_START);
            await ClickWhenVisible(UIds.HEROIC_QUEST_END_QUEST_SKIP);

            Func <bool> homeVisible = () => Game.IsVisible(UIds.HEROIC_QUEST_END_QUEST_HOME);
            var         authFight   = new AutoFight(Game, Repository, Settings, homeVisible);
            await authFight.Run(token);

            await Task.Delay(1000);

            await ClickWhenVisible(UIds.HEROIC_QUEST_END_QUEST_HOME);
            await ClickWhenVisible(UIds.HEROIC_QUEST_END_QUEST_SKIP);
            await HandleHeroicQuestNotice();
            await GoToMainScreen();
        }
Ejemplo n.º 7
0
        protected override async Task RunCore(CancellationToken token)
        {
            var status = await StartContentBoardMission("LEGENDARY BATTLE");

            if (status == null)
            {
                Logger.LogError("Could not find legendary battle");
                return;
            }

            if (status.Completed)
            {
                Logger.LogInformation("Already completed");
                return;
            }

            if (ClearCount > status.Available)
            {
                Logger.LogError($"Cannot run {ClearCount} times. Only {status.Available} available");
                return;
            }
            else
            {
                Logger.LogDebug($"Trying to clear legendary battle {ClearCount} times.");
            }

            await Task.Delay(1000);

            bool found = false;

            // TODO: implement search for mission via drag
            for (int y = 0; y < 4; y++)
            {
                var mission     = Repository["LEGENDARY_BATTLE_NAME_DYN", 0, y];
                var missionText = Game.GetText(mission);
                if (missionText.Similarity(BattleName) > 0.75) // Accept small changes. TODO: figure out if this is sufficent.
                {
                    found = true;
                    Game.Click(mission);
                    break;
                }
            }

            if (!found)
            {
                Logger.LogError($"Failed to find mission {BattleName}.");
                Game.OnError(new ElementNotFoundError(Repository["LEGENDARY_BATTLE_NAME_DYN"]));
            }

            await Task.Delay(1000);

            Game.Click("LEGENDARY_BATTLE_NORMAL_MODE_BUTTON");
            Logger.LogDebug("Starting normal mode");

            await Task.Delay(1000);

            var enter = Repository["LEGENDARY_BATTLE_MISSION_ENTER", 0, 0];

            if (!await WaitUntilVisible(enter))
            {
                Logger.LogError("Enter button did not appear");
                Game.OnError(new ElementNotFoundError(enter));
                return;
            }

            Game.Click(enter);
            Logger.LogDebug("Entering mission");


            for (int i = 0; i < ClearCount; i++)
            {
                Logger.LogDebug($"Running mission (1/{status.Available})");

                await Task.Delay(3000);

                Logger.LogDebug("Starting mission.");
                Game.Click("LEGENDARY_BATTLE_MISSION_START");

                await Task.Delay(1000, token);

                if (Game.IsVisible(UIds.LEGENDARY_BATTLE_CHARACTER_NOTICE_IGNORE))
                {
                    Logger.LogDebug("Ignoring character requirement message");
                    Game.Click(UIds.LEGENDARY_BATTLE_CHARACTER_NOTICE_IGNORE);
                }

                Logger.LogDebug("Waiting for skip into button");
                if (await WaitUntilVisible("LEGENDARY_BATTLE_MISSION_SKIP_INTRO", 10))
                {
                    Game.Click("LEGENDARY_BATTLE_MISSION_SKIP_INTRO");
                }

                Logger.LogDebug("Starting auto fight");

                Func <bool> end      = () => Game.IsVisible("LEGENDARY_BATTLE_MISSION_SUCCESS");
                var         fightBot = new AutoFight(Game, Repository, Settings, end);
                await fightBot.Run(token);

                await Task.Delay(1000);

                Logger.LogDebug("Starting auto fight finished. Repeating run.");
                Game.Click("LEGENDARY_BATTLE_ENDSCREEN_REPEAT_RUN");
            }

            await Task.Delay(2000);

            // Handle heroic quest notices.
            await GoToMainScreen();
        }
Ejemplo n.º 8
0
        protected override async Task RunCore(CancellationToken token)
        {
            var status = await StartContentBoardMission("SQUAD BATTLE");

            if (status.Completed)
            {
                Logger.LogInformation("Already completed...");
                return;
            }

            await Task.Delay(2000);

            if (Game.IsVisible(UIds.SQUAD_BATTLE_RANK_DROP))
            {
                Game.Click(UIds.SQUAD_BATTLE_RANK_DROP);
            }

            int leastPoints  = int.MaxValue;
            int leastPointsX = 0;
            int leastPointsY = 1; // first row is 1 not 0.

            for (int y = 1; y < 4; y++)
            {
                for (int x = 0; x < 2; x++)
                {
                    var pointsStr = Game.GetText(Repository[$"SQUAD_BATTLE_POINTS_{y}_ROW", x, 0]);
                    var trimStr   = "Point(s)";
                    if (pointsStr.Contains(trimStr))
                    {
                        var pointSubString = pointsStr.Substring(0, pointsStr.Length - trimStr.Length).TrimEnd();
                        if (int.TryParse(pointSubString, NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out var points))
                        {
                            if (points < leastPoints)
                            {
                                leastPointsX = x;
                                leastPointsY = y;
                                leastPoints  = points;
                                Logger.LogDebug($"Found new least points. {points} {leastPointsX}/{leastPointsY}");
                            }
                        }
                    }
                    Logger.LogDebug(pointsStr);
                }
            }

            var chosenOpponent = Repository[$"SQUAD_BATTLE_SELECTION_{leastPointsY}_ROW", leastPointsX, 0];

            Game.Click(chosenOpponent);

            await Task.Delay(2000);

            await SelectHeroes();

            Game.Click(UIds.SQUAD_BATTLE_START_BATTLE);

            await Task.Delay(1000);

            if (Game.IsVisible(UIds.SQUAD_BATTLE_ALL_SLOTS_MUST_BE_FILLED))
            {
                Game.Click(UIds.SQUAD_BATTLE_ALL_SLOTS_MUST_BE_FILLED_OK);
                await Task.Delay(1000);
                await SelectHeroes();

                Game.Click(UIds.SQUAD_BATTLE_START_BATTLE);
            }

            Func <bool> endCondition        = () => Game.IsVisible(UIds.SQUAD_BATTLE_END_BATTLE_MESSAGE);
            Func <bool> summaryBattlePoints = () => Game.IsVisible(UIds.SQUAD_BATTLE_SUMMARY_OVERALL_BATTLEPOINTS);
            var         fightBot            = new AutoFight(Game, Repository, Settings, endCondition, summaryBattlePoints);
            await fightBot.Run(token);

            await Task.Delay(2000);

            if (!await ClickWhenVisible(UIds.SQUAD_BATTLE_SUMMARY_OVERALL_BATTLEPOINTS, 10))
            {
                Logger.LogError("Rank up/down notification did not appear. Did we already run this mode?");
                return;
            }

            await Task.Delay(3000);

            if (Game.IsVisible(UIds.SQUAD_BATTLE_SUMMARY_OVERALL_BATTLEPOINTS))
            {
                Logger.LogDebug("Clicking one more time... (SQUAD_BATTLE_SUMMARY_OVERALL_BATTLEPOINTS)");
                Game.Click(UIds.SQUAD_BATTLE_SUMMARY_OVERALL_BATTLEPOINTS);
            }

            await Task.Delay(3000);

            if (!await ClickWhenVisible(UIds.SQUAD_BATTLE_END_HOME_BUTTON))
            {
                Game.OnError(new ElementNotFoundError(Repository[UIds.SQUAD_BATTLE_END_HOME_BUTTON]));
                Logger.LogError("Rank up/down notification did not appear.");
                return;
            }

            await Task.Delay(2000);
        }