Files
better-genshin-impact/BetterGenshinImpact/GameTask/Common/Job/GoToAdventurersGuildTask.cs
辉鸭蛋 7a5efe208f pathing opt
在 `PathExecutor` 类中添加了 `EndAction` 和 `EndJudgment` 属性,用于判断路径追踪的结束条件,并在路径执行过程中调用 `ResolveAnomalies` 和 `EndJudgment` 方法处理异常和结束条件。处理 `NormalEndException` 异常并记录日志。检查游戏窗口分辨率,低于 1920x1080 记录错误日志。

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

在 `GoToAdventurersGuildTask` 和 `GoToCraftingBenchTask` 类中,添加结束日志信息,移除交互代码,并添加 `EndAction` 属性判断任务结束条件。
2024-11-13 23:42:15 +08:00

138 lines
4.5 KiB
C#

using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.GameTask.AutoPathing;
using BetterGenshinImpact.GameTask.AutoPathing.Model;
using BetterGenshinImpact.GameTask.AutoSkip.Assets;
using BetterGenshinImpact.GameTask.AutoSkip;
using BetterGenshinImpact.GameTask.Common.BgiVision;
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
using Vanara.PInvoke;
using static BetterGenshinImpact.GameTask.Common.TaskControl;
namespace BetterGenshinImpact.GameTask.Common.Job;
public class GoToAdventurersGuildTask
{
public string Name => "前往冒险家协会领取奖励";
private readonly int _retryTimes = 2;
private readonly ChooseTalkOptionTask _chooseTalkOptionTask = new();
public async Task Start(string country, CancellationToken ct)
{
Logger.LogInformation("→ {Name} 开始", Name);
for (int i = 0; i < _retryTimes; i++)
{
try
{
await DoOnce(country, ct);
break;
}
catch (Exception e)
{
Logger.LogError("前往冒险家协会领取奖励执行异常:" + e.Message);
if (i == _retryTimes - 1)
{
// 通知失败
throw;
}
else
{
await Delay(1000, ct);
Logger.LogInformation("重试前往冒险家协会领取奖励");
}
}
}
Logger.LogInformation("→ {Name} 结束", Name);
}
public async Task DoOnce(string country, CancellationToken ct)
{
// 1. 走到冒险家协会并对话
await GoToAdventurersGuild(country, ct);
// 每日
var res = await _chooseTalkOptionTask.SingleSelectText("每日", ct, 10, true);
if (res == TalkOptionRes.FoundAndClick)
{
Logger.LogInformation("▶ {Text}", "领取『每日委托』奖励!");
await Delay(200, ct);
await _chooseTalkOptionTask.SelectLastOptionUntilEnd(ct, null, 3); // 点几下
await Delay(500, ct);
await new ReturnMainUiTask().Start(ct);
// 结束后重新打开
await Delay(200, ct);
var ra = CaptureToRectArea();
if (!Bv.FindFAndPress(ra, "凯瑟琳"))
{
throw new Exception("未找与凯瑟琳对话交互按钮");
}
}
else if (res == TalkOptionRes.FoundButNotOrange)
{
Logger.LogInformation("▶ {Text} 未完成或者已领取", "领取『每日委托』奖励");
}
else
{
Logger.LogWarning("▶ 未找到 {Text} 选项", "领取『每日委托』奖励");
}
// 探索
res = await _chooseTalkOptionTask.SingleSelectText("探索", ct, 10, true);
if (res == TalkOptionRes.FoundAndClick)
{
await Delay(500, ct);
new OneKeyExpeditionTask().Run(AutoSkipAssets.Instance);
}
else if (res == TalkOptionRes.FoundButNotOrange)
{
Logger.LogInformation("▶ {Text} 未探索完成或已领取", "探索派遣");
}
else
{
Logger.LogWarning("▶ 未找到 {Text} 选项", "探索派遣");
}
// 如果最后还在对话界面,选择最后一个选项退出
if (Bv.IsInTalkUi(CaptureToRectArea()))
{
await _chooseTalkOptionTask.SelectLastOptionUntilEnd(ct);
Logger.LogInformation("退出当前对话");
}
}
/// <summary>
/// 前往冒险家协会
/// </summary>
/// <param name="country"></param>
/// <param name="ct"></param>
/// <returns></returns>
public async Task GoToAdventurersGuild(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(300, ct);
using var ra = CaptureToRectArea();
if (!Bv.IsInTalkUi(ra))
{
throw new Exception("未找与凯瑟琳对话交互按钮");
}
}
}