feat: 支持肉鸽事件choice_require解析

This commit is contained in:
uye
2024-01-04 17:54:28 +08:00
parent b6110031db
commit 018a3cdf4a
5 changed files with 73 additions and 3 deletions

View File

@@ -12513,6 +12513,17 @@
"Roguelike@StageEncounterJudgeOption"
]
},
"Roguelike@SpecialValRecognition": {
"algorithm": "OcrDetect",
"action": "DoNothing",
"text": [],
"roi": [
615,
0,
80,
45
]
},
"Roguelike@StageEncounterJudgeOption": {
"algorithm": "JustReturn",
"action": "DoNothing",

View File

@@ -16,6 +16,15 @@ bool asst::RoguelikeStageEncounterConfig::parse(const json::value& json)
event.name = event_json.at("name").as_string();
event.option_num = event_json.get("option_num", 0);
event.default_choose = event_json.get("choose", 0);
if (event_json.contains("choice_require")) {
for (const auto& requirement_json : event_json.at("choice_require").as_array()) {
ChoiceRequire requirement;
requirement.name = requirement_json.at("name").as_string();
requirement.chaos_level.value = requirement_json.at("ChaosLevel").get("value", 0);
requirement.chaos_level.type = requirement_json.at("ChaosLevel").at("type").as_string();
event.choice_require.emplace_back(std::move(requirement));
}
}
m_events[theme].emplace_back(std::move(event));
}
return true;

View File

@@ -8,11 +8,22 @@
namespace asst
{
struct ChaosLevel
{
int value = 0;
std::string type; // '>' or '<'
};
struct ChoiceRequire
{
std::string name;
ChaosLevel chaos_level;
};
struct RoguelikeEvent
{
std::string name;
int option_num = 0;
int default_choose = 0;
std::vector<ChoiceRequire> choice_require;
};
class RoguelikeStageEncounterConfig final : public SingletonHolder<RoguelikeStageEncounterConfig>,

View File

@@ -73,14 +73,32 @@ bool asst::RoguelikeStageEncounterTaskPlugin::_run()
RoguelikeEvent event = event_map.at(text);
Log.info("Event:", event.name, "choose option", event.default_choose);
int special_val = 0;
// 水月的不好识别,先试试萨米能不能用
if (m_config->get_theme() == "Sami") {
OCRer analyzer(image);
analyzer.set_task_info(m_config->get_theme() + "Roguelike@SpecialValRecognition");
analyzer.set_replace(Task.get<OcrTaskInfo>("NumberOcrReplace")->replace_map);
analyzer.set_use_char_model(true);
if (!analyzer.analyze()) {
return false;
}
special_val = std::stoi(analyzer.get_result().front().text);
}
int choose_option = process_task(event, special_val);
Log.info("Event:", event.name, "special_val", special_val, "choose option", choose_option);
auto info = basic_info_with_what("RoguelikeEvent");
info["details"]["name"] = event.name;
info["details"]["default_choose"] = event.default_choose;
info["details"]["special_val"] = special_val;
info["details"]["choose"] = choose_option;
callback(AsstMsg::SubTaskExtraInfo, info);
for (int j = 0; j < 2; ++j) {
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@OptionChoose" + std::to_string(event.option_num) + "-" +
std::to_string(event.default_choose) })
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@OptionChoose" + std::to_string(event.option_num) +
"-" + std::to_string(choose_option) })
.run();
sleep(300);
}

View File

@@ -1,5 +1,6 @@
#pragma once
#include "AbstractRoguelikeTaskPlugin.h"
#include "Config/Roguelike/RoguelikeStageEncounterConfig.h"
namespace asst
{
@@ -14,5 +15,25 @@ namespace asst
protected:
virtual bool _run() override;
static bool satisfies_condition(const asst::ChoiceRequire& requirement, const int special_val)
{
if (requirement.chaos_level.type == ">") {
return special_val > requirement.chaos_level.value;
}
if (requirement.chaos_level.type == "<") {
return special_val < requirement.chaos_level.value;
}
return false;
}
static int process_task(const asst::RoguelikeEvent& event, const int special_val)
{
for (const auto& requirement : event.choice_require) {
if (satisfies_condition(requirement, special_val)) {
return requirement.chaos_level.value;
}
}
return event.default_choose;
}
};
}