diff --git a/src/MaaCore/Common/AsstBattleDef.h b/src/MaaCore/Common/AsstBattleDef.h index 3e3c6514ce..9a5bf31b79 100644 --- a/src/MaaCore/Common/AsstBattleDef.h +++ b/src/MaaCore/Common/AsstBattleDef.h @@ -317,8 +317,8 @@ struct CheckInfo // 定义until操作需要的信息 struct UntilInfo { - TriggerInfo::Category mode; // all 全部命令执行完毕后才结束, any 只要有一个执行就结束 - std::vector candidate; // 备用的命令序列 + TriggerInfo::Category mode = TriggerInfo::Category::All; // all 全部命令执行完毕后才结束, any 只要有一个执行就结束 + std::vector candidate; // 备用的命令序列 }; // 定义point操作需要的信息 @@ -332,6 +332,8 @@ struct PointInfo int interval = 0; std::chrono::steady_clock::time_point tNow; + + SnapShot() = default; }; std::string target_code; @@ -340,6 +342,8 @@ struct PointInfo std::vector then_actions; // 当条件满足时执行 std::vector else_actions; // 当条件不满足时执行 + + PointInfo() = default; }; struct CheckIfStartOverInfo diff --git a/src/MaaCore/Config/Miscellaneous/CopilotConfig.cpp b/src/MaaCore/Config/Miscellaneous/CopilotConfig.cpp index 6b89c99b94..de8b4b50d3 100644 --- a/src/MaaCore/Config/Miscellaneous/CopilotConfig.cpp +++ b/src/MaaCore/Config/Miscellaneous/CopilotConfig.cpp @@ -217,13 +217,13 @@ bool asst::CopilotConfig::parse_action(const json::value& action_info, asst::bat { "Check", ActionType::Check }, { "check", ActionType::Check }, { "CHECK", ActionType::Check }, - { "检查", ActionType::Check }, + { "确认", ActionType::Check }, { "分支", ActionType::Check }, { "Until", ActionType::Until }, { "until", ActionType::Until }, { "UNTIL", ActionType::Until }, - { "直到", ActionType::Until }, + { "轮询", ActionType::Until }, { "SavePoint", ActionType::SavePoint }, { "savepoint", ActionType::SavePoint }, @@ -376,8 +376,11 @@ bool asst::CopilotConfig::parse_action(const json::value& action_info, asst::bat case ActionType::Until: { auto& until = action.payload.emplace(); - // 必选字段 - until.mode = TriggerInfo::loadCategoryFrom(action_info.at("mode").as_string()); + // 可选字段 + if (auto t = action_info.find("mode")) { + until.mode = TriggerInfo::loadCategoryFrom(t.value().as_string()); + } + switch (until.mode) { case TriggerInfo::Category::Any: case TriggerInfo::Category::All: @@ -387,8 +390,13 @@ bool asst::CopilotConfig::parse_action(const json::value& action_info, asst::bat break; } - // 必选字段,缺省值为0 - action.trigger.count = action_info.get("limit", 0); + // 可选字段,缺省值为0 + if (auto t = action_info.find("limit")) { + action.trigger.count = t.value().as_integer(); + } + else if (action.trigger.count == TriggerInfo::DEACTIVE_COUNT) { + action.trigger.count = 0; + } // 可选字段 if (auto t = action_info.find("candidate_actions")) { diff --git a/src/MaaCore/Task/Miscellaneous/BattleProcessTask.cpp b/src/MaaCore/Task/Miscellaneous/BattleProcessTask.cpp index 414f3c4096..3903ed0406 100644 --- a/src/MaaCore/Task/Miscellaneous/BattleProcessTask.cpp +++ b/src/MaaCore/Task/Miscellaneous/BattleProcessTask.cpp @@ -420,6 +420,12 @@ END_LOOP:; case ActionType::SyncPoint: { auto& info = action.getPayload(); + // 目标编码不匹配,退出 + if (!find_snap_shot(info.target_code)) { + ret = false; + break; + } + thread_local auto prev_frame_time = std::chrono::steady_clock::time_point {}; static const auto min_frame_interval = std::chrono::milliseconds(Config.get_options().copilot_fight_screencap_interval); @@ -454,6 +460,12 @@ END_LOOP:; case ActionType::CheckPoint: { auto& info = action.getPayload(); + // 目标编码不匹配,退出 + if (!find_snap_shot(info.target_code)) { + ret = false; + break; + } + if (check_point(info)) { size_t i = 0; for (; i < info.then_actions.size(); ++i) { @@ -1293,10 +1305,13 @@ auto asst::BattleProcessTask::gen_snap_shot() -> battle::copilot::PointInfo::Sna return shot; } +bool asst::BattleProcessTask::find_snap_shot(const std::string& code) const noexcept +{ + return m_snap_shots.find(code) != m_snap_shots.cend(); +} + void asst::BattleProcessTask::save_snap_shot(const std::string& code) { - using TriggerInfo = battle::copilot::TriggerInfo; - if (code.empty()) { return; } diff --git a/src/MaaCore/Task/Miscellaneous/BattleProcessTask.h b/src/MaaCore/Task/Miscellaneous/BattleProcessTask.h index 5cb57388c5..37b22ab065 100644 --- a/src/MaaCore/Task/Miscellaneous/BattleProcessTask.h +++ b/src/MaaCore/Task/Miscellaneous/BattleProcessTask.h @@ -68,9 +68,8 @@ protected: void sleep_and_do_strategy(unsigned millisecond); auto gen_snap_shot() -> battle::copilot::PointInfo::SnapShot; - + bool find_snap_shot(const std::string& code) const noexcept; void save_snap_shot(const std::string& code); - auto get_snap_shot(const std::string& code) const noexcept -> battle::copilot::PointInfo::SnapShot const&; virtual bool check_in_battle(const cv::Mat& reusable = cv::Mat(), bool weak = true) override;