コード例 #1
0
        private bool Upgraded()
        {
            Thread.Sleep(2000);
            Utils.doScreenShoot(tempImgName);
            var sb = new StringBuilder();

            sb.Append($"-input {tempImgName} ");
            sb.Append($"-name g1 -match data\\check\\upgradeWithEliButton.png 400 ");
            sb.Append($" -name g2 -match data\\check\\upgradeWithGoldButton.png 400 ");
            var btns = context.GetAppInfo(sb.ToString());

            foreach (var btn in btns)
            {
                context.DebugLog("           check train button " + btn);
            }
            btns = btns.OrderBy(r => r.cmpRes).ToList();
            if (btns.FirstOrDefault() != null)
            {
                var btn   = btns.First();
                var fname = btn.extraInfo == "g1" ? "upgradeWithEliButton.png" : "upgradeWithGoldButton.png";
                context.LogMatchAnalyst($"UPGRADING -match {fname} 400", btn.cmpRes);
                context.MoveMouseAndClick(btn.x + 20, btn.y + 20);
                return(true);
            }
            return(false);
        }
コード例 #2
0
ファイル: StandardClicks.cs プロジェクト: gzhangx/ccauto
        public List <CommandInfo> Processing()
        {
            Utils.doScreenShoot(tempImgName);
            var sb = new StringBuilder();

            sb.Append($"-input {tempImgName} ");
            foreach (var clk in clicks)
            {
                sb.Append($"-name {clk.Desc} -match {clk.ImageName} {clk.Threadshold} ");
            }
            var results  = context.GetAppInfo(sb.ToString());
            var topMatch = results.Where(r => r.decision == "true" &&
                                         r.extraInfo != null &&
                                         r.extraInfo.StartsWith("PRMXYCLICK_STD_")).OrderBy(r => r.cmpRes).FirstOrDefault();

            if (topMatch != null)
            {
                var clk = clicks.FirstOrDefault(r => r.Desc == topMatch.extraInfo);
                if (clk == null)
                {
                    context.InfoLog("!!!!!!!!!!!!!!!!!! Error: Failed to get match data " + sb.ToString() + " " + topMatch);
                }
                context.MoveMouseAndClick(topMatch.x + clk.point.x, topMatch.y + clk.point.y);
                context.InfoLog("StandClick topMatch " + topMatch);
                context.LogMatchAnalyst($"-name {clk.Desc} -match {clk.ImageName} {clk.Threadshold} ", topMatch.cmpRes);
            }
            return(results);
        }
コード例 #3
0
        private bool CheckMatchAndAct(string img, int offx, int offy, int repeat = 1)
        {
            Utils.doScreenShoot(tempImgName);
            var sb = new StringBuilder();

            sb.Append($"-input {tempImgName} ");
            sb.Append($"-name g1 -match data\\check\\{img} ");
            var btns = context.GetAppInfo(sb.ToString());

            foreach (var btn in btns)
            {
                context.DebugLog("           check rearmall " + btn);
            }
            btns = btns.Where(r => r.decision == "true").OrderBy(r => r.cmpRes).ToList();
            if (btns.FirstOrDefault() != null)
            {
                var btn = btns.First();
                context.LogMatchAnalyst(sb.ToString(), btn.cmpRes);
                context.MoveMouseAndClick(btn.x + offx, btn.y + offy);
                while (repeat > 0)
                {
                    context.MouseClick();
                    repeat--;
                    if (repeat != 0)
                    {
                        //btns = Utils.GetAppInfo(sb.ToString());
                        //btn = btns.FirstOrDefault(r => r.decision == "true");
                        //if (btn == null) break;
                    }
                }
                return(true);
            }
            return(false);
        }
コード例 #4
0
ファイル: AutoResourceLoader.cs プロジェクト: gzhangx/ccauto
        public List <CommandInfo> Processing(Func <ImgChecksAndTags, bool> tagCheck = null, bool doCenter = true)
        {
            Utils.doScreenShoot(_imgName);
            var sb = new StringBuilder();

            sb.Append($"-input {_imgName} -top {topX} ");
            foreach (var clk in clicks)
            {
                if (tagCheck != null)
                {
                    if (!tagCheck(clk))
                    {
                        continue;
                    }
                }
                sb.Append($"-name {clk.ImageName} -match {clk.ImageName} {clk.Threadshold} ");
            }
            var results = Utils.GetAppInfo(sb.ToString(), context);

            results.ForEach(r =>
            {
                r.imgInfo = clicks.FirstOrDefault(c => c.ImageName == r.extraInfo);
                if (r.imgInfo != null && doCenter)
                {
                    r.x = r.x + (r.imgInfo.center.x);
                    r.y = r.y + (r.imgInfo.center.y);
                }
            });
            return(results.OrderBy(x => x.cmpRes).ToList());
        }
コード例 #5
0
 public static List <CommandInfo> GetNameAtPoint(ProcessingContext context, ccPoint loc)
 {
     context.MoveMouseAndClick(loc);
     context.Sleep(1000);
     Utils.doScreenShoot(tempImgName);
     return(context.GetAppInfo());
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: gzhangx/ccauto
        static void TestAccounts(ProcessingContext context)
        {
            Utils.doScreenShoot("tstimgs\\tmptesttest.png");
            var actr = ProcessorMapByText.canUpgrade(context, "tstimgs\\tmptesttest.png", 0);

            Console.WriteLine(actr.upgrade);

            /*
             * for (int i = 1; i <= 4; i++)
             * {
             *  //generate mask
             *  //Utils.GetAppInfo($"-name data\\accounts\\img_act{i}.png -input tstimgs\\full_act_full_{i}.png -matchRect 80,30,100,27_200 -imagecorp");
             * }
             * for (int i = 1; i <= 4; i++)
             * {
             *  //generate mask
             *  //Utils.GetAppInfo($"-name data\\accounts\\img_act{i}.png -input tstimgs\\full_act_full_{i}.png -matchRect 80,30,100,27_200 -imagecorp");
             *  var res = context.GetAppInfo($"-name cmpact{i} -input tstimgs\\accountFull_1.png {SwitchAccount.acctNameMatchRect} -match data\\accounts\\img_act{i}.png 10000");
             *  foreach (var r in res)
             *  {
             *      Console.WriteLine(r);
             *  }
             * }
             */
        }
コード例 #7
0
        int getNumBuilders()
        {
            Utils.doScreenShoot(tempImgName);
            var cmdres = context.GetAppInfo();

            return(ActionUpgrade.NumBuilders(context, cmdres));
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: gzhangx/ccauto
        private static void GenerateAccountPics(ProcessingContext context, int who)
        {
            context.DebugLog("------------------Generate account pics");
            context.GetToEntrance();
            var fullImg = $"tstimgs\\accountFull_{who}.png";

            Utils.doScreenShoot(fullImg);
            //Utils.GetAppInfo($"-name data\\accounts\\img_act{who}.png -input {fullImg} {SwitchAccount.acctNameMatchRect} -imagecorp");
        }
コード例 #9
0
ファイル: SwitchAccount.cs プロジェクト: gzhangx/ccauto
        public int CheckAccount()
        {
            const string tempName = "tstimgs\\tempFullScreen.png";

            Utils.doScreenShoot(tempName);
            const string tempPartName = "tstimgs\\tempName.png";

            context.GetAppInfo($"-name {tempPartName} -input {tempName} {acctNameMatchRect} -imagecorp");
            return(CheckAccountWithImage(tempPartName));
        }
コード例 #10
0
        protected virtual CommandInfo FindSpotOnStep(StepInfo cur, string printDebug = "")
        {
            var fullInputPath = $"{imgdir}\\{cur.inputName}";
            var fullcmd       = $"-input {fullInputPath} {cur.cmd.Replace("-match ", "-match data\\check\\")}";

            context.DebugLog($"{printDebug}Doing step {cur.name} {fullcmd}");
            Utils.doScreenShoot(fullInputPath);
            var found = FindSpot(fullcmd, 1, printDebug);

            return(found);
        }
コード例 #11
0
        protected void DonateArchier()
        {
            Utils.doScreenShoot(ProcessorMapByText.tempImgName);
            var dw    = Utils.GetAppInfo($"-input {ProcessorMapByText.tempImgName} -name dw  -match data\\check\\donate_archer.png 300", context);
            var dwbtn = dw.FirstOrDefault(dwf => dwf.decision == "true");

            if (dwbtn != null)
            {
                context.MoveMouseAndClick(50 + dwbtn.x, 50 + dwbtn.y);
                for (int cli = 0; cli < 5; cli++)
                {
                    context.MouseClick();
                }
            }
        }
コード例 #12
0
        public static CommandInfo canUpgrade(ProcessingContext context, int numBuilders)
        {
            context.MouseMouseTo(0, 0);
            string imgName = StandardClicks.GetTempDirFile("tempUpgradeBuildingUpg.png");

            Utils.doScreenShoot(imgName);
            string[] resultTypes = new[] { "Good", "Bad" };
            string[] itemTypes   = new[] { "Gold", "Eli" };
            var      sb          = new StringBuilder();

            sb.Append($"-input {imgName} ");
            const int actx = 200;
            const int acty = 630;

            if (numBuilders > 0)
            {
                foreach (var rt in resultTypes)
                {
                    foreach (var itm in itemTypes)
                    {
                        sb.Append($"-name {itm}_{rt} -matchRect {actx},{acty},650,105_200 -match data\\check\\upgrade{itm}{rt}.png 40 ");
                    }
                }
            }
            var res = context.GetAppInfo(sb.ToString());

            res.ForEach(r =>
            {
                r.x += actx;
                r.y += acty;
            });

            if (context != null)
            {
                foreach (var r in res)
                {
                    context.DebugLog("           DEBUGRM " + r);
                }
            }
            return(res.Where(r => r.decision == "true").OrderBy(r => r.cmpRes).FirstOrDefault());
        }
コード例 #13
0
        public void ProcessCommand(int act)
        {
            return;

            //Test();
            if (act <= 0)
            {
                context.InfoLog("Failed to recognize account");
                return;
            }
            var fname = $"data\\accounts\\accountFull_{act}.txt";

            if (File.Exists(fname))
            {
                locations = JsonConvert.DeserializeObject <List <PosInfo> >(File.ReadAllText(fname));
            }
            locations.ForEach(loc =>
            {
                Console.WriteLine("====>" + loc.Name() + " " + loc.point.x + "," + loc.point.y);
                if (context.vdcontroller.redoStructureNames)
                {
                    loc.nameLevel = null;
                }
                for (int nameRetry = 0; nameRetry < 2; nameRetry++)
                {
                    if (loc.nameLevel == null)
                    {
                        context.MoveMouseAndClick(loc.point.x, loc.point.y);
                        context.Sleep(1000);
                        Utils.doScreenShoot(tempImgName);
                        var res       = context.GetAppInfo();
                        loc.nameLevel = GetStructureName(loc, res);
                        context.vdcontroller.Log("info", "====> After reco" + loc.Name() + " level=" + loc.Level());
                    }
                    else
                    {
                        break;
                    }
                }
            });



            locations = reorderLocation(locations, context.vdcontroller);


            var  badLocs      = new List <PosInfo>();
            var  results      = context.GetAppInfo();
            int  numBuilders  = NumBuilders(results);
            bool gotFirstGold = false;
            bool gotFirstEli  = false;
            bool trained      = false;

            foreach (var loc in locations)
            {
                if (context.vdcontroller.humanMode)
                {
                    break;
                }
                if (numBuilders == 0 && !string.IsNullOrWhiteSpace(loc.Name()))
                {
                    if (loc.Name() == GoldMine && !gotFirstGold)
                    {
                        gotFirstGold = true;
                        context.MoveMouseAndClick(loc.point.x, loc.point.y);
                    }
                    if (loc.Name() == ElixirCollector && !gotFirstEli)
                    {
                        gotFirstEli = true;
                        context.MoveMouseAndClick(loc.point.x, loc.point.y);
                    }
                    if (loc.Name() != TownHall && loc.Name() != Barracks)
                    {
                        continue;
                    }
                    if (loc.Name() == Barracks && trained)
                    {
                        continue;
                    }
                }
                context.MoveMouseAndClick(loc.point.x, loc.point.y);
                context.Sleep(1000);
                Utils.doScreenShoot(tempImgName);
                results = context.GetAppInfo();
                //"RecoResult_INFO_Builders"
                numBuilders = context.vdcontroller.doUpgrades? NumBuilders(results) : 0;
                context.InfoLog($"Number of builders available {numBuilders}");
                if (numBuilders == 0 || !context.vdcontroller.doUpgrades)
                {
                    if (loc.Name() != TownHall && loc.Name() != Barracks)
                    {
                        continue;
                    }
                    if (loc.Name() == Barracks && trained)
                    {
                        continue;
                    }
                }
                var actionItems = canUpgrade(context, tempImgName, numBuilders);
                if (numBuilders > 0 && context.vdcontroller.doUpgrades)
                {
                    RetryAction(actionItems.upgrade, Upgraded);
                }
                foreach (var otherAct in actionItems.other)
                {
                    if (context.vdcontroller.humanMode)
                    {
                        break;
                    }
                    switch (otherAct.extraInfo)
                    {
                    case "RearmAll":
                        RetryAction(otherAct, () => CheckMatchAndAct("okcancel.png 3000 ", 300, 54));
                        break;

                    case "Train":
                        if (!trained && context.vdcontroller.doDonate)
                        {
                            RetryAction(otherAct, () => CheckMatchAndAct("buildwizardbutton.png 120 ", 54, 46, 10));
                            RetryAction(otherAct, () => CheckMatchAndAct("buildArchierButton.png 120 ", 54, 46, 2));
                            trained = true;
                        }
                        break;
                    }
                }
            }
            foreach (var p in badLocs)
            {
                locations.Remove(p);
            }
            File.WriteAllText(fname, JsonConvert.SerializeObject(locations, Formatting.Indented));
        }
コード例 #14
0
        public void ProcessDonate(CommandInfo cmd)
        {
            if (cmd.cmpRes > 2)
            {
                return;
            }

            var donatedPos = new List <CommandInfo>();
            //ImgChecksAndTags("donatebutton1.png", "INFO_DonateButtonFound", Point(51,19)),
            var processed = new List <CommandInfo>();

            for (int i = 0; i < 5; i++)
            {
                //if (context.vdcontroller.humanMode) break;
                context.MoveMouseAndClick(cmd.x, cmd.y);
                bool found = false;
                context.Sleep(2000);
                Utils.doScreenShoot(ProcessorMapByText.tempImgName);
                context.DebugLog("DEBUGPRINTINFO trying to find donation button");
                //-matchRect 227,102,140,600_200
                const int donateRectx = 227;
                const int donateRecty = 102;
                var       results     = Utils.GetAppInfo($"-input {ProcessorMapByText.tempImgName} -name donate -matchRect {donateRectx},{donateRecty},140,600_200 -top 5  -match data\\check\\donatebutton.png 1900", context);
                foreach (var donate in results)
                {
                    //if (context.vdcontroller.humanMode) break;
                    if (donatedPos.Any(dp => dp.y == donate.y))
                    {
                        continue;
                    }
                    donatedPos.Add(donate);
                    if (donate.decision == "true")
                    {
                        if (processed.Any(p =>
                        {
                            return(Math.Abs(p.y - donate.y) < 20);
                        }))
                        {
                            continue;
                        }
                        processed.Add(donate);
                        found = true;
                        context.Sleep(100);
                        context.MoveMouseAndClick(donateRectx + donate.x + 55, donateRecty + donate.y + 23);
                        context.Sleep(1000);
                        for (int dwretry = 0; dwretry < 2; dwretry++)
                        {
                            Utils.doScreenShoot(ProcessorMapByText.tempImgName);
                            var dw    = Utils.GetAppInfo($"-input {ProcessorMapByText.tempImgName} -name dw  -match data\\check\\donate_wizard.png 300", context);
                            var dwbtn = dw.FirstOrDefault(dwf => dwf.decision == "true");
                            if (dwbtn != null)
                            {
                                context.MoveMouseAndClick(50 + dwbtn.x, 50 + dwbtn.y);
                                for (int cli = 0; cli < 5; cli++)
                                {
                                    context.MouseClick();
                                }
                                break;
                            }
                        }
                        DonateArchier();
                        context.DoStdClicks();
                    }
                }
                if (!found)
                {
                    break;
                }
            }
        }