Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
877074b303 | ||
|
|
fee2bd7ade | ||
|
|
7cf826a80b | ||
|
|
94b6b3b0c9 | ||
|
|
e9f0294286 | ||
|
|
f5509dd540 | ||
|
|
f8c870b8ca | ||
|
|
fce70c0e96 | ||
|
|
1a71d052eb |
No files matched your search
@@ -10,7 +10,7 @@
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<ApplicationIcon>Assets\Images\logo.ico</ApplicationIcon>
|
||||
<AssemblyName>BetterGI</AssemblyName>
|
||||
<AssemblyVersion>0.44.3</AssemblyVersion>
|
||||
<AssemblyVersion>0.44.4</AssemblyVersion>
|
||||
<Platforms>x64</Platforms>
|
||||
<DebugType>embedded</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -18,6 +18,7 @@ using System.ComponentModel;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.GameTask.AutoTrackPath;
|
||||
using BetterGenshinImpact.GameTask.AutoArtifactSalvage;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
|
||||
@@ -145,6 +146,11 @@ public partial class AllConfig : ObservableObject
|
||||
/// </summary>
|
||||
public AutoDomainConfig AutoDomainConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 自动分解圣遗物配置
|
||||
/// </summary>
|
||||
public AutoArtifactSalvageConfig AutoArtifactSalvageConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 宏配置
|
||||
/// </summary>
|
||||
@@ -206,6 +212,7 @@ public partial class AllConfig : ObservableObject
|
||||
AutoWoodConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
AutoFightConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
AutoDomainConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
AutoArtifactSalvageConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
AutoMusicGameConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
TpConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
ScriptConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
|
||||
@@ -91,12 +91,19 @@ public class OpenCvCommonHelper
|
||||
|
||||
public static Mat InRangeHsv(Mat src, Scalar low, Scalar high)
|
||||
{
|
||||
using var mask = new Mat();
|
||||
using var rgbMat = new Mat();
|
||||
using var rgbMat = src.CvtColor(ColorConversionCodes.BGR2HSV);
|
||||
return rgbMat.InRange(low, high);
|
||||
}
|
||||
|
||||
Cv2.CvtColor(src, rgbMat, ColorConversionCodes.BGR2HSV);
|
||||
Cv2.InRange(rgbMat, low, high, mask);
|
||||
return mask.Clone();
|
||||
public static Mat InRangeHsvFull(Mat src, Scalar low, Scalar high)
|
||||
{
|
||||
using var rgbMat = src.CvtColor(ColorConversionCodes.BGR2HSV_FULL);
|
||||
return rgbMat.InRange(low, high);
|
||||
}
|
||||
|
||||
public static Scalar CommonHSV2OpenCVHSVFull(Scalar commonHSV)
|
||||
{
|
||||
return new Scalar(commonHSV.Val0 / 255 * 180, commonHSV.Val1 * 255, commonHSV.Val2 * 255);
|
||||
}
|
||||
|
||||
public static Mat Threshold(Mat src, Scalar s)
|
||||
|
||||
@@ -4,12 +4,14 @@ using BetterGenshinImpact.GameTask.Model.Area;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using Vanara.PInvoke;
|
||||
using static Vanara.PInvoke.User32;
|
||||
using BetterGenshinImpact.Core.Simulator.Extensions;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.ViewModel.Pages;
|
||||
using Fischless.WindowsInput;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Script.Dependence;
|
||||
|
||||
@@ -43,7 +45,14 @@ public class GlobalMethod
|
||||
Simulation.SendInput.Mouse.XButtonDown(0x0001);
|
||||
break;
|
||||
default:
|
||||
Simulation.SendInput.Keyboard.KeyDown(vk);
|
||||
if (InputBuilder.IsExtendedKey(vk))
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyDown(false, vk);
|
||||
}
|
||||
else
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyDown(vk);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -69,7 +78,14 @@ public class GlobalMethod
|
||||
Simulation.SendInput.Mouse.XButtonUp(0x0001);
|
||||
break;
|
||||
default:
|
||||
Simulation.SendInput.Keyboard.KeyUp(vk);
|
||||
if (InputBuilder.IsExtendedKey(vk))
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyUp(false, vk);
|
||||
}
|
||||
else
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyUp(vk);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -112,7 +128,6 @@ public class GlobalMethod
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion 键盘操作
|
||||
|
||||
#region 鼠标操作
|
||||
@@ -217,4 +232,43 @@ public class GlobalMethod
|
||||
}
|
||||
|
||||
#endregion 识图操作
|
||||
}
|
||||
|
||||
#region 文字输入操作
|
||||
|
||||
public static void InputText(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 保存当前剪贴板内容
|
||||
string originalClipboardText = Clipboard.GetText();
|
||||
|
||||
try
|
||||
{
|
||||
// 将要输入的文本复制到剪贴板
|
||||
Clipboard.SetText(text);
|
||||
|
||||
// 模拟Ctrl+V粘贴操作
|
||||
Simulation.SendInput.Keyboard.KeyDown(false, VK.VK_CONTROL);
|
||||
Sleep(20);
|
||||
Simulation.SendInput.Keyboard.KeyPress(VK.VK_V);
|
||||
Sleep(20);
|
||||
Simulation.SendInput.Keyboard.KeyUp(false, VK.VK_CONTROL);
|
||||
|
||||
// 等待一小段时间确保粘贴完成
|
||||
Sleep(100);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// 恢复原始剪贴板内容
|
||||
if (!string.IsNullOrEmpty(originalClipboardText))
|
||||
{
|
||||
Clipboard.SetText(originalClipboardText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion 文字输入操作
|
||||
}
|
||||
@@ -72,4 +72,153 @@ public class LimitedFile(string rootPath)
|
||||
var mat = Mat.FromStream(File.OpenRead(path), ImreadModes.Color);
|
||||
return mat;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 允许的文件扩展名白名单
|
||||
/// </summary>
|
||||
private readonly string[] _allowedExtensions = [".txt", ".json", ".log", ".csv", ".xml", ".html", ".css"];
|
||||
|
||||
/// <summary>
|
||||
/// 最大允许的文件大小(字节)
|
||||
/// </summary>
|
||||
private const long MaxFileSize = 999 * 1024 * 1024; // 999 MB
|
||||
|
||||
/// <summary>
|
||||
/// 验证路径和内容是否合法,并确保目录存在
|
||||
/// </summary>
|
||||
/// <param name="path">文件路径</param>
|
||||
/// <param name="content">要写入的内容,如果为null则只验证路径</param>
|
||||
/// <returns>是否合法</returns>
|
||||
private bool IsValid(string path, string? content = null)
|
||||
{
|
||||
// 验证文件扩展名
|
||||
string extension = Path.GetExtension(path).ToLower();
|
||||
if (!Array.Exists(_allowedExtensions, ext => ext == extension))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 确保目录存在
|
||||
var normalizedPath = NormalizePath(path);
|
||||
string? directoryPath = Path.GetDirectoryName(normalizedPath);
|
||||
if (!string.IsNullOrEmpty(directoryPath) && !Directory.Exists(directoryPath))
|
||||
{
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
}
|
||||
|
||||
// 如果提供了内容,验证内容是否合法
|
||||
if (content != null)
|
||||
{
|
||||
// 检查文件大小
|
||||
if (content.Length > MaxFileSize)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步写入文本到文件
|
||||
/// </summary>
|
||||
/// <param name="path">文件路径</param>
|
||||
/// <param name="content">要写入的内容</param>
|
||||
/// <param name="append">是否追加到文件末尾,默认为false(覆盖)</param>
|
||||
/// <returns>是否写入成功</returns>
|
||||
public bool WriteTextSync(string path, string content, bool append = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
path = NormalizePath(path);
|
||||
if (!IsValid(path, content))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (append && File.Exists(path))
|
||||
{
|
||||
File.AppendAllText(path, content);
|
||||
}
|
||||
else
|
||||
{
|
||||
File.WriteAllText(path, content);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步写入文本到文件
|
||||
/// </summary>
|
||||
/// <param name="path">文件路径</param>
|
||||
/// <param name="content">要写入的内容</param>
|
||||
/// <param name="append">是否追加到文件末尾,默认为false(覆盖)</param>
|
||||
/// <returns>是否写入成功</returns>
|
||||
public async Task<bool> WriteText(string path, string content, bool append = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
path = NormalizePath(path);
|
||||
if (!IsValid(path, content))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (append && File.Exists(path))
|
||||
{
|
||||
await File.AppendAllTextAsync(path, content);
|
||||
}
|
||||
else
|
||||
{
|
||||
await File.WriteAllTextAsync(path, content);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步写入文本到文件(带回调)
|
||||
/// </summary>
|
||||
/// <param name="path">文件路径</param>
|
||||
/// <param name="content">要写入的内容</param>
|
||||
/// <param name="callbackFunc">回调函数</param>
|
||||
/// <param name="append">是否追加到文件末尾,默认为false(覆盖)</param>
|
||||
/// <returns>是否写入成功</returns>
|
||||
public async Task<bool> WriteText(string path, string content, dynamic callbackFunc, bool append = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
path = NormalizePath(path);
|
||||
if (!IsValid(path, content))
|
||||
{
|
||||
callbackFunc("路径不合法或文件内容不合法", null);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (append && File.Exists(path))
|
||||
{
|
||||
await File.AppendAllTextAsync(path, content);
|
||||
}
|
||||
else
|
||||
{
|
||||
await File.WriteAllTextAsync(path, content);
|
||||
}
|
||||
callbackFunc(null, true);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
callbackFunc(ex.ToString(), null);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoArtifactSalvage;
|
||||
|
||||
[Serializable]
|
||||
public partial class AutoArtifactSalvageConfig : ObservableObject
|
||||
{
|
||||
// 正则表达式
|
||||
[ObservableProperty]
|
||||
private string _regularExpression = @"(?=[\S\s]*攻击力\+[\d]*\n)(?=[\S\s]*防御力\+[\d]*\n)";
|
||||
|
||||
// 快速分解圣遗物的最大星级
|
||||
// 1~4
|
||||
[ObservableProperty]
|
||||
private string _maxArtifactStar = "4";
|
||||
|
||||
// 最多检查多少个圣遗物
|
||||
[ObservableProperty]
|
||||
private int _maxNumToCheck = 100;
|
||||
}
|
||||
@@ -0,0 +1,453 @@
|
||||
using BetterGenshinImpact.GameTask.Common.BgiVision;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Recognition;
|
||||
using BetterGenshinImpact.Core.Simulator;
|
||||
using BetterGenshinImpact.GameTask.Common.Element.Assets;
|
||||
using BetterGenshinImpact.Helpers.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Vanara.PInvoke;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
using BetterGenshinImpact.Core.Simulator.Extensions;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System.Globalization;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using System.Text.RegularExpressions;
|
||||
using BetterGenshinImpact.GameTask.Model.Area;
|
||||
using System.Collections.Generic;
|
||||
using Fischless.WindowsInput;
|
||||
using OpenCvSharp;
|
||||
using System.Linq;
|
||||
using BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
using BetterGenshinImpact.Core.Recognition.OCR;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.GameTask.Common.Job;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoArtifactSalvage;
|
||||
|
||||
/// <summary>
|
||||
/// 圣遗物自动分解
|
||||
/// </summary>
|
||||
public class AutoArtifactSalvageTask : ISoloTask
|
||||
{
|
||||
private readonly ILogger logger = App.GetLogger<AutoArtifactSalvageTask>();
|
||||
private readonly InputSimulator input = Simulation.SendInput;
|
||||
private readonly ReturnMainUiTask _returnMainUiTask = new();
|
||||
|
||||
private CancellationToken ct;
|
||||
|
||||
public string Name => "圣遗物分解独立任务";
|
||||
|
||||
private readonly int star;
|
||||
|
||||
private readonly string quickSelectLocalizedString;
|
||||
|
||||
private readonly string[] numOfStarLocalizedString;
|
||||
|
||||
private readonly string? regularExpression;
|
||||
|
||||
private readonly int? maxNumToCheck;
|
||||
|
||||
public AutoArtifactSalvageTask(int star, string? regularExpression = null, int? maxNumToCheck = null)
|
||||
{
|
||||
this.star = star;
|
||||
this.regularExpression = regularExpression;
|
||||
this.maxNumToCheck = maxNumToCheck;
|
||||
IStringLocalizer<AutoArtifactSalvageTask> stringLocalizer = App.GetService<IStringLocalizer<AutoArtifactSalvageTask>>() ?? throw new NullReferenceException();
|
||||
CultureInfo cultureInfo = new CultureInfo(TaskContext.Instance().Config.OtherConfig.GameCultureInfoName);
|
||||
quickSelectLocalizedString = stringLocalizer.WithCultureGet(cultureInfo, "快速选择");
|
||||
numOfStarLocalizedString = [
|
||||
stringLocalizer.WithCultureGet(cultureInfo, "1星圣遗物"),
|
||||
stringLocalizer.WithCultureGet(cultureInfo, "2星圣遗物"),
|
||||
stringLocalizer.WithCultureGet(cultureInfo, "3星圣遗物"),
|
||||
stringLocalizer.WithCultureGet(cultureInfo, "4星圣遗物")
|
||||
];
|
||||
}
|
||||
|
||||
public async Task Start(CancellationToken ct)
|
||||
{
|
||||
this.ct = ct;
|
||||
await _returnMainUiTask.Start(ct);
|
||||
|
||||
// B键打开背包
|
||||
input.SimulateAction(GIActions.OpenInventory);
|
||||
await Delay(1000, ct);
|
||||
|
||||
var openBagSuccess = await NewRetry.WaitForAction(() =>
|
||||
{
|
||||
// 选择圣遗物
|
||||
using var ra = CaptureToRectArea();
|
||||
using var artifactBtn = ra.Find(ElementAssets.Instance.BagArtifactChecked);
|
||||
if (artifactBtn.IsEmpty())
|
||||
{
|
||||
using var artifactBtn2 = ra.Find(ElementAssets.Instance.BagArtifactUnchecked);
|
||||
if (artifactBtn2.IsExist())
|
||||
{
|
||||
artifactBtn2.Click();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 如果还在主界面就尝试再按下B键打开背包
|
||||
if (Bv.IsInMainUi(ra))
|
||||
{
|
||||
Debug.WriteLine("背包打开失败,再次尝试打开背包");
|
||||
input.SimulateAction(GIActions.OpenInventory);
|
||||
}
|
||||
|
||||
return false;
|
||||
}, ct, 5);
|
||||
|
||||
if (!openBagSuccess)
|
||||
{
|
||||
logger.LogError("未找到背包中圣遗物菜单按钮,打开背包失败");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
await Delay(800, ct);
|
||||
|
||||
// 点击分解按钮打开分解界面
|
||||
using var ra2 = CaptureToRectArea();
|
||||
using var salvageBtn = ra2.Find(ElementAssets.Instance.BtnArtifactSalvage);
|
||||
if (salvageBtn.IsExist())
|
||||
{
|
||||
salvageBtn.Click();
|
||||
await Delay(1000, ct);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogError("未找到圣遗物分解按钮");
|
||||
return;
|
||||
}
|
||||
|
||||
// 快速选择
|
||||
using var ra3 = CaptureToRectArea();
|
||||
var ocrList = ra3.FindMulti(RecognitionObject.Ocr(ra3.ToRect().CutLeftBottom(0.25, 0.1)));
|
||||
foreach (var ocr in ocrList)
|
||||
{
|
||||
if (Regex.IsMatch(ocr.Text, quickSelectLocalizedString))
|
||||
{
|
||||
ocr.Click();
|
||||
await Delay(500, ct);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 确认选择
|
||||
// 5.5 变成反选
|
||||
using var ra4 = CaptureToRectArea();
|
||||
if (star < 4)
|
||||
{
|
||||
List<Region> ocrList2 = ra4.FindMulti(RecognitionObject.Ocr(ra4.ToRect().CutLeft(0.20)));
|
||||
for (int i = star; i < 4; i++)
|
||||
{
|
||||
foreach (var ocr in ocrList2)
|
||||
{
|
||||
if (Regex.IsMatch(ocr.Text, numOfStarLocalizedString[i]))
|
||||
{
|
||||
ocr.Click();
|
||||
await Delay(500, ct);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Bv.ClickWhiteConfirmButton(ra4);
|
||||
await Delay(500, ct);
|
||||
|
||||
|
||||
// 点击分解
|
||||
using var ra5 = CaptureToRectArea();
|
||||
var salvageBtnConfirm = ra5.Find(ElementAssets.Instance.BtnArtifactSalvageConfirm);
|
||||
if (salvageBtnConfirm.IsExist())
|
||||
{
|
||||
salvageBtnConfirm.Click();
|
||||
await Delay(800, ct);
|
||||
// 点击确认
|
||||
using var ra6 = CaptureToRectArea();
|
||||
if (Bv.ClickBlackConfirmButton(ra6))
|
||||
{
|
||||
logger.LogInformation("完成{Star}星圣遗物快速分解", star);
|
||||
await Delay(400, ct);
|
||||
if (regularExpression != null)
|
||||
{
|
||||
input.Mouse.LeftButtonClick();
|
||||
await Delay(1000, ct);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogInformation("未找到进行分解按钮,可能发生了卡顿");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogInformation("未找到圣遗物分解按钮,可能已经没有圣遗物需要快速分解");
|
||||
}
|
||||
|
||||
// 分解5星
|
||||
if (regularExpression != null)
|
||||
{
|
||||
await Salvage5Star(this.regularExpression, this.maxNumToCheck ?? throw new ArgumentException($"{nameof(this.maxNumToCheck)}不能为空"));
|
||||
logger.LogInformation("筛选完毕,请复查并手动分解");
|
||||
}
|
||||
else
|
||||
{
|
||||
input.Keyboard.KeyPress(User32.VK.VK_ESCAPE);
|
||||
|
||||
await _returnMainUiTask.Start(ct);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async Task Salvage5Star(string regularExpression, int maxNumToCheck)
|
||||
{
|
||||
int count = maxNumToCheck;
|
||||
Queue<string> checkedArtifactAffixesQueue = new Queue<string>();
|
||||
int duplicateSum = 0;
|
||||
while (count > 0 && duplicateSum < 3)
|
||||
{
|
||||
// VisionContext.Instance().DrawContent.ClearAll();
|
||||
// await Delay(400, this.ct);
|
||||
|
||||
using var ra = CaptureToRectArea();
|
||||
using ImageRegion grid = ra.DeriveCrop(new Rect((int)(ra.Width * 0.025), (int)(ra.Width * 0.055), (int)(ra.Width * 0.66), (int)(ra.Width * 0.4)));
|
||||
IEnumerable<Rect> gridItems = GetArtifactGridItems(grid.SrcMat);
|
||||
|
||||
//foreach (Rect item in gridItems)
|
||||
//{
|
||||
// grid.DrawRect(item, item.GetHashCode().ToString(), new System.Drawing.Pen(System.Drawing.Color.Blue));
|
||||
//}
|
||||
|
||||
bool anyItemChecked = false;
|
||||
foreach (Rect item in gridItems)
|
||||
{
|
||||
using ImageRegion itemRegion = grid.DeriveCrop(item);
|
||||
if (GetArtifactStatus(itemRegion.SrcMat) == ArtifactStatus.None)
|
||||
{
|
||||
anyItemChecked = true;
|
||||
itemRegion.Click();
|
||||
await Delay(300, ct);
|
||||
|
||||
using var ra1 = CaptureToRectArea();
|
||||
using ImageRegion grid1 = ra1.DeriveCrop(new Rect((int)(ra1.Width * 0.025), (int)(ra1.Width * 0.055), (int)(ra1.Width * 0.66), (int)(ra1.Width * 0.4)));
|
||||
using ImageRegion itemRegion1 = grid1.DeriveCrop(item);
|
||||
if (GetArtifactStatus(itemRegion1.SrcMat) == ArtifactStatus.Selected)
|
||||
{
|
||||
using ImageRegion card = ra1.DeriveCrop(new Rect((int)(ra1.Width * 0.70), (int)(ra1.Width * 0.055), (int)(ra1.Width * 0.24), (int)(ra1.Width * 0.29)));
|
||||
string affixes = GetArtifactAffixes(card.SrcMat, OcrFactory.Paddle);
|
||||
|
||||
if (checkedArtifactAffixesQueue.Any(c => c == affixes))
|
||||
{
|
||||
duplicateSum++;
|
||||
logger.LogInformation($"重复检查了该圣遗物");
|
||||
}
|
||||
if (checkedArtifactAffixesQueue.Count >= 36) // 一个grid最多能看到36个完整的圣遗物
|
||||
{
|
||||
checkedArtifactAffixesQueue.Dequeue();
|
||||
}
|
||||
checkedArtifactAffixesQueue.Enqueue(affixes);
|
||||
|
||||
if (IsMatchRegularExpression(affixes, regularExpression, out string msg))
|
||||
{
|
||||
logger.LogInformation(message: msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemRegion.Click();
|
||||
await Delay(100, ct);
|
||||
}
|
||||
if (duplicateSum >= 3)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
count--;
|
||||
if (count <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count <= 0 || duplicateSum >= 3)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (anyItemChecked)
|
||||
{
|
||||
for (int i = 0; i < 32; i++) // 先滚动大约三行半
|
||||
{
|
||||
input.Mouse.VerticalScroll(-2);
|
||||
await Delay(40, ct);
|
||||
}
|
||||
|
||||
DateTimeOffset rollingEndTime = DateTime.Now.AddSeconds(2);
|
||||
while (DateTime.Now < rollingEndTime)
|
||||
{
|
||||
await Delay(60, ct);
|
||||
using var ra2 = CaptureToRectArea();
|
||||
using ImageRegion grid2 = ra2.DeriveCrop(new Rect((int)(ra2.Width * 0.025), (int)(ra2.Width * 0.055), (int)(ra2.Width * 0.66), (int)(ra2.Width * 0.4)));
|
||||
IEnumerable<Rect> gridItems2 = GetArtifactGridItems(grid2.SrcMat);
|
||||
if (gridItems2.Min(i => i.Y) > (ra2.Width * 0.018)) // 精细滚动,保证完整地显示四行
|
||||
{
|
||||
input.Mouse.VerticalScroll(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
grid.MoveTo(grid.Width, grid.Height);
|
||||
await Delay(500, ct);
|
||||
}
|
||||
else
|
||||
{
|
||||
await Delay(400, ct);
|
||||
logger.LogInformation("找不到可检查的圣遗物了");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (count <= 0)
|
||||
{
|
||||
logger.LogInformation("检查次数已耗尽");
|
||||
}
|
||||
if (duplicateSum >= 3)
|
||||
{
|
||||
logger.LogInformation("重复检查次数过多,推断为找不到可检查的了");
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsMatchRegularExpression(string affixes, string regularExpression, out string msg)
|
||||
{
|
||||
Match match = Regex.Match(affixes, regularExpression);
|
||||
if (match.Success)
|
||||
{
|
||||
if (string.IsNullOrEmpty(match.Value))
|
||||
{
|
||||
msg = "匹配成功!";
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = $"匹配成功:{match.Value}";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = "匹配失败!";
|
||||
}
|
||||
return match.Success;
|
||||
}
|
||||
|
||||
public static string GetArtifactAffixes(Mat src, IOcrService ocrService)
|
||||
{
|
||||
var ocrResult = ocrService.OcrResult(src);
|
||||
return ocrResult.Text;
|
||||
}
|
||||
|
||||
public static IEnumerable<Rect> GetArtifactGridItems(Mat src)
|
||||
{
|
||||
using Mat grey = src.CvtColor(ColorConversionCodes.BGR2GRAY);
|
||||
|
||||
using Mat canny = grey.Canny(20, 40);
|
||||
|
||||
Cv2.FindContours(canny, out var contours, out _, RetrievalModes.External,
|
||||
ContourApproximationModes.ApproxSimple, null);
|
||||
|
||||
IEnumerable<Rect> boxes = contours.Where(c => Cv2.MinAreaRect(c).Angle % 90 <= 1) // 剔除倾斜
|
||||
.Select(Cv2.BoundingRect).Where(r =>
|
||||
{
|
||||
if (r.Height == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return Math.Abs((float)r.Width / r.Height - 0.8) < 0.05; // 按形状筛选
|
||||
}).ToList();
|
||||
|
||||
//src.DrawContours(contours, -1, Scalar.Red);
|
||||
|
||||
int biggestRectHeight = boxes.Max(b => b.Height);
|
||||
boxes = boxes.Where(b => (float)b.Height / biggestRectHeight > 0.88); // 剔除太小的
|
||||
|
||||
return boxes.ToArray();
|
||||
}
|
||||
|
||||
public static ArtifactStatus GetArtifactStatus(Mat src)
|
||||
{
|
||||
using Mat upperLine = new Mat(src, new Rect(0, 0, src.Width, (int)(src.Height * 0.19)));
|
||||
//using Mat hsvMat = upperLine.CvtColor(ColorConversionCodes.BGR2HSV_FULL);
|
||||
//var pixel_hsv_pink = hsvMat.At<Vec3b>(17, 12); // 注意是(Y,X)
|
||||
//var pixel_hsv_grren = hsvMat.At<Vec3b>(8, 105); // 注意是(Y,X)
|
||||
|
||||
// 粉色锁
|
||||
Scalar pinkhsv = OpenCvCommonHelper.CommonHSV2OpenCVHSVFull(new Scalar(9, 0.54, 1.00));
|
||||
var lowPink = new Scalar(pinkhsv.Val0 - 3, pinkhsv.Val1 - 25, pinkhsv.Val2 - 25);
|
||||
var highPink = new Scalar(pinkhsv.Val0 + 3, pinkhsv.Val1 + 25, pinkhsv.Val2);
|
||||
using Mat pinkMask = OpenCvCommonHelper.InRangeHsvFull(upperLine, lowPink, highPink);
|
||||
|
||||
using Mat pinkThreshold = pinkMask.Threshold(0, 255, ThresholdTypes.Binary); //二值化
|
||||
|
||||
Cv2.FindContours(pinkThreshold, out var contours, out _, RetrievalModes.External,
|
||||
ContourApproximationModes.ApproxSimple, null);
|
||||
|
||||
var allPinkContours = contours.Where(c => c.Max(p => p.X) < pinkMask.Width * 0.2) // 都在左侧
|
||||
.SelectMany(c => c); // 拼凑零碎的像素
|
||||
if (allPinkContours.Any())
|
||||
{
|
||||
var bounding = Cv2.BoundingRect(allPinkContours);
|
||||
if (bounding.Width > pinkMask.Width * 0.07 && bounding.Height > pinkMask.Height * 0.3) //不能太小
|
||||
{
|
||||
return ArtifactStatus.Locked;
|
||||
}
|
||||
}
|
||||
|
||||
// 绿色线
|
||||
Scalar greenhsv = OpenCvCommonHelper.CommonHSV2OpenCVHSVFull(new Scalar(80, 0.76, 1.00));
|
||||
var lowGreen = new Scalar(greenhsv.Val0 - 3, greenhsv.Val1 - 10, greenhsv.Val2 - 5);
|
||||
var highGreen = new Scalar(greenhsv.Val0 + 3, greenhsv.Val1 + 10, greenhsv.Val2);
|
||||
using Mat greenMask = OpenCvCommonHelper.InRangeHsvFull(upperLine, lowGreen, highGreen);
|
||||
|
||||
Cv2.Threshold(greenMask, greenMask, 0, 255, ThresholdTypes.Binary); //二值化
|
||||
|
||||
Cv2.FindContours(greenMask, out contours, out _, RetrievalModes.External,
|
||||
ContourApproximationModes.ApproxSimple, null);
|
||||
|
||||
var allGreenContours = contours.SelectMany(c => c); // 拼凑零碎的像素
|
||||
if (allGreenContours.Any())
|
||||
{
|
||||
var bounding = Cv2.BoundingRect(allGreenContours);
|
||||
if (bounding.Width > greenMask.Width * 0.2 && bounding.Height > greenMask.Height * 0.8) //不能太小;至少存在右上角勾号的绿色背景,忽略上底边的绿线(因有缩放动画,每次都要重新框定不利缩减步骤)
|
||||
{
|
||||
return ArtifactStatus.Selected;
|
||||
}
|
||||
}
|
||||
|
||||
return ArtifactStatus.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 圣遗物分解界面Grid元素的状态
|
||||
/// </summary>
|
||||
public enum ArtifactStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// 啥也没有
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// 左上角有粉色锁定标记
|
||||
/// </summary>
|
||||
Locked,
|
||||
/// <summary>
|
||||
/// 上下有绿色选择框
|
||||
/// </summary>
|
||||
Selected
|
||||
}
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -47,9 +47,4 @@ public partial class AutoDomainConfig : ObservableObject
|
||||
// 结束后是否自动分解圣遗物
|
||||
[ObservableProperty]
|
||||
private bool _autoArtifactSalvage = false;
|
||||
|
||||
// 分解圣遗物的最大星级
|
||||
// 1~4
|
||||
[ObservableProperty]
|
||||
private string _maxArtifactStar = "4";
|
||||
}
|
||||
@@ -40,6 +40,6 @@ public class AutoDomainParam : BaseTaskParam
|
||||
PartyName = config.PartyName;
|
||||
DomainName = config.DomainName;
|
||||
AutoArtifactSalvage = config.AutoArtifactSalvage;
|
||||
MaxArtifactStar = config.MaxArtifactStar;
|
||||
MaxArtifactStar = TaskContext.Instance().Config.AutoArtifactSalvageConfig.MaxArtifactStar;
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,6 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Recognition;
|
||||
using BetterGenshinImpact.GameTask.AutoTrackPath;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.GameTask.Common.BgiVision;
|
||||
using BetterGenshinImpact.GameTask.Common.Element.Assets;
|
||||
using BetterGenshinImpact.GameTask.Common.Job;
|
||||
@@ -39,6 +38,7 @@ using static Vanara.PInvoke.User32;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using BetterGenshinImpact.GameTask.AutoArtifactSalvage;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoDomain;
|
||||
|
||||
@@ -1058,6 +1058,6 @@ public class AutoDomainTask : ISoloTask
|
||||
star = 4;
|
||||
}
|
||||
|
||||
await new ArtifactSalvageTask(star).Start(_ct);
|
||||
await new AutoArtifactSalvageTask(star).Start(_ct);
|
||||
}
|
||||
}
|
||||
@@ -209,34 +209,18 @@ public class AutoFightTask : ISoloTask
|
||||
|
||||
// var actionSchedulerByCd = ParseStringToDictionary(_taskParam.ActionSchedulerByCd);
|
||||
var combatCommands = _combatScriptBag.FindCombatScript(combatScenes.GetAvatars());
|
||||
// 命令用到的角色 筛选交集
|
||||
var commandAvatars = combatCommands.Select(c => c.Name).Distinct()
|
||||
.Select(n => combatScenes.SelectAvatar(n))
|
||||
.WhereNotNull().ToImmutableDictionary(avatar => avatar.Name);
|
||||
// 命令用到的角色名 筛选交集
|
||||
var commandAvatarNames = combatCommands.Select(c => c.Name).Distinct()
|
||||
.Select(n => combatScenes.SelectAvatar(n)?.Name)
|
||||
.WhereNotNull().ToList();
|
||||
// 过滤不可执行的脚本,Task里并不支持"当前角色"。
|
||||
combatCommands = combatCommands
|
||||
.Where(c =>commandAvatars.ContainsKey(c.Name))
|
||||
.Where(c => commandAvatarNames.Contains(c.Name))
|
||||
.ToList();
|
||||
if (commandAvatars.IsEmpty)
|
||||
if (commandAvatarNames.Count <= 0)
|
||||
{
|
||||
throw new Exception("没有可用战斗脚本");
|
||||
}
|
||||
// 可以跳过的角色名
|
||||
List<string> canBeSkippedAvatarNames = [];
|
||||
// 通过环境更新角色的cd并看看那些角色启用了跳过
|
||||
foreach (var avatar in commandAvatars)
|
||||
{
|
||||
var mCd = Avatar.ParseActionSchedulerByCd(_taskParam.ActionSchedulerByCd, avatar.Key);
|
||||
if (mCd is not null)
|
||||
{
|
||||
avatar.Value.ManualSkillCd = (double)mCd;
|
||||
canBeSkippedAvatarNames.Add(avatar.Key);
|
||||
}
|
||||
else
|
||||
{
|
||||
avatar.Value.ManualSkillCd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// 新的取消token
|
||||
var cts2 = new CancellationTokenSource();
|
||||
@@ -259,6 +243,14 @@ public class AutoFightTask : ISoloTask
|
||||
|
||||
//统计切换人打架次数
|
||||
var countFight = 0;
|
||||
|
||||
// 可以跳过的角色名,配置中有的和命令中有的取交
|
||||
var canBeSkippedAvatarNames = combatScenes.UpdateActionSchedulerByCd(_taskParam.ActionSchedulerByCd)
|
||||
.Where(s => commandAvatarNames.Contains(s)).WhereNotNull().ToList();
|
||||
|
||||
//所有角色是否都可被跳过
|
||||
var allCanBeSkipped = commandAvatarNames.All(a => canBeSkippedAvatarNames.Contains(a));
|
||||
|
||||
// 战斗操作
|
||||
var fightTask = Task.Run(async () =>
|
||||
{
|
||||
@@ -266,34 +258,59 @@ public class AutoFightTask : ISoloTask
|
||||
{
|
||||
while (!cts2.Token.IsCancellationRequested)
|
||||
{
|
||||
if (commandAvatars.Count == canBeSkippedAvatarNames.Count)
|
||||
// 所有战斗角色都可以被取消
|
||||
|
||||
#region 本次战斗的跳过战斗判定
|
||||
|
||||
//如果所有角色都可以被跳过,且没有任何一个cd大于0的(技能都还没好)
|
||||
//则强制等待,因为不等待的话什么都不能做,而且会造成刷屏
|
||||
if (allCanBeSkipped)
|
||||
{
|
||||
// 所有战斗角色都可以被取消
|
||||
var minCoolDown = commandAvatars.Select(a => a.Value.GetSkillCdSeconds()).Min();
|
||||
//获取最低cd
|
||||
var minCoolDown = commandAvatarNames.Select(a => combatScenes.SelectAvatar(a)).WhereNotNull()
|
||||
.Select(a => a.GetSkillCdSeconds()).Min();
|
||||
if (minCoolDown > 0)
|
||||
{
|
||||
Logger.LogInformation("队伍中所有角色的技能都在冷却中,等待{MinCoolDown}秒后继续。", Math.Round(minCoolDown, 2));
|
||||
await Delay((int)Math.Ceiling(minCoolDown * 1000), ct);
|
||||
}
|
||||
}
|
||||
|
||||
var skipFightName = "";
|
||||
// 通用化战斗策略
|
||||
|
||||
#endregion
|
||||
|
||||
for (var i = 0; i < combatCommands.Count; i++)
|
||||
{
|
||||
var command = combatCommands[i];
|
||||
//如果上个执行者和这次是一个角色,且中间没有跳过,继续执行不判断cd
|
||||
if (lastFightName != command.Name || skipFightName != "")
|
||||
{
|
||||
var avatar = combatScenes.SelectAvatar(command.Name);
|
||||
if (avatar is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var avatar = combatScenes.SelectAvatar(command.Name);
|
||||
if (avatar is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
#region 每个命令的跳过战斗判定
|
||||
|
||||
// 判断是否满足跳过条件:
|
||||
// 1.上一次成功执行命令的最后执行角色不是这次的执行角色
|
||||
// 2.这次执行的角色包含在可跳过的角色列表中
|
||||
if (!
|
||||
//上次命令的执行角色和这次相同
|
||||
(lastFightName == command.Name &&
|
||||
// 且未跳过(成功执行)了,则不进行跳过判定
|
||||
skipFightName == "")
|
||||
&&
|
||||
// 且这次执行的角色包含在可跳过的角色列表中
|
||||
(allCanBeSkipped || canBeSkippedAvatarNames.Contains(command.Name))
|
||||
)
|
||||
{
|
||||
var cd = avatar.GetSkillCdSeconds();
|
||||
if (cd > 0)
|
||||
{
|
||||
if (skipFightName != command.Name && canBeSkippedAvatarNames.Contains(command.Name))
|
||||
// 如果上一次该角色已经被跳过,则不进行log输出,以免刷屏
|
||||
if (skipFightName != command.Name)
|
||||
{
|
||||
var manualSkillCd = avatar.ManualSkillCd;
|
||||
if (manualSkillCd > 0)
|
||||
@@ -313,9 +330,12 @@ public class AutoFightTask : ISoloTask
|
||||
skipFightName = command.Name;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 表示这次执行命令没有跳过
|
||||
skipFightName = "";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
if (timeoutStopwatch.Elapsed > fightTimeout)
|
||||
{
|
||||
@@ -324,6 +344,7 @@ public class AutoFightTask : ISoloTask
|
||||
break;
|
||||
}
|
||||
|
||||
// 通用化战斗策略
|
||||
command.Execute(combatScenes);
|
||||
//统计战斗人次
|
||||
if (i == combatCommands.Count - 1 || command.Name != combatCommands[i + 1].Name)
|
||||
|
||||
@@ -430,7 +430,8 @@ public class Avatar
|
||||
var cd = AfterUseSkill(region);
|
||||
if (cd > 0)
|
||||
{
|
||||
Logger.LogInformation(hold ? "{Name} 长按元素战技,cd:{Cd}" : "{Name} 点按元素战技,cd:{Cd}", Name, cd);
|
||||
Logger.LogInformation(hold ? "{Name} 长按元素战技,cd:{Cd} 秒" : "{Name} 点按元素战技,cd:{Cd} 秒", Name,
|
||||
Math.Round(cd, 2));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -883,10 +884,10 @@ public class Avatar
|
||||
/// 从配置字符串中查找角色cd
|
||||
/// 仅有角色名时返回 -1 ,没找到角色返回null
|
||||
/// </summary>
|
||||
/// <param name="input">序列</param>
|
||||
/// <param name="avatarName">角色名</param>
|
||||
/// <param name="input">序列</param>
|
||||
/// <returns></returns>
|
||||
public static double? ParseActionSchedulerByCd(string input, string avatarName)
|
||||
public static double? ParseActionSchedulerByCd(string avatarName, string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input) || string.IsNullOrEmpty(avatarName))
|
||||
return null;
|
||||
|
||||
@@ -255,6 +255,31 @@ public class CombatScenes : IDisposable
|
||||
return avatars;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新角色手动设置的CD
|
||||
/// </summary>
|
||||
/// <param name="cdConfig">配置字符串</param>
|
||||
/// <returns>返回配置中有效的角色名</returns>
|
||||
public List<string> UpdateActionSchedulerByCd(string cdConfig)
|
||||
{
|
||||
if (string.IsNullOrEmpty(cdConfig))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
List<string> names = [];
|
||||
foreach (var t in Avatars)
|
||||
{
|
||||
var mCd = Avatar.ParseActionSchedulerByCd(t.Name, cdConfig);
|
||||
// 手动cd不为0,不是麦当劳不是0
|
||||
if (mCd is null) continue;
|
||||
t.ManualSkillCd = (double)mCd;
|
||||
names.Add(t.Name);
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
public void BeforeTask(CancellationToken ct)
|
||||
{
|
||||
for (var i = 0; i < AvatarCount; i++)
|
||||
@@ -315,7 +340,7 @@ public class CombatScenes : IDisposable
|
||||
{
|
||||
return Avatar.LastActiveAvatar;
|
||||
}
|
||||
|
||||
|
||||
var imageRegion = region ?? CaptureToRectArea();
|
||||
string? avatarName = null;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using OpenCvSharp;
|
||||
using BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -18,16 +19,17 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
|
||||
try
|
||||
{
|
||||
// 拉条框的黄色是:RGB 255, 255, 192 ~ HSV 43, 63, 255
|
||||
// var testPixel = rgbMat.At<Vec3b>(105, 968);
|
||||
using Mat rgbMat = src.CvtColor(ColorConversionCodes.BGR2HSV_FULL);
|
||||
// var testPixel = src.At<Vec3b>(105, 968); // 注意是(Y,X)
|
||||
// using Mat rgbMat = src.CvtColor(ColorConversionCodes.BGR2HSV_FULL);
|
||||
// var testPixelHSV = rgbMat.At<Vec3b>(105, 968); // 注意是(Y,X)
|
||||
Scalar hsv = OpenCvCommonHelper.CommonHSV2OpenCVHSVFull(new Scalar(60, 0.25, 1.00));
|
||||
var lowYellow = new Scalar(hsv.Val0 - 3, hsv.Val1 - 20, hsv.Val2 - 10);
|
||||
var highYellow = new Scalar(hsv.Val0 + 3.5, hsv.Val1 + 40, hsv.Val2);
|
||||
using Mat mask = OpenCvCommonHelper.InRangeHsvFull(src, lowYellow, highYellow);
|
||||
|
||||
var lowYellow = new Scalar(43 - 3, 63 - 20, 255 - 10);
|
||||
var highYellow = new Scalar(43 + 3, 63 + 40, 255);
|
||||
using Mat mask = rgbMat.InRange(lowYellow, highYellow);
|
||||
using Mat threshold = mask.Threshold(0, 255, ThresholdTypes.Binary); //二值化
|
||||
|
||||
Cv2.Threshold(mask, mask, 0, 255, ThresholdTypes.Binary); //二值化
|
||||
|
||||
Cv2.FindContours(mask, out var contours, out _, RetrievalModes.External,
|
||||
Cv2.FindContours(threshold, out var contours, out _, RetrievalModes.External,
|
||||
ContourApproximationModes.ApproxSimple, null);
|
||||
if (contours.Length > 0)
|
||||
{
|
||||
|
||||
@@ -392,6 +392,10 @@ public class TpTask(CancellationToken ct)
|
||||
// throw; // 不抛出异常,继续重试
|
||||
Logger.LogWarning(e.Message + " 重试");
|
||||
}
|
||||
catch (Exception e) when (e is NormalEndException || e is TaskCanceledException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("传送失败,重试 {I} 次", i + 1);
|
||||
|
||||
@@ -1,173 +0,0 @@
|
||||
using BetterGenshinImpact.GameTask.Common.BgiVision;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Recognition;
|
||||
using BetterGenshinImpact.Core.Simulator;
|
||||
using BetterGenshinImpact.GameTask.Common.Element.Assets;
|
||||
using BetterGenshinImpact.Helpers.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Vanara.PInvoke;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
using BetterGenshinImpact.Core.Simulator.Extensions;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System.Globalization;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using System.Text.RegularExpressions;
|
||||
using BetterGenshinImpact.GameTask.Model.Area;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.Common.Job;
|
||||
|
||||
/// <summary>
|
||||
/// 圣遗物自动分解
|
||||
/// </summary>
|
||||
public class ArtifactSalvageTask : ISoloTask
|
||||
{
|
||||
private readonly ReturnMainUiTask _returnMainUiTask = new();
|
||||
|
||||
public string Name => "圣遗物分解独立任务";
|
||||
|
||||
private readonly int star;
|
||||
|
||||
private readonly string quickSelectLocalizedString;
|
||||
|
||||
private readonly string[] numOfStarLocalizedString;
|
||||
|
||||
public ArtifactSalvageTask(int star)
|
||||
{
|
||||
this.star = star;
|
||||
IStringLocalizer<ArtifactSalvageTask> stringLocalizer = App.GetService<IStringLocalizer<ArtifactSalvageTask>>() ?? throw new NullReferenceException();
|
||||
CultureInfo cultureInfo = new CultureInfo(TaskContext.Instance().Config.OtherConfig.GameCultureInfoName);
|
||||
this.quickSelectLocalizedString = stringLocalizer.WithCultureGet(cultureInfo, "快速选择");
|
||||
this.numOfStarLocalizedString = [
|
||||
stringLocalizer.WithCultureGet(cultureInfo, "1星圣遗物"),
|
||||
stringLocalizer.WithCultureGet(cultureInfo, "2星圣遗物"),
|
||||
stringLocalizer.WithCultureGet(cultureInfo, "3星圣遗物"),
|
||||
stringLocalizer.WithCultureGet(cultureInfo, "4星圣遗物")
|
||||
];
|
||||
}
|
||||
|
||||
public async Task Start(CancellationToken ct)
|
||||
{
|
||||
await _returnMainUiTask.Start(ct);
|
||||
|
||||
// B键打开背包
|
||||
Simulation.SendInput.SimulateAction(GIActions.OpenInventory);
|
||||
await Delay(1000, ct);
|
||||
|
||||
var openBagSuccess = await NewRetry.WaitForAction(() =>
|
||||
{
|
||||
// 选择圣遗物
|
||||
using var ra = CaptureToRectArea();
|
||||
using var artifactBtn = ra.Find(ElementAssets.Instance.BagArtifactChecked);
|
||||
if (artifactBtn.IsEmpty())
|
||||
{
|
||||
using var artifactBtn2 = ra.Find(ElementAssets.Instance.BagArtifactUnchecked);
|
||||
if (artifactBtn2.IsExist())
|
||||
{
|
||||
artifactBtn2.Click();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 如果还在主界面就尝试再按下B键打开背包
|
||||
if (Bv.IsInMainUi(ra))
|
||||
{
|
||||
Debug.WriteLine("背包打开失败,再次尝试打开背包");
|
||||
Simulation.SendInput.SimulateAction(GIActions.OpenInventory);
|
||||
}
|
||||
|
||||
return false;
|
||||
}, ct, 5);
|
||||
|
||||
if (!openBagSuccess)
|
||||
{
|
||||
Logger.LogError("未找到背包中圣遗物菜单按钮,打开背包失败");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
await Delay(800, ct);
|
||||
|
||||
// 点击分解按钮打开分解界面
|
||||
using var ra2 = CaptureToRectArea();
|
||||
using var salvageBtn = ra2.Find(ElementAssets.Instance.BtnArtifactSalvage);
|
||||
if (salvageBtn.IsExist())
|
||||
{
|
||||
salvageBtn.Click();
|
||||
await Delay(1000, ct);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogError("未找到圣遗物分解按钮");
|
||||
return;
|
||||
}
|
||||
|
||||
// 快速选择
|
||||
using var ra3 = CaptureToRectArea();
|
||||
var ocrList = ra3.FindMulti(RecognitionObject.Ocr(ra3.ToRect().CutLeftBottom(0.25, 0.1)));
|
||||
foreach (var ocr in ocrList)
|
||||
{
|
||||
if (Regex.IsMatch(ocr.Text, this.quickSelectLocalizedString))
|
||||
{
|
||||
ocr.Click();
|
||||
await Delay(500, ct);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 确认选择
|
||||
// 5.5 变成反选
|
||||
if (star < 4)
|
||||
{
|
||||
using var ra4 = CaptureToRectArea();
|
||||
List<Region> ocrList2 = ra4.FindMulti(RecognitionObject.Ocr(ra3.ToRect().CutLeft(0.20)));
|
||||
for (int i = star; i < 4; i++)
|
||||
{
|
||||
foreach (var ocr in ocrList2)
|
||||
{
|
||||
if (Regex.IsMatch(ocr.Text, this.numOfStarLocalizedString[i]))
|
||||
{
|
||||
ocr.Click();
|
||||
await Delay(500, ct);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Bv.ClickWhiteConfirmButton(ra4);
|
||||
await Delay(500, ct);
|
||||
}
|
||||
|
||||
|
||||
// 点击分解
|
||||
using var ra5 = CaptureToRectArea();
|
||||
var salvageBtnConfirm = ra5.Find(ElementAssets.Instance.BtnArtifactSalvageConfirm);
|
||||
if (salvageBtnConfirm.IsExist())
|
||||
{
|
||||
salvageBtnConfirm.Click();
|
||||
await Delay(800, ct);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogInformation("未找到圣遗物分解按钮,可能已经没有圣遗物需要分解");
|
||||
await _returnMainUiTask.Start(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
// 点击确认
|
||||
using var ra6 = CaptureToRectArea();
|
||||
Bv.ClickBlackConfirmButton(ra6);
|
||||
Logger.LogInformation("完成{Star}星圣遗物分解", star);
|
||||
await Delay(400, ct);
|
||||
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_ESCAPE);
|
||||
|
||||
await _returnMainUiTask.Start(ct);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.GameTask.Common.Exceptions;
|
||||
using Vanara.PInvoke;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.Common.Job;
|
||||
|
||||
@@ -52,7 +53,7 @@ public class SwitchPartyTask
|
||||
{
|
||||
await Delay(1000, ct);
|
||||
using var raCheck = CaptureToRectArea();
|
||||
if (Bv.IsInPartyViewUi(CaptureToRectArea()))
|
||||
if (Bv.IsInPartyViewUi(raCheck))
|
||||
{
|
||||
isOpened = true;
|
||||
break;
|
||||
@@ -71,19 +72,17 @@ public class SwitchPartyTask
|
||||
var partyViewBtn = ra.Find(ElementAssets.Instance.PartyBtnChooseView);
|
||||
|
||||
// OCR 当前队伍名称(无法单字,中间禁止空格)
|
||||
var currTeamNameRaList = ra.FindMulti(new RecognitionObject
|
||||
var currTeamName = ra.Find(new RecognitionObject
|
||||
{
|
||||
RecognitionType = RecognitionTypes.Ocr,
|
||||
RegionOfInterest = new Rect(partyViewBtn.Right, partyViewBtn.Top, (int)(350 * _assetScale),
|
||||
partyViewBtn.Height)
|
||||
});
|
||||
}).Text;
|
||||
|
||||
var currTeamName = string.Join("",
|
||||
currTeamNameRaList.Select(x => x.Text).Where(x => !string.IsNullOrWhiteSpace(x)));
|
||||
// Logger.LogInformation("切换队伍,当前队伍名称: {Text}", currTeamName);
|
||||
if (currTeamName == partyName)
|
||||
Logger.LogInformation("切换队伍,当前队伍名称: {Text},使用正则表达式规则进行模糊匹配", currTeamName);
|
||||
if (Regex.IsMatch(currTeamName, partyName))
|
||||
{
|
||||
Logger.LogInformation("切换队伍,当前队伍[{Name}]即为目标队伍,无需切换", partyName);
|
||||
Logger.LogInformation("当前队伍[{Name}]即为目标队伍,无需切换", currTeamName);
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_ESCAPE);
|
||||
await Delay(500, ct);
|
||||
await _returnMainUiTask.Start(ct);
|
||||
@@ -96,19 +95,21 @@ public class SwitchPartyTask
|
||||
|
||||
ImageRegion? switchRa = null;
|
||||
Region? partyDeleteBtn = null;
|
||||
var openPartyChooseSuccess = await NewRetry.WaitForAction(() =>
|
||||
using (var ocrRa = CaptureToRectArea())
|
||||
{
|
||||
switchRa = CaptureToRectArea();
|
||||
partyDeleteBtn = switchRa.Find(ElementAssets.Instance.PartyBtnDelete);
|
||||
return partyDeleteBtn.IsExist();
|
||||
}, ct, 5);
|
||||
var openPartyChooseSuccess = await NewRetry.WaitForAction(() =>
|
||||
{
|
||||
switchRa = ocrRa;
|
||||
partyDeleteBtn = switchRa.Find(ElementAssets.Instance.PartyBtnDelete);
|
||||
return partyDeleteBtn.IsExist();
|
||||
}, ct, 5);
|
||||
|
||||
if (!openPartyChooseSuccess || switchRa == null || partyDeleteBtn == null)
|
||||
{
|
||||
throw new PartySetupFailedException("未能打开队伍配置界面");
|
||||
if (!openPartyChooseSuccess || switchRa == null || partyDeleteBtn == null)
|
||||
{
|
||||
throw new PartySetupFailedException("未能打开队伍配置界面");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var nextX = partyDeleteBtn.Left;
|
||||
var nextY = partyDeleteBtn.Top - partyDeleteBtn.Height * 2;
|
||||
|
||||
@@ -126,7 +127,7 @@ public class SwitchPartyTask
|
||||
// 逐页查找
|
||||
for (var i = 0; i < 11; i++)
|
||||
{
|
||||
var page = CaptureToRectArea();
|
||||
using var page = CaptureToRectArea();
|
||||
var found = await FindPage(partyName, page, partyDeleteBtn, ct);
|
||||
if (found)
|
||||
{
|
||||
@@ -146,6 +147,7 @@ public class SwitchPartyTask
|
||||
|
||||
// 未找到
|
||||
Logger.LogError("未找到队伍: {Name},返回主界面", partyName);
|
||||
Logger.LogInformation("如果找不到设定的队伍名,有可能是文字识别效果不佳,请尝试正则表达式");
|
||||
await _returnMainUiTask.Start(ct);
|
||||
return false;
|
||||
|
||||
@@ -162,7 +164,7 @@ public class SwitchPartyTask
|
||||
// 当前页存在则直接点击
|
||||
foreach (var textRegion in partySwitchNameRaList)
|
||||
{
|
||||
if (textRegion.Text == partyName)
|
||||
if (Regex.IsMatch(textRegion.Text, partyName))
|
||||
{
|
||||
page.ClickTo(textRegion.Right + textRegion.Width, textRegion.Bottom);
|
||||
await Delay(200, ct);
|
||||
|
||||
@@ -484,7 +484,7 @@
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="结束后自动分解圣遗物"
|
||||
Text="结束后自动快速分解圣遗物"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
@@ -498,7 +498,7 @@
|
||||
Width="80"
|
||||
Margin="0,0,10,0"
|
||||
ItemsSource="{Binding Source={x:Static pages:TaskSettingsPageViewModel.ArtifactSalvageStarList}}"
|
||||
SelectedItem="{Binding Config.AutoDomainConfig.MaxArtifactStar, Mode=TwoWay}">
|
||||
SelectedItem="{Binding Config.AutoArtifactSalvageConfig.MaxArtifactStar, Mode=TwoWay}">
|
||||
</ComboBox>
|
||||
<ui:ToggleSwitch
|
||||
Margin="0,0,36,0"
|
||||
|
||||
@@ -1063,7 +1063,7 @@
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="需要分解圣遗物的最高星级"
|
||||
Text="需要快速分解圣遗物的最高星级"
|
||||
TextWrapping="Wrap" />
|
||||
<ComboBox Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
@@ -1071,7 +1071,7 @@
|
||||
Width="80"
|
||||
Margin="0,0,10,0"
|
||||
ItemsSource="{Binding Source={x:Static pages:TaskSettingsPageViewModel.ArtifactSalvageStarList}}"
|
||||
SelectedItem="{Binding Config.AutoDomainConfig.MaxArtifactStar, Mode=TwoWay}">
|
||||
SelectedItem="{Binding Config.AutoArtifactSalvageConfig.MaxArtifactStar, Mode=TwoWay}">
|
||||
</ComboBox>
|
||||
<ui:ToggleSwitch Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
@@ -1605,6 +1605,154 @@
|
||||
</StackPanel>
|
||||
</ui:CardExpander>
|
||||
|
||||
<!-- 自动分解圣遗物 -->
|
||||
<ui:CardExpander Margin="0,0,0,12" ContentPadding="0">
|
||||
<ui:CardExpander.Icon>
|
||||
<ui:FontIcon Glyph="" Style="{StaticResource FaFontIconStyle}" />
|
||||
</ui:CardExpander.Icon>
|
||||
<ui:CardExpander.Header>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="自动分解圣遗物"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
TextWrapping="Wrap">
|
||||
指定匹配表达式逐一筛选分解,支持5星圣遗物
|
||||
</ui:TextBlock>
|
||||
<controls:TwoStateButton Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,24,0"
|
||||
DisableCommand="{Binding StopSoloTaskCommand}"
|
||||
DisableContent="停止"
|
||||
EnableCommand="{Binding SwitchArtifactSalvageCommand}"
|
||||
EnableContent="{Binding SwitchAutoFishingButtonText}"
|
||||
IsChecked="{Binding SwitchArtifactSalvageEnabled}" />
|
||||
</Grid>
|
||||
</ui:CardExpander.Header>
|
||||
<StackPanel>
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="测试识别效果"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="请先将游戏界面切换至圣遗物分解界面"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:Button Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,36,0"
|
||||
Content="打开测试窗口"
|
||||
Command="{Binding OpenArtifactSalvageTestOCRWindowCommand}" />
|
||||
</Grid>
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="2*" />
|
||||
<ColumnDefinition Width="3*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="正则表达式"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="只要满足的圣遗物都会被选中"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBox Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
MinWidth="180"
|
||||
MaxWidth="800"
|
||||
Margin="0,0,36,0"
|
||||
Text="{Binding Config.AutoArtifactSalvageConfig.RegularExpression, Mode=TwoWay}"
|
||||
TextWrapping="Wrap" Cursor="IBeam" />
|
||||
</Grid>
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="需要快速分解圣遗物的最高星级"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="先会进行一次快速分解选择"
|
||||
TextWrapping="Wrap" />
|
||||
<ComboBox Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Width="80"
|
||||
Margin="0,0,36,0"
|
||||
ItemsSource="{Binding Source={x:Static pages:TaskSettingsPageViewModel.ArtifactSalvageStarList}}"
|
||||
SelectedItem="{Binding Config.AutoArtifactSalvageConfig.MaxArtifactStar, Mode=TwoWay}">
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
<Grid Margin="16" Cursor="">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="7*" />
|
||||
<ColumnDefinition Width="3*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="最大检查数量"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="达到最大检查数量后也会停止"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:NumberBox Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
MinWidth="90"
|
||||
Margin="0,0,36,0"
|
||||
Value="{Binding Config.AutoArtifactSalvageConfig.MaxNumToCheck, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ui:CardExpander>
|
||||
|
||||
<!--<ui:CardExpander Margin="0,0,0,12" ContentPadding="0" Icon="{ui:SymbolIcon Accessibility24}">
|
||||
<ui:CardExpander.Header>
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
</Hyperlink>
|
||||
<LineBreak />
|
||||
|
||||
<ui:TextBlock Margin="0,8,0,0" TextWrapping="Wrap" Name="RzTextBlock" Visibility="Collapsed">
|
||||
<ui:TextBlock Margin="0,8,0,0" TextWrapping="Wrap" Name="RzTextBlock" Visibility="Visible">
|
||||
<ui:TextBlock FontSize="16" FontWeight="Bold" Name="Line1" />
|
||||
<LineBreak />
|
||||
<Run Name="Line2" />
|
||||
|
||||
@@ -18,6 +18,10 @@ public partial class AboutWindow
|
||||
public AboutWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Line1.Text = Base64Helper.DecodeToString("54mI5p2D5L+h5oGv");
|
||||
Line2.Text = Base64Helper.DecodeToString("6K+B5Lmm5Y+377yaIOi9r+iRl+eZu+Wtl+esrDE1MTU2OTUw5Y+3");
|
||||
Line3.Text = Base64Helper.DecodeToString("55m76K6w5Y+377yaIDIwMjVTUjA1MDA3NTI=");
|
||||
MouseDown += Window_MouseDown;
|
||||
}
|
||||
|
||||
@@ -37,9 +41,7 @@ public partial class AboutWindow
|
||||
|
||||
if (_clickCount >= RequiredClicks)
|
||||
{
|
||||
Line1.Text = Base64Helper.DecodeToString("54mI5p2D5L+h5oGv");
|
||||
Line2.Text = Base64Helper.DecodeToString("6K+B5Lmm5Y+377yaIOi9r+iRl+eZu+Wtl+esrDE1MTU2OTUw5Y+3");
|
||||
Line3.Text = Base64Helper.DecodeToString("55m76K6w5Y+377yaIDIwMjVTUjA1MDA3NTI=");
|
||||
|
||||
RzTextBlock.Visibility = Visibility.Visible;
|
||||
|
||||
_clickCount = 0;
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<ui:FluentWindow x:Class="BetterGenshinImpact.View.Windows.OcrDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
SizeToContent="WidthAndHeight"
|
||||
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
|
||||
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
ExtendsContentIntoTitleBar="True"
|
||||
FontFamily="{DynamicResource TextThemeFontFamily}"
|
||||
ResizeMode="CanMinimize"
|
||||
WindowBackdropType="Mica"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
WindowStyle="SingleBorderWindow"
|
||||
mc:Ignorable="d">
|
||||
<StackPanel>
|
||||
<ui:TitleBar Name="MyTitleBar">
|
||||
<ui:TitleBar.Icon>
|
||||
<ui:ImageIcon Source="pack://application:,,,/Assets/Images/logo.png" />
|
||||
</ui:TitleBar.Icon>
|
||||
</ui:TitleBar>
|
||||
<Grid>
|
||||
<Border BorderThickness="3">
|
||||
<Border.BorderBrush>
|
||||
<VisualBrush>
|
||||
<VisualBrush.Visual>
|
||||
<Rectangle StrokeDashArray="3 5" Stroke="#86ffff" StrokeThickness="3"
|
||||
Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualWidth}"
|
||||
Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualHeight}" />
|
||||
</VisualBrush.Visual>
|
||||
</VisualBrush>
|
||||
</Border.BorderBrush>
|
||||
</Border>
|
||||
<Image Name="Screenshot" Source="pack://application:,,,/Assets/Images/logo.png" Stretch="None" Margin="3"/>
|
||||
</Grid>
|
||||
<StackPanel Margin="12">
|
||||
<ui:TextBox Name="TxtRecognized" Margin="5" />
|
||||
<ui:TextBox Name="RegexResult" Margin="5" />
|
||||
<StackPanel Margin="5"
|
||||
HorizontalAlignment="Right"
|
||||
Orientation="Horizontal">
|
||||
<ui:Button Name="BtnOk"
|
||||
Margin="5"
|
||||
Appearance="Primary"
|
||||
Click="BtnOkClick"
|
||||
Content="刷新"
|
||||
IsDefault="True" />
|
||||
<ui:Button Name="BtnCancel"
|
||||
Margin="5"
|
||||
Click="BtnCancelClick"
|
||||
Content="退出"
|
||||
IsCancel="True" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
</StackPanel>
|
||||
</ui:FluentWindow>
|
||||
@@ -0,0 +1,66 @@
|
||||
using BetterGenshinImpact.Core.Recognition.OCR;
|
||||
using BetterGenshinImpact.GameTask.AutoArtifactSalvage;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.GameTask.Model.Area;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace BetterGenshinImpact.View.Windows;
|
||||
|
||||
public partial class OcrDialog
|
||||
{
|
||||
private readonly double xRatio;
|
||||
private readonly double yRatio;
|
||||
private readonly double widthRatio;
|
||||
private readonly double heightRatio;
|
||||
private readonly string? regularExpression;
|
||||
public OcrDialog(double xRatio, double yRatio, double widthRatio, double heightRatio, string title, string? regularExpression = null)
|
||||
{
|
||||
this.xRatio = xRatio;
|
||||
this.yRatio = yRatio;
|
||||
this.widthRatio = widthRatio;
|
||||
this.heightRatio = heightRatio;
|
||||
this.regularExpression = regularExpression;
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
MyTitleBar.Title = title;
|
||||
Capture();
|
||||
}
|
||||
|
||||
public void Capture()
|
||||
{
|
||||
using var ra = TaskControl.CaptureToRectArea();
|
||||
using ImageRegion card = ra.DeriveCrop(new OpenCvSharp.Rect((int)(ra.Width * xRatio), (int)(ra.Height * yRatio), (int)(ra.Width * widthRatio), (int)(ra.Height * heightRatio)));
|
||||
using Bitmap bitmap = card.SrcBitmap;
|
||||
using Stream stream = new MemoryStream();
|
||||
bitmap.Save(stream, format: System.Drawing.Imaging.ImageFormat.Png);
|
||||
BitmapImage bitmapImage = new BitmapImage();
|
||||
bitmapImage.BeginInit();
|
||||
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
||||
bitmapImage.StreamSource = stream;
|
||||
bitmapImage.EndInit();
|
||||
|
||||
this.Screenshot.Source = bitmapImage;
|
||||
|
||||
this.TxtRecognized.Text = OcrFactory.Paddle.OcrResult(card.SrcMat).Text;
|
||||
if (this.regularExpression != null)
|
||||
{
|
||||
AutoArtifactSalvageTask.IsMatchRegularExpression(this.TxtRecognized.Text, this.regularExpression, out string msg);
|
||||
this.RegexResult.Text = msg;
|
||||
}
|
||||
this.UpdateLayout();
|
||||
}
|
||||
|
||||
private void BtnOkClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Capture();
|
||||
}
|
||||
|
||||
private void BtnCancelClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
@@ -252,6 +252,7 @@ public partial class HomePageViewModel : ViewModel
|
||||
_taskDispatcher.UiTaskStartTickEvent += OnUiTaskStartTick;
|
||||
_maskWindow ??= new MaskWindow();
|
||||
_maskWindow.Show();
|
||||
MaskWindow.Instance().RefreshPosition();
|
||||
_mouseKeyMonitor.Subscribe(hWnd);
|
||||
TaskDispatcherEnabled = true;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ using BetterGenshinImpact.ViewModel.Pages.View;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Collections.Frozen;
|
||||
using BetterGenshinImpact.GameTask.AutoArtifactSalvage;
|
||||
using BetterGenshinImpact.View.Windows;
|
||||
|
||||
namespace BetterGenshinImpact.ViewModel.Pages;
|
||||
|
||||
@@ -135,6 +137,9 @@ public partial class TaskSettingsPageViewModel : ViewModel
|
||||
set => SetProperty(ref saveScreenshotOnKeyTick, value);
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _switchArtifactSalvageEnabled;
|
||||
|
||||
public TaskSettingsPageViewModel(IConfigService configService, INavigationService navigationService, TaskTriggerDispatcher taskTriggerDispatcher)
|
||||
{
|
||||
Config = configService.Get();
|
||||
@@ -164,7 +169,7 @@ public partial class TaskSettingsPageViewModel : ViewModel
|
||||
[RelayCommand]
|
||||
private void OnStrategyDropDownOpened(string type)
|
||||
{
|
||||
_autoFightViewModel.OnStrategyDropDownOpened(type);
|
||||
AutoFightViewModel?.OnStrategyDropDownOpened(type);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -298,7 +303,7 @@ public partial class TaskSettingsPageViewModel : ViewModel
|
||||
[RelayCommand]
|
||||
public void OnOpenFightFolder()
|
||||
{
|
||||
_autoFightViewModel?.OnOpenFightFolder();
|
||||
AutoFightViewModel?.OnOpenFightFolder();
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
@@ -414,6 +419,27 @@ public partial class TaskSettingsPageViewModel : ViewModel
|
||||
[RelayCommand]
|
||||
private void OnOpenLocalScriptRepo()
|
||||
{
|
||||
_autoFightViewModel.OnOpenLocalScriptRepo();
|
||||
AutoFightViewModel?.OnOpenLocalScriptRepo();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task OnSwitchArtifactSalvage()
|
||||
{
|
||||
SwitchArtifactSalvageEnabled = true;
|
||||
await new TaskRunner()
|
||||
.RunSoloTaskAsync(new AutoArtifactSalvageTask(int.Parse(Config.AutoArtifactSalvageConfig.MaxArtifactStar), Config.AutoArtifactSalvageConfig.RegularExpression, Config.AutoArtifactSalvageConfig.MaxNumToCheck));
|
||||
SwitchArtifactSalvageEnabled = false;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OnOpenArtifactSalvageTestOCRWindow()
|
||||
{
|
||||
if (!TaskContext.Instance().IsInitialized)
|
||||
{
|
||||
PromptDialog.Prompt("请先启动截图器!", ""); // todo 自动启动截图器
|
||||
return;
|
||||
}
|
||||
OcrDialog ocrDialog = new OcrDialog(0.70, 0.098, 0.24, 0.52, "圣遗物分解", this.Config.AutoArtifactSalvageConfig.RegularExpression);
|
||||
ocrDialog.ShowDialog();
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,12 @@ public class BitBltCapture : IGameCapture
|
||||
private volatile nint _hWnd; // 需要加锁
|
||||
private BitBltSession? _session; // 需要加锁
|
||||
|
||||
private volatile bool _needResetSession;
|
||||
private volatile bool _lastCaptureFailed;
|
||||
|
||||
public void Dispose() => Stop();
|
||||
|
||||
public Mat? Capture() => Capture(false);
|
||||
|
||||
public void Start(nint hWnd, Dictionary<string, object>? settings = null)
|
||||
{
|
||||
if (settings == null || !settings.TryGetValue("autoFixWin11BitBlt", out var value)) return;
|
||||
@@ -52,16 +54,20 @@ public class BitBltCapture : IGameCapture
|
||||
/// 检查窗口大小,如果改变则更新截图尺寸。返回是否成功。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool CheckSession()
|
||||
private void CheckSession()
|
||||
{
|
||||
if (!_lockSlim.TryEnterWriteLock(TimeSpan.FromSeconds(0.5)))
|
||||
if (_lockSlim.WaitingWriteCount > 0 || !_lockSlim.TryEnterWriteLock(TimeSpan.FromSeconds(0.5)))
|
||||
{
|
||||
return false;
|
||||
// 写锁持有只会有两种情况:start和CheckSession。无论哪一种都会检查&更新session。
|
||||
// 所以当有线程等待更新时,将直接返回
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (_session is not null && (_session.IsInvalid() || _needResetSession)) // 窗口状态变化可能会导致会话失效
|
||||
// 窗口状态变化可能会导致会话失效
|
||||
// 上次截图失败则重置会话,避免一直截图失败
|
||||
if (_session is not null && (_session.IsInvalid() || _lastCaptureFailed))
|
||||
{
|
||||
_session.Dispose();
|
||||
_session = null;
|
||||
@@ -73,7 +79,7 @@ public class BitBltCapture : IGameCapture
|
||||
// 窗口获取不到或者最小化
|
||||
_session?.Dispose();
|
||||
_session = null;
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
var width = windowRect.right - windowRect.left;
|
||||
@@ -82,18 +88,17 @@ public class BitBltCapture : IGameCapture
|
||||
_session ??= new BitBltSession(_hWnd, width, height);
|
||||
if (_session.Width == width && _session.Height == height)
|
||||
{
|
||||
return true;
|
||||
// 窗口大小没有改变
|
||||
return;
|
||||
}
|
||||
|
||||
// 窗口尺寸被改变,释放资源
|
||||
// 窗口尺寸被改变,释放资源,然后重新创建会话
|
||||
_session.Dispose();
|
||||
_session = new BitBltSession(_hWnd, width, height);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Error.WriteLine("[BitBlt]Failed to create session:{0}", e);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -101,7 +106,12 @@ public class BitBltCapture : IGameCapture
|
||||
}
|
||||
}
|
||||
|
||||
public Mat? Capture()
|
||||
/// <summary>
|
||||
/// 递归只尝试一次,会设置标志,正常调用置假即可
|
||||
/// </summary>
|
||||
/// <param name="recursive">递归标志</param>
|
||||
/// <returns>截图</returns>
|
||||
private Mat? Capture(bool recursive)
|
||||
{
|
||||
if (_hWnd == IntPtr.Zero)
|
||||
{
|
||||
@@ -113,46 +123,71 @@ public class BitBltCapture : IGameCapture
|
||||
_sizeCheckTimer.Start();
|
||||
}
|
||||
|
||||
if (_sizeCheckTimer.ElapsedMilliseconds > 1000)
|
||||
// 不会经常调整窗口尺寸的,所以隔一段时间检查一次就行
|
||||
// 上次如果截图失败的话忽略计时器,避免重复截图失败
|
||||
// 递归标志也说明上次截图失败
|
||||
if (_lastCaptureFailed || recursive || _sizeCheckTimer.ElapsedMilliseconds > 1000)
|
||||
{
|
||||
_sizeCheckTimer.Reset();
|
||||
// 不会经常调整窗口尺寸的,所以隔一段时间检查一次就行
|
||||
if (!CheckSession())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
CheckSession();
|
||||
}
|
||||
|
||||
Mat? mat = null;
|
||||
try
|
||||
{
|
||||
_lockSlim.EnterReadLock();
|
||||
var result = Capture0();
|
||||
if (result is not null && !result.Empty())
|
||||
{
|
||||
// 成功截图
|
||||
_lastCaptureFailed = false;
|
||||
return result;
|
||||
}
|
||||
else if (result is null)
|
||||
{
|
||||
if (_lastCaptureFailed) return result; // 这不是首次失败,不再进行尝试
|
||||
_lastCaptureFailed = true; // 设置失败标志
|
||||
if (recursive) return result; // 已设置递归标志,说明也不是首次失败
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (_lockSlim.IsReadLockHeld)
|
||||
{
|
||||
_lockSlim.ExitReadLock();
|
||||
}
|
||||
}
|
||||
|
||||
// 首次出现截图异常会跳到这里
|
||||
// 首次出现错误重试截图,尽可能不出现截图失败(递归)
|
||||
return Capture(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 截图功能的实现。需要加锁后调用,一般只由 Capture 方法调用。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private Mat? Capture0()
|
||||
{
|
||||
Mat? mat = null;
|
||||
try
|
||||
{
|
||||
if (_session is null)
|
||||
{
|
||||
// 没有成功创建会话,直接返回空
|
||||
return null;
|
||||
}
|
||||
mat = _session.GetMat();
|
||||
|
||||
if (mat is not null) // 成功执行
|
||||
{
|
||||
if (!mat.Empty()) // 并且获取到了图
|
||||
{
|
||||
_needResetSession = false;
|
||||
return mat;
|
||||
}
|
||||
else // 成功执行但是没有图,可能是截图过快导致的
|
||||
{
|
||||
mat.Dispose();
|
||||
mat = null; // 防止二次释放
|
||||
}
|
||||
}
|
||||
|
||||
// 无论没有图还是执行失败都会到这里
|
||||
if (_session is not null && !_session.IsInvalid())
|
||||
mat = _session.GetMat();
|
||||
|
||||
if (mat is null) return null; // 执行失败
|
||||
if (!mat.Empty()) // 成功执行并且获取到了图
|
||||
{
|
||||
// _session正确但是截图失败,如果持续出现这个问题需要重置会话
|
||||
_needResetSession = true;
|
||||
return mat;
|
||||
}
|
||||
else // 成功执行但是没有图,可能是截图过快导致的
|
||||
{
|
||||
mat.Dispose();
|
||||
mat = null; // 防止二次释放
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -162,15 +197,9 @@ public class BitBltCapture : IGameCapture
|
||||
// 理论这里不应出现异常,除非窗口不存在了或者有什么bug
|
||||
// 出现异常的时候释放内存
|
||||
mat?.Dispose();
|
||||
// 如果持续出现异常则重置会话
|
||||
_needResetSession = true;
|
||||
Error.WriteLine("[BitBlt]Failed to capture image {0}", e);
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lockSlim.ExitReadLock();
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
using BetterGenshinImpact.GameTask.AutoArtifactSalvage;
|
||||
using BetterGenshinImpact.GameTask.AutoFight.Model;
|
||||
using BetterGenshinImpact.UnitTest.CoreTests.RecognitionTests.OCRTests;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media.Media3D;
|
||||
using static BetterGenshinImpact.GameTask.AutoArtifactSalvage.AutoArtifactSalvageTask;
|
||||
|
||||
namespace BetterGenshinImpact.UnitTest.GameTaskTests.AutoArtifactSalvageTests
|
||||
{
|
||||
[Collection("Paddle Collection")]
|
||||
public partial class AutoArtifactSalvageTaskTests
|
||||
{
|
||||
private readonly PaddleFixture paddle;
|
||||
public AutoArtifactSalvageTaskTests(PaddleFixture paddle)
|
||||
{
|
||||
this.paddle = paddle;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(@"ArtifactGrid.png", 7, 7, 126, 162, ArtifactStatus.Selected)]
|
||||
[InlineData(@"ArtifactGrid.png", 140, 2, 136, 168, ArtifactStatus.Selected)]
|
||||
[InlineData(@"ArtifactGrid.png", 7, 176, 126, 154, ArtifactStatus.Locked)]
|
||||
[InlineData(@"ArtifactGrid.png", 139, 172, 136, 165, ArtifactStatus.Locked)]
|
||||
/// <summary>
|
||||
/// 测试获取分解圣遗物Grid界面中圣遗物的状态,结果应正确
|
||||
/// </summary>
|
||||
public void GetArtifactStatus_VariousStatus_ShouldBeRight(string screenshot, int x, int y, int width, int height, ArtifactStatus status)
|
||||
{
|
||||
//
|
||||
using Mat mat = new Mat(@$"..\..\..\Assets\AutoArtifactSalvage\{screenshot}");
|
||||
using Mat cropped = new Mat(mat, new Rect(x, y, width, height));
|
||||
|
||||
//
|
||||
ArtifactStatus result = AutoArtifactSalvageTask.GetArtifactStatus(cropped);
|
||||
|
||||
//
|
||||
Assert.Equal(status, result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(@"ArtifactGrid.png")]
|
||||
/// <summary>
|
||||
/// 测试获取分解圣遗物Grid界面中的圣遗物,结果应正确
|
||||
/// </summary>
|
||||
public void GetArtifactGridItems_ShouldBeRight(string screenshot)
|
||||
{
|
||||
//
|
||||
using Mat mat = new Mat(@$"..\..\..\Assets\AutoArtifactSalvage\{screenshot}");
|
||||
|
||||
//
|
||||
var result = AutoArtifactSalvageTask.GetArtifactGridItems(mat);
|
||||
|
||||
//
|
||||
Assert.Equal(4, result.Count());
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
/// <summary>
|
||||
/// 测试获取分解圣遗物Grid界面中的圣遗物,以及其状态,结果应正确
|
||||
/// </summary>
|
||||
public void GetArtifactGridItems_AndStatus_ShouldBeRight()
|
||||
{
|
||||
//
|
||||
using Mat mat = new Mat(@$"..\..\..\Assets\AutoArtifactSalvage\ArtifactGrid.png");
|
||||
|
||||
//
|
||||
var result = AutoArtifactSalvageTask.GetArtifactGridItems(mat);
|
||||
using Mat leftTopOne = new Mat(mat, result.Single(r => r.X + r.Width / 2 < mat.Width / 2 && r.Y + r.Height / 2 < mat.Height / 2));
|
||||
using Mat rightTopOne = new Mat(mat, result.Single(r => r.X + r.Width / 2 > mat.Width / 2 && r.Y + r.Height / 2 < mat.Height / 2));
|
||||
using Mat leftBottomOne = new Mat(mat, result.Single(r => r.X + r.Width / 2 < mat.Width / 2 && r.Y + r.Height / 2 > mat.Height / 2));
|
||||
using Mat rightBottomOne = new Mat(mat, result.Single(r => r.X + r.Width / 2 > mat.Width / 2 && r.Y + r.Height / 2 > mat.Height / 2));
|
||||
var leftTopOneStatus = AutoArtifactSalvageTask.GetArtifactStatus(leftTopOne);
|
||||
var rightTopOneStatus = AutoArtifactSalvageTask.GetArtifactStatus(rightTopOne);
|
||||
var leftBottomOneStatus = AutoArtifactSalvageTask.GetArtifactStatus(leftBottomOne);
|
||||
var rightBottomOneStatus = AutoArtifactSalvageTask.GetArtifactStatus(rightBottomOne);
|
||||
|
||||
//
|
||||
Assert.Equal(4, result.Count());
|
||||
Assert.Equal(ArtifactStatus.Selected, leftTopOneStatus);
|
||||
Assert.Equal(ArtifactStatus.Selected, rightTopOneStatus);
|
||||
Assert.Equal(ArtifactStatus.Locked, leftBottomOneStatus);
|
||||
Assert.Equal(ArtifactStatus.Locked, rightBottomOneStatus);
|
||||
}
|
||||
|
||||
private static ConcurrentDictionary<string, string> PaddleResultDic { get; } = new ConcurrentDictionary<string, string>();
|
||||
|
||||
/// <summary>
|
||||
/// 测试获取分解圣遗物界面右侧圣遗物的词缀等属性,结果应正确
|
||||
/// </summary>
|
||||
/// <param name="screenshot"></param>
|
||||
[Theory]
|
||||
[InlineData(@"ArtifactAffixes.png", "异种的期许")]
|
||||
[InlineData(@"ArtifactAffixes.png", "生之花")]
|
||||
[InlineData(@"ArtifactAffixes.png", "生命值")]
|
||||
[InlineData(@"ArtifactAffixes.png", @"(?=[\S\s]*元素精通\+)(?=[\S\s]*元素充能效率\+)")]
|
||||
[InlineData(@"ArtifactAffixes.png", @"(?=[\S\s]*元素精通\+)(?=[\S\s]*暴击率\+)", false)]
|
||||
[InlineData(@"ArtifactAffixes.png", @"(元素精通\+)|(暴击率\+)")]
|
||||
[InlineData(@"ArtifactAffixes.png", @"(暴击伤害\+)|(暴击率\+)", false)]
|
||||
[InlineData(@"ArtifactAffixes.png", @"攻击力\+[\d.]*%\n")]
|
||||
[InlineData(@"ArtifactAffixes.png", @"攻击力\+[\d]*\n", false)]
|
||||
[InlineData(@"ArtifactAffixes.png", @"防御力\+[\d.]*%\n", false)]
|
||||
[InlineData(@"ArtifactAffixes.png", @"防御力\+[\d]*\n")]
|
||||
public void GetArtifactAffixes_ShouldBeRight(string screenshot, string pattern, bool isMatch = true)
|
||||
{
|
||||
//
|
||||
|
||||
//
|
||||
string result = PaddleResultDic.GetOrAdd(screenshot, screenshot_ =>
|
||||
{
|
||||
using Mat mat = new Mat(@$"..\..\..\Assets\AutoArtifactSalvage\{screenshot_}");
|
||||
return AutoArtifactSalvageTask.GetArtifactAffixes(mat, paddle.Get());
|
||||
});
|
||||
|
||||
//
|
||||
if (isMatch)
|
||||
{
|
||||
Assert.Matches(pattern, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.DoesNotMatch(pattern, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user