예제 #1
0
 public CurBaseType PrimaryOrSecondary(int state = 0)
 {
     for (int retry = 0; retry < 3; retry++)
     {
         var baseInfo = baseMark.Processing(img => img.ImageName.Contains("base"));
         if (baseInfo.Count == 0)
         {
             context.InfoLog($"Can't find primary nor secondary retry {retry}, sleep 5s");
             context.Sleep(5000);
             continue;
         }
         var theBase = baseInfo.First();
         if (theBase.cmpRes > 100)
         {
             context.InfoLog($"Can't find primary nor secondary retry {retry}, base {theBase.ToString()}, sleep 5s");
         }
         if (theBase.extraInfo.IndexOf("primary_base") > 0)
         {
             context.InfoLog("in primary base");
             return(CurBaseType.PrimaryBase);
         }
         if (theBase.extraInfo.IndexOf("secondary_base") > 0)
         {
             context.InfoLog("in secondary base");
             return(CurBaseType.SecondaryBase);
         }
         break;
     }
     return(CurBaseType.Unknown);
 }
예제 #2
0
        public static void MouseDrageTo(IMouse mouse, int x, int y, int tx, int ty, ProcessingContext context)
        {
            MouseMouseTo(mouse, x, y, context);
            context.Sleep(100);
            mouse.PutMouseEvent(0, 0, 0, 0, 1);
            context.Sleep(100);
            const int MAX   = 20;
            int       dx    = tx - x;
            int       dy    = ty - y;
            int       signX = dx > 0 ? 1 : -1;
            int       signY = dy > 0 ? 1 : -1;

            dx = Math.Abs(dx);
            dy = Math.Abs(dy);
            while (dx > MAX || dy > MAX)
            {
                int mx = dx > MAX ? MAX : dx;
                dx -= mx;
                int my = dy > MAX ? MAX : dy;
                dy -= my;
                mouse.PutMouseEvent(mx * signX, my * signY, 0, 0, 1);
                context.Sleep(100);
            }
            context.Sleep(800);
            mouse.PutMouseEvent(dx, dy, 0, 0, 0);
            context.Sleep(100);
        }
예제 #3
0
        protected bool WaitNextStep(StepContext stepCtx)
        {
            var cur        = stepCtx.Steps[stepCtx.step];
            var nextStepPt = stepCtx.step + 1;

            if (nextStepPt >= stepCtx.Steps.Count)
            {
                if (cur.delay > 0)
                {
                    context.Sleep(cur.delay);
                }
                return(true);
            }
            else
            {
                for (int wt = 0; wt < cur.delay; wt += 1000)
                {
                    var nextStep = stepCtx.Steps[nextStepPt];
                    if (FindSpotOnStep(nextStep, "   WAITNEXT ") != null)
                    {
                        return(true);
                    }
                    if (FoundOtherGoodAlts(stepCtx, nextStep))
                    {
                        return(true);
                    }
                    context.Sleep(1000);
                }
            }

            return(false);
        }
예제 #4
0
 public static void MouseClick(IMouse mouse, ProcessingContext context)
 {
     context.Sleep(100);
     mouse.PutMouseEvent(0, 0, 0, 0, 1);
     context.Sleep(200);
     mouse.PutMouseEvent(0, 0, 0, 0, 0);
     context.Sleep(100);
 }
예제 #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
        public static void SendString(IKeyboard keyboard, string str, ProcessingContext context)
        {
            var codes = new short[str.Length];

            Console.Write("writiting ");
            Thread.Sleep(1000);
            //keyboard.PutScancode(0x2A); //shift
            for (int i = 0; i < str.Length; i++)
            {
                codes[i] = (short)GetScanCode(str[i]);
                Console.Write(str[i]);
                keyboard.PutScancode((int)codes[i]);
                context.Sleep(200);
                keyboard.PutScancode((int)codes[i] | 0x80);
                context.Sleep(300);
            }
            Console.WriteLine();
        }
예제 #7
0
        const int YOFF       = 0;// 21;

        public static void MouseMouseTo(IMouse mouse, int x, int y, ProcessingContext context)
        {
            y -= YOFF;
            for (int i = 0; i < 5; i++)
            {
                mouse.PutMouseEvent(-200, -200, 0, 0, 0);
                context.Sleep(100);
            }

            const int MAX = 200;

            while (x > MAX || y > MAX)
            {
                int mx = x > MAX ? MAX : x;
                x -= mx;
                int my = y > MAX ? MAX : y;
                y -= my;
                mouse.PutMouseEvent(mx, my, 0, 0, 0);
                context.Sleep(100);
            }
            mouse.PutMouseEvent(x, y, 0, 0, 0);
        }
예제 #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));
        }
예제 #9
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;
                }
            }
        }
예제 #10
0
파일: Program.cs 프로젝트: gzhangx/ccauto
        private static void DoProcess(ProcessingContext context)
        {
            var controller = context.vdcontroller;

            //context.DebugLog("TODOREMOVETEMP");
            //Thread.Sleep(5000);
            //context.MouseDragTo(1024/2, 768/2, 1024/4, 768/4); //Christmas hack

            var  resourceClick  = new ResourceClicks(context);
            var  baseType       = resourceClick.PrimaryOrSecondary();
            bool skipProcessing = TryForceMoveToPrimary(resourceClick, context);

            resourceClick.Processing(baseType);
            skipProcessing = TryForceMoveToPrimary(resourceClick, context);
            context.DebugLog("ENDTODOREMOVETEMP");

            resourceClick.RearmAll();

            new ActionJunkRemove(context).Process();
            new ActionUpgrade(context).Process();
            //while(controller.humanMode && controller.CurState != ProcessState.SwitchAccount)
            //{
            //    controller.Sleep(100);
            //}
            var switchAccount = new SwitchAccount(context);

            context.GetToEntrance();
            context.DebugLog("In Entrance, sleep 100");
            context.Sleep(1000);
            int acct = switchAccount.CheckAccount();

            if (acct <= 0)
            {
                context.InfoLog("failed to get account, try again");
                context.Sleep(4000);
                acct = switchAccount.CheckAccount();
            }
            context.InfoLog($"===>Step gen acct pic {acct}");
            switchAccount.CurAccount = acct;
            GenerateAccountPics(context, switchAccount.CurAccount);
            context.InfoLog($"===>Step Using account {switchAccount.CurAccount}");
            context.vdcontroller.NotifyStartingAccount(switchAccount);
            if (!skipProcessing)
            {
                if (controller.DoDonate())
                {
                    var train = new ActionTrainUnits(context);
                    train.ProcessCommand(context);
                }

                if (controller.DoDonate() && controller.doDonate)
                {
                    context.InfoLog("===>Step Donate");
                    //cmds = Utils.GetAppInfo();
                    ProcessDonate(context, context.GetToEntrance());
                    context.GetToEntrance();
                }
                if (controller.DoBuilds() && !controller.switchAccountOnly)
                {
                    context.InfoLog("===>Step textmap");
                    new ProcessorMapByText(context).ProcessCommand(acct);
                }
            }

            DoProcessSecondary(resourceClick, context);

            switchAccount.CurAccount = controller.CheckSetCurAccount(acct);
            context.InfoLog("===>Step SwitchAccount");
            switchAccount.Process();
            context.InfoLog("===>Step get to entrance");
            context.GetToEntrance();
            context.Sleep(4000);
            controller.DoneCurProcessing();
        }