public void MoveToPrimary() { context.MouseDragTo(726, 89, 401, 468); context.MouseMouseTo(0, 0); context.Sleep(2000); for (int retry = 0; retry < 3; retry++) { var marks = baseMark.Processing(img => img.ImageName.Contains("boat")); if (marks.Count == 0) { context.InfoLog($"Can't find primary nor secondary retry {retry}, sleep 5s"); context.Sleep(5000); continue; } var secboat = marks.FirstOrDefault(m => m.extraInfo.Contains("secondary_boat.png")); if (secboat == null) { context.InfoLog("failed find boat"); continue; } if (secboat.x < 250 || secboat.y > 700) { context.InfoLog("this is primary boat"); break; } context.MoveMouseAndClick(secboat.x, secboat.y); break; } }
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); }
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 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()); }
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); }