refactor: 补充相关机制

This commit is contained in:
Weiyou Wang
2024-10-25 22:26:50 +11:00
committed by status102
parent 1202210b16
commit c0382209bc
8 changed files with 104 additions and 48 deletions

View File

@@ -6288,18 +6288,27 @@
"roi": [1061, 373, 208, 71],
"next": ["Roguelike@StartExplore"]
},
"Roguelike@ChooseDifficulty_specified": {
"Doc": "base_task",
"Roguelike@ChooseDifficulty_Specified": {
"doc": "用于 RoguelikeDifficultySelectionTaskPlugin",
"baseTask": "NumberOcrReplace",
"algorithm": "OcrDetect",
"action": "ClickSelf",
"fullMatch": true,
"isAscii": true,
"roi": [400, 450, 225, 160],
"text": [],
"fullMatch": true,
"action": "ClickSelf",
"postDelay": 800,
"next": ["#self", "Stop"]
},
"Roguelike@ChooseDifficulty_CheckEasiest": {
"doc": "用于 RoguelikeDifficultySelectionTaskPlugin",
"algorithm": "OcrDetect",
"text": [],
"roi": [400, 450, 225, 160]
},
"Roguelike@ChooseDifficulty_AnalyzeCurrentDifficulty": {
"doc": "用于 RoguelikeDifficultySelectionTaskPlugin",
"baseTask": "NumberOcrReplace",
"roi": [400, 300, 225, 160],
"fullMatch": true
},
"Roguelike@ChooseDifficultyConfirm": {
"algorithm": "OcrDetect",
"action": "ClickSelf",
@@ -7656,9 +7665,6 @@
"roi": [1026, 470, 254, 248],
"sub": ["SwipeToTheDown*2"]
},
"Mizuki@Roguelike@ChooseDifficulty_specified": {
"baseTask": "Roguelike@ChooseDifficulty_specified"
},
"Mizuki@Roguelike@ChooseOper": {
"next": [
"Mizuki@Roguelike@CloseCollectionContinue",
@@ -8208,9 +8214,6 @@
"roi": [958, 530, 322, 189],
"sub": ["SwipeToTheDown*2"]
},
"Sami@Roguelike@ChooseDifficulty_specified": {
"baseTask": "Roguelike@ChooseDifficulty_specified"
},
"Sami@Roguelike@ChooseOper": {
"next": [
"Sami@Roguelike@CloseCollectionClose",
@@ -9436,9 +9439,6 @@
"roi": [958, 530, 322, 189],
"sub": ["SwipeToTheDown*2"]
},
"Sarkaz@Roguelike@ChooseDifficulty_specified": {
"baseTask": "Roguelike@ChooseDifficulty_specified"
},
"Sarkaz@Roguelike@ChooseOper": {
"next": [
"Sarkaz@Roguelike@CloseCollectionContinue",

View File

@@ -20,7 +20,9 @@ bool asst::RoguelikeConfig::verify_and_load_params(const json::value& params)
m_theme = theme;
m_mode = mode;
m_difficulty = 0;
m_difficulty = params.get("difficulty", 0);
m_next_difficulty = m_difficulty;
// 凹指定干员开局直升
m_start_with_elite_two = params.get("start_with_elite_two", false);

View File

@@ -70,6 +70,10 @@ public:
int get_difficulty() const { return m_difficulty; }
void set_next_difficulty(int next_difficulty) { m_next_difficulty = next_difficulty; }
int get_next_difficulty() const { return m_next_difficulty; }
void set_squad(std::string squad) { m_squad = std::move(squad); }
const std::string& get_squad() const { return m_squad; }
@@ -92,6 +96,7 @@ private:
std::string m_theme; // 主题
RoguelikeMode m_mode = RoguelikeMode::Exp; // 模式
int m_difficulty = 0; // 难度
int m_next_difficulty= 0; // 下次开局目标难度
std::string m_squad; // 分队
// ------------------ 开局 ------------------

View File

@@ -1,9 +1,23 @@
#include "RoguelikeDifficultySelectionTaskPlugin.h"
#include "Config/TaskData.h"
#include "Controller/Controller.h"
#include "Status.h"
#include "Task/ProcessTask.h"
#include "Utils/Logger.hpp"
#include "Vision/OCRer.h"
bool asst::RoguelikeDifficultySelectionTaskPlugin::load_params([[maybe_unused]] const json::value& params)
{
LogTraceFunction;
// 集成战略 <傀影与猩红孤钻> 的难度选项没有数字标注,暂不支持难度选择功能
if (m_config->get_theme() == RoguelikeTheme::Phantom) {
return false;
}
return true;
}
bool asst::RoguelikeDifficultySelectionTaskPlugin::verify(AsstMsg msg, const json::value& details) const
{
@@ -33,33 +47,64 @@ bool asst::RoguelikeDifficultySelectionTaskPlugin::_run()
{
LogTraceFunction;
auto mode = m_config->get_mode();
// todo:以后可以根据传入的难度值选择难度?
const int next_difficulty = m_config->get_next_difficulty();
Log.info(__FUNCTION__, "| current_difficulty:", m_current_difficulty, "next difficulty:", next_difficulty);
// 当前难度
int difficulty = 5;
// 是否不进行作战
bool no_battle = m_config->get_only_start_with_elite_two() || m_config->get_first_floor_foldartal();
if (m_config->get_theme() != RoguelikeTheme::Phantom && mode == RoguelikeMode::Collectible && !no_battle) {
if (difficulty == INT_MAX) {
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficulty_Hardest" }).run();
}
else if (difficulty == 0) {
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficulty_Easiest" }).run();
}
else {
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficulty_Hardest" }).run();
// 难度识别内容为 20 ~ difficulty
std::vector<std::string> difficulty_list;
for (int i = 20; i >= difficulty; --i) {
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" }).run();
}
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficultyConfirm" }).run();
// 仅在插件记录的当前难度与目标难度不一致时重新选择难度
if (m_current_difficulty != next_difficulty) {
select_difficulty(next_difficulty);
}
return true;
}
bool asst::RoguelikeDifficultySelectionTaskPlugin::select_difficulty(const int difficulty)
{
LogTraceFunction;
if (difficulty == INT_MAX) {
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficulty_Hardest" }).run();
}
else if (difficulty == 0) {
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficulty_Easiest" }).run();
}
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));
}
Task.get<OcrTaskInfo>(m_config->get_theme() + "@Roguelike@ChooseDifficulty_Specified")->text = difficulty_list;
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficulty_Specified" }).run();
}
// 识别当前难度
const cv::Mat image = ctrler()->get_image();
OCRer easiest_checker(image);
easiest_checker.set_task_info("Roguelike@ChooseDifficulty_CheckEasiest");
if (!easiest_checker.analyze()) {
m_current_difficulty = 0;
}
else {
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.debug(__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 -1");
m_current_difficulty = -1;
}
}
else {
Log.error(__FUNCTION__, "| Fail to detect current difficulty, reset current difficulty to -1");
m_current_difficulty = -1;
}
}
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficultyConfirm" }).run();
return true;
}

View File

@@ -8,11 +8,15 @@ class RoguelikeDifficultySelectionTaskPlugin : public AbstractRoguelikeTaskPlugi
public:
using AbstractRoguelikeTaskPlugin::AbstractRoguelikeTaskPlugin;
virtual ~RoguelikeDifficultySelectionTaskPlugin() override = default;
public:
virtual bool verify(AsstMsg msg, const json::value& details) const override;
virtual bool load_params(const json::value& params) override;
protected:
virtual bool _run() override;
private:
bool select_difficulty(const int difficulty = 0);
int m_current_difficulty = -1;
};
}

View File

@@ -60,7 +60,7 @@ bool asst::RoguelikeLastRewardTaskPlugin::_run()
bool start_with_elite_two = m_config->get_start_with_elite_two();
if (m_config->get_theme() != RoguelikeTheme::Phantom && mode == RoguelikeMode::Collectible) {
if (m_is_next_hardest) {
m_config->set_difficulty(INT_MAX);
m_config->set_next_difficulty(m_config->get_difficulty());
// 获得热水壶和演讲时停止肉鸽(凹直升则继续),获得其他奖励时重开
std::string last_reward_stop_or_continue =
start_with_elite_two ? "Roguelike@LastReward_default" : "Roguelike@LastReward_stop";
@@ -71,7 +71,7 @@ bool asst::RoguelikeLastRewardTaskPlugin::_run()
Task.set_task_base("Roguelike@LastRewardRand", "Roguelike@LastReward_restart");
}
else {
m_config->set_difficulty(0);
m_config->set_next_difficulty(0);
// 重置开局奖励 next获得任意奖励均继续
Task.set_task_base("Roguelike@LastReward", "Roguelike@LastReward_default");
Task.set_task_base("Roguelike@LastReward2", "Roguelike@LastReward_default");

View File

@@ -529,7 +529,7 @@ bool asst::RoguelikeRecruitTaskPlugin::recruit_appointed_char(const std::string&
else {
// 非只凹直升时重置难度并放弃
if (!only_start_with_elite_two) {
m_config->set_difficulty(0);
m_config->set_next_difficulty(0);
}
m_control_ptr->exit_then_stop();
}

View File

@@ -68,7 +68,7 @@ bool asst::RoguelikeFoldartalStartTaskPlugin::_run()
// 没有刷到需要的板子,退出重开
if (mode == RoguelikeMode::Collectible && !start_foldartal_checked) {
m_config->set_difficulty(0);
m_config->set_next_difficulty(0);
Task.set_task_base("Roguelike@LastReward", "Roguelike@LastReward_restart");
Task.set_task_base("Roguelike@LastReward4", "Roguelike@LastReward_restart");
}