From 3fa6fd63409a1663e81677f5b8ec1617c1524ee4 Mon Sep 17 00:00:00 2001 From: MistEO Date: Sun, 21 May 2023 01:19:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=A8=E5=B1=80=E5=87=8F=E5=B0=8Fadb?= =?UTF-8?q?=E6=BB=91=E5=8A=A8=E8=B7=9D=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 糊屎! --- resource/config.json | 4 +++- src/MaaCore/Config/GeneralConfig.cpp | 1 + src/MaaCore/Config/GeneralConfig.h | 3 ++- src/MaaCore/Controller/ControlScaleProxy.cpp | 21 ++++++++++++++++---- src/MaaCore/Controller/ControlScaleProxy.h | 4 +++- src/MaaCore/Controller/Controller.cpp | 2 +- src/MaaCore/Task/BattleHelper.cpp | 6 +++--- 7 files changed, 30 insertions(+), 11 deletions(-) diff --git a/resource/config.json b/resource/config.json index e68b1e39df..4672ee7a0e 100644 --- a/resource/config.json +++ b/resource/config.json @@ -14,6 +14,8 @@ "adbExtraSwipeDuration_Doc": "额外的滑动持续时间:adb有bug,同样的参数,偶尔会划得非常远。额外做一个短程滑动,把之前的停下来。若小于0,则关闭额外滑动功能", "adbSwipeDurationMultiplier": 10.0, "adbSwipeDurationMultiplier_Doc": "adb 滑动延迟倍数", + "adbSwipeXDistanceMultiplier": 0.8, + "adbSwipeXDistanceMultiplier_Doc": "adb 滑动 X 距离倍数", "minitouchSwipeDefaultDuration": 200, "minitouchSwipeExtraEndDelay": 150, "minitouchExtraSwipeDist": 100, @@ -146,4 +148,4 @@ "screencapEncode": "[Adb] -s [AdbSerial] exec-out \"screencap -p 2>/tmp/maa-assistant-arknights.log\"" } ] -} \ No newline at end of file +} diff --git a/src/MaaCore/Config/GeneralConfig.cpp b/src/MaaCore/Config/GeneralConfig.cpp index f2b896d854..3d8ec6687f 100644 --- a/src/MaaCore/Config/GeneralConfig.cpp +++ b/src/MaaCore/Config/GeneralConfig.cpp @@ -18,6 +18,7 @@ bool asst::GeneralConfig::parse(const json::value& json) m_options.adb_extra_swipe_dist = options_json.get("adbExtraSwipeDist", 100); m_options.adb_extra_swipe_duration = options_json.get("adbExtraSwipeDuration", -1); m_options.adb_swipe_duration_multiplier = options_json.get("adbSwipeDurationMultiplier", 10.0); + m_options.adb_swipe_x_distance_multiplier = options_json.get("adbSwipeXDistanceMultiplier", 10.0); m_options.minitouch_extra_swipe_dist = options_json.get("minitouchExtraSwipeDist", 100); m_options.minitouch_extra_swipe_duration = options_json.get("minitouchExtraSwipeDuration", -1); m_options.minitouch_swipe_default_duration = options_json.get("minitouchSwipeDefaultDuration", 200); diff --git a/src/MaaCore/Config/GeneralConfig.h b/src/MaaCore/Config/GeneralConfig.h index ad43d9a189..9121613cab 100644 --- a/src/MaaCore/Config/GeneralConfig.h +++ b/src/MaaCore/Config/GeneralConfig.h @@ -36,7 +36,8 @@ namespace asst // adb有bug,同样的参数,偶尔会划得非常远。 // 额外做一个短程滑动,把之前的停下来。 // 若小于0,则关闭额外滑动功能。 - double adb_swipe_duration_multiplier = 0; // adb 滑动持续时间倍数 + double adb_swipe_duration_multiplier = 0; // adb 滑动持续时间倍数 + double adb_swipe_x_distance_multiplier = 0; // adb 滑动距离倍数 int minitouch_extra_swipe_dist = 0; int minitouch_extra_swipe_duration = -1; int minitouch_swipe_default_duration = 0; diff --git a/src/MaaCore/Controller/ControlScaleProxy.cpp b/src/MaaCore/Controller/ControlScaleProxy.cpp index 11c8ce250d..1b94c1e43b 100644 --- a/src/MaaCore/Controller/ControlScaleProxy.cpp +++ b/src/MaaCore/Controller/ControlScaleProxy.cpp @@ -1,7 +1,11 @@ #include "ControlScaleProxy.h" -asst::ControlScaleProxy::ControlScaleProxy(std::shared_ptr controller, ProxyCallback proxy_callback) - : m_controller(controller), m_callback(proxy_callback), m_rand_engine(std::random_device {}()) +#include "Config/GeneralConfig.h" + +asst::ControlScaleProxy::ControlScaleProxy(std::shared_ptr controller, ControllerType controller_type, + ProxyCallback proxy_callback) + : m_controller(controller), m_controller_type(controller_type), m_callback(proxy_callback), + m_rand_engine(std::random_device {}()) { auto screen_res = m_controller->get_screen_res(); @@ -74,8 +78,17 @@ bool asst::ControlScaleProxy::swipe(const Point& p1, const Point& p2, int durati bool asst::ControlScaleProxy::swipe(const Rect& r1, const Rect& r2, int duration, bool extra_swipe, double slope_in, 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, - with_pause); + auto rand_p1 = rand_point_in_rect(r1); + auto rand_p2 = rand_point_in_rect(r2); + + if (m_controller_type == ControllerType::Adb) { + // 同样的参数 ADB 总是划过头,糊点屎进来 + const auto& opt = Config.get_options(); + auto x_dist = rand_p1.x - rand_p2.x; + rand_p2.x = rand_p1.x - static_cast(x_dist * opt.adb_swipe_x_distance_multiplier); + } + + return swipe(rand_p1, rand_p2, duration, extra_swipe, slope_in, slope_out, with_pause); } bool asst::ControlScaleProxy::inject_input_event(InputEvent event) diff --git a/src/MaaCore/Controller/ControlScaleProxy.h b/src/MaaCore/Controller/ControlScaleProxy.h index dd2f1e9281..3a9cc8a067 100644 --- a/src/MaaCore/Controller/ControlScaleProxy.h +++ b/src/MaaCore/Controller/ControlScaleProxy.h @@ -15,7 +15,8 @@ namespace asst using ProxyCallback = std::function; public: - ControlScaleProxy(std::shared_ptr controller, ProxyCallback proxy_callback); + ControlScaleProxy(std::shared_ptr controller, ControllerType controller_type, + ProxyCallback proxy_callback); ~ControlScaleProxy() = default; ControlScaleProxy(const ControlScaleProxy&) = delete; @@ -45,5 +46,6 @@ namespace asst std::pair m_scale_size = { WindowWidthDefault, WindowHeightDefault }; double m_control_scale = 1.0; + ControllerType m_controller_type = ControllerType::Minitouch; }; } diff --git a/src/MaaCore/Controller/Controller.cpp b/src/MaaCore/Controller/Controller.cpp index d17cbc63a2..d3185798d7 100644 --- a/src/MaaCore/Controller/Controller.cpp +++ b/src/MaaCore/Controller/Controller.cpp @@ -186,7 +186,7 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a }; try { - m_scale_proxy = std::make_shared(m_controller, proxy_callback); + m_scale_proxy = std::make_shared(m_controller, m_controller_type, proxy_callback); } catch (const std::exception& e) { Log.error("Cannot create controller proxy: {}", e.what()); diff --git a/src/MaaCore/Task/BattleHelper.cpp b/src/MaaCore/Task/BattleHelper.cpp index 535204b955..a76f221fe0 100644 --- a/src/MaaCore/Task/BattleHelper.cpp +++ b/src/MaaCore/Task/BattleHelper.cpp @@ -282,9 +282,9 @@ bool asst::BattleHelper::deploy_oper(const std::string& name, const Point& loc, } bool deploy_with_pause = ControlFeat::support(m_inst_helper.ctrler()->support_features(), ControlFeat::SWIPE_WITH_PAUSE); - m_inst_helper.ctrler()->swipe(oper_rect, Rect(target_point.x, target_point.y, 1, 1), duration, false, - swipe_oper_task_ptr->special_params.at(1), swipe_oper_task_ptr->special_params.at(2), - deploy_with_pause); + m_inst_helper.ctrler()->swipe(Point(oper_rect.x, oper_rect.y), Point(target_point.x, target_point.y), duration, + false, swipe_oper_task_ptr->special_params.at(1), + swipe_oper_task_ptr->special_params.at(2), deploy_with_pause); // 拖动干员朝向 if (direction != DeployDirection::None) {