From 34fa74e8f3c2c6b9402293cf130d0f106ece2a6f Mon Sep 17 00:00:00 2001 From: status102 <102887808+status102@users.noreply.github.com> Date: Thu, 13 Feb 2025 09:49:44 +0800 Subject: [PATCH] =?UTF-8?q?feat!:=20=E8=87=AA=E5=8A=A8=E6=88=98=E6=96=97?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E5=85=81=E8=AE=B8=E4=BD=BF=E7=94=A8=E5=B8=A6?= =?UTF-8?q?TR=E7=9A=84=E5=AF=BC=E8=88=AA=E5=85=B3=E5=8D=A1=E5=90=8D?= =?UTF-8?q?=E7=A6=81=E7=94=A8=E8=87=AA=E5=8A=A8=E7=BC=96=E9=98=9F=EF=BC=8C?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E8=87=AA=E5=8A=A8=E6=A3=80=E6=B5=8B=20(#1186?= =?UTF-8?q?8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 自动战斗不再允许使用带TR的导航关卡名禁用自动编队,改为自动检测 * chore: Auto update by pre-commit hooks [skip changelog] --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- resource/tasks.json | 4 +++ resource/template/BattleFormationInvalid.png | Bin 0 -> 3815 bytes src/MaaCore/Task/Interface/CopilotTask.cpp | 3 +- .../Miscellaneous/BattleFormationTask.cpp | 33 ++++++++++++------ .../Task/Miscellaneous/BattleFormationTask.h | 7 ++-- 5 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 resource/template/BattleFormationInvalid.png diff --git a/resource/tasks.json b/resource/tasks.json index 40a3c12ef4..0f78f216ff 100644 --- a/resource/tasks.json +++ b/resource/tasks.json @@ -5909,6 +5909,10 @@ "baseTask": "BattleStartPre", "action": "DoNothing" }, + "BattleFormationInvalid": { + "action": "DoNothing", + "roi": [200, 650, 400, 70] + }, "BattleFormationOCRNameFlag": { "templThreshold": 0.6, "roi": [88, 264, 873, 354] diff --git a/resource/template/BattleFormationInvalid.png b/resource/template/BattleFormationInvalid.png new file mode 100644 index 0000000000000000000000000000000000000000..06645d2a06c1629a339680a120c392ed2d71cddb GIT binary patch literal 3815 zcmVPx#32;bRa{vGi!vFvd!vV){sAK>D4va}eK~#9!y;yr}6nB1~_s;IjKKxjFjg1|f z01nv4!(4#7D7>+a0R>R)M35s@lPXem{pY0ipOY%JmHPOvQBP`h5lxYjJl7=QE zP4ML|fe=G@*#-`<@f&;X-JPA8o%i&^j6KeJ4N;=%zBB9$zxn>Yzt8Xc{+WE~_>TyZ zSRfKNE|B;1Z~P;@5e&JcKR(Yzk<|P|io%%VO_3$QM%iWfInJOETQMg(y1<8w4LG!Xwk6fFGR1&}LOt}KzbR7rm@ zA~$W?RI(yj3I>l7;|Fgg-+c=N1COV`TwrhC*Io=D@QX!3Wbh4CylCJ_OJ@b|0XUzb z6oU`kM{}U#Krp>1fJ&tza01s|9P^orMuVvs4!E2El=lb_1wIU-z6Nvwt6Rcf?ESbv z{(dNmN~LP*>+35jDzJL-Rs$~ApX9F`EZ`IIH6G7W#Y6`BEjEh(DcCT^Sca{tuKw|l z|Gc(#MPJ{g)BpZPJ}w@y$VF$}YA-MU@7cG0de_r)n?r|W8KcI?;@ z3Wa>heu02kF2sS5pC01?)YnrBxGO3vDwD}rG|I8;vL+Knar5TQTefUr^OM@ew+&6c zY*zoTT6;wnjr558+0PTavwi#4mX;O<5=as^%d)X}tfIUe(Z?{4^Hd731IGk6QV0ZS zx?Y+#0EnTPy1Kgdj*f&FF^8_EubiKcac_7*KON=lvh)rKvB_X6!y+$vvYHEg+jqu&gsF^+WNhgmi4qeMSpfml`|hH zD@QawZ!>p{*cDxnX9v^2`B$DY&>A$YS{33$@kAWCz_y)iHiuN?x=slU*AFllm!Uku zGBAOrY3X#@ah8V*4x%0^2OwFNVHqIOa#9Y8fwu!q!0bO92cSpDUaz zLcYY5_gghm!Jaw)i9J19Ut81N-IGWpVD6yh0(zbgMPpHhWz>QyD>9$}0EN7Q$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1iX&67p$K{G*s*9dW@>UCHOSE6 zCyQs_;$5RYB&(8$Qb|G$FF3C4xeIu_s|YoLvs`sm6^e8wlksa1+{I&F3LA}zAVw1v zNmP6C<(FTEMKK4pW%;}^?};HCB;WyHRusPmEyEm~I#95XOMt^qo_@hvlB*UvG7;?? dmYGe@{vU;B==e0t0-OK<002ovPDHLkV1k`JN(%r0 literal 0 HcmV?d00001 diff --git a/src/MaaCore/Task/Interface/CopilotTask.cpp b/src/MaaCore/Task/Interface/CopilotTask.cpp index 507739c609..ebe2ee24c3 100644 --- a/src/MaaCore/Task/Interface/CopilotTask.cpp +++ b/src/MaaCore/Task/Interface/CopilotTask.cpp @@ -144,8 +144,7 @@ bool asst::CopilotTask::set_params(const json::value& params) m_not_use_prts_task_ptr->set_enable(need_navigate); // 不使用代理指挥 m_medicine_plugin_ptr->set_enable(use_sanity_potion); - // 关卡名含有"TR"的为教学关,不需要编队 - m_formation_task_ptr->set_enable(with_formation && navigate_name.find("TR") == std::string::npos); + m_formation_task_ptr->set_enable(with_formation); m_formation_task_ptr->set_select_formation(select_formation); m_formation_task_ptr->set_add_trust(add_trust); m_formation_task_ptr->set_support_unit_usage(support_unit_usage); diff --git a/src/MaaCore/Task/Miscellaneous/BattleFormationTask.cpp b/src/MaaCore/Task/Miscellaneous/BattleFormationTask.cpp index 57a05085a3..4ee3818967 100644 --- a/src/MaaCore/Task/Miscellaneous/BattleFormationTask.cpp +++ b/src/MaaCore/Task/Miscellaneous/BattleFormationTask.cpp @@ -48,15 +48,20 @@ bool asst::BattleFormationTask::_run() { LogTraceFunction; + const auto& img = ctrler()->get_image(); + if (!is_formation_valid(img)) { + return true; // 编队不可用,直接返回,常见于TR关卡 + } + if (!parse_formation()) { return false; } - if (m_select_formation_index > 0 && !select_formation(m_select_formation_index)) { + if (m_select_formation_index > 0 && !select_formation(m_select_formation_index, img)) { return false; } - if (!enter_selection_page()) { + if (!enter_selection_page(img)) { save_img(utils::path("debug") / utils::path("other")); return false; } @@ -387,9 +392,9 @@ std::vector asst::BattleFormationTask::analyzer_ope return opers_result; } -bool asst::BattleFormationTask::enter_selection_page() +bool asst::BattleFormationTask::enter_selection_page(const cv::Mat& img) { - return ProcessTask(*this, { "BattleQuickFormation" }).set_retry_times(3).run(); + return ProcessTask(*this, { "BattleQuickFormation" }).set_reusable_image(img).set_retry_times(3).run(); } bool asst::BattleFormationTask::select_opers_in_cur_page(std::vector& groups) @@ -534,17 +539,25 @@ bool asst::BattleFormationTask::parse_formation() return true; } -bool asst::BattleFormationTask::select_formation(int select_index) +bool asst::BattleFormationTask::select_formation(int select_index, const cv::Mat& img) { // 编队不会触发改名的区域有两组 // 一组是上面的黑长条 260*9 // 第二组是名字最左边和最右边的一块区域 // 右边比左边窄,暂定为左边 10*58 - static const std::vector select_formation_task = { "BattleSelectFormation1", - "BattleSelectFormation2", - "BattleSelectFormation3", - "BattleSelectFormation4" }; + static const std::array select_formation_task = { "BattleSelectFormation1", + "BattleSelectFormation2", + "BattleSelectFormation3", + "BattleSelectFormation4" }; - return ProcessTask { *this, { select_formation_task[select_index - 1] } }.run(); + return ProcessTask { *this, { select_formation_task[select_index - 1] } }.set_reusable_image(img).run(); +} + +bool asst::BattleFormationTask::is_formation_valid(const cv::Mat& img) const +{ + static const std::string valid_task = "BattleStartPre@BattleQuickFormation"; + ProcessTask task(*this, { "BattleFormationInvalid", valid_task }); + task.set_reusable_image(img); + return task.run() && task.get_last_task_name() == valid_task; } diff --git a/src/MaaCore/Task/Miscellaneous/BattleFormationTask.h b/src/MaaCore/Task/Miscellaneous/BattleFormationTask.h index e2035917fa..46c68c8cdc 100644 --- a/src/MaaCore/Task/Miscellaneous/BattleFormationTask.h +++ b/src/MaaCore/Task/Miscellaneous/BattleFormationTask.h @@ -79,6 +79,10 @@ protected: using OperGroup = std::pair>; virtual bool _run() override; + bool parse_formation(); + bool is_formation_valid(const cv::Mat& img) const; + bool select_formation(int select_index, const cv::Mat& img); + bool enter_selection_page(const cv::Mat& img = cv::Mat()); // 进入快捷编队清空选择后执行,快速选择非干员组的干员 void formation_with_last_opers(); bool add_formation(battle::Role role, std::vector oper_group, std::vector& missing); @@ -86,14 +90,11 @@ protected: bool add_additional(); // 补充刷信赖的干员,从最小的开始 bool add_trust_operators(); - bool enter_selection_page(); bool select_opers_in_cur_page(std::vector& groups); void swipe_page(); void swipe_to_the_left(int times = 2); bool confirm_selection(); bool click_role_table(battle::Role role); - bool parse_formation(); - bool select_formation(int select_index); bool select_random_support_unit(); void report_missing_operators(std::vector& groups);