From 3f94fab9f1be09efd9f18109938b3050a121571f Mon Sep 17 00:00:00 2001 From: MistEO Date: Wed, 11 Jan 2023 23:34:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8A=84=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E5=8A=9F=E8=83=BD=E5=BE=AA=E7=8E=AF=E6=AC=A1=E6=95=B0?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaCore/Task/Interface/CopilotTask.cpp | 41 ++++++++++++------- src/MaaCore/Task/Interface/CopilotTask.h | 2 + src/MaaWpfGui/Main/AsstProxy.cs | 9 ++++- src/MaaWpfGui/Main/CopilotViewModel.cs | 17 +++++++- src/MaaWpfGui/Res/Localizations/en-us.xaml | 1 + src/MaaWpfGui/Res/Localizations/ja-jp.xaml | 1 + src/MaaWpfGui/Res/Localizations/ko-kr.xaml | 1 + src/MaaWpfGui/Res/Localizations/zh-cn.xaml | 1 + src/MaaWpfGui/Res/Localizations/zh-tw.xaml | 1 + src/MaaWpfGui/Views/CopilotView.xaml | 46 ++++++++++++++++------ 10 files changed, 91 insertions(+), 29 deletions(-) diff --git a/src/MaaCore/Task/Interface/CopilotTask.cpp b/src/MaaCore/Task/Interface/CopilotTask.cpp index 72d4c300a1..59cc88a942 100644 --- a/src/MaaCore/Task/Interface/CopilotTask.cpp +++ b/src/MaaCore/Task/Interface/CopilotTask.cpp @@ -10,25 +10,24 @@ asst::CopilotTask::CopilotTask(const AsstCallback& callback, Assistant* inst) : InterfaceTask(callback, inst, TaskType), m_formation_task_ptr(std::make_shared(callback, inst, TaskType)), - m_battle_task_ptr(std::make_shared(callback, inst, TaskType)) + m_battle_task_ptr(std::make_shared(callback, inst, TaskType)), + m_stop_task_ptr(std::make_shared(callback, inst, TaskType)) { - for (int i = 0; i != 1000; ++i) { - auto start_1_tp = std::make_shared(callback, inst, TaskType); - start_1_tp->set_tasks({ "BattleStartPre" }).set_retry_times(0).set_ignore_error(true); - m_subtasks.emplace_back(start_1_tp); + auto start_1_tp = std::make_shared(callback, inst, TaskType); + start_1_tp->set_tasks({ "BattleStartPre" }).set_retry_times(0).set_ignore_error(true); + m_subtasks.emplace_back(start_1_tp); - m_subtasks.emplace_back(m_formation_task_ptr); + m_subtasks.emplace_back(m_formation_task_ptr); - auto start_2_tp = std::make_shared(callback, inst, TaskType); - start_2_tp->set_tasks({ "BattleStartAll" }).set_ignore_error(false); - m_subtasks.emplace_back(start_2_tp); + auto start_2_tp = std::make_shared(callback, inst, TaskType); + start_2_tp->set_tasks({ "BattleStartAll" }).set_ignore_error(false); + m_subtasks.emplace_back(start_2_tp); - m_subtasks.emplace_back(m_battle_task_ptr)->set_retry_times(0); + m_subtasks.emplace_back(m_battle_task_ptr)->set_retry_times(0); - auto stop_task_ptr = std::make_shared(callback, inst, TaskType); - stop_task_ptr->set_tasks({ "ClickCornerUntilStartButton" }); - m_subtasks.emplace_back(stop_task_ptr); - } + m_stop_task_ptr->set_tasks({ "ClickCornerUntilStartButton" }); + m_stop_task_ptr->set_enable(false); + m_subtasks.emplace_back(m_stop_task_ptr); } bool asst::CopilotTask::set_params(const json::value& params) @@ -59,5 +58,19 @@ bool asst::CopilotTask::set_params(const json::value& params) std::string support_unit_name = params.get("support_unit_name", std::string()); m_formation_task_ptr->set_support_unit_name(std::move(support_unit_name)); + size_t loop_times = params.get("loop_times", 1); + if (loop_times > 1) { + m_subtasks.reserve(m_subtasks.size() * loop_times); + auto raw_end = m_subtasks.end(); + for (int i = 1; i < loop_times; ++i) { + // FIXME: 如果多次调用 set_params,这里复制的会有问题 + m_subtasks.insert(m_subtasks.end(), m_subtasks.begin(), raw_end); + } + m_stop_task_ptr->set_enable(true); + } + else { + m_stop_task_ptr->set_enable(false); + } + return true; } diff --git a/src/MaaCore/Task/Interface/CopilotTask.h b/src/MaaCore/Task/Interface/CopilotTask.h index 43893dc468..323fcb9a46 100644 --- a/src/MaaCore/Task/Interface/CopilotTask.h +++ b/src/MaaCore/Task/Interface/CopilotTask.h @@ -7,6 +7,7 @@ namespace asst { class BattleProcessTask; class BattleFormationTask; + class ProcessTask; // 抄作业任务 class CopilotTask final : public InterfaceTask @@ -23,6 +24,7 @@ namespace asst private: std::shared_ptr m_formation_task_ptr = nullptr; std::shared_ptr m_battle_task_ptr = nullptr; + std::shared_ptr m_stop_task_ptr = nullptr; std::string m_stage_name; }; } diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index 8fb0dbc085..8794a4c9d9 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -632,6 +632,7 @@ namespace MaaWpfGui string subTask = details["subtask"].ToString(); var mainModel = _container.Get(); + var copilotModel = _container.Get(); if (subTask == "ProcessTask") { string taskName = details["details"]["task"].ToString(); @@ -735,6 +736,10 @@ namespace MaaWpfGui case "GamePass": mainModel.AddLog(Localization.GetString("RoguelikeGamePass"), UILogColor.RareOperator); break; + + case "BattleStartAll": + copilotModel.AddLog(Localization.GetString("MissionStart"), UILogColor.Info); + break; } } } @@ -1526,13 +1531,15 @@ namespace MaaWpfGui /// 作业 JSON 的文件路径,绝对、相对路径均可。 /// 是否进行 “快捷编队”。 /// 任务类型 + /// 任务重复执行次数 /// 是否成功。 - public bool AsstStartCopilot(string filename, bool formation, string type) + public bool AsstStartCopilot(string filename, bool formation, string type, int loop_times) { var task_params = new JObject { ["filename"] = filename, ["formation"] = formation, + ["loop_times"] = loop_times, }; AsstTaskId id = AsstAppendTaskWithEncoding(type, task_params); _latestTaskId[TaskType.Copilot] = id; diff --git a/src/MaaWpfGui/Main/CopilotViewModel.cs b/src/MaaWpfGui/Main/CopilotViewModel.cs index e28bf28a03..5455e512bd 100644 --- a/src/MaaWpfGui/Main/CopilotViewModel.cs +++ b/src/MaaWpfGui/Main/CopilotViewModel.cs @@ -400,6 +400,20 @@ namespace MaaWpfGui set => SetAndNotify(ref _form, value); } + public bool Loop { get; set; } = false; + + private int _loopTimes = int.Parse(ViewStatusStorage.Get("Copilot.LoopTimes", "1")); + + public int LoopTimes + { + get => _loopTimes; + set + { + SetAndNotify(ref _loopTimes, value); + ViewStatusStorage.Set("Copilot.LoopTimes", value.ToString()); + } + } + private bool _caught = false; /// @@ -434,7 +448,8 @@ namespace MaaWpfGui AddLog(errMsg, UILogColor.Error); } - bool ret = asstProxy.AsstStartCopilot(_isDataFromWeb ? TempCopilotFile : Filename, Form, TaskType); + bool ret = asstProxy.AsstStartCopilot(_isDataFromWeb ? TempCopilotFile : Filename, Form, TaskType, + Loop ? LoopTimes : 1); if (ret) { AddLog(Localization.GetString("Running")); diff --git a/src/MaaWpfGui/Res/Localizations/en-us.xaml b/src/MaaWpfGui/Res/Localizations/en-us.xaml index 0445965ddc..f5e2f5555c 100644 --- a/src/MaaWpfGui/Res/Localizations/en-us.xaml +++ b/src/MaaWpfGui/Res/Localizations/en-us.xaml @@ -359,6 +359,7 @@ Task files can be directly dragged in with the mouse (o゚v゚)ノ Auto squad The operator of "special focus" cannot be identified at this time + LoopTimes Start diff --git a/src/MaaWpfGui/Res/Localizations/ja-jp.xaml b/src/MaaWpfGui/Res/Localizations/ja-jp.xaml index 4a36a93a04..4dc18ac012 100644 --- a/src/MaaWpfGui/Res/Localizations/ja-jp.xaml +++ b/src/MaaWpfGui/Res/Localizations/ja-jp.xaml @@ -329,6 +329,7 @@ 攻略ファイルはマウスで直接ドラッグして取り込むことがきます(o゚v゚)ノ 自動編成 自動編成では、一時的に「戦術要員」オペレーターを認識できません + LoopTimes 開始 diff --git a/src/MaaWpfGui/Res/Localizations/ko-kr.xaml b/src/MaaWpfGui/Res/Localizations/ko-kr.xaml index 0071cfeabf..43611436b7 100644 --- a/src/MaaWpfGui/Res/Localizations/ko-kr.xaml +++ b/src/MaaWpfGui/Res/Localizations/ko-kr.xaml @@ -356,6 +356,7 @@ 마우스로 작업 파일을 드래그해 선택할 수 있어요 (o゚v゚)ノ 자동 편성 자동 편성은 '선호' 오퍼레이터를 인식할 수 없습니다 + LoopTimes 시작 diff --git a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml index 4679d1baac..2dfaa2ae90 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml @@ -358,6 +358,7 @@ 选择作业 作业文件可以直接用鼠标拖进来哦 (o゚v゚)ノ 自动编队 + 循环次数 自动编队暂时无法识别“特别关注”的干员 开始 diff --git a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml index 4d08005799..aa248176eb 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml @@ -313,6 +313,7 @@ 選擇作業 作業檔可以直接用滑鼠拖進來喔 (o゚v゚)ノ 自動編隊 + LoopTimes 自動編隊暫時無法辨識“特別關注”的幹員 開始 diff --git a/src/MaaWpfGui/Views/CopilotView.xaml b/src/MaaWpfGui/Views/CopilotView.xaml index 9557ca4fc9..a862a6b183 100644 --- a/src/MaaWpfGui/Views/CopilotView.xaml +++ b/src/MaaWpfGui/Views/CopilotView.xaml @@ -4,6 +4,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:c="clr-namespace:CalcBinding;assembly=CalcBinding" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:local="clr-namespace:MaaWpfGui" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:s="https://github.com/canton7/Stylet" @@ -48,25 +49,44 @@ ToolTip="{DynamicResource SelectTheFileTip}" /> -