feat: 支持自定义换班autofill和candidates字段

This commit is contained in:
MistEO
2022-09-18 15:33:13 +08:00
parent 9465e253eb
commit 2ca8b9a09f
8 changed files with 46 additions and 22 deletions

View File

@@ -119,6 +119,7 @@ namespace asst::infrast
bool autofill = false;
std::string product;
std::vector<std::string> candidates;
int selected = 0;
};
using CustomFacilityConfig = std::vector<CustomRoomConfig>;
} // namespace asst::infrast

View File

@@ -4,6 +4,7 @@
#include <utility>
#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<std::string>& 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<std::string>& 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<std::string>& 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;
}
}

View File

@@ -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<std::string>& opers_name);
bool select_opers_by_name(std::vector<std::string>& opers_name);
bool swipe_and_select_custom_opers();
bool select_custom_opers();
virtual bool click_bottom_left_tab(); // 点击进入设施后左下角的tab我也不知道这玩意该叫啥
virtual bool click_clear_button(); // 点击干员选择页面的“清空选择”按钮

View File

@@ -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;
}

View File

@@ -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();
// }
// }

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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<infrast::SkillsComb> 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;
}