feat: 自动编队时使用指定编队

This commit is contained in:
youqii
2023-10-24 15:02:25 +08:00
parent 8e74daf8f2
commit 199782dbfa
4 changed files with 98 additions and 1 deletions

View File

@@ -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"
]
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@@ -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());
}

View File

@@ -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<std::pair<std::string, int>> 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<TextRect> analyzer_opers();
@@ -77,5 +83,17 @@ namespace asst
DataResource m_data_resource = DataResource::Copilot;
std::vector<AdditionalFormation> m_additional;
std::string m_last_oper_name;
formation_index m_select_formation_index = 3;
const std::vector<std::string> 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