refactor: 迁移肉鸽部分数据 (#7184)

This commit is contained in:
status102
2023-11-10 21:47:12 +08:00
committed by GitHub
14 changed files with 110 additions and 78 deletions

View File

@@ -41,20 +41,9 @@ namespace asst
static inline const std::string RoguelikeCharElitePrefix = "RoguelikeElite-";
static inline const std::string RoguelikeCharLevelPrefix = "RoguelikeLevel-";
static inline const std::string RoguelikeCharRarityPrefix = "RoguelikeRarity-";
static inline const std::string RoguelikeCharOverview = "RoguelikeOverview";
static inline const std::string RoguelikeCoreChar = "RoguelikeCoreChar";
static inline const std::string RoguelikeStartWithEliteTwo = "RoguelikeStartWithEliteTwo";
static inline const std::string RoguelikeUseSupport = "RoguelikeUseSupport";
static inline const std::string RoguelikeUseNonfriendSupport = "RoguelikeUseNonfriendSupport";
static inline const std::string RoguelikeTraderNoLongerBuy = "RoguelikeNoLongerBuy";
static inline const std::string RoguelikeTeamFullWithoutRookie = "RoguelikeTeamFullWithoutRookie";
static inline const std::string RoguelikeRecruitmentStartsComplete = "RoguelikeRecruitmentStartsComplete";
static inline const std::string RoguelikeRecruitmentTeamComplete = "RoguelikeRecruitmentTeamComplete";
static inline const std::string RoguelikeRecruitmentCount = "RoguelikeRecruitmentCount";
static inline const std::string RoguelikeMode = "RoguelikeMode";
static inline const std::string RoguelikeDifficulty = "RoguelikeDifficulty";
static inline const std::string RoguelikeFoldartalOverview = "RoguelikeFoldartalOverview";
static inline const std::string RoguelikeFoldartalFloor = "RoguelikeFoldartalFloor";

View File

@@ -92,35 +92,30 @@ bool asst::RoguelikeTask::set_params(const json::value& params)
m_roguelike_config_ptr->set_theme(theme);
m_roguelike_task_ptr->set_tasks({ theme + "@Roguelike@Begin" });
// 0 - 刷经验,尽可能稳定地打更多层数,不期而遇采用激进策略
// 1 - 刷源石锭,第一层投资完就退出,不期而遇采用保守策略
// 2 - 【已移除】两者兼顾,投资过后再退出,没有投资就继续往后打
// 3 - 尝试通关激进策略TODO
// 4 - 刷开局藏品,以获得热水壶或者演讲稿开局,不期而遇采用保守策略
int mode = params.get("mode", 0);
if (mode != 0 && mode != 1 && mode != 4) {
auto mode = static_cast<RoguelikeMode>(params.get("mode", 0));
m_roguelike_config_ptr->set_mode(mode);
if (mode != RoguelikeMode::Exp && mode != RoguelikeMode::Investment && mode != RoguelikeMode::Collectible) {
m_roguelike_task_ptr->set_tasks({ "Stop" });
Log.error(__FUNCTION__, "| Unknown mode", mode);
Log.error(__FUNCTION__, "| Unknown mode", static_cast<int>(mode));
return false;
}
m_debug_plugin_ptr->set_enable(mode != 1);
m_debug_plugin_ptr->set_enable(mode != RoguelikeMode::Investment);
// 是否凹指定干员开局直升
bool start_with_elite_two = params.get("start_with_elite_two", false);
status()->set_properties(Status::RoguelikeMode, std::to_string(mode));
status()->set_properties(Status::RoguelikeDifficulty, "0");
status()->set_properties(Status::RoguelikeStartWithEliteTwo, std::to_string(start_with_elite_two));
m_roguelike_config_ptr->set_difficulty(0);
m_roguelike_config_ptr->set_start_with_elite_two(start_with_elite_two);
// 设置层数选点策略,相关逻辑在 RoguelikeStrategyChangeTaskPlugin
{
Task.set_task_base(theme + "@Roguelike@Stages", theme + "@Roguelike@Stages_default");
std::string strategy_task = theme + "@Roguelike@StrategyChange";
std::string strategy_task_with_mode = strategy_task + "_mode" + std::to_string(mode);
std::string strategy_task_with_mode = strategy_task + "_mode" + std::to_string(static_cast<int>(mode));
if (Task.get(strategy_task_with_mode) == nullptr) {
strategy_task_with_mode = "#none"; // 没有对应的层数选点策略,使用默认策略(避战)
Log.warn(__FUNCTION__, "No strategy for mode", mode);
Log.warn(__FUNCTION__, "No strategy for mode", static_cast<int>(mode));
}
Task.set_task_base(strategy_task, strategy_task_with_mode);
}
@@ -132,7 +127,7 @@ bool asst::RoguelikeTask::set_params(const json::value& params)
Task.set_task_base("Roguelike@LastReward4", "Roguelike@LastReward_default");
Task.set_task_base("Roguelike@LastRewardRand", "Roguelike@LastReward_default");
if (mode == 1) {
if (mode == RoguelikeMode::Investment) {
// 战斗后奖励只拿钱
Task.set_task_base(theme + "@Roguelike@DropsFlag", theme + "@Roguelike@DropsFlag_mode1");
// 刷源石锭模式是否进入第二层

View File

@@ -1,3 +1,10 @@
#include "RoguelikeConfig.h"
void asst::RoguelikeConfig::clear() {}
void asst::RoguelikeConfig::clear() {
m_recruitment_count = 0;
m_recruitment_starts_complete = false;
m_recruitment_team_complete = false;
m_trader_no_longer_buy = false;
m_core_char = std::string();
m_team_full_without_rookie = false;
}

View File

@@ -3,17 +3,64 @@
namespace asst
{
enum class RoguelikeMode
{
// 0 - 刷经验,尽可能稳定地打更多层数,不期而遇采用激进策略
Exp = 0,
// 1 - 刷源石锭,第一层投资完就退出,不期而遇采用保守策略
Investment = 1,
// 2 - 【已移除】两者兼顾,投资过后再退出,没有投资就继续往后打
// 3 - 尝试通关激进策略TODO
// 4 - 刷开局藏品,以获得热水壶或者演讲稿开局,不期而遇采用保守策略
Collectible = 4,
};
class RoguelikeConfig
{
public:
// 清理缓存的肉鸽数据
void clear();
public:
void set_theme(std::string roguelike_theme) { m_theme = std::move(roguelike_theme); }
void set_theme(std::string theme) { m_theme = std::move(theme); }
std::string get_theme() { return m_theme; }
void set_mode(RoguelikeMode mode) { m_mode = mode; }
RoguelikeMode get_mode() { return m_mode; }
void set_difficulty(int difficulty) { m_difficulty = difficulty; }
int get_difficulty() { return m_difficulty; }
void set_start_with_elite_two(bool start_with_elite_two) { m_start_with_elite_two = start_with_elite_two; }
bool get_start_with_elite_two() { return m_start_with_elite_two; }
void set_recruitment_count(int count) { m_recruitment_count = count; }
int get_recruitment_count() { return m_recruitment_count; }
void set_recruitment_starts_complete(bool complete) { m_recruitment_starts_complete = complete; }
bool get_recruitment_starts_complete() { return m_recruitment_starts_complete; }
void set_recruitment_team_complete(bool complete) { m_recruitment_team_complete = complete; }
bool get_recruitment_team_complete() { return m_recruitment_team_complete; }
void set_trader_no_longer_buy(bool no_longer_buy) { m_trader_no_longer_buy = no_longer_buy; }
bool get_trader_no_longer_buy() { return m_trader_no_longer_buy; }
void set_core_char(std::string core_char) { m_core_char = std::move(core_char); }
std::string get_core_char() { return m_core_char; }
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; }
protected:
// 肉鸽主题
std::string m_theme;
RoguelikeMode m_mode = RoguelikeMode::Exp;
int m_difficulty = 0;
bool m_start_with_elite_two = false;
/* 每次重置 */
// 肉鸽招募次数
int m_recruitment_count = 0;
// 开局干员是否已经招募
bool m_recruitment_starts_complete = false;
// 阵容是否完备
bool m_recruitment_team_complete = false;
bool m_trader_no_longer_buy = false;
std::string m_core_char;
bool m_team_full_without_rookie = false;
};
}
} // namespace asst

View File

@@ -142,6 +142,6 @@ bool asst::RoguelikeCustomStartTaskPlugin::hijack_core_char()
status()->set_str(Status::RoguelikeUseSupport, m_customs[RoguelikeCustomType::UseSupport]);
status()->set_str(Status::RoguelikeUseNonfriendSupport, m_customs[RoguelikeCustomType::UseNonfriendSupport]);
status()->set_str(Status::RoguelikeCoreChar, char_name);
m_config->set_core_char(char_name);
return true;
}

View File

@@ -32,13 +32,13 @@ bool asst::RoguelikeDifficultySelectionTaskPlugin::_run()
{
LogTraceFunction;
std::string mode = status()->get_properties(Status::RoguelikeMode).value();
auto mode = m_config->get_mode();
// todo:以后可以根据传入的难度值选择难度?
// 当前难度
std::string difficulty = status()->get_properties(Status::RoguelikeDifficulty).value();
if (m_config->get_theme() != "Phantom" && mode == "4") {
if (difficulty == "max") {
int difficulty = m_config->get_difficulty();
if (m_config->get_theme() != "Phantom" && mode == RoguelikeMode::Collectible) {
if (difficulty == INT_MAX) {
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ChooseDifficulty_Hardest" }).run();
}
else {

View File

@@ -57,8 +57,6 @@ bool asst::RoguelikeFoldartalGainTaskPlugin::_run()
LogTraceFunction;
std::string theme = m_config->get_theme();
std::string mode = status()->get_properties(Status::RoguelikeMode).value();
auto image = ctrler()->get_image();
OCRer analyzer(image);

View File

@@ -21,7 +21,7 @@ bool asst::RoguelikeFoldartalUseTaskPlugin::verify(AsstMsg msg, const json::valu
if (m_config->get_theme() != "Sami") {
return false;
}
std::string mode = status()->get_properties(Status::RoguelikeMode).value();
auto mode = m_config->get_mode();
std::string task_name_pre = m_config->get_theme() + "@Roguelike@Stage";
const std::string& task = details.get("details", "task", "");
std::string_view task_view = task;
@@ -39,28 +39,28 @@ bool asst::RoguelikeFoldartalUseTaskPlugin::verify(AsstMsg msg, const json::valu
task_view.remove_suffix(task_name_suf.length());
}
if (task_view == "CombatDps" || task_view == "EmergencyDps" || task_view == "FerociousPresage") {
if (mode == "1" || mode == "4") {
if (mode == RoguelikeMode::Investment || mode == RoguelikeMode::Collectible) {
m_stage = "SkipBattle";
}
else if (mode == "0") {
else if (mode == RoguelikeMode::Exp) {
m_stage = "Battle";
}
return true;
}
if (task_view == "DreadfulFoe-5" && mode == "0") {
if (task_view == "DreadfulFoe-5" && mode == RoguelikeMode::Exp) {
m_stage = "Boss";
return true;
}
if (task_view == "Trader" && mode == "0") {
if (task_view == "Trader" && mode == RoguelikeMode::Exp) {
m_stage = "Trader";
return true;
}
if (task_view == "Encounter" && mode == "0") {
if (task_view == "Encounter" && mode == RoguelikeMode::Exp) {
m_stage = "Encounter";
return true;
}
if ((task_view == "Gambling" || task_view == "EmergencyTransportation" || task_view == "WindAndRain") &&
mode == "0") {
mode == RoguelikeMode::Exp) {
m_stage = "Gambling";
return true;
}

View File

@@ -44,7 +44,7 @@ bool asst::RoguelikeLastRewardTaskPlugin::_run()
{
LogTraceFunction;
std::string mode = status()->get_properties(Status::RoguelikeMode).value();
auto mode = m_config->get_mode();
std::string stages_task_name = m_config->get_theme() + "@Roguelike@Stages";
std::string strategy_task_name = stages_task_name + "_default";
@@ -57,11 +57,10 @@ bool asst::RoguelikeLastRewardTaskPlugin::_run()
}
// 需要开局凹直升
bool start_with_elite_two =
status()->get_properties(Status::RoguelikeStartWithEliteTwo).value() == std::to_string(true);
if (m_config->get_theme() != "Phantom" && mode == "4") {
bool start_with_elite_two = m_config->get_start_with_elite_two();
if (m_config->get_theme() != "Phantom" && mode == RoguelikeMode::Collectible) {
if (m_is_next_hardest) {
status()->set_properties(Status::RoguelikeDifficulty, "max");
m_config->set_difficulty(INT_MAX);
// 获得热水壶和演讲时停止肉鸽(凹直升则继续),获得其他奖励时重开
std::string last_reward_stop_or_continue =
start_with_elite_two ? "Roguelike@LastReward_default" : "Roguelike@LastReward_stop";
@@ -72,7 +71,7 @@ bool asst::RoguelikeLastRewardTaskPlugin::_run()
Task.set_task_base("Roguelike@LastRewardRand", "Roguelike@LastReward_restart");
}
else {
status()->set_properties(Status::RoguelikeDifficulty, "0");
m_config->set_difficulty(0);
// 重置开局奖励 next获得任意奖励均继续
Task.set_task_base("Roguelike@LastReward", "Roguelike@LastReward_default");
Task.set_task_base("Roguelike@LastReward2", "Roguelike@LastReward_default");

View File

@@ -57,13 +57,13 @@ bool asst::RoguelikeRecruitTaskPlugin::_run()
LogTraceFunction;
// 这是第几次招募
size_t recruit_count = status()->get_number(Status::RoguelikeRecruitmentCount).value_or(0) + 1;
status()->set_number(Status::RoguelikeRecruitmentCount, recruit_count);
int recruit_count = m_config->get_recruitment_count() + 1;
m_config->set_recruitment_count(recruit_count);
// 是否有开局干员阵容中必须有开局干员没有前仅招募start干员或预备干员
bool start_complete = status()->get_number(Status::RoguelikeRecruitmentStartsComplete).value_or(0);
bool start_complete = m_config->get_recruitment_starts_complete();
// 是否阵容完备阵容完备前仅招募key干员或预备干员
bool team_complete = status()->get_number(Status::RoguelikeRecruitmentTeamComplete).value_or(0);
bool team_complete = m_config->get_recruitment_team_complete();
// 是否使用助战干员开局
bool use_support = get_status_bool(Status::RoguelikeUseSupport);
@@ -80,7 +80,7 @@ bool asst::RoguelikeRecruitTaskPlugin::_run()
}
}
bool team_full_without_rookie = status()->get_number(Status::RoguelikeTeamFullWithoutRookie).value_or(0);
bool team_full_without_rookie = m_config->get_team_full_without_rookie();
// Log.info("team_full_without_rookie", team_full_without_rookie);
// 编队信息 (已有角色)
@@ -144,10 +144,8 @@ bool asst::RoguelikeRecruitTaskPlugin::_run()
team_complete = true;
}
status()->set_number(Status::RoguelikeRecruitmentStartsComplete,
start_complete); // 阵容中必须有开局干员没有前仅招募start干员或预备干员
status()->set_number(Status::RoguelikeRecruitmentTeamComplete,
team_complete); // 阵容完备前仅招募key干员或预备干员
m_config->set_recruitment_starts_complete(start_complete); // 阵容中必须有开局干员没有前仅招募start干员或预备干员
m_config->set_recruitment_team_complete(team_complete); // 阵容完备前仅招募key干员或预备干员
// 候选干员
std::vector<RoguelikeRecruitInfo> recruit_list;
@@ -435,9 +433,9 @@ bool asst::RoguelikeRecruitTaskPlugin::recruit_appointed_char(const std::string&
bool has_been_same = false;
int i = 0;
// 是否凹直升
std::string start_with_elite_two = status()->get_properties(Status::RoguelikeStartWithEliteTwo).value();
bool start_with_elite_two = m_config->get_start_with_elite_two();
// 当前肉鸽难度
std::string difficulty = status()->get_properties(Status::RoguelikeDifficulty).value();
int difficulty = m_config->get_difficulty();
for (; i != SwipeTimes; ++i) {
if (need_exit()) {
@@ -461,13 +459,13 @@ bool asst::RoguelikeRecruitTaskPlugin::recruit_appointed_char(const std::string&
if (it != chars.cend()) {
// 需要凹直升且当前为max难度时
if (start_with_elite_two == "1" && difficulty == "max") {
if (start_with_elite_two && difficulty == INT_MAX) {
if (it->elite == 2) {
m_task_ptr->set_enable(false);
}
else {
// 重置难度并放弃
status()->set_properties(Status::RoguelikeDifficulty, "0");
m_config->set_difficulty(0);
ProcessTask(*this, { m_config->get_theme() + "@Roguelike@ExitThenAbandon" })
.set_times_limit("Roguelike@Abandon", 0)
.run();
@@ -512,10 +510,10 @@ bool asst::RoguelikeRecruitTaskPlugin::recruit_support_char()
LogTraceFunction;
const int MaxRefreshTimes = Task.get("RoguelikeRefreshSupportBtnOcr")->special_params.front();
auto core_opt = status()->get_str(Status::RoguelikeCoreChar);
status()->set_str(Status::RoguelikeCoreChar, "");
if (core_opt && !core_opt->empty()) {
if (recruit_support_char(core_opt.value(), MaxRefreshTimes)) return true;
auto core_opt = m_config->get_core_char();
m_config->set_core_char("");
if (!core_opt.empty()) {
if (recruit_support_char(core_opt, MaxRefreshTimes)) return true;
}
return false;
}
@@ -597,12 +595,12 @@ bool asst::RoguelikeRecruitTaskPlugin::recruit_own_char()
{
LogTraceFunction;
auto core_opt = status()->get_str(Status::RoguelikeCoreChar);
if (!core_opt || core_opt->empty()) {
auto core_opt = m_config->get_core_char();
if (core_opt.empty()) {
return false;
}
status()->set_str(Status::RoguelikeCoreChar, "");
return recruit_appointed_char(core_opt.value());
m_config->set_core_char("");
return recruit_appointed_char(core_opt);
}
void asst::RoguelikeRecruitTaskPlugin::select_oper(const battle::roguelike::Recruitment& oper)

View File

@@ -46,7 +46,7 @@ bool asst::RoguelikeShoppingTaskPlugin::_run()
return false;
}
bool no_longer_buy = status()->get_number(Status::RoguelikeTraderNoLongerBuy).value_or(0) ? true : false;
bool no_longer_buy = m_config->get_trader_no_longer_buy();
std::string str_chars_info = status()->get_str(Status::RoguelikeCharOverview).value_or(json::value().to_string());
json::value json_chars_info = json::parse(str_chars_info).value_or(json::value());
@@ -184,7 +184,7 @@ bool asst::RoguelikeShoppingTaskPlugin::_run()
}
}
if (goods.no_longer_buy) {
status()->set_number(Status::RoguelikeTraderNoLongerBuy, 1);
m_config->set_trader_no_longer_buy(true);
}
break;
}

View File

@@ -80,11 +80,11 @@ bool asst::RoguelikeSkillSelectionTaskPlugin::_run()
if (analyzer.get_team_full() && !has_rookie) {
Log.info("Team full and no rookie");
status()->set_number(Status::RoguelikeTeamFullWithoutRookie, 1);
m_config->set_team_full_without_rookie(true);
}
else {
Log.info("Team not full or has rookie");
status()->set_number(Status::RoguelikeTeamFullWithoutRookie, 0);
m_config->set_team_full_without_rookie(false);
}
return true;
}

View File

@@ -38,10 +38,10 @@ bool asst::RoguelikeStageEncounterTaskPlugin::_run()
{
LogTraceFunction;
std::string rogue_mode = status()->get_properties(Status::RoguelikeMode).value();
auto mode = m_config->get_mode();
std::vector<RoguelikeEvent> events = RoguelikeStageEncounter.get_events(m_config->get_theme());
// 刷源石锭模式和烧水模式
if (rogue_mode == "1" || rogue_mode == "4") {
if (mode == RoguelikeMode::Investment || mode == RoguelikeMode::Collectible) {
events = RoguelikeStageEncounter.get_events(m_config->get_theme() + "_deposit");
}
std::vector<std::string> event_names;

View File

@@ -36,7 +36,6 @@ bool asst::RoguelikeStrategyChangeTaskPlugin::_run()
LogTraceFunction;
std::string theme = m_config->get_theme();
std::string mode = status()->get_properties(Status::RoguelikeMode).value();
// TODO: 这段识别有点冗余,要是 plugin 能获取识别结果就好了
std::string task_name = theme + "@Roguelike@StrategyChange";