From 1ad7b3a6a022630077e9a90cfddf29a4234cc4c8 Mon Sep 17 00:00:00 2001 From: Status102 <102887808+status102@users.noreply.github.com> Date: Sun, 23 Nov 2025 15:55:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(MaaCore):=20Copilot=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E6=8A=80=E8=83=BD=E7=94=A8=E6=B3=95=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E5=9D=90=E6=A0=87=20(#14818)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 支持切换技能用法使用坐标 * chore: Auto update by pre-commit hooks [skip changelog] * fix: usage * fix: const ref * perf: capture * fix: case define --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- src/MaaCore/Task/BattleHelper.cpp | 17 +++++---- src/MaaCore/Task/BattleHelper.h | 2 ++ .../Task/Miscellaneous/BattleProcessTask.cpp | 35 +++++++++++++++---- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/MaaCore/Task/BattleHelper.cpp b/src/MaaCore/Task/BattleHelper.cpp index 4fdd65be3c..4672129623 100644 --- a/src/MaaCore/Task/BattleHelper.cpp +++ b/src/MaaCore/Task/BattleHelper.cpp @@ -492,9 +492,7 @@ bool asst::BattleHelper::deploy_oper(const std::string& name, const Point& loc, // m_used_tiles.erase(pre_loc); } - m_used_tiles.emplace(loc, name); - m_battlefield_opers.emplace(name, loc); - m_last_use_skill_time.emplace(loc, std::chrono::steady_clock::time_point()); + register_deployed_oper(name, loc); m_inst_helper.sleep(200); // 部署完会有 166 ms 的动画 return true; @@ -692,10 +690,8 @@ bool asst::BattleHelper::use_all_ready_skill(const cv::Mat& reusable) Log.info("Skill", name, "is ready"); if (auto interval = now - last_use_time; min_frame_interval > interval) { - Log.info( - name, - "use skill too fast, interval time:", - std::to_string(std::chrono::duration_cast(interval).count()) + " ms"); + LogInfo << name << "use skill too fast, interval time:" + << std::chrono::duration_cast(interval).count() << " ms"; continue; } @@ -1047,6 +1043,13 @@ int asst::BattleHelper::elapsed_time() return static_cast(elapsed_ms); } +void asst::BattleHelper::register_deployed_oper(const std::string& name, const Point& loc) +{ + m_used_tiles.emplace(loc, name); + m_battlefield_opers.emplace(name, loc); + m_last_use_skill_time.emplace(loc, std::chrono::steady_clock::time_point()); +} + void asst::BattleHelper::remove_cooling_from_battlefield(const battle::DeploymentOper& oper) { if (!oper.cooling) { diff --git a/src/MaaCore/Task/BattleHelper.h b/src/MaaCore/Task/BattleHelper.h index 8883a2247b..ee84e3d0dd 100644 --- a/src/MaaCore/Task/BattleHelper.h +++ b/src/MaaCore/Task/BattleHelper.h @@ -98,6 +98,8 @@ protected: int elapsed_time(); + // 注册已部署干员及位置 + void register_deployed_oper(const std::string& name, const Point& loc); // 从场上干员和已占用格子中移除冷却中的干员 void remove_cooling_from_battlefield(const battle::DeploymentOper& oper); diff --git a/src/MaaCore/Task/Miscellaneous/BattleProcessTask.cpp b/src/MaaCore/Task/Miscellaneous/BattleProcessTask.cpp index 00a0748898..93b8b704de 100644 --- a/src/MaaCore/Task/Miscellaneous/BattleProcessTask.cpp +++ b/src/MaaCore/Task/Miscellaneous/BattleProcessTask.cpp @@ -247,13 +247,36 @@ bool asst::BattleProcessTask::do_action(const battle::copilot::Action& action, s } break; - case ActionType::SkillUsage: - m_skill_usage[name] = action.modify_usage; - if (action.modify_usage == SkillUsage::Times) { - m_skill_times[name] = action.modify_times; + { + case ActionType::SkillUsage: + const auto set_usage = [this](const std::string& name, SkillUsage usage, int times) { + m_skill_usage[name] = usage; + if (usage == SkillUsage::Times) { + m_skill_times[name] = times; + } + }; + if (!location.empty()) { + std::string drone_name; + if (!name.empty()) { + LogWarn << "Both name and location are set for SkillUsage action. Skip this step."; + break; + } + if (auto it = m_used_tiles.find(location); it == m_used_tiles.end()) { + LogInfo << "Tile hasn't used, register for drone" << location; + drone_name = std::format("drone_{}_{}", location.x, location.y); + register_deployed_oper(drone_name, location); + } + else { + drone_name = it->second; + } + set_usage(drone_name, action.modify_usage, action.modify_times); + } + else { + set_usage(name, action.modify_usage, action.modify_times); + } + ret = true; + break; } - ret = true; - break; case ActionType::Output: // DoNothing