feat: 支持暂停部署干员

This commit is contained in:
MistEO
2022-12-02 22:42:47 +08:00
parent ed07d46003
commit dc48ff8028
8 changed files with 75 additions and 31 deletions

View File

@@ -12,7 +12,7 @@
"adbExtraSwipeDist_Doc": "额外的滑动距离adb有bug同样的参数偶尔会划得非常远。额外做一个短程滑动把之前的停下来",
"adbExtraSwipeDuration": 500,
"adbExtraSwipeDuration_Doc": "额外的滑动持续时间adb有bug同样的参数偶尔会划得非常远。额外做一个短程滑动把之前的停下来。若小于0则关闭额外滑动功能",
"adbSwipeDurationMultiplier": 15.0,
"adbSwipeDurationMultiplier": 10.0,
"adbSwipeDurationMultiplier_Doc": "adb 滑动延迟倍数",
"minitouchExtraSwipeDist": 100,
"minitouchExtraSwipeDuration": 200,
@@ -24,6 +24,8 @@
"armeabi",
"maatouch"
],
"swipeWithPauseRequiredDistance": 50,
"swipeWithPauseRequiredDistance_Doc": "暂停下干员滑动多远距离后开始按暂停",
"penguinReport": {
"Doc": "企鹅物流汇报: https://penguin-stats.cn/",
"cmdFormat": "curl -H \"Content-Type: application/json\" -s -S -m 10 -i -d \"[body]\" \"https://penguin-stats.io/PenguinStats/api/v2/report\" --ssl-no-revoke [extra]",
@@ -56,6 +58,7 @@
"uuid": "[Adb] -s [AdbSerial] shell settings get secure android_id",
"click": "[Adb] -s [AdbSerial] shell input tap [x] [y]",
"swipe": "[Adb] -s [AdbSerial] shell input swipe [x1] [y1] [x2] [y2] [duration]",
"pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111",
"display": "[Adb] -s [AdbSerial] shell dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+",
"displayFormat": "%d%d",
"screencapRawByNC": "[Adb] -s [AdbSerial] exec-out \"screencap | nc -w 3 [NcAddress] [NcPort]\"",
@@ -79,6 +82,7 @@
"uuid": "[Adb] -s [AdbSerial] shell settings get secure android_id",
"click": "[Adb] -s [AdbSerial] shell input tap [x] [y]",
"swipe": "[Adb] -s [AdbSerial] shell input swipe [x1] [y1] [x2] [y2] [duration]",
"pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111",
"display": "[Adb] -s [AdbSerial] shell dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+",
"displayFormat": "%d%d",
"screencapRawByNC": "[Adb] -s [AdbSerial] exec-out \"screencap | nc -w 3 [NcAddress] [NcPort]\"",
@@ -102,6 +106,7 @@
"uuid": "[Adb] -s [AdbSerial] shell settings get secure android_id",
"click": "[Adb] -s [AdbSerial] shell input tap [x] [y]",
"swipe": "[Adb] -s [AdbSerial] shell input swipe [x1] [y1] [x2] [y2] [duration]",
"pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111",
"display": "[Adb] -s [AdbSerial] shell dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+",
"displayFormat": "%d%d",
"screencapRawByNC": "[Adb] -s [AdbSerial] exec-out \"screencap | nc -w 3 [NcAddress] [NcPort]\"",
@@ -125,6 +130,7 @@
"uuid": "[Adb] -s [AdbSerial] shell settings get secure android_id",
"click": "[Adb] -s [AdbSerial] shell input tap [x] [y]",
"swipe": "[Adb] -s [AdbSerial] shell input swipe [x1] [y1] [x2] [y2] [duration]",
"pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111",
"display": "[Adb] -s [AdbSerial] shell dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+",
"displayFormat": "%d%d",
"screencapRawByNC": "[Adb] -s [AdbSerial] shell \"screencap | nc -w 3 [NcAddress] [NcPort]\"",
@@ -148,6 +154,8 @@
"uuid": "[Adb] -s [AdbSerial] shell settings get secure android_id",
"click": "[Adb] -s [AdbSerial] shell input tap [x] [y]",
"swipe": "[Adb] -s [AdbSerial] shell input swipe [x1] [y1] [x2] [y2] [duration]",
"pressEsc": "",
"pressEsc_Doc": "据群友反馈,夜神不支持暂停部署",
"display": "[Adb] -s [AdbSerial] shell dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+",
"displayFormat": "%d%d",
"screencapRawByNC": "[Adb] -s [AdbSerial] exec-out \"screencap | nc -w 3 [NcAddress] [NcPort]\"",
@@ -171,6 +179,7 @@
"uuid": "[Adb] -s [AdbSerial] shell settings get secure android_id",
"click": "[Adb] -s [AdbSerial] shell input tap [x] [y]",
"swipe": "[Adb] -s [AdbSerial] shell input swipe [x1] [y1] [x2] [y2] [duration]",
"pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111",
"display": "[Adb] -s [AdbSerial] shell dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+",
"displayFormat": "%d%d",
"screencapRawByNC": "[Adb] -s [AdbSerial] exec-out \"screencap | nc -w 3 [NcAddress] [NcPort]\"",
@@ -195,6 +204,7 @@
"uuid": "[Adb] -s [AdbSerial] shell settings get secure android_id",
"click": "[Adb] -s [AdbSerial] shell input -d [DisplayId] tap [x] [y]",
"swipe": "[Adb] -s [AdbSerial] shell input -d [DisplayId] swipe [x1] [y1] [x2] [y2] [duration]",
"pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111",
"display": "[Adb] -s [AdbSerial] shell \"wm size -d [DisplayId] | grep -o -E [0-9]+\"",
"displayFormat": "%d%d",
"screencapRawByNC": "[Adb] -s [AdbSerial] exec-out \"screencap | nc -w 3 [NcAddress] [NcPort]\"",
@@ -218,6 +228,7 @@
"uuid": "[Adb] -s [AdbSerial] shell echo 111111",
"click": "[Adb] -s [AdbSerial] shell input tap [x] [y]",
"swipe": "[Adb] -s [AdbSerial] shell input swipe [x1] [y1] [x2] [y2] [duration]",
"pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111",
"display": "[Adb] -s [AdbSerial] shell dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+",
"displayFormat": "%d%d",
"screencapRawByNC": "[Adb] -s [AdbSerial] exec-out \"screencap | nc -w 3 [NcAddress] [NcPort]\"",
@@ -241,6 +252,7 @@
"uuid": "[Adb] -s [AdbSerial] shell echo 111111",
"click": "[Adb] -s [AdbSerial] shell input tap [x] [y]",
"swipe": "[Adb] -s [AdbSerial] shell input swipe [x1] [y1] [x2] [y2] [duration]",
"pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111",
"display": "[Adb] -s [AdbSerial] shell dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+",
"displayFormat": "%d%d",
"screencapRawByNC": "[Adb] -s [AdbSerial] exec-out \"screencap | nc -w 3 [NcAddress] [NcPort]\"",
@@ -264,6 +276,7 @@
"uuid": "[Adb] -s [AdbSerial] shell settings get secure android_id",
"click": "[Adb] -s [AdbSerial] shell input tap [x] [y]",
"swipe": "[Adb] -s [AdbSerial] shell input swipe [x1] [y1] [x2] [y2] [duration]",
"pressEsc": "[Adb] -s [AdbSerial] shell input keyevent 111",
"display": "[Adb] -s [AdbSerial] shell dumpsys window displays | grep -o -E cur=+[^\\ ]+ | grep -o -E [0-9]+",
"displayFormat": "%d%d",
"screencapRawByNC": "[Adb] -s [AdbSerial] exec-out \"screencap | nc -w 3 [NcAddress] [NcPort]\"",

View File

@@ -6362,14 +6362,14 @@
},
"BattleUseOper": {
"algorithm": "JustReturn",
"preDelay": 100,
"postDelay": 150,
"preDelay": 200,
"postDelay": 300,
"Doc": "pre 是从点击干员到干员信息弹出来等待的时间post 是干员上场,到设置朝向之间等待的时间"
},
"BattleSwipeOper": {
"algorithm": "JustReturn",
"preDelay": 200,
"postDelay": 80,
"preDelay": 500,
"postDelay": 150,
"Doc": "pre 是将干员滑动到场上的 duration 系数post 是设置干员朝向滑动的 duration",
"specialParams": [
300,
@@ -7064,7 +7064,7 @@
"InfrastOperListSlowlySwipeToTheRight": {
"baseTask": "SlowlySwipeToTheRight",
"specificRect": [
1150,
1000,
350,
20,
20

View File

@@ -43,6 +43,7 @@ bool asst::GeneralConfig::parse(const json::value& json)
adb.uuid = cfg_json.at("uuid").as_string();
adb.click = cfg_json.at("click").as_string();
adb.swipe = cfg_json.at("swipe").as_string();
adb.press_esc = cfg_json.get("pressEsc", std::string());
adb.display = cfg_json.at("display").as_string();
adb.display_format = cfg_json.at("displayFormat").as_string();
adb.screencap_raw_with_gzip = cfg_json.at("screencapRawWithGzip").as_string();

View File

@@ -42,6 +42,7 @@ namespace asst
double adb_swipe_duration_multiplier = 0; // adb 滑动持续时间倍数
int minitouch_extra_swipe_dist = 0;
int minitouch_extra_swipe_duration = -1;
int swipe_with_pause_required_distance = 0;
std::vector<std::string> minitouch_programs_order;
PenguinReportCfg penguin_report; // 企鹅物流汇报:
// 每次到结算界面,汇报掉落数据至企鹅物流 https://penguin-stats.cn/
@@ -62,6 +63,7 @@ namespace asst
std::string uuid;
std::string click;
std::string swipe;
std::string press_esc;
std::string display;
std::string screencap_raw_with_gzip;
std::string screencap_raw_by_nc;

View File

@@ -1129,7 +1129,7 @@ bool asst::Controller::click_without_scale(const Rect& rect)
}
bool asst::Controller::swipe(const Point& p1, const Point& p2, int duration, bool extra_swipe, double slope_in,
double slope_out)
double slope_out, bool with_pause)
{
int x1 = static_cast<int>(p1.x * m_control_scale);
int y1 = static_cast<int>(p1.y * m_control_scale);
@@ -1137,17 +1137,18 @@ bool asst::Controller::swipe(const Point& p1, const Point& p2, int duration, boo
int y2 = static_cast<int>(p2.y * m_control_scale);
// log.trace("Swipe, raw:", p1.x, p1.y, p2.x, p2.y, "corr:", x1, y1, x2, y2);
return swipe_without_scale(Point(x1, y1), Point(x2, y2), duration, extra_swipe, slope_in, slope_out);
return swipe_without_scale(Point(x1, y1), Point(x2, y2), duration, extra_swipe, slope_in, slope_out, with_pause);
}
bool asst::Controller::swipe(const Rect& r1, const Rect& r2, int duration, bool extra_swipe, double slope_in,
double slope_out)
double slope_out, bool with_pause)
{
return swipe(rand_point_in_rect(r1), rand_point_in_rect(r2), duration, extra_swipe, slope_in, slope_out);
return swipe(rand_point_in_rect(r1), rand_point_in_rect(r2), duration, extra_swipe, slope_in, slope_out,
with_pause);
}
bool asst::Controller::swipe_without_scale(const Point& p1, const Point& p2, int duration, bool extra_swipe,
double slope_in, double slope_out)
double slope_in, double slope_out, bool with_pause)
{
int x1 = p1.x, y1 = p1.y;
int x2 = p2.x, y2 = p2.y;
@@ -1164,9 +1165,6 @@ bool asst::Controller::swipe_without_scale(const Point& p1, const Point& p2, int
Log.info("minitouch swipe", p1, p2, duration, extra_swipe, slope_in, slope_out);
Minitoucher toucher(std::bind(&Controller::input_to_minitouch, this, std::placeholders::_1), m_minitouch_props);
toucher.down(x1, y1);
if (duration == 0) {
duration = 150;
}
constexpr int TimeInterval = Minitoucher::DefaultSwipeDelay;
@@ -1177,11 +1175,18 @@ bool asst::Controller::swipe_without_scale(const Point& p1, const Point& p2, int
return a * t + b * std::pow(t, 2) + c * std::pow(t, 3);
}; // TODO: move this to math.hpp
bool need_pause = with_pause && support_swipe_with_pause();
std::future<void> pause_future;
auto minitouch_move = [&](int _x1, int _y1, int _x2, int _y2, int _duration) {
for (int cur_time = TimeInterval; cur_time < _duration; cur_time += TimeInterval) {
double progress = cubic_spline(slope_in, slope_out, static_cast<double>(cur_time) / duration);
int cur_x = static_cast<int>(std::lerp(_x1, _x2, progress));
int cur_y = static_cast<int>(std::lerp(_y1, _y2, progress));
if (need_pause && std::sqrt(std::pow(cur_x - _x1, 2) + std::pow(cur_y - _y1, 2)) >
opt.swipe_with_pause_required_distance) {
need_pause = false;
pause_future = std::async(std::launch::async, [&]() { press_esc(); });
}
if (cur_x < 0 || cur_x > m_minitouch_props.max_x || cur_y < 0 || cur_y > m_minitouch_props.max_y) {
continue;
}
@@ -1191,13 +1196,14 @@ bool asst::Controller::swipe_without_scale(const Point& p1, const Point& p2, int
toucher.move(_x2, _y2);
}
};
minitouch_move(x1, y1, x2, y2, duration);
constexpr int DefaultDuration = 200;
minitouch_move(x1, y1, x2, y2, duration ? duration : DefaultDuration);
if (extra_swipe && opt.minitouch_extra_swipe_duration > 0) {
constexpr int ExtraEndDelay = 100; // 停留终点
toucher.wait(ExtraEndDelay);
minitouch_move(x2, y2, x2, y2 - opt.minitouch_extra_swipe_dist, opt.minitouch_extra_swipe_duration);
duration += opt.minitouch_extra_swipe_duration;
}
return toucher.up();
}
@@ -1230,9 +1236,22 @@ bool asst::Controller::swipe_without_scale(const Point& p1, const Point& p2, int
}
bool asst::Controller::swipe_without_scale(const Rect& r1, const Rect& r2, int duration, bool extra_swipe, double v0,
double v1)
double v1, bool with_pause)
{
return swipe_without_scale(rand_point_in_rect(r1), rand_point_in_rect(r2), duration, extra_swipe, v0, v1);
return swipe_without_scale(rand_point_in_rect(r1), rand_point_in_rect(r2), duration, extra_swipe, v0, v1,
with_pause);
}
bool asst::Controller::press_esc()
{
LogTraceFunction;
return call_command(m_adb.press_esc).has_value();
}
bool asst::Controller::support_swipe_with_pause() const noexcept
{
return m_minitouch_enabled && m_minitouch_avaiable && !m_adb.swipe.empty();
}
bool asst::Controller::connect(const std::string& adb_path, const std::string& address, const std::string& config)
@@ -1460,6 +1479,7 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a
m_adb.click = cmd_replace(adb_cfg.click);
m_adb.swipe = cmd_replace(adb_cfg.swipe);
m_adb.press_esc = cmd_replace(adb_cfg.press_esc);
m_adb.screencap_raw_with_gzip = cmd_replace(adb_cfg.screencap_raw_with_gzip);
m_adb.screencap_encode = cmd_replace(adb_cfg.screencap_encode);
m_adb_release = m_adb.release = cmd_replace(adb_cfg.release);

View File

@@ -52,13 +52,16 @@ namespace asst
bool click_without_scale(const Rect& rect);
bool swipe(const Point& p1, const Point& p2, int duration = 0, bool extra_swipe = false, double slope_in = 1,
double slope_out = 1);
double slope_out = 1, bool with_pause = false);
bool swipe(const Rect& r1, const Rect& r2, int duration = 0, bool extra_swipe = false, double slope_in = 1,
double slope_out = 1);
double slope_out = 1, bool with_pause = false);
bool swipe_without_scale(const Point& p1, const Point& p2, int duration = 0, bool extra_swipe = false,
double slope_in = 1, double slope_out = 1);
double slope_in = 1, double slope_out = 1, bool with_pause = false);
bool swipe_without_scale(const Rect& r1, const Rect& r2, int duration = 0, bool extra_swipe = false,
double slope_in = 1, double slope_out = 1);
double slope_in = 1, double slope_out = 1, bool with_pause = false);
bool press_esc();
bool support_swipe_with_pause() const noexcept;
std::pair<int, int> get_scale_size() const noexcept;
@@ -127,6 +130,7 @@ namespace asst
std::string call_minitouch;
std::string click;
std::string swipe;
std::string press_esc;
std::string screencap_raw_by_nc;
std::string screencap_raw_with_gzip;

View File

@@ -527,11 +527,6 @@ bool asst::BattleProcessTask::oper_deploy(const BattleAction& action, bool only_
auto iter = m_cur_opers_info.find(oper_info.name);
Rect oper_rect = iter->second.rect;
if (!m_in_bullet_time) {
// 点击干员
ctrler()->click(oper_rect);
sleep(use_oper_task_ptr->pre_delay);
}
if (only_pre_process) {
return true;
}
@@ -543,9 +538,10 @@ bool asst::BattleProcessTask::oper_deploy(const BattleAction& action, bool only_
int dist = static_cast<int>(
Point::distance(placed_point, { oper_rect.x + oper_rect.width / 2, oper_rect.y + oper_rect.height / 2 }));
// 1000 是随便取的一个系数,把整数的 pre_delay 转成小数用的
int duration = static_cast<int>(dist / 800.0 * swipe_oper_task_ptr->pre_delay);
int duration = static_cast<int>(dist / 1000.0 * swipe_oper_task_ptr->pre_delay);
bool deploy_with_pause = ctrler()->support_swipe_with_pause();
ctrler()->swipe(oper_rect, placed_rect, duration, false, swipe_oper_task_ptr->special_params.at(1),
swipe_oper_task_ptr->special_params.at(2));
swipe_oper_task_ptr->special_params.at(2), deploy_with_pause);
sleep(use_oper_task_ptr->post_delay);
@@ -568,6 +564,10 @@ bool asst::BattleProcessTask::oper_deploy(const BattleAction& action, bool only_
sleep(use_oper_task_ptr->post_delay);
}
if (deploy_with_pause) {
ctrler()->press_esc();
}
m_used_opers[iter->first] =
BattleDeployInfo { action.location, m_normal_tile_info[action.location].pos, oper_info };

View File

@@ -721,9 +721,10 @@ bool asst::RoguelikeBattleTaskPlugin::auto_battle()
int dist = static_cast<int>(Point::distance(
placed_point, { opt_oper.rect.x + opt_oper.rect.width / 2, opt_oper.rect.y + opt_oper.rect.height / 2 }));
// 1000 是随便取的一个系数,把整数的 pre_delay 转成小数用的
int duration = static_cast<int>(dist / 800.0 * swipe_oper_task_ptr->pre_delay);
int duration = static_cast<int>(dist / 1000.0 * swipe_oper_task_ptr->pre_delay);
bool deploy_with_pause = ctrler()->support_swipe_with_pause();
ctrler()->swipe(opt_oper.rect, placed_rect, duration, false, swipe_oper_task_ptr->special_params.at(1),
swipe_oper_task_ptr->special_params.at(2));
swipe_oper_task_ptr->special_params.at(2), deploy_with_pause);
sleep(use_oper_task_ptr->post_delay);
// 将方向转换为实际的 swipe end 坐标点
@@ -744,6 +745,9 @@ bool asst::RoguelikeBattleTaskPlugin::auto_battle()
m_need_clear_tiles.emplace(now_time + std::chrono::seconds(35), placed_loc);
}
}
if (deploy_with_pause) {
ctrler()->press_esc();
}
Log.info("Try to deploy oper", opt_oper.name);
m_opers_used = true;