mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-04-18 21:29:13 +08:00
* 记录一次对hutaofisher的访谈,帮助开发者理解其算法
* 本地化HelloWorld
* .csproj取消windows版本号,此处导致了IDE在新建代码文件和自动生成代码时,默认命名空间丢失的问题。已知VisualStudio和ReSharper存在这个问题。
* 优化扩展方法写法,改为从localizer扩展;Converter优化写法,避免冲突;新增两种语言,待测试ocr效果
* Revert ".csproj取消windows版本号,此处导致了IDE在新建代码文件和自动生成代码时,默认命名空间丢失的问题。已知VisualStudio和ReSharper存在这个问题。"
This reverts commit 8bd7ee74c5.
* localizer改为由构造函数传入以支持单元测试;一个英语上钩的单元测试
* 传送任务支持英语游戏界面;本地化参数挪至OtherConfig类下,但界面位置暂不挪动,待定
* 调整resx位置风格,放在直接使用字符串的类下;一条龙合成树脂及领取每日奖励支持游戏内中英双语
* 删除无用碎片文件
* 删去两个不必要的Sdcb包引用
* Paddle服务类去掉分类模型;检测和识别新增支持繁中和法语,配有单元测试;因小语种识别效果不理想,使用正则匹配替换多处识别文本相等或包含判断;钓鱼、一条龙合成树脂及领取每日奖励支持游戏内繁中和法语;
* 检查今日奖励任务的多语言化;右侧联机的P图标检测区域宽度缩减,避免英语角色名被误识别成P
* AutoDomainTask的游戏多语言化,由于我的游戏账号无法测试,仅配一些测试用例
* 修复有3个Mizuki导致异常的bug,临时用拼音代替新角色英文名,并为该数据初始化方法添加单元测试
* 瓦雷莎删去别名“牛牛”,因荒泷一斗已占用此别名;别名加载和读取优化
* 加个锁避免单元测试中多线程初始化paddle崩溃
110 lines
3.5 KiB
C#
110 lines
3.5 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using BetterGenshinImpact.Core.Recognition;
|
|
using BetterGenshinImpact.Core.Simulator.Extensions;
|
|
using BetterGenshinImpact.GameTask.Common.Element.Assets;
|
|
using BetterGenshinImpact.GameTask.Model.Area;
|
|
using BetterGenshinImpact.Helpers;
|
|
using BetterGenshinImpact.Helpers.Extensions;
|
|
using Microsoft.Extensions.Localization;
|
|
using Microsoft.Extensions.Logging;
|
|
using Vanara.PInvoke;
|
|
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
|
|
|
namespace BetterGenshinImpact.GameTask.Common.Job;
|
|
|
|
/// <summary>
|
|
/// 一键领取纪行
|
|
/// </summary>
|
|
public class ClaimBattlePassRewardsTask
|
|
{
|
|
private readonly ReturnMainUiTask _returnMainUiTask = new();
|
|
|
|
private readonly string claimAllLocalizedString;
|
|
|
|
public ClaimBattlePassRewardsTask()
|
|
{
|
|
IStringLocalizer<ClaimBattlePassRewardsTask> stringLocalizer = App.GetService<IStringLocalizer<ClaimBattlePassRewardsTask>>() ?? throw new NullReferenceException();
|
|
CultureInfo cultureInfo = new CultureInfo(TaskContext.Instance().Config.OtherConfig.GameCultureInfoName);
|
|
this.claimAllLocalizedString = stringLocalizer.WithCultureGet(cultureInfo, "一键");
|
|
}
|
|
|
|
public async Task Start(CancellationToken ct)
|
|
{
|
|
try
|
|
{
|
|
await DoOnce(ct);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Logger.LogDebug(e, "领取纪行奖励异常");
|
|
Logger.LogError("领取纪行奖励异常: {Msg}", e.Message);
|
|
}
|
|
}
|
|
|
|
public async Task DoOnce(CancellationToken ct)
|
|
{
|
|
await _returnMainUiTask.Start(ct);
|
|
|
|
await Delay(200, ct);
|
|
TaskContext.Instance().PostMessageSimulator.SimulateAction(GIActions.OpenBattlePassScreen); // F4 开纪行
|
|
|
|
// 领取战令1
|
|
await Delay(500, ct);
|
|
await ClaimAll(ct);
|
|
|
|
|
|
// 领取点数
|
|
await Delay(1000, ct);
|
|
GameCaptureRegion.GameRegion1080PPosClick(960, 45); // 点中间
|
|
await Delay(500, ct);
|
|
await ClaimAll(ct);
|
|
|
|
// 领取战令2
|
|
await Delay(2000, ct); // 等待升级动画
|
|
// 还可能存在领取到原石的情况
|
|
if (CaptureToRectArea().Find(ElementAssets.Instance.PrimogemRo).IsExist())
|
|
{
|
|
TaskContext.Instance().PostMessageSimulator.KeyPress(User32.VK.VK_ESCAPE);
|
|
}
|
|
GameCaptureRegion.GameRegion1080PPosClick(858, 45);
|
|
await Delay(500, ct);
|
|
await ClaimAll(ct);
|
|
|
|
// 关闭
|
|
await _returnMainUiTask.Start(ct);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 一键领取
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task<bool> ClaimAll(CancellationToken ct)
|
|
{
|
|
using var ra = CaptureToRectArea();
|
|
var ocrList = ra.FindMulti(RecognitionObject.Ocr(ra.ToRect().CutRightBottom(0.3, 0.18)));
|
|
var wt = ocrList.FirstOrDefault(txt => Regex.IsMatch(txt.Text, this.claimAllLocalizedString));
|
|
if (wt != null)
|
|
{
|
|
wt.Click();
|
|
Logger.LogInformation("纪行:{Text}", "一键领取");
|
|
await Delay(500, ct);
|
|
using var ra2 = CaptureToRectArea();
|
|
if (ra2.Find(ElementAssets.Instance.PrimogemRo).IsExist())
|
|
{
|
|
TaskContext.Instance().PostMessageSimulator.KeyPress(User32.VK.VK_ESCAPE);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
Logger.LogInformation("纪行:{Text}", "无需领取");
|
|
return false;
|
|
}
|
|
}
|
|
} |