Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e65c57c486 | ||
|
|
8f2484f336 | ||
|
|
30a774233a | ||
|
|
b97bbd0eee | ||
|
|
5e9b78eb55 | ||
|
|
a35fecf579 | ||
|
|
3ca0eb27e3 | ||
|
|
f4fdef9720 | ||
|
|
08fbd772b7 | ||
|
|
f937726f86 | ||
|
|
a7aa62f433 | ||
|
|
0c687840f9 | ||
|
|
36d53a6cb3 | ||
|
|
5e242f2be3 | ||
|
|
e0aa5f0821 | ||
|
|
64c9f717aa | ||
|
|
f08a53c7cd | ||
|
|
1a1141feaa | ||
|
|
b56003fa87 | ||
|
|
3b3ac00097 | ||
|
|
82be4d4555 | ||
|
|
8799f34ce8 | ||
|
|
9284a51ce6 | ||
|
|
269869e9d8 | ||
|
|
65b5b80a47 | ||
|
|
98ab2089c2 | ||
|
|
13a47e64b8 | ||
|
|
71ea62beb6 | ||
|
|
bc6c0ed3d0 | ||
|
|
bd2070b94c | ||
|
|
3ed6a04caa | ||
|
|
e7073e5d8a | ||
|
|
64b1fa2c2d | ||
|
|
93c994570e | ||
|
|
255e7bb08e | ||
|
|
0bb23b9fcc | ||
|
|
c04d47f7a7 | ||
|
|
0c467d2f97 | ||
|
|
d2092a6c32 | ||
|
|
3a635524c4 | ||
|
|
5cb032b851 | ||
|
|
795c089100 | ||
|
|
e81676847c | ||
|
|
d44eaa5312 | ||
|
|
008c1b2e03 | ||
|
|
26590f7268 | ||
|
|
909e29f268 | ||
|
|
1ae0db15d3 | ||
|
|
a520ee8785 | ||
|
|
f386b743c3 | ||
|
|
3575a7274e | ||
|
|
a60229cad2 | ||
|
|
26456bb5ee | ||
|
|
7a41056fc1 | ||
|
|
32f744538b | ||
|
|
937c86927c |
No files matched your search
@@ -6,8 +6,8 @@ on:
|
||||
types: [released]
|
||||
|
||||
jobs:
|
||||
mirrorchyan_7z:
|
||||
runs-on: macos-latest
|
||||
mirrorchyan:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: 📥 Download release
|
||||
uses: robinraju/[email protected]
|
||||
@@ -15,14 +15,48 @@ jobs:
|
||||
latest: true
|
||||
fileName: "*"
|
||||
|
||||
- name: Extract 7z
|
||||
- name: 📥 Download kachina-builder release
|
||||
uses: robinraju/[email protected]
|
||||
with:
|
||||
repository: "YuehaiTeam/kachina-installer"
|
||||
latest: true
|
||||
fileName: "kachina-builder.exe"
|
||||
|
||||
- name: Embed Dotnet and VCRedist
|
||||
shell: bash
|
||||
run: |
|
||||
# dotnet
|
||||
VERSION_URL="https://builds.dotnet.microsoft.com/dotnet/WindowsDesktop/8.0/latest.version"
|
||||
VERSION=$(curl -fsSL "$VERSION_URL" | tr -d '\r\n')
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Cannot get the latest version from $VERSION_URL"
|
||||
exit 1
|
||||
fi
|
||||
INSTALLER_URL="https://builds.dotnet.microsoft.com/dotnet/WindowsDesktop/${VERSION}/windowsdesktop-runtime-${VERSION}-win-x64.exe"
|
||||
OUTPUT="windowsdesktop-runtime-${VERSION}-win-x64.exe"
|
||||
echo "Downloading Windows Desktop Runtime version $VERSION from $INSTALLER_URL"
|
||||
curl -fSL -o "$OUTPUT" "$INSTALLER_URL"
|
||||
# vcredist
|
||||
echo "Downloading VCRedist"
|
||||
curl -fSL -o "vc_redist.x64.exe" "https://aka.ms/vs/17/release/vc_redist.x64.exe"
|
||||
# embed
|
||||
echo "Embedding runtimes"
|
||||
./kachina-builder.exe append -o ./BetterGI.Install.*.exe -f "$OUTPUT" -n "Microsoft.DotNet.DesktopRuntime.8" -f "vc_redist.x64.exe" -n "Microsoft.VCRedist.2015+.x64"
|
||||
./kachina-builder.exe extract -i ./BetterGI.Install.*.exe -f ./metadata.json -n "\0META"
|
||||
|
||||
- name: Extract 7z and create zip
|
||||
shell: bash
|
||||
run: |
|
||||
7z a -tzip BetterGI.Install.zip ./BetterGI.Install.*.exe -mx=1 -r -y
|
||||
choco install wget --no-progress
|
||||
7z x BetterGI_v*.7z -oun7z
|
||||
mv ./BetterGI.Metadata.json ./un7z/BetterGI/.metadata.json
|
||||
mv ./metadata.json ./un7z/BetterGI/.metadata.json
|
||||
cd un7z
|
||||
7z a -tzip ../BetterGI.zip ./BetterGI -mx=5 -r -y
|
||||
|
||||
- name: Determine version number
|
||||
id: get-version
|
||||
shell: bash
|
||||
run: |
|
||||
if [ "${{ github.event_name }}" = "release" ]; then
|
||||
echo "version=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
|
||||
@@ -38,25 +72,17 @@ jobs:
|
||||
with:
|
||||
filetype: local
|
||||
mirrorchyan_rid: BGI
|
||||
working-directory: ./un7z/
|
||||
pick_files: '["BetterGI"]'
|
||||
filename: "BetterGI.zip"
|
||||
version_name: ${{ steps.get-version.outputs.version }}
|
||||
upload_token: ${{ secrets.MirrorChyanUploadToken }}
|
||||
os: win
|
||||
arch: x64
|
||||
|
||||
mirrorchyan_exe:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: MirrorChyan/uploading-action@v1
|
||||
- name: Upload Exe
|
||||
uses: MirrorChyan/uploading-action@v1
|
||||
with:
|
||||
filetype: latest-release
|
||||
filename: "BetterGI.Install.*.exe"
|
||||
extra_zip: true
|
||||
filetype: local
|
||||
mirrorchyan_rid: BGI
|
||||
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
owner: babalae
|
||||
repo: better-genshin-impact
|
||||
filename: "BetterGI.Install.zip"
|
||||
version_name: ${{ steps.get-version.outputs.version }}
|
||||
upload_token: ${{ secrets.MirrorChyanUploadToken }}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
name: BetterGI Publish
|
||||
run-name: "BetterGI ${{ inputs.version }}"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
@@ -299,8 +300,8 @@ jobs:
|
||||
path: dist/BetterGI.Install.*.exe
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: BetterGI_Metadata
|
||||
path: dist/metadata.json
|
||||
name: BetterGI_OnlineInst
|
||||
path: dist/BetterGI/BetterGI.update.exe
|
||||
|
||||
build_setup:
|
||||
runs-on: windows-latest
|
||||
@@ -349,11 +350,6 @@ jobs:
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
|
||||
- name: Append Metadata
|
||||
shell: bash
|
||||
run: |
|
||||
mv artifacts/BetterGI_Metadata/metadata.json artifacts/BetterGI_Metadata/BetterGI_Metadata.json
|
||||
|
||||
- name: Create Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
@@ -366,46 +362,86 @@ jobs:
|
||||
files: |
|
||||
artifacts/BetterGI_7z/*.7z
|
||||
artifacts/BetterGI_Install/*.exe
|
||||
artifacts/BetterGI_Metadata/*.json
|
||||
|
||||
mirrorchyan_uploading:
|
||||
if: github.repository_owner == 'babalae' && contains(needs.validate.outputs.version, '-')
|
||||
needs: [validate, build_dist, build_installer]
|
||||
runs-on: macos-latest
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: downloads
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: 📥 Download kachina-builder release
|
||||
if: ${{ github.event.inputs.kachina-channel == 'release' }}
|
||||
uses: robinraju/[email protected]
|
||||
with:
|
||||
repository: "YuehaiTeam/kachina-installer"
|
||||
latest: true
|
||||
fileName: "kachina-builder.exe"
|
||||
- name: 📥 Download kachina-builder dev
|
||||
if: ${{ github.event.inputs.kachina-channel == 'dev' }}
|
||||
uses: dawidd6/action-download-artifact@v8
|
||||
with:
|
||||
github_token: ${{secrets.GITHUB_TOKEN}}
|
||||
repo: "YuehaiTeam/kachina-installer"
|
||||
workflow: "build.yml"
|
||||
name: artifact
|
||||
branch: main
|
||||
event: push
|
||||
workflow_conclusion: success
|
||||
|
||||
- name: Extract 7z
|
||||
- name: Embed Dotnet and VCRedist
|
||||
shell: bash
|
||||
run: |
|
||||
# dotnet
|
||||
VERSION_URL="https://builds.dotnet.microsoft.com/dotnet/WindowsDesktop/8.0/latest.version"
|
||||
VERSION=$(curl -fsSL "$VERSION_URL" | tr -d '\r\n')
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Cannot get the latest version from $VERSION_URL"
|
||||
exit 1
|
||||
fi
|
||||
INSTALLER_URL="https://builds.dotnet.microsoft.com/dotnet/WindowsDesktop/${VERSION}/windowsdesktop-runtime-${VERSION}-win-x64.exe"
|
||||
OUTPUT="windowsdesktop-runtime-${VERSION}-win-x64.exe"
|
||||
echo "Downloading Windows Desktop Runtime version $VERSION from $INSTALLER_URL"
|
||||
curl -fSL -o "$OUTPUT" "$INSTALLER_URL"
|
||||
# vcredist
|
||||
echo "Downloading VCRedist"
|
||||
curl -fSL -o "vc_redist.x64.exe" "https://aka.ms/vs/17/release/vc_redist.x64.exe"
|
||||
# embed
|
||||
echo "Embedding runtimes"
|
||||
./kachina-builder.exe append -o ./downloads/BetterGI_Install/BetterGI.Install.*.exe -f "$OUTPUT" -n "Microsoft.DotNet.DesktopRuntime.8" -f "vc_redist.x64.exe" -n "Microsoft.VCRedist.2015+.x64"
|
||||
./kachina-builder.exe extract -i ./downloads/BetterGI_Install/BetterGI.Install.*.exe -f ./metadata.json -n "\0META"
|
||||
- name: Extract 7z and create zip
|
||||
shell: bash
|
||||
run: |
|
||||
choco install wget --no-progress
|
||||
7z a -tzip BetterGI.Install.${{ needs.validate.outputs.version }}.zip ./downloads/BetterGI_Install/BetterGI.Install.${{ needs.validate.outputs.version }}.exe -mx=1 -r -y
|
||||
cd downloads/BetterGI_7z
|
||||
7z x BetterGI_v*.7z -oun7z
|
||||
mv ../BetterGI_Metadata/metadata.json ./un7z/BetterGI/.metadata.json
|
||||
mv ../../metadata.json ./un7z/BetterGI/.metadata.json
|
||||
cd un7z
|
||||
7z a -tzip ../BetterGI.zip ./BetterGI -mx=5 -r -y
|
||||
|
||||
- name: Upload Zip
|
||||
uses: MirrorChyan/uploading-action@v1
|
||||
with:
|
||||
filetype: local
|
||||
mirrorchyan_rid: BGI
|
||||
working-directory: downloads/BetterGI_7z/un7z/
|
||||
pick_files: '["BetterGI"]'
|
||||
filename: "downloads/BetterGI_7z/BetterGI.zip"
|
||||
version_name: ${{ needs.validate.outputs.version }}
|
||||
upload_token: ${{ secrets.MirrorChyanUploadToken }}
|
||||
os: win
|
||||
arch: x64
|
||||
|
||||
|
||||
- name: Upload Install.exe
|
||||
uses: MirrorChyan/uploading-action@v1
|
||||
with:
|
||||
filetype: local
|
||||
mirrorchyan_rid: BGI
|
||||
working-directory: downloads/BetterGI_Install/
|
||||
filename: "BetterGI.Install.*.exe"
|
||||
extra_zip: true
|
||||
filename: "BetterGI.Install.${{ needs.validate.outputs.version }}.zip"
|
||||
version_name: ${{ needs.validate.outputs.version }}
|
||||
upload_token: ${{ secrets.MirrorChyanUploadToken }}
|
||||
|
||||
Binary file not shown.
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<AssemblyName>BetterGI</AssemblyName>
|
||||
<Version>0.45.4-alpha.3</Version>
|
||||
<Version>0.46.2</Version>
|
||||
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
|
||||
|
||||
@@ -16,32 +16,32 @@ public class TextInferenceFactory
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
|
||||
};
|
||||
}
|
||||
public static Mat PreProcessForInference(Mat mat)
|
||||
{
|
||||
if (mat.Channels() == 3)
|
||||
{
|
||||
mat = mat.CvtColor(ColorConversionCodes.BGR2GRAY);
|
||||
}
|
||||
else if (mat.Channels() == 4)
|
||||
{
|
||||
mat = mat.CvtColor(ColorConversionCodes.BGRA2GRAY);
|
||||
}
|
||||
else if (mat.Channels() != 1)
|
||||
{
|
||||
throw new ArgumentException("mat must be 1, 3 or 4 channels");
|
||||
}
|
||||
|
||||
// Yap 已经改用灰度图了 https://github.com/Alex-Beng/Yap/commit/c2ad1e7b1442aaf2d80782a032e00876cd1c6c84
|
||||
// 二值化
|
||||
// Cv2.Threshold(mat, mat, 0, 255, ThresholdTypes.Otsu | ThresholdTypes.Binary);
|
||||
//Cv2.AdaptiveThreshold(mat, mat, 255, AdaptiveThresholdTypes.GaussianC, ThresholdTypes.Binary, 31, 3); // 效果不错 但是和模型不搭
|
||||
//mat = OpenCvCommonHelper.Threshold(mat, Scalar.FromRgb(235, 235, 235), Scalar.FromRgb(255, 255, 255)); // 识别物品不太行
|
||||
// 不知道为什么要强制拉伸到 221x32
|
||||
mat = ResizeHelper.ResizeTo(mat, 221, 32);
|
||||
// 填充到 384x32
|
||||
var padded = new Mat(new Size(384, 32), MatType.CV_8UC1, Scalar.Black);
|
||||
padded[new Rect(0, 0, mat.Width, mat.Height)] = mat;
|
||||
//Cv2.ImWrite(Global.Absolute("padded.png"), padded);
|
||||
return padded;
|
||||
}
|
||||
// public static Mat PreProcessForInference(Mat mat)
|
||||
// {
|
||||
// if (mat.Channels() == 3)
|
||||
// {
|
||||
// mat = mat.CvtColor(ColorConversionCodes.BGR2GRAY);
|
||||
// }
|
||||
// else if (mat.Channels() == 4)
|
||||
// {
|
||||
// mat = mat.CvtColor(ColorConversionCodes.BGRA2GRAY);
|
||||
// }
|
||||
// else if (mat.Channels() != 1)
|
||||
// {
|
||||
// throw new ArgumentException("mat must be 1, 3 or 4 channels");
|
||||
// }
|
||||
//
|
||||
// // Yap 已经改用灰度图了 https://github.com/Alex-Beng/Yap/commit/c2ad1e7b1442aaf2d80782a032e00876cd1c6c84
|
||||
// // 二值化
|
||||
// // Cv2.Threshold(mat, mat, 0, 255, ThresholdTypes.Otsu | ThresholdTypes.Binary);
|
||||
// //Cv2.AdaptiveThreshold(mat, mat, 255, AdaptiveThresholdTypes.GaussianC, ThresholdTypes.Binary, 31, 3); // 效果不错 但是和模型不搭
|
||||
// //mat = OpenCvCommonHelper.Threshold(mat, Scalar.FromRgb(235, 235, 235), Scalar.FromRgb(255, 255, 255)); // 识别物品不太行
|
||||
// // 不知道为什么要强制拉伸到 221x32
|
||||
// mat = ResizeHelper.ResizeTo(mat, 221, 32);
|
||||
// // 填充到 384x32
|
||||
// var padded = new Mat(new Size(384, 32), MatType.CV_8UC1, Scalar.Black);
|
||||
// padded[new Rect(0, 0, mat.Width, mat.Height)] = mat;
|
||||
// //Cv2.ImWrite(Global.Absolute("padded.png"), padded);
|
||||
// return padded;
|
||||
// }
|
||||
}
|
||||
@@ -47,6 +47,8 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
|
||||
public static readonly string CenterRepoUnzipName = "bettergi-scripts-list-git";
|
||||
|
||||
public static readonly string CenterRepoPath = Path.Combine(ReposPath, CenterRepoUnzipName);
|
||||
|
||||
public static readonly string CenterRepoPathOld = Path.Combine(ReposPath, "bettergi-scripts-list-main");
|
||||
|
||||
public static readonly Dictionary<string, string> PathMapper = new Dictionary<string, string>
|
||||
{
|
||||
|
||||
@@ -24,6 +24,7 @@ using BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
using BetterGenshinImpact.Core.Recognition.OCR;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.GameTask.Common.Job;
|
||||
using GameTask.Model.GameUI;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoArtifactSalvage;
|
||||
|
||||
@@ -210,118 +211,42 @@ public class AutoArtifactSalvageTask : ISoloTask
|
||||
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)
|
||||
|
||||
using var ra0 = CaptureToRectArea();
|
||||
Rect gridRoi = new Rect((int)(ra0.Width * 0.025), (int)(ra0.Width * 0.055), (int)(ra0.Width * 0.66), (int)(ra0.Width * 0.4));
|
||||
GridScreen gridScreen = new GridScreen(gridRoi, 3, 40, 28, 0.018, this.logger, this.ct); // 圣遗物分解Grid有4行9列
|
||||
await foreach (ImageRegion itemRegion in gridScreen)
|
||||
{
|
||||
// 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)
|
||||
Rect gridRect = itemRegion.ToRect();
|
||||
if (GetArtifactStatus(itemRegion.SrcMat) == ArtifactStatus.None)
|
||||
{
|
||||
using ImageRegion itemRegion = grid.DeriveCrop(item);
|
||||
if (GetArtifactStatus(itemRegion.SrcMat) == ArtifactStatus.None)
|
||||
itemRegion.Click();
|
||||
await Delay(300, ct);
|
||||
|
||||
using var ra1 = CaptureToRectArea();
|
||||
using ImageRegion itemRegion1 = ra1.DeriveCrop(gridRect + new Point(gridRoi.X, gridRoi.Y));
|
||||
if (GetArtifactStatus(itemRegion1.SrcMat) == ArtifactStatus.Selected)
|
||||
{
|
||||
anyItemChecked = true;
|
||||
itemRegion.Click();
|
||||
await Delay(300, ct);
|
||||
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);
|
||||
|
||||
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)
|
||||
if (IsMatchRegularExpression(affixes, regularExpression, out string msg))
|
||||
{
|
||||
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);
|
||||
logger.LogInformation(message: msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
itemRegion.Click();
|
||||
await Delay(100, ct);
|
||||
}
|
||||
}
|
||||
|
||||
grid.MoveTo(grid.Width, grid.Height);
|
||||
await Delay(500, ct);
|
||||
count--;
|
||||
if (count <= 0)
|
||||
{
|
||||
logger.LogInformation("检查次数已耗尽");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await Delay(400, ct);
|
||||
logger.LogInformation("找不到可检查的圣遗物了");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (count <= 0)
|
||||
{
|
||||
logger.LogInformation("检查次数已耗尽");
|
||||
}
|
||||
if (duplicateSum >= 3)
|
||||
{
|
||||
logger.LogInformation("重复检查次数过多,推断为找不到可检查的了");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,33 +277,6 @@ public class AutoArtifactSalvageTask : ISoloTask
|
||||
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)));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoDomain;
|
||||
|
||||
@@ -51,4 +52,32 @@ public partial class AutoDomainConfig : ObservableObject
|
||||
// 周日奖励序号
|
||||
[ObservableProperty]
|
||||
private string _sundaySelectedValue = string.Empty;
|
||||
|
||||
// 指定树脂的使用次数
|
||||
[ObservableProperty]
|
||||
private bool _specifyResinUse = false;
|
||||
|
||||
// 自定义使用树脂优先级
|
||||
[ObservableProperty]
|
||||
private List<string> _resinPriorityList =
|
||||
[
|
||||
"浓缩树脂",
|
||||
"原粹树脂"
|
||||
];
|
||||
|
||||
// 使用原粹树脂刷取副本次数
|
||||
[ObservableProperty]
|
||||
private int _originalResinUseCount = 0;
|
||||
|
||||
//使用浓缩树脂刷取副本次数
|
||||
[ObservableProperty]
|
||||
private int _condensedResinUseCount = 0;
|
||||
|
||||
// 使用须臾树脂刷取副本次数
|
||||
[ObservableProperty]
|
||||
private int _transientResinUseCount = 0;
|
||||
|
||||
// 使用脆弱树脂刷取副本次数
|
||||
[ObservableProperty]
|
||||
private int _fragileResinUseCount = 0;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using BetterGenshinImpact.GameTask.Model;
|
||||
using System.Collections.Generic;
|
||||
using BetterGenshinImpact.GameTask.Model;
|
||||
using System.Threading;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoDomain;
|
||||
@@ -25,6 +26,27 @@ public class AutoDomainParam : BaseTaskParam
|
||||
// 1~4
|
||||
public string MaxArtifactStar { get; set; } = "4";
|
||||
|
||||
public bool SpecifyResinUse { get; set; } = false;
|
||||
|
||||
// 使用树脂优先级
|
||||
public List<string> ResinPriorityList { get; set; } =
|
||||
[
|
||||
"浓缩树脂",
|
||||
"原粹树脂"
|
||||
];
|
||||
|
||||
// 使用原粹树脂刷取副本次数
|
||||
public int OriginalResinUseCount { get; set; } = 0;
|
||||
|
||||
// 使用浓缩树脂刷取副本次数
|
||||
public int CondensedResinUseCount { get; set; } = 0;
|
||||
|
||||
// 使用须臾树脂刷取副本次数
|
||||
public int TransientResinUseCount { get; set; } = 0;
|
||||
|
||||
// 使用脆弱树脂刷取副本次数
|
||||
public int FragileResinUseCount { get; set; } = 0;
|
||||
|
||||
public AutoDomainParam(int domainRoundNum, string path)
|
||||
{
|
||||
DomainRoundNum = domainRoundNum;
|
||||
@@ -45,5 +67,11 @@ public class AutoDomainParam : BaseTaskParam
|
||||
SundaySelectedValue = config.SundaySelectedValue;
|
||||
AutoArtifactSalvage = config.AutoArtifactSalvage;
|
||||
MaxArtifactStar = TaskContext.Instance().Config.AutoArtifactSalvageConfig.MaxArtifactStar;
|
||||
ResinPriorityList = config.ResinPriorityList;
|
||||
OriginalResinUseCount = config.OriginalResinUseCount;
|
||||
CondensedResinUseCount = config.CondensedResinUseCount;
|
||||
TransientResinUseCount = config.TransientResinUseCount;
|
||||
FragileResinUseCount = config.FragileResinUseCount;
|
||||
SpecifyResinUse = config.SpecifyResinUse;
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,8 @@ using System.Text.RegularExpressions;
|
||||
using BetterGenshinImpact.GameTask.AutoArtifactSalvage;
|
||||
using System.Collections.ObjectModel;
|
||||
using BetterGenshinImpact.Core.Script.Dependence;
|
||||
using BetterGenshinImpact.GameTask.AutoDomain.Model;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using Compunet.YoloSharp;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
@@ -69,6 +71,8 @@ public class AutoDomainTask : ISoloTask
|
||||
private readonly string matchingChallengeString;
|
||||
private readonly string rapidformationString;
|
||||
|
||||
private List<ResinUseRecord> _resinPriorityListWhenSpecifyUse;
|
||||
|
||||
public AutoDomainTask(AutoDomainParam taskParam)
|
||||
{
|
||||
AutoFightAssets.DestroyInstance();
|
||||
@@ -79,6 +83,8 @@ public class AutoDomainTask : ISoloTask
|
||||
|
||||
_combatScriptBag = CombatScriptParser.ReadAndParse(_taskParam.CombatStrategyPath);
|
||||
|
||||
_resinPriorityListWhenSpecifyUse = ResinUseRecord.BuildFromDomainParam(taskParam);
|
||||
|
||||
IStringLocalizer<AutoDomainTask> stringLocalizer =
|
||||
App.GetService<IStringLocalizer<AutoDomainTask>>() ?? throw new NullReferenceException();
|
||||
CultureInfo cultureInfo = new CultureInfo(TaskContext.Instance().Config.OtherConfig.GameCultureInfoName);
|
||||
@@ -182,17 +188,9 @@ public class AutoDomainTask : ISoloTask
|
||||
|
||||
// 5. 快速领取奖励并判断是否有下一轮
|
||||
Logger.LogInformation("自动秘境:{Text}", "5. 领取奖励");
|
||||
if (!GettingTreasure(_taskParam.DomainRoundNum == 9999, i == _taskParam.DomainRoundNum - 1))
|
||||
if (!await GettingTreasure())
|
||||
{
|
||||
if (i == _taskParam.DomainRoundNum - 1)
|
||||
{
|
||||
Logger.LogInformation("配置的{Cnt}轮秘境已经完成,结束自动秘境", _taskParam.DomainRoundNum);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogInformation("体力已经耗尽,结束自动秘境");
|
||||
}
|
||||
|
||||
Logger.LogInformation("体力耗尽或者设置轮次已达标,结束自动秘境");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -400,84 +398,58 @@ public class AutoDomainTask : ISoloTask
|
||||
Logger.LogInformation("周日未设置秘境奖励序号,不进行奖励选择");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning("周日设置秘境奖励序号错误,请检查配置页面");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning("周日奖励选择:圣遗物副本无需选择奖励");
|
||||
Logger.LogDebug("周日奖励选择:圣遗物副本无需选择奖励");
|
||||
}
|
||||
|
||||
await Delay(300, _ct);
|
||||
//await Delay(100000, _ct);//调试延时=========
|
||||
}
|
||||
|
||||
// 点击单人挑战,增加容错,点击失败则继续尝试
|
||||
// 点击单人挑战
|
||||
int retryTimes = 0;
|
||||
while (retryTimes < 40)
|
||||
while (retryTimes < 20)
|
||||
{
|
||||
retryTimes++;
|
||||
using var confirmRectArea = CaptureToRectArea().Find(fightAssets.ConfirmRa);
|
||||
if (!confirmRectArea.IsEmpty())
|
||||
{
|
||||
await Delay(500, _ct);
|
||||
confirmRectArea.Click();
|
||||
await Delay(500, _ct);
|
||||
var ra = CaptureToRectArea();
|
||||
var matchingChallengeArea = ra.FindMulti(RecognitionObject.Ocr(ra.Width * 0.64, ra.Height * 0.91,
|
||||
ra.Width * 0.13, ra.Height * 0.06));
|
||||
var done = matchingChallengeArea.LastOrDefault(t =>
|
||||
Regex.IsMatch(t.Text, this.matchingChallengeString));
|
||||
if (done != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
await Delay(500, _ct);
|
||||
}
|
||||
|
||||
//如果卡顿,可能会错过"是否仍要挑战该秘境"判断弹框,改为判断"快速编队"后进行点击进入
|
||||
retryTimes = 0;
|
||||
while (retryTimes < 30)
|
||||
{
|
||||
await Delay(600, _ct);
|
||||
var ra = CaptureToRectArea();
|
||||
var rapidformationStringArea = ra.FindMulti(RecognitionObject.Ocr(ra.Width * 0.64, ra.Height * 0.91,
|
||||
ra.Width * 0.13, ra.Height * 0.06));
|
||||
var done = rapidformationStringArea.LastOrDefault(t =>
|
||||
Regex.IsMatch(t.Text, this.rapidformationString));
|
||||
if (done != null)
|
||||
{
|
||||
using var confirmRectArea = CaptureToRectArea().Find(fightAssets.ConfirmRa);
|
||||
if (!confirmRectArea.IsEmpty())
|
||||
{
|
||||
confirmRectArea.Click();
|
||||
await Delay(500, _ct);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
using var confirmRectArea2 = ra.Find(RecognitionObject.Ocr(ra.Width * 0.263, ra.Height * 0.32,
|
||||
ra.Width - ra.Width * 0.263 * 2, ra.Height - ra.Height * 0.32 - ra.Height * 0.353));
|
||||
if (confirmRectArea2.IsExist() && confirmRectArea2.Text.Contains("是否仍要挑战该秘境"))
|
||||
await Delay(1500, _ct);
|
||||
}
|
||||
|
||||
// 判断弹框
|
||||
await Delay(600, _ct);
|
||||
var ra = CaptureToRectArea();
|
||||
using var confirmRectArea2 = ra.Find(RecognitionObject.Ocr(ra.Width * 0.263, ra.Height * 0.32,
|
||||
ra.Width - ra.Width * 0.263 * 2, ra.Height - ra.Height * 0.32 - ra.Height * 0.353));
|
||||
if (confirmRectArea2.IsExist() && confirmRectArea2.Text.Contains("是否仍要挑战该秘境"))
|
||||
{
|
||||
Logger.LogWarning("自动秘境:检测到树脂不足提示:{Text}", confirmRectArea2.Text);
|
||||
throw new Exception("当前树脂不足,自动秘境停止运行。");
|
||||
}
|
||||
|
||||
// 点击进入
|
||||
retryTimes = 0;
|
||||
while (retryTimes < 20)
|
||||
{
|
||||
retryTimes++;
|
||||
using var confirmRectArea = CaptureToRectArea().Find(fightAssets.ConfirmRa);
|
||||
if (!confirmRectArea.IsEmpty())
|
||||
{
|
||||
Logger.LogWarning("自动秘境:检测到树脂不足提示:{Text}", confirmRectArea2.Text);
|
||||
throw new Exception("当前树脂不足,自动秘境停止运行。");
|
||||
confirmRectArea.Click();
|
||||
break;
|
||||
}
|
||||
|
||||
retryTimes++;
|
||||
await Delay(1200, _ct);
|
||||
}
|
||||
|
||||
|
||||
// 载入动画
|
||||
await Delay(3000, _ct);
|
||||
}
|
||||
@@ -615,6 +587,7 @@ public class AutoDomainTask : ISoloTask
|
||||
finally
|
||||
{
|
||||
Logger.LogInformation("自动战斗线程结束");
|
||||
Simulation.ReleaseAllKey();
|
||||
}
|
||||
}, cts.Token);
|
||||
|
||||
@@ -997,7 +970,7 @@ public class AutoDomainTask : ISoloTask
|
||||
Simulation.SendInput.Mouse.MoveMouseBy(moveAngle, 0);
|
||||
}
|
||||
|
||||
Sleep(100);
|
||||
Sleep(100, _ct);
|
||||
}
|
||||
|
||||
Logger.LogInformation("锁定东方向视角线程结束");
|
||||
@@ -1008,64 +981,131 @@ public class AutoDomainTask : ISoloTask
|
||||
/// <summary>
|
||||
/// 领取奖励
|
||||
/// </summary>
|
||||
/// <param name="recognizeResin">是否识别树脂</param>
|
||||
/// <param name="isLastTurn">是否最后一轮</param>
|
||||
private bool GettingTreasure(bool recognizeResin, bool isLastTurn)
|
||||
private async Task<bool> GettingTreasure()
|
||||
{
|
||||
bool isLastTurn = false;
|
||||
// 等待窗口弹出
|
||||
Sleep(1500, _ct);
|
||||
await Delay(300, _ct);
|
||||
|
||||
// 优先使用浓缩树脂
|
||||
var retryTimes = 0;
|
||||
while (true)
|
||||
// 1. OCR 直到确认弹出框弹出
|
||||
bool chooseResinPrompt = await NewRetry.WaitForAction(() =>
|
||||
{
|
||||
retryTimes++;
|
||||
if (retryTimes > 3)
|
||||
using var ra = CaptureToRectArea();
|
||||
var regionList = ra.FindMulti(RecognitionObject.Ocr(ra.Width * 0.25, ra.Height * 0.2, ra.Width * 0.5, ra.Height * 0.6));
|
||||
var res = regionList.FirstOrDefault(t => t.Text.Contains("石化古树"));
|
||||
if (res != null)
|
||||
{
|
||||
Logger.LogInformation("没有浓缩树脂了");
|
||||
break;
|
||||
// 解决水龙王按下左键后没松开,然后后续点击按下就没反应了,界面上点一下
|
||||
res.Click();
|
||||
return true;
|
||||
}
|
||||
|
||||
var useCondensedResinRa = CaptureToRectArea().Find(AutoFightAssets.Instance.UseCondensedResinRa);
|
||||
if (!useCondensedResinRa.IsEmpty())
|
||||
{
|
||||
useCondensedResinRa.Click();
|
||||
// 点两下 #224 #218
|
||||
// 解决水龙王按下左键后没松开,然后后续点击按下就没反应了
|
||||
Sleep(400, _ct);
|
||||
useCondensedResinRa.Click();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}, _ct, 10, 500);
|
||||
Debug.WriteLine("识别到选择树脂页");
|
||||
await Delay(800, _ct);
|
||||
|
||||
Sleep(800, _ct);
|
||||
// 再 OCR 一次,弹出框,确认当前是否有原粹树脂
|
||||
using var ra2 = CaptureToRectArea();
|
||||
var textListInPrompt = ra2.FindMulti(RecognitionObject.Ocr(ra2.Width * 0.25, ra2.Height * 0.2, ra2.Width * 0.5, ra2.Height * 0.6));
|
||||
if (textListInPrompt.Any(t => t.Text.Contains("数量不足") || t.Text.Contains("补充原粹树脂")))
|
||||
{
|
||||
// 没有原粹树脂,直接退出秘境
|
||||
Logger.LogInformation("自动秘境:原粹树脂已用尽,退出秘境");
|
||||
await ExitDomain();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (chooseResinPrompt)
|
||||
{
|
||||
using var ra3 = CaptureToRectArea();
|
||||
|
||||
if (!_taskParam.SpecifyResinUse)
|
||||
{
|
||||
// 自动刷干树脂
|
||||
// 识别树脂状况
|
||||
var resinStatus = ResinStatus.RecogniseFromRegion(ra3);
|
||||
resinStatus.Print(Logger);
|
||||
|
||||
if (resinStatus is { CondensedResinCount: <= 0, OriginalResinCount: < 20 })
|
||||
{
|
||||
Logger.LogWarning("树脂不足");
|
||||
await ExitDomain();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool resinUsed = false;
|
||||
if (resinStatus.CondensedResinCount > 0)
|
||||
{
|
||||
resinUsed = PressUseResin(ra3, "浓缩树脂");
|
||||
resinStatus.CondensedResinCount -= 1;
|
||||
}
|
||||
else if (resinStatus.OriginalResinCount >= 20)
|
||||
{
|
||||
resinUsed = PressUseResin(ra3, "原粹树脂");
|
||||
resinStatus.OriginalResinCount -= 20;
|
||||
}
|
||||
|
||||
if (!resinUsed)
|
||||
{
|
||||
Logger.LogWarning("自动秘境:未找到可用的树脂,可能是{Msg1} 或者 {Msg2}。", "树脂不足", "OCR 识别失败");
|
||||
await ExitDomain();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (resinStatus is { CondensedResinCount: <= 0, OriginalResinCount: < 20 })
|
||||
{
|
||||
// 没树脂了就是最后一回合了
|
||||
isLastTurn = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 指定使用树脂
|
||||
var textListInPrompt2 = ra3.FindMulti(RecognitionObject.Ocr(ra3.Width * 0.25, ra3.Height * 0.2, ra3.Width * 0.5, ra3.Height * 0.6));
|
||||
// 按优先级使用
|
||||
var failCount = 0;
|
||||
foreach (var record in _resinPriorityListWhenSpecifyUse)
|
||||
{
|
||||
if (record.RemainCount > 0 && PressUseResin(textListInPrompt2, record.Name))
|
||||
{
|
||||
record.RemainCount -= 1;
|
||||
Logger.LogInformation("自动秘境:{Name} 刷取 {Re}/{Max}", record.Name, record.MaxCount - record.RemainCount, record.MaxCount);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (_resinPriorityListWhenSpecifyUse.Sum(o => o.RemainCount) <= 0)
|
||||
{
|
||||
// 全部刷完
|
||||
isLastTurn = true;
|
||||
}
|
||||
|
||||
if (failCount == _resinPriorityListWhenSpecifyUse.Count)
|
||||
{
|
||||
// 没有找到对应的树脂
|
||||
Logger.LogWarning("自动秘境:指定树脂领取次数时,当前可用树脂选项无法满足配置。你可能设置的刷取次数过多!退出秘境。");
|
||||
Logger.LogInformation("当前刷取情况:{ResinList}", string.Join(", ", _resinPriorityListWhenSpecifyUse.Select(o => $"{o.Name}({o.MaxCount - o.RemainCount}/{o.MaxCount})")));
|
||||
await ExitDomain();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果没有选择树脂的提示,说明只有原粹树脂
|
||||
// 继续向下执行
|
||||
}
|
||||
|
||||
Sleep(1000, _ct);
|
||||
|
||||
var hasSkip = false;
|
||||
var captureArea = TaskContext.Instance().SystemInfo.ScaleMax1080PCaptureRect;
|
||||
var assetScale = TaskContext.Instance().SystemInfo.AssetScale;
|
||||
for (var i = 0; i < 30; i++)
|
||||
{
|
||||
// 跳过领取动画
|
||||
if (!hasSkip)
|
||||
{
|
||||
TaskContext.Instance().PostMessageSimulator.LeftButtonClick(); // 先随便点一个地方使得跳过出现
|
||||
}
|
||||
|
||||
using var ra = CaptureToRectArea();
|
||||
|
||||
// OCR识别是否有跳过
|
||||
var ocrList = ra.FindMulti(RecognitionObject.Ocr(captureArea.Width - 230 * assetScale, 0,
|
||||
230 * assetScale - 5, 80 * assetScale));
|
||||
var skipTextRa = ocrList.FirstOrDefault(t => Regex.IsMatch(t.Text, this.skipLocalizedString));
|
||||
if (skipTextRa != null)
|
||||
{
|
||||
hasSkip = true;
|
||||
skipTextRa.Click(); // 有则点击
|
||||
}
|
||||
|
||||
|
||||
// 优先点击继续
|
||||
using var confirmRectArea = ra.Find(AutoFightAssets.Instance.ConfirmRa);
|
||||
if (!confirmRectArea.IsEmpty())
|
||||
@@ -1080,28 +1120,33 @@ public class AutoDomainTask : ISoloTask
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!recognizeResin)
|
||||
{
|
||||
confirmRectArea.Click();
|
||||
return true;
|
||||
}
|
||||
|
||||
var (condensedResinCount, fragileResinCount) = GetRemainResinStatus();
|
||||
if (condensedResinCount == 0 && fragileResinCount < 20)
|
||||
{
|
||||
// 没有体力了退出
|
||||
var exitRectArea = ra.Find(AutoFightAssets.Instance.ExitRa);
|
||||
if (!exitRectArea.IsEmpty())
|
||||
{
|
||||
exitRectArea.Click();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!chooseResinPrompt)
|
||||
{
|
||||
// TODO 前面没有弹框的情况下,意味着只有原粹树脂,要再识别一次右上角确认树脂余量,没有余量直接退出
|
||||
}
|
||||
|
||||
// 有体力继续
|
||||
confirmRectArea.Click();
|
||||
await Delay(60, _ct); // 双击
|
||||
confirmRectArea.Click();
|
||||
|
||||
if (!chooseResinPrompt)
|
||||
{
|
||||
// 真没树脂了还有提示兜底
|
||||
await Delay(900, _ct);
|
||||
var textListInNoResinPrompt = CaptureToRectArea().FindMulti(RecognitionObject.Ocr(ra2.Width * 0.25, ra2.Height * 0.2, ra2.Width * 0.5, ra2.Height * 0.6));
|
||||
if (textListInNoResinPrompt.Any(t => t.Text.Contains("是否仍要") && t.Text.Contains("挑战") && t.Text.Contains("秘境")))
|
||||
{
|
||||
var cancelBtn = textListInNoResinPrompt.FirstOrDefault(t => t.Text.Contains("取消"));
|
||||
if (cancelBtn != null)
|
||||
{
|
||||
cancelBtn.Click();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1112,41 +1157,69 @@ public class AutoDomainTask : ISoloTask
|
||||
throw new NormalEndException("未检测到秘境结束,可能是背包物品已满。");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取剩余树脂状态
|
||||
/// </summary>
|
||||
private (int, int) GetRemainResinStatus()
|
||||
private async Task ExitDomain()
|
||||
{
|
||||
var condensedResinCount = 0;
|
||||
var fragileResinCount = 0;
|
||||
Simulation.SendInput.Keyboard.KeyPress(VK.VK_ESCAPE);
|
||||
await Delay(500, _ct);
|
||||
Simulation.SendInput.Keyboard.KeyPress(VK.VK_ESCAPE);
|
||||
await Delay(800, _ct);
|
||||
Bv.ClickBlackConfirmButton(CaptureToRectArea());
|
||||
}
|
||||
|
||||
var ra = CaptureToRectArea();
|
||||
// 浓缩树脂
|
||||
var condensedResinCountRa = ra.Find(AutoFightAssets.Instance.CondensedResinCountRa);
|
||||
if (!condensedResinCountRa.IsEmpty())
|
||||
private bool PressUseResin(ImageRegion ra, string resinName)
|
||||
{
|
||||
var regionList = ra.FindMulti(RecognitionObject.Ocr(ra.Width * 0.25, ra.Height * 0.2, ra.Width * 0.5, ra.Height * 0.6));
|
||||
return PressUseResin(regionList, resinName);
|
||||
}
|
||||
|
||||
private bool PressUseResin(List<Region> regionList, string resinName)
|
||||
{
|
||||
var resinKey = regionList.FirstOrDefault(t => t.Text.Contains(resinName));
|
||||
if (resinKey != null)
|
||||
{
|
||||
// 图像右侧就是浓缩树脂数量
|
||||
var countArea = ra.DeriveCrop(condensedResinCountRa.X + condensedResinCountRa.Width,
|
||||
condensedResinCountRa.Y, condensedResinCountRa.Width, condensedResinCountRa.Height);
|
||||
// Cv2.ImWrite($"log/resin_{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff")}.png", countArea.SrcGreyMat);
|
||||
var count = OcrFactory.Paddle.OcrWithoutDetector(countArea.CacheGreyMat);
|
||||
condensedResinCount = StringUtils.TryParseInt(count);
|
||||
// 找到树脂名称对应的按键,关键词为使用,是同一行的(高度相交)
|
||||
var useList = regionList.Where(t => t.Text.Contains("使用")).ToList();
|
||||
if (useList.Count != 0)
|
||||
{
|
||||
// 找到使用按键
|
||||
var useKey = useList.FirstOrDefault(t => t.X > TaskContext.Instance().SystemInfo.ScaleMax1080PCaptureRect.Width / 2
|
||||
&& IsHeightOverlap(t, resinKey));
|
||||
if (useKey != null)
|
||||
{
|
||||
// 点击使用
|
||||
useKey.Click();
|
||||
// 解决水龙王按下左键后没松开,然后后续点击按下就没反应了。使用双击
|
||||
Sleep(60, _ct);
|
||||
useKey.Click();
|
||||
Logger.LogInformation("自动秘境:使用 {ResinName}", resinName);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning("自动秘境:未找到 {ResinName} 的使用按键", resinName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning("自动秘境:未找到 {ResinName} 的使用按键", resinName);
|
||||
}
|
||||
}
|
||||
|
||||
// 脆弱树脂
|
||||
var fragileResinCountRa = ra.Find(AutoFightAssets.Instance.FragileResinCountRa);
|
||||
if (!fragileResinCountRa.IsEmpty())
|
||||
{
|
||||
// 图像右侧就是脆弱树脂数量
|
||||
var countArea = ra.DeriveCrop(fragileResinCountRa.X + fragileResinCountRa.Width, fragileResinCountRa.Y,
|
||||
(int)(fragileResinCountRa.Width * 3), fragileResinCountRa.Height);
|
||||
var count = OcrFactory.Paddle.Ocr(countArea.SrcMat);
|
||||
fragileResinCount = StringUtils.TryParseInt(count);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Logger.LogInformation("剩余:浓缩树脂 {CondensedResinCount} 原粹树脂 {FragileResinCount}", condensedResinCount,
|
||||
fragileResinCount);
|
||||
return (condensedResinCount, fragileResinCount);
|
||||
/// <summary>
|
||||
/// 判断两个区域在垂直方向上是否有重叠
|
||||
/// </summary>
|
||||
private bool IsHeightOverlap(Region region1, Region region2)
|
||||
{
|
||||
int region1Top = region1.Y;
|
||||
int region1Bottom = region1.Y + region1.Height;
|
||||
int region2Top = region2.Y;
|
||||
int region2Bottom = region2.Y + region2.Height;
|
||||
|
||||
// 检查区域是否在垂直方向上重叠
|
||||
return (region1Top <= region2Bottom && region1Bottom >= region2Top);
|
||||
}
|
||||
|
||||
private async Task ArtifactSalvage()
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using BetterGenshinImpact.Core.Recognition.OCR;
|
||||
using BetterGenshinImpact.GameTask.AutoFight.Assets;
|
||||
using BetterGenshinImpact.GameTask.Model.Area;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoDomain.Model;
|
||||
|
||||
public class ResinStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// 原粹树脂(1自回体)
|
||||
/// </summary>
|
||||
public int OriginalResinCount { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 脆弱树脂(60)
|
||||
/// </summary>
|
||||
public int FragileResinCount { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 浓缩树脂(40)
|
||||
/// </summary>
|
||||
public int CondensedResinCount { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 须臾树脂(60壶内购买)
|
||||
/// </summary>
|
||||
public int TransientResinCount { get; set; } = 0;
|
||||
|
||||
public static ResinStatus RecogniseFromRegion(ImageRegion region)
|
||||
{
|
||||
var status = new ResinStatus();
|
||||
|
||||
// 1. 原粹树脂 起点 w-(256+100) ~ w-256
|
||||
var captureArea = TaskContext.Instance().SystemInfo.ScaleMax1080PCaptureRect;
|
||||
var assetScale = TaskContext.Instance().SystemInfo.AssetScale;
|
||||
var originalResinTopIconRa = AutoFightAssets.Instance.OriginalResinTopIconRa;
|
||||
var originalResinRes = region.Find(originalResinTopIconRa);
|
||||
if (originalResinRes.IsEmpty())
|
||||
{
|
||||
throw new Exception("未找到原粹树脂图标");
|
||||
}
|
||||
|
||||
// 找出 icon 的位置 + 30 ~ w-267 就是原粹树脂的数字
|
||||
var originalResinCountRect = new Rect(originalResinRes.Right + 30, (int)(37 * assetScale),
|
||||
captureArea.Width - (originalResinRes.Right + 30) - (int)(267 * assetScale), (int)(21 * assetScale));
|
||||
string cnt1 = OcrFactory.Paddle.OcrWithoutDetector(region.DeriveCrop(originalResinCountRect).SrcMat);
|
||||
status.OriginalResinCount = StringUtils.TryExtractPositiveInt(cnt1, 0);
|
||||
|
||||
// 2. 浓缩树脂
|
||||
var condensedResinRes = region.Find(AutoFightAssets.Instance.CondensedResinTopIconRa);
|
||||
if (condensedResinRes.IsExist())
|
||||
{
|
||||
// 找出 icon 的位置 + 25 ~ icon 的位置+45 就是浓缩树脂的数字,数字宽20
|
||||
var condensedResinCountRect = new Rect(condensedResinRes.Right + (int)(25 * assetScale), condensedResinRes.Y, (int)(20 * assetScale), condensedResinRes.Height);
|
||||
string cnt40 = OcrFactory.Paddle.OcrWithoutDetector(region.DeriveCrop(condensedResinCountRect).SrcMat);
|
||||
status.CondensedResinCount = StringUtils.TryExtractPositiveInt(cnt40, 0);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
public void Print(ILogger logger)
|
||||
{
|
||||
// logger.LogInformation("原粹树脂:{Cnt1},浓缩树脂:{Cnt2},须臾树脂:{Cnt3},脆弱树脂:{Cnt4}",
|
||||
// OriginalResinCount, CondensedResinCount, FragileResinCount, TransientResinCount);
|
||||
logger.LogInformation("原粹树脂:{Cnt1},浓缩树脂:{Cnt2}",
|
||||
OriginalResinCount, CondensedResinCount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoDomain.Model;
|
||||
|
||||
/// <summary>
|
||||
/// 树脂使用记录
|
||||
/// 用于自动秘境指定树脂刷取次数时候,计算剩余刷取次数
|
||||
/// </summary>
|
||||
public class ResinUseRecord
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public int RemainCount { get; set; }
|
||||
|
||||
public int MaxCount { get; set; }
|
||||
|
||||
public ResinUseRecord(string name, int maxCount)
|
||||
{
|
||||
Name = name;
|
||||
RemainCount = maxCount;
|
||||
MaxCount = maxCount;
|
||||
}
|
||||
|
||||
public static List<ResinUseRecord> BuildFromDomainParam(AutoDomainParam taskParam)
|
||||
{
|
||||
List<ResinUseRecord> list = [];
|
||||
if (taskParam.SpecifyResinUse)
|
||||
{
|
||||
if (taskParam.CondensedResinUseCount > 0)
|
||||
{
|
||||
list.Add(new ResinUseRecord("浓缩树脂", taskParam.CondensedResinUseCount));
|
||||
}
|
||||
if (taskParam.OriginalResinUseCount > 0)
|
||||
{
|
||||
list.Add(new ResinUseRecord("原粹树脂", taskParam.OriginalResinUseCount));
|
||||
}
|
||||
if (taskParam.TransientResinUseCount > 0)
|
||||
{
|
||||
list.Add(new ResinUseRecord("须臾树脂", taskParam.TransientResinUseCount));
|
||||
}
|
||||
if (taskParam.FragileResinUseCount > 0)
|
||||
{
|
||||
list.Add(new ResinUseRecord("脆弱树脂", taskParam.FragileResinUseCount));
|
||||
}
|
||||
|
||||
if (list.Count == 0)
|
||||
{
|
||||
throw new Exception("你选择了指定树脂刷取次数,请至少配置一种树脂的刷取次数!");
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 456 B |
@@ -26,8 +26,11 @@ public class AutoFightAssets : BaseAssets<AutoFightAssets>
|
||||
|
||||
// 树脂状态
|
||||
public RecognitionObject CondensedResinCountRa;
|
||||
|
||||
public RecognitionObject FragileResinCountRa;
|
||||
// 自动秘境
|
||||
// public RecognitionObject LockIconRa; // 锁定辅助图标
|
||||
public RecognitionObject CondensedResinTopIconRa;
|
||||
public RecognitionObject OriginalResinTopIconRa;
|
||||
|
||||
public Dictionary<string, string> AvatarCostumeMap;
|
||||
|
||||
@@ -245,5 +248,31 @@ public class AutoFightAssets : BaseAssets<AutoFightAssets>
|
||||
RegionOfInterest = new Rect(CaptureRect.Width / 2, CaptureRect.Height / 3 * 2, CaptureRect.Width / 2, CaptureRect.Height / 3),
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
|
||||
// 自动秘境
|
||||
// LockIconRa = new RecognitionObject
|
||||
// {
|
||||
// Name = "LockIcon",
|
||||
// RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
// TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", "lock_icon.png"),
|
||||
// RegionOfInterest = new Rect(CaptureRect.Width - (int)(215 * AssetScale), 0, (int)(215 * AssetScale), (int)(80 * AssetScale)),
|
||||
// DrawOnWindow = false
|
||||
// }.InitTemplate();
|
||||
CondensedResinTopIconRa = new RecognitionObject
|
||||
{
|
||||
Name = "CondensedResinTopIcon",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", "condensed_resin_top_icon.png"),
|
||||
RegionOfInterest = new Rect((int)(1270 * AssetScale), (int)(25 * AssetScale), (int)(520 * AssetScale), (int)(45 * AssetScale)),
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
OriginalResinTopIconRa = new RecognitionObject
|
||||
{
|
||||
Name = "OriginalResinTopIcon",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", "original_resin_top_icon.png"),
|
||||
RegionOfInterest = new Rect(CaptureRect.Width - (int)(450 * AssetScale), (int)(25 * AssetScale), (int)(265 * AssetScale), (int)(45 * AssetScale)),
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,11 @@ public partial class AutoFightConfig : ObservableObject
|
||||
[ObservableProperty]
|
||||
private int _pickDropsAfterFightSeconds = 15;
|
||||
|
||||
/// <summary>
|
||||
/// 拾取战斗人次阈值,当战斗人次小于一定次数,就结束战斗情况下,不触发拾取掉落物和万叶拾取后拾取,只有不小于2时才生效。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private int? _battleThresholdForLoot;
|
||||
/// <summary>
|
||||
/// 战斗结束后,如果存在枫原万叶,则使用该角色捡材料
|
||||
/// </summary>
|
||||
|
||||
@@ -36,6 +36,7 @@ public class AutoFightParam : BaseTaskParam
|
||||
FinishDetectConfig.BeforeDetectDelay = autoFightConfig.FinishDetectConfig.BeforeDetectDelay;
|
||||
KazuhaPartyName = autoFightConfig.KazuhaPartyName;
|
||||
OnlyPickEliteDropsMode = autoFightConfig.OnlyPickEliteDropsMode;
|
||||
BattleThresholdForLoot = autoFightConfig.BattleThresholdForLoot ?? BattleThresholdForLoot;
|
||||
//下面参数固定,只取自动战斗里面的
|
||||
FinishDetectConfig.BattleEndProgressBarColor = TaskContext.Instance().Config.AutoFightConfig.FinishDetectConfig.BattleEndProgressBarColor;
|
||||
FinishDetectConfig.BattleEndProgressBarColorTolerance = TaskContext.Instance().Config.AutoFightConfig.FinishDetectConfig.BattleEndProgressBarColorTolerance;
|
||||
@@ -48,7 +49,7 @@ public class AutoFightParam : BaseTaskParam
|
||||
public bool FightFinishDetectEnabled { get; set; } = false;
|
||||
public bool PickDropsAfterFightEnabled { get; set; } = false;
|
||||
public int PickDropsAfterFightSeconds { get; set; } = 15;
|
||||
|
||||
public int BattleThresholdForLoot { get; set; } = -1;
|
||||
public int Timeout { get; set; } = 120;
|
||||
|
||||
public bool KazuhaPickupEnabled = true;
|
||||
|
||||
@@ -417,44 +417,12 @@ public class AutoFightTask : ISoloTask
|
||||
}, cts2.Token);
|
||||
|
||||
await fightTask;
|
||||
|
||||
// 战斗结束检测线程
|
||||
// var endTask = Task.Run(async () =>
|
||||
// {
|
||||
// if (!_taskParam.FightFinishDetectEnabled)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// while (!cts2.IsCancellationRequested)
|
||||
// {
|
||||
// var finish = await CheckFightFinish();
|
||||
// if (finish)
|
||||
// {
|
||||
// await cts2.CancelAsync();
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// Sleep(1000, cts2.Token);
|
||||
// }
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// Debug.WriteLine(e.Message);
|
||||
// Debug.WriteLine(e.StackTrace);
|
||||
// }
|
||||
// }, cts2.Token);
|
||||
//
|
||||
// await Task.WhenAll(fightTask, endTask);
|
||||
//战斗人次少于2时(通常无怪物情况下),跳过拾取
|
||||
if (countFight < 2)
|
||||
if (_taskParam.BattleThresholdForLoot>=2 && countFight < _taskParam.BattleThresholdForLoot)
|
||||
{
|
||||
Logger.LogInformation($"战斗人次({countFight})低于配置人次({_taskParam.BattleThresholdForLoot}),跳过此次拾取!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (_taskParam.KazuhaPickupEnabled)
|
||||
{
|
||||
// 队伍中存在万叶的时候使用一次长E
|
||||
@@ -505,7 +473,7 @@ public class AutoFightTask : ISoloTask
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogInformation((countFight < 2 ? "首个人出招就结束战斗,应该无怪物" : "距最近一次万叶出招,时间过短") + ",跳过此次万叶拾取!");
|
||||
Logger.LogInformation("距最近一次万叶出招,时间过短,跳过此次万叶拾取!");
|
||||
}
|
||||
}
|
||||
//切换过队伍的,需要再切回来
|
||||
|
||||
@@ -2988,12 +2988,6 @@
|
||||
"nameEn": "pyro",
|
||||
"type": "火元素",
|
||||
"count": 4
|
||||
},
|
||||
{
|
||||
"id": null,
|
||||
"nameEn": null,
|
||||
"type": null,
|
||||
"count": null
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -198,7 +198,7 @@ public partial class AutoPickTrigger : ITaskTrigger
|
||||
if (config.OcrEngine == PickOcrEngineEnum.Yap.ToString())
|
||||
{
|
||||
var textMat = new Mat(content.CaptureRectArea.CacheGreyMat, textRect);
|
||||
text = _pickTextInference.Inference(TextInferenceFactory.PreProcessForInference(textMat));
|
||||
text = _pickTextInference.Inference(textMat);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -0,0 +1,232 @@
|
||||
using BetterGenshinImpact.Core.Simulator;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.GameTask.Model.Area;
|
||||
using Fischless.WindowsInput;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GameTask.Model.GameUI
|
||||
{
|
||||
public class GridScreen : IAsyncEnumerable<ImageRegion>
|
||||
{
|
||||
private readonly Rect gridRoi;
|
||||
private readonly CancellationToken ct;
|
||||
private readonly ILogger logger;
|
||||
private readonly InputSimulator input = Simulation.SendInput;
|
||||
private readonly int s1Round;
|
||||
private readonly int roundMilliseconds;
|
||||
private readonly int s2Round;
|
||||
private readonly double s3Scale;
|
||||
|
||||
/// <summary>
|
||||
/// 对Gird类型界面的操作封装类
|
||||
/// 直接对此类对象进行遍历即可获取所有项
|
||||
/// 每次的截图是上次滚动后的,如果实时性要求高,应每次迭代自行截图
|
||||
/// 在末页可能重复返回GridItem,须自行处理
|
||||
/// </summary>
|
||||
/// <param name="gridRoi">Grid所在位置</param>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="ct"></param>
|
||||
public GridScreen(Rect gridRoi, int s1Round, int roundMilliseconds, int s2Round, double s3Scale, ILogger logger, CancellationToken ct)
|
||||
{
|
||||
this.gridRoi = gridRoi;
|
||||
this.ct = ct;
|
||||
this.logger = logger;
|
||||
this.s1Round = s1Round;
|
||||
this.roundMilliseconds = roundMilliseconds;
|
||||
this.s2Round = s2Round;
|
||||
this.s3Scale = s3Scale;
|
||||
}
|
||||
|
||||
public IAsyncEnumerator<ImageRegion> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new GridEnumerator(this.gridRoi, this.s1Round, this.roundMilliseconds, this.s2Round, this.s3Scale, this.logger, this.input, this.ct);
|
||||
}
|
||||
|
||||
public class GridEnumerator : IAsyncEnumerator<ImageRegion>
|
||||
{
|
||||
private readonly Rect roi;
|
||||
private readonly CancellationToken ct;
|
||||
private readonly ILogger logger;
|
||||
private readonly InputSimulator input = Simulation.SendInput;
|
||||
private readonly int s1Round;
|
||||
private readonly int roundMilliseconds;
|
||||
private readonly int s2Round;
|
||||
private readonly double s3Scale;
|
||||
|
||||
private record Page(ImageRegion ImageRegion, Stack<Rect> Rects);
|
||||
private Page? currentPage;
|
||||
private ImageRegion current;
|
||||
ImageRegion IAsyncEnumerator<ImageRegion>.Current => current;
|
||||
|
||||
/// <summary>
|
||||
/// 滚动操作枚举器
|
||||
/// </summary>
|
||||
/// <param name="roi"></param>
|
||||
/// <param name="s1Round">测试是否能滚动时发出的滚动命令次数</param>
|
||||
/// <param name="roundMilliseconds">滚动命令间隔毫秒</param>
|
||||
/// <param name="s2Round">滚过一整页时发出的滚动命令次数</param>
|
||||
/// <param name="s3Scale">微调滚动时控制首行距离上边界的参数</param>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="ct"></param>
|
||||
public GridEnumerator(Rect roi, int s1Round, int roundMilliseconds, int s2Round, double s3Scale, ILogger logger, InputSimulator input, CancellationToken ct)
|
||||
{
|
||||
this.roi = roi;
|
||||
this.ct = ct;
|
||||
this.logger = logger;
|
||||
this.input = input;
|
||||
this.s1Round = s1Round;
|
||||
this.roundMilliseconds = roundMilliseconds;
|
||||
this.s2Round = s2Round;
|
||||
this.s3Scale = s3Scale;
|
||||
}
|
||||
|
||||
public async Task<bool> TryVerticalScollDown()
|
||||
{
|
||||
using var ra = TaskControl.CaptureToRectArea();
|
||||
using ImageRegion prevGrid = ra.DeriveCrop(roi);
|
||||
|
||||
for (int i = 0; i < this.s1Round; i++)
|
||||
{
|
||||
this.input.Mouse.VerticalScroll(-2);
|
||||
await TaskControl.Delay(this.roundMilliseconds, this.ct);
|
||||
}
|
||||
await TaskControl.Delay(300, this.ct);
|
||||
using var ra2 = TaskControl.CaptureToRectArea();
|
||||
using ImageRegion scrolledGrid = ra2.DeriveCrop(this.roi);
|
||||
|
||||
bool isScrolling = IsScrolling(prevGrid.CacheGreyMat, scrolledGrid.CacheGreyMat, out Point2d shift, logger: this.logger);
|
||||
|
||||
return isScrolling;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否还能继续滚动,如果到底了则只能滚动一丝并很快地回弹
|
||||
/// </summary>
|
||||
/// <param name="prevGray">先前的灰度图</param>
|
||||
/// <param name="nextGray">尝试滚动并等待可能的回弹后的灰度图</param>
|
||||
/// <param name="shift">估计的位移</param>
|
||||
/// <param name="lowerThreshold">低于下限则可能不存在平移</param>
|
||||
/// <param name="upperThreshold">上限用于抵消微小的其他差异</param>
|
||||
/// <param name="logger"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsScrolling(Mat prevGray, Mat nextGray, out Point2d shift, double lowerThreshold = 0.5, double upperThreshold = 0.95, ILogger? logger = null)
|
||||
{
|
||||
using Mat prev = new Mat();
|
||||
prevGray.ConvertTo(prev, MatType.CV_32FC1);
|
||||
using Mat next = new Mat();
|
||||
nextGray.ConvertTo(next, MatType.CV_32FC1);
|
||||
|
||||
using Mat window = new Mat();
|
||||
shift = Cv2.PhaseCorrelate(prev, next, window, out double response); // 相位相关性
|
||||
logger?.LogInformation($"response={response:F3}, shift=({shift.X:F2}, {shift.Y:F2})");
|
||||
return response > lowerThreshold && response < upperThreshold;
|
||||
}
|
||||
|
||||
public static IEnumerable<Rect> GetGridItems(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 async ValueTask<bool> MoveNextAsync()
|
||||
{
|
||||
if (this.currentPage == null || this.currentPage.Rects.Count < 1)
|
||||
{
|
||||
if (this.currentPage != null)
|
||||
{
|
||||
//BetterGenshinImpact.View.Drawable.VisionContext.Instance().DrawContent.ClearAll();
|
||||
|
||||
using var ra4 = TaskControl.CaptureToRectArea();
|
||||
ra4.MoveTo(this.roi.X + this.roi.Width / 2, this.roi.Y + this.roi.Height / 2);
|
||||
await TaskControl.Delay(300, ct);
|
||||
|
||||
bool canScoll = await TryVerticalScollDown();
|
||||
|
||||
if (canScoll)
|
||||
{
|
||||
for (int i = 0; i < this.s2Round; i++) // 再滚动差不多(最多行数-1)行
|
||||
{
|
||||
input.Mouse.VerticalScroll(-2);
|
||||
await TaskControl.Delay(this.roundMilliseconds, ct);
|
||||
}
|
||||
|
||||
DateTimeOffset rollingEndTime = DateTime.Now.AddSeconds(2);
|
||||
while (DateTime.Now < rollingEndTime)
|
||||
{
|
||||
await TaskControl.Delay(60, ct);
|
||||
using var ra2 = TaskControl.CaptureToRectArea();
|
||||
using ImageRegion grid2 = ra2.DeriveCrop(this.roi);
|
||||
IEnumerable<Rect> gridItems2 = GetGridItems(grid2.SrcMat);
|
||||
if (gridItems2.Min(i => i.Y) > (ra2.Width * this.s3Scale)) // 最后精细滚动,保证完整地显示最多行
|
||||
{
|
||||
input.Mouse.VerticalScroll(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
using var ra3 = TaskControl.CaptureToRectArea();
|
||||
using ImageRegion grid3 = ra3.DeriveCrop(this.roi);
|
||||
grid3.MoveTo(grid3.Width, grid3.Height);
|
||||
await TaskControl.Delay(300, ct);
|
||||
}
|
||||
else
|
||||
{
|
||||
await TaskControl.Delay(300, ct);
|
||||
this.logger.LogInformation("滚动到底部了");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
using var ra = TaskControl.CaptureToRectArea();
|
||||
var imageRegion = ra.DeriveCrop(this.roi);
|
||||
IEnumerable<Rect> gridItems = GetGridItems(imageRegion.SrcMat);
|
||||
this.currentPage = new Page(imageRegion, new Stack<Rect>(gridItems));
|
||||
|
||||
//foreach (Rect item in gridItems)
|
||||
//{
|
||||
// imageRegion.DrawRect(item, item.GetHashCode().ToString(), new System.Drawing.Pen(System.Drawing.Color.Blue));
|
||||
//}
|
||||
}
|
||||
|
||||
this.current = this.currentPage.ImageRegion.DeriveCrop(this.currentPage.Rects.Pop());
|
||||
return true;
|
||||
}
|
||||
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,21 +88,21 @@ public partial class StringUtils
|
||||
return int.TryParse(text, out int result) ? result : defaultValue;
|
||||
}
|
||||
|
||||
public static int TryExtractPositiveInt(string text)
|
||||
public static int TryExtractPositiveInt(string text, int defaultValue = -1)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
return -1;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
text = RegexHelper.ExcludeNumberRegex().Replace(text, "");
|
||||
return int.Parse(text);
|
||||
return TryParseInt(text, defaultValue);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return -1;
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -335,13 +335,18 @@
|
||||
|
||||
|
||||
<!-- 自动秘境 -->
|
||||
<TextBlock Margin="4,0,0,4"
|
||||
FontSize="14"
|
||||
Foreground="{DynamicResource SystemAccentColorPrimaryBrush}"
|
||||
Text="自动秘境" />
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" Margin="4,0,0,4">
|
||||
<TextBlock FontSize="14"
|
||||
Foreground="{DynamicResource SystemAccentColorPrimaryBrush}"
|
||||
Text="自动秘境" />
|
||||
<TextBlock Margin="4,0,0,0"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="11"
|
||||
Text="(此处未覆盖的配置可在 独立任务-自动秘境 中配置)" />
|
||||
</StackPanel>
|
||||
|
||||
|
||||
|
||||
<ui:CardExpander Margin="0,0,0,12" ContentPadding="0" IsExpanded="{Binding SelectedConfig.WeeklyDomainEnabled, Converter={StaticResource InverseBooleanConverter}, Mode=TwoWay}">
|
||||
<ui:CardExpander Margin="0,0,0,12" ContentPadding="0">
|
||||
<ui:CardExpander.Icon>
|
||||
<ui:FontIcon Glyph="" Style="{StaticResource FaFontIconStyle}" />
|
||||
</ui:CardExpander.Icon>
|
||||
@@ -470,7 +475,8 @@
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ui:CardExpander>
|
||||
<ui:CardExpander Margin="0,0,0,12" ContentPadding="0" IsExpanded="{Binding SelectedConfig.WeeklyDomainEnabled, Mode=TwoWay}">
|
||||
|
||||
<ui:CardExpander Margin="0,0,0,12" ContentPadding="0" IsExpanded="True">
|
||||
<ui:CardExpander.Icon>
|
||||
<ui:FontIcon Glyph="" Style="{StaticResource FaFontIconStyle}" />
|
||||
</ui:CardExpander.Icon>
|
||||
@@ -502,7 +508,7 @@
|
||||
</Grid>
|
||||
</ui:CardExpander.Header>
|
||||
<StackPanel>
|
||||
<Grid Margin="52,16,16,8">
|
||||
<Grid Margin="52,16,16,16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:pages="clr-namespace:BetterGenshinImpact.ViewModel.Pages"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
|
||||
Title="TaskSettingsPage"
|
||||
d:DataContext="{d:DesignInstance Type=pages:TaskSettingsPageViewModel}"
|
||||
d:DesignHeight="1150"
|
||||
@@ -954,20 +955,113 @@
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="循环次数"
|
||||
Text="刷取至树脂耗尽"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="循环秘境多少次,输入 0 则为用光所有树脂为止,优先使用浓缩树脂"
|
||||
Text="优先使用浓缩树脂,然后使用原粹树脂,其余树脂不使用"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBox Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
MinWidth="90"
|
||||
Margin="0,0,36,0"
|
||||
Text="{Binding AutoDomainRoundNum, Mode=TwoWay}" />
|
||||
<ui:ToggleSwitch Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,36,0"
|
||||
IsChecked="{Binding Config.AutoDomainConfig.SpecifyResinUse,Converter={StaticResource InverseBooleanConverter}, Mode=TwoWay}" />
|
||||
</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" />
|
||||
<ui:ToggleSwitch Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,36,0"
|
||||
IsChecked="{Binding Config.AutoDomainConfig.SpecifyResinUse, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
|
||||
<!-- 树脂设置组 -->
|
||||
<Border Margin="16,8,16,16"
|
||||
BorderThickness="1"
|
||||
BorderBrush="{ui:ThemeResource CardStrokeColorDefaultBrush}"
|
||||
Background="{ui:ThemeResource ControlFillColorSecondaryBrush}"
|
||||
CornerRadius="8"
|
||||
IsEnabled="{Binding Config.AutoDomainConfig.SpecifyResinUse, Mode=OneWay}">
|
||||
<StackPanel Margin="12">
|
||||
|
||||
<!-- 原粹树脂设置 -->
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,8,0,12">
|
||||
<ui:TextBlock Text="原粹树脂刷取次数:"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,8,0" />
|
||||
<ui:NumberBox Value="{Binding Config.AutoDomainConfig.OriginalResinUseCount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
Minimum="0"
|
||||
SmallChange="1"
|
||||
LargeChange="5"
|
||||
SpinButtonPlacementMode="Inline"
|
||||
Width="120"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 浓缩树脂设置 -->
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,0,0,12">
|
||||
<ui:TextBlock Text="浓缩树脂刷取次数:"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,8,0" />
|
||||
<ui:NumberBox Value="{Binding Config.AutoDomainConfig.CondensedResinUseCount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
Minimum="0"
|
||||
SmallChange="1"
|
||||
LargeChange="5"
|
||||
SpinButtonPlacementMode="Inline"
|
||||
Width="120" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- 须臾树脂设置 -->
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,0,0,12">
|
||||
<ui:TextBlock Text="须臾树脂刷取次数:"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,8,0" />
|
||||
<ui:NumberBox Value="{Binding Config.AutoDomainConfig.TransientResinUseCount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
Minimum="0"
|
||||
SmallChange="1"
|
||||
LargeChange="5"
|
||||
SpinButtonPlacementMode="Inline"
|
||||
Width="120" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- 脆弱树脂设置 -->
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,0,0,0">
|
||||
<ui:TextBlock Text="脆弱树脂刷取次数:"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,8,0" />
|
||||
<ui:NumberBox Value="{Binding Config.AutoDomainConfig.FragileResinUseCount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
Minimum="0"
|
||||
SmallChange="1"
|
||||
LargeChange="5"
|
||||
SpinButtonPlacementMode="Inline"
|
||||
Width="120" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
|
||||
@@ -878,6 +878,32 @@
|
||||
Margin="0,0,36,0"
|
||||
IsChecked="{Binding PathingConfig.AutoFightConfig.KazuhaPickupEnabled, Mode=TwoWay}" />
|
||||
</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="拾取战斗人次阈值,当战斗人次小于一定次数,就结束战斗情况下,不触发拾取掉落物和万叶拾取配置,只有不小于2时才生效。"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBox Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
MinWidth="120"
|
||||
Margin="0,0,36,0"
|
||||
Text="{Binding PathingConfig.AutoFightConfig.BattleThresholdForLoot}" />
|
||||
</Grid>
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
|
||||
@@ -135,11 +135,11 @@ public partial class CheckUpdateWindow : FluentWindow
|
||||
|
||||
if (_option.Channel == UpdateChannel.Stable)
|
||||
{
|
||||
await RunUpdaterAsync("--source mirrorc");
|
||||
await RunUpdaterAsync("-I --source mirrorc");
|
||||
}
|
||||
else
|
||||
{
|
||||
await RunUpdaterAsync("--source mirrorc-alpha");
|
||||
await RunUpdaterAsync("-I --source mirrorc-alpha");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ public partial class ScriptRepoWindow
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Toast.Error($"更新失败: {ex.Message}");
|
||||
await MessageBox.ErrorAsync($"更新失败,可尝试重置仓库后重新更新。失败原因:: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -226,15 +226,16 @@ public partial class CommonSettingsPageViewModel : ViewModel
|
||||
{
|
||||
var zipPath = dialog.FileName;
|
||||
// 删除旧文件夹
|
||||
if (Directory.Exists(ScriptRepoUpdater.CenterRepoPath))
|
||||
if (Directory.Exists(ScriptRepoUpdater.CenterRepoPathOld))
|
||||
{
|
||||
DirectoryHelper.DeleteReadOnlyDirectory(ScriptRepoUpdater.CenterRepoPath);
|
||||
DirectoryHelper.DeleteReadOnlyDirectory(ScriptRepoUpdater.CenterRepoPathOld);
|
||||
}
|
||||
|
||||
ZipFile.ExtractToDirectory(zipPath, ScriptRepoUpdater.ReposPath, true);
|
||||
|
||||
if (Directory.Exists(ScriptRepoUpdater.CenterRepoPath))
|
||||
if (Directory.Exists(ScriptRepoUpdater.CenterRepoPathOld))
|
||||
{
|
||||
DirectoryHelper.CopyDirectory(ScriptRepoUpdater.CenterRepoPathOld, ScriptRepoUpdater.CenterRepoPath);
|
||||
MessageBox.Information("脚本仓库离线包导入成功!");
|
||||
}
|
||||
else
|
||||
|
||||
@@ -31,6 +31,7 @@ using BetterGenshinImpact.ViewModel.Pages.View;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Collections.Frozen;
|
||||
using System.Diagnostics;
|
||||
using BetterGenshinImpact.GameTask.AutoArtifactSalvage;
|
||||
using BetterGenshinImpact.View.Windows;
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@ public class OcrTest
|
||||
{
|
||||
public static void TestYap()
|
||||
{
|
||||
Mat mat = Cv2.ImRead(@"E:\HuiTask\更好的原神\临时文件\fuben_jueyuan.png");
|
||||
var text = TextInferenceFactory.Pick.Inference(TextInferenceFactory.PreProcessForInference(mat));
|
||||
Debug.WriteLine(text);
|
||||
|
||||
Mat mat2 = Cv2.ImRead(@"E:\HuiTask\更好的原神\临时文件\fuben_jueyuan.png");
|
||||
var text2 = OcrFactory.Paddle.Ocr(mat2);
|
||||
Debug.WriteLine(text2);
|
||||
// Mat mat = Cv2.ImRead(@"E:\HuiTask\更好的原神\临时文件\fuben_jueyuan.png");
|
||||
// var text = TextInferenceFactory.Pick.Inference(TextInferenceFactory.PreProcessForInference(mat));
|
||||
// Debug.WriteLine(text);
|
||||
//
|
||||
// Mat mat2 = Cv2.ImRead(@"E:\HuiTask\更好的原神\临时文件\fuben_jueyuan.png");
|
||||
// var text2 = OcrFactory.Paddle.Ocr(mat2);
|
||||
// Debug.WriteLine(text2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
using BetterGenshinImpact.GameTask.AutoArtifactSalvage;
|
||||
using BetterGenshinImpact.UnitTest.CoreTests.RecognitionTests.OCRTests;
|
||||
using GameTask.Model.GameUI;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
@@ -52,7 +53,7 @@ namespace BetterGenshinImpact.UnitTest.GameTaskTests.AutoArtifactSalvageTests
|
||||
using Mat mat = new Mat(@$"..\..\..\Assets\AutoArtifactSalvage\{screenshot}");
|
||||
|
||||
//
|
||||
var result = AutoArtifactSalvageTask.GetArtifactGridItems(mat);
|
||||
var result = GridScreen.GridEnumerator.GetGridItems(mat);
|
||||
|
||||
//
|
||||
Assert.Equal(4, result.Count());
|
||||
@@ -69,7 +70,7 @@ namespace BetterGenshinImpact.UnitTest.GameTaskTests.AutoArtifactSalvageTests
|
||||
using Mat mat = new Mat(@$"..\..\..\Assets\AutoArtifactSalvage\ArtifactGrid.png");
|
||||
|
||||
//
|
||||
var result = AutoArtifactSalvageTask.GetArtifactGridItems(mat);
|
||||
var result = GridScreen.GridEnumerator.GetGridItems(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));
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using GameTask.Model.GameUI;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BetterGenshinImpact.UnitTest.GameTaskTests.Model.GameUI
|
||||
{
|
||||
public class GridScreenTests
|
||||
{
|
||||
[Fact]
|
||||
/// <summary>
|
||||
/// 测试判断前后两张图是否属于滚动,结果应正确
|
||||
/// </summary>
|
||||
public void IsScrolling_ResultShouldBeRight()
|
||||
{
|
||||
//
|
||||
using Mat mat = new Mat(@$"..\..\..\Assets\AutoArtifactSalvage\ArtifactGrid.png", flags: ImreadModes.Grayscale);
|
||||
using Mat cropped = mat[new Rect(0, 0, mat.Width, mat.Height - 10)];
|
||||
using Mat black = new Mat(mat.Size(), mat.Type(), Scalar.Black);
|
||||
using Mat scrolled = black.Clone(); // 一个向下平移了10像素的图
|
||||
using Mat pos = scrolled[new Rect(0, 10, mat.Width, mat.Height - 10)];
|
||||
cropped.CopyTo(pos);
|
||||
|
||||
//
|
||||
bool result1 = GridScreen.GridEnumerator.IsScrolling(mat, scrolled, out Point2d shift);
|
||||
bool result2 = GridScreen.GridEnumerator.IsScrolling(mat, mat, out Point2d _);
|
||||
bool result3 = GridScreen.GridEnumerator.IsScrolling(mat, black, out Point2d _);
|
||||
|
||||
//
|
||||
Assert.True(result1);
|
||||
Assert.True(shift.Y <= 10 && shift.Y > 9.9);
|
||||
Assert.False(result2);
|
||||
Assert.False(result3);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user