diff --git a/src/MeoAssistant/AbstractTask.h b/src/MeoAssistant/AbstractTask.h index a8bf460538..dd9851d54e 100644 --- a/src/MeoAssistant/AbstractTask.h +++ b/src/MeoAssistant/AbstractTask.h @@ -41,7 +41,7 @@ namespace asst template std::shared_ptr register_plugin() - requires std::derived_from // Plugin must inherit AbstractTaskPlugin + requires std::derived_from // Plugin must inherit AbstractTaskPlugin { auto plugin = std::make_shared(m_callback, m_callback_arg, m_task_chain); m_plugins.emplace(plugin); diff --git a/src/MeoAssistant/Assistant.cpp b/src/MeoAssistant/Assistant.cpp index 140ae4bbac..e5c6e08c76 100644 --- a/src/MeoAssistant/Assistant.cpp +++ b/src/MeoAssistant/Assistant.cpp @@ -88,7 +88,7 @@ asst::Assistant::TaskId asst::Assistant::append_task(const std::string& type, co else if (type == TASK::TaskType) { ptr = std::make_shared(task_callback, static_cast(this)); } if constexpr (false) {} - ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(FightTask) + ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(FightTask) ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(StartUpTask) ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(CloseDownTask) ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(AwardTask) diff --git a/src/MeoAssistant/AsstRanges.hpp b/src/MeoAssistant/AsstRanges.hpp index 6f3fe7f7eb..8fbb03e2ec 100644 --- a/src/MeoAssistant/AsstRanges.hpp +++ b/src/MeoAssistant/AsstRanges.hpp @@ -17,7 +17,7 @@ namespace asst { template S, typename C, typename P = identity> constexpr subrange - operator()(I first, S last, C pred, P proj = P{}) const + operator()(I first, S last, C pred, P proj = P{}) const { return { ::ranges::remove_if(std::move(first), last, std::move(pred), std::move(proj)), last }; } @@ -53,7 +53,8 @@ namespace asst #include #include -namespace asst { +namespace asst +{ namespace ranges = boost::range; namespace views = boost::adaptors; } diff --git a/src/MeoAssistant/AsstTypes.h b/src/MeoAssistant/AsstTypes.h index e1ff817429..165d9751e0 100644 --- a/src/MeoAssistant/AsstTypes.h +++ b/src/MeoAssistant/AsstTypes.h @@ -36,16 +36,16 @@ namespace asst constexpr Point(int x, int y) : x(x), y(y) {} Point& operator=(const Point&) noexcept = default; Point& operator=(Point&&) noexcept = default; - Point operator-() const noexcept { return {-x, -y}; } + Point operator-() const noexcept { return { -x, -y }; } bool operator==(const Point& rhs) const noexcept { return x == rhs.x && y == rhs.y; } std::string to_string() const { return "[ " + std::to_string(x) + ", " + std::to_string(y) + " ]"; } - static constexpr Point right() { return {1, 0}; } - static constexpr Point down() { return {0, 1}; } - static constexpr Point left() { return {-1, 0}; } - static constexpr Point up() { return {0, -1}; } + static constexpr Point right() { return { 1, 0 }; } + static constexpr Point down() { return { 0, 1 }; } + static constexpr Point left() { return { -1, 0 }; } + static constexpr Point up() { return { 0, -1 }; } int x = 0; int y = 0; @@ -54,13 +54,13 @@ friend Point operator Op (const Point& lhs, const Point& rhs) noexcept { return friend Point& operator Op##= (Point& val, const Point& opd) noexcept { val.x Op##= opd.x; val.y Op##= opd.y; return val; } DEFINE_ASST_POINT_BINARY_OP_AND_ARG_ASSIGN(+) - DEFINE_ASST_POINT_BINARY_OP_AND_ARG_ASSIGN(-) - DEFINE_ASST_POINT_BINARY_OP_AND_ARG_ASSIGN(*) + DEFINE_ASST_POINT_BINARY_OP_AND_ARG_ASSIGN(-) + DEFINE_ASST_POINT_BINARY_OP_AND_ARG_ASSIGN(*) #undef DEFINE_ASST_POINT_BINARY_OP_AND_ARG_ASSIGN - friend Point operator*(int scalar, const Point& value) noexcept { return {value.x * scalar, value.y * scalar}; } - friend Point operator*(const Point& value, int scalar) noexcept { return {value.x * scalar, value.y * scalar}; } + friend Point operator*(int scalar, const Point& value) noexcept { return { value.x * scalar, value.y * scalar }; } + friend Point operator*(const Point& value, int scalar) noexcept { return { value.x * scalar, value.y * scalar }; } static int dot(const Point& lhs, const Point& rhs) noexcept { return (lhs.x * rhs.x) + (lhs.y * rhs.y); } static double distance(const Point& lhs, const Point& rhs) noexcept { diff --git a/src/MeoAssistant/AsstUtils.hpp b/src/MeoAssistant/AsstUtils.hpp index cdb5f411fd..b43008f63a 100644 --- a/src/MeoAssistant/AsstUtils.hpp +++ b/src/MeoAssistant/AsstUtils.hpp @@ -47,8 +47,8 @@ namespace asst::utils template inline std::string string_replace_all_batch(const std::string& src, const map_t& replace_pairs) - requires std::derived_from - && std::derived_from + requires std::derived_from + && std::derived_from { std::string str = src; for (const auto& [old_value, new_value] : replace_pairs) { @@ -194,9 +194,9 @@ namespace asst::utils #ifdef _WIN32 ASST_AUTO_DEDUCED_ZERO_INIT_START - SECURITY_ATTRIBUTES pipe_sec_attr = { 0 }; + SECURITY_ATTRIBUTES pipe_sec_attr = { 0 }; ASST_AUTO_DEDUCED_ZERO_INIT_END - pipe_sec_attr.nLength = sizeof(SECURITY_ATTRIBUTES); + pipe_sec_attr.nLength = sizeof(SECURITY_ATTRIBUTES); pipe_sec_attr.lpSecurityDescriptor = nullptr; pipe_sec_attr.bInheritHandle = TRUE; HANDLE pipe_read = nullptr; @@ -204,19 +204,19 @@ namespace asst::utils CreatePipe(&pipe_read, &pipe_child_write, &pipe_sec_attr, PipeBuffSize); ASST_AUTO_DEDUCED_ZERO_INIT_START - STARTUPINFOA si = { 0 }; + STARTUPINFOA si = { 0 }; ASST_AUTO_DEDUCED_ZERO_INIT_END - si.cb = sizeof(STARTUPINFO); + si.cb = sizeof(STARTUPINFO); si.dwFlags = STARTF_USESTDHANDLES; si.wShowWindow = SW_HIDE; si.hStdOutput = pipe_child_write; si.hStdError = pipe_child_write; ASST_AUTO_DEDUCED_ZERO_INIT_START - PROCESS_INFORMATION pi = { nullptr }; + PROCESS_INFORMATION pi = { nullptr }; ASST_AUTO_DEDUCED_ZERO_INIT_END - BOOL p_ret = CreateProcessA(nullptr, const_cast(cmdline.c_str()), nullptr, nullptr, TRUE, CREATE_NO_WINDOW, nullptr, nullptr, &si, &pi); + BOOL p_ret = CreateProcessA(nullptr, const_cast(cmdline.c_str()), nullptr, nullptr, TRUE, CREATE_NO_WINDOW, nullptr, nullptr, &si, &pi); if (p_ret) { DWORD peek_num = 0; DWORD read_num = 0; diff --git a/src/MeoAssistant/AutoRecruitTask.cpp b/src/MeoAssistant/AutoRecruitTask.cpp index 6b0b16e123..d4232c5b95 100644 --- a/src/MeoAssistant/AutoRecruitTask.cpp +++ b/src/MeoAssistant/AutoRecruitTask.cpp @@ -147,7 +147,6 @@ asst::AutoRecruitTask& asst::AutoRecruitTask::set_recruitment_time(std::unordere return *this; } - bool asst::AutoRecruitTask::_run() { if (m_force_discard_flag) return false; @@ -315,7 +314,7 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc has_special_tag = true; } - // robot tags + // robot tags const std::vector RobotTags = { "支援机械" }; auto robot_iter = ranges::find_first_of(RobotTags, tag_names); if (robot_iter != RobotTags.cend()) [[unlikely]] { @@ -326,7 +325,6 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc has_robot_tag = true; } - std::vector result_vec = recruit_calc::get_all_combs(tag_names); // assuming timer would be set to 09:00:00 @@ -361,7 +359,6 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc } ); - if (result_vec.empty()) continue; const auto& final_combination = result_vec.front(); @@ -407,7 +404,6 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc && final_combination.min_level == 3 && !(m_skip_robot && has_robot_tag) ) { - if (refresh_count > refresh_limit) [[unlikely]] { json::value info = basic_info(); info["what"] = "RecruitError"; diff --git a/src/MeoAssistant/AutoRecruitTask.h b/src/MeoAssistant/AutoRecruitTask.h index dd0bb1b986..b63259044e 100644 --- a/src/MeoAssistant/AutoRecruitTask.h +++ b/src/MeoAssistant/AutoRecruitTask.h @@ -37,7 +37,8 @@ namespace asst bool confirm(); bool refresh(); - struct calc_task_result_type { + struct calc_task_result_type + { bool success = false; bool force_skip = false; int recruitment_time = 60; @@ -64,7 +65,7 @@ namespace asst std::set m_force_skipped; - static slot_index slot_index_from_rect(const Rect &r) + static slot_index slot_index_from_rect(const Rect& r) { /* 公开招募 * 0 | 1 diff --git a/src/MeoAssistant/BattleProcessTask.cpp b/src/MeoAssistant/BattleProcessTask.cpp index 898befcb14..7a68d21680 100644 --- a/src/MeoAssistant/BattleProcessTask.cpp +++ b/src/MeoAssistant/BattleProcessTask.cpp @@ -330,7 +330,7 @@ bool asst::BattleProcessTask::do_action(const BattleAction& action) case BattleActionType::BulletTime: action_desc = "子弹时间"; break; - // TODO 其他情况 + // TODO 其他情况 case BattleActionType::SkillUsage: case BattleActionType::UseAllSkill: case BattleActionType::Output:; @@ -379,7 +379,7 @@ bool asst::BattleProcessTask::do_action(const BattleAction& action) case BattleActionType::SkillDaemon: ret = wait_to_end(action); break; - // TODO 其他情况 + // TODO 其他情况 case BattleActionType::UseAllSkill:; } sleep_with_possible_skill(action.rear_delay); diff --git a/src/MeoAssistant/Controller.cpp b/src/MeoAssistant/Controller.cpp index db56d3a687..92711a25ee 100644 --- a/src/MeoAssistant/Controller.cpp +++ b/src/MeoAssistant/Controller.cpp @@ -264,10 +264,10 @@ std::optional> asst::Controller::call_command(const std::stri #ifdef _WIN32 ASST_AUTO_DEDUCED_ZERO_INIT_START - PROCESS_INFORMATION process_info = { nullptr }; // 进程信息结构体 + PROCESS_INFORMATION process_info = { nullptr }; // 进程信息结构体 ASST_AUTO_DEDUCED_ZERO_INIT_END - BOOL create_ret = CreateProcessA(nullptr, const_cast(cmd.c_str()), nullptr, nullptr, TRUE, CREATE_NO_WINDOW, nullptr, nullptr, &m_child_startup_info, &process_info); + BOOL create_ret = CreateProcessA(nullptr, const_cast(cmd.c_str()), nullptr, nullptr, TRUE, CREATE_NO_WINDOW, nullptr, nullptr, &m_child_startup_info, &process_info); if (!create_ret) { Log.error("Call `", cmd, "` create process failed, ret", create_ret); return std::nullopt; diff --git a/src/MeoAssistant/Controller.h b/src/MeoAssistant/Controller.h index 81a096acc6..b5f80c143a 100644 --- a/src/MeoAssistant/Controller.h +++ b/src/MeoAssistant/Controller.h @@ -104,7 +104,7 @@ namespace asst HANDLE m_pipe_child_write = nullptr; // 子进程的写管道句柄 ASST_AUTO_DEDUCED_ZERO_INIT_START - SECURITY_ATTRIBUTES m_pipe_sec_attr = { 0 }; // 管道安全描述符 + SECURITY_ATTRIBUTES m_pipe_sec_attr = { 0 }; // 管道安全描述符 STARTUPINFOA m_child_startup_info = { 0 }; // 子进程启动信息 WSADATA m_wsa_data = { 0 }; diff --git a/src/MeoAssistant/CopilotTask.cpp b/src/MeoAssistant/CopilotTask.cpp index 38aadd96a3..c4c385731d 100644 --- a/src/MeoAssistant/CopilotTask.cpp +++ b/src/MeoAssistant/CopilotTask.cpp @@ -6,45 +6,45 @@ #include "BattleFormationTask.h" asst::CopilotTask::CopilotTask(const AsstCallback& callback, void* callback_arg) - : PackageTask(callback, callback_arg, TaskType), - m_formation_task_ptr(std::make_shared(callback, callback_arg, TaskType)), - m_battle_task_ptr(std::make_shared(callback, callback_arg, TaskType)) + : PackageTask(callback, callback_arg, TaskType), + m_formation_task_ptr(std::make_shared(callback, callback_arg, TaskType)), + m_battle_task_ptr(std::make_shared(callback, callback_arg, TaskType)) { - auto start_1_tp = std::make_shared(callback, callback_arg, TaskType); - start_1_tp->set_tasks({ "BattleStartPre" }) - .set_retry_times(0) - .set_ignore_error(true); - m_subtasks.emplace_back(start_1_tp); + auto start_1_tp = std::make_shared(callback, callback_arg, TaskType); + start_1_tp->set_tasks({ "BattleStartPre" }) + .set_retry_times(0) + .set_ignore_error(true); + m_subtasks.emplace_back(start_1_tp); - m_subtasks.emplace_back(m_formation_task_ptr)->set_ignore_error(false).set_retry_times(0); + m_subtasks.emplace_back(m_formation_task_ptr)->set_ignore_error(false).set_retry_times(0); - auto start_2_tp = std::make_shared(callback, callback_arg, TaskType); - start_2_tp->set_tasks({ "BattleStartNormal", "BattleStartRaid", "BattleStartExercise", "BattleStartSimulation" }) - .set_ignore_error(false); - m_subtasks.emplace_back(start_2_tp); + auto start_2_tp = std::make_shared(callback, callback_arg, TaskType); + start_2_tp->set_tasks({ "BattleStartNormal", "BattleStartRaid", "BattleStartExercise", "BattleStartSimulation" }) + .set_ignore_error(false); + m_subtasks.emplace_back(start_2_tp); - m_subtasks.emplace_back(m_battle_task_ptr)->set_retry_times(0); + m_subtasks.emplace_back(m_battle_task_ptr)->set_retry_times(0); } bool asst::CopilotTask::set_params(const json::value& params) { - if (m_running) { - return false; - } + if (m_running) { + return false; + } - auto stage_name_opt = params.find("stage_name"); - if (!stage_name_opt) { - return false; - } + auto stage_name_opt = params.find("stage_name"); + if (!stage_name_opt) { + return false; + } - const std::string& stage_name = *stage_name_opt; - m_battle_task_ptr->set_stage_name(stage_name); - m_formation_task_ptr->set_stage_name(stage_name); + const std::string& stage_name = *stage_name_opt; + m_battle_task_ptr->set_stage_name(stage_name); + m_formation_task_ptr->set_stage_name(stage_name); - bool with_formation = params.get("formation", false); - m_formation_task_ptr->set_enable(with_formation); + bool with_formation = params.get("formation", false); + m_formation_task_ptr->set_enable(with_formation); - std::string filename = params.get("filename", std::string()); - // 文件名为空时,不加载资源,直接返回 true - return filename.empty() || Resrc.copilot().load(filename); -} \ No newline at end of file + std::string filename = params.get("filename", std::string()); + // 文件名为空时,不加载资源,直接返回 true + return filename.empty() || Resrc.copilot().load(filename); +} diff --git a/src/MeoAssistant/InfrastFacilityImageAnalyzer.cpp b/src/MeoAssistant/InfrastFacilityImageAnalyzer.cpp index 75bc9cde13..8d54be2151 100644 --- a/src/MeoAssistant/InfrastFacilityImageAnalyzer.cpp +++ b/src/MeoAssistant/InfrastFacilityImageAnalyzer.cpp @@ -59,7 +59,7 @@ bool asst::InfrastFacilityImageAnalyzer::analyze() const auto& cur_res = mm_analyzer.get_result(); auto cur_max_iter = ranges::max_element(cur_res, [](const MatchRect& lhs, const MatchRect& rhs) -> bool { - return lhs.score < rhs.score; + return lhs.score < rhs.score; }); if (cur_max_iter == cur_res.cend()) { continue; diff --git a/src/MeoAssistant/InfrastOperImageAnalyzer.cpp b/src/MeoAssistant/InfrastOperImageAnalyzer.cpp index bf5a4b3d75..aeea6ae50c 100644 --- a/src/MeoAssistant/InfrastOperImageAnalyzer.cpp +++ b/src/MeoAssistant/InfrastOperImageAnalyzer.cpp @@ -297,7 +297,7 @@ void asst::InfrastOperImageAnalyzer::skill_analyze() // 即排除容器中,除了有同一个技能的不同等级,还有别的技能的情况 auto max_iter = ranges::max_element(possible_skills, [](const auto& lhs, const auto& rhs) -> bool { - return lhs.second.score < rhs.second.score; + return lhs.second.score < rhs.second.score; }); double base_score = max_iter->second.score; std::string base_id = max_iter->first.id; diff --git a/src/MeoAssistant/InfrastProductionTask.cpp b/src/MeoAssistant/InfrastProductionTask.cpp index ba6ddc08a8..67b9ef09aa 100644 --- a/src/MeoAssistant/InfrastProductionTask.cpp +++ b/src/MeoAssistant/InfrastProductionTask.cpp @@ -497,79 +497,79 @@ bool asst::InfrastProductionTask::opers_choose() [&](const infrast::Oper& rhs) -> bool { return rhs.mood_ratio < m_mood_threshold; }).begin(); - cur_all_opers.erase(remove_iter, cur_all_opers.end()); - Log.trace("after mood filter, opers size:", cur_all_opers.size()); - for (auto opt_iter = m_optimal_combs.begin(); opt_iter != m_optimal_combs.end();) { - Log.trace("to find", opt_iter->skills.begin()->names.front()); - auto find_iter = ranges::find_if(cur_all_opers, - [&](const infrast::Oper& lhs) -> bool { - if (lhs.skills != opt_iter->skills) { - return false; - } - if (opt_iter->name_filter.empty()) { - return true; - } - else { - OcrWithPreprocessImageAnalyzer name_analyzer(lhs.name_img); - name_analyzer.set_replace( - Task.get("CharsNameOcrReplace")->replace_map); - Log.trace("Analyze name filter"); - if (!name_analyzer.analyze()) { + cur_all_opers.erase(remove_iter, cur_all_opers.end()); + Log.trace("after mood filter, opers size:", cur_all_opers.size()); + for (auto opt_iter = m_optimal_combs.begin(); opt_iter != m_optimal_combs.end();) { + Log.trace("to find", opt_iter->skills.begin()->names.front()); + auto find_iter = ranges::find_if(cur_all_opers, + [&](const infrast::Oper& lhs) -> bool { + if (lhs.skills != opt_iter->skills) { return false; } - std::string name = name_analyzer.get_result().front().text; - return ranges::find(std::as_const(opt_iter->name_filter), name) != opt_iter->name_filter.cend(); - } - }); + if (opt_iter->name_filter.empty()) { + return true; + } + else { + OcrWithPreprocessImageAnalyzer name_analyzer(lhs.name_img); + name_analyzer.set_replace( + Task.get("CharsNameOcrReplace")->replace_map); + Log.trace("Analyze name filter"); + if (!name_analyzer.analyze()) { + return false; + } + std::string name = name_analyzer.get_result().front().text; + return ranges::find(std::as_const(opt_iter->name_filter), name) != opt_iter->name_filter.cend(); + } + }); - if (find_iter == cur_all_opers.cend()) { - ++opt_iter; - Log.trace("not found in this page"); - continue; - } - Log.trace("found in this page"); - // 这种情况可能是需要选择两个同样的技能,上一次循环选了一个,但是没有把滑出当前页面,本次又识别到了这个已选择的人 - if (find_iter->selected == true) { - if (cur_max_num_of_opers != 1) { - cur_all_opers.erase(find_iter); - Log.trace("skill matched, but it's selected, pass"); + if (find_iter == cur_all_opers.cend()) { + ++opt_iter; + Log.trace("not found in this page"); continue; } - // 但是如果当前设施只有一个位置,即不存在“上次循环”的情况,说明是清除干员按钮没点到 - } - else { - m_ctrler->click(find_iter->rect); - } - { - auto avlb_iter = ranges::find_if(m_all_available_opers, - [&](const infrast::Oper& lhs) -> bool { - int dist = HashImageAnalyzer::hamming(lhs.face_hash, find_iter->face_hash); - Log.debug("opers_choose | face hash dist", dist); - return dist < face_hash_thres; + Log.trace("found in this page"); + // 这种情况可能是需要选择两个同样的技能,上一次循环选了一个,但是没有把滑出当前页面,本次又识别到了这个已选择的人 + if (find_iter->selected == true) { + if (cur_max_num_of_opers != 1) { + cur_all_opers.erase(find_iter); + Log.trace("skill matched, but it's selected, pass"); + continue; } - ); - if (avlb_iter != m_all_available_opers.cend()) { - m_all_available_opers.erase(avlb_iter); + // 但是如果当前设施只有一个位置,即不存在“上次循环”的情况,说明是清除干员按钮没点到 } else { - Log.error("opers_choose | not found oper"); + m_ctrler->click(find_iter->rect); } + { + auto avlb_iter = ranges::find_if(m_all_available_opers, + [&](const infrast::Oper& lhs) -> bool { + int dist = HashImageAnalyzer::hamming(lhs.face_hash, find_iter->face_hash); + Log.debug("opers_choose | face hash dist", dist); + return dist < face_hash_thres; + } + ); + if (avlb_iter != m_all_available_opers.cend()) { + m_all_available_opers.erase(avlb_iter); + } + else { + Log.error("opers_choose | not found oper"); + } + } + ++count; + cur_all_opers.erase(find_iter); + opt_iter = m_optimal_combs.erase(opt_iter); } - ++count; - cur_all_opers.erase(find_iter); - opt_iter = m_optimal_combs.erase(opt_iter); - } - if (m_optimal_combs.empty()) { - Log.trace(__FUNCTION__, "| count", count, "cur_max_num_of_opers", cur_max_num_of_opers); - if (count < cur_max_num_of_opers) { - // 这种情况可能是萌新,可用干员人数不足以填满当前设施 - callback(AsstMsg::SubTaskExtraInfo, basic_info_with_what("NotEnoughStaff")); + if (m_optimal_combs.empty()) { + Log.trace(__FUNCTION__, "| count", count, "cur_max_num_of_opers", cur_max_num_of_opers); + if (count < cur_max_num_of_opers) { + // 这种情况可能是萌新,可用干员人数不足以填满当前设施 + callback(AsstMsg::SubTaskExtraInfo, basic_info_with_what("NotEnoughStaff")); + } + break; } - break; - } - // 因为识别完了还要点击,所以这里不能异步滑动 - swipe_of_operlist(); + // 因为识别完了还要点击,所以这里不能异步滑动 + swipe_of_operlist(); } return true; diff --git a/src/MeoAssistant/InfrastProductionTask.h b/src/MeoAssistant/InfrastProductionTask.h index 9288578cd7..630504542a 100644 --- a/src/MeoAssistant/InfrastProductionTask.h +++ b/src/MeoAssistant/InfrastProductionTask.h @@ -6,35 +6,35 @@ namespace asst { - // 生产类设施的任务,适用于制造站/贸易站 - class InfrastProductionTask : public InfrastAbstractTask - { - public: - using InfrastAbstractTask::InfrastAbstractTask; - virtual ~InfrastProductionTask() override = default; + // 生产类设施的任务,适用于制造站/贸易站 + class InfrastProductionTask : public InfrastAbstractTask + { + public: + using InfrastAbstractTask::InfrastAbstractTask; + virtual ~InfrastProductionTask() override = default; - InfrastProductionTask& set_uses_of_drone(std::string uses_of_drones) noexcept; - std::string get_uses_of_drone() const noexcept; + InfrastProductionTask& set_uses_of_drone(std::string uses_of_drones) noexcept; + std::string get_uses_of_drone() const noexcept; - protected: - bool shift_facility_list(); - bool facility_list_detect(); - bool opers_detect_with_swipe(); - size_t opers_detect(); // 返回当前页面的干员数 - bool optimal_calc(); - bool opers_choose(); - bool use_drone(); - void set_product(std::string product_name) noexcept; + protected: + bool shift_facility_list(); + bool facility_list_detect(); + bool opers_detect_with_swipe(); + size_t opers_detect(); // 返回当前页面的干员数 + bool optimal_calc(); + bool opers_choose(); + bool use_drone(); + void set_product(std::string product_name) noexcept; - infrast::SkillsComb efficient_regex_calc( - std::unordered_set skills) const; + infrast::SkillsComb efficient_regex_calc( + std::unordered_set skills) const; - std::string m_product; - std::string m_uses_of_drones; - int m_cur_num_of_locked_opers = 0; - std::vector m_all_available_opers; - std::vector m_optimal_combs; - std::vector m_facility_list_tabs; - size_t max_num_of_opers_per_page = 0; - }; + std::string m_product; + std::string m_uses_of_drones; + int m_cur_num_of_locked_opers = 0; + std::vector m_all_available_opers; + std::vector m_optimal_combs; + std::vector m_facility_list_tabs; + size_t max_num_of_opers_per_page = 0; + }; } diff --git a/src/MeoAssistant/InfrastTask.cpp b/src/MeoAssistant/InfrastTask.cpp index 9b86bae894..6f9bdb66cf 100644 --- a/src/MeoAssistant/InfrastTask.cpp +++ b/src/MeoAssistant/InfrastTask.cpp @@ -15,95 +15,95 @@ #include "ReplenishOriginiumShardTaskPlugin.h" asst::InfrastTask::InfrastTask(const AsstCallback& callback, void* callback_arg) - : PackageTask(callback, callback_arg, TaskType), - m_infrast_begin_task_ptr(std::make_shared(callback, callback_arg, TaskType)), - m_info_task_ptr(std::make_shared(callback, callback_arg, TaskType)), - m_mfg_task_ptr(std::make_shared(callback, callback_arg, TaskType)), - m_trade_task_ptr(std::make_shared(callback, callback_arg, TaskType)), - m_power_task_ptr(std::make_shared(callback, callback_arg, TaskType)), - m_control_task_ptr(std::make_shared(callback, callback_arg, TaskType)), - m_reception_task_ptr(std::make_shared(callback, callback_arg, TaskType)), - m_office_task_ptr(std::make_shared(callback, callback_arg, TaskType)), - m_dorm_task_ptr(std::make_shared(callback, callback_arg, TaskType)) + : PackageTask(callback, callback_arg, TaskType), + m_infrast_begin_task_ptr(std::make_shared(callback, callback_arg, TaskType)), + m_info_task_ptr(std::make_shared(callback, callback_arg, TaskType)), + m_mfg_task_ptr(std::make_shared(callback, callback_arg, TaskType)), + m_trade_task_ptr(std::make_shared(callback, callback_arg, TaskType)), + m_power_task_ptr(std::make_shared(callback, callback_arg, TaskType)), + m_control_task_ptr(std::make_shared(callback, callback_arg, TaskType)), + m_reception_task_ptr(std::make_shared(callback, callback_arg, TaskType)), + m_office_task_ptr(std::make_shared(callback, callback_arg, TaskType)), + m_dorm_task_ptr(std::make_shared(callback, callback_arg, TaskType)) { - m_infrast_begin_task_ptr->set_tasks({ "InfrastBegin" }); - m_trade_task_ptr->register_plugin()->set_retry_times(0); - m_replenish_task_ptr = m_mfg_task_ptr->register_plugin(); + m_infrast_begin_task_ptr->set_tasks({ "InfrastBegin" }); + m_trade_task_ptr->register_plugin()->set_retry_times(0); + m_replenish_task_ptr = m_mfg_task_ptr->register_plugin(); - m_subtasks.emplace_back(m_infrast_begin_task_ptr); + m_subtasks.emplace_back(m_infrast_begin_task_ptr); } bool asst::InfrastTask::set_params(const json::value& params) { - if (!m_running) { - auto facility_opt = params.find("facility"); - if (!facility_opt) { - return false; - } + if (!m_running) { + auto facility_opt = params.find("facility"); + if (!facility_opt) { + return false; + } - auto append_infrast_begin = [&]() { - m_subtasks.emplace_back(m_infrast_begin_task_ptr); - }; + auto append_infrast_begin = [&]() { + m_subtasks.emplace_back(m_infrast_begin_task_ptr); + }; - m_subtasks.clear(); - append_infrast_begin(); - m_subtasks.emplace_back(m_info_task_ptr); + m_subtasks.clear(); + append_infrast_begin(); + m_subtasks.emplace_back(m_info_task_ptr); - for (const auto& facility_json : facility_opt.value()) { - if (!facility_json.is_string()) { - m_subtasks.clear(); - append_infrast_begin(); - return false; - } + for (const auto& facility_json : facility_opt.value()) { + if (!facility_json.is_string()) { + m_subtasks.clear(); + append_infrast_begin(); + return false; + } - std::string facility = facility_json.as_string(); - if (facility == "Dorm") { - m_subtasks.emplace_back(m_dorm_task_ptr); - } - else if (facility == "Mfg") { - m_subtasks.emplace_back(m_mfg_task_ptr); - } - else if (facility == "Trade") { - m_subtasks.emplace_back(m_trade_task_ptr); - } - else if (facility == "Power") { - m_subtasks.emplace_back(m_power_task_ptr); - } - else if (facility == "Office") { - m_subtasks.emplace_back(m_office_task_ptr); - } - else if (facility == "Reception") { - m_subtasks.emplace_back(m_reception_task_ptr); - } - else if (facility == "Control") { - m_subtasks.emplace_back(m_control_task_ptr); - } - else { - Log.error(__FUNCTION__, "| Unknown facility", facility); - m_subtasks.clear(); - append_infrast_begin(); - return false; - } - append_infrast_begin(); - } - } + std::string facility = facility_json.as_string(); + if (facility == "Dorm") { + m_subtasks.emplace_back(m_dorm_task_ptr); + } + else if (facility == "Mfg") { + m_subtasks.emplace_back(m_mfg_task_ptr); + } + else if (facility == "Trade") { + m_subtasks.emplace_back(m_trade_task_ptr); + } + else if (facility == "Power") { + m_subtasks.emplace_back(m_power_task_ptr); + } + else if (facility == "Office") { + m_subtasks.emplace_back(m_office_task_ptr); + } + else if (facility == "Reception") { + m_subtasks.emplace_back(m_reception_task_ptr); + } + else if (facility == "Control") { + m_subtasks.emplace_back(m_control_task_ptr); + } + else { + Log.error(__FUNCTION__, "| Unknown facility", facility); + m_subtasks.clear(); + append_infrast_begin(); + return false; + } + append_infrast_begin(); + } + } - std::string drones = params.get("drones", "_NotUse"); - m_mfg_task_ptr->set_uses_of_drone(drones); - m_trade_task_ptr->set_uses_of_drone(drones); + std::string drones = params.get("drones", "_NotUse"); + m_mfg_task_ptr->set_uses_of_drone(drones); + m_trade_task_ptr->set_uses_of_drone(drones); - double threshold = params.get("threshold", 0.3); - m_info_task_ptr->set_mood_threshold(threshold); - m_mfg_task_ptr->set_mood_threshold(threshold); - m_trade_task_ptr->set_mood_threshold(threshold); - m_power_task_ptr->set_mood_threshold(threshold); - m_control_task_ptr->set_mood_threshold(threshold); - m_reception_task_ptr->set_mood_threshold(threshold); - m_office_task_ptr->set_mood_threshold(threshold); - m_dorm_task_ptr->set_mood_threshold(threshold); + double threshold = params.get("threshold", 0.3); + m_info_task_ptr->set_mood_threshold(threshold); + m_mfg_task_ptr->set_mood_threshold(threshold); + m_trade_task_ptr->set_mood_threshold(threshold); + m_power_task_ptr->set_mood_threshold(threshold); + m_control_task_ptr->set_mood_threshold(threshold); + m_reception_task_ptr->set_mood_threshold(threshold); + m_office_task_ptr->set_mood_threshold(threshold); + m_dorm_task_ptr->set_mood_threshold(threshold); - bool replenish = params.get("replenish", false); - m_replenish_task_ptr->set_enable(replenish); + bool replenish = params.get("replenish", false); + m_replenish_task_ptr->set_enable(replenish); - return true; -} \ No newline at end of file + return true; +} diff --git a/src/MeoAssistant/Logger.hpp b/src/MeoAssistant/Logger.hpp index e301ee1745..391ea60143 100644 --- a/src/MeoAssistant/Logger.hpp +++ b/src/MeoAssistant/Logger.hpp @@ -169,9 +169,9 @@ namespace asst template struct has_stream_insertion_operator< - Stream, T, - std::void_t() << std::declval())>> - : std::true_type + Stream, T, + std::void_t() << std::declval())>> + : std::true_type { }; @@ -180,25 +180,27 @@ namespace asst template struct is_range_expression()))>::iterator_category, - std::forward_iterator_tag - > - >> : std::true_type + std::is_convertible_v< + typename std::iterator_traits()))>::iterator_category, + std::forward_iterator_tag + > + >> : std::true_type { }; template static Stream& stream_put(Stream& s, T&& v) { - if constexpr(std::is_constructible_v) { + if constexpr (std::is_constructible_v) { if constexpr (ToAnsi) s << utils::utf8_to_ansi(std::forward(v)); else s << std::string(std::forward(v)); return s; - } else if constexpr (has_stream_insertion_operator::value) { + } + else if constexpr (has_stream_insertion_operator::value) { s << std::forward(v); return s; - } else if constexpr (is_range_expression::value) { + } + else if constexpr (is_range_expression::value) { s << "["; std::string_view comma{}; for (const auto& elem : std::forward(v)) { @@ -208,7 +210,8 @@ namespace asst } s << "]"; return s; - } else { + } + else { ASST_STATIC_ASSERT_FALSE( "\nunsupported type, one of the following expected\n" "\t1. those can be converted to string;\n" @@ -222,8 +225,10 @@ namespace asst struct stream_put_line_impl; template - struct stream_put_line_impl { - static constexpr Stream& apply(Stream& s) { + struct stream_put_line_impl + { + static constexpr Stream& apply(Stream& s) + { s << std::endl; return s; } diff --git a/src/MeoAssistant/PackageTask.cpp b/src/MeoAssistant/PackageTask.cpp index 0ece122073..062be69755 100644 --- a/src/MeoAssistant/PackageTask.cpp +++ b/src/MeoAssistant/PackageTask.cpp @@ -5,81 +5,81 @@ bool asst::PackageTask::run() { - if (!m_enable) { - Log.info("task disabled, pass", basic_info().to_string()); - return true; - } - m_running = true; + if (!m_enable) { + Log.info("task disabled, pass", basic_info().to_string()); + return true; + } + m_running = true; - const auto task_delay = Resrc.cfg().get_options().task_delay; + const auto task_delay = Resrc.cfg().get_options().task_delay; - for (size_t i = 0; i != m_subtasks.size(); ++i) { - if (need_exit()) { - return false; - } + for (size_t i = 0; i != m_subtasks.size(); ++i) { + if (need_exit()) { + return false; + } - auto task_ptr = m_subtasks.at(i); - if (!task_ptr->get_enable()) { - continue; - } + auto task_ptr = m_subtasks.at(i); + if (!task_ptr->get_enable()) { + continue; + } - task_ptr->set_exit_flag(m_exit_flag) - .set_ctrler(m_ctrler) - .set_status(m_status) - .set_task_id(m_task_id); + task_ptr->set_exit_flag(m_exit_flag) + .set_ctrler(m_ctrler) + .set_status(m_status) + .set_task_id(m_task_id); - if (!task_ptr->run() && !task_ptr->get_ignore_error()) { - return false; - } + if (!task_ptr->run() && !task_ptr->get_ignore_error()) { + return false; + } - if (i != m_subtasks.size() - 1) { - sleep(task_delay); - } - } - return true; + if (i != m_subtasks.size() - 1) { + sleep(task_delay); + } + } + return true; } asst::AbstractTask& asst::PackageTask::set_exit_flag(bool* exit_flag) noexcept { - AbstractTask::set_exit_flag(exit_flag); - for (auto&& sub : m_subtasks) { - sub->set_exit_flag(exit_flag); - } - return *this; + AbstractTask::set_exit_flag(exit_flag); + for (auto&& sub : m_subtasks) { + sub->set_exit_flag(exit_flag); + } + return *this; } asst::AbstractTask& asst::PackageTask::set_retry_times(int times) noexcept { - AbstractTask::set_retry_times(times); - for (auto&& sub : m_subtasks) { - sub->set_retry_times(times); - } - return *this; + AbstractTask::set_retry_times(times); + for (auto&& sub : m_subtasks) { + sub->set_retry_times(times); + } + return *this; } asst::AbstractTask& asst::PackageTask::set_ctrler(std::shared_ptr ctrler) noexcept { - AbstractTask::set_ctrler(ctrler); - for (auto&& sub : m_subtasks) { - sub->set_ctrler(ctrler); - } - return *this; + AbstractTask::set_ctrler(ctrler); + for (auto&& sub : m_subtasks) { + sub->set_ctrler(ctrler); + } + return *this; } asst::AbstractTask& asst::PackageTask::set_status(std::shared_ptr status) noexcept { - AbstractTask::set_status(status); - for (auto&& sub : m_subtasks) { - sub->set_status(status); - } - return *this; + AbstractTask::set_status(status); + for (auto&& sub : m_subtasks) { + sub->set_status(status); + } + return *this; } asst::AbstractTask& asst::PackageTask::set_task_id(int task_id) noexcept { - AbstractTask::set_task_id(task_id); - for (auto&& sub : m_subtasks) { - sub->set_task_id(task_id); - } - return *this; -} \ No newline at end of file + AbstractTask::set_task_id(task_id); + for (auto&& sub : m_subtasks) { + sub->set_task_id(task_id); + } + return *this; +} diff --git a/src/MeoAssistant/RecruitTask.cpp b/src/MeoAssistant/RecruitTask.cpp index 7cf1da66f7..b383178990 100644 --- a/src/MeoAssistant/RecruitTask.cpp +++ b/src/MeoAssistant/RecruitTask.cpp @@ -47,17 +47,16 @@ bool asst::RecruitTask::set_params(const json::value& params) recruitment_time_map[5] = std::clamp(params.get("recruitment_time", "5", 9 * 60), 1 * 60, 9 * 60); recruitment_time_map[6] = std::clamp(params.get("recruitment_time", "6", 9 * 60), 1 * 60, 9 * 60); - m_auto_recruit_task_ptr->set_enable(true); m_auto_recruit_task_ptr->set_max_times(times) - .set_need_refresh(refresh) - .set_use_expedited(expedite) - .set_select_level(std::move(select)) - .set_confirm_level(std::move(confirm)) - .set_skip_robot(skip_robot) - .set_recruitment_time(recruitment_time_map) - .set_set_time(set_time).set_retry_times(3); + .set_need_refresh(refresh) + .set_use_expedited(expedite) + .set_select_level(std::move(select)) + .set_confirm_level(std::move(confirm)) + .set_skip_robot(skip_robot) + .set_recruitment_time(recruitment_time_map) + .set_set_time(set_time).set_retry_times(3); return true; } diff --git a/src/MeoAssistant/StopGameTaskPlugin.h b/src/MeoAssistant/StopGameTaskPlugin.h index 3255a112fc..2028e2db12 100644 --- a/src/MeoAssistant/StopGameTaskPlugin.h +++ b/src/MeoAssistant/StopGameTaskPlugin.h @@ -5,7 +5,6 @@ namespace asst { - class StopGameTaskPlugin : public AbstractTaskPlugin { public: diff --git a/src/MeoAssistant/TaskData.h b/src/MeoAssistant/TaskData.h index c7f79bee11..55333f0951 100644 --- a/src/MeoAssistant/TaskData.h +++ b/src/MeoAssistant/TaskData.h @@ -26,9 +26,9 @@ namespace asst const std::unordered_set& get_templ_required() const noexcept; template - requires std::derived_from - && (!std::same_as) // Parameter must be a TaskInfo and not same as TaskInfo - std::shared_ptr get(const std::string& name) + requires std::derived_from + && (!std::same_as) // Parameter must be a TaskInfo and not same as TaskInfo + std::shared_ptr get(const std::string& name) { auto it = m_all_tasks_info.find(name); if (it == m_all_tasks_info.cend()) { @@ -39,7 +39,7 @@ namespace asst } template - requires std::same_as // Parameter must be a TaskInfo + requires std::same_as // Parameter must be a TaskInfo std::shared_ptr get(const std::string& name) { auto it = m_all_tasks_info.find(name);