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; } } } } }
private static void DoProcessSecondary(ResourceClicks resourceClick, ProcessingContext context) { var baseType = resourceClick.PrimaryOrSecondary(); if (baseType == ResourceClicks.CurBaseType.PrimaryBase) { resourceClick.MoveToSecondary(); context.MouseMouseTo(0, 0); context.InfoLog("Skip processing since we are in secondary"); } context.InfoLog("sleeping 2s for things to settle down"); Thread.Sleep(2000); resourceClick.Processing(ResourceClicks.CurBaseType.SecondaryBase); TryForceMoveToPrimary(resourceClick, context); }
public CommandInfo FindSpot(string name, int retry = 5, string printDebug = "") { for (int retryi = 0; retryi < retry; retryi++) { context.DebugLog($"{printDebug}Trying to find SINGLEMATCH for {name}"); var cmds = Utils.GetAppInfo(name, context); var found = cmds.FirstOrDefault(cmd => cmd.command == "SINGLEMATCH"); if (found != null && found.decision == "true") { context.InfoLog($"{printDebug}matching {name} found {found.cmpRes} {found.decision}"); context.LogMatchAnalyst(name, found.cmpRes); return(found); } else { context.InfoLog($"{printDebug}matching {name} NOT found {found.cmpRes} {found.decision}"); } context.Sleep(1000); } return(null); }
private static bool TryForceMoveToPrimary(ResourceClicks resourceClick, ProcessingContext context) { var baseType = resourceClick.PrimaryOrSecondary(); bool skipProcessing = false; if (baseType == ResourceClicks.CurBaseType.SecondaryBase) { resourceClick.MoveToPrimary(); context.MouseMouseTo(0, 0); context.InfoLog("Skip processing since we are in secondary"); skipProcessing = true; } return(skipProcessing); }
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); } } } } }
public static int NumBuilders(ProcessingContext context, List <CommandInfo> cmds) { var cmd = cmds.FirstOrDefault(c => c.command == "RecoResult_INFO_Builders"); try { if (cmd != null) { if (cmd.Text != null && cmd.Text.Contains("/")) { var cc = cmd.Text.Split('/'); return(int.Parse(cc[0].Trim())); } } } catch (Exception exc) { context.InfoLog("ERROR " + exc.ToString() + " " + cmd); } return(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); }
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)); }
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(); }