コード例 #1
0
ファイル: Village.cs プロジェクト: trananh1992/Coc-bot-Csharp
        public static void Idle()
        {
            Stopwatch sw = new Stopwatch();

            if (!GlobalVariables.fullArmy)
            {
                Main.Bot.WriteToOutput("~~~ Waiting for full army ~~~", GlobalVariables.OutputStates.Verified);
                while (!Barrack.CheckFullArmy(false))
                {
                    sw.Start();

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

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

                    Main.Bot.WriteToOutput("Going idle for 30 seconds...", GlobalVariables.OutputStates.Information);
                    Thread.Sleep(30000);
                    CollectResources();

                    Barrack.TrainTroops();
                    if (Barrack.CheckFullArmy(false))
                    {
                        break;
                    }

                    Thread.Sleep(1000);
                    DropTrophies();

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

                    sw.Stop();

                    double   idleTime = (double)sw.ElapsedMilliseconds / 1000;
                    TimeSpan ts       = TimeSpan.FromSeconds(idleTime);

                    string output = string.Format("Time Idle: {0:D2} hours {1:D2} minutes {2:D2} seconds", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
                    Main.Bot.WriteToOutput(output, GlobalVariables.OutputStates.Verified);
                }
            }
        }
コード例 #2
0
ファイル: Barrack.cs プロジェクト: trananh1992/Coc-bot-Csharp
        public static void TrainTroops()
        {
            var barracks     = DataCollection.BuildingPoints.Where(b => b.BuildingType == BuildingType.Barrack);
            var darkBarracks = DataCollection.BuildingPoints.Where(b => b.BuildingType == BuildingType.DarkBarrack);

            if (barracks.Count() <= 0)
            {
                return;                 // The DataCollection.BuildingPoints is empty. Something is wrong!
            }
            if (darkBarracks.Count() > 0)
            {
                return;                 // The DataCollection.BuildingPoints is empty. Something is wrong!
            }
            var barrackPos     = barracks.Select(x => new ClickablePoint(x.Coordinates)).ToArray();
            var darkBarrackPos = darkBarracks.Select(x => new ClickablePoint(x.Coordinates)).ToArray();
            //ClickablePoint[] barrackPos = new ClickablePoint[] { (ClickablePoint)Main.Bot.LocationBarrack1, (ClickablePoint)Main.Bot.LocationBarrack2, (ClickablePoint)Main.Bot.LocationBarrack3, (ClickablePoint)Main.Bot.LocationBarrack4 };
            //ClickablePoint[] darkBarrackPos = new ClickablePoint[] { (ClickablePoint)Main.Bot.LocationDarkBarrack1, (ClickablePoint)Main.Bot.LocationDarkBarrack2 };

            bool armyFull = false;

            // FF, do not change this to just checking if barrackPos[0].isEmpty. It needs to check if the x or y values are 0 as well to work.
            if (Main.Bot.IsUseBarracks1 && (barrackPos[0].IsEmpty || barrackPos[0].Point.X == 0 || barrackPos[0].Point.Y == 0))
            {
                Main.Bot.LocateBarracks();
            }

            // FF, do not change this to just checking if darkBarrackPos[0].isEmpty. It needs to check if the x or y values are 0 as well to work.
            if ((Main.Bot.IsUseDarkBarracks1 && (darkBarrackPos[0].IsEmpty || darkBarrackPos[0].Point.X == 0 || darkBarrackPos[0].Point.Y == 0)) || (Main.Bot.IsUseDarkBarracks2 && (darkBarrackPos[1].IsEmpty || darkBarrackPos[1].Point.X == 0 || darkBarrackPos[1].Point.Y == 0)))
            {
                Main.Bot.LocateDarkBarracks();
            }

            Main.Bot.WriteToOutput("Training Barracks Troops...");

            for (int i = 0; i < 4; i++)
            {
                // FF, do not change this to just checking if barrackPos[0].isEmpty. It needs to check if the x or y values are 0 as well to work.
                if (barrackPos[i].IsEmpty || barrackPos[i].Point.X == 0 || barrackPos[i].Point.Y == 0)
                {
                    Main.Bot.WriteToOutput(string.Format("Barrack {0} is not set...", i + 1));
                }
                else
                {
                    Tools.CoCHelper.Click(Data.ScreenData.TopLeftClient, 2, 200);
                    Thread.Sleep(500);

                    Tools.CoCHelper.Click(barrackPos[i], 1);
                    Thread.Sleep(500);

                    Point trainPos = Barrack.GetTrainTroopsButton();

                    if (trainPos.IsEmpty)
                    {
                        Main.Bot.WriteToOutput(string.Format("Barrack {0} is not available...", i + 1));
                    }
                    else
                    {
                        Tools.CoCHelper.Click(new ClickablePoint(trainPos));
                        Thread.Sleep(500);

                        armyFull = CheckFullArmy(true);

                        if (!armyFull)
                        {
                            Troop troop = GetTroopToBeTrainedInBarrack(i, false);

                            while (!CheckBarrackFull())
                            {
                                TrainIt(troop, 5);
                                Thread.Sleep(50);
                            }
                        }
                        else
                        {
                            Main.Bot.WriteToOutput("Barracks Full...", GlobalVariables.OutputStates.Normal);
                        }
                    }

                    Tools.CoCHelper.Click(Data.ScreenData.TopLeftClient, 2, 250);
                }
            }

            // Train Dark Barracks only if the army isn't full
            if (!armyFull)
            {
                Main.Bot.WriteToOutput("Training Dark Barracks Troops...");

                for (int i = 0; i < 2; i++)
                {
                    // FF, do not change this to just checking if darkBarrackPos[0].isEmpty. It needs to check if the x or y values are 0 as well to work.
                    if (darkBarrackPos[i].IsEmpty || darkBarrackPos[i].Point.X == 0 || darkBarrackPos[i].Point.Y == 0)
                    {
                        Main.Bot.WriteToOutput(string.Format("Dark Barrack {0} is not set...", i + 1));
                    }
                    else
                    {
                        Tools.CoCHelper.Click(Data.ScreenData.TopLeftClient, 2, 200);
                        Thread.Sleep(500);

                        Tools.CoCHelper.Click(darkBarrackPos[i], 1);
                        Thread.Sleep(500);

                        Point trainPos = GetTrainTroopsButton();

                        if (trainPos.IsEmpty)
                        {
                            Main.Bot.WriteToOutput(string.Format("Dark Barrack {0} is not available...", i + 1));
                        }
                        else
                        {
                            Tools.CoCHelper.Click(new ClickablePoint(trainPos));
                            Thread.Sleep(50);

                            if (!armyFull)
                            {
                                Troop troop = GetTroopToBeTrainedInBarrack(i, true);

                                while (!CheckBarrackFull())
                                {
                                    TrainIt(troop, 5);
                                    Thread.Sleep(50);
                                }
                            }
                        }

                        Tools.CoCHelper.Click(Data.ScreenData.TopLeftClient, 2, 250);
                    }
                }
            }

            Main.Bot.WriteToOutput("Training Troops Complete...");
        }
コード例 #3
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();
        }