From df600c60166a27e67223475995f96f238879ec74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89=E9=B8=AD=E8=9B=8B?= Date: Sun, 22 Dec 2024 20:52:39 +0800 Subject: [PATCH] start game when start one dragon --- .../GameTask/Common/BgiVision/BvStatus.cs | 10 +++++ .../GameTask/GameLoading/GameLoading.cs | 2 +- BetterGenshinImpact/Service/ScriptService.cs | 41 ++++++++++++++++++- .../ViewModel/Pages/OneDragonFlowViewModel.cs | 6 +++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/BetterGenshinImpact/GameTask/Common/BgiVision/BvStatus.cs b/BetterGenshinImpact/GameTask/Common/BgiVision/BvStatus.cs index aeb39577..8494733a 100644 --- a/BetterGenshinImpact/GameTask/Common/BgiVision/BvStatus.cs +++ b/BetterGenshinImpact/GameTask/Common/BgiVision/BvStatus.cs @@ -58,6 +58,16 @@ public static partial class Bv return false; } + + /// + /// 在任意可以关闭的UI界面(识别关闭按钮) + /// + /// + /// + public static bool IsInAnyClosableUi(ImageRegion captureRa) + { + return captureRa.Find(QuickTeleportAssets.Instance.MapCloseButtonRo).IsExist(); + } /// /// 是否在队伍选择界面 diff --git a/BetterGenshinImpact/GameTask/GameLoading/GameLoading.cs b/BetterGenshinImpact/GameTask/GameLoading/GameLoading.cs index 44589dac..52e5d427 100644 --- a/BetterGenshinImpact/GameTask/GameLoading/GameLoading.cs +++ b/BetterGenshinImpact/GameTask/GameLoading/GameLoading.cs @@ -64,7 +64,7 @@ public class GameLoadingTrigger : ITaskTrigger return; } - if (Bv.IsInMainUi(content.CaptureRectArea)) + if (Bv.IsInMainUi(content.CaptureRectArea) || Bv.IsInAnyClosableUi(content.CaptureRectArea)) { IsEnabled = false; return; diff --git a/BetterGenshinImpact/Service/ScriptService.cs b/BetterGenshinImpact/Service/ScriptService.cs index a6243ac9..14ec3321 100644 --- a/BetterGenshinImpact/Service/ScriptService.cs +++ b/BetterGenshinImpact/Service/ScriptService.cs @@ -12,10 +12,12 @@ using System.Diagnostics; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; +using BetterGenshinImpact.GameTask.Common; +using BetterGenshinImpact.GameTask.Common.BgiVision; namespace BetterGenshinImpact.Service; -public partial class ScriptService(HomePageViewModel homePageViewModel) : IScriptService +public partial class ScriptService : IScriptService { private readonly ILogger _logger = App.GetLogger(); @@ -35,7 +37,7 @@ public partial class ScriptService(HomePageViewModel homePageViewModel) : IScrip } // 没启动时候,启动截图器 - await homePageViewModel.OnStartTriggerAsync(); + await StartGameTask(); if (!string.IsNullOrEmpty(groupName)) { @@ -197,4 +199,39 @@ public partial class ScriptService(HomePageViewModel homePageViewModel) : IScrip [GeneratedRegex(@"^(?!\s*\/\/)\s*dispatcher\.\s*addTimer", RegexOptions.Multiline)] private static partial Regex DispatcherAddTimerRegex(); + + + public static async Task StartGameTask() + { + // 没启动时候,启动截图器 + var homePageViewModel = App.GetService(); + if (!homePageViewModel!.TaskDispatcherEnabled) + { + await homePageViewModel.OnStartTriggerAsync(); + + await Task.Run(() => + { + var first = true; + while (true) + { + if (!homePageViewModel.TaskDispatcherEnabled || !TaskContext.Instance().IsInitialized) + { + continue; + } + + var content = TaskControl.CaptureToRectArea(); + if (Bv.IsInMainUi(content) || Bv.IsInAnyClosableUi(content)) + { + return; + } + + if (first) + { + first = false; + TaskControl.Logger.LogInformation("当前不在游戏主界面,等待进入主界面后执行任务..."); + } + } + }); + } + } } diff --git a/BetterGenshinImpact/ViewModel/Pages/OneDragonFlowViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/OneDragonFlowViewModel.cs index b38c492b..b0a62465 100644 --- a/BetterGenshinImpact/ViewModel/Pages/OneDragonFlowViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/OneDragonFlowViewModel.cs @@ -9,8 +9,11 @@ using BetterGenshinImpact.Core.Recorder; using BetterGenshinImpact.Core.Script; using BetterGenshinImpact.GameTask; using BetterGenshinImpact.GameTask.AutoDomain; +using BetterGenshinImpact.GameTask.Common; +using BetterGenshinImpact.GameTask.Common.BgiVision; using BetterGenshinImpact.GameTask.Common.Job; using BetterGenshinImpact.GameTask.Model.Enum; +using BetterGenshinImpact.Service; using CommunityToolkit.Mvvm.Input; using Wpf.Ui.Controls; using static BetterGenshinImpact.GameTask.Common.TaskControl; @@ -86,6 +89,9 @@ public partial class OneDragonFlowViewModel : ObservableObject, INavigationAware [RelayCommand] private async Task OnOneKeyExecute() { + // 没启动的时候先启动 + await ScriptService.StartGameTask(); + await new TaskRunner(DispatcherTimerOperationEnum.UseSelfCaptureImage) .RunAsync(async () => {