diff --git a/blcrack/cracker/cracker.cpp b/blcrack/cracker/cracker.cpp index e514dfead..f443c8b15 100644 --- a/blcrack/cracker/cracker.cpp +++ b/blcrack/cracker/cracker.cpp @@ -361,6 +361,10 @@ void Cracker::disable_skip_enter_battle() { restore_combat_delay_active(); } +void Cracker::set_white_flagship_keep_count(int ships) { + m_keep_white_flagship_number.store(ships); +} + void Cracker::enable_auto_retire() { ENABLE(AUTO_RETIRE); } @@ -1750,6 +1754,13 @@ Lua::Table Cracker::filter_ship(sol::this_state& l, Lua::VariadicArgs& args) { } }); + int white_flagship_to_keep = 0; + int keep_white_flagship_number = m_keep_white_flagship_number.load(); + + auto is_white_flagship = [](int configId) { + return configId == 107041 || configId == 106021 || configId == 107011 || configId == 206011; + }; + auto filter = [&](sol::this_state, Lua::Object value) { Lua::Table ship = value; @@ -1787,6 +1798,19 @@ Lua::Table Cracker::filter_ship(sol::this_state& l, Lua::VariadicArgs& args) { return false; } } + + if (keep_white_flagship_number != 0) { + if (is_white_flagship(configId)) { + int level = ship["level"]; + if (level == 1) { + if (white_flagship_to_keep < keep_white_flagship_number) { + white_flagship_to_keep++; + return false; + } + } + } + } + return true; }; @@ -1938,6 +1962,7 @@ Cracker::Config Cracker::get_config() { .exercise_more_power_rate = static_cast(m_exercise_more_power_rate.load() * 100), .better_global_speedup_rate = static_cast(m_better_global_speedup_rate.load()), .chapter_auto_clear_step_interval = m_mover.interval.load(), + .white_flagship_keep_count = m_keep_white_flagship_number.load(), }; return config; } @@ -1964,6 +1989,7 @@ void Cracker::apply_config(Config& config) { } if(IS_CONFIG_ENABLED(AUTO_RETIRE)) { + set_white_flagship_keep_count(config.white_flagship_keep_count); enable_auto_retire(); } else { disable_auto_retire(); diff --git a/blcrack/cracker/cracker.hpp b/blcrack/cracker/cracker.hpp index d251a561f..fcd09b7d2 100644 --- a/blcrack/cracker/cracker.hpp +++ b/blcrack/cracker/cracker.hpp @@ -130,6 +130,7 @@ public: int exercise_more_power_rate = 1; int better_global_speedup_rate = 1; double chapter_auto_clear_step_interval = 0.5; + int white_flagship_keep_count = 0; }; public: @@ -169,6 +170,7 @@ public: void enable_skip_enter_battle(); void disable_skip_enter_battle(); + void set_white_flagship_keep_count(int ships); void enable_auto_retire(); void disable_auto_retire(); @@ -533,6 +535,7 @@ private: std::atomic m_fast_stage_move_need_pause = false; std::atomic m_no_emotion_warning_need_pause = false; std::atomic m_skip_enter_battle_need_pause = false; + std::atomic m_keep_white_flagship_number = 0; static std::vector s_shipStatus; static std::vector s_excludedShips; diff --git a/blcrack/cracker/server.cpp b/blcrack/cracker/server.cpp index 6796c272b..37445a285 100644 --- a/blcrack/cracker/server.cpp +++ b/blcrack/cracker/server.cpp @@ -1382,6 +1382,20 @@ CrackerServer::CrackerServer() { CRACK_OK(); }); + Post("/set_white_flagship_keep_count", [](const httplib::Request& req, httplib::Response& res) { + try { + Json::Reader reader; + Json::Value j; + reader.parse(req.body, j); + Cracker::Instance().set_white_flagship_keep_count(j["count"].asInt()); + } catch (std::exception& e) { + SPDLOG_ERROR("Set white flagship keep count failed: {}", e.what()); + res.status = 500; + return; + } + CRACK_OK(); + }); + Post("/enable_auto_retire", [](const httplib::Request& req, httplib::Response& res) { try { Cracker::Instance().enable_auto_retire(); diff --git a/blcrack/cracker/ui/ui.cpp b/blcrack/cracker/ui/ui.cpp index 4c1b4b8a5..f29140a3f 100644 --- a/blcrack/cracker/ui/ui.cpp +++ b/blcrack/cracker/ui/ui.cpp @@ -173,6 +173,7 @@ void CrackerUI::draw_menu() { ImGui::Checkbox("自动再次前往", &CONFIG_FLAG(AUTO_ONCE_AGAIN)); ImGui::Checkbox("自动退役", &CONFIG_FLAG(AUTO_RETIRE)); ImGui::Checkbox("跳过战斗进场", &CONFIG_FLAG(SKIP_ENTER_BATTLE)); + ImGui::InputInt("自动退役保留白皮航母数量", &m_cracker_config.white_flagship_keep_count); ImGui::EndTable(); } diff --git a/config/template.json b/config/template.json index c3d859d2f..2687a4ca5 100644 --- a/config/template.json +++ b/config/template.json @@ -235,6 +235,7 @@ "SkipAirStrikeAnimation": false, "AutoOnceAgain": false, "AutoRetire": false, + "AutoRetireKeepWhiteFlagshipCount": 0, "SkipEnemyScan": false, "SkipBattleResult": false, "SkipEnterBattle": false diff --git a/module/config/argument/args.json b/module/config/argument/args.json index 494841fc3..c6861c289 100644 --- a/module/config/argument/args.json +++ b/module/config/argument/args.json @@ -934,6 +934,10 @@ "type": "checkbox", "value": false }, + "AutoRetireKeepWhiteFlagshipCount": { + "type": "input", + "value": 0 + }, "SkipEnemyScan": { "type": "checkbox", "value": false diff --git a/module/config/argument/argument.yaml b/module/config/argument/argument.yaml index 99ef536af..00a895a72 100644 --- a/module/config/argument/argument.yaml +++ b/module/config/argument/argument.yaml @@ -900,6 +900,7 @@ Misc: SkipAirStrikeAnimation: false AutoOnceAgain: false AutoRetire: false + AutoRetireKeepWhiteFlagshipCount: 0 SkipEnemyScan: false SkipBattleResult: false SkipEnterBattle: false diff --git a/module/config/config_generated.py b/module/config/config_generated.py index b42d1242a..fe4db486a 100644 --- a/module/config/config_generated.py +++ b/module/config/config_generated.py @@ -555,6 +555,7 @@ class GeneratedConfig: Misc_SkipAirStrikeAnimation = False Misc_AutoOnceAgain = False Misc_AutoRetire = False + Misc_AutoRetireKeepWhiteFlagshipCount = 0 Misc_SkipEnemyScan = False Misc_SkipBattleResult = False Misc_SkipEnterBattle = False diff --git a/module/config/full_config_generated.py b/module/config/full_config_generated.py index 3cd3745aa..bafbabccf 100644 --- a/module/config/full_config_generated.py +++ b/module/config/full_config_generated.py @@ -168,6 +168,7 @@ class FullGeneratedConfig: Hook_Misc_SkipAirStrikeAnimation = None Hook_Misc_AutoOnceAgain = None Hook_Misc_AutoRetire = None + Hook_Misc_AutoRetireKeepWhiteFlagshipCount = None Hook_Misc_SkipEnemyScan = None Hook_Misc_SkipBattleResult = None Hook_Misc_SkipEnterBattle = None diff --git a/module/config/i18n/en-US.json b/module/config/i18n/en-US.json index e3d068910..af7f2b263 100644 --- a/module/config/i18n/en-US.json +++ b/module/config/i18n/en-US.json @@ -3195,6 +3195,10 @@ "name": "Misc.AutoRetire.name", "help": "Misc.AutoRetire.help" }, + "AutoRetireKeepWhiteFlagshipCount": { + "name": "Misc.AutoRetireKeepWhiteFlagshipCount.name", + "help": "Misc.AutoRetireKeepWhiteFlagshipCount.help" + }, "SkipEnemyScan": { "name": "Misc.SkipEnemyScan.name", "help": "Misc.SkipEnemyScan.help" diff --git a/module/config/i18n/ja-JP.json b/module/config/i18n/ja-JP.json index 654b5c3be..3afe99249 100644 --- a/module/config/i18n/ja-JP.json +++ b/module/config/i18n/ja-JP.json @@ -3195,6 +3195,10 @@ "name": "Misc.AutoRetire.name", "help": "Misc.AutoRetire.help" }, + "AutoRetireKeepWhiteFlagshipCount": { + "name": "Misc.AutoRetireKeepWhiteFlagshipCount.name", + "help": "Misc.AutoRetireKeepWhiteFlagshipCount.help" + }, "SkipEnemyScan": { "name": "Misc.SkipEnemyScan.name", "help": "Misc.SkipEnemyScan.help" diff --git a/module/config/i18n/zh-CN.json b/module/config/i18n/zh-CN.json index 442be71e0..de8faddbf 100644 --- a/module/config/i18n/zh-CN.json +++ b/module/config/i18n/zh-CN.json @@ -3195,6 +3195,10 @@ "name": "自动退役", "help": "注意:该功能存在风险,开启前请确保船是锁上的!!!" }, + "AutoRetireKeepWhiteFlagshipCount": { + "name": "自动退役时保留 X 个一级白皮航母", + "help": "设置为 0 时全部退役,推荐设置为 5" + }, "SkipEnemyScan": { "name": "章节图跳过索敌", "help": "" diff --git a/module/config/i18n/zh-TW.json b/module/config/i18n/zh-TW.json index 4e1a7a79d..9af129f7b 100644 --- a/module/config/i18n/zh-TW.json +++ b/module/config/i18n/zh-TW.json @@ -3195,6 +3195,10 @@ "name": "Misc.AutoRetire.name", "help": "Misc.AutoRetire.help" }, + "AutoRetireKeepWhiteFlagshipCount": { + "name": "Misc.AutoRetireKeepWhiteFlagshipCount.name", + "help": "Misc.AutoRetireKeepWhiteFlagshipCount.help" + }, "SkipEnemyScan": { "name": "Misc.SkipEnemyScan.name", "help": "Misc.SkipEnemyScan.help" diff --git a/module/luahook/api.py b/module/luahook/api.py index e9423849a..bef03c121 100644 --- a/module/luahook/api.py +++ b/module/luahook/api.py @@ -57,6 +57,9 @@ class CrackApi: class ChapterAutoClearStepInterval(BaseModel): interval: float + class AutoRetireKeepWhiteFlagshipCount(BaseModel): + count: int + def __init__(self, base_url, timeout=10): self.api_url = base_url self.timeout = timeout @@ -422,6 +425,9 @@ class CrackApi: def disable_auto_once_again(self): self.post("disable_auto_once_again") + def set_white_flagship_keep_count(self, param: AutoRetireKeepWhiteFlagshipCount): + self.post("set_white_flagship_keep_count", data=param.json()) + def enable_auto_retire(self): self.post("enable_auto_retire") diff --git a/module/luahook/op.py b/module/luahook/op.py index 576ab17bf..4f047c709 100644 --- a/module/luahook/op.py +++ b/module/luahook/op.py @@ -393,6 +393,9 @@ class CrackOp: class EnableAutoRetire(Op): def execute_with_pause(self): if self.full_config.Hook_Misc_AutoRetire: + white_flagship_keep_count = self.full_config.Hook_Misc_AutoRetireKeepWhiteFlagshipCount + if white_flagship_keep_count != 0: + self.api.set_white_flagship_keep_count(CrackApi.AutoRetireKeepWhiteFlagshipCount(count=white_flagship_keep_count)) self.api.enable_auto_retire() class DisableAutoRetire(Op):