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; }; }