From eab91a63494de3dfffbd2bc181d9b78070d0d046 Mon Sep 17 00:00:00 2001 From: MistEO Date: Sat, 20 May 2023 13:52:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E6=88=98=E6=96=97?= =?UTF-8?q?=E7=BC=96=E9=98=9F=E5=88=97=E8=A1=A8=E8=AF=86=E5=88=AB=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E6=97=B6=EF=BC=8C=E8=87=AA=E5=8A=A8=E5=88=92=E5=9B=9E?= =?UTF-8?q?=E6=9D=A5=E9=87=8D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/MaaAssistantArknights/MaaAssistantArknights/issues/4819 --- resource/tasks.json | 15 ++++++++++++ .../Miscellaneous/BattleFormationTask.cpp | 23 +++++++++++++++++-- .../Task/Miscellaneous/BattleFormationTask.h | 3 +++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/resource/tasks.json b/resource/tasks.json index fb89cbd3f0..3010fb8130 100644 --- a/resource/tasks.json +++ b/resource/tasks.json @@ -7286,6 +7286,21 @@ 20 ] }, + "BattleFormationOperListSwipeToTheLeft": { + "baseTask": "SwipeToTheLeft", + "specificRect": [ + 400, + 350, + 20, + 20 + ], + "rectMove": [ + 1100, + 350, + 20, + 20 + ] + }, "Roguelike@Abandon": { "Doc": "base_task", "template": "empty.png", diff --git a/src/MaaCore/Task/Miscellaneous/BattleFormationTask.cpp b/src/MaaCore/Task/Miscellaneous/BattleFormationTask.cpp index b4c1423a8b..1d7cd03cdb 100644 --- a/src/MaaCore/Task/Miscellaneous/BattleFormationTask.cpp +++ b/src/MaaCore/Task/Miscellaneous/BattleFormationTask.cpp @@ -41,6 +41,7 @@ bool asst::BattleFormationTask::_run() for (auto& [role, oper_groups] : m_formation) { click_role_table(role); bool has_error = false; + int swipe_times = 0; while (!need_exit()) { if (select_opers_in_cur_page(oper_groups)) { has_error = false; @@ -48,17 +49,21 @@ bool asst::BattleFormationTask::_run() break; } swipe_page(); + ++swipe_times; } else if (has_error) { + swipe_to_the_left(swipe_times); // reset page click_role_table(role == battle::Role::Unknown ? battle::Role::Pioneer : battle::Role::Unknown); click_role_table(role); + swipe_to_the_left(swipe_times); + swipe_times = 0; has_error = false; } else { has_error = true; - // swipe and retry again - swipe_page(); + swipe_to_the_left(swipe_times); + swipe_times = 0; } } } @@ -179,6 +184,13 @@ bool asst::BattleFormationTask::select_opers_in_cur_page(std::vector& Task.get("BattleQuickFormationSkill3")->specific_rect, }; + if (opers_result.empty() || m_last_oper_name == opers_result.back().text) { + Log.info("last oper name is same as current, skip"); + return false; + } + + m_last_oper_name = opers_result.back().text; + int delay = Task.get("BattleQuickFormationOCR")->post_delay; int skill = 1; @@ -223,6 +235,13 @@ void asst::BattleFormationTask::swipe_page() ProcessTask(*this, { "BattleFormationOperListSlowlySwipeToTheRight" }).run(); } +void asst::BattleFormationTask::swipe_to_the_left(int times) +{ + for (int i = 0; i < times; ++i) { + ProcessTask(*this, { "BattleFormationOperListSwipeToTheLeft" }).run(); + } +} + bool asst::BattleFormationTask::confirm_selection() { return ProcessTask(*this, { "BattleQuickFormationConfirm" }).run(); diff --git a/src/MaaCore/Task/Miscellaneous/BattleFormationTask.h b/src/MaaCore/Task/Miscellaneous/BattleFormationTask.h index 256757b166..221e04036d 100644 --- a/src/MaaCore/Task/Miscellaneous/BattleFormationTask.h +++ b/src/MaaCore/Task/Miscellaneous/BattleFormationTask.h @@ -43,6 +43,7 @@ namespace asst 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(); @@ -56,5 +57,7 @@ namespace asst std::string m_support_unit_name; DataResource m_data_resource = DataResource::Copilot; std::vector m_additional; + + std::string m_last_oper_name; }; }