Exemple #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);
        }
 public static List <CommandInfo> GetNameAtPoint(ProcessingContext context, ccPoint loc)
 {
     context.MoveMouseAndClick(loc);
     context.Sleep(1000);
     Utils.doScreenShoot(tempImgName);
     return(context.GetAppInfo());
 }
Exemple #3
0
        int getNumBuilders()
        {
            Utils.doScreenShoot(tempImgName);
            var cmdres = context.GetAppInfo();

            return(ActionUpgrade.NumBuilders(context, cmdres));
        }
Exemple #4
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());
        }
Exemple #5
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));
        }
Exemple #6
0
        public static UpgradeTrain canUpgrade(ProcessingContext context, string imgName, int numBuilders)
        {
            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 {rt} -matchRect {actx},{acty},650,105_200 -match data\\check\\upgrade{itm}{rt}.png 40 ");
                    }
                }
            }
            var otherActs = new[] { "Train", "RearmAll" };
            var otherImgs = new Dictionary <string, string>
            {
                { "Train", "data\\check\\traintroops.png 30" },
                { "RearmAll", "data\\check\\rearmall.png 30" }
            };

            foreach (var name in otherActs)
            {
                sb.Append($" -name {name} -matchRect {actx},{acty},650,105_200 -match {otherImgs[name]} ");
            }
            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);
                }
            }
            res = res.Where(r => r.decision == "true").OrderBy(r => r.cmpRes).ToList();

            if (context != null)
            {
                var upgrade = res.FirstOrDefault(r => r.extraInfo == "Good" || r.extraInfo == "Bad");
                if (upgrade != null)
                {
                    context.LogMatchAnalyst(sb.ToString(), upgrade.cmpRes);
                }
            }
            var others = new List <CommandInfo>();

            foreach (var name in otherActs)
            {
                var found = res.FirstOrDefault(r => r.extraInfo == name);
                if (found != null)
                {
                    others.Add(found);
                    context.LogMatchAnalyst(sb.ToString(), found.cmpRes);
                }
            }
            return(new UpgradeTrain
            {
                upgrade = res.FirstOrDefault(r => r.extraInfo == "Good" || r.extraInfo == "Bad"),
                other = others,
            });
        }