From 77e6bfa466ddb601cb0055fc443a6c418008241a Mon Sep 17 00:00:00 2001 From: status102 Date: Wed, 20 Sep 2023 17:07:57 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E5=A6=82=E6=9E=9C=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=B5=81=E7=A8=8B=E4=B8=AD=E5=8B=BE=E9=80=89=E4=BA=86?= =?UTF-8?q?=E5=88=B7=E7=90=86=E6=99=BA=EF=BC=8C=E5=88=99=E5=9C=A8=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E9=93=BE=E7=BB=93=E6=9D=9F=E6=97=B6=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E7=90=86=E6=99=BA=E5=9B=9E=E6=BB=A1=E7=9A=84?= =?UTF-8?q?=E9=A2=84=E6=B5=8B=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resource/tasks.json | 2 +- src/MaaCore/Assistant.cpp | 8 ++++ src/MaaCore/Status.h | 1 + .../Task/Fight/SanityBeforeStagePlugin.cpp | 12 +++++- src/MaaWpfGui/Main/AsstProxy.cs | 37 +++++++++++++++++-- src/MaaWpfGui/Res/Localizations/en-us.xaml | 3 +- src/MaaWpfGui/Res/Localizations/ja-jp.xaml | 3 +- src/MaaWpfGui/Res/Localizations/ko-kr.xaml | 3 +- src/MaaWpfGui/Res/Localizations/zh-cn.xaml | 3 +- src/MaaWpfGui/Res/Localizations/zh-tw.xaml | 3 +- 10 files changed, 64 insertions(+), 11 deletions(-) diff --git a/resource/tasks.json b/resource/tasks.json index c5be75ca4e..f5d532dd9f 100644 --- a/resource/tasks.json +++ b/resource/tasks.json @@ -3970,7 +3970,7 @@ "roi": [ 1120, 20, - 150, + 160, 40 ], "ocrReplace": [ diff --git a/src/MaaCore/Assistant.cpp b/src/MaaCore/Assistant.cpp index 14e749a487..0b7c80cb27 100644 --- a/src/MaaCore/Assistant.cpp +++ b/src/MaaCore/Assistant.cpp @@ -421,6 +421,14 @@ void Assistant::working_proc() if (m_tasks_list.empty()) { callback_json["finished_tasks"] = json::array(finished_tasks); + + const auto& sanity_str = status()->get_str(Status::FightSanityReport); + if (sanity_str) { + auto sanity_array = json::array(json::parse(*sanity_str).value_or(json::value(json::array()))); + // ["100/135", "2023-09-01 09:31:53.527"] + callback_json["sanity"] = sanity_array; + } + append_callback(AsstMsg::AllTasksCompleted, callback_json); finished_tasks.clear(); clear_cache(); diff --git a/src/MaaCore/Status.h b/src/MaaCore/Status.h index 815f3d8b8c..fe87157669 100644 --- a/src/MaaCore/Status.h +++ b/src/MaaCore/Status.h @@ -38,6 +38,7 @@ namespace asst public: static inline const std::string InfrastAvailableOpersForGroup = "InfrastAvailableOpersForGroup"; + static inline const std::string FightSanityReport = "FightSanityReport"; static inline const std::string RoguelikeCharElitePrefix = "RoguelikeElite-"; static inline const std::string RoguelikeCharLevelPrefix = "RoguelikeLevel-"; diff --git a/src/MaaCore/Task/Fight/SanityBeforeStagePlugin.cpp b/src/MaaCore/Task/Fight/SanityBeforeStagePlugin.cpp index 5d45e25255..f721540a21 100644 --- a/src/MaaCore/Task/Fight/SanityBeforeStagePlugin.cpp +++ b/src/MaaCore/Task/Fight/SanityBeforeStagePlugin.cpp @@ -4,6 +4,7 @@ #include "Config/TaskData.h" #include "Controller/Controller.h" +#include "Status.h" #include "Utils/ImageIo.hpp" #include "Utils/Logger.hpp" #include "Vision/RegionOCRer.h" @@ -19,6 +20,10 @@ bool asst::SanityBeforeStagePlugin::verify(AsstMsg msg, const json::value& detai if (task.ends_with("StartButton1")) { return true; } + else if (task.ends_with("Stop") && details.at("pre_task").as_string().ends_with("StartButton1")) { + // 次数达限 + return true; + } else { return false; } @@ -49,8 +54,8 @@ void asst::SanityBeforeStagePlugin::get_sanity() if (!analyzer.analyze()) { Log.info(__FUNCTION__, "Current Sanity analyze failed"); - cv::rectangle(img, make_rect(Task.get("SanityMatch")->roi), cv::Scalar(0, 0, 255), 2); std::string stem = utils::get_time_filestem(); + cv::rectangle(img, make_rect(Task.get("SanityMatch")->roi), cv::Scalar(0, 0, 255), 2); imwrite(utils::path("debug") / utils::path("sanity") / (stem + "_failed_img.png"), img); return; } @@ -69,4 +74,9 @@ void asst::SanityBeforeStagePlugin::get_sanity() json::value sanity_info = basic_info_with_what("SanityBeforeStage"); sanity_info["details"]["sanity"] = text; callback(AsstMsg::SubTaskExtraInfo, sanity_info); + + json::array value; + value.emplace_back(std::move(text)); + value.emplace_back(utils::get_format_time()); + status()->set_str(Status::FightSanityReport, value.dumps()); } diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index 53d9f67919..d03de96ee9 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -589,6 +589,7 @@ namespace MaaWpfGui.Main case AsstMsg.AllTasksCompleted: bool isMainTaskQueueAllCompleted = true; var finished_tasks = details["finished_tasks"] as JArray; + var sanity_report = details["sanity"] as JArray; if (finished_tasks.Count == 1) { var unique_finished_task = (AsstTaskId)finished_tasks[0]; @@ -617,19 +618,47 @@ namespace MaaWpfGui.Main if (isMainTaskQueueAllCompleted) { - Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AllTasksComplete")); + bool isSanityForecastSucc = true; + DateTimeOffset? reportTime = null; + if (isSanityForecastSucc &= sanity_report.Count == 2 && ((string)sanity_report[0]).Contains("/")) + { + int[] sanity = ((string)sanity_report[0]).Split('/').Select(i => Convert.ToInt32(i)).ToArray(); + reportTime = DateTimeOffset.Parse((string)sanity_report[1]); + if (isSanityForecastSucc &= sanity.Length == 2 && sanity[1] > 1) + { + reportTime = reportTime?.AddMinutes(sanity[0] < sanity[1] ? (sanity[1] - sanity[0]) * 6 : 0); + } + } + var allTaskCompleteTitle = LocalizationHelper.GetString("AllTasksComplete"); var allTaskCompleteMessage = LocalizationHelper.GetString("AllTaskCompleteContent"); + var sanityReport = LocalizationHelper.GetString("SanityReport"); - var configurationPreset = ConfigurationHelper.GetValue(ConfigurationKeys.CurrentConfiguration, "Default"); + var configurationPreset = ConfigurationHelper.GetCurrentConfiguration(); allTaskCompleteMessage = allTaskCompleteMessage - .Replace("{Datetime}", DateTime.Now.ToString("U")) + .Replace("{DateTime}", DateTime.Now.ToString("U")) .Replace("{Preset}", configurationPreset); + if (isSanityForecastSucc) + { + sanityReport = sanityReport.Replace("{DateTime}", reportTime?.ToString("g")); + + Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AllTasksComplete") + Environment.NewLine + sanityReport); + ExternalNotificationService.Send(allTaskCompleteTitle, allTaskCompleteMessage + Environment.NewLine + sanityReport); + } + else + { + Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AllTasksComplete")); + ExternalNotificationService.Send(allTaskCompleteTitle, allTaskCompleteMessage); + } - ExternalNotificationService.Send(allTaskCompleteTitle, allTaskCompleteMessage); using (var toast = new ToastNotification(allTaskCompleteTitle)) { + if (isSanityForecastSucc) + { + toast.AppendContentText(sanityReport); + } + toast.Show(); } diff --git a/src/MaaWpfGui/Res/Localizations/en-us.xaml b/src/MaaWpfGui/Res/Localizations/en-us.xaml index 2aad54a6dd..435b7f06b1 100644 --- a/src/MaaWpfGui/Res/Localizations/en-us.xaml +++ b/src/MaaWpfGui/Res/Localizations/en-us.xaml @@ -541,7 +541,8 @@ The video aspect ratio needs to be 16:9 without interference factors such as bla Start combat: Complete combat All task(s) completed! - MAA has completed all tasks under the {Preset} configuration in {Datetime}. + Sanity will be full on {DateTime}. + MAA has completed all tasks under the {Preset} configuration in {DateTime}. Tasks started Tasks stopped Failed to open the client. Please check the configuration file diff --git a/src/MaaWpfGui/Res/Localizations/ja-jp.xaml b/src/MaaWpfGui/Res/Localizations/ja-jp.xaml index 2329e90b67..9aae9557ce 100644 --- a/src/MaaWpfGui/Res/Localizations/ja-jp.xaml +++ b/src/MaaWpfGui/Res/Localizations/ja-jp.xaml @@ -541,7 +541,8 @@ Bilibili: ログイン インターフェイスに表示されるアカウント 戦闘開始: 戦闘完了 すべてのタスクが完了しました! - MAA は、{Datetime} の {Preset} 構成の下にあるすべてのプリセット タスクを完了しました。 + 理性は {DateTime} に満杯になります。 + MAA は、{DateTime} の {Preset} 構成の下にあるすべてのプリセット タスクを完了しました。 Tasks started Tasks stopped クライアントを開くのに失敗しました。構成ファイルを確認してください diff --git a/src/MaaWpfGui/Res/Localizations/ko-kr.xaml b/src/MaaWpfGui/Res/Localizations/ko-kr.xaml index e0209e8ffb..f829a50926 100644 --- a/src/MaaWpfGui/Res/Localizations/ko-kr.xaml +++ b/src/MaaWpfGui/Res/Localizations/ko-kr.xaml @@ -541,7 +541,8 @@ Bilibili: 로그인 인터페이스에 표시되는 계정 이름(예: Zhang San 작전 시작: 작전 완료 모든 작업이 완료되었습니다! - MAA는 {Datetime}의 {Preset} 구성에서 모든 사전 설정 작업을 완료했습니다. + {DateTime}에 정신력이 가득 차게 됩니다. + MAA는 {DateTime}의 {Preset} 구성에서 모든 사전 설정 작업을 완료했습니다. 작업 시작됨 작업 중지됨 클라이언트를 시작하지 못했습니다. 설정 파일을 확인하세요 diff --git a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml index 47c7babffb..ad22bf0b39 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml @@ -541,7 +541,8 @@ 开始战斗: 完成战斗 任务已全部完成! - MAA 已在 {Datetime} 完成了 {Preset} 配置下所有预设的任务。 + 理智将在 {DateTime} 回满。 + MAA 已在 {DateTime} 完成了 {Preset} 配置下所有预设的任务。 开始执行任务 任务终止 打开客户端失败,请检查配置文件 diff --git a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml index 389a3b867e..73aebe9c9c 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml @@ -541,7 +541,8 @@ 開始戰鬥: 完成戰鬥 任務已全部完成! - MAA 已在 {Datetime} 完成了 {Preset} 配置下所有預設的任務。 + 理智將在 {DateTime} 回滿。 + MAA 已在 {DateTime} 完成了 {Preset} 配置下所有預設的任務。 開始執行任務 任務終止 打開用戶端失敗,請檢查設定檔 From 6e7650ea7373bc4329c3bff6f2a65237972e594b Mon Sep 17 00:00:00 2001 From: status102 Date: Thu, 21 Sep 2023 08:38:53 +0800 Subject: [PATCH 2/3] =?UTF-8?q?perf:=20=E6=97=B6=E9=97=B4=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E4=BF=AE=E6=94=B9=E4=B8=BAHH:mm:ss?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Main/AsstProxy.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index d03de96ee9..2e66a0c6d9 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -641,7 +641,7 @@ namespace MaaWpfGui.Main .Replace("{Preset}", configurationPreset); if (isSanityForecastSucc) { - sanityReport = sanityReport.Replace("{DateTime}", reportTime?.ToString("g")); + sanityReport = sanityReport.Replace("{DateTime}", reportTime?.ToString("T")); Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AllTasksComplete") + Environment.NewLine + sanityReport); ExternalNotificationService.Send(allTaskCompleteTitle, allTaskCompleteMessage + Environment.NewLine + sanityReport); From 89aaf14cd69ff1749176f74cf1ce83f6b1cada96 Mon Sep 17 00:00:00 2001 From: status102 Date: Fri, 22 Sep 2023 15:42:45 +0800 Subject: [PATCH 3/3] =?UTF-8?q?perf:=20=E8=BF=BD=E5=8A=A0=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E9=97=B4=E9=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Main/AsstProxy.cs | 6 ++++-- src/MaaWpfGui/Res/Localizations/en-us.xaml | 2 +- src/MaaWpfGui/Res/Localizations/ja-jp.xaml | 2 +- src/MaaWpfGui/Res/Localizations/ko-kr.xaml | 2 +- src/MaaWpfGui/Res/Localizations/zh-cn.xaml | 2 +- src/MaaWpfGui/Res/Localizations/zh-tw.xaml | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index 2e66a0c6d9..23fc2491f9 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -620,13 +620,15 @@ namespace MaaWpfGui.Main { bool isSanityForecastSucc = true; DateTimeOffset? reportTime = null; + TimeSpan timeDiff = TimeSpan.Zero; if (isSanityForecastSucc &= sanity_report.Count == 2 && ((string)sanity_report[0]).Contains("/")) { int[] sanity = ((string)sanity_report[0]).Split('/').Select(i => Convert.ToInt32(i)).ToArray(); reportTime = DateTimeOffset.Parse((string)sanity_report[1]); if (isSanityForecastSucc &= sanity.Length == 2 && sanity[1] > 1) { - reportTime = reportTime?.AddMinutes(sanity[0] < sanity[1] ? (sanity[1] - sanity[0]) * 6 : 0); + timeDiff = new TimeSpan(0, sanity[0] < sanity[1] ? (sanity[1] - sanity[0]) * 6 : 0, 0); + reportTime = reportTime?.AddMinutes(timeDiff.TotalMinutes); } } @@ -641,7 +643,7 @@ namespace MaaWpfGui.Main .Replace("{Preset}", configurationPreset); if (isSanityForecastSucc) { - sanityReport = sanityReport.Replace("{DateTime}", reportTime?.ToString("T")); + sanityReport = sanityReport.Replace("{DateTime}", reportTime?.ToString("T")).Replace("{TimeDiff}", timeDiff.ToString(@"hh\:mm")); Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AllTasksComplete") + Environment.NewLine + sanityReport); ExternalNotificationService.Send(allTaskCompleteTitle, allTaskCompleteMessage + Environment.NewLine + sanityReport); diff --git a/src/MaaWpfGui/Res/Localizations/en-us.xaml b/src/MaaWpfGui/Res/Localizations/en-us.xaml index 435b7f06b1..d394a30a29 100644 --- a/src/MaaWpfGui/Res/Localizations/en-us.xaml +++ b/src/MaaWpfGui/Res/Localizations/en-us.xaml @@ -541,7 +541,7 @@ The video aspect ratio needs to be 16:9 without interference factors such as bla Start combat: Complete combat All task(s) completed! - Sanity will be full on {DateTime}. + Sanity will be full on {DateTime} ({TimeDiff} later). MAA has completed all tasks under the {Preset} configuration in {DateTime}. Tasks started Tasks stopped diff --git a/src/MaaWpfGui/Res/Localizations/ja-jp.xaml b/src/MaaWpfGui/Res/Localizations/ja-jp.xaml index 9aae9557ce..18f1dfaf03 100644 --- a/src/MaaWpfGui/Res/Localizations/ja-jp.xaml +++ b/src/MaaWpfGui/Res/Localizations/ja-jp.xaml @@ -541,7 +541,7 @@ Bilibili: ログイン インターフェイスに表示されるアカウント 戦闘開始: 戦闘完了 すべてのタスクが完了しました! - 理性は {DateTime} に満杯になります。 + 理性は {DateTime} に満杯になります ({TimeDiff} 後)。 MAA は、{DateTime} の {Preset} 構成の下にあるすべてのプリセット タスクを完了しました。 Tasks started Tasks stopped diff --git a/src/MaaWpfGui/Res/Localizations/ko-kr.xaml b/src/MaaWpfGui/Res/Localizations/ko-kr.xaml index f829a50926..1af088791a 100644 --- a/src/MaaWpfGui/Res/Localizations/ko-kr.xaml +++ b/src/MaaWpfGui/Res/Localizations/ko-kr.xaml @@ -541,7 +541,7 @@ Bilibili: 로그인 인터페이스에 표시되는 계정 이름(예: Zhang San 작전 시작: 작전 완료 모든 작업이 완료되었습니다! - {DateTime}에 정신력이 가득 차게 됩니다. + {DateTime}({TimeDiff} 이후)에 정신 상태가 가득 차게 됩니다. MAA는 {DateTime}의 {Preset} 구성에서 모든 사전 설정 작업을 완료했습니다. 작업 시작됨 작업 중지됨 diff --git a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml index ad22bf0b39..68f113a8ec 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml @@ -541,7 +541,7 @@ 开始战斗: 完成战斗 任务已全部完成! - 理智将在 {DateTime} 回满。 + 理智将在 {DateTime} ({TimeDiff} 后) 回满。 MAA 已在 {DateTime} 完成了 {Preset} 配置下所有预设的任务。 开始执行任务 任务终止 diff --git a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml index 73aebe9c9c..5b3b080515 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml @@ -541,7 +541,7 @@ 開始戰鬥: 完成戰鬥 任務已全部完成! - 理智將在 {DateTime} 回滿。 + 理智會在 {DateTime} ({TimeDiff} 後) 回滿。 MAA 已在 {DateTime} 完成了 {Preset} 配置下所有預設的任務。 開始執行任務 任務終止