From 2ca8b9a09fc2d3d8ddecf9245c3e21e99ce1f28e Mon Sep 17 00:00:00 2001 From: MistEO Date: Sun, 18 Sep 2022 15:33:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=8D=A2=E7=8F=ADautofill=E5=92=8Ccandidates=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MeoAssistant/AsstInfrastDef.h | 1 + src/MeoAssistant/InfrastAbstractTask.cpp | 36 +++++++++++++++------- src/MeoAssistant/InfrastAbstractTask.h | 4 +-- src/MeoAssistant/InfrastControlTask.cpp | 2 +- src/MeoAssistant/InfrastDormTask.cpp | 4 +-- src/MeoAssistant/InfrastOfficeTask.cpp | 4 +-- src/MeoAssistant/InfrastPowerTask.cpp | 2 +- src/MeoAssistant/InfrastProductionTask.cpp | 15 +++++++-- 8 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/MeoAssistant/AsstInfrastDef.h b/src/MeoAssistant/AsstInfrastDef.h index d3d8e93671..2ef0432bd3 100644 --- a/src/MeoAssistant/AsstInfrastDef.h +++ b/src/MeoAssistant/AsstInfrastDef.h @@ -119,6 +119,7 @@ namespace asst::infrast bool autofill = false; std::string product; std::vector candidates; + int selected = 0; }; using CustomFacilityConfig = std::vector; } // namespace asst::infrast diff --git a/src/MeoAssistant/InfrastAbstractTask.cpp b/src/MeoAssistant/InfrastAbstractTask.cpp index 87a97858b3..d62cbd4e4a 100644 --- a/src/MeoAssistant/InfrastAbstractTask.cpp +++ b/src/MeoAssistant/InfrastAbstractTask.cpp @@ -4,6 +4,7 @@ #include #include "AsstMsg.h" +#include "AsstRanges.hpp" #include "Controller.h" #include "InfrastFacilityImageAnalyzer.h" #include "InfrastOperImageAnalyzer.h" @@ -139,7 +140,7 @@ bool asst::InfrastAbstractTask::is_use_custom_config() return false; } return !m_current_room_custom_config.names.empty() || !m_current_room_custom_config.candidates.empty() || - m_current_room_custom_config.autofill; + !m_current_room_custom_config.autofill; } void asst::InfrastAbstractTask::await_swipe() @@ -151,28 +152,31 @@ void asst::InfrastAbstractTask::await_swipe() sleep(extra_delay); } -bool asst::InfrastAbstractTask::swipe_and_select_opers_by_name(std::vector& opers_name) +bool asst::InfrastAbstractTask::swipe_and_select_custom_opers() { LogTraceFunction; - while (!opers_name.empty()) { + while (true) { if (need_exit()) { return false; } - if (!select_opers_by_name(opers_name)) { + if (!select_custom_opers()) { return false; } + if (m_current_room_custom_config.selected >= max_num_of_opers()) { + break; + } swipe_of_operlist(); } - return opers_name.empty(); + return m_current_room_custom_config.names.empty(); } -bool asst::InfrastAbstractTask::select_opers_by_name(std::vector& opers_name) +bool asst::InfrastAbstractTask::select_custom_opers() { LogTraceFunction; - if (opers_name.empty()) { + if (m_current_room_custom_config.names.empty() && m_current_room_custom_config.candidates.empty()) { Log.warn("opers_name is empty"); return false; } @@ -194,15 +198,25 @@ bool asst::InfrastAbstractTask::select_opers_by_name(std::vector& o continue; } const std::string& name = name_analyzer.get_result().front().text; - auto iter = std::find(opers_name.begin(), opers_name.end(), name); - if (iter == opers_name.end()) { + + if (auto iter = ranges::find(m_current_room_custom_config.names, name); + iter != m_current_room_custom_config.names.end()) { + m_current_room_custom_config.names.erase(iter); + } + else if (max_num_of_opers() - m_current_room_custom_config.selected > + m_current_room_custom_config.names.size()) { // names中的数量,比剩余的空位多,就可以选备选的 + if (auto candd_iter = ranges::find(m_current_room_custom_config.candidates, name); + candd_iter != m_current_room_custom_config.candidates.end()) { + m_current_room_custom_config.candidates.erase(candd_iter); + } + } + else { continue; } if (!oper.selected) { m_ctrler->click(oper.rect); } - opers_name.erase(iter); - if (opers_name.empty()) { + if (++m_current_room_custom_config.selected >= max_num_of_opers()) { break; } } diff --git a/src/MeoAssistant/InfrastAbstractTask.h b/src/MeoAssistant/InfrastAbstractTask.h index 5fdf243651..5d9adc6fb7 100644 --- a/src/MeoAssistant/InfrastAbstractTask.h +++ b/src/MeoAssistant/InfrastAbstractTask.h @@ -37,8 +37,8 @@ namespace asst void async_swipe_of_operlist(bool reverse = false); void await_swipe(); bool is_use_custom_config(); - bool swipe_and_select_opers_by_name(std::vector& opers_name); - bool select_opers_by_name(std::vector& opers_name); + bool swipe_and_select_custom_opers(); + bool select_custom_opers(); virtual bool click_bottom_left_tab(); // 点击进入设施后,左下角的tab(我也不知道这玩意该叫啥) virtual bool click_clear_button(); // 点击干员选择页面的“清空选择”按钮 diff --git a/src/MeoAssistant/InfrastControlTask.cpp b/src/MeoAssistant/InfrastControlTask.cpp index c468c3650b..8506e85a76 100644 --- a/src/MeoAssistant/InfrastControlTask.cpp +++ b/src/MeoAssistant/InfrastControlTask.cpp @@ -21,7 +21,7 @@ bool asst::InfrastControlTask::_run() click_clear_button(); if (is_use_custom_config()) { - bool name_select_ret = swipe_and_select_opers_by_name(m_current_room_custom_config.names); + bool name_select_ret = swipe_and_select_custom_opers(); if (name_select_ret) { break; } diff --git a/src/MeoAssistant/InfrastDormTask.cpp b/src/MeoAssistant/InfrastDormTask.cpp index 668dcfdc2f..a995df9b0f 100644 --- a/src/MeoAssistant/InfrastDormTask.cpp +++ b/src/MeoAssistant/InfrastDormTask.cpp @@ -47,7 +47,7 @@ bool asst::InfrastDormTask::_run() click_clear_button(); if (is_use_custom_config()) { - swipe_and_select_opers_by_name(m_current_room_custom_config.names); + swipe_and_select_custom_opers(); } else { opers_choose(); @@ -218,4 +218,4 @@ bool asst::InfrastDormTask::opers_choose() // // ProcessTask task(*this, { "InfrastDormConfirmButton" }); // return task.run(); -// } +// } \ No newline at end of file diff --git a/src/MeoAssistant/InfrastOfficeTask.cpp b/src/MeoAssistant/InfrastOfficeTask.cpp index 51e8d2b8ca..6ecdc0b1f6 100644 --- a/src/MeoAssistant/InfrastOfficeTask.cpp +++ b/src/MeoAssistant/InfrastOfficeTask.cpp @@ -23,7 +23,7 @@ bool asst::InfrastOfficeTask::_run() return false; } if (is_use_custom_config()) { - bool name_select_ret = swipe_and_select_opers_by_name(m_current_room_custom_config.names); + bool name_select_ret = swipe_and_select_custom_opers(); if (name_select_ret) { break; } @@ -45,4 +45,4 @@ bool asst::InfrastOfficeTask::_run() click_return_button(); return true; -} +} \ No newline at end of file diff --git a/src/MeoAssistant/InfrastPowerTask.cpp b/src/MeoAssistant/InfrastPowerTask.cpp index afb6da6903..a4d96cd27f 100644 --- a/src/MeoAssistant/InfrastPowerTask.cpp +++ b/src/MeoAssistant/InfrastPowerTask.cpp @@ -27,7 +27,7 @@ bool asst::InfrastPowerTask::_run() for (int j = 0; j <= OperSelectRetryTimes; ++j) { if (is_use_custom_config()) { - bool name_select_ret = swipe_and_select_opers_by_name(m_current_room_custom_config.names); + bool name_select_ret = swipe_and_select_custom_opers(); if (name_select_ret) { break; } diff --git a/src/MeoAssistant/InfrastProductionTask.cpp b/src/MeoAssistant/InfrastProductionTask.cpp index 5fd581a0dc..f36ac8a437 100644 --- a/src/MeoAssistant/InfrastProductionTask.cpp +++ b/src/MeoAssistant/InfrastProductionTask.cpp @@ -123,7 +123,7 @@ bool asst::InfrastProductionTask::shift_facility_list() click_clear_button(); if (is_use_custom_config()) { - bool name_select_ret = swipe_and_select_opers_by_name(m_current_room_custom_config.names); + bool name_select_ret = swipe_and_select_custom_opers(); if (name_select_ret) { break; } @@ -246,6 +246,14 @@ bool asst::InfrastProductionTask::optimal_calc() LogTraceFunction; auto& facility_info = InfrastData.get_facility_info(facility_name()); int cur_max_num_of_opers = facility_info.max_num_of_opers - m_cur_num_of_locked_opers; + if (m_is_custom) { + cur_max_num_of_opers -= m_current_room_custom_config.selected; + } + if (cur_max_num_of_opers == 0) { + Log.warn("no need select opers"); + m_optimal_combs.clear(); + return true; + } std::vector all_available_combs; all_available_combs.reserve(m_all_available_opers.size()); @@ -308,8 +316,9 @@ bool asst::InfrastProductionTask::optimal_calc() Log.trace("Single comb efficient", max_efficient, " , skills:", log_str); } - // 如果有被锁住的干员,说明当前基建没升满级,组合就不启用 - if (m_cur_num_of_locked_opers != 0) { + // 需要选的人和当前房间最大人数不想等,组合就不启用。 + // 可能是房间等级没升满,或者是自定义配置提前选了几个人等 + if (cur_max_num_of_opers != facility_info.max_num_of_opers) { m_optimal_combs = std::move(optimal_combs); return true; }