Exemple #1
0
        public void Process()
        {
            var items = upgradeBuildingFinder.Processing();

            foreach (var itm in items)
            {
                if (itm.x > 200)
                {
                    if (!StandardClicks.isRegionGood(itm))
                    {
                        context.InfoLog($"found too far skipp {itm.extraInfo} {itm.x}/{itm.y}");
                        continue;
                    }
                    context.InfoLog($"found {itm.extraInfo} {itm.x}/{itm.y}");
                    var cmdres      = ActionStructureNameReco.GetNameAtPoint(context, itm);
                    var numBuilders = NumBuilders(context, cmdres);
                    if (numBuilders == 0)
                    {
                        context.InfoLog($"No builder");
                        return;
                    }
                    Thread.Sleep(1000);
                    var nameLevel = ActionStructureNameReco.GetStructureName(itm, cmdres, context);
                    if (nameLevel == null)
                    {
                        cmdres    = ActionStructureNameReco.GetNameAtPoint(context, itm);
                        nameLevel = ActionStructureNameReco.GetStructureName(itm, cmdres, context);
                        if (nameLevel == null)
                        {
                            context.InfoLog($"failed reco namelevel {itm.extraInfo} {itm.x}/{itm.y}");
                            continue;
                        }
                    }
                    var goodNames = ActionStructureNameReco.GetGoodNames();

                    foreach (var gname in goodNames)
                    {
                        if (gname.ToLower() == nameLevel.name.ToLower())
                        {
                            context.DebugLog($"found match name {gname}");
                            //context.MoveMouseAndClick(itm);
                            //Thread.Sleep(1000);
                            var upgGrood = canUpgrade(context, numBuilders);
                            if (upgGrood != null && upgGrood.extraInfo.Contains("Good"))
                            {
                                context.MoveMouseAndClick(upgGrood);
                                Upgraded();
                                numBuilders--;
                            }
                            break;
                        }
                    }
                }
            }
        }
Exemple #2
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();
                }
            }
        }
 public static List <CommandInfo> GetNameAtPoint(ProcessingContext context, ccPoint loc)
 {
     context.MoveMouseAndClick(loc);
     context.Sleep(1000);
     Utils.doScreenShoot(tempImgName);
     return(context.GetAppInfo());
 }
Exemple #4
0
        public void Process()
        {
            var numBuilders = getNumBuilders();

            if (numBuilders == 0)
            {
                context.InfoLog($"No builder");
                return;
            }
            const int SLEEPS = 5;
            var       junks  = junkFinder.Processing();

            foreach (var junk in junks)
            {
                if (StandardClicks.isRegionGood(junk) && junk.decision == "true")
                {
                    context.DebugLog($"Found {junk.extraInfo} {junk.cmpRes}");
                    context.MoveMouseAndClick(junk);
                    Thread.Sleep(1000);
                    var btn = buttons.ProcessingWithRetryTop1();
                    if (btn != null && btn.decision == "true")
                    {
                        context.MoveMouseAndClick(btn);
                        Thread.Sleep(1000);
                        int found = 0;
                        for (int i = 0; i < 30; i += SLEEPS)
                        {
                            btn = buttons.ProcessingWithRetryTop1();
                            if (btn != null && btn.decision == "true" && btn.extraInfo.Contains("cancelremove"))
                            {
                                found++;
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (found == 0)
                        {
                            context.DebugLog($"Wait not found, sleep 15s");
                            Thread.Sleep(1000 * 15);
                        }
                    }
                }
            }
        }
Exemple #5
0
        public void ProcessCommand(ProcessingContext context)
        {
            var cmd = trainButtonFinder.ProcessingWithRetryTop1();

            if (cmd == null)
            {
                context.DebugLog("Didn't find Train button");
                return;
            }
            context.MoveMouseAndClick(cmd);
            Thread.Sleep(1000);

            cmd = trainButtonFinder.ProcessingWithRetryTop1();
            if (cmd == null)
            {
                context.DebugLog("Didn't find Train tab button");
                return;
            }
            context.MoveMouseAndClick(cmd);
            Thread.Sleep(1000);

            var cmds = buildArcherWizardButton.ProcessingWithRetry();

            if (!cmds.Any())
            {
                context.DebugLog("Didn't find troop button");
                return;
            }
            cmd = cmds.FirstOrDefault(c => c.extraInfo.Contains("buildwizardbutton"));
            if (cmd != null)
            {
                context.MoveMouseAndClick(cmd);
                for (int i = 0; i < 10; i++)
                {
                    context.MouseClick();
                }
            }
            cmd = cmds.FirstOrDefault(c => c.extraInfo.Contains("buildArchierButton"));
            if (cmd != null)
            {
                context.MoveMouseAndClick(cmd);
                context.MouseClick();
            }
        }
Exemple #6
0
        public void RearmAll()
        {
            var ldr = new AutoResourceLoader(context, StandardClicks.GetTempDirFile("tmpRearmAll.png"),
                                             getCheckImgs());

            var cmd = ldr.ProcessingWithRetryTop1(r => r.extraInfo != null && r.extraInfo.Contains("townhall"));

            if (cmd == null)
            {
                context.InfoLog("Warning, didn't find townhall");
                return;
            }
            context.InfoLog($"Found townhall clicking {cmd.extraInfo} {cmd.cmpRes} {cmd.decision}");
            context.MoveMouseAndClick(cmd);
            Thread.Sleep(1000);
            context.InfoLog($"done wait, try find rearmall");
            var cmds = ldr.ProcessingWithRetry();

            cmd = cmds.Where(c => c.decision == "true" && c.extraInfo.Contains("rearmall")).OrderBy(c => c.cmpRes).FirstOrDefault();
            //cmd = cmds.FirstOrDefault(c => c.extraInfo.Contains("rearmall") && c.cmpRes < 30000);
            if (cmd == null)
            {
                context.InfoLog("Warning, didn't find rearm all");
                return;
            }
            context.InfoLog($"Found rearm all {cmd.extraInfo} {cmd.cmpRes} {cmd.decision}");
            context.MoveMouseAndClick(cmd);

            cmds = ldr.ProcessingWithRetry(r => r.extraInfo.Contains("ok_bigv1"));
            cmd  = cmds.FirstOrDefault();
            if (cmd == null)
            {
                context.InfoLog("Warning, didn't find ok button");
                return;
            }
            context.InfoLog($"Found rearm all ok button {cmd.extraInfo} {cmd.cmpRes} {cmd.decision}");
            context.MoveMouseAndClick(cmd);
        }
Exemple #7
0
        protected StepContext DoSteps(List <StepInfo> steps)
        {
            var stepCtx = new StepContext
            {
                step      = 0,
                Steps     = steps,
                stepRetry = new int[steps.Count]
            };

            for (int i = 0; i < steps.Count; i++)
            {
                steps[i].stepInd = i;
            }

            //while (!stepCtx.finished)
            {
                for (int i = 0; i < steps.Count; i++)
                {
                    var cur = steps[i];
                    stepCtx.step = i;
                    CommandInfo found = FindSpotOnStep(cur);
                    if (found == null)
                    {
                        stepCtx.stepRetry[i]++;
                        if (FoundOtherGoodAlts(stepCtx, cur))
                        {
                            i = stepCtx.step;
                            continue;
                        }
                        if (stepCtx.stepRetry[i] > cur.maxRetry)
                        {
                            stepCtx.failed   = true;
                            stepCtx.finished = true;
                            break;
                        }
                        i--;
                    }
                    else
                    {
                        if (cur.Act != null)
                        {
                            cur.Act(found, cur, stepCtx);
                            i = stepCtx.step;
                            if (stepCtx.finished)
                            {
                                break;
                            }
                        }
                        else
                        {
                            context.MoveMouseAndClick(found.x + cur.xoff, found.y + cur.yoff);
                            context.MouseMouseTo(0, 0);
                            bool lastStepRes = WaitNextStep(stepCtx);
                            if (!lastStepRes)
                            {
                                stepCtx.failed = true;
                                stepCtx.stepRetry[i]++;
                                if (checkRetryFail(stepCtx, i))
                                {
                                    break;
                                }
                                i--;
                            }
                            else
                            {
                                if (i == steps.Count - 1)
                                {
                                    stepCtx.finished = true;
                                }
                            }
                        }
                    }
                }
            }
            return(stepCtx);
        }
Exemple #8
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));
        }