diff --git a/resource/tasks.json b/resource/tasks.json index 960c7e5a17..2f7fae73c6 100644 --- a/resource/tasks.json +++ b/resource/tasks.json @@ -7216,6 +7216,57 @@ ] ] }, + "BattleSelectedFormation": { + "action": "DoNothing", + "roi": [ + 50, + 600, + 1180, + 120 + ], + "cache": false, + "maskRange": [ + 1, + 255 + ] + }, + "BattleSelectFormation0": { + "algorithm": "JustReturn", + "action": "ClickRect", + "specificRect": [ + 180, + 670, + 115, + 40 + ] + }, + "BattleSelectFormation1": { + "baseTask": "BattleSelectFormation0", + "specificRect": [ + 460, + 670, + 100, + 40 + ] + }, + "BattleSelectFormation2": { + "baseTask": "BattleSelectFormation0", + "specificRect": [ + 720, + 670, + 120, + 40 + ] + }, + "BattleSelectFormation3": { + "baseTask": "BattleSelectFormation0", + "specificRect": [ + 995, + 675, + 110, + 40 + ] + }, "BattleSupportUnitFormation": { "action": "ClickSelf", "roi": [ @@ -15519,4 +15570,4 @@ "Stop" ] } -} \ No newline at end of file +} diff --git a/resource/template/BattleSelectedFormation.png b/resource/template/BattleSelectedFormation.png new file mode 100644 index 0000000000..bd221c8b36 Binary files /dev/null and b/resource/template/BattleSelectedFormation.png differ diff --git a/src/MaaCore/Task/Miscellaneous/BattleFormationTask.cpp b/src/MaaCore/Task/Miscellaneous/BattleFormationTask.cpp index ec97cc33eb..5a55642af7 100644 --- a/src/MaaCore/Task/Miscellaneous/BattleFormationTask.cpp +++ b/src/MaaCore/Task/Miscellaneous/BattleFormationTask.cpp @@ -10,6 +10,7 @@ #include "Task/ProcessTask.h" #include "Utils/ImageIo.hpp" #include "Utils/Logger.hpp" +#include "Vision/Matcher.h" #include "Vision/MultiMatcher.h" #include "Vision/TemplDetOCRer.h" @@ -38,6 +39,11 @@ void asst::BattleFormationTask::set_add_trust(bool add_trust) m_add_trust = add_trust; } +void asst::BattleFormationTask::set_select_formation(formation_index index) +{ + m_select_formation_index = index; +} + void asst::BattleFormationTask::set_data_resource(DataResource resource) { m_data_resource = resource; @@ -51,6 +57,10 @@ bool asst::BattleFormationTask::_run() return false; } + if (!select_formation()) { + return false; + } + if (!enter_selection_page()) { save_img(utils::path("debug") / utils::path("other")); return false; @@ -415,3 +425,21 @@ bool asst::BattleFormationTask::parse_formation() callback(AsstMsg::SubTaskExtraInfo, info); return true; } + +bool asst::BattleFormationTask::select_formation(const cv::Mat& image) +{ + LogTraceFunction; + + Matcher selected_searcher(image); + selected_searcher.set_task_info("BattleSelectedFormation"); + selected_searcher.analyze(); + formation_index result = formation_index_from_rect(selected_searcher.get_result().rect); + if (result == m_select_formation_index) return true; + + return ProcessTask { *this, { m_taskname_from_index[m_select_formation_index] } }.run(); +} + +bool asst::BattleFormationTask::select_formation() +{ + return select_formation(ctrler()->get_image()); +} diff --git a/src/MaaCore/Task/Miscellaneous/BattleFormationTask.h b/src/MaaCore/Task/Miscellaneous/BattleFormationTask.h index 39053954f6..3c41809cd6 100644 --- a/src/MaaCore/Task/Miscellaneous/BattleFormationTask.h +++ b/src/MaaCore/Task/Miscellaneous/BattleFormationTask.h @@ -12,6 +12,8 @@ namespace asst using AbstractTask::AbstractTask; virtual ~BattleFormationTask() override = default; + using formation_index = size_t; + enum class Filter { None, @@ -33,6 +35,8 @@ namespace asst void set_user_additional(std::vector> user_additional); // 是否追加低信赖干员 void set_add_trust(bool add_trust); + // 设置对指定编队自动编队 + void set_select_formation(formation_index index); enum class DataResource { @@ -57,6 +61,8 @@ namespace asst bool confirm_selection(); bool click_role_table(battle::Role role); bool parse_formation(); + bool select_formation(const cv::Mat& image); + bool select_formation(); bool select_random_support_unit(); std::vector analyzer_opers(); @@ -77,5 +83,17 @@ namespace asst DataResource m_data_resource = DataResource::Copilot; std::vector m_additional; std::string m_last_oper_name; + formation_index m_select_formation_index = 3; + const std::vector m_taskname_from_index = { "BattleSelectFormation0", "BattleSelectFormation1", + "BattleSelectFormation2", "BattleSelectFormation3" }; + + static formation_index formation_index_from_rect(const Rect& r) + { /* 0 | 1 | 2 | 3 */ + int cx = r.x + r.width / 2; + if (cx <= 370) return 0; + if (cx >= 370 && cx <= 640) return 1; + if (cx >= 645 && cx <= 915) return 2; + return 3; + } }; } // namespace asst