private async Task ClaimRewards(Account acc)
        {
            await Task.Delay(AccountHelper.Delay());

            do
            {
                await DriverHelper.ClickByClassName(acc, "collect", false);
            }while (acc.Wb.Html.DocumentNode.Descendants("button").Any(x => x.HasClass("collect")));
        }
예제 #2
0
        /// <summary>
        /// Is called whenever a web browser loaded a new page.
        /// Usage: After navigation (has to execute) and after execution (click on button etc.)
        /// In first case execute the task, in second remove it.
        /// </summary>
        /// <param name="acc"></param>
        public static async Task PageLoaded(Account acc)
        {
            if (IsCaptcha(acc) || IsWWMsg(acc) || IsBanMsg(acc) || IsMaintanance(acc)) //Check if a captcha/ban/end of server/maintanance
            {
                acc.Wb.Log("Captcha/WW/Ban/Maintanance found! Stopping bot for this account!");
                acc.TaskTimer.Stop();
                return;
            }
            if (CheckCookies(acc))
            {
                await DriverHelper.ExecuteScript(acc, "document.getElementById('CybotCookiebotDialogBodyLevelButtonLevelOptinDeclineAll').click();");
            }
            if (CheckCookiesNew(acc))
            {
                await DriverHelper.ExecuteScript(acc, "document.getElementsByClassName('cmpboxbtnyes')[0].click();");
            }

            if (CheckContextualHelp(acc) &&
                acc.AccInfo.ServerVersion == Classificator.ServerVersionEnum.T4_5)
            {
                AddTaskIfNotExists(acc, new EditPreferences()
                {
                    ExecuteAt      = DateTime.Now.AddHours(-1),
                    TroopsPerPage  = 99,
                    ContextualHelp = true
                });
            }

            if (acc.AccInfo.Tribe == null && CheckSkipTutorial(acc))
            {
                await DriverHelper.ClickByClassName(acc, "questButtonSkipTutorial");
            }

            if (IsLoginScreen(acc)) //Check if you are on login page -> Login task
            {
                AddTask(acc, new LoginTask()
                {
                    ExecuteAt = DateTime.MinValue
                });
                return;
            }
            if (IsSysMsg(acc)) //Check if there is a system message (eg. Artifacts/WW plans appeared)
            {
                await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf1.php?ok");

                await Task.Delay(AccountHelper.Delay());
            }

            //TODO: limit this for performance reasons?
            PostLoadTasks(acc);
        }
예제 #3
0
        /// <summary>
        /// Tries to watch an Ad for +25% faster upgrade
        /// </summary>
        /// <param name="acc">Account</param>
        /// <returns>Whether bot watched the ad</returns>
        private async Task <bool> TryFastUpgrade(Account acc)
        {
            if (!await DriverHelper.ClickByClassName(acc, "videoFeatureButton green", false))
            {
                return(false);
            }

            // Accept ads
            if (await DriverHelper.ClickByName(acc, "adSalesVideoInfoScreen", false))
            {
                await DriverHelper.ExecuteScript(acc, "jQuery(window).trigger('showVideoWindowAfterInfoScreen')");
            }

            // Has to be a legit "click"
            acc.Wb.Driver.FindElementById("videoFeature").Click();

            var timeout = DateTime.Now.AddSeconds(100);

            do
            {
                await System.Threading.Tasks.Task.Delay(1000);

                if (timeout < DateTime.Now)
                {
                    return(false);
                }
            }while (acc.Wb.Driver.Url.Contains("build.php"));

            // Don't show again
            acc.Wb.UpdateHtml();
            if (acc.Wb.Html.GetElementbyId("dontShowThisAgain") != null)
            {
                await DriverHelper.ClickById(acc, "dontShowThisAgain");

                await DriverHelper.ClickByClassName(acc, "dialogButtonOk ok");
            }
            return(true);
        }
예제 #4
0
        /// <summary>
        /// Tries to watch an Ad for +25% faster upgrade
        /// </summary>
        /// <param name="acc">Account</param>
        /// <returns>Whether bot watched the ad</returns>
        private async Task <bool> TryFastUpgrade(Account acc)
        {
            if (!await DriverHelper.ClickByClassName(acc, "videoFeatureButton green", false))
            {
                return(false);
            }
            await System.Threading.Tasks.Task.Delay(AccountHelper.Delay());

            // Confirm
            acc.Wb.UpdateHtml();
            if (acc.Wb.Html.DocumentNode.SelectSingleNode("//input[@name='adSalesVideoInfoScreen']") != null)
            {
                await DriverHelper.ClickByName(acc, "adSalesVideoInfoScreen");

                await System.Threading.Tasks.Task.Delay(AccountHelper.Delay());

                await DriverHelper.ExecuteScript(acc, "jQuery(window).trigger('showVideoWindowAfterInfoScreen')");

                await System.Threading.Tasks.Task.Delay(AccountHelper.Delay());
            }

            // Has to be a legit "click"
            acc.Wb.Driver.FindElementById("videoFeature").Click();

            // wait for finish watching ads
            var timeout = DateTime.Now.AddSeconds(100);

            do
            {
                await System.Threading.Tasks.Task.Delay(3000);

                //skip ads from Travian Games
                //they use ifarme to emebed ads video to their game
                acc.Wb.UpdateHtml();
                if (acc.Wb.Html.GetElementbyId("videoArea") != null)
                {
                    acc.Wb.Driver.SwitchTo().Frame(acc.Wb.Driver.FindElementById("videoArea"));
                    // trick to skip
                    await DriverHelper.ExecuteScript(acc, "var video = document.getElementsByTagName('video')[0];video.currentTime = video.duration - 1;", false, false);

                    //back to first page
                    acc.Wb.Driver.SwitchTo().DefaultContent();
                }
                if (timeout < DateTime.Now)
                {
                    return(false);
                }
            }while (acc.Wb.Driver.Url.Contains("build.php"));

            // Don't show again
            acc.Wb.UpdateHtml();
            if (acc.Wb.Html.GetElementbyId("dontShowThisAgain") != null)
            {
                await DriverHelper.ClickById(acc, "dontShowThisAgain");

                await System.Threading.Tasks.Task.Delay(AccountHelper.Delay());

                await DriverHelper.ClickByClassName(acc, "dialogButtonOk ok");
            }

            return(true);
        }