pathing opt

在 `PathExecutor` 类中添加了 `EndAction` 和 `EndJudgment` 属性,用于判断路径追踪的结束条件,并在路径执行过程中调用 `ResolveAnomalies` 和 `EndJudgment` 方法处理异常和结束条件。处理 `NormalEndException` 异常并记录日志。检查游戏窗口分辨率,低于 1920x1080 记录错误日志。

更新 `冒险家协会_枫丹.json` 文件,将路径点类型从 `path` 修改为 `target`。

在 `GoToAdventurersGuildTask` 和 `GoToCraftingBenchTask` 类中,添加结束日志信息,移除交互代码,并添加 `EndAction` 属性判断任务结束条件。
This commit is contained in:
辉鸭蛋
2024-11-13 23:42:15 +08:00
parent 8941f6ce8c
commit 7a5efe208f
4 changed files with 52 additions and 29 deletions

View File

@@ -44,6 +44,11 @@ public class PathExecutor(CancellationToken ct)
set => _partyConfig = value;
}
/// <summary>
/// 判断是否中止路径追踪的条件
/// </summary>
public Func<ImageRegion, bool>? EndAction { get; set; }
private CombatScenes? _combatScenes;
// private readonly Dictionary<string, string> _actionAvatarIndexMap = new();
@@ -97,6 +102,7 @@ public class PathExecutor(CancellationToken ct)
{
try
{
await ResolveAnomalies(); // 异常场景处理
foreach (var waypoint in waypoints)
{
await RecoverWhenLowHp(); // 低血量恢复
@@ -122,6 +128,11 @@ public class PathExecutor(CancellationToken ct)
break;
}
catch (NormalEndException normalEndException)
{
Logger.LogInformation(normalEndException.Message);
break;
}
catch (RetryException retryException)
{
Logger.LogWarning(retryException.Message);
@@ -131,7 +142,6 @@ public class PathExecutor(CancellationToken ct)
// 不管咋样,松开所有按键
Simulation.SendInput.Keyboard.KeyUp(User32.VK.VK_W);
Simulation.SendInput.Mouse.RightButtonUp();
await ResolveAnomalies(); // 异常场景处理
}
}
}
@@ -150,6 +160,7 @@ public class PathExecutor(CancellationToken ct)
{
Logger.LogError("游戏窗口分辨率不是 16:9 !当前分辨率为 {Width}x{Height} , 非 16:9 分辨率的游戏无法正常使用路径追踪功能!", gameScreenSize.Width, gameScreenSize.Height);
}
if (gameScreenSize.Width < 1920 || gameScreenSize.Height < 1080)
{
Logger.LogError("游戏窗口分辨率小于 1920x1080 !当前分辨率为 {Width}x{Height} , 小于 1920x1080 的分辨率的游戏路径追踪的效果非常差!", gameScreenSize.Width, gameScreenSize.Height);
@@ -351,6 +362,9 @@ public class PathExecutor(CancellationToken ct)
}
screen = CaptureToRectArea();
EndJudgment(screen);
position = await GetPosition(screen);
var distance = Navigation.GetDistance(waypoint, position);
Debug.WriteLine($"接近目标点中,距离为{distance}");
@@ -555,6 +569,9 @@ public class PathExecutor(CancellationToken ct)
}
screen = CaptureToRectArea();
EndJudgment(screen);
position = await GetPosition(screen);
if (Navigation.GetDistance(waypoint, position) < 2)
{
@@ -695,4 +712,12 @@ public class PathExecutor(CancellationToken ct)
}
}
}
private void EndJudgment(ImageRegion ra)
{
if (EndAction != null && EndAction(ra))
{
throw new NormalEndException("达成结束条件,结束路径追踪");
}
}
}

View File

@@ -20,7 +20,7 @@
"id": 2,
"x": 4495.0,
"y": 3638.0,
"type": "path",
"type": "target",
"move_mode": "walk",
"action": ""
}

View File

@@ -46,24 +46,15 @@ public class GoToAdventurersGuildTask
}
}
}
Logger.LogInformation("→ {Name} 结束", Name);
}
public async Task DoOnce(string country, CancellationToken ct)
{
// 1. 走到冒险家协会
// 1. 走到冒险家协会并对话
await GoToAdventurersGuild(country, ct);
// 2. 交互
var ra = CaptureToRectArea();
if (!Bv.FindFAndPress(ra, "凯瑟琳"))
{
throw new Exception("未找与凯瑟琳对话交互按钮");
}
// 3. 等待对话界面
await Delay(200, ct);
// 每日
var res = await _chooseTalkOptionTask.SingleSelectText("每日", ct, 10, true);
if (res == TalkOptionRes.FoundAndClick)
@@ -76,7 +67,7 @@ public class GoToAdventurersGuildTask
// 结束后重新打开
await Delay(200, ct);
ra = CaptureToRectArea();
var ra = CaptureToRectArea();
if (!Bv.FindFAndPress(ra, "凯瑟琳"))
{
throw new Exception("未找与凯瑟琳对话交互按钮");
@@ -130,10 +121,17 @@ public class GoToAdventurersGuildTask
{
Enabled = true,
AutoSkipEnabled = true
}
},
EndAction = region => Bv.FindFAndPress(region, "凯瑟琳")
};
await pathingTask.Pathing(task);
await Delay(500, ct);
await Delay(300, ct);
using var ra = CaptureToRectArea();
if (!Bv.IsInTalkUi(ra))
{
throw new Exception("未找与凯瑟琳对话交互按钮");
}
}
}

View File

@@ -52,18 +52,10 @@ public class GoToCraftingBenchTask
public async Task DoOnce(string country, CancellationToken ct)
{
// 1. 走到合成台
// 1. 走到合成台并交互
await GoToCraftingBench(country, ct);
// 2. 交互
var ra = CaptureToRectArea();
if (!Bv.FindFAndPress(ra, "合成"))
{
throw new Exception("未找与合成台交互按钮");
}
// 3. 等待合成界面
await Delay(100, ct);
// 2. 等待合成界面
await _chooseTalkOptionTask.SelectLastOptionUntilEnd(ct,
region => region.Find(ElementAssets.Instance.BtnWhiteConfirm).IsExist()
);
@@ -71,7 +63,7 @@ public class GoToCraftingBenchTask
// 判断浓缩树脂是否存在
// TODO 满的情况是怎么样子的
ra = CaptureToRectArea();
var ra = CaptureToRectArea();
var resin = ra.Find(ElementAssets.Instance.CraftCondensedResin);
if (resin.IsExist())
{
@@ -100,16 +92,24 @@ public class GoToCraftingBenchTask
public async Task GoToCraftingBench(string country, CancellationToken ct)
{
var task = PathingTask.BuildFromFilePath(Global.Absolute(@$"GameTask\Common\Element\Assets\Json\合成台_{country}.json"));
var pathingTask = new PathExecutor(ct)
{
PartyConfig = new PathingPartyConfig
{
Enabled = true,
AutoSkipEnabled = true
}
},
EndAction = region => Bv.FindFAndPress(region, "合成")
};
await pathingTask.Pathing(task);
await Delay(500, ct);
await Delay(300, ct);
using var ra = CaptureToRectArea();
if (!Bv.IsInTalkUi(ra))
{
throw new Exception("未找与合成台交互按钮");
}
}
}