From 826bb26d45ca417f3f2d7d9752c5580da7e0cff4 Mon Sep 17 00:00:00 2001 From: MistEO Date: Sat, 28 Jan 2023 03:41:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8D=95=E6=AD=A5=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE=E5=85=B3=E5=8D=A1=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaCore/Task/Interface/SingleStepTask.cpp | 13 +++++++++---- src/MaaCore/Task/Interface/SingleStepTask.h | 1 + .../SingleStep/SingleStepBattleProcessTask.cpp | 16 ++++++++++++++-- .../SingleStep/SingleStepBattleProcessTask.h | 5 ++++- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/MaaCore/Task/Interface/SingleStepTask.cpp b/src/MaaCore/Task/Interface/SingleStepTask.cpp index d51430691f..cd5528f2ff 100644 --- a/src/MaaCore/Task/Interface/SingleStepTask.cpp +++ b/src/MaaCore/Task/Interface/SingleStepTask.cpp @@ -18,7 +18,10 @@ bool asst::SingleStepTask::set_params(const json::value& params) auto details_opt = params.find("details"); if (type == "copilot") { - if (subtype == "start") { + if (subtype == "stage" && details_opt) { + return set_copilot_stage(*details_opt); + } + else if (subtype == "start") { return append_copllot_start(); } else if (subtype == "action" && details_opt) { @@ -28,6 +31,11 @@ bool asst::SingleStepTask::set_params(const json::value& params) return false; } +bool asst::SingleStepTask::set_copilot_stage(const json::value& details) +{ + return SingleStepBattleProcessTask::set_stage_name_cache(details.get("stage_name", "")); +} + bool asst::SingleStepTask::append_copllot_start() { LogTraceFunction; @@ -45,9 +53,6 @@ bool asst::SingleStepTask::append_copilot_action(const json::value& details) auto task = std::make_shared(m_callback, m_inst, TaskType); - // for debug - task->set_stage_name("OF-1"); - try { // 请参考自动战斗协议 auto actions = CopilotConfig::parse_actions(details); diff --git a/src/MaaCore/Task/Interface/SingleStepTask.h b/src/MaaCore/Task/Interface/SingleStepTask.h index d60c1b5707..719f97cd5b 100644 --- a/src/MaaCore/Task/Interface/SingleStepTask.h +++ b/src/MaaCore/Task/Interface/SingleStepTask.h @@ -16,6 +16,7 @@ namespace asst virtual bool set_params(const json::value& params) override; private: + bool set_copilot_stage(const json::value& details); bool append_copllot_start(); bool append_copilot_action(const json::value& details); }; diff --git a/src/MaaCore/Task/SingleStep/SingleStepBattleProcessTask.cpp b/src/MaaCore/Task/SingleStep/SingleStepBattleProcessTask.cpp index 7ce41a5b3b..3c5b521997 100644 --- a/src/MaaCore/Task/SingleStep/SingleStepBattleProcessTask.cpp +++ b/src/MaaCore/Task/SingleStep/SingleStepBattleProcessTask.cpp @@ -4,6 +4,18 @@ #include "Task/ProcessTask.h" #include "Utils/Logger.hpp" +bool asst::SingleStepBattleProcessTask::set_stage_name_cache(const std::string& stage_name) +{ + LogTraceFunction; + + if (!Tile.contains(stage_name)) { + Log.error("get stage info failed", stage_name); + return false; + } + m_stage_name_cache = stage_name; + return true; +} + void asst::SingleStepBattleProcessTask::set_actions(Actions actions) { m_actions = std::move(actions); @@ -13,8 +25,8 @@ bool asst::SingleStepBattleProcessTask::_run() { LogTraceFunction; - if (!calc_tiles_info(m_stage_name)) { - Log.error("get stage info failed"); + if (!calc_tiles_info(m_stage_name_cache)) { + Log.error("get stage info failed", m_stage_name_cache); return false; } diff --git a/src/MaaCore/Task/SingleStep/SingleStepBattleProcessTask.h b/src/MaaCore/Task/SingleStep/SingleStepBattleProcessTask.h index a334d81efa..95d5e088c4 100644 --- a/src/MaaCore/Task/SingleStep/SingleStepBattleProcessTask.h +++ b/src/MaaCore/Task/SingleStep/SingleStepBattleProcessTask.h @@ -13,8 +13,8 @@ namespace asst virtual ~SingleStepBattleProcessTask() override = default; using BattleProcessTask::clear; - using BattleProcessTask::set_stage_name; + static bool set_stage_name_cache(const std::string& stage_name); void set_actions(Actions actions); protected: @@ -23,5 +23,8 @@ namespace asst private: Actions m_actions; + + // for debug + inline static std::string m_stage_name_cache; }; }