From 2c785389550aaeda5e171cd34b7fa660f4d8bfef Mon Sep 17 00:00:00 2001 From: MistEO Date: Mon, 6 Sep 2021 23:04:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=BF=E8=88=8D=E6=8D=A2?= =?UTF-8?q?=E7=8F=AD=EF=BC=8C=E4=B8=8D=E9=9C=80=E8=A6=81=E6=8D=A2=E7=8F=AD?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E7=9B=B4=E6=8E=A5=E9=80=80=E5=87=BA?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E5=AE=BF=E8=88=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MeoAssistance/InfrastDormTask.cpp | 47 +++++++++++++++++++------------ MeoAssistance/InfrastDormTask.h | 2 +- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/MeoAssistance/InfrastDormTask.cpp b/MeoAssistance/InfrastDormTask.cpp index 87189a9b2b..99f6a9ee4b 100644 --- a/MeoAssistance/InfrastDormTask.cpp +++ b/MeoAssistance/InfrastDormTask.cpp @@ -166,25 +166,39 @@ bool asst::InfrastDormTask::enter_operator_selection() bool asst::InfrastDormTask::select_operators() { - static auto click_clear_button = [](InfrastDormTask* ptr) { - // 点击“清空选择”按钮 + // 点击“清空选择”按钮 + auto click_clear_button = [&]() { const static Rect clear_button(430, 655, 150, 40); - ptr->m_control_ptr->click(clear_button); - ptr->sleep(300); + m_control_ptr->click(clear_button); + sleep(300); + }; + // 点击“确定”按钮 + auto click_confirm_button = [&]() { + const static Rect confirm_button(1105, 655, 150, 40); + m_control_ptr->click(confirm_button); + sleep(500); }; - cv::Mat image = get_format_image(); - std::future click_clear_button_future = std::async(std::launch::async, click_clear_button, this); + cv::Mat image = get_format_image(); // 识别“休息中”的干员 auto resting_result = m_identify_ptr->find_all_images(image, "Resting", 0.8); + if (resting_result.size() == MaxOperNumInDorm) { // 如果所有人都在休息,那这个宿舍不用换班,直接关了 + click_confirm_button(); + return true; + } + // 识别“注意力涣散”的干员 // TODO,这个阈值太低了,不正常,有时间再调整一下模板图片 auto listless_result = m_identify_ptr->find_all_images(image, "Listless", 0.6); // 识别正在工作中的干员的心情状态 - auto work_mood_result = detect_mood_status_at_work(image); + auto work_mood_result = detect_mood_status_at_work(image, Configer::get_instance().m_infrast_options.dorm_threshold); - click_clear_button_future.wait(); + if (listless_result.size() == 0 && work_mood_result.size() == 0) { // 如果没有注意力涣散的和心情低的,也直接关了 + click_confirm_button(); + return true; + } + click_clear_button(); int count = 0; // 把“休息中”的干员,都再次选上 @@ -204,16 +218,11 @@ bool asst::InfrastDormTask::select_operators() if (count++ >= MaxOperNumInDorm) { break; } - if (mood_status.process > Configer::get_instance().m_infrast_options.dorm_threshold) { - break; // 这个容器是排过序的,如果一个大于,后面的就都是大于了 - } m_control_ptr->click(mood_status.rect); } - // 点击“确定”按钮,确定完要联网加载的,比较慢,多sleep一会 - const static Rect confirm_button(1105, 655, 150, 40); - m_control_ptr->click(confirm_button); - sleep(500); + click_confirm_button(); + // 点完确定后,如果把工作中的干员撤下来了,会再弹出来一个确认的界面,如果没扯下来则不会弹出。先识别一下再决定要不要点击 auto&& [algorithm, score, second_confirm_rect] = m_identify_ptr->find_image(get_format_image(), "DormConfirm"); if (score >= Configer::TemplThresholdDefault) { @@ -224,7 +233,7 @@ bool asst::InfrastDormTask::select_operators() return true; } -std::vector InfrastDormTask::detect_mood_status_at_work(const cv::Mat& image) const +std::vector InfrastDormTask::detect_mood_status_at_work(const cv::Mat& image, double process_threshold) const { constexpr static int MoodWidth = Configer::WindowWidthDefault * 0.0664 + 0.5; // 心情进度条长度(满心情的时候) constexpr static int MoodHeight = Configer::WindowHeightDefault * 0.00416 + 0.5; // 心情进度条高度 @@ -291,9 +300,11 @@ std::vector InfrastDormTask::detect_mood_status_at_ cv::rectangle(draw_image, cv_actual_rect, cv::Scalar(0, 0, 255), 1); cv::putText(draw_image, std::to_string(mood_status.process), cv::Point(cv_actual_rect.x, cv_actual_rect.y), cv::FONT_HERSHEY_PLAIN, 1, cv::Scalar(0, 0, 255)); #endif - moods_vec.emplace_back(std::move(mood_status)); + if (mood_status.process <= process_threshold) { + moods_vec.emplace_back(std::move(mood_status)); + } } - + std::sort(moods_vec.begin(), moods_vec.end(), [](const auto& lhs, const auto& rhs) -> bool { // 按剩余心情进度排个序,少的在前面 diff --git a/MeoAssistance/InfrastDormTask.h b/MeoAssistance/InfrastDormTask.h index c3605e2c93..458c9dbe8d 100644 --- a/MeoAssistance/InfrastDormTask.h +++ b/MeoAssistance/InfrastDormTask.h @@ -34,6 +34,6 @@ namespace asst { bool select_operators(); // 检测正在工作中的干员心情状态 - std::vector detect_mood_status_at_work(const cv::Mat& image) const; + std::vector detect_mood_status_at_work(const cv::Mat& image, double process_threshold = 1.0) const; }; }