Exemplo n.º 1
0
        public string GetExePath()
        {
            BlueStacks.GetWindowThreadProcessId(MainWindowAS.Handle, out uint num);
            if (num == 0u)
            {
                return(null);
            }
            Process processById = Process.GetProcessById((int)num);

            return(processById.MainModule.FileName);
        }
Exemplo n.º 2
0
 public uint GetProcessID()
 {
     BlueStacks.GetWindowThreadProcessId(MainWindowAS.Handle, out uint num);
     if (num == 0u)
     {
         return((int)0u);
     }
     else
     {
         return(num);
     }
 }
Exemplo n.º 3
0
        private void MainLoop(object sender, DoWorkEventArgs e)
        {
            bool flag = false;
            bool flag2 = false;
            bool flag3 = false;
            this.Log("Initializing AI...");
            this.BlueStacks = new BlueStacks();
            string errorMessage;
            if (!this.BlueStacks.Hook())
            {
                errorMessage = "BlueStacks is not active or not yet initialized";
                this.LogError(errorMessage);
                this.SynchronizationContext.Send(delegate (object callback)
                {
                    MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }, null);
                return;
            }
            if (this.BlueStacks.NeedResize() || this.BlueStacks.NeedRenderConfig())
            {
                string text = "BlueStacks needs to be resized. Proceed?";
                DialogResult dialogResult = MessageBox.Show(text, "Restart Required", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
                if (dialogResult == DialogResult.OK)
                {
                    string exePath = this.BlueStacks.GetExePath();
                    this.BlueStacks.RenderConfig();
                    this.BlueStacks.Resize();
                    this.BlueStacks.Kill();
                    SevenKnightsCore.Sleep(500);
                    Process.Start(exePath);
                }
                return;
            }
            if (this.BlueStacks.IsGameInstalled())
            {
                if (!this.BlueStacks.IsGameActive())
                {
                    this.Log("Launching Seven Knights...");
                    this.BlueStacks.LaunchGame();
                    this.LongSleep(3000, 1000);
                }
                this.InitLoop();
                string value = null;
                while (!this.Worker.CancellationPending)
                {
                    try
                    {
                        if (!this.AIProfiles.TMP_Paused && !this.AIProfiles.TMP_WaitingForKeys)
                        {
                            //if (!this.IsGameActive())
                            //{
                            //    errorMessage = "Seven Knights is not active";
                            //    this.LogError(errorMessage);
                            //    this.SynchronizationContext.Send(delegate (object callback)
                            //    {
                            //        MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            //    }, null);
                            //    break;
                            //}
                            if (this.AIProfiles.ST_BlueStacksForceActive)
                            {
                                this.BlueStacks.MainWindowAS.BringToFront();
                            }
                            int sT_Delay = this.AIProfiles.ST_Delay;
                            SevenKnightsCore.Sleep(sT_Delay);
                            this.IdleCounter += sT_Delay;
                            this.HangCounter += sT_Delay;
                            this.MapSelectCounter += sT_Delay;
                            this.CooldownInbox -= sT_Delay;
                            this.CooldownQuests -= sT_Delay;
                            this.CooldownSendHonors -= sT_Delay;
                            this.CooldownSellHeroes -= sT_Delay;
                            this.CooldownSellItems -= sT_Delay;
                            this.CaptureFrame();
                            if (this.BlueStacks.MainWindowAS.CurrentFrame != null)
                            {
                                this.UpdateHangFingerprint();
                                if (this.HangCounter >= 30000)
                                {
                                    this.Log("Restarting Seven Knights", Color.DarkRed);
                                    this.PushNote("Restarting Seven Knights", "The game is not responding... AI will restart the game and continue.");
                                    this.HangCounter = 0;
                                    if (!this.BlueStacks.RestartGame(5))
                                    {
                                        errorMessage = "Restart failed";
                                        this.LogError(errorMessage);
                                        this.SynchronizationContext.Send(delegate (object callback)
                                        {
                                            MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                                        }, null);
                                        break;
                                    }
                                    if (this.PreviousObjective == Objective.HERO_MANAGEMENT)
                                    {
                                        this.ChangeObjective(Objective.HERO_MANAGEMENT);
                                    }
                                    this.IdleCounter = 0;
                                    this.LongSleep(10000, 1000);
                                }
                                Scene scene = this.SceneSearch();
                                bool flag4 = false;
                                string text2;
                                if (scene == null)
                                {
                                    text2 = "...";
                                    flag4 = true;
                                }
                                else
                                {
                                    text2 = scene.SceneType.ToString();
                                }
                                if (!text2.Equals(value))
                                {
                                    this.LogScene(text2);
                                    value = text2;
                                }
                                if (flag4)
                                {
                                    if (this.MatchMapping(SharedPM.BackButton, 2) && this.MatchMapping(SharedPM.BackButtonAnchor, 2))
                                    {
                                        this.LogScene("BACKABLE");
                                        this.Escape();
                                    }
                                    else if (this.IdleCounter >= 8000)
                                    {
                                        this.Escape();
                                        this.IdleCounter = 0;
                                    }
                                }
                                else
                                {
                                    if (scene.SceneType != SceneType.ADVENTURE_FIGHT && scene.SceneType != SceneType.TOWER_FIGHT && scene.SceneType != SceneType.ARENA_FIGHT && scene.SceneType != SceneType.RAID_FIGHT)
                                    {
                                        this.CurrentWave = 0;
                                        this.CurrentRaidTeam = 0;
                                        this.CurrentSkillSet = null;
                                        this.CurrentSkill = -1;
                                        this.PressedSkill = -1;
                                    }
                                    if (scene.SceneType != SceneType.MAP_SELECT)
                                    {
                                        this.MapSelectCounter = 0;
                                    }
                                    if (scene.SceneType != SceneType.ADVENTURE_START && scene.SceneType != SceneType.MAP_SELECT && scene.SceneType != SceneType.ADVENTURE_READY && scene.SceneType != SceneType.MAP_SELECT_POPUP)
                                    {
                                        this.MapCheckCount = 0;
                                    }
                                    this.IdleCounter = 0;
                                    switch (scene.SceneType)
                                    {
                                        case SceneType._ANDROID_POPUP:
                                            if (this.AIProfiles.ST_ReconnectInterruptEnable)
                                            {
                                                this.LongSleep(this.AIProfiles.ST_ReconnectInterruptInterval * 60000, 1000);
                                                if (!this.BlueStacks.RestartGame(5))
                                                {
                                                    this.SynchronizationContext.Send(delegate (object callback)
                                                    {
                                                        MessageBox.Show("BlueStacks restart failed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                                                    }, null);
                                                    return;
                                                }
                                            }
                                            break;

                                        case SceneType._DIALOG:
                                            this.Escape();
                                            SevenKnightsCore.Sleep(300);
                                            break;

                                        case SceneType.TAP_TO_PLAY:
                                            this.WeightedClick(TapToPlayPM.TapArea, 1.0, 1.0, 1, 0, "left");
                                            SevenKnightsCore.Sleep(1000);
                                            break;

                                        case SceneType.NOTICE:
                                            this.Escape();
                                            break;

                                        case SceneType.ADS:
                                            this.Escape();
                                            break;

                                        case SceneType.ADS_CLOSE:
                                            this.WeightedClick(AdsClosePM.CloseButton, 1.0, 1.0, 1, 0, "left");
                                            break;

                                        case SceneType.CHECK_IN:
                                            this.Escape();
                                            break;

                                        case SceneType.POPUP_1:
                                            this.Escape();
                                            break;

                                        case SceneType.POPUP_2:
                                            this.Escape();
                                            break;

                                        case SceneType.DISCONNECTED_POPUP:
                                            this.WeightedClick(DisconnectedPopupPM.OkButton, 1.0, 1.0, 1, 0, "left");
                                            this.LongSleep(3000, 1000);
                                            break;

                                        case SceneType.WIFI_WARNING_POPUP:
                                            this.WeightedClick(WifiWarningPopupPM.OkButton, 1.0, 1.0, 1, 0, "left");
                                            break;

                                        case SceneType.LOBBY:
                                            this.UpdateAdventureKeys(scene.SceneType);
                                            this.UpdateGold(scene.SceneType);
                                            this.UpdateRuby(scene.SceneType);
                                            this.UpdateHonor(scene.SceneType);
                                            this.UpdateTopaz(scene.SceneType);
                                            if (this.AISettings.RS_CollectLuckyChest && this.MatchMapping(LobbyPM.MaysLuckyChestAvailable_1, 4) && this.MatchMapping(LobbyPM.MaysLuckyChestAvailable_2, 4))
                                            {
                                                this.WeightedClick(LobbyPM.MaysLuckyChestButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            else if (this.AISettings.RS_CollectLuckyBox && this.EnableLuckyBox && this.MatchMapping(LobbyPM.LuckyBoxAvailable_1, 4) && this.MatchMapping(LobbyPM.LuckyBoxAvailable_2, 4))
                                            {
                                                if (this.MatchMapping(LobbyPM.LuckyBoxLastOne_1, 2) && this.MatchMapping(LobbyPM.LuckyBoxLastOne_2, 2))
                                                {
                                                    this.StopLuckyBox(false);
                                                }
                                                else
                                                {
                                                    this.WeightedClick(LobbyPM.LuckyBoxButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                            }
                                            else
                                            {
                                                if (this.IsSendHonorsEnabled() && this.CooldownSendHonors <= 0)
                                                {
                                                    this.CooldownSendHonors = 1800000;
                                                    if (this.IsSendHonorsEnabled() && this.CurrentObjective != Objective.COLLECT_QUESTS && this.CurrentObjective != Objective.COLLECT_INBOX && this.CurrentObjective != Objective.SEND_HONORS && this.CurrentObjective != Objective.BUY_KEYS && this.CurrentObjective != Objective.HERO_MANAGEMENT)
                                                    {
                                                        this.ChangeObjective(Objective.SEND_HONORS);
                                                    }
                                                }
                                                else if (this.MatchMapping(LobbyPM.QuestAvailable, 3) && this.IsAnyQuestsEnabled() && this.CooldownQuests <= 0)
                                                {
                                                    this.CooldownQuests = 1800000;
                                                    if (this.IsAnyQuestsEnabled() && this.CurrentObjective != Objective.COLLECT_QUESTS && this.CurrentObjective != Objective.COLLECT_INBOX && this.CurrentObjective != Objective.SEND_HONORS && this.CurrentObjective != Objective.BUY_KEYS && this.CurrentObjective != Objective.HERO_MANAGEMENT)
                                                    {
                                                        this.ChangeObjective(Objective.COLLECT_QUESTS);
                                                    }
                                                }
                                                else if (this.MatchMapping(LobbyPM.InboxAvailable, 3) && this.IsInboxEnabled() && this.CooldownInbox <= 0)
                                                {
                                                    this.CooldownInbox = 1800000;
                                                    if (this.IsInboxEnabled() && this.CurrentObjective != Objective.COLLECT_INBOX && this.CurrentObjective != Objective.COLLECT_QUESTS && this.CurrentObjective != Objective.SEND_HONORS && this.CurrentObjective != Objective.BUY_KEYS && this.CurrentObjective != Objective.HERO_MANAGEMENT)
                                                    {
                                                        this.ChangeObjective(Objective.COLLECT_INBOX);
                                                    }
                                                }
                                                if (this.CurrentObjective == Objective.ADVENTURE || this.CurrentObjective == Objective.GOLD_CHAMBER || this.CurrentObjective == Objective.RAID)
                                                {
                                                    this.WeightedClick(LobbyPM.AdventureButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                                else if (this.CurrentObjective == Objective.ARENA)
                                                {
                                                    this.WeightedClick(LobbyPM.BattleButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                                else if (this.CurrentObjective == Objective.HERO_MANAGEMENT || this.CurrentObjective == Objective.SELL_HEROES)
                                                {
                                                    this.WeightedClick(LobbyPM.HeroButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                                else if (this.CurrentObjective == Objective.BUY_KEYS)
                                                {
                                                    this.WeightedClick(LobbyPM.ShopButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                                else if (this.CurrentObjective == Objective.COLLECT_INBOX)
                                                {
                                                    this.WeightedClick(LobbyPM.InboxButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                                else if (this.CurrentObjective == Objective.COLLECT_QUESTS)
                                                {
                                                    this.WeightedClick(LobbyPM.QuestButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                                else if (this.CurrentObjective == Objective.SEND_HONORS)
                                                {
                                                    this.WeightedClick(LobbyPM.SocialButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                                else if (this.CurrentObjective == Objective.IDLE)
                                                {
                                                    this.NextPossibleObjective();
                                                }
                                                SevenKnightsCore.Sleep(300);
                                            }
                                            break;

                                        case SceneType.GIFT_REWARDS_POPUP:
                                            this.PushNote("Reward Received!", "AI has collected May's Lucky Chest or Lucky Box.");
                                            this.WeightedClick(SharedPM.Rewards_OkButton, 1.0, 1.0, 1, 0, "left");
                                            SevenKnightsCore.Sleep(300);
                                            break;

                                        case SceneType.GIFT_FULL_ITEM_POPUP:
                                            this.StopLuckyBox(true);
                                            break;

                                        case SceneType.GIFT_FULL_HERO_POPUP:
                                            this.StopLuckyBox(true);
                                            break;

                                        case SceneType.GIFT_FULL_HONOR_POPUP:
                                            this.StopLuckyBox(true);
                                            break;

                                        case SceneType.OUT_OF_LUCKY_BOX_POPUP:
                                            this.Escape();
                                            break;

                                        case SceneType.MASTERY_POPUP:
                                            {
                                                if (this.MasteryChecked)
                                                {
                                                    this.WeightedClick(MasteryPopupPM.CloseButton, 1.0, 1.0, 1, 0, "left");
                                                    return;
                                                }
                                                int num = -1;
                                                if (this.CurrentObjective == Objective.ADVENTURE)
                                                {
                                                    num = (int)this.AISettings.AD_Mastery;
                                                }
                                                else if (this.CurrentObjective == Objective.GOLD_CHAMBER)
                                                {
                                                    num = (int)this.AISettings.GC_Mastery;
                                                }
                                                else if (this.CurrentObjective == Objective.ARENA)
                                                {
                                                    num = (int)this.AISettings.AR_Mastery;
                                                }
                                                if (num == 0 || num == -1)
                                                {
                                                    this.WeightedClick(MasteryPopupPM.CloseButton, 1.0, 1.0, 1, 0, "left");
                                                    return;
                                                }
                                                PixelMapping[] array = new PixelMapping[]
                                                {
                                            MasteryPopupPM.Tab1,
                                            MasteryPopupPM.Tab2,
                                            MasteryPopupPM.Tab3
                                                };
                                                this.WeightedClick(array[num - 1], 1.0, 1.0, 1, 0, "left");
                                                SevenKnightsCore.Sleep(500);
                                                this.MasteryChecked = true;
                                                this.WeightedClick(MasteryPopupPM.CloseButton, 1.0, 1.0, 1, 0, "left");
                                                break;
                                            }
                                        case SceneType.ADVENTURE_MODES:
                                            this.UpdateAdventureKeys(scene.SceneType);
                                            this.UpdateGold(scene.SceneType);
                                            this.UpdateRuby(scene.SceneType);
                                            if (this.CurrentObjective == Objective.ADVENTURE)
                                            {
                                                this.WeightedClick(AdventureModesPM.AdventureButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            else if (this.CurrentObjective == Objective.GOLD_CHAMBER)
                                            {
                                                this.WeightedClick(AdventureModesPM.CelestialTowerButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            else if (this.CurrentObjective == Objective.RAID)
                                            {
                                                this.WeightedClick(AdventureModesPM.RaidButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.MAP_SELECT:
                                            this.UpdateAdventureKeys(scene.SceneType);
                                            this.UpdateGold(scene.SceneType);
                                            this.UpdateRuby(scene.SceneType);
                                            if (this.MapSelectCounter >= 10000)
                                            {
                                                this.WeightedClick(SharedPM.BackButton, 1.0, 1.0, 1, 0, "left");
                                                SevenKnightsCore.Sleep(500);
                                            }
                                            else if (this.CurrentObjective == Objective.ADVENTURE)
                                            {
                                                World world = this.AISettings.AD_World;
                                                int stage = this.AISettings.AD_Stage;
                                                if (this.AISettings.AD_World == World.Sequencer)
                                                {
                                                    Tuple<World, int> worldStageFromSequencer = this.GetWorldStageFromSequencer();
                                                    if (worldStageFromSequencer == null)
                                                    {
                                                        this.LogError("Stage sequence is empty");
                                                        this.NextPossibleObjective();
                                                        break;
                                                    }
                                                    world = worldStageFromSequencer.Item1;
                                                    stage = worldStageFromSequencer.Item2;
                                                }
                                                if (world == World.MoonlitIsle || world == World.WesternEmpire || world == World.EasternEmpire)
                                                {
                                                    if (this.MatchMapping(MapSelectPM.DifficultyBoxBorderLeft, 2) && this.MatchMapping(MapSelectPM.DifficultyBoxBorderRight, 2))
                                                    {
                                                        this.WeightedClick(MapSelectPM.ContinentButton, 1.0, 1.0, 1, 0, "left");
                                                        SevenKnightsCore.Sleep(1000);
                                                    }
                                                    this.SelectStageAisha(world, stage);
                                                }
                                                else
                                                {
                                                    if (!this.MatchMapping(MapSelectPM.DifficultyBoxBorderLeft, 2) && !this.MatchMapping(MapSelectPM.DifficultyBoxBorderRight, 2))
                                                    {
                                                        this.WeightedClick(MapSelectPM.ContinentButton, 1.0, 1.0, 1, 0, "left");
                                                        SevenKnightsCore.Sleep(1000);
                                                    }
                                                    this.SelectStageAsgar(world, stage);
                                                }
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.MAP_SELECT_POPUP:
                                            this.Escape();
                                            break;

                                        case SceneType.FULL_ITEM_POPUP:
                                            if (!flag)
                                            {
                                                this.PushNote("Item Full!", "Your inventory is full. AI will start selling them if enabled.");
                                                flag = true;
                                            }
                                            if (this.AISettings.RS_SellItems && this.CooldownSellItems <= 0)
                                            {
                                                if (this.CurrentObjective != Objective.SELL_ITEMS)
                                                {
                                                    this.ChangeObjective(Objective.SELL_ITEMS);
                                                }
                                                this.WeightedClick(SharedPM.Full_SellButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            else
                                            {
                                                this.WeightedClick(SharedPM.Full_ProceedButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            SevenKnightsCore.Sleep(500);
                                            break;

                                        case SceneType.FULL_HERO_POPUP:
                                            if (this.AISettings.AD_StopOnFullHeroes)
                                            {
                                                this.Alert("Heroes Full");
                                                this.Escape();
                                            }
                                            if (!flag2)
                                            {
                                                this.PushNote("Hero Full!", "Your hero cards are full. AI will start selling them if enabled.");
                                                flag2 = true;
                                            }
                                            if (this.AISettings.RS_SellHeroes && this.CooldownSellHeroes <= 0)
                                            {
                                                if (this.CurrentObjective != Objective.SELL_HEROES)
                                                {
                                                    this.ChangeObjective(Objective.SELL_HEROES);
                                                }
                                                this.WeightedClick(SharedPM.Full_SellButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            else
                                            {
                                                this.WeightedClick(SharedPM.Full_ProceedButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            SevenKnightsCore.Sleep(500);
                                            break;

                                        case SceneType.ADVENTURE_READY:
                                            if (this.CurrentObjective == Objective.ADVENTURE)
                                            {
                                                this.WeightedClick(AdventureReadyPM.ReadyButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            else
                                            {
                                                this.WeightedClick(AdventureReadyPM.CloseButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            break;

                                        case SceneType.ADVENTURE_START:
                                            this.UpdateAdventureKeys(scene.SceneType);
                                            this.UpdateGold(scene.SceneType);
                                            if (this.CurrentObjective == Objective.ADVENTURE)
                                            {
                                                World world2 = this.AISettings.AD_World;
                                                int stage2 = this.AISettings.AD_Stage;
                                                if (this.AISettings.AD_World == World.Sequencer)
                                                {
                                                    Tuple<World, int> worldStageFromSequencer2 = this.GetWorldStageFromSequencer();
                                                    if (worldStageFromSequencer2 == null)
                                                    {
                                                        this.LogError("Stage sequence is empty");
                                                        this.NextPossibleObjective();
                                                        break;
                                                    }
                                                    world2 = worldStageFromSequencer2.Item1;
                                                    stage2 = worldStageFromSequencer2.Item2;
                                                }
                                                if (this.AISettings.AD_Continuous || this.CheckMapNumber(world2, stage2) || this.MapCheckCount >= 3)
                                                {
                                                    if (!this.CheckMastery(scene.SceneType))
                                                    {
                                                        this.MasteryChecked = false;
                                                        this.SelectTeam(SceneType.ADVENTURE_START);
                                                        this.WeightedClick(SharedPM.PrepareFight_StartButton, 1.0, 1.0, 1, 0, "left");
                                                        SevenKnightsCore.Sleep(300);
                                                    }
                                                }
                                                else
                                                {
                                                    this.MapCheckCount++;
                                                    this.Escape();
                                                    SevenKnightsCore.Sleep(300);
                                                }
                                            }
                                            else if (this.CurrentObjective == Objective.HERO_MANAGEMENT)
                                            {
                                                this.WeightedClick(SharedPM.PrepareFight_ManageButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.ADVENTURE_FIGHT:
                                            this.PerformFightTatics(scene.SceneType);
                                            break;

                                        case SceneType.ADVENTURE_LOST:
                                            this.AdventureAfterFight();
                                            this.Log("Your team lost the battle [Adventure]", this.COLOR_DEATH);
                                            this.PushNote("You Lose! [Adventure]", "Your team has lost a battle. Continuing AI.");
                                            this.WeightedClick(AdventureLostPM.AdventureButton, 1.0, 1.0, 1, 0, "left");
                                            break;

                                        case SceneType.VICTORY:
                                            for (int i = 0; i < 3; i++)
                                            {
                                                SevenKnightsCore.Sleep(500);
                                                this.WeightedClick(VictoryPM.TapToSkipArea, 1.0, 1.0, 1, 0, "left");
                                            }
                                            break;

                                        case SceneType.ADVENTURE_LOOT_ITEM:
                                        case SceneType.ADVENTURE_LOOT_HERO:
                                        case SceneType.ADVENTURE_LOOT_GOLD:
                                            this.AdventureAfterFight();
                                            SevenKnightsCore.Sleep(500);
                                            if (this.CurrentObjective == Objective.ADVENTURE)
                                            {
                                                if (this.AISettings.AD_Continuous && this.AISettings.AD_World != World.Sequencer)
                                                {
                                                    this.WeightedClick(AdventureLootItemPM.NextZoneButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                                else if (this.AISettings.AD_World == World.None)
                                                {
                                                    this.WeightedClick(AdventureLootItemPM.QuickStartButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                                else
                                                {
                                                    this.WeightedClick(AdventureLootItemPM.AgainButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                            }
                                            else
                                            {
                                                this.WeightedClick(SharedPM.Loot_LobbyButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            break;

                                        case SceneType.ADVENTURE_LOOT_HERO_SPECIAL:
                                            this.AdventureAfterFight();
                                            SevenKnightsCore.Sleep(300);
                                            this.WeightedClick(SharedPM.Loot_LobbyButton, 1.0, 1.0, 1, 0, "left");
                                            break;

                                        case SceneType.OUT_OF_KEYS_OFFER:
                                            if (!flag3)
                                            {
                                                this.PushNote("Out of Keys [Adventure]", "AI will buy more keys or play other modes while waiting.");
                                                flag3 = true;
                                            }
                                            if (this.CurrentObjective != Objective.BUY_KEYS)
                                            {
                                                this.ChangeObjective(Objective.BUY_KEYS);
                                            }
                                            this.Escape();
                                            break;

                                        case SceneType.OUT_OF_KEYS_POPUP:
                                            if (!flag3)
                                            {
                                                this.PushNote("Out of Keys [Adventure]", "AI will buy more keys or play other modes while waiting.");
                                                flag3 = true;
                                            }
                                            this.HandleOutOfKey(scene.SceneType);
                                            break;

                                        case SceneType.TOWER_SELECT:
                                            this.UpdateTowerKeys();
                                            if (this.CurrentObjective == Objective.GOLD_CHAMBER)
                                            {
                                                if (this.TowerKeys > 0)
                                                {
                                                    this.WeightedClick(TowerSelectPM.GoldChamberButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                                else
                                                {
                                                    this.NextPossibleObjective();
                                                }
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.TOWER_START:
                                            this.UpdateTowerKeys();
                                            if (this.CurrentObjective == Objective.GOLD_CHAMBER)
                                            {
                                                if (this.TowerKeys > 0)
                                                {
                                                    if (!this.CheckMastery(scene.SceneType))
                                                    {
                                                        this.MasteryChecked = false;
                                                        this.SelectTeam(SceneType.TOWER_START);
                                                        this.WeightedClick(TowerStartPM.StartButton, 1.0, 1.0, 1, 0, "left");
                                                        SevenKnightsCore.Sleep(300);
                                                    }
                                                }
                                                else
                                                {
                                                    this.NextPossibleObjective();
                                                }
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.TOWER_FIGHT:
                                            this.PerformFightTatics(scene.SceneType);
                                            break;

                                        case SceneType.TOWER_LOST:
                                            this.GoldChamberAfterFight();
                                            this.Log("Your team lost the battle [Tower]", this.COLOR_DEATH);
                                            this.PushNote("You Lose! [Tower]", "Your team has lost a battle. Continuing AI.");
                                            this.WeightedClick(TowerLostPM.ReadyButton, 1.0, 1.0, 1, 0, "left");
                                            break;

                                        case SceneType.GOLD_CHAMBER_LOOT:
                                            this.GoldChamberAfterFight();
                                            if (this.CurrentObjective == Objective.GOLD_CHAMBER)
                                            {
                                                this.WeightedClick(GoldChamberLootPM.AgainButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            else
                                            {
                                                this.WeightedClick(SharedPM.Loot_LobbyButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            break;

                                        case SceneType.OUT_OF_SILVER_KEYS_POPUP:
                                            this.Escape();
                                            this.NextPossibleObjective();
                                            break;

                                        case SceneType.BATTLE_MODES:
                                            this.UpdateGold(scene.SceneType);
                                            this.UpdateRuby(scene.SceneType);
                                            this.UpdateHonor(scene.SceneType);
                                            if (this.CurrentObjective == Objective.ARENA)
                                            {
                                                this.WeightedClick(BattleModesPM.ArenaButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.ARENA_READY:
                                            this.UpdateArenaKeys();
                                            this.UpdateRuby(scene.SceneType);
                                            this.UpdateHonor(scene.SceneType);
                                            if (this.CurrentObjective == Objective.ARENA)
                                            {
                                                if (this.ArenaKeys > 0 || this.ArenaUseRuby())
                                                {
                                                    this.WeightedClick(ArenaReadyPM.ReadyButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                                else
                                                {
                                                    this.NextPossibleObjective();
                                                }
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.ARENA_START:
                                            this.UpdateArenaKeys();
                                            this.UpdateRuby(scene.SceneType);
                                            this.UpdateHonor(scene.SceneType);
                                            if (this.CurrentObjective == Objective.ARENA)
                                            {
                                                bool flag5 = this.ArenaUseRuby();
                                                if (this.ArenaKeys > 0 || flag5)
                                                {
                                                    if (!this.CheckMastery(scene.SceneType))
                                                    {
                                                        this.MasteryChecked = false;
                                                        this.WeightedClick(ArenaStartPM.StartButton, 1.0, 1.0, 1, 0, "left");
                                                        SevenKnightsCore.Sleep(300);
                                                    }
                                                }
                                                else
                                                {
                                                    this.NextPossibleObjective();
                                                }
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.ARENA_FIGHT:
                                            this.PerformFightTatics(scene.SceneType);
                                            break;

                                        case SceneType.ARENA_END:
                                            if (this.MatchMapping(ArenaEndPM.GetStrongerButton, 2))
                                            {
                                                this.Log("Arena Lose", this.COLOR_ARENA);
                                                this.ArenaAfterFight(false);
                                            }
                                            else
                                            {
                                                this.Log("Arena Victory", this.COLOR_ARENA);
                                                this.ArenaAfterFight(true);
                                            }
                                            if (this.CurrentObjective == Objective.ARENA)
                                            {
                                                this.WeightedClick(ArenaEndPM.QuickStartButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            else
                                            {
                                                this.WeightedClick(ArenaEndPM.LobbyButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            this.LongSleep(2000, 1000);
                                            break;

                                        case SceneType.ARENA_FULL_HONOR_POPUP:
                                            this.WeightedClick(ArenaFullHonorPopupPM.YesButton, 1.0, 1.0, 1, 0, "left");
                                            break;

                                        case SceneType.OUT_OF_SWORDS_POPUP:
                                            if (this.ArenaUseRuby())
                                            {
                                                this.Log(string.Format("Entering arena using Ruby ({0})", this.ArenaRubiesCount + 1), this.COLOR_ARENA);
                                                this.WeightedClick(OutOfSwordsPopupPM.EnterButton, 1.0, 1.0, 1, 0, "left");
                                                SevenKnightsCore.Sleep(1000);
                                                this.ArenaRubiesCount++;
                                            }
                                            else
                                            {
                                                this.Escape();
                                                this.NextPossibleObjective();
                                            }
                                            SevenKnightsCore.Sleep(1000);
                                            break;

                                        case SceneType.LEVEL_UP_DIALOG:
                                            this.Log("Player Level Up", this.COLOR_LEVEL_UP);
                                            if (this.AISettings.AD_Formation != Formation.None && this.AISettings.AD_HeroManagePositions != null && this.AISettings.AD_HeroManagePositions.Length > 0)
                                            {
                                                this.ChangeObjective(Objective.HERO_MANAGEMENT);
                                            }
                                            this.WeightedClick(LevelUpDialogPM.OkButton, 1.0, 1.0, 1, 0, "left");
                                            SevenKnightsCore.Sleep(300);
                                            break;

                                        case SceneType.LEVEL_30_DIALOG:
                                        case SceneType.LEVEL_30_MAX_DIALOG:
                                            this.Log("Hero Level 30", this.COLOR_LEVEL_30);
                                            if (this.AISettings.AD_Formation != Formation.None && this.AISettings.AD_HeroManagePositions != null && this.AISettings.AD_HeroManagePositions.Length > 0)
                                            {
                                                this.ChangeObjective(Objective.HERO_MANAGEMENT);
                                            }
                                            this.WeightedClick(Level30DialogPM.OkButton, 1.0, 1.0, 1, 0, "left");
                                            SevenKnightsCore.Sleep(300);
                                            break;

                                        case SceneType.HEROES:
                                            this.UpdateAdventureKeys(scene.SceneType);
                                            this.UpdateGold(scene.SceneType);
                                            this.UpdateRuby(scene.SceneType);
                                            if (this.CurrentObjective != Objective.HERO_MANAGEMENT && this.PreviousObjective != Objective.HERO_MANAGEMENT && this.CurrentObjective != Objective.SELL_HEROES && this.PreviousObjective != Objective.SELL_HEROES && this.AISettings.AD_Formation != Formation.None && this.AISettings.AD_HeroManagePositions != null && this.AISettings.AD_HeroManagePositions.Length > 0)
                                            {
                                                this.ChangeObjective(Objective.HERO_MANAGEMENT);
                                            }
                                            if (this.MatchMapping(HeroesPM.BlockingChatCloseButton, 2))
                                            {
                                                this.WeightedClick(HeroesPM.BlockingChatCloseButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            else if (this.CurrentObjective == Objective.HERO_MANAGEMENT)
                                            {
                                                if (this.AISettings.AD_ElementHeroesOnly)
                                                {
                                                    if (this.MatchMapping(HeroesPM.ElementButton, 2))
                                                    {
                                                        this.WeightedClick(HeroesPM.ElementButton, 1.0, 1.0, 1, 0, "left");
                                                        break;
                                                    }
                                                }
                                                else if (!this.MatchMapping(HeroesPM.ElementButton, 2))
                                                {
                                                    this.WeightedClick(HeroesPM.ElementButton, 1.0, 1.0, 1, 0, "left");
                                                    break;
                                                }
                                                this.ManageHeroes();
                                            }
                                            else if (this.CurrentObjective == Objective.SELL_HEROES)
                                            {
                                                if (!this.MatchMapping(HeroesPM.ElementButton, 2))
                                                {
                                                    this.WeightedClick(HeroesPM.ElementButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                                else
                                                {
                                                    this.SellHeroes();
                                                }
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.HEROES_SAME_TEAM_POPUP:
                                            this.Escape();
                                            break;

                                        case SceneType.HERO_JOIN:
                                            this.Escape();
                                            break;

                                        case SceneType.HERO_REMOVE:
                                            this.Escape();
                                            break;

                                        case SceneType.RAID_DRAGON:
                                            this.PushNote("The dragon appears!", "AI will fight the dragon or ignore it depending on your settings.");
                                            if (this.AISettings.RD_Enable)
                                            {
                                                this.ChangeObjective(Objective.RAID);
                                            }
                                            this.WeightedClick(RaidDragonPM.TapArea, 1.0, 1.0, 1, 0, "left");
                                            SevenKnightsCore.Sleep(500);
                                            break;

                                        case SceneType.RAID_LOBBY:
                                            if (this.CurrentObjective == Objective.RAID)
                                            {
                                                if (this.EnableRaidRewards)
                                                {
                                                    this.WeightedClick(RaidLobbyPM.DefeatedTab, 1.0, 1.0, 1, 0, "left");
                                                    SevenKnightsCore.Sleep(500);
                                                    this.CaptureFrame();
                                                    if (this.MatchMapping(RaidLobbyPM.EnterButton, 2))
                                                    {
                                                        this.WeightedClick(RaidLobbyPM.EnterButton, 1.0, 1.0, 1, 0, "left");
                                                    }
                                                    else
                                                    {
                                                        this.DoneRaid();
                                                    }
                                                }
                                                else
                                                {
                                                    this.WeightedClick(RaidLobbyPM.NewTab, 1.0, 1.0, 1, 0, "left");
                                                    SevenKnightsCore.Sleep(500);
                                                    this.CaptureFrame();
                                                    if (this.MatchMapping(RaidLobbyPM.EnterButton, 2))
                                                    {
                                                        this.WeightedClick(RaidLobbyPM.EnterButton, 1.0, 1.0, 1, 0, "left");
                                                        this.EnableRaidRewards = true;
                                                    }
                                                    else
                                                    {
                                                        this.DoneRaid();
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.RAID_READY:
                                            if (this.CurrentObjective == Objective.RAID &&
                                                (!this.AISettings.RD_EnableDragonLimit || this.ParseEntred() < this.AISettings.RD_DragonLimit)
                                                )
                                            {
                                                this.WeightedClick(RaidReadyPM.ReadyButton, 1.0, 1.0, 1, 0, "left");
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.RAID_START:
                                            if (this.CurrentObjective == Objective.RAID)
                                            {
                                                this.WeightedClick(RaidStartPM.StartButton, 1.0, 1.0, 1, 0, "left");
                                                SevenKnightsCore.Sleep(300);
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.RAID_FIGHT:
                                            this.PerformFightTatics(scene.SceneType);
                                            break;

                                        case SceneType.RAID_END:
                                            this.RaidAfterFight();
                                            this.PushNote("Raid has ended!", "AI will collect the reward and if there is any.");
                                            this.WeightedClick(RaidEndPM.AgainButton, 1.0, 1.0, 1, 0, "left");
                                            this.LongSleep(1000, 1000);
                                            break;

                                        case SceneType.RAID_REWARD:
                                            if (this.CurrentObjective == Objective.RAID)
                                            {
                                                if (this.MatchMapping(RaidRewardPM.RewardButtonRedIcon, 2))
                                                {
                                                    this.WeightedClick(RaidRewardPM.RewardButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                                else
                                                {
                                                    this.DoneRaid();
                                                }
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.RAID_REWARD_POPUP:
                                            this.DoneRaid();
                                            break;

                                        case SceneType.RAID_REWARD_FAILED_POPUP:
                                            this.DoneRaid();
                                            break;

                                        case SceneType.RAID_OUT_OF_KEYS_POPUP:
                                            if (!flag3)
                                            {
                                                this.PushNote("Out of Keys [Raid]", "AI will buy more keys or play other modes while waiting.");
                                                flag3 = true;
                                            }
                                            this.HandleOutOfKey(scene.SceneType);
                                            break;

                                        case SceneType.RAID_ALREADY_ENDED_POPUP:
                                            this.DoneRaid();
                                            break;

                                        case SceneType.ENTER_RAID_AGAIN_POPUP:
                                            this.DoneRaid();
                                            break;

                                        case SceneType.SELL_HERO_CONFIRM_POPUP:
                                            this.Escape();
                                            break;

                                        case SceneType.SELL_ITEM_POPUP:
                                            if (this.AISettings.RS_SellItems)
                                            {
                                                if (this.CurrentObjective != Objective.SELL_ITEMS)
                                                {
                                                    this.ChangeObjective(Objective.SELL_ITEMS);
                                                }
                                                this.SellItems();
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.SELL_ITEM_CONFIRM_POPUP:
                                            this.Escape();
                                            break;

                                        case SceneType.LOOT_HERO:
                                            this.Escape();
                                            break;

                                        case SceneType.LOOT_ITEM:
                                            this.Escape();
                                            break;

                                        case SceneType.SHOP:
                                            this.UpdateAdventureKeys(scene.SceneType);
                                            this.UpdateGold(scene.SceneType);
                                            this.UpdateRuby(scene.SceneType);
                                            this.UpdateHonor(scene.SceneType);
                                            if (this.CurrentObjective == Objective.BUY_KEYS)
                                            {
                                                this.BuyKeys();
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.SHOP_BUY_POPUP:
                                            this.Escape();
                                            break;

                                        case SceneType.SHOP_BUY_FAILED_POPUP:
                                            this.Escape();
                                            break;

                                        case SceneType.SHOP_PURCHASE_COMPLETE_POPUP:
                                            this.Escape();
                                            break;

                                        case SceneType.INBOX:
                                            this.UpdateAdventureKeys(scene.SceneType);
                                            this.UpdateGold(scene.SceneType);
                                            this.UpdateRuby(scene.SceneType);
                                            this.UpdateHonor(scene.SceneType);
                                            if (this.IsInboxEnabled())
                                            {
                                                if (this.CurrentObjective != Objective.COLLECT_INBOX && this.PreviousObjective != Objective.COLLECT_INBOX)
                                                {
                                                    this.ChangeObjective(Objective.COLLECT_INBOX);
                                                }
                                                if (this.CurrentObjective == Objective.COLLECT_INBOX)
                                                {
                                                    this.CollectInbox();
                                                }
                                                else
                                                {
                                                    this.Escape();
                                                }
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.INBOX_REWARDS_POPUP:
                                            this.WeightedClick(SharedPM.Rewards_OkButton, 1.0, 1.0, 1, 0, "left");
                                            break;

                                        case SceneType.INBOX_COLLECT_FAILED_POPUP:
                                            this.Escape();
                                            break;

                                        case SceneType.INBOX_SELECT_HERO:
                                            this.Escape();
                                            break;

                                        case SceneType.QUEST_SELECT:
                                            if (this.CurrentObjective == Objective.COLLECT_QUESTS && this.IsAnyQuestsEnabled())
                                            {
                                                bool flag6 = this.IsSpecialQuestsEnabled() && this.MatchMapping(QuestSelectPM.SpecialQuestAvailable, 4);
                                                bool flag7 = this.IsQuestsEnabled() && this.MatchMapping(QuestSelectPM.QuestAvailable, 4);
                                                if (this.CollectQuestsTotal == -1 || this.CollectQuestsCount == -1)
                                                {
                                                    this.CollectQuestsCount = 0;
                                                    this.CollectQuestsTotal = 0;
                                                    if (flag6)
                                                    {
                                                        this.CollectQuestsTotal++;
                                                    }
                                                    if (flag7)
                                                    {
                                                        this.CollectQuestsTotal++;
                                                    }
                                                }
                                                if (this.CollectQuestsCount == 0 && this.CollectQuestsTotal == 1)
                                                {
                                                    if (flag6)
                                                    {
                                                        this.WeightedClick(QuestSelectPM.SpecialQuestButton, 1.0, 1.0, 1, 0, "left");
                                                    }
                                                    else if (flag7)
                                                    {
                                                        this.WeightedClick(QuestSelectPM.QuestButton, 1.0, 1.0, 1, 0, "left");
                                                    }
                                                }
                                                else if (this.CollectQuestsCount == 0 && this.CollectQuestsTotal == 2)
                                                {
                                                    this.WeightedClick(QuestSelectPM.SpecialQuestButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                                else
                                                {
                                                    if (this.CollectQuestsCount != 1 || this.CollectQuestsTotal != 2)
                                                    {
                                                        this.DoneCollectAllQuests();
                                                        break;
                                                    }
                                                    this.WeightedClick(QuestSelectPM.QuestButton, 1.0, 1.0, 1, 0, "left");
                                                }
                                                this.LongSleep(1000, 1000);
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.SPECIAL_QUEST:
                                            this.UpdateAdventureKeys(scene.SceneType);
                                            this.UpdateGold(scene.SceneType);
                                            this.UpdateRuby(scene.SceneType);
                                            this.UpdateHonor(scene.SceneType);
                                            if (this.CurrentObjective == Objective.COLLECT_QUESTS && this.IsSpecialQuestsEnabled())
                                            {
                                                this.CollectSpecialQuests();
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.QUEST:
                                            this.UpdateAdventureKeys(scene.SceneType);
                                            this.UpdateGold(scene.SceneType);
                                            this.UpdateRuby(scene.SceneType);
                                            this.UpdateHonor(scene.SceneType);
                                            if (this.CurrentObjective == Objective.COLLECT_QUESTS && this.IsQuestsEnabled())
                                            {
                                                this.CollectQuests();
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.QUEST_REWARDS_POPUP:
                                            this.WeightedClick(SharedPM.Rewards_OkButton, 1.0, 1.0, 1, 0, "left");
                                            break;

                                        case SceneType.QUEST_COLLECT_FAILED_POPUP:
                                            this.Escape();
                                            break;

                                        case SceneType.SOCIAL_SELECT:
                                            if (this.CurrentObjective == Objective.SEND_HONORS && this.IsSendHonorsEnabled())
                                            {
                                                this.WeightedClick(SocialSelectPM.FriendsButton, 1.0, 1.0, 1, 0, "left");
                                                SevenKnightsCore.Sleep(500);
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.FRIENDS:
                                            this.UpdateAdventureKeys(scene.SceneType);
                                            this.UpdateGold(scene.SceneType);
                                            this.UpdateHonor(scene.SceneType);
                                            if (this.CurrentObjective == Objective.SEND_HONORS && this.IsSendHonorsEnabled())
                                            {
                                                this.SendHonors();
                                            }
                                            else
                                            {
                                                this.Escape();
                                            }
                                            break;

                                        case SceneType.SEND_HONOR_SENDING_POPUP:
                                            this.Escape();
                                            break;

                                        case SceneType.SEND_HONOR_FAILED_POPUP:
                                            this.WeightedClick(SendHonorFailedPopupPM.YellowTick, 1.0, 1.0, 1, 0, "left");
                                            break;

                                        case SceneType.SEND_HONOR_CONFIRM_POPUP:
                                            this.Escape();
                                            break;

                                        case SceneType.SEND_HONOR_FULL_POPUP:
                                            this.Escape();
                                            break;
                                    }
                                }
                            }
                        }
                        else if (this.AIProfiles.TMP_WaitingForKeys)
                        {
                            Random rnd = new Random();
            #if DEBUG
                            if ((this.AISettings.AD_Enable && this.AdventureKeys >= 1 && rnd.Next(1, (int)this.AdventureKeyTime.TotalMinutes) == 1) ||
                                (this.AISettings.AR_Enable && this.ArenaKeys >= 1 && rnd.Next(1, (int)this.ArenaKeyTime.TotalMinutes) == 1) ||
                                (this.AISettings.GC_Enable && this.TowerKeys >= 1 && rnd.Next(1, (int)this.TowerKeyTime.TotalMinutes) == 1) ||
                                (this.AISettings.RD_Enable && this.AdventureKeys >= 1 && rnd.Next(1, (int)this.AdventureKeyTime.TotalMinutes) == 1))
            #else
                            if ((this.AISettings.AD_Enable && this.AdventureKeys >= 10 && rnd.Next(1, (int)this.AdventureKeyTime.TotalSeconds) == 1) ||
                                (this.AISettings.AR_Enable && this.ArenaKeys >= 4 && rnd.Next(1, (int)this.ArenaKeyTime.TotalSeconds) == 1) ||
                                (this.AISettings.GC_Enable && this.TowerKeys >= 4 && rnd.Next(1, (int)this.TowerKeyTime.TotalSeconds) == 1) ||
                                (this.AISettings.RD_Enable && this.AdventureKeys >= 10 && rnd.Next(1, (int)this.AdventureKeyTime.TotalSeconds) == 1))
            #endif
                            {
                                int resumeIn = rnd.Next(1, 60);
                                this.Log("Resuming in " + resumeIn + " seconds");
                                Sleep(resumeIn * 1000);
                                this.BlueStacks.LaunchGame();
                                this.AIProfiles.TMP_WaitingForKeys = false;
                                this.Log("Keys sufficiently Replenished. Resuming");
                            }
                        }
                        if (!this.AIProfiles.TMP_WaitingForKeys &&
                            this.AISettings.GB_WaitForKeys &&
                            ((!this.AISettings.AD_Enable && !this.AISettings.RD_Enable) || this.AdventureKeys == 0) &&
                            (!this.AISettings.AR_Enable || this.ArenaKeys == 0) &&
                            (!this.AISettings.GC_Enable || this.TowerKeys == 0))
                        {
                            this.AIProfiles.TMP_WaitingForKeys = true;
                            this.Log("Waiting for keys to replenish");
                            this.BlueStacks.TerminateGame();
                        }
                        MousePos();
                    }
                    catch (Exception ex)
                    {
                        this.LogError(ex.Message);
                        this.LogError(ex.ToString());
                    }
                }
                this.OneSecTimer.Enabled = false;
                return;
            }
            errorMessage = "Seven Knights not installed in BlueStacks";
            this.LogError(errorMessage);
            this.SynchronizationContext.Send(delegate (object callback)
            {
                MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }, null);
        }