From 107e42e9e89df483c31402ae797bcc0c982ee33b Mon Sep 17 00:00:00 2001 From: MistEO Date: Fri, 27 Jan 2023 15:13:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=8D=95=E6=AD=A5?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84json=E8=A7=A3=E6=9E=90=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaCore/Task/Interface/SingleStepTask.cpp | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/MaaCore/Task/Interface/SingleStepTask.cpp b/src/MaaCore/Task/Interface/SingleStepTask.cpp index 70a515df3b..d6ae5628a3 100644 --- a/src/MaaCore/Task/Interface/SingleStepTask.cpp +++ b/src/MaaCore/Task/Interface/SingleStepTask.cpp @@ -2,6 +2,7 @@ #include "../SingleStep/SingleStepBattleProcessTask.h" #include "Config/Miscellaneous/CopilotConfig.h" +#include "Utils/Logger.hpp" asst::SingleStepTask::SingleStepTask(const AsstCallback& callback, Assistant* inst) : InterfaceTask(callback, inst, TaskType) @@ -9,14 +10,28 @@ asst::SingleStepTask::SingleStepTask(const AsstCallback& callback, Assistant* in bool asst::SingleStepTask::set_params(const json::value& params) { - std::string type = params.at("type").as_string(); - std::string subtype = params.at("subtype").as_string(); - const json::value& details = params.at("details"); + std::string type = params.get("type", ""); + std::string subtype = params.get("subtype", ""); + auto details_opt = params.find("details"); - if (type == "copilot" && subtype == "action") { + if (type == "copilot" && subtype == "action" && details_opt) { auto task = std::make_shared(m_callback, m_inst, TaskType); + // for debug + task->set_stage_name("OF-1"); + // 请参考自动战斗协议 - task->set_actions(CopilotConfig::parse_actions(details)); + try { + task->set_actions(CopilotConfig::parse_actions(*details_opt)); + } + catch (const json::exception& e) { + Log.error(__FUNCTION__, e.what()); + return false; + } + catch (const std::exception& e) { + Log.error(__FUNCTION__, e.what()); + return false; + } + m_subtasks.emplace_back(std::move(task)); return true;