add PickAroundHandler action params

This commit is contained in:
辉鸭蛋 2024-11-25 22:37:19 +08:00
parent fa9eacf4ac
commit fa1809a1f0
3 changed files with 17 additions and 3 deletions

View File

@ -15,7 +15,7 @@ public class ActionFactory
return key switch return key switch
{ {
"nahida_collect" => new NahidaCollectHandler(), "nahida_collect" => new NahidaCollectHandler(),
"pick_around" => new PickAroundHandler(1), "pick_around" => new PickAroundHandler(),
"fight" => new AutoFightHandler(), "fight" => new AutoFightHandler(),
"normal_attack" => new NormalAttackHandler(), "normal_attack" => new NormalAttackHandler(),
"elemental_skill" => new ElementalSkillHandler(), "elemental_skill" => new ElementalSkillHandler(),

View File

@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BetterGenshinImpact.GameTask.AutoPathing.Model; using BetterGenshinImpact.GameTask.AutoPathing.Model;
using BetterGenshinImpact.Helpers;
using Vanara.PInvoke; using Vanara.PInvoke;
using static BetterGenshinImpact.GameTask.Common.TaskControl; using static BetterGenshinImpact.GameTask.Common.TaskControl;
@ -13,15 +14,22 @@ namespace BetterGenshinImpact.GameTask.AutoPathing.Handler;
/// <summary> /// <summary>
/// 采集任务到达点位后执行拾取操作 /// 采集任务到达点位后执行拾取操作
/// </summary> /// </summary>
public class PickAroundHandler(int turns) : IActionHandler public class PickAroundHandler() : IActionHandler
{ {
private CancellationToken _ct; private CancellationToken _ct;
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null) public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null)
{ {
this._ct = ct; this._ct = ct;
Logger.LogInformation("执行 {Text}", "小范围内自动拾取"); Logger.LogInformation("执行 {Text}", "小范围内自动拾取");
double speed = 1.1; double speed = 1.1;
int turns = 1;
if (waypointForTrack is { ActionParams: not null })
{
turns = StringUtils.TryParseInt(waypointForTrack.ActionParams, 1);
}
// 无加成幼年为 1, 少年为 1.1, 成年为 1.2, 若有移速加成, 再乘以加成倍率. // 无加成幼年为 1, 少年为 1.1, 成年为 1.2, 若有移速加成, 再乘以加成倍率.
CircularMotionCalculator calculator = new CircularMotionCalculator(speed); CircularMotionCalculator calculator = new CircularMotionCalculator(speed);
double oldRadiusT = 0; double oldRadiusT = 0;
@ -45,6 +53,7 @@ public class PickAroundHandler(int turns) : IActionHandler
Simulation.SendInput.Mouse.MiddleButtonClick(); Simulation.SendInput.Mouse.MiddleButtonClick();
await Delay((int)Math.Round(edgeT), _ct); await Delay((int)Math.Round(edgeT), _ct);
} }
Simulation.SendInput.Keyboard.KeyUp(User32.VK.VK_A); Simulation.SendInput.Keyboard.KeyUp(User32.VK.VK_A);
await Delay(200, _ct); await Delay(200, _ct);
} }
@ -126,4 +135,4 @@ public class CircularMotionCalculator
double endAngle = angle - _mixAngle + Math.Atan2(x, y) + Math.PI / 2; double endAngle = angle - _mixAngle + Math.Atan2(x, y) + Math.PI / 2;
return (edgeT / Speed, smallRadiusT / Speed, endAngle); return (edgeT / Speed, smallRadiusT / Speed, endAngle);
} }
} }

View File

@ -82,6 +82,11 @@ public partial class StringUtils
_ = int.TryParse(text, out int result); _ = int.TryParse(text, out int result);
return result; return result;
} }
public static int TryParseInt(string text, int defaultValue)
{
return int.TryParse(text, out int result) ? result : defaultValue;
}
public static int TryExtractPositiveInt(string text) public static int TryExtractPositiveInt(string text)
{ {