예제 #1
0
        public static bool CheckObstacles()
        {
            ClickablePoint messagePos = CoCHelper.SearchPixelInRect(ScreenData.Inactivity);

            if (!messagePos.IsEmpty)
            {
                CoCHelper.Click(ScreenData.ReloadButton);
                Thread.Sleep(7000);
                return(true);
            }

            if (CoCHelper.CheckPixelColor(ScreenData.Attacked))
            {
                CoCHelper.Click(ScreenData.AttackedBtn);
                return(true);
            }

            // The main screen
            if (CoCHelper.CheckPixelColor(ScreenData.IsMainGrayed))
            {
                CoCHelper.Click(ScreenData.TopLeftClient);
                return(true);
            }

            // If we have a screen with a small x to cancel it, like when you start a fight.
            if (CoCHelper.CheckPixelColor(ScreenData.SomeXCancelBtn))
            {
                CoCHelper.Click(ScreenData.SomeXCancelBtn);
                return(true);
            }

            // If a fight is on going, than cancel it.
            if (CoCHelper.CheckPixelColor(ScreenData.CancelFight) || CoCHelper.CheckPixelColor(ScreenData.CancelFight2))
            {
                CoCHelper.Click(ScreenData.CancelFight);
                return(true);
            }

            if (CoCHelper.CheckPixelColorBad(new Point(331, 330), Color.FromArgb(240, 160, 59), 20))
            {
                CoCHelper.ClickBad(new Point(331, 330), 1);
                Thread.Sleep(1000);
                return(true);
            }

            if (CoCHelper.CheckPixelColorBad(new Point(429, 519), Color.FromArgb(184, 227, 95), 20))
            {
                CoCHelper.ClickBad(new Point(429, 519), 1);
                return(true);
            }

            if (CoCHelper.CheckPixelColorBad(new Point(71, 530), Color.FromArgb(192, 0, 0), 20))
            {
                CoCHelper.ClickBad(new Point(331, 330), 1);
                ReturnHome(false, false);
                return(true);
            }

            return(false);
        }
예제 #2
0
        public static void WaitForMainScreen()
        {
            Main.Bot.WriteToOutput("Waiting for Main Screen");
            for (int i = 0; i < 150; i++)
            {
                if (!CoCHelper.CheckPixelColor(ScreenData.IsMain))
                {
                    Thread.Sleep(2000);
                    if (CheckObstacles())
                    {
                        i = 0;
                    }
                }
                else
                {
                    return;
                }
            }

            Main.Bot.WriteToOutput("Unable to load Clash of Clans, Restarting...");

            ClickablePoint appPos = GetAppPos();

            CoCHelper.Click(appPos, 1);

            Thread.Sleep(10000);
        }
예제 #3
0
        public static void PrepareSearch()
        {
            Main.Bot.WriteToOutput("Preparing Search...");

            CoCHelper.Click(ScreenData.AttackButton);
            Thread.Sleep(1000);
            CoCHelper.Click(ScreenData.MatchButton);
            Thread.Sleep(3000);

            if (CoCHelper.CheckPixelColor(ScreenData.HasShield))
            {
                CoCHelper.Click(ScreenData.BreakShield);
            }
        }
예제 #4
0
        public static void CheckMainScreen()
        {
            Main.Bot.WriteToOutput(Properties.Resources.OutputTryingToLocateMainScreen, GlobalVariables.OutputStates.Information);

            while (!CoCHelper.CheckPixelColor(ScreenData.IsMain))
            {
                Thread.Sleep(1000);

                if (!CheckObstacles())
                {
                    ClickablePoint appPos = GetAppPos();
                    CoCHelper.Click(appPos, 1);
                }

                WaitForMainScreen();
            }

            Main.Bot.WriteToOutput("Main Screen Located", GlobalVariables.OutputStates.Information);
        }
        /// <summary>
        /// Make Troop Specific Donations.
        /// </summary>
        /// <param name="troop">The troop.</param>
        private static void DonateCCTroopSpecific(TroopModel troop)
        {
            // TODO: Fix GetDonationButton() then implement actual donating

            CoCHelper.Click(ScreenData.TopLeftClient, 2, 50);    // Click out of anything
            Thread.Sleep(300);
            CoCHelper.Click(ScreenData.OpenChatBtn);             // Click Green Chat Tab
            Thread.Sleep(300);
            CoCHelper.Click(ScreenData.IsClanTabSelected);       // Clicks Clan Chat Tab
            Thread.Sleep(300);

            ClickablePoint donatePos;
            ClickablePoint showMore;

            do
            {
                donatePos = GetDonateButton();
                showMore  = GetNotificationButton();

                MessageBox.Show(donatePos.Point.X + "x" + donatePos.Point.Y);

                if (donatePos.IsEmpty)
                {
                    if (showMore.IsEmpty)
                    {
                        break;
                    }
                    CoCHelper.Click(showMore);
                    Thread.Sleep(500);
                }
                else
                {
                    MessageBox.Show(donatePos.Point.X + "x" + donatePos.Point.Y);
                    // Donate
                }
            } while (!showMore.IsEmpty);

            Main.Bot.WriteToOutput("Finished donating...");


            //if (!donatePos.IsEmpty)
            //{
            //    string requestText = ReadText.GetString(donatePos.Point.Y - 28);

            //    if (string.IsNullOrEmpty(requestText))
            //        requestText = ReadText.GetString(donatePos.Point.Y - 17);
            //    else
            //        requestText = requestText + Environment.NewLine + ReadText.GetString(donatePos.Point.Y - 17);

            //    Main.Bot.WriteToOutput("Requested Troops: " + requestText, GlobalVariables.OutputStates.Information);

            //    string[] str = troop.DonateKeywords.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

            //    for (int i = 0; i < str.Length; i++)
            //    {
            //        if (requestText.Contains(str[i]))
            //        {
            //            ClickablePoint showMore;

            //            do
            //            {
            //                ClickablePoint donateBtn = GetDonateButton();
            //                showMore = GetNotificationButton();

            //                if (donateBtn.IsEmpty)
            //                {
            //                    if (showMore.IsEmpty)
            //                    {
            //                        Main.Bot.WriteToOutput("No Donation Opportunities For " + troop.Name + "s...", GlobalVariables.OutputStates.Normal);
            //                        break;
            //                    }
            //                }
            //                else
            //                {
            //                    //FIX
            //                    Main.Bot.WriteToOutput(string.Format("Donating {0} {1}s...", troop.MaxDonationsPerRequest, troop.Troop.Name()), GlobalVariables.OutputStates.Verified);

            //                    Tools.CoCHelper.Click(donateBtn);
            //                    ClickablePoint barb = new ClickablePoint(donateBtn.Point.X + 108, donateBtn.Point.Y - 58);
            //                    Tools.CoCHelper.Click(barb, troop.MaxDonationsPerRequest);

            //                    if (!showMore.IsEmpty)
            //                    {
            //                        Tools.CoCHelper.Click(showMore);
            //                        Thread.Sleep(500);
            //                        showMore = GetNotificationButton();
            //                    }
            //                }

            //            } while (!showMore.IsEmpty);
            //        }
            //    }
            //}
            //else
            //    Main.Bot.WriteToOutput("No clan members to donate to...", GlobalVariables.OutputStates.Normal);

            Tools.CoCHelper.Click(ScreenData.CloseChat);
        }
예제 #6
0
        public static bool VillageSearch()
        {
            switch (Main.Bot.SelectedAttackMode)
            {
            case AttackMode.AllBases:
                Main.Bot.WriteToOutput("============Searching For All Bases============", GlobalVariables.OutputStates.Information);
                break;

            case AttackMode.DeadBases:
                Main.Bot.WriteToOutput("============Searching For Dead Bases============", GlobalVariables.OutputStates.Information);
                break;

            case AttackMode.WeakBases:
                Main.Bot.WriteToOutput("============Searching For Weak Bases============", GlobalVariables.OutputStates.Information);
                break;
            }

            Main.Bot.WriteToOutput("~Gold: " + Main.Bot.MinimumGold + "; Elixir: " + Main.Bot.MinimumElixir + "; Dark Elixir: " + Main.Bot.MinimumDarkElixir + "; Trophies: " + Main.Bot.MinimumTrophyCount + ";");

            while (true)
            {
                var timeout = 0;
                while (!CoCHelper.CheckPixelColor(ScreenData.NextBtn))
                {
                    if (timeout >= 20) // After 10 seconds
                    {
                        return(false);
                    }

                    timeout++;
                    Thread.Sleep(500);
                }

                if (CompareResources())
                {
                    if (Main.Bot.SelectedAttackMode.Equals(AttackMode.DeadBases))
                    {
                        if (CheckDeadBase())
                        {
                            Main.Bot.WriteToOutput("~~~~~~~ Dead Base Found! ~~~~~~~");
                            return(true);
                        }

                        Main.Bot.WriteToOutput("~~~~~~~ Not Dead Base, Skipping ~~~~~~~");
                        CoCHelper.Click(ScreenData.NextBtn);
                    }
                    else if (Main.Bot.SelectedAttackMode.Equals(AttackMode.WeakBases))
                    {
                        if (CheckWeakBase())
                        {
                            Main.Bot.WriteToOutput("~~~~~~~ Weak Base Found! ~~~~~~~");
                            return(true);
                        }

                        Main.Bot.WriteToOutput("~~~~~~~ Not Weak Base, Skipping ~~~~~~~");
                        CoCHelper.Click(ScreenData.NextBtn);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    CoCHelper.Click(ScreenData.NextBtn);
                    Thread.Sleep(1000);
                }
            }
        }
예제 #7
0
 void ICocBot.Click(int x, int y, int delayInMs, int nbClicks)
 {
     CoCHelper.Click(new Data.ClickablePoint(x, y), nbClicks, delayInMs);
 }
 static public bool SelectDropTroop(int buttonNumber)
 {
     return(CoCHelper.Click(DropTroopPixelByPosition(buttonNumber)));
 }
예제 #9
0
        /// <summary>
        /// Initializes the Bot.
        /// </summary>
        public static void Initialize(MainViewModel vm)
        {
            // Store in properties so we can access in the SubFunctions
            Bot = vm;
            Bot.ClearOutput();

            Bot.WriteToOutput(string.Format(Resources.OutputWelcomeMessage, Resources.AppName));
            Bot.WriteToOutput(Resources.OutputBotIsStarting);

            // Check if BlueStacks is running
            if (!BlueStacksHelper.IsBlueStacksRunning)
            {
                Bot.WriteToOutput(Resources.OutputBSNotFound, GlobalVariables.OutputStates.Error);

                Bot.IsExecuting = false;
                return;
            }

            if (!BlueStacksHelper.IsRunningWithRequiredDimensions)
            {
                Bot.WriteToOutput(Resources.OutputBSNotRunningWithDimensions);
                Bot.WriteToOutput(Resources.OutputBSApplyDimensionsIntoRegistry);

                if (!BlueStacksHelper.SetDimensionsIntoRegistry())
                {
                    // Woops! Something went wrong, log the error!
                    Bot.WriteToOutput(Resources.OutputBSApplyDimensionsError, GlobalVariables.OutputStates.Error);

                    Bot.IsExecuting = false;
                    return;
                }
                else
                {
                    Bot.WriteToOutput(Resources.OutputBSAppliedDimensionsIntoRegistry);
                }

                // Restart BlueStacks
                // Wait until restart and continue...

                BlueStacksHelper.ActivateBlueStacks();
            }

            CreateDirectory(GlobalVariables.LogPath);
            CreateDirectory(GlobalVariables.ScreenshotZombieAttacked);
            CreateDirectory(GlobalVariables.ScreenshotZombieSkipped);

            WriteLicense();

            // Run Everything related to the bot in the background
            var thread = new Thread(() =>
            {
                while (Bot.IsExecuting)
                {
                    FastFindWrapper.SetHWnd(BlueStacksHelper.GetBlueStacksWindowHandle(), true);

                    MainScreen.CheckMainScreen();
                    Thread.Sleep(1000);

                    MainScreen.ZoomOut();
                    Thread.Sleep(1000);

                    CoCHelper.Click(ScreenData.OpenChatBtn);
                    Thread.Sleep(1000);
                    string str = ReadText.GetString(151);
                    System.Windows.MessageBox.Show(str);

                    Village.ReArmTraps();
                    Thread.Sleep(1000);

                    Barrack.TrainTroops();
                    Thread.Sleep(1000);

                    Barrack.Boost();
                    Thread.Sleep(1000);

                    RequestAndDonate.RequestTroops();
                    Thread.Sleep(1000);

                    RequestAndDonate.DonateCC();
                    Thread.Sleep(1000);

                    Village.CollectResources();
                    Thread.Sleep(1000);

                    Village.UpgradeWalls();
                    Thread.Sleep(1000);

                    Village.Idle();
                    Thread.Sleep(1000);

                    //Attack.AttackMain();
                }
                ;
            })
            {
                IsBackground = true
            };

            thread.Start();
        }