public void ConfigureStateMachine() { _setFoundHookTrigger = _stateMachine.SetTriggerParameters <TeraPixel>(Trigger.FoundHook); this._stateMachine.Configure(State.Paused) .Permit(Trigger.ThrowFishingHook, State.LookingForHook); this._stateMachine.Configure(State.LookingForHook) .PermitReentry(Trigger.Fish) .OnEntryAsync(async t => await OnLookingForHook()) .Permit(Trigger.FoundHook, State.IsFishing); this._stateMachine.Configure(State.IsFishing) .PermitReentry(Trigger.Fish) .OnEntryAsync(async t => await OnIsFishing()) .OnEntryFrom(Trigger.FoundHook, () => Console.WriteLine("Is Fishing: Wait for a catch!")) .Permit(Trigger.HookNotFound, State.IsCatching) .OnEntryFromAsync(_setFoundHookTrigger, async pixel => { _placeOfHook = pixel; }); this._stateMachine.Configure(State.IsCatching) .OnEntryAsync(async t => await OnIsCatching()) .Permit(Trigger.ThrowFishingHook, State.IsThrowingHook); this._stateMachine.Configure(State.IsThrowingHook) .OnEntryAsync(async t => await OnThrowHook()) .Permit(Trigger.Fish, State.LookingForHook); }
public void ShowResult(TeraPixel foundPoint, string screenFile, string fileName) { Bitmap foundBitmap = new Bitmap(screenFile); var resMin = RodHooks.SitingDuckHook.Aggregate((prev, next) => { var min = prev.X + prev.Y >= next.X + next.Y ? next : prev; return(min); }); var resMax = RodHooks.SitingDuckHook.Aggregate((prev, next) => { var max = prev.X + prev.Y <= next.X + next.Y ? next : prev; return(max); }); var rectangle = Enumerable.Range(resMin.X, resMax.X - resMin.X).Select(x => (x: x, y: resMin.Y)).ToList(); rectangle.AddRange(Enumerable.Range(resMin.X, resMax.X - resMin.X).Select(x => (x, resMax.Y))); rectangle.AddRange(Enumerable.Range(resMin.Y, resMax.Y - resMin.Y).Select(y => (resMin.X, y))); rectangle.AddRange(Enumerable.Range(resMin.Y, resMax.Y - resMin.Y).Select(y => (resMax.X, y))); foreach (var p in rectangle) { foundBitmap.SetPixel(foundPoint.X + p.x, foundPoint.Y + p.y, ColorTranslator.FromHtml("#ff0000")); } foundBitmap.Save(Path.Combine("./TestData/Passed/", fileName)); }
public async Task FoundHook(TeraPixel pixel) { if (this.m_token.IsCancellationRequested) { return; } Console.WriteLine($"FoundHook : {pixel.X} {pixel.Y}"); this._placeOfHook = pixel; await _stateMachine.FireAsync(_setFoundHookTrigger, pixel); }