mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 17:57:01 +08:00
style. 格式化代码
This commit is contained in:
@@ -17,8 +17,7 @@ namespace asst::recruit_calc
|
||||
|
||||
{
|
||||
rcs_with_single_tag.reserve(tags.size());
|
||||
std::ranges::transform(tags, std::back_inserter(rcs_with_single_tag), [](const std::string& t)
|
||||
{
|
||||
std::ranges::transform(tags, std::back_inserter(rcs_with_single_tag), [](const std::string& t) {
|
||||
RecruitCombs result;
|
||||
result.tags = { t };
|
||||
result.min_level = 6;
|
||||
@@ -164,11 +163,10 @@ std::optional<asst::Rect> asst::AutoRecruitTask::try_get_start_button(const cv::
|
||||
if (!start_analyzer.analyze()) return std::nullopt;
|
||||
start_analyzer.sort_result_horizontal();
|
||||
auto iter =
|
||||
std::ranges::find_if(std::as_const(start_analyzer.get_result()),
|
||||
[&](const TextRect& r) -> bool
|
||||
{
|
||||
return !m_force_skipped.contains(slot_index_from_rect(r.rect));
|
||||
});
|
||||
std::ranges::find_if(std::as_const(start_analyzer.get_result()),
|
||||
[&](const TextRect& r) -> bool {
|
||||
return !m_force_skipped.contains(slot_index_from_rect(r.rect));
|
||||
});
|
||||
if (iter == start_analyzer.get_result().cend()) return std::nullopt;
|
||||
Log.info("Found slot index", slot_index_from_rect(iter->rect), ".");
|
||||
return iter->rect;
|
||||
@@ -267,7 +265,7 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc
|
||||
std::ranges::transform(tags, std::back_inserter(tag_json_vector), std::mem_fn(&TextRect::text));
|
||||
|
||||
info["what"] = "RecruitTagsDetected";
|
||||
info["details"] = json::object{{ "tags", json::array(tag_json_vector) }};
|
||||
info["details"] = json::object{ { "tags", json::array(tag_json_vector) } };
|
||||
callback(AsstMsg::SubTaskExtraInfo, info);
|
||||
}
|
||||
|
||||
@@ -277,7 +275,7 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc
|
||||
if (special_iter != SpecialTags.cend()) {
|
||||
json::value info = basic_info();
|
||||
info["what"] = "RecruitSpecialTag";
|
||||
info["details"] = json::object{{ "tag", *special_iter }};
|
||||
info["details"] = json::object{ { "tag", *special_iter } };
|
||||
callback(AsstMsg::SubTaskExtraInfo, info);
|
||||
has_special_tag = true;
|
||||
}
|
||||
@@ -288,7 +286,7 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc
|
||||
if (robot_iter != RobotTags.cend()) {
|
||||
json::value info = basic_info();
|
||||
info["what"] = "RecruitRobotTag";
|
||||
info["details"] = json::object{{ "tag", *robot_iter }};
|
||||
info["details"] = json::object{ { "tag", *robot_iter } };
|
||||
callback(AsstMsg::SubTaskExtraInfo, info);
|
||||
has_robot_tag = true;
|
||||
}
|
||||
@@ -309,8 +307,7 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc
|
||||
|
||||
std::ranges::sort(result_vec
|
||||
,
|
||||
[&](const RecruitCombs& lhs, const RecruitCombs& rhs) -> bool
|
||||
{
|
||||
[&](const RecruitCombs& lhs, const RecruitCombs& rhs) -> bool {
|
||||
// prefer the one with special tag
|
||||
// workaround for https://github.com/MaaAssistantArknights/MaaAssistantArknights/issues/1336
|
||||
if (has_special_tag) {
|
||||
@@ -450,7 +447,7 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc
|
||||
// select tags
|
||||
for (const std::string& final_tag_name : final_combination.tags) {
|
||||
auto tag_rect_iter =
|
||||
std::ranges::find_if(tags, [&](const TextRect& r) { return r.text == final_tag_name; });
|
||||
std::ranges::find_if(tags, [&](const TextRect& r) { return r.text == final_tag_name; });
|
||||
if (tag_rect_iter != tags.cend()) {
|
||||
m_ctrler->click(tag_rect_iter->rect);
|
||||
}
|
||||
|
||||
@@ -501,7 +501,7 @@ bool asst::BattleImageAnalyzer::kills_analyze()
|
||||
std::string kills_count = kills_text.substr(0, pos);
|
||||
if (kills_count.empty() ||
|
||||
!std::ranges::all_of(std::as_const(kills_count),
|
||||
[](char c) -> bool {return std::isdigit(c);})) {
|
||||
[](char c) -> bool {return std::isdigit(c);})) {
|
||||
return false;
|
||||
}
|
||||
int cur_kills = std::stoi(kills_count);
|
||||
@@ -512,7 +512,7 @@ bool asst::BattleImageAnalyzer::kills_analyze()
|
||||
int cur_total_kills = 0;
|
||||
if (total_kills.empty() ||
|
||||
!std::ranges::all_of(std::as_const(total_kills),
|
||||
[](char c) -> bool {return std::isdigit(c);})) {
|
||||
[](char c) -> bool {return std::isdigit(c);})) {
|
||||
Log.warn("total kills recognition failed, set to", m_pre_total_kills);
|
||||
cur_total_kills = m_pre_total_kills;
|
||||
}
|
||||
@@ -540,7 +540,7 @@ bool asst::BattleImageAnalyzer::cost_analyze()
|
||||
|
||||
if (cost_str.empty() ||
|
||||
!std::ranges::all_of(std::as_const(cost_str),
|
||||
[](char c) -> bool {return std::isdigit(c);})) {
|
||||
[](char c) -> bool {return std::isdigit(c);})) {
|
||||
return false;
|
||||
}
|
||||
m_cost = std::stoi(cost_str);
|
||||
|
||||
@@ -92,9 +92,9 @@ bool asst::CreditShopImageAnalyzer::whether_to_buy_analyze()
|
||||
|
||||
if (m_is_white_list) {
|
||||
std::ranges::sort(m_need_to_buy, [&](const auto& lhs, const auto& rhs) -> bool {
|
||||
return std::find(m_shopping_list.cbegin(), m_shopping_list.cend(), lhs.second)
|
||||
< std::find(m_shopping_list.cbegin(), m_shopping_list.cend(), rhs.second);
|
||||
});
|
||||
return std::find(m_shopping_list.cbegin(), m_shopping_list.cend(), lhs.second)
|
||||
< std::find(m_shopping_list.cbegin(), m_shopping_list.cend(), rhs.second);
|
||||
});
|
||||
}
|
||||
|
||||
return !m_need_to_buy.empty();
|
||||
|
||||
@@ -282,7 +282,7 @@ int asst::DepotImageAnalyzer::match_quantity(const Rect& roi)
|
||||
|
||||
if (digit_str.empty() ||
|
||||
!std::ranges::all_of(std::as_const(digit_str),
|
||||
[](char c) -> bool {return std::isdigit(c) || c == '.';})) {
|
||||
[](char c) -> bool {return std::isdigit(c) || c == '.';})) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,63 +4,63 @@
|
||||
|
||||
bool asst::InfrastOfficeTask::_run()
|
||||
{
|
||||
m_all_available_opers.clear();
|
||||
m_all_available_opers.clear();
|
||||
|
||||
// 办公室只能造这一个
|
||||
set_product("HR");
|
||||
// 办公室只能造这一个
|
||||
set_product("HR");
|
||||
|
||||
swipe_to_the_right_of_main_ui();
|
||||
enter_facility();
|
||||
click_bottom_left_tab();
|
||||
swipe_to_the_right_of_main_ui();
|
||||
enter_facility();
|
||||
click_bottom_left_tab();
|
||||
|
||||
for (int i = 0; i <= OperSelectRetryTimes; ++i) {
|
||||
if (need_exit()) {
|
||||
return false;
|
||||
}
|
||||
if (!opers_detect_with_swipe()) {
|
||||
return false;
|
||||
}
|
||||
swipe_to_the_left_of_operlist();
|
||||
for (int i = 0; i <= OperSelectRetryTimes; ++i) {
|
||||
if (need_exit()) {
|
||||
return false;
|
||||
}
|
||||
if (!opers_detect_with_swipe()) {
|
||||
return false;
|
||||
}
|
||||
swipe_to_the_left_of_operlist();
|
||||
|
||||
auto find_iter = std::ranges::find_if(m_all_available_opers
|
||||
auto find_iter = std::ranges::find_if(m_all_available_opers
|
||||
,
|
||||
[&](const infrast::Oper& info) -> bool {
|
||||
return info.selected;
|
||||
});
|
||||
|
||||
bool need_shift = true;
|
||||
if (find_iter != m_all_available_opers.end()) {
|
||||
switch (m_work_mode) {
|
||||
case infrast::WorkMode::Gentle:
|
||||
// 如果之前有干员在,那就不换人,直接退出
|
||||
m_all_available_opers.erase(find_iter);
|
||||
need_shift = false;
|
||||
break;
|
||||
case infrast::WorkMode::Aggressive:
|
||||
need_shift = true;
|
||||
// TODO,这里有个bug,全部干员中的selected,和当前的,不一定是同一个页面
|
||||
// 不过目前没影响,反正滑动到最前面了,selected的一定是在最前面
|
||||
//m_ctrler->click(find_iter->rect);
|
||||
//sleep(300);
|
||||
break;
|
||||
case infrast::WorkMode::Extreme: // TODO
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (need_shift) {
|
||||
optimal_calc();
|
||||
if (!opers_choose()) {
|
||||
m_all_available_opers.clear();
|
||||
swipe_to_the_left_of_operlist();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
click_confirm_button();
|
||||
click_return_button();
|
||||
bool need_shift = true;
|
||||
if (find_iter != m_all_available_opers.end()) {
|
||||
switch (m_work_mode) {
|
||||
case infrast::WorkMode::Gentle:
|
||||
// 如果之前有干员在,那就不换人,直接退出
|
||||
m_all_available_opers.erase(find_iter);
|
||||
need_shift = false;
|
||||
break;
|
||||
case infrast::WorkMode::Aggressive:
|
||||
need_shift = true;
|
||||
// TODO,这里有个bug,全部干员中的selected,和当前的,不一定是同一个页面
|
||||
// 不过目前没影响,反正滑动到最前面了,selected的一定是在最前面
|
||||
//m_ctrler->click(find_iter->rect);
|
||||
//sleep(300);
|
||||
break;
|
||||
case infrast::WorkMode::Extreme: // TODO
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (need_shift) {
|
||||
optimal_calc();
|
||||
if (!opers_choose()) {
|
||||
m_all_available_opers.clear();
|
||||
swipe_to_the_left_of_operlist();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
click_confirm_button();
|
||||
click_return_button();
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -206,17 +206,16 @@ size_t asst::InfrastProductionTask::opers_detect()
|
||||
//--cur_available_num;
|
||||
continue;
|
||||
}
|
||||
auto find_iter = std::ranges::find_if(std::as_const(m_all_available_opers)
|
||||
,
|
||||
[&](const infrast::Oper& oper) -> bool {
|
||||
if (oper.skills != cur_oper.skills) {
|
||||
return false;
|
||||
}
|
||||
// 有可能是同一个干员,比一下hash
|
||||
int dist = HashImageAnalyzer::hamming(cur_oper.face_hash, oper.face_hash);
|
||||
Log.debug("opers_detect hash dist |", dist);
|
||||
return dist < face_hash_thres;
|
||||
});
|
||||
auto find_iter = std::ranges::find_if(std::as_const(m_all_available_opers),
|
||||
[&](const infrast::Oper& oper) -> bool {
|
||||
if (oper.skills != cur_oper.skills) {
|
||||
return false;
|
||||
}
|
||||
// 有可能是同一个干员,比一下hash
|
||||
int dist = HashImageAnalyzer::hamming(cur_oper.face_hash, oper.face_hash);
|
||||
Log.debug("opers_detect hash dist |", dist);
|
||||
return dist < face_hash_thres;
|
||||
});
|
||||
// 如果两个的hash距离过小,则认为是同一个干员,不进行插入
|
||||
if (find_iter != m_all_available_opers.cend()) {
|
||||
continue;
|
||||
@@ -363,7 +362,7 @@ bool asst::InfrastProductionTask::optimal_calc()
|
||||
std::ranges::sort(optional,
|
||||
[&](const infrast::SkillsComb& lhs,
|
||||
const infrast::SkillsComb& rhs) -> bool {
|
||||
return lhs.efficient.at(m_product) > rhs.efficient.at(m_product);
|
||||
return lhs.efficient.at(m_product) > rhs.efficient.at(m_product);
|
||||
});
|
||||
|
||||
// 可能有多个干员有同样的技能,所以这里需要循环找同一个技能,直到找不到为止
|
||||
@@ -497,36 +496,33 @@ bool asst::InfrastProductionTask::opers_choose()
|
||||
Log.trace("before mood filter, opers size:", cur_all_opers.size());
|
||||
// 小于心情阈值的干员则不可用
|
||||
auto remove_iter = std::ranges::remove_if(cur_all_opers,
|
||||
[&](const infrast::Oper& rhs) -> bool {
|
||||
return rhs.mood_ratio < m_mood_threshold;
|
||||
}).begin();
|
||||
[&](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 = std::ranges::find_if(std::as_const(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<OcrTaskInfo>("CharsNameOcrReplace")->replace_map);
|
||||
Log.trace("Analyze name filter");
|
||||
if (!name_analyzer.analyze()) {
|
||||
return false;
|
||||
}
|
||||
std::string name = name_analyzer.get_result().front().text;
|
||||
return std::ranges::find(std::as_const(opt_iter->name_filter)
|
||||
, name)
|
||||
!= opt_iter->name_filter.cend();
|
||||
}
|
||||
});
|
||||
auto find_iter = std::ranges::find_if(std::as_const(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<OcrTaskInfo>("CharsNameOcrReplace")->replace_map);
|
||||
Log.trace("Analyze name filter");
|
||||
if (!name_analyzer.analyze()) {
|
||||
return false;
|
||||
}
|
||||
std::string name = name_analyzer.get_result().front().text;
|
||||
return std::ranges::find(std::as_const(opt_iter->name_filter), name) != opt_iter->name_filter.cend();
|
||||
}
|
||||
});
|
||||
|
||||
if (find_iter == cur_all_opers.cend()) {
|
||||
++opt_iter;
|
||||
@@ -547,13 +543,12 @@ bool asst::InfrastProductionTask::opers_choose()
|
||||
m_ctrler->click(find_iter->rect);
|
||||
}
|
||||
{
|
||||
auto avlb_iter = std::ranges::find_if(std::as_const(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;
|
||||
}
|
||||
auto avlb_iter = std::ranges::find_if(std::as_const(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);
|
||||
|
||||
@@ -23,7 +23,8 @@ namespace asst
|
||||
bool hidden = false;
|
||||
std::string name_en;
|
||||
|
||||
bool has_tag(const std::string &tag) const {
|
||||
bool has_tag(const std::string& tag) const
|
||||
{
|
||||
return tags.contains(tag);
|
||||
}
|
||||
|
||||
@@ -49,7 +50,8 @@ namespace asst
|
||||
int min_level = 0;
|
||||
double avg_level = 0;
|
||||
|
||||
void update_attributes() {
|
||||
void update_attributes()
|
||||
{
|
||||
min_level = std::transform_reduce(
|
||||
opers.cbegin(), opers.cend(), 7,
|
||||
[](int a, int b) -> int { return (std::min)(a, b); },
|
||||
@@ -76,10 +78,10 @@ namespace asst
|
||||
|
||||
RecruitCombs result;
|
||||
|
||||
std::ranges::set_union(std::as_const(lhs.tags), std::as_const(rhs.tags) ,
|
||||
std::ranges::set_union(std::as_const(lhs.tags), std::as_const(rhs.tags),
|
||||
std::back_inserter(result.tags));
|
||||
|
||||
std::ranges::set_intersection(std::as_const(lhs.opers), std::as_const(rhs.opers) ,
|
||||
std::ranges::set_intersection(std::as_const(lhs.opers), std::as_const(rhs.opers),
|
||||
std::back_inserter(result.opers));
|
||||
|
||||
result.update_attributes();
|
||||
|
||||
@@ -37,7 +37,7 @@ bool asst::RoguelikeRecruitImageAnalyzer::analyze()
|
||||
Log.info(__FUNCTION__, name, elite, level, rect.to_string());
|
||||
m_result.emplace_back(std::move(info));
|
||||
}
|
||||
|
||||
|
||||
auto first_un_req = std::ranges::find_if(m_result,
|
||||
[&](const auto& info) -> bool {
|
||||
return info.required == false;
|
||||
@@ -101,7 +101,7 @@ int asst::RoguelikeRecruitImageAnalyzer::match_level(const Rect& raw_roi)
|
||||
|
||||
const std::string& level = analyzer.get_result().front().text;
|
||||
if (level.empty() || !std::ranges::all_of(level,
|
||||
[](char c) -> bool {return std::isdigit(c);})) {
|
||||
[](char c) -> bool {return std::isdigit(c);})) {
|
||||
return 0;
|
||||
}
|
||||
return std::stoi(level);
|
||||
|
||||
@@ -560,7 +560,7 @@ int asst::StageDropsImageAnalyzer::match_quantity(const Rect& roi)
|
||||
|
||||
if (digit_str.empty() ||
|
||||
!std::ranges::all_of(std::as_const(digit_str),
|
||||
[](char c) -> bool {return std::isdigit(c) || c == '.';})) {
|
||||
[](char c) -> bool {return std::isdigit(c) || c == '.';})) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user