示例#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);
        }
        public static ClickablePoint GetDonateButton()
        {
            int left   = ScreenData.ChatArea.Left;
            int top    = ScreenData.ChatArea.Top;
            int right  = ScreenData.ChatArea.Right;
            int bottom = ScreenData.ChatArea.Bottom;
            int count  = 0;

            do
            {
                DetectableArea area = new DetectableArea(left, top, right, bottom, ScreenData.ChatArea.Color, ScreenData.ChatArea.ShadeVariation);
                ClickablePoint p1   = CoCHelper.SearchPixelInRect(area);

                if (!p1.IsEmpty && !(p1.Point.X == -1 || p1.Point.Y == -1))
                {
                    return(p1);
                }

                if (count >= 100)
                {
                    break;
                }


                if (!p1.IsEmpty && !(p1.Point.X == -1 || p1.Point.Y == -1))
                {
                    top = p1.Point.Y;
                }

                count++;
            } while (true);

            return(new ClickablePoint());
        }
示例#3
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);
        }
示例#4
0
        public App()
        {
            FieldInfo colorCacheField = typeof(SystemColors).GetField("_colorCache", BindingFlags.Static | BindingFlags.NonPublic);

            Color[] _colorCache = (Color[])colorCacheField.GetValue(typeof(SystemColors));
            _colorCache[14] = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            UI.Services.ServiceInjector.InjectServices();

            CoCHelper.Initialize();
        }
示例#5
0
        public static void ReturnHome(bool takeSS = true, bool goldChangeCheck = true)
        {
            if (goldChangeCheck)
            {
//TODO:         CHECK KING AND QUEENS POWER
            }

//TODO:     SET KING AND QUEEN POWER TO FALSE
            Main.Bot.WriteToOutput("Returning Home...");

            CoCHelper.ClickBad(new Point(62, 519), 1);
            Thread.Sleep(500);
            CoCHelper.ClickBad(new Point(512, 394), 1);
            Thread.Sleep(2000);

            if (takeSS)
            {
                Main.Bot.WriteToOutput("Taking snapshot of your loot");

                DateTime now  = DateTime.Now;
                string   date = string.Format("{0}.{1}.{2}", now.Day, now.Month, now.Year);
                string   time = string.Format("{0}.{1}", now.Hour, now.Minute);
                CoCHelper.MakeFullScreenCapture(string.Format("{0}/{1} at {2}", GlobalVariables.LogPath, date, time));
            }

            Thread.Sleep(2000);
            CoCHelper.ClickBad(new Point(428, 544), 1);

            int counter = 0;

            do
            {
                Thread.Sleep(2000);
                if (CoCHelper.CheckPixelColorBad(new Point(284, 28), Color.FromArgb(65, 177, 205), 20))
                {
                    CoCHelper.ClickBad(new Point(331, 330), 1);
//TODO:             _GUICtrlEdit_SetText($txtLog, "")
                    return;
                }

                counter++;

                if (counter >= 50)
                {
                    Main.Bot.WriteToOutput("Cannot return home...");

                    CheckMainScreen();
                    return;
                }
            } while (true);
        }
示例#6
0
        public static ClickablePoint GetAppPos()
        {
            ClickablePoint p1 = CoCHelper.SearchPixelInRect(ScreenData.ClashApp);

            if (CoCHelper.IsInColorRange(new ClickablePoint(p1.Point.X + ScreenData.ClashApp2.Point.X, p1.Point.Y + ScreenData.ClashApp2.Point.Y), ScreenData.ClashApp2.Color, ScreenData.ClashApp2.ShadeVariation))
            {
                if (CoCHelper.IsInColorRange(new ClickablePoint(p1.Point.X + ScreenData.ClashApp3.Point.X, p1.Point.Y + ScreenData.ClashApp3.Point.Y), ScreenData.ClashApp3.Color, ScreenData.ClashApp3.ShadeVariation))
                {
                    return(p1);
                }
            }

            return(new ClickablePoint());
        }
示例#7
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);
            }
        }
示例#8
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);
        }
        static public Troop IdentifyTroopKind(int buttonNumber)
        {
            Color troopPixel = CoCHelper.GetPixelColor(DropTroopPixelByPosition(buttonNumber));

            if (CoCHelper.SameColor(troopPixel, Color.FromArgb(0xF8B020), 5))
            {
                return(Troop.Barbarian);
            }
            if (CoCHelper.SameColor(troopPixel, Color.FromArgb(0xD83F68), 5))
            {
                return(Troop.Archer);
            }
            if (CoCHelper.SameColor(troopPixel, Color.FromArgb(0x7BC950), 5))
            {
                return(Troop.Goblin);
            }
            if (CoCHelper.SameColor(troopPixel, Color.FromArgb(0xF8D49E), 5))
            {
                return(Troop.Giant);
            }
            if (CoCHelper.SameColor(troopPixel, Color.FromArgb(0x60A4D0), 5))
            {
                return(Troop.WallBreaker);
            }
            if (CoCHelper.SameColor(troopPixel, Color.FromArgb(0xF8EB79), 5))
            {
                return(Troop.King);
            }
            if (CoCHelper.IsInColorRange(new ClickablePoint(68 + (72 * buttonNumber), 588), Color.FromArgb(0x7031F0), 5))
            {
                return(Troop.Queen);
            }
            if (CoCHelper.IsInColorRange(new ClickablePoint(68 + (72 * buttonNumber), 585), Color.FromArgb(0x68ACD4), 5))
            {
                return(Troop.CastleClan);
            }
            if (CoCHelper.IsInColorRange(new ClickablePoint(68 + (72 * buttonNumber), 632), Color.FromArgb(0x0426EC), 5))
            {
                return(Troop.SpellLightning);
            }
            return(Troop.None);
        }
示例#10
0
        public static void ZoomOut()
        {
            Main.Bot.WriteToOutput("Zooming Out");

            int count = 0;

            while (!CoCHelper.SameColor(CoCHelper.GetPixelColor(ScreenData.TopLeftClient), Color.Black))
            {
                if (count >= 15)
                {
                    break;
                }
                else
                {
                    KeyboardHelper.SendVirtualKeyToBS(KeyboardHelper.VirtualKeys.VK_DOWN);
                    Thread.Sleep(300);
                    count++;
                }
            }

            Main.Bot.WriteToOutput("Zoomed Out");
        }
        /// <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);
        }
示例#12
0
 public bool CheckFrom(int x, int y)
 {
     return(CoCHelper.CheckPixelColor(new DetectablePoint(x + DeltaX, y + DeltaY, Color, ShadeVariation)));
 }
示例#13
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);
                }
            }
        }
示例#14
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)));
 }
示例#16
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();
        }