mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-20 02:55:38 +08:00
perf: 优化肉鸽难度选择逻辑
This commit is contained in:
@@ -56,21 +56,12 @@
|
||||
"JieGarden@Roguelike@ChooseDifficulty": {
|
||||
"roi": [1079, 304, 201, 153]
|
||||
},
|
||||
"JieGarden@Roguelike@ChooseDifficulty_Easiest": {
|
||||
"JieGarden@Roguelike@ChooseDifficultyEnter": {
|
||||
"action": "ClickRect",
|
||||
"specificRect": [1119, 479, 80, 22],
|
||||
"postDelay": 800,
|
||||
"template": "JieGarden@Roguelike@StartExplore.png",
|
||||
"roi": [958, 530, 322, 189],
|
||||
"sub": ["SwipeToTheUp*2"]
|
||||
},
|
||||
"JieGarden@Roguelike@ChooseDifficulty_Hardest": {
|
||||
"action": "ClickRect",
|
||||
"specificRect": [1119, 479, 80, 22],
|
||||
"postDelay": 800,
|
||||
"template": "JieGarden@Roguelike@StartExplore.png",
|
||||
"roi": [958, 530, 322, 189],
|
||||
"sub": ["SwipeToTheDown*2"]
|
||||
"roi": [958, 530, 322, 189]
|
||||
},
|
||||
"JieGarden@Roguelike@ChooseOper": {
|
||||
"next": [
|
||||
|
||||
@@ -18,21 +18,12 @@
|
||||
"text": ["生态谱系"]
|
||||
},
|
||||
"Mizuki@Roguelike@ChooseDifficulty": {},
|
||||
"Mizuki@Roguelike@ChooseDifficulty_Easiest": {
|
||||
"Mizuki@Roguelike@ChooseDifficultyEnter": {
|
||||
"action": "ClickRect",
|
||||
"specificRect": [1144, 472, 78, 24],
|
||||
"postDelay": 800,
|
||||
"template": "Mizuki@Roguelike@StartExplore.png",
|
||||
"roi": [1026, 470, 254, 248],
|
||||
"sub": ["SwipeToTheUp*2"]
|
||||
},
|
||||
"Mizuki@Roguelike@ChooseDifficulty_Hardest": {
|
||||
"action": "ClickRect",
|
||||
"specificRect": [1144, 472, 78, 24],
|
||||
"postDelay": 800,
|
||||
"template": "Mizuki@Roguelike@StartExplore.png",
|
||||
"roi": [1026, 470, 254, 248],
|
||||
"sub": ["SwipeToTheDown*2"]
|
||||
"roi": [1026, 470, 254, 248]
|
||||
},
|
||||
"Mizuki@Roguelike@ChooseOper": {
|
||||
"next": [
|
||||
|
||||
@@ -18,21 +18,12 @@
|
||||
"text": ["古堡笔记"]
|
||||
},
|
||||
"Phantom@Roguelike@ChooseDifficulty": {},
|
||||
"Phantom@Roguelike@ChooseDifficulty_Easiest": {
|
||||
"Phantom@Roguelike@ChooseDifficultyEnter": {
|
||||
"action": "ClickRect",
|
||||
"specificRect": [1144, 472, 78, 24],
|
||||
"postDelay": 800,
|
||||
"template": "Phantom@Roguelike@StartExplore.png",
|
||||
"roi": [1026, 470, 254, 248],
|
||||
"sub": ["SwipeToTheUp*2"]
|
||||
},
|
||||
"Phantom@Roguelike@ChooseDifficulty_Hardest": {
|
||||
"action": "ClickRect",
|
||||
"specificRect": [1144, 472, 78, 24],
|
||||
"postDelay": 800,
|
||||
"template": "Phantom@Roguelike@StartExplore.png",
|
||||
"roi": [1026, 470, 254, 248],
|
||||
"sub": ["SwipeToTheDown*2"]
|
||||
"roi": [1026, 470, 254, 248]
|
||||
},
|
||||
"Phantom@Roguelike@ChooseOper": {
|
||||
"next": [
|
||||
|
||||
@@ -90,21 +90,12 @@
|
||||
"Sami@Roguelike@ChooseDifficulty": {
|
||||
"roi": [1064, 294, 216, 170]
|
||||
},
|
||||
"Sami@Roguelike@ChooseDifficulty_Easiest": {
|
||||
"Sami@Roguelike@ChooseDifficultyEnter": {
|
||||
"action": "ClickRect",
|
||||
"specificRect": [1119, 479, 80, 22],
|
||||
"postDelay": 800,
|
||||
"template": "Sami@Roguelike@StartExplore.png",
|
||||
"roi": [958, 530, 322, 189],
|
||||
"sub": ["SwipeToTheUp*2"]
|
||||
},
|
||||
"Sami@Roguelike@ChooseDifficulty_Hardest": {
|
||||
"action": "ClickRect",
|
||||
"specificRect": [1119, 479, 80, 22],
|
||||
"postDelay": 800,
|
||||
"template": "Sami@Roguelike@StartExplore.png",
|
||||
"roi": [958, 530, 322, 189],
|
||||
"sub": ["SwipeToTheDown*2"]
|
||||
"roi": [958, 530, 322, 189]
|
||||
},
|
||||
"Sami@Roguelike@ChooseOper": {
|
||||
"next": [
|
||||
|
||||
@@ -77,21 +77,12 @@
|
||||
"Sarkaz@Roguelike@ChooseDifficulty": {
|
||||
"roi": [1086, 309, 194, 140]
|
||||
},
|
||||
"Sarkaz@Roguelike@ChooseDifficulty_Easiest": {
|
||||
"Sarkaz@Roguelike@ChooseDifficultyEnter": {
|
||||
"action": "ClickRect",
|
||||
"specificRect": [1119, 479, 80, 22],
|
||||
"postDelay": 800,
|
||||
"template": "Sarkaz@Roguelike@StartExplore.png",
|
||||
"roi": [958, 530, 322, 189],
|
||||
"sub": ["SwipeToTheUp*2"]
|
||||
},
|
||||
"Sarkaz@Roguelike@ChooseDifficulty_Hardest": {
|
||||
"action": "ClickRect",
|
||||
"specificRect": [1119, 479, 80, 22],
|
||||
"postDelay": 800,
|
||||
"template": "Sarkaz@Roguelike@StartExplore.png",
|
||||
"roi": [958, 530, 322, 189],
|
||||
"sub": ["SwipeToTheDown*2"]
|
||||
"roi": [958, 530, 322, 189]
|
||||
},
|
||||
"Sarkaz@Roguelike@ChooseOper": {
|
||||
"next": [
|
||||
|
||||
@@ -62,44 +62,68 @@ bool asst::RoguelikeDifficultySelectionTaskPlugin::_run()
|
||||
return true;
|
||||
}
|
||||
|
||||
int asst::RoguelikeDifficultySelectionTaskPlugin::detect_current_difficulty() const
|
||||
{
|
||||
LogTraceFunction;
|
||||
|
||||
const cv::Mat image = ctrler()->get_image();
|
||||
OCRer analyzer(image);
|
||||
analyzer.set_task_info("Roguelike@ChooseDifficulty_AnalyzeCurrentDifficulty");
|
||||
if (analyzer.analyze()) {
|
||||
const std::string text = analyzer.get_result().front().text;
|
||||
Log.info("Detected difficulty text:", text);
|
||||
int difficulty;
|
||||
if (!utils::chars_to_number(text, difficulty)) {
|
||||
Log.error("Failed to convert difficulty text to number. Text =", text);
|
||||
return 0;
|
||||
}
|
||||
return difficulty;
|
||||
}
|
||||
else {
|
||||
Log.error("OCR failed. Cannot detect difficulty.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool asst::RoguelikeDifficultySelectionTaskPlugin::select_difficulty(const int difficulty)
|
||||
{
|
||||
LogTraceFunction;
|
||||
|
||||
if (difficulty == INT_MAX) {
|
||||
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficulty_Hardest" }).run();
|
||||
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficultyEnter" }).run();
|
||||
ProcessTask(*this, { "SwipeToTheDown" }).run();
|
||||
ProcessTask(*this, { "SwipeToTheDown" }).run();
|
||||
m_current_difficulty = detect_current_difficulty();
|
||||
}
|
||||
else if (difficulty == 0) {
|
||||
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficulty_Easiest" }).run();
|
||||
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficultyEnter" }).run();
|
||||
ProcessTask(*this, { "SwipeToTheUp" }).run();
|
||||
ProcessTask(*this, { "SwipeToTheUp" }).run();
|
||||
m_current_difficulty = detect_current_difficulty();
|
||||
}
|
||||
else {
|
||||
// 从最高难度依次点下来
|
||||
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficulty_Hardest" }).run();
|
||||
std::vector<std::string> difficulty_list;
|
||||
for (int i = 20; i >= difficulty; --i) { // 难度识别内容为 20 ~ difficulty
|
||||
difficulty_list.push_back(std::to_string(i));
|
||||
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficultyEnter" }).run();
|
||||
m_current_difficulty = detect_current_difficulty();
|
||||
Log.info("Target difficulty:", difficulty);
|
||||
Log.info("Current difficulty:", m_current_difficulty);
|
||||
if (m_current_difficulty != difficulty) {
|
||||
if (m_current_difficulty < difficulty) {
|
||||
ProcessTask(*this, { "SwipeToTheDown" }).run();
|
||||
ProcessTask(*this, { "SwipeToTheDown" }).run();
|
||||
}
|
||||
std::vector<std::string> difficulty_list;
|
||||
for (int i = 20; i >= difficulty; --i) { // 难度识别内容为 20 ~ difficulty
|
||||
difficulty_list.push_back(std::to_string(i));
|
||||
}
|
||||
Task.get<OcrTaskInfo>(m_config->get_theme() + "@Roguelike@ChooseDifficulty_Specified")->text =
|
||||
difficulty_list;
|
||||
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficulty_Specified", "Stop" }).run();
|
||||
m_current_difficulty = detect_current_difficulty();
|
||||
}
|
||||
Task.get<OcrTaskInfo>(m_config->get_theme() + "@Roguelike@ChooseDifficulty_Specified")->text = difficulty_list;
|
||||
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficulty_Specified", "Stop" }).run();
|
||||
}
|
||||
|
||||
// 识别当前难度
|
||||
const cv::Mat image = ctrler()->get_image();
|
||||
OCRer current_difficulty_analyzer(image);
|
||||
current_difficulty_analyzer.set_task_info("Roguelike@ChooseDifficulty_AnalyzeCurrentDifficulty");
|
||||
if (current_difficulty_analyzer.analyze()) {
|
||||
const std::string current_difficulty_text = current_difficulty_analyzer.get_result().front().text;
|
||||
Log.info(__FUNCTION__, "| Current difficulty text is", current_difficulty_text);
|
||||
if (!utils::chars_to_number(current_difficulty_text, m_current_difficulty)) {
|
||||
Log.error("Fail to convert current difficulty text to int, reset current difficulty to 0");
|
||||
m_current_difficulty = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Log.error(__FUNCTION__, "| Fail to detect current difficulty, reset current difficulty to 0");
|
||||
m_current_difficulty = 0;
|
||||
}
|
||||
Log.info(__FUNCTION__, "| Current difficulty is", m_current_difficulty);
|
||||
Log.info("Target difficulty:", difficulty);
|
||||
Log.info("Current difficulty:", m_current_difficulty);
|
||||
|
||||
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficultyConfirm" }).run();
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ protected:
|
||||
virtual bool _run() override;
|
||||
|
||||
private:
|
||||
int detect_current_difficulty() const;
|
||||
bool select_difficulty(const int difficulty = 0);
|
||||
|
||||
int m_current_difficulty = -1;
|
||||
|
||||
Reference in New Issue
Block a user