mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 18:47:55 +08:00
feat: 添加hp识别判断是否成功点击
This commit is contained in:
@@ -12516,6 +12516,8 @@
|
||||
"Roguelike@SpecialValRecognition": {
|
||||
"algorithm": "OcrDetect",
|
||||
"action": "DoNothing",
|
||||
"Doc": "特殊值识别,如抗干扰值,需修改对应主题的roi",
|
||||
";": null,
|
||||
"text": [],
|
||||
"roi": [
|
||||
615,
|
||||
@@ -12524,6 +12526,18 @@
|
||||
45
|
||||
]
|
||||
},
|
||||
"Roguelike@HpRecognition": {
|
||||
"algorithm": "OcrDetect",
|
||||
"action": "DoNothing",
|
||||
"Doc": "生命值识别,暂时是把整个框进去,估计会把后面的生命值也识别到,后面得改改",
|
||||
"text": [],
|
||||
"roi": [
|
||||
190,
|
||||
30,
|
||||
60,
|
||||
30
|
||||
]
|
||||
},
|
||||
"Roguelike@StageEncounterJudgeOption": {
|
||||
"algorithm": "JustReturn",
|
||||
"action": "DoNothing",
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
#include "RoguelikeStageEncounterTaskPlugin.h"
|
||||
|
||||
#include "Config/Roguelike/RoguelikeStageEncounterConfig.h"
|
||||
#include "Config/TaskData.h"
|
||||
#include "Controller/Controller.h"
|
||||
#include "Status.h"
|
||||
#include "Task/ProcessTask.h"
|
||||
#include "Utils/ImageIo.hpp"
|
||||
#include "Utils/Logger.hpp"
|
||||
#include "Vision/OCRer.h"
|
||||
|
||||
bool asst::RoguelikeStageEncounterTaskPlugin::verify(AsstMsg msg, const json::value& details) const
|
||||
{
|
||||
@@ -84,7 +82,7 @@ bool asst::RoguelikeStageEncounterTaskPlugin::_run()
|
||||
if (!analyzer.analyze()) {
|
||||
return false;
|
||||
}
|
||||
special_val = std::stoi(analyzer.get_result().front().text);
|
||||
utils::chars_to_number(analyzer.get_result().front().text, special_val);
|
||||
}
|
||||
|
||||
int choose_option = process_task(event, special_val);
|
||||
@@ -103,5 +101,30 @@ bool asst::RoguelikeStageEncounterTaskPlugin::_run()
|
||||
sleep(300);
|
||||
}
|
||||
|
||||
return true;
|
||||
// 判断是否点击成功,成功进入对话后左上角的生命值会消失
|
||||
image = ctrler()->get_image();
|
||||
if (hp(image) == -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int max_time = event.option_num;
|
||||
while (max_time > 0) {
|
||||
for (int i = 0; i < max_time; ++i) {
|
||||
for (int j = 0; j < 2; ++j) {
|
||||
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@OptionChoose" + std::to_string(max_time) +
|
||||
"-" + std::to_string(i) })
|
||||
.run();
|
||||
sleep(300);
|
||||
}
|
||||
|
||||
image = ctrler()->get_image();
|
||||
if (hp(image) == -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// 没通关结局有些事件会少选项
|
||||
--max_time;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
#include "AbstractRoguelikeTaskPlugin.h"
|
||||
#include "Config/Roguelike/RoguelikeStageEncounterConfig.h"
|
||||
#include "Config/TaskData.h"
|
||||
#include "Vision/OCRer.h"
|
||||
|
||||
namespace asst
|
||||
{
|
||||
@@ -20,11 +22,11 @@ namespace asst
|
||||
int num = 0;
|
||||
switch (requirement.chaos_level.type) {
|
||||
case ">":
|
||||
return utils::chars_to_number<int, true>(requirement.chaos_level.value, num) && special_val > num;
|
||||
return utils::chars_to_number(requirement.chaos_level.value, num) && special_val > num;
|
||||
case "<":
|
||||
return utils::chars_to_number<int, true>(requirement.chaos_level.value, num) && special_val < num;
|
||||
return utils::chars_to_number(requirement.chaos_level.value, num) && special_val < num;
|
||||
case "=":
|
||||
return utils::chars_to_number<int, true>(requirement.chaos_level.value, num) && special_val == num;
|
||||
return utils::chars_to_number(requirement.chaos_level.value, num) && special_val == num;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -39,5 +41,19 @@ namespace asst
|
||||
}
|
||||
return event.default_choose;
|
||||
}
|
||||
|
||||
static int hp(const cv::Mat& image)
|
||||
{
|
||||
int hp_val = -1;
|
||||
asst::OCRer analyzer(image);
|
||||
analyzer.set_task_info("Roguelike@HpRecognition");
|
||||
analyzer.set_replace(Task.get<OcrTaskInfo>("NumberOcrReplace")->replace_map);
|
||||
analyzer.set_use_char_model(true);
|
||||
|
||||
if (!analyzer.analyze()) {
|
||||
return 0;
|
||||
}
|
||||
return utils::chars_to_number(analyzer.get_result().front().text, hp_val) ? hp_val : -1;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user