#include "InfrastDormTask.h" #include #include #include #include "WinMacro.h" #include "Identify.h" #include "Configer.h" using namespace asst; asst::InfrastDormTask::InfrastDormTask(AsstCallback callback, void* callback_arg) : OcrAbstractTask(callback, callback_arg) { ; } bool asst::InfrastDormTask::run() { if (m_view_ptr == nullptr || m_identify_ptr == nullptr || m_control_ptr == nullptr) { m_callback(AsstMsg::PtrIsNull, json::value(), m_callback_arg); return false; } enter_dorm(m_dorm_begin); for (int i = m_dorm_begin; i != DormNum; ++i) { bool to_left = false; if (i != m_dorm_begin) { enter_next_dorm(); to_left = false; } else { to_left = true; // 第一个进入的宿舍需要滑动到最左侧一下。后面的宿舍都不用了 } enter_operator_selection(); int selected = select_operators(to_left); if (selected < MaxOperNumInDorm) { // 如果选不满5个人,说明没有更多需要休息的了,直接结束宿舍任务 break; } } return true; } bool asst::InfrastDormTask::enter_dorm(int index) { cv::Mat image = get_format_image(); // 普通的和mini的,正常情况应该只有一个有结果,另一个是empty auto dorm_result = m_identify_ptr->find_all_images(image, "Dorm", 0.8); auto dorm_mini_result = m_identify_ptr->find_all_images(image, "DormMini", 0.8); decltype(dorm_result) cur_dorm_result; if (dorm_result.empty() && dorm_mini_result.empty()) { // 没找到宿舍,TODO,报错 return false; } else if (dorm_result.empty()) { cur_dorm_result = std::move(dorm_mini_result); } else if (dorm_mini_result.empty()) { cur_dorm_result = std::move(dorm_result); } if (index >= cur_dorm_result.size()) { return false; } std::sort(cur_dorm_result.begin(), cur_dorm_result.end(), []( const auto& lhs, const auto& rhs) -> bool { return lhs.rect.y < rhs.rect.y; }); m_control_ptr->click(cur_dorm_result.at(index).rect); sleep(1000); return false; } bool asst::InfrastDormTask::enter_next_dorm() { static const Rect swipe_down_begin( // 向下滑动起点 Configer::WindowWidthDefault * 0.3, Configer::WindowHeightDefault * 0.8, Configer::WindowWidthDefault * 0.2, Configer::WindowWidthDefault * 0.1); static const Rect swipe_down_end( // 向下滑动终点 Configer::WindowWidthDefault * 0.3, Configer::WindowHeightDefault * 0.2, Configer::WindowWidthDefault * 0.2, Configer::WindowWidthDefault * 0.1); static const int swipe_dwon_duration = 1000; // 向下滑动持续时间 // 游戏bug,宿舍中如果“进驻信息”已被选中,直接进行滑动会被滑的很远 // 所以这里先检查一下,如果进驻信息被选中了,就先把它关了,再进行滑动 auto find_result = m_identify_ptr->find_image(get_format_image(), "StationInfoSelected"); if (find_result.score >= 0.75) { m_control_ptr->click(find_result.rect); } m_control_ptr->swipe(swipe_down_begin, swipe_down_end, swipe_dwon_duration); static const Rect double_click_rect( Configer::WindowWidthDefault * 0.4, Configer::WindowHeightDefault * 0.4, Configer::WindowWidthDefault * 0.2, Configer::WindowWidthDefault * 0.2 ); // 游戏中的宿舍里,双击可以让当前设施回到正确的位置 m_control_ptr->click(double_click_rect); m_control_ptr->click(double_click_rect); return true; } bool asst::InfrastDormTask::enter_operator_selection() { // 有这些文字之一就说明“进驻信息”这个按钮已经点开了 static const std::vector info_opened_flags = { GbkToUtf8("当前房间入住信息"), GbkToUtf8("进驻人数"), GbkToUtf8("清空") }; std::vector