void StartScriptLoop(ScriptBase script) { if (scriptTask != null && scriptTask.Status == TaskStatus.Running) { logTools.Error("Already has one running Script Task", false); return; } logTools.Info("StartScriptLoop..."); mumuState = MumuState.Create(); script.SetMumuState(mumuState); tokenSource = new CancellationTokenSource(); ct = tokenSource.Token; scriptTask = new Task(() => { viewportRect = mumuState.ViewportRect; viewportCapture = mumuState.DoCapture(viewportRect); logTools.Info($"Script: {script.Name} OnStart"); script.OnStart(viewportCapture, viewportRect); while (true) { if (ct.IsCancellationRequested) { ct.ThrowIfCancellationRequested(); } try { Thread.Sleep(script.Interval); viewportRect = mumuState.ViewportRect; viewportCapture = mumuState.DoCapture(viewportRect); logTools.Info($"Script: {script.Name} Tick"); script.Tick(viewportCapture, viewportRect); } catch (Exception e) { logTools.Error($"Script: {script.Name} Tick ERROR", false); if (!script.CanKeepOnWhenException || logTools.IsSelfOrChildrenBreakException(e)) { throw e; } else { PrintException(e); } } } }, tokenSource.Token); scriptTask.ContinueWith((t) => { if (t.IsFaulted) { PrintException(t.Exception); } else if (t.IsCanceled) { logTools.Error("Script Canceled", false); } ScriptBase.OnScriptEnded(script.Name, !t.IsFaulted && !t.IsCanceled); }); scriptTask.Start(); }
void StartActStageExchangeLoop() { logTools.Info("StartActStageExchangeLoop..."); mumuState = GetMumuState(); script = new ActivityStageExchangeScript(); StartScriptLoop(script); }
MumuState GetMumuState() { if (mumuState == null) { mumuState = MumuState.Create(); } return(mumuState); }
void StartReceivePresentLoop() { logTools.Info("StartReceivePresentLoop..."); mumuState = GetMumuState(); script = new ReceivePresentScript(); StartScriptLoop(script); }
void StartAutoStageLineLoop() { logTools.Info("StartAutoStageLineLoop..."); mumuState = GetMumuState(); script = new AutoStageLineScript(); StartScriptLoop(script); }
void StartReadReliabilityLoop() { logTools.Info("StartReadReliabilityLoop..."); mumuState = GetMumuState(); script = new ReadReliabilityScript(); StartScriptLoop(script); }
void StartAutoUndergroundLoop() { logTools.Info("StartAutoUndergroundLoop..."); mumuState = GetMumuState(); script = new AutoUndergroundScript(); StartScriptLoop(script); }
void StartStorySkipLoop() { oldFixedTopBottomY = configMgr.FixedViewportTopBottomY; configMgr.FixedViewportTopBottomY = true; logTools.Info("StartStorySkipLoop..."); mumuState = GetMumuState(); script = new ReadStoryScript(); StartScriptLoop(script); }
void StartArenaSearchLoop() { configMgr.InitTesseractConfig(); name = txtName.Text; rank = txtRank.Text; logTools.Info("StartCaptureLoop..."); mumuState = GetMumuState(); var script = new ArenaSearchScript(); script.SetGetPatternNameFunc(new Func <string>(() => { return(name); })); script.SetGetPatternRankFunc(new Func <string>(() => { return(rank); })); this.script = script; StartScriptLoop(script); }