From 4859c4dc4a4039b2805d8cf91aebbbd4afd280d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89=E9=B8=AD=E8=9B=8B?= Date: Wed, 16 Oct 2024 01:31:44 +0800 Subject: [PATCH] add log & pathing opt --- .../AutoPathing/Handler/AutoFightHandler.cs | 3 ++ .../Handler/ElementalSkillHandler.cs | 3 ++ .../Handler/NahidaCollectHandler.cs | 2 ++ .../Handler/NormalAttackHandler.cs | 10 +++--- .../GameTask/AutoPathing/PathExecutor.cs | 31 ++++++------------- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/BetterGenshinImpact/GameTask/AutoPathing/Handler/AutoFightHandler.cs b/BetterGenshinImpact/GameTask/AutoPathing/Handler/AutoFightHandler.cs index 9cceb50a..a391d6bd 100644 --- a/BetterGenshinImpact/GameTask/AutoPathing/Handler/AutoFightHandler.cs +++ b/BetterGenshinImpact/GameTask/AutoPathing/Handler/AutoFightHandler.cs @@ -1,9 +1,11 @@ using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.GameTask.AutoFight; +using BetterGenshinImpact.GameTask.Common; using System; using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; namespace BetterGenshinImpact.GameTask.AutoPathing.Handler; @@ -16,6 +18,7 @@ internal class AutoFightHandler : IActionHandler private async Task StartFight(CancellationTokenSource cts) { + TaskControl.Logger.LogInformation("执行 {Text}", "自动战斗"); // 爷们要战斗 var taskParams = new AutoFightParam(GetFightStrategy()) { diff --git a/BetterGenshinImpact/GameTask/AutoPathing/Handler/ElementalSkillHandler.cs b/BetterGenshinImpact/GameTask/AutoPathing/Handler/ElementalSkillHandler.cs index 7ee9465c..d968b62c 100644 --- a/BetterGenshinImpact/GameTask/AutoPathing/Handler/ElementalSkillHandler.cs +++ b/BetterGenshinImpact/GameTask/AutoPathing/Handler/ElementalSkillHandler.cs @@ -2,6 +2,8 @@ using System.Threading; using System.Threading.Tasks; using BetterGenshinImpact.Core.Simulator; +using BetterGenshinImpact.GameTask.Common; +using Microsoft.Extensions.Logging; using Vanara.PInvoke; namespace BetterGenshinImpact.GameTask.AutoPathing.Handler; @@ -13,6 +15,7 @@ public class ElementalSkillHandler : IActionHandler { public Task RunAsync(CancellationTokenSource cts) { + TaskControl.Logger.LogInformation("执行 {Text}", "释放元素战技"); Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_E); return Task.CompletedTask; } diff --git a/BetterGenshinImpact/GameTask/AutoPathing/Handler/NahidaCollectHandler.cs b/BetterGenshinImpact/GameTask/AutoPathing/Handler/NahidaCollectHandler.cs index 2f3cc8d1..0582448a 100644 --- a/BetterGenshinImpact/GameTask/AutoPathing/Handler/NahidaCollectHandler.cs +++ b/BetterGenshinImpact/GameTask/AutoPathing/Handler/NahidaCollectHandler.cs @@ -2,6 +2,7 @@ using System.Threading; using System.Threading.Tasks; using BetterGenshinImpact.Core.Simulator; +using Microsoft.Extensions.Logging; using Vanara.PInvoke; using static BetterGenshinImpact.GameTask.Common.TaskControl; @@ -16,6 +17,7 @@ public class NahidaCollectHandler : IActionHandler public async Task RunAsync(CancellationTokenSource cts) { + Logger.LogInformation("执行 {Nhd} 长按E转圈拾取", "纳西妲"); var cd = DateTime.Now - lastETime; if (cd < TimeSpan.FromSeconds(10)) { diff --git a/BetterGenshinImpact/GameTask/AutoPathing/Handler/NormalAttackHandler.cs b/BetterGenshinImpact/GameTask/AutoPathing/Handler/NormalAttackHandler.cs index 6c789d71..23b6723d 100644 --- a/BetterGenshinImpact/GameTask/AutoPathing/Handler/NormalAttackHandler.cs +++ b/BetterGenshinImpact/GameTask/AutoPathing/Handler/NormalAttackHandler.cs @@ -1,18 +1,20 @@ -using System; +using BetterGenshinImpact.Core.Simulator; +using BetterGenshinImpact.GameTask.Common; +using Microsoft.Extensions.Logging; using System.Threading; using System.Threading.Tasks; -using BetterGenshinImpact.Core.Simulator; -using Vanara.PInvoke; namespace BetterGenshinImpact.GameTask.AutoPathing.Handler; /// -/// 触发元素战技 +/// 触发普通攻击 /// public class NormalAttackHandler : IActionHandler { public Task RunAsync(CancellationTokenSource cts) { + TaskControl.Logger.LogInformation("执行 {Text}", "普通攻击"); + Simulation.SendInput.Mouse.LeftButtonClick(); return Task.CompletedTask; } diff --git a/BetterGenshinImpact/GameTask/AutoPathing/PathExecutor.cs b/BetterGenshinImpact/GameTask/AutoPathing/PathExecutor.cs index 71890039..2fbb6909 100644 --- a/BetterGenshinImpact/GameTask/AutoPathing/PathExecutor.cs +++ b/BetterGenshinImpact/GameTask/AutoPathing/PathExecutor.cs @@ -261,12 +261,11 @@ public class PathExecutor(CancellationTokenSource cts) } await _rotateTask.WaitUntilRotatedTo(targetOrientation, 2); - var wPressed = false; var stepsTaken = 0; while (!cts.IsCancellationRequested) { stepsTaken++; - if (stepsTaken > 12) + if (stepsTaken > 20) { Logger.LogWarning("精确接近超时"); break; @@ -280,27 +279,16 @@ public class PathExecutor(CancellationTokenSource cts) break; } - _rotateTask.RotateToApproach(targetOrientation, screen); //不再改变视角 - if (waypoint.MoveMode == MoveModeEnum.Walk.Code) - { - // 小碎步接近 - Simulation.SendInput.Keyboard.KeyDown(User32.VK.VK_W).Sleep(60).KeyUp(User32.VK.VK_W); - await Delay(200, cts); - continue; - } - - if (!wPressed) - { - Simulation.SendInput.Keyboard.KeyDown(User32.VK.VK_W); - } - - await Delay(100, cts); + await _rotateTask.WaitUntilRotatedTo(targetOrientation, 2); + // 小碎步接近 + Simulation.SendInput.Keyboard.KeyDown(User32.VK.VK_W).Sleep(60).KeyUp(User32.VK.VK_W); + await Delay(50, cts); } - if (wPressed) - { - Simulation.SendInput.Keyboard.KeyUp(User32.VK.VK_W); - } + Simulation.SendInput.Keyboard.KeyUp(User32.VK.VK_W); + + // 到达目的地后停顿一秒 + await Delay(1000, cts); } private async Task AfterMoveToTarget(Waypoint waypoint) @@ -311,6 +299,7 @@ public class PathExecutor(CancellationTokenSource cts) { var handler = ActionFactory.GetHandler(waypoint.Action); await handler.RunAsync(cts); + await Delay(800, cts); } } }