mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-21 09:45:48 +08:00
优化 NahidaCollectHandler 逻辑并更新 HotKeyPageViewModel 在 NahidaCollectHandler.cs 文件中,调整了 RunAsync 方法的多个参数和延迟时间,增加了条件判断以优化逻辑。在 HotKeyPageViewModel.cs 文件中,添加了新的引用,并修改了 Test1Hotkey 的回调函数以调用 NahidaCollectHandler 的 RunAsync 方法。
58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
using System;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using BetterGenshinImpact.Core.Simulator;
|
||
using Vanara.PInvoke;
|
||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||
|
||
namespace BetterGenshinImpact.GameTask.AutoPathing.Handler;
|
||
|
||
/// <summary>
|
||
/// 使用纳西妲长按E技能进行收集,360°球形无死角扫码,`type = target`的情况才有效
|
||
/// </summary>
|
||
public class NahidaCollectHandler : IActionHandler
|
||
{
|
||
private DateTime lastETime = DateTime.MinValue;
|
||
|
||
public async Task RunAsync(CancellationTokenSource cts)
|
||
{
|
||
var cd = DateTime.Now - lastETime;
|
||
if (cd < TimeSpan.FromSeconds(10))
|
||
{
|
||
await Delay((int)((6 - cd.TotalSeconds + 0.5) * 1000), cts);
|
||
}
|
||
|
||
var dpi = TaskContext.Instance().DpiScale;
|
||
|
||
int x = (int)(200 * dpi), y = (int)(-50 * dpi);
|
||
int i = 80;
|
||
// 视角拉到最下面
|
||
Simulation.SendInput.Mouse.MoveMouseBy(0, 10000);
|
||
await Delay(200, cts);
|
||
|
||
// 按住E技能 无死角扫码
|
||
Simulation.SendInput.Keyboard.KeyDown(User32.VK.VK_E);
|
||
await Delay(200, cts);
|
||
while (!cts.IsCancellationRequested && i > 0)
|
||
{
|
||
i--;
|
||
if (i == 40)
|
||
{
|
||
y -= (int)(20 * dpi);
|
||
}
|
||
Simulation.SendInput.Mouse.MoveMouseBy(x, y);
|
||
await Delay(40, cts);
|
||
}
|
||
Simulation.SendInput.Keyboard.KeyUp(User32.VK.VK_E);
|
||
|
||
lastETime = DateTime.Now;
|
||
|
||
await Delay(1000, cts);
|
||
|
||
// 恢复视角
|
||
Simulation.SendInput.Mouse.MiddleButtonClick();
|
||
|
||
await Delay(1000, cts);
|
||
}
|
||
}
|