Merge pull request #3812 from MaaAssistantArknights/feat/rogue_recruit

feat: 加速肉鸽招募时滑动
This commit is contained in:
MistEO
2023-02-25 15:53:25 +08:00
committed by GitHub
5 changed files with 36 additions and 15 deletions

View File

@@ -9091,13 +9091,13 @@
"baseTask": "SlowlySwipeToTheLeft",
"Doc": "为了保证每次滑动至少多出一列 且 不能跳过一列应保证滑动距离在400-500之间。",
"specificRect": [
620,
500,
340,
20,
20
],
"rectMove": [
1100,
980,
340,
20,
20
@@ -9106,13 +9106,13 @@
"RoguelikeRecruitOperListSlowlySwipeToTheRight": {
"baseTask": "SlowlySwipeToTheRight",
"specificRect": [
1100,
1150,
340,
20,
20
],
"rectMove": [
620,
670,
340,
20,
20
@@ -9144,7 +9144,7 @@
"RoguelikeRecruitSwipeMaxTime": {
"algorithm": "JustReturn",
"maxTimes_Doc": "这个参数是肉鸽招募时,向右划动的最大次数",
"maxTimes": 4
"maxTimes": 5
},
"RoguelikeSkillSelectionFlag": {
"templThreshold": 0.9,

View File

@@ -896,6 +896,11 @@ bool asst::Controller::support_swipe_with_pause() const noexcept
return m_minitouch_enabled && m_minitouch_available && m_swipe_with_pause_enabled && !m_adb.press_esc.empty();
}
bool asst::Controller::support_precise_swipe() const noexcept
{
return m_minitouch_enabled && m_minitouch_available;
}
bool asst::Controller::connect(const std::string& adb_path, const std::string& address, const std::string& config)
{
LogTraceFunction;

View File

@@ -65,6 +65,7 @@ namespace asst
bool press_esc();
bool support_swipe_with_pause() const noexcept;
bool support_precise_swipe() const noexcept;
std::pair<int, int> get_scale_size() const noexcept;

View File

@@ -124,9 +124,11 @@ bool asst::RoguelikeRecruitTaskPlugin::_run()
const auto& oper_list = analyzer.get_result();
bool stop_swipe = false;
int max_oper_x = 0;
for (const auto& oper_info : oper_list) {
oper_names.emplace(oper_info.name);
max_oper_x = std::max(max_oper_x, oper_info.rect.x);
// 查询上次识别位置
const auto& rect_it = last_oper_rects.find(oper_info.name);
if (rect_it == last_oper_rects.cend()) {
@@ -251,7 +253,7 @@ bool asst::RoguelikeRecruitTaskPlugin::_run()
// 向右滑动
Log.trace(__FUNCTION__, "| Page", i, "oper count:", oper_count, "- continue swiping");
slowly_swipe(false);
slowly_swipe(false, max_oper_x - 200);
sleep(Task.get("RoguelikeCustom-HijackCoChar")->post_delay);
}
@@ -329,7 +331,7 @@ bool asst::RoguelikeRecruitTaskPlugin::check_char(const std::string& char_name,
{
LogTraceFunction;
constexpr int SwipeTimes = 5;
int SwipeTimes = Task.get("RoguelikeRecruitSwipeMaxTime")->max_times;
std::unordered_set<std::string> pre_oper_names;
bool has_been_same = false;
int i = 0;
@@ -341,8 +343,10 @@ bool asst::RoguelikeRecruitTaskPlugin::check_char(const std::string& char_name,
RoguelikeRecruitImageAnalyzer analyzer(image);
// 只处理识别成功的情况,失败(无任何结果)时继续滑动
int max_oper_x = 700;
if (analyzer.analyze()) {
const auto& chars = analyzer.get_result();
max_oper_x = ranges::max(chars | views::transform([&](const auto& x) { return x.rect.x; }));
auto it = ranges::find_if(
chars, [&](const battle::roguelike::Recruitment& oper) -> bool { return oper.name == char_name; });
@@ -375,7 +379,7 @@ bool asst::RoguelikeRecruitTaskPlugin::check_char(const std::string& char_name,
slowly_swipe(true);
}
else {
slowly_swipe(false);
slowly_swipe(false, max_oper_x - 200);
}
sleep(Task.get("RoguelikeCustom-HijackCoChar")->post_delay);
}
@@ -513,12 +517,23 @@ void asst::RoguelikeRecruitTaskPlugin::swipe_to_the_left_of_operlist(int loop_ti
ProcessTask(*this, { "SleepAfterOperListQuickSwipe" }).run();
}
void asst::RoguelikeRecruitTaskPlugin::slowly_swipe(bool to_left)
void asst::RoguelikeRecruitTaskPlugin::slowly_swipe(bool to_left, int swipe_dist)
{
if (to_left) {
ProcessTask(*this, { "RoguelikeRecruitOperListSlowlySwipeToTheLeft" }).run();
}
else {
ProcessTask(*this, { "RoguelikeRecruitOperListSlowlySwipeToTheRight" }).run();
std::string swipe_task_name =
to_left ? "RoguelikeRecruitOperListSlowlySwipeToTheLeft" : "RoguelikeRecruitOperListSlowlySwipeToTheRight";
if (!ctrler()->support_precise_swipe()) { // 不能精准滑动时不使用 swipe_dist 参数
ProcessTask(*this, { swipe_task_name }).run();
return;
}
if (!to_left) swipe_dist = -swipe_dist;
auto swipe_task = Task.get(swipe_task_name);
const Rect& StartPoint = swipe_task->specific_rect;
ctrler()->swipe(StartPoint,
{ StartPoint.x + swipe_dist - StartPoint.width, StartPoint.y, StartPoint.width, StartPoint.height },
swipe_task->special_params.empty() ? 0 : swipe_task->special_params.at(0),
(swipe_task->special_params.size() < 2) ? false : swipe_task->special_params.at(1),
(swipe_task->special_params.size() < 3) ? 1 : swipe_task->special_params.at(2),
(swipe_task->special_params.size() < 4) ? 1 : swipe_task->special_params.at(3));
sleep(swipe_task->post_delay);
}

View File

@@ -26,7 +26,7 @@ namespace asst
// 滑动到干员列表的最左侧
void swipe_to_the_left_of_operlist(int loop_times = 2);
// 缓慢向干员列表的左侧/右侧滑动
void slowly_swipe(bool to_left);
void slowly_swipe(bool to_left, int swipe_dist = 500);
private:
bool check_support_char();