mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-04-09 13:00:39 +08:00
在 `BetterGenshinImpact.csproj` 文件中,添加了两个新文件夹路径 `GameTask\OneDragon\` 和 `User\AutoPathing\`。 在 `BvStatus.cs` 文件中: - 将 `WaitForMainUi` 方法的默认重试次数从 25 次减少到 10 次。 - 添加了 `IsInPartyViewUi` 和 `WaitForPartyViewUi` 方法。 在 `ElementAssets.cs` 文件中: - 添加并初始化了 `PartyBtnChooseView` 和 `PartyBtnDelete` 两个新的识别对象。 在 `NewRetry.cs` 文件中: - 添加了 `using System.Threading.Tasks;` 引用。 - 添加了 `WaitForAction` 方法。 在 `Region.cs` 文件中,添加了一个新的 `ClickTo` 方法,该方法接受 `double` 类型的参数。 在 `ReturnMainUiTask.cs` 文件中: - 删除了旧的 `ReturnMainUiTask` 类。 - 添加了新的 `ReturnMainUiTask` 类,内容与旧的类似,但文件路径和命名空间有所变化。 在 `RunnerContext.cs` 文件中,移除了 `using BetterGenshinImpact.GameTask.OneDragon;` 引用,添加了 `using BetterGenshinImpact.GameTask.Common.Job;` 引用。 在 `HotKeyPageViewModel.cs` 文件中: - 添加了多个 `using` 引用,包括 `using System.Threading.Tasks;` 和 `using BetterGenshinImpact.GameTask.Common.Job;`。 - 修改了多个方法的代码格式,使其更加简洁。 - 添加了多个新的快捷键设置。 添加了两个新的 PNG 图片文件 `party_btn_choose_view.png` 和 `party_btn_delete.png`。 在 `SwitchPartyTask.cs` 文件中,添加了新的 `SwitchPartyTask` 类,用于切换队伍。
65 lines
1.6 KiB
C#
65 lines
1.6 KiB
C#
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BetterGenshinImpact.GameTask.Common;
|
|
|
|
/// <summary>
|
|
/// https://stackoverflow.com/questions/1563191/cleanest-way-to-write-retry-logic
|
|
/// </summary>
|
|
public static class NewRetry
|
|
{
|
|
public static void Do(Action action, TimeSpan retryInterval, int maxAttemptCount = 3)
|
|
{
|
|
_ = Do<object?>(() =>
|
|
{
|
|
action();
|
|
return null;
|
|
}, retryInterval, maxAttemptCount);
|
|
}
|
|
|
|
public static T Do<T>(Func<T> action, TimeSpan retryInterval, int maxAttemptCount = 3)
|
|
{
|
|
List<System.Exception> exceptions = [];
|
|
|
|
for (int attempted = 0; attempted < maxAttemptCount; attempted++)
|
|
{
|
|
try
|
|
{
|
|
if (attempted > 0)
|
|
{
|
|
Thread.Sleep(retryInterval);
|
|
}
|
|
|
|
return action();
|
|
}
|
|
catch (RetryException ex)
|
|
{
|
|
exceptions.Add(ex);
|
|
}
|
|
}
|
|
|
|
if (exceptions.Count > 0)
|
|
{
|
|
throw exceptions.Last();
|
|
}
|
|
throw new AggregateException(exceptions);
|
|
}
|
|
|
|
public static async Task<bool> WaitForAction(Func<bool> action, CancellationToken ct, int retryTimes = 10, int delayMs = 1000)
|
|
{
|
|
for (var i = 0; i < retryTimes; i++)
|
|
{
|
|
await TaskControl.Delay(delayMs, ct);
|
|
if (action())
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|