diff --git a/src/MeoAssistant/BattleProcessTask.cpp b/src/MeoAssistant/BattleProcessTask.cpp index cb74b1e275..c437b32814 100644 --- a/src/MeoAssistant/BattleProcessTask.cpp +++ b/src/MeoAssistant/BattleProcessTask.cpp @@ -479,10 +479,8 @@ bool asst::BattleProcessTask::oper_deploy(const BattleAction& action) Point placed_point = m_side_tile_info[action.location].pos; Rect placed_rect{ placed_point.x ,placed_point.y, 0, 0 }; - int dist = static_cast( - std::sqrt( - (std::pow(std::abs(placed_point.x - oper_rect.x), 2)) - + (std::pow(std::abs(placed_point.y - oper_rect.y), 2)))); + int dist = static_cast(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(swipe_oper_task_ptr->pre_delay / 1000.0 * dist * log10(dist)); m_ctrler->swipe(oper_rect, placed_rect, duration, true, 0); @@ -503,15 +501,8 @@ bool asst::BattleProcessTask::oper_deploy(const BattleAction& action) Point direction = DirectionMapping.at(action.direction); // 将方向转换为实际的 swipe end 坐标点 - Point end_point = placed_point; constexpr int coeff = 500; - end_point.x += direction.x * coeff; - end_point.y += direction.y * coeff; - - end_point.x = std::max(0, end_point.x); - end_point.x = std::min(end_point.x, WindowWidthDefault); - end_point.y = std::max(0, end_point.y); - end_point.y = std::min(end_point.y, WindowHeightDefault); + Point end_point = placed_point + (direction * coeff); m_ctrler->swipe(placed_point, end_point, swipe_oper_task_ptr->rear_delay, true, 100); } diff --git a/src/MeoAssistant/RoguelikeBattleTaskPlugin.cpp b/src/MeoAssistant/RoguelikeBattleTaskPlugin.cpp index f3a52a4dc4..56c175635f 100644 --- a/src/MeoAssistant/RoguelikeBattleTaskPlugin.cpp +++ b/src/MeoAssistant/RoguelikeBattleTaskPlugin.cpp @@ -309,24 +309,16 @@ bool asst::RoguelikeBattleTaskPlugin::auto_battle() // 将干员拖动到场上 Point placed_point = m_side_tile_info.at(placed_loc).pos; Rect placed_rect(placed_point.x, placed_point.y, 1, 1); - int dist = static_cast( - std::sqrt( - (std::pow(std::abs(placed_point.x - opt_oper.rect.x), 2)) - + (std::pow(std::abs(placed_point.y - opt_oper.rect.y), 2)))); + int dist = static_cast(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(swipe_oper_task_ptr->pre_delay / 800.0 * dist * log10(dist)); m_ctrler->swipe(opt_oper.rect, placed_rect, duration, true, 0); + int duration = static_cast(swipe_oper_task_ptr->pre_delay / 800.0 * dist * log10(dist)); + m_ctrler->swipe(opt_oper.rect, placed_rect, duration, true, 0); sleep(use_oper_task_ptr->rear_delay); // 将方向转换为实际的 swipe end 坐标点 - Point end_point = placed_point; constexpr int coeff = 500; - end_point.x += direction.x * coeff; - end_point.y += direction.y * coeff; - - end_point.x = std::max(0, end_point.x); - end_point.x = std::min(end_point.x, WindowWidthDefault); - end_point.y = std::max(0, end_point.y); - end_point.y = std::min(end_point.y, WindowHeightDefault); + Point end_point = placed_point + (direction * coeff); m_ctrler->swipe(placed_point, end_point, swipe_oper_task_ptr->rear_delay, true, 100);