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;