fix.修复自动抄作业的一些bug

This commit is contained in:
MistEO
2022-03-28 22:32:57 +08:00
parent d1d29b537a
commit e49c3ee367
4 changed files with 44 additions and 15 deletions

View File

@@ -3484,7 +3484,7 @@
118
],
"action": "ClickSelf",
"preDelay": 500,
"rearDelay": 500,
"rectMove": [
0,
-110,
@@ -3495,7 +3495,7 @@
"BattleOperRetreat": {
"algorithm": "JustReturn",
"action": "ClickRect",
"preDelay": 500,
"rearDelay": 500,
"specificRect": [
563,
190,
@@ -4228,6 +4228,10 @@
[
"姜哦",
"嵯峨"
],
[
"健影",
"傀影"
]
],
"roi": [

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -2,6 +2,7 @@
#include "AsstUtils.hpp"
#include "Controller.h"
#include "Logger.hpp"
asst::AbstractImageAnalyzer::AbstractImageAnalyzer(const cv::Mat image)
: m_image(image), m_roi(empty_rect_to_full(Rect(), image))
@@ -43,5 +44,28 @@ void asst::AbstractImageAnalyzer::set_roi(const Rect& roi) noexcept
asst::Rect asst::AbstractImageAnalyzer::empty_rect_to_full(const Rect& rect, const cv::Mat image) noexcept
{
return rect.empty() ? Rect(0, 0, image.cols, image.rows) : rect;
if (rect.empty()) {
return Rect(0, 0, image.cols, image.rows);
}
else {
Rect res = rect;
if (image.cols < res.x) {
Log.error("roi is out of range", image.cols, image.rows, res.to_string());
res.x = image.cols - res.width;
}
if (image.rows < res.y) {
Log.error("roi is out of range", image.cols, image.rows, res.to_string());
res.y = image.rows - res.height;
}
if (image.cols < res.x + res.width) {
Log.error("roi is out of range", res.to_string());
res.width = image.cols - res.x;
}
if (image.rows < res.y + res.height) {
Log.error("roi is out of range", res.to_string());
res.height = image.rows - res.y;
}
return res;
}
}

View File

@@ -101,20 +101,23 @@ bool asst::BattleProcessTask::analyze_opers_preview()
}
opers.at(i).name = oper_name;
bool not_found = true;
// 找出这个干员是哪个组里的,以及他的技能用法等
for (const auto& [group_name, deploy_opers] : m_actions_group.groups) {
auto iter = std::find_if(deploy_opers.cbegin(), deploy_opers.cend(),
[&](const BattleDeployOper& deploy) -> bool {
return deploy.name == oper_name;
});
// 没找到,可能是召唤物等新出现的;可能是干员名识别错了(这种情况处理不了,不管了)
if (iter == deploy_opers.cend()) {
m_group_to_oper_mapping.emplace(group_name, BattleDeployOper{ group_name });
}
else {
if (iter != deploy_opers.cend()) {
m_group_to_oper_mapping.emplace(group_name, *iter);
not_found = false;
break;
}
}
// 没找到,可能是召唤物等新出现的
if (not_found) {
m_group_to_oper_mapping.emplace(oper_name, BattleDeployOper{ oper_name });
}
m_cur_opers_info.emplace(std::move(oper_name), std::move(opers.at(i)));
@@ -208,8 +211,7 @@ bool asst::BattleProcessTask::update_opers_info(const cv::Mat& image)
m_ctrler->click(cur_oper.rect);
sleep(Task.get("BattleUseOper")->pre_delay);
auto image = m_ctrler->get_image();
OcrImageAnalyzer name_analyzer(image);
OcrImageAnalyzer name_analyzer(m_ctrler->get_image());
name_analyzer.set_task_info("BattleOperName");
name_analyzer.set_replace(
std::dynamic_pointer_cast<OcrTaskInfo>(
@@ -263,7 +265,7 @@ bool asst::BattleProcessTask::do_action(const BattleAction& action)
break;
case BattleActionType::BulletTime:
break;
case BattleActionType::SkillUsage:
case BattleActionType::SkillUsage:
{
auto& oper_info = m_group_to_oper_mapping[action.group_name];
oper_info.skill_usage = action.modify_usage;
@@ -313,7 +315,6 @@ bool asst::BattleProcessTask::oper_deploy(const BattleAction& action)
}
try_possible_skill(image);
} while (iter == m_cur_opers_info.cend() || !iter->second.available);
// 点击干员
@@ -356,9 +357,9 @@ bool asst::BattleProcessTask::oper_deploy(const BattleAction& action)
m_ctrler->swipe(placed_point, end_point, swipe_oper_task_ptr->rear_delay);
}
m_used_opers[iter->first] = BattleDeployInfo{
action.location,
m_normal_tile_info[action.location].pos,
m_used_opers[iter->first] = BattleDeployInfo{
action.location,
m_normal_tile_info[action.location].pos,
std::move(oper_info) };
m_cur_opers_info.erase(iter);