diff --git a/src/MaaCore/Task/BattleHelper.cpp b/src/MaaCore/Task/BattleHelper.cpp index 96d0d179db..b120a4c78e 100644 --- a/src/MaaCore/Task/BattleHelper.cpp +++ b/src/MaaCore/Task/BattleHelper.cpp @@ -98,7 +98,14 @@ bool asst::BattleHelper::update_deployment(bool init, const cv::Mat& reusable) } BattlefieldMatcher oper_analyzer(image); - oper_analyzer.set_object_of_interest({ .deployment = true }); + + // 保全要识别开局费用,先用init判断了,之后别的地方要用的话再做cache + if (init) { + oper_analyzer.set_object_of_interest({ .deployment = true, .oper_cost = true }); + } + else { + oper_analyzer.set_object_of_interest({ .deployment = true }); + } auto oper_result_opt = oper_analyzer.analyze(); if (!oper_result_opt) { check_in_battle(image); diff --git a/src/MaaCore/Task/SSS/SSSBattleProcessTask.cpp b/src/MaaCore/Task/SSS/SSSBattleProcessTask.cpp index e4727e8ea8..3bb2f9dda9 100644 --- a/src/MaaCore/Task/SSS/SSSBattleProcessTask.cpp +++ b/src/MaaCore/Task/SSS/SSSBattleProcessTask.cpp @@ -37,6 +37,43 @@ bool asst::SSSBattleProcessTask::set_stage_name(const std::string& stage_name) return true; } +bool asst::SSSBattleProcessTask::update_deployment_with_skip(const cv::Mat& reusable) +{ + const auto now = std::chrono::steady_clock::now(); + const std::vector old_deployment_opers = m_cur_deployment_opers; + static auto last_same_time = now; + static auto last_skip_time = now; + static auto interval_time = 0; + + if (std::chrono::duration_cast(now - last_skip_time).count() < interval_time) { + Log.trace("Passed without update deployment"); + sleep(interval_time); + return true; + } + last_skip_time = now; + + if (!update_deployment(false, reusable)) { + return false; + } + + if (ranges::equal( + m_cur_deployment_opers, old_deployment_opers, + [](const DeploymentOper& oper1, const DeploymentOper& oper2) { return oper1.name == oper2.name; })) { + if (std::chrono::duration_cast(now - last_same_time).count() > 30000) { + // 30s 能回 60 费,基本上已经到了挂机的时候,放缓检查的速度 + Log.trace("30s is unchanged and the waiting time is extended to 5s"); + interval_time = 5000; + } + } + else { + last_same_time = now; + Log.trace("Changed, the waiting time is reset to 0s"); + interval_time = 0; + } + + return true; +} + bool asst::SSSBattleProcessTask::do_derived_action(const battle::copilot::Action& action, size_t index) { LogTraceFunction; @@ -45,7 +82,7 @@ bool asst::SSSBattleProcessTask::do_derived_action(const battle::copilot::Action switch (action.type) { case battle::copilot::ActionType::DrawCard: - return draw_card(); + return draw_card() && update_deployment(); case battle::copilot::ActionType::CheckIfStartOver: return check_if_start_over(action); default: @@ -63,10 +100,6 @@ bool asst::SSSBattleProcessTask::do_strategic_action(const cv::Mat& reusable) return true; } - if (m_sss_combat_data.draw_as_possible && draw_card(false, image)) { - image = ctrler()->get_image(); - } - if (check_and_do_strategy(image)) { image = ctrler()->get_image(); } @@ -75,6 +108,10 @@ bool asst::SSSBattleProcessTask::do_strategic_action(const cv::Mat& reusable) // image = ctrler()->get_image(); } + if (m_sss_combat_data.draw_as_possible && draw_card(false, image)) { + // image = ctrler()->get_image(); + } + return true; } @@ -129,7 +166,7 @@ bool asst::SSSBattleProcessTask::check_and_do_strategy(const cv::Mat& reusable) } cv::Mat image = reusable.empty() ? ctrler()->get_image() : reusable; - if (!update_deployment(false, image)) { + if (!update_deployment_with_skip(image)) { return false; } @@ -157,7 +194,7 @@ bool asst::SSSBattleProcessTask::check_and_do_strategy(const cv::Mat& reusable) } m_all_cores.erase(strategy.core); // 部署完,画面会发生变化,所以直接返回,后续逻辑交给下次循环处理 - return deploy_oper(strategy.core, strategy.location, strategy.direction); + return deploy_oper(strategy.core, strategy.location, strategy.direction) && update_deployment(); } bool skip = false; @@ -174,7 +211,7 @@ bool asst::SSSBattleProcessTask::check_and_do_strategy(const cv::Mat& reusable) if (available_iter != tool_men.cend()) { --quantity; // 部署完,画面会发生变化,所以直接返回,后续逻辑交给下次循环处理 - return deploy_oper(available_iter->name, strategy.location, strategy.direction); + return deploy_oper(available_iter->name, strategy.location, strategy.direction) && update_deployment(); } auto not_available_iter = diff --git a/src/MaaCore/Task/SSS/SSSBattleProcessTask.h b/src/MaaCore/Task/SSS/SSSBattleProcessTask.h index e48eb5a2f7..44ee685cf8 100644 --- a/src/MaaCore/Task/SSS/SSSBattleProcessTask.h +++ b/src/MaaCore/Task/SSS/SSSBattleProcessTask.h @@ -19,6 +19,7 @@ namespace asst virtual bool need_to_wait_until_end() const noexcept override { return true; } virtual bool wait_until_start(bool weak = true) override; + bool update_deployment_with_skip(const cv::Mat& reusable = cv::Mat()); bool check_and_do_strategy(const cv::Mat& reusable = cv::Mat()); bool check_if_start_over(const battle::copilot::Action& action); bool draw_card(bool with_retry = true, const cv::Mat& reusable = cv::Mat()); diff --git a/src/MaaCore/Vision/Battle/BattlefieldMatcher.cpp b/src/MaaCore/Vision/Battle/BattlefieldMatcher.cpp index 80ad86911c..036b8c2a95 100644 --- a/src/MaaCore/Vision/Battle/BattlefieldMatcher.cpp +++ b/src/MaaCore/Vision/Battle/BattlefieldMatcher.cpp @@ -129,8 +129,10 @@ std::vector BattlefieldMatcher::deployment_analyze() con Log.error("oper is available, but with cooling"); } - Rect cost_rect = correct_rect(flag_res.rect.move(cost_move), m_image); - oper.cost = oper_cost_analyze(cost_rect); + if (m_object_of_interest.oper_cost) { + Rect cost_rect = correct_rect(flag_res.rect.move(cost_move), m_image); + oper.cost = oper_cost_analyze(cost_rect); + } oper.index = index++; diff --git a/src/MaaCore/Vision/Battle/BattlefieldMatcher.h b/src/MaaCore/Vision/Battle/BattlefieldMatcher.h index 3f1cfc453d..26fff20329 100644 --- a/src/MaaCore/Vision/Battle/BattlefieldMatcher.h +++ b/src/MaaCore/Vision/Battle/BattlefieldMatcher.h @@ -16,6 +16,7 @@ namespace asst bool costs = false; // bool in_detail = false; bool speed_button = false; + bool oper_cost = false; }; struct Result