refactor: 重构肉鸽每一层的预见密文板获取

This commit is contained in:
status102
2023-11-15 16:21:14 +08:00
parent 03b81a53d5
commit ff2a87d91e
5 changed files with 49 additions and 28 deletions

View File

@@ -14007,6 +14007,10 @@
[
"黜",
"黜人"
],
[
"\"",
""
]
]
},

View File

@@ -7,4 +7,5 @@ void asst::RoguelikeConfig::clear() {
m_trader_no_longer_buy = false;
m_core_char = std::string();
m_team_full_without_rookie = false;
m_foldartal_floor = std::nullopt;
}

View File

@@ -1,5 +1,8 @@
#pragma once
#include <string>
#include <vector>
#include <queue>
#include <optional>
namespace asst
{
@@ -64,6 +67,9 @@ namespace asst
void set_team_full_without_rookie(bool without_rookie) { m_team_full_without_rookie = without_rookie; }
bool get_team_full_without_rookie() { return m_team_full_without_rookie; }
void set_foldartal_floor(std::optional<std::string> floor) { m_foldartal_floor = std::move(floor); }
const std::optional<std::string>& get_foldartal_floor() { return m_foldartal_floor; }
protected:
// 肉鸽主题
std::string m_theme;
@@ -81,5 +87,9 @@ namespace asst
bool m_trader_no_longer_buy = false;
std::string m_core_char;
bool m_team_full_without_rookie = false;
/* 密文板 */
// 当前层的预见密文板,在下一层获得
std::optional<std::string> m_foldartal_floor;
};
} // namespace asst

View File

@@ -56,41 +56,44 @@ bool asst::RoguelikeFoldartalGainTaskPlugin::_run()
{
LogTraceFunction;
std::string theme = m_config->get_theme();
auto image = ctrler()->get_image();
OCRer analyzer(image);
std::string foldartal = "None";
if (m_ocr_next_level) {
analyzer.set_task_info(theme + "@Roguelike@FoldartalGainOcrNextLevel");
if (analyzer.analyze()) {
foldartal = analyzer.get_result().front().text;
}
store_to_status(foldartal, Status::RoguelikeFoldartalFloor);
json::array foldartal_floor_array = get_array(Status::RoguelikeFoldartalFloor);
// 到达第二层后,获得上一层预见的密文板
if (foldartal_floor_array.size() >= 2) {
std::string foldartal_last_floor = (foldartal_floor_array.end() - 2)->to_string();
if (foldartal_last_floor.size() >= 2 && foldartal_last_floor.front() == '"' &&
foldartal_last_floor.back() == '"') {
foldartal_last_floor = foldartal_last_floor.substr(1, foldartal_last_floor.size() - 2);
}
if (foldartal_last_floor != "None") {
store_to_status(foldartal_last_floor, Status::RoguelikeFoldartalOverview);
}
}
enter_next_floor();
return true;
};
}
else {
return after_combat();
}
}
std::string task_name =
m_ocr_after_combat ? theme + "@Roguelike@FoldartalGainOcrAfterCombat" : theme + "@Roguelike@FoldartalGainOcr";
analyzer.set_task_info(task_name);
void asst::RoguelikeFoldartalGainTaskPlugin::enter_next_floor()
{
auto foldartal_floor = m_config->get_foldartal_floor();
// 到达第二层后,获得上一层预见的密文板
if (foldartal_floor) {
store_to_status(*foldartal_floor, Status::RoguelikeFoldartalOverview);
}
foldartal_floor.reset();
OCRer analyzer(ctrler()->get_image());
analyzer.set_task_info(m_config->get_theme() + "@Roguelike@FoldartalGainOcrNextLevel");
if (analyzer.analyze()) {
foldartal_floor = analyzer.get_result().front().text;
}
m_config->set_foldartal_floor(std::move(foldartal_floor));
}
bool asst::RoguelikeFoldartalGainTaskPlugin::after_combat()
{
OCRer analyzer(ctrler()->get_image());
analyzer.set_task_info(m_config->get_theme() + (m_ocr_after_combat ? "@Roguelike@FoldartalGainOcrAfterCombat"
: "@Roguelike@FoldartalGainOcr"));
if (!analyzer.analyze()) {
return false;
}
foldartal = analyzer.get_result().front().text;
store_to_status(foldartal, Status::RoguelikeFoldartalOverview);
auto foldartal = analyzer.get_result().front().text;
store_to_status(std::move(foldartal), Status::RoguelikeFoldartalOverview);
if (m_ocr_after_combat) {
ctrler()->click(analyzer.get_result().front().rect);
}

View File

@@ -16,6 +16,9 @@ namespace asst
virtual bool _run() override;
private:
void enter_next_floor();
bool after_combat();
json::array get_array(auto& status_string);
bool store_to_status(std::string foldartal, auto& status_string);
// 战斗后识别密文板