Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6e549814d | ||
|
|
c80799cbee | ||
|
|
c2fce8618d | ||
|
|
663277a990 | ||
|
|
c0fecd079e | ||
|
|
97f1000370 | ||
|
|
02f2c1321a | ||
|
|
f9d0bd4521 | ||
|
|
5e929d3d07 | ||
|
|
3c393087eb | ||
|
|
85c7707c7a | ||
|
|
a41a0bdba1 | ||
|
|
5de2067489 | ||
|
|
c95343e953 | ||
|
|
f34e6c3530 | ||
|
|
2d3395b491 | ||
|
|
d86959297c | ||
|
|
726863462a | ||
|
|
9971817e44 | ||
|
|
bfeaa1b14a | ||
|
|
71fa4eaf3a | ||
|
|
9049c85be7 | ||
|
|
ac85cda170 | ||
|
|
178d253c38 | ||
|
|
8ba5b16710 | ||
|
|
25373cac2a | ||
|
|
2411e1dbef | ||
|
|
4118e7b6f2 | ||
|
|
d6c4f5ab57 | ||
|
|
ac2c7e7ac7 | ||
|
|
07e5ea643a | ||
|
|
f4f9f22977 | ||
|
|
e6c8804b09 | ||
|
|
d71ff06868 | ||
|
|
741da4e0c7 | ||
|
|
a66b802bbd | ||
|
|
60f1a271c4 | ||
|
|
2396daf206 | ||
|
|
d8f06598aa | ||
|
|
6127fab70b | ||
|
|
6432ff1aed | ||
|
|
0670fd9c0d | ||
|
|
c14025181c | ||
|
|
2b658afad6 | ||
|
|
54eecbe046 | ||
|
|
9d807e1e42 | ||
|
|
c3ef67f57a | ||
|
|
13f3272b9c | ||
|
|
7e04d77f88 | ||
|
|
8f1cf62449 | ||
|
|
cad2cf039d | ||
|
|
215f2ce450 | ||
|
|
0a5c78ebbe | ||
|
|
f9671467fc | ||
|
|
621a91638a | ||
|
|
34d0917818 | ||
|
|
2b371cce33 | ||
|
|
510ca82304 | ||
|
|
b83017f52e | ||
|
|
dd6b26ae8d | ||
|
|
cb19255fb4 | ||
|
|
71f2c2f52e | ||
|
|
5d780ec4f8 | ||
|
|
a091bb6734 | ||
|
|
81a7518f72 | ||
|
|
340a3142e5 | ||
|
|
dfad3022c2 | ||
|
|
bb8ccd2297 | ||
|
|
17282a3cef | ||
|
|
bb7d84ffe3 | ||
|
|
28ceb3dd85 | ||
|
|
ce75d038b2 | ||
|
|
17dd19aa47 | ||
|
|
a861a335ac | ||
|
|
c439403231 | ||
|
|
a63ed2f2d2 | ||
|
|
c9634abebb | ||
|
|
1214ca2d65 | ||
|
|
dc853f2307 | ||
|
|
875058ae5b | ||
|
|
e9d715876b | ||
|
|
57bcb3cd6b | ||
|
|
ff993f642f | ||
|
|
4aa8c69d0e | ||
|
|
7511ccc637 | ||
|
|
e9d206eca0 | ||
|
|
88110a21cc | ||
|
|
84c7fcec21 | ||
|
|
b19adcfba4 | ||
|
|
404457922d | ||
|
|
733e5fb98a | ||
|
|
a04d2e437a | ||
|
|
08b921b982 | ||
|
|
e6e78aded0 | ||
|
|
df600c6016 | ||
|
|
d374a95bb8 | ||
|
|
f5e8edccb8 | ||
|
|
f690bc849b | ||
|
|
c3c272c241 | ||
|
|
537f647ba7 | ||
|
|
ca353fea70 | ||
|
|
9bf82a1bbb | ||
|
|
e497f6ec79 | ||
|
|
36e49bcbc7 | ||
|
|
7c1568a809 | ||
|
|
b99144cd3d | ||
|
|
d5d65b7820 | ||
|
|
7d04997300 | ||
|
|
36cbd168ed | ||
|
|
5162bcc88f | ||
|
|
1a2cdbbfd7 | ||
|
|
ec8fa6e824 | ||
|
|
3266b63187 | ||
|
|
294d096229 | ||
|
|
48b5ab8af6 | ||
|
|
e00b38eb66 | ||
|
|
0c435a9393 | ||
|
|
3ca7ab6d4c | ||
|
|
c480cf484e | ||
|
|
2ce4e6d665 | ||
|
|
7b158c442e | ||
|
|
9180b58d94 | ||
|
|
5b8caef75a | ||
|
|
c22edcd39a | ||
|
|
7e88c9a57d | ||
|
|
49fc8ed260 | ||
|
|
f37d1d34a6 | ||
|
|
76dd2f3903 | ||
|
|
5e94037722 | ||
|
|
57610a3945 | ||
|
|
11dda84592 | ||
|
|
b600d577c4 | ||
|
|
dd19afaca5 | ||
|
|
c2cd6dbe9c | ||
|
|
c059611edb | ||
|
|
7ebbfda15d | ||
|
|
54887b90f6 | ||
|
|
77cfcbe73f | ||
|
|
f3e16fbb77 | ||
|
|
99c8cd450e | ||
|
|
dffccd0740 | ||
|
|
6cfa4b27a6 | ||
|
|
e2a25e4492 | ||
|
|
b6220db756 | ||
|
|
958703dcd7 | ||
|
|
c182ec13f9 | ||
|
|
ff0533288a | ||
|
|
2383761b5d | ||
|
|
ebc6ed8e07 | ||
|
|
9ab518d593 | ||
|
|
df84cc9ef1 | ||
|
|
60bd96f1f4 | ||
|
|
d9faefd446 | ||
|
|
19530e6c50 | ||
|
|
842f8506a5 | ||
|
|
2083caa9d7 | ||
|
|
67a418b984 | ||
|
|
216c78d4d5 | ||
|
|
fa1809a1f0 | ||
|
|
fa9eacf4ac | ||
|
|
968048baa9 | ||
|
|
436dfef2ee | ||
|
|
c2f81877dd | ||
|
|
0d6ab88c4a | ||
|
|
d7302b65c3 | ||
|
|
74acb4eb1c | ||
|
|
026dcd4488 | ||
|
|
1cad8c3a00 | ||
|
|
84629942bc | ||
|
|
a6f6ce55dd | ||
|
|
62a19c0052 | ||
|
|
3d63f18831 |
No files matched your search
@@ -1,7 +1,7 @@
|
||||
---
|
||||
name: Bug report / 错误报告
|
||||
about: Create a report to help us improve / 创建报告以帮助我们改进
|
||||
title: "[bug] "
|
||||
title: "[bug]请补充标题内容"
|
||||
labels: bug
|
||||
---
|
||||
|
||||
|
||||
@@ -19,17 +19,17 @@ public class AvatarClassifyGen
|
||||
// 读取基础图像
|
||||
// List<string> sideImageFiles = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "*.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
// 只用一个图像
|
||||
List<string> sideImageFiles = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Chasca.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
List<string> sideImageFiles2 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Olorun.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
List<string> sideImageFiles = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_HutaoCostumeWinter.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
List<string> sideImageFiles2 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Iansan.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
sideImageFiles.AddRange(sideImageFiles2);
|
||||
// List<string> sideImageFiles3 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_NilouCostumeFairy.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
// sideImageFiles.AddRange(sideImageFiles3);
|
||||
// List<string> sideImageFiles4 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Kachina.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
// sideImageFiles.AddRange(sideImageFiles4);
|
||||
// List<string> sideImageFiles5 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Mualani.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
// sideImageFiles.AddRange(sideImageFiles5);
|
||||
// List<string> sideImageFiles6 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Kinich.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
// sideImageFiles.AddRange(sideImageFiles6);
|
||||
List<string> sideImageFiles3 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Citlali.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
sideImageFiles.AddRange(sideImageFiles3);
|
||||
List<string> sideImageFiles4 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Lanyan.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
sideImageFiles.AddRange(sideImageFiles4);
|
||||
List<string> sideImageFiles5 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_XianglingCostumeWinter.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
sideImageFiles.AddRange(sideImageFiles5);
|
||||
List<string> sideImageFiles6 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Mavuika.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
sideImageFiles.AddRange(sideImageFiles6);
|
||||
|
||||
// 生成训练集
|
||||
GenTo(sideImageFiles, Path.Combine(BaseDir, @"dateset\train"), 200);
|
||||
|
||||
@@ -27,9 +27,17 @@ public class AvatarClassifyTransparentGen
|
||||
// 读取基础图像
|
||||
// List<string> sideImageFiles = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "*.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
// 只用一个图像
|
||||
List<string> sideImageFiles = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_Chasca.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
List<string> sideImageFiles2 = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_Olorun.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
List<string> sideImageFiles = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_HutaoCostumeWinter.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
List<string> sideImageFiles2 = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_Iansan.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
sideImageFiles.AddRange(sideImageFiles2);
|
||||
List<string> sideImageFiles3 = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_Citlali.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
sideImageFiles.AddRange(sideImageFiles3);
|
||||
List<string> sideImageFiles4 = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_Lanyan.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
sideImageFiles.AddRange(sideImageFiles4);
|
||||
List<string> sideImageFiles5 = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_XianglingCostumeWinter.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
sideImageFiles.AddRange(sideImageFiles5);
|
||||
List<string> sideImageFiles6 = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_Mavuika.png", SearchOption.TopDirectoryOnly).ToList();
|
||||
sideImageFiles.AddRange(sideImageFiles6);
|
||||
// 生成训练集
|
||||
GenTo(sideImageFiles, Path.Combine(BaseDir, @"dateset\train"), 200);
|
||||
// 生成测试集
|
||||
|
||||
@@ -78,5 +78,13 @@
|
||||
VerticalAlignment="Center"
|
||||
Click="ZoomOut"
|
||||
Content="缩小地图到256" />
|
||||
<Button Canvas.Left="120"
|
||||
Canvas.Top="40"
|
||||
Width="100"
|
||||
Height="23"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
Click="CameraTest"
|
||||
Content="新视角识别测试" />
|
||||
</Canvas>
|
||||
</Window>
|
||||
@@ -1,10 +1,14 @@
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using System.Diagnostics;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.Test.Dataset;
|
||||
using BetterGenshinImpact.Test.Simple;
|
||||
using BetterGenshinImpact.Test.Simple.AllMap;
|
||||
using BetterGenshinImpact.Test.Simple.Track;
|
||||
using BetterGenshinImpact.Test.View;
|
||||
using System.Windows;
|
||||
using BetterGenshinImpact.GameTask.Common.Map;
|
||||
using OpenCvSharp;
|
||||
using Window = System.Windows.Window;
|
||||
|
||||
namespace BetterGenshinImpact.Test;
|
||||
|
||||
@@ -49,10 +53,10 @@ public partial class MainWindow : Window
|
||||
// BigMapMatchTest.Test();
|
||||
|
||||
// FeatureTransfer.Transfer();
|
||||
|
||||
|
||||
// var extractor = new LargeSiftExtractor();
|
||||
// extractor.ExtractAndSaveSift(@"E:\HuiTask\更好的原神\地图匹配\有用的素材\5.2\map_52_2048.png", @"E:\HuiTask\更好的原神\地图匹配\有用的素材\5.2\");
|
||||
|
||||
|
||||
EntireMapTest.Storage256();
|
||||
}
|
||||
|
||||
@@ -85,4 +89,25 @@ public partial class MainWindow : Window
|
||||
{
|
||||
AvatarClassifyTransparentGen.GenAll();
|
||||
}
|
||||
}
|
||||
|
||||
private void CameraTest(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var path = @"E:\HuiTask\更好的原神\地图匹配\比较\小地图\Clip_20240323_185854.png";
|
||||
|
||||
var pic1 = new Mat(path);
|
||||
CameraOrientationFromLimint cameraOrientation = new();
|
||||
var f = cameraOrientation.PredictRotation(pic1);
|
||||
Debug.WriteLine("C#版本 方向1:" + f);
|
||||
|
||||
|
||||
// var pic2 = new Mat(path);
|
||||
// CameraOrientationV2 cameraOrientation3 = new();
|
||||
// var f3 = cameraOrientation3.PredictRotation(pic2);
|
||||
// Debug.WriteLine("py直接翻译C#版本 方向1:" + f3);
|
||||
|
||||
|
||||
var grey = new Mat(path, ImreadModes.Grayscale);
|
||||
var f2 = CameraOrientation.ComputeMiniMap(grey);
|
||||
Debug.WriteLine("老版本方向2:" + f2);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public class BigMapMatchTest
|
||||
SpeedTimer speedTimer = new();
|
||||
// var mainMap100BlockMat = new Mat(@"D:\HuiPrograming\Projects\CSharp\MiHoYo\BetterGenshinImpact\BetterGenshinImpact\Assets\Map\mainMap100Block.png", ImreadModes.Grayscale);
|
||||
|
||||
var map2048 = MapAssets.Instance.MainMap2048BlockMat.Value;
|
||||
var map2048 = new Mat(@"E:\HuiTask\更好的原神\地图匹配\有用的素材\5.2\map_52_2048.png", ImreadModes.Grayscale);
|
||||
var mainMap100BlockMat = ResizeHelper.Resize(map2048, 1d / (4 * 2));
|
||||
Cv2.ImWrite(@"E:\HuiTask\更好的原神\地图匹配\有用的素材\mainMap128Block.png", mainMap100BlockMat);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public class MapTeleportPointDraw
|
||||
// var pList = LoadTeleportPoint(@"E:\HuiTask\更好的原神\地图匹配\地图点位\5.0");
|
||||
// pList.AddRange(MapAssets.Instance.TpPositions);
|
||||
var map = new Mat(@"E:\HuiTask\更好的原神\地图匹配\有用的素材\5.0\mainMap1024BlockColor.png");
|
||||
DrawTeleportPoint(map, MapAssets.Instance.TpPositions);
|
||||
DrawTeleportPoint(map, MapLazyAssets.Instance.TpPositions);
|
||||
Cv2.ImWrite(@"E:\HuiTask\更好的原神\地图匹配\有用的素材\5.0\传送点_1024_0.34.3.png", map);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Platforms>x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="NativeMethods.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.46-beta">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/microsoft/CsWin32/main/src/Microsoft.Windows.CsWin32/settings.schema.json",
|
||||
"allowMarshaling": true,
|
||||
"useSafeHandles": false,
|
||||
"emitSingleFile": true,
|
||||
"public": true,
|
||||
"comInterop": {
|
||||
"useIntPtrForComOutPointers": true
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
// D3D11
|
||||
CreateDirect3D11DeviceFromDXGIDevice
|
||||
CreateDirect3D11SurfaceFromDXGISurface
|
||||
|
||||
// GDI32
|
||||
BitBlt
|
||||
CreateCompatibleBitmap
|
||||
CreateCompatibleDC
|
||||
DeleteDC
|
||||
GetDeviceCaps
|
||||
SelectObject
|
||||
|
||||
// User32
|
||||
GetClientRect
|
||||
GetDC
|
||||
GetForegroundWindow
|
||||
GetSystemMetrics
|
||||
GetWindowDC
|
||||
GetWindowRect
|
||||
GetWindowThreadProcessId
|
||||
mouse_event
|
||||
PostMessage
|
||||
ReleaseDC
|
||||
EnumWindows
|
||||
GetWindowText
|
||||
IsWindowVisible
|
||||
GetWindowTextLength
|
||||
|
||||
// COM & WinRT
|
||||
D3D11CreateDevice
|
||||
ID3D11Device3
|
||||
IDirect3DDxgiInterfaceAccess
|
||||
|
||||
// Constants
|
||||
D3D11_SDK_VERSION
|
||||
DXGI_ERROR_UNSUPPORTED
|
||||
WM_LBUTTONDOWN
|
||||
WM_LBUTTONUP
|
||||
@@ -5,18 +5,10 @@ VisualStudioVersion = 17.6.33815.320
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetterGenshinImpact", "BetterGenshinImpact\BetterGenshinImpact.csproj", "{75EC89E2-413D-4725-BCEA-AFAC57708F07}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vision.WindowCapture", "Vision.WindowCapture\Vision.WindowCapture.csproj", "{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetterGenshinImpact.Win32", "BetterGenshinImpact.Win32\BetterGenshinImpact.Win32.csproj", "{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fischless.GameCapture", "Fischless.GameCapture\Fischless.GameCapture.csproj", "{6B0A3D96-D88D-48DD-8112-4CD5BA5D27CE}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vision.WindowCapture.Test", "Vision.WindowCapture.Test\Vision.WindowCapture.Test.csproj", "{D35CB953-C666-4E57-9A9A-3AAE5BF78402}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fischless.HotkeyCapture", "Fischless.HotkeyCapture\Fischless.HotkeyCapture.csproj", "{08152E44-2564-46C5-B5B2-54DD43C01A79}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fischless.KeyboardCapture", "Fischless.KeyboardCapture\Fischless.KeyboardCapture.csproj", "{10A48327-7E58-4B51-B1FC-55506C703C8F}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Deploy", "Deploy", "{458E1106-43A4-47E6-B11B-D243035D4C76}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MicaSetup", "Build\MicaSetup\MicaSetup.csproj", "{AB85DA23-EB8F-4FBF-A7FA-35CE05B23C15}"
|
||||
@@ -43,22 +35,6 @@ Global
|
||||
{75EC89E2-413D-4725-BCEA-AFAC57708F07}.Release|Any CPU.Build.0 = Release|x64
|
||||
{75EC89E2-413D-4725-BCEA-AFAC57708F07}.Release|x64.ActiveCfg = Release|x64
|
||||
{75EC89E2-413D-4725-BCEA-AFAC57708F07}.Release|x64.Build.0 = Release|x64
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Debug|x64.Build.0 = Debug|x64
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Release|Any CPU.ActiveCfg = Release|x64
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Release|Any CPU.Build.0 = Release|x64
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Release|x64.ActiveCfg = Release|x64
|
||||
{C9080C1D-1B26-46CB-A494-A5E7FE3FCEBA}.Release|x64.Build.0 = Release|x64
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Debug|x64.Build.0 = Debug|x64
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Release|Any CPU.ActiveCfg = Release|x64
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Release|Any CPU.Build.0 = Release|x64
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Release|x64.ActiveCfg = Release|x64
|
||||
{75F4541B-9624-4AFB-BAEA-3EAFD3300EE1}.Release|x64.Build.0 = Release|x64
|
||||
{6B0A3D96-D88D-48DD-8112-4CD5BA5D27CE}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{6B0A3D96-D88D-48DD-8112-4CD5BA5D27CE}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{6B0A3D96-D88D-48DD-8112-4CD5BA5D27CE}.Debug|x64.ActiveCfg = Debug|x64
|
||||
@@ -67,14 +43,6 @@ Global
|
||||
{6B0A3D96-D88D-48DD-8112-4CD5BA5D27CE}.Release|Any CPU.Build.0 = Release|x64
|
||||
{6B0A3D96-D88D-48DD-8112-4CD5BA5D27CE}.Release|x64.ActiveCfg = Release|x64
|
||||
{6B0A3D96-D88D-48DD-8112-4CD5BA5D27CE}.Release|x64.Build.0 = Release|x64
|
||||
{D35CB953-C666-4E57-9A9A-3AAE5BF78402}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{D35CB953-C666-4E57-9A9A-3AAE5BF78402}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{D35CB953-C666-4E57-9A9A-3AAE5BF78402}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{D35CB953-C666-4E57-9A9A-3AAE5BF78402}.Debug|x64.Build.0 = Debug|x64
|
||||
{D35CB953-C666-4E57-9A9A-3AAE5BF78402}.Release|Any CPU.ActiveCfg = Release|x64
|
||||
{D35CB953-C666-4E57-9A9A-3AAE5BF78402}.Release|Any CPU.Build.0 = Release|x64
|
||||
{D35CB953-C666-4E57-9A9A-3AAE5BF78402}.Release|x64.ActiveCfg = Release|x64
|
||||
{D35CB953-C666-4E57-9A9A-3AAE5BF78402}.Release|x64.Build.0 = Release|x64
|
||||
{08152E44-2564-46C5-B5B2-54DD43C01A79}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{08152E44-2564-46C5-B5B2-54DD43C01A79}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{08152E44-2564-46C5-B5B2-54DD43C01A79}.Debug|x64.ActiveCfg = Debug|x64
|
||||
@@ -83,14 +51,6 @@ Global
|
||||
{08152E44-2564-46C5-B5B2-54DD43C01A79}.Release|Any CPU.Build.0 = Release|x64
|
||||
{08152E44-2564-46C5-B5B2-54DD43C01A79}.Release|x64.ActiveCfg = Release|x64
|
||||
{08152E44-2564-46C5-B5B2-54DD43C01A79}.Release|x64.Build.0 = Release|x64
|
||||
{10A48327-7E58-4B51-B1FC-55506C703C8F}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{10A48327-7E58-4B51-B1FC-55506C703C8F}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{10A48327-7E58-4B51-B1FC-55506C703C8F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{10A48327-7E58-4B51-B1FC-55506C703C8F}.Debug|x64.Build.0 = Debug|x64
|
||||
{10A48327-7E58-4B51-B1FC-55506C703C8F}.Release|Any CPU.ActiveCfg = Release|x64
|
||||
{10A48327-7E58-4B51-B1FC-55506C703C8F}.Release|Any CPU.Build.0 = Release|x64
|
||||
{10A48327-7E58-4B51-B1FC-55506C703C8F}.Release|x64.ActiveCfg = Release|x64
|
||||
{10A48327-7E58-4B51-B1FC-55506C703C8F}.Release|x64.Build.0 = Release|x64
|
||||
{AB85DA23-EB8F-4FBF-A7FA-35CE05B23C15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AB85DA23-EB8F-4FBF-A7FA-35CE05B23C15}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AB85DA23-EB8F-4FBF-A7FA-35CE05B23C15}.Debug|x64.ActiveCfg = Debug|x64
|
||||
|
||||
@@ -94,7 +94,7 @@ public partial class App : Application
|
||||
services.AddView<CommonSettingsPage, CommonSettingsPageViewModel>();
|
||||
services.AddView<TaskSettingsPage, TaskSettingsPageViewModel>();
|
||||
services.AddView<HotKeyPage, HotKeyPageViewModel>();
|
||||
services.AddView<NotificationSettingsPage, NotificationSettingsPageViewModel>();
|
||||
// services.AddView<NotificationSettingsPage, NotificationSettingsPageViewModel>();
|
||||
services.AddView<KeyMouseRecordPage, KeyMouseRecordPageViewModel>();
|
||||
services.AddView<JsListPage, JsListViewModel>();
|
||||
services.AddView<MapPathingPage, MapPathingViewModel>();
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<ApplicationIcon>Assets\Images\logo.ico</ApplicationIcon>
|
||||
<AssemblyName>BetterGI</AssemblyName>
|
||||
<AssemblyVersion>0.37.0</AssemblyVersion>
|
||||
<AssemblyVersion>0.39.1</AssemblyVersion>
|
||||
<Platforms>x64</Platforms>
|
||||
<DebugType>embedded</DebugType>
|
||||
</PropertyGroup>
|
||||
@@ -128,6 +128,9 @@
|
||||
<None Update="GameTask\AutoWood\Assets\1920x1080\**">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\AutoMusicGame\Assets\1920x1080\**">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="GameTask\GameLoading\Assets\1920x1080\**">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
@@ -143,7 +146,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="GameTask\Common\Element\Assets\Json\" />
|
||||
<Folder Include="GameTask\OneDragon\" />
|
||||
<Folder Include="User\AutoPathing\" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -12,8 +12,10 @@ using BetterGenshinImpact.Service.Notification;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Fischless.GameCapture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
|
||||
@@ -67,6 +69,15 @@ public partial class AllConfig : ObservableObject
|
||||
[ObservableProperty]
|
||||
private string _inferenceDevice = "CPU";
|
||||
|
||||
[ObservableProperty]
|
||||
private List<ValueTuple<string, int, string, string>> _nextScheduledTask = [];
|
||||
|
||||
/// <summary>
|
||||
/// 一条龙选中使用的配置
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _selectedOneDragonFlowConfigName = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 遮罩窗口配置
|
||||
/// </summary>
|
||||
@@ -191,4 +202,4 @@ public partial class AllConfig : ObservableObject
|
||||
{
|
||||
NotificationService.Instance().RefreshNotifiers();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,11 @@ namespace BetterGenshinImpact.Core.Config;
|
||||
[Serializable]
|
||||
public partial class GenshinStartConfig : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 自动点击月卡
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _autoClickBlessingOfTheWelkinMoonEnabled;
|
||||
// /// <summary>
|
||||
// /// 自动点击月卡
|
||||
// /// </summary>
|
||||
// [ObservableProperty]
|
||||
// private bool _autoClickBlessingOfTheWelkinMoonEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// 自动进入游戏(开门)
|
||||
|
||||
@@ -211,7 +211,12 @@ public partial class HotKeyConfig : ObservableObject
|
||||
|
||||
[ObservableProperty]
|
||||
private string _keyMouseMacroRecordHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
// 暂停
|
||||
[ObservableProperty]
|
||||
private string _suspendHotkey = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _suspendHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
|
||||
// 停止任意独立任务
|
||||
[ObservableProperty]
|
||||
private string _cancelTaskHotkey = "";
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
|
||||
[Serializable]
|
||||
public partial class OneDragonFlowConfig : ObservableObject
|
||||
{
|
||||
// 配置名
|
||||
[ObservableProperty]
|
||||
private string _name = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 所有任务的开关状态
|
||||
/// </summary>
|
||||
public Dictionary<string, bool> TaskEnabledList { get; set; } = new();
|
||||
|
||||
// 合成树脂的国家
|
||||
[ObservableProperty]
|
||||
private string _craftingBenchCountry = "枫丹";
|
||||
|
||||
// 冒险者协会的国家
|
||||
[ObservableProperty]
|
||||
private string _adventurersGuildCountry = "枫丹";
|
||||
|
||||
// 自动战斗配置的队伍名称
|
||||
[ObservableProperty]
|
||||
private string _partyName = string.Empty;
|
||||
|
||||
// 自动战斗配置的策略名称
|
||||
[ObservableProperty]
|
||||
private string _domainName = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _weeklyDomainEnabled = false;
|
||||
|
||||
// 领取每日奖励的好感队伍名称
|
||||
[ObservableProperty]
|
||||
private string _dailyRewardPartyName = string.Empty;
|
||||
|
||||
|
||||
#region 每周秘境配置
|
||||
|
||||
[ObservableProperty]
|
||||
private string _mondayThursdayPartyName = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _mondayThursdayDomainName = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _tuesdayFridayPartyName = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _tuesdayFridayDomainName = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _wednesdaySaturdayPartyName = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _wednesdaySaturdayDomainName = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _sundayPartyName = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _sundayDomainName = string.Empty;
|
||||
|
||||
// 通过当天是哪一天来返回配置
|
||||
public (string partyName, string domainName) GetDomainConfig()
|
||||
{
|
||||
if (WeeklyDomainEnabled)
|
||||
{
|
||||
var dayOfWeek = DateTime.Now.DayOfWeek;
|
||||
return dayOfWeek switch
|
||||
{
|
||||
DayOfWeek.Monday => (MondayThursdayPartyName, MondayThursdayDomainName),
|
||||
DayOfWeek.Tuesday => (TuesdayFridayPartyName, TuesdayFridayDomainName),
|
||||
DayOfWeek.Wednesday => (WednesdaySaturdayPartyName, WednesdaySaturdayDomainName),
|
||||
DayOfWeek.Thursday => (MondayThursdayPartyName, MondayThursdayDomainName),
|
||||
DayOfWeek.Friday => (TuesdayFridayPartyName, TuesdayFridayDomainName),
|
||||
DayOfWeek.Saturday => (WednesdaySaturdayPartyName, WednesdaySaturdayDomainName),
|
||||
DayOfWeek.Sunday => (SundayPartyName, SundayDomainName),
|
||||
_ => (PartyName, DomainName)
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return (PartyName, DomainName);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -18,6 +18,14 @@ public partial class PathingConditionConfig : ObservableObject
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<Condition> _avatarConditions = [];
|
||||
|
||||
// 只在传送传送点时复活
|
||||
[ObservableProperty]
|
||||
private bool _onlyInTeleportRecover = false;
|
||||
|
||||
// 使用小道具的间隔时间(ms)
|
||||
[ObservableProperty]
|
||||
private int _useGadgetIntervalMs = 0;
|
||||
|
||||
public static PathingConditionConfig Default => new()
|
||||
{
|
||||
@@ -98,7 +106,7 @@ public partial class PathingConditionConfig : ObservableObject
|
||||
/// <returns></returns>
|
||||
public PathingPartyConfig BuildPartyConfigByCondition(CombatScenes combatScenes)
|
||||
{
|
||||
PathingPartyConfig partyConfig = new();
|
||||
PathingPartyConfig partyConfig = PathingPartyConfig.BuildDefault();
|
||||
// 使用最优先匹配上的条件
|
||||
foreach (var avatarCondition in AvatarConditions)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.GameTask.AutoFight;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
|
||||
@@ -58,8 +60,30 @@ public partial class PathingPartyConfig : ObservableObject
|
||||
// 只在传送传送点时复活
|
||||
[ObservableProperty]
|
||||
private bool _onlyInTeleportRecover = false;
|
||||
|
||||
// 使用小道具的间隔时间
|
||||
[ObservableProperty]
|
||||
private int _useGadgetIntervalMs = 0;
|
||||
|
||||
// 启用进入剧情自动脱离
|
||||
[ObservableProperty]
|
||||
private bool _autoSkipEnabled = false;
|
||||
private bool _autoSkipEnabled = true;
|
||||
|
||||
//启用自动战斗配置
|
||||
[ObservableProperty]
|
||||
private bool _autoFightEabled = false;
|
||||
|
||||
[ObservableProperty]
|
||||
private AutoFightConfig _autoFightConfig = new();
|
||||
|
||||
public static PathingPartyConfig BuildDefault()
|
||||
{
|
||||
// 即便是不启用的情况下也设置默认值,减少后续使用的判断
|
||||
var pathingConditionConfig = TaskContext.Instance().Config.PathingConditionConfig;
|
||||
return new PathingPartyConfig
|
||||
{
|
||||
OnlyInTeleportRecover = pathingConditionConfig.OnlyInTeleportRecover,
|
||||
UseGadgetIntervalMs = pathingConditionConfig.UseGadgetIntervalMs
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using SharpDX.DirectInput;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Vanara.PInvoke;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Monitor;
|
||||
|
||||
@@ -11,6 +12,8 @@ public class DirectInputMonitor : IDisposable
|
||||
private bool _isRunning = true;
|
||||
|
||||
private readonly Mouse _mouse;
|
||||
|
||||
public static int Interval = 5;
|
||||
|
||||
public DirectInputMonitor()
|
||||
{
|
||||
@@ -34,8 +37,8 @@ public class DirectInputMonitor : IDisposable
|
||||
_mouse.Acquire();
|
||||
MouseState state = _mouse.GetCurrentState();
|
||||
// Debug.WriteLine($"{state.X} {state.Y} {state.Buttons[0]} {state.Buttons[1]}");
|
||||
GlobalKeyMouseRecord.Instance.GlobalHookMouseMoveBy(state);
|
||||
Thread.Sleep(5); // 10ms, equivalent to CLOCKS_PER_SEC/100
|
||||
GlobalKeyMouseRecord.Instance.GlobalHookMouseMoveBy(state, Kernel32.GetTickCount());
|
||||
Thread.Sleep(Interval); // 10ms, equivalent to CLOCKS_PER_SEC/100
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ public class MouseKeyMonitor
|
||||
_globalHook.MouseDownExt += GlobalHookMouseDownExt;
|
||||
_globalHook.MouseUpExt += GlobalHookMouseUpExt;
|
||||
_globalHook.MouseMoveExt += GlobalHookMouseMoveExt;
|
||||
_globalHook.MouseWheelExt += GlobalHookMouseWheelExt;
|
||||
//_globalHook.KeyPress += GlobalHookKeyPress;
|
||||
|
||||
_firstSpaceKeyDownTime = DateTime.MaxValue;
|
||||
@@ -61,7 +62,7 @@ public class MouseKeyMonitor
|
||||
private void GlobalHookKeyDown(object? sender, KeyEventArgs e)
|
||||
{
|
||||
// Debug.WriteLine("KeyDown: \t{0}", e.KeyCode);
|
||||
GlobalKeyMouseRecord.Instance.GlobalHookKeyDown(e);
|
||||
GlobalKeyMouseRecord.Instance.GlobalHookKeyDown(e, Kernel32.GetTickCount());
|
||||
|
||||
// 热键按下事件
|
||||
HotKeyDown(sender, e);
|
||||
@@ -99,7 +100,7 @@ public class MouseKeyMonitor
|
||||
private void GlobalHookKeyUp(object? sender, KeyEventArgs e)
|
||||
{
|
||||
// Debug.WriteLine("KeyUp: \t{0}", e.KeyCode);
|
||||
GlobalKeyMouseRecord.Instance.GlobalHookKeyUp(e);
|
||||
GlobalKeyMouseRecord.Instance.GlobalHookKeyUp(e, Kernel32.GetTickCount());
|
||||
|
||||
// 热键松开事件
|
||||
HotKeyUp(sender, e);
|
||||
@@ -166,6 +167,12 @@ public class MouseKeyMonitor
|
||||
// Debug.WriteLine("MouseMove: {0}; \t Location: {1};\t System Timestamp: {2}", e.Button, e.Location, e.Timestamp);
|
||||
GlobalKeyMouseRecord.Instance.GlobalHookMouseMoveTo(e);
|
||||
}
|
||||
|
||||
private void GlobalHookMouseWheelExt(object? sender, MouseEventExtArgs e)
|
||||
{
|
||||
// Debug.WriteLine("MouseMove: {0}; \t Location: {1};\t Delta: {2};\t System Timestamp: {3}", e.Button, e.Location, e.Delta, e.Timestamp);
|
||||
GlobalKeyMouseRecord.Instance.GlobalHookMouseWheel(e);
|
||||
}
|
||||
|
||||
public void Unsubscribe()
|
||||
{
|
||||
@@ -176,6 +183,7 @@ public class MouseKeyMonitor
|
||||
_globalHook.MouseDownExt -= GlobalHookMouseDownExt;
|
||||
_globalHook.MouseUpExt -= GlobalHookMouseUpExt;
|
||||
_globalHook.MouseMoveExt -= GlobalHookMouseMoveExt;
|
||||
_globalHook.MouseWheelExt -= GlobalHookMouseWheelExt;
|
||||
//_globalHook.KeyPress -= GlobalHookKeyPress;
|
||||
_globalHook.Dispose();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Diagnostics;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using BetterGenshinImpact.View.Drawable;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.ONNX;
|
||||
|
||||
@@ -45,6 +46,16 @@ public class BgiYoloV8Predictor(string modelRelativePath) : IDisposable
|
||||
}
|
||||
}
|
||||
Debug.WriteLine("YOLOv8识别结果:" + JsonSerializer.Serialize(dict));
|
||||
|
||||
var list = new List<RectDrawable>();
|
||||
foreach (var box in result.Boxes)
|
||||
{
|
||||
var rect = new Rect(box.Bounds.X, box.Bounds.Y, box.Bounds.Width, box.Bounds.Height);
|
||||
list.Add(region.ToRectDrawable(rect, modelRelativePath));
|
||||
}
|
||||
|
||||
VisionContext.Instance().DrawContent.PutOrRemoveRectList(modelRelativePath, list);
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.ONNX;
|
||||
|
||||
public class BgiYoloV8PredictorFactory
|
||||
{
|
||||
static Dictionary<string, BgiYoloV8Predictor> _predictors = new();
|
||||
|
||||
public static BgiYoloV8Predictor GetPredictor(string modelRelativePath)
|
||||
{
|
||||
if (!_predictors.ContainsKey(modelRelativePath))
|
||||
{
|
||||
_predictors[modelRelativePath] = new BgiYoloV8Predictor(modelRelativePath);
|
||||
}
|
||||
|
||||
return _predictors[modelRelativePath];
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging;
|
||||
using SharpDX.DirectInput;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Wpf.Ui.Violeta.Controls;
|
||||
@@ -114,7 +115,7 @@ public class GlobalKeyMouseRecord : Singleton<GlobalKeyMouseRecord>
|
||||
ra.Dispose();
|
||||
}
|
||||
|
||||
public void GlobalHookKeyDown(KeyEventArgs e)
|
||||
public void GlobalHookKeyDown(KeyEventArgs e, uint time)
|
||||
{
|
||||
// 排除热键
|
||||
if (e.KeyCode.ToString() == TaskContext.Instance().Config.HotKeyConfig.KeyMouseMacroRecordHotkey)
|
||||
@@ -138,10 +139,10 @@ public class GlobalKeyMouseRecord : Singleton<GlobalKeyMouseRecord>
|
||||
_keyDownState.Add(e.KeyCode, true);
|
||||
}
|
||||
// Debug.WriteLine($"KeyDown: {e.KeyCode}");
|
||||
_recorder?.KeyDown(e);
|
||||
_recorder?.KeyDown(e, time);
|
||||
}
|
||||
|
||||
public void GlobalHookKeyUp(KeyEventArgs e)
|
||||
public void GlobalHookKeyUp(KeyEventArgs e, uint time)
|
||||
{
|
||||
if (e.KeyCode.ToString() == TaskContext.Instance().Config.HotKeyConfig.Test1Hotkey)
|
||||
{
|
||||
@@ -152,7 +153,7 @@ public class GlobalKeyMouseRecord : Singleton<GlobalKeyMouseRecord>
|
||||
{
|
||||
// Debug.WriteLine($"KeyUp: {e.KeyCode}");
|
||||
_keyDownState[e.KeyCode] = false;
|
||||
_recorder?.KeyUp(e);
|
||||
_recorder?.KeyUp(e, time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,15 +178,21 @@ public class GlobalKeyMouseRecord : Singleton<GlobalKeyMouseRecord>
|
||||
// Debug.WriteLine($"MouseMove: {e.X}, {e.Y}");
|
||||
_recorder?.MouseMoveTo(e);
|
||||
}
|
||||
|
||||
public void GlobalHookMouseWheel(MouseEventExtArgs e)
|
||||
{
|
||||
// Debug.WriteLine($"MouseWheel: {e.Delta}");
|
||||
_recorder?.MouseWheel(e);
|
||||
}
|
||||
|
||||
public void GlobalHookMouseMoveBy(MouseState state)
|
||||
public void GlobalHookMouseMoveBy(MouseState state, uint time)
|
||||
{
|
||||
if (state is { X: 0, Y: 0 } || !_isInMainUi)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Debug.WriteLine($"MouseMoveBy: {state.X}, {state.Y}");
|
||||
_recorder?.MouseMoveBy(state);
|
||||
_recorder?.MouseMoveBy(state, time);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Fischless.WindowsInput;
|
||||
using Vanara.PInvoke;
|
||||
using Wpf.Ui.Violeta.Controls;
|
||||
|
||||
@@ -48,7 +49,7 @@ public class KeyMouseMacroPlayer
|
||||
public static async Task PlayMacro(List<MacroEvent> macroEvents, CancellationToken ct)
|
||||
{
|
||||
WorkingArea = PrimaryScreen.WorkingArea;
|
||||
var startTime = DateTime.UtcNow;
|
||||
var startTime = Kernel32.GetTickCount();
|
||||
foreach (var e in macroEvents)
|
||||
{
|
||||
if (ct.IsCancellationRequested)
|
||||
@@ -56,23 +57,42 @@ public class KeyMouseMacroPlayer
|
||||
return;
|
||||
}
|
||||
|
||||
var timeToWait = (int)(e.Time - (DateTime.UtcNow - startTime).TotalMilliseconds);
|
||||
var timeToWait = e.Time - (Kernel32.GetTickCount() - startTime);
|
||||
if (timeToWait < 0)
|
||||
{
|
||||
TaskControl.Logger.LogWarning("无法原速重放事件{Event},落后{TimeToWait}ms", e.Type.ToString(), -timeToWait);
|
||||
TaskControl.Logger.LogDebug("无法原速重放事件{Event},落后{TimeToWait}ms", e.Type.ToString(), (-timeToWait).ToString("F0"));
|
||||
}
|
||||
else
|
||||
{
|
||||
await Task.Delay(timeToWait, ct);
|
||||
await Task.Delay((int)timeToWait, ct);
|
||||
}
|
||||
|
||||
switch (e.Type)
|
||||
{
|
||||
case MacroEventType.KeyDown:
|
||||
Simulation.SendInput.Keyboard.KeyDown((User32.VK)e.KeyCode!);
|
||||
break;
|
||||
var vkDown = (User32.VK)e.KeyCode!;
|
||||
if (InputBuilder.IsExtendedKey(vkDown))
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyDown(false, vkDown);
|
||||
}
|
||||
else
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyDown(vkDown);
|
||||
}
|
||||
|
||||
break;
|
||||
case MacroEventType.KeyUp:
|
||||
Simulation.SendInput.Keyboard.KeyUp((User32.VK)e.KeyCode!);
|
||||
|
||||
var vkUp = (User32.VK)e.KeyCode!;
|
||||
if (InputBuilder.IsExtendedKey(vkUp))
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyUp(false, vkUp);
|
||||
}
|
||||
else
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyUp(vkUp);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MacroEventType.MouseDown:
|
||||
@@ -145,11 +165,21 @@ public class KeyMouseMacroPlayer
|
||||
Simulation.SendInput.Mouse.MoveMouseTo(ToVirtualDesktopX(e.MouseX), ToVirtualDesktopY(e.MouseY));
|
||||
break;
|
||||
|
||||
case MacroEventType.MouseWheel:
|
||||
var num = (int)(e.MouseY / 120.0);
|
||||
if (num != 0)
|
||||
{
|
||||
// 不支持多次的场景,但是不会出现这种情况
|
||||
Simulation.SendInput.Mouse.VerticalScroll(num);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MacroEventType.MouseMoveBy:
|
||||
if (e.CameraOrientation != null)
|
||||
{
|
||||
var cao = CameraOrientation.Compute(TaskControl.CaptureToRectArea().SrcGreyMat);
|
||||
var diff = (cao - (int)e.CameraOrientation + 180) % 360 - 180;
|
||||
var cao = CameraOrientation.Compute(TaskControl.CaptureToRectArea().SrcMat);
|
||||
var diff = ((int)Math.Round(cao) - (int)e.CameraOrientation + 180) % 360 - 180;
|
||||
diff += diff < -180 ? 360 : 0;
|
||||
//过滤一下特别大的角度偏差
|
||||
if (diff != 0 && diff < 8 && diff > -8)
|
||||
@@ -158,6 +188,7 @@ public class KeyMouseMacroPlayer
|
||||
e.MouseX -= diff;
|
||||
}
|
||||
}
|
||||
|
||||
Simulation.SendInput.Mouse.MoveMouseBy(e.MouseX, e.MouseY);
|
||||
break;
|
||||
|
||||
@@ -178,4 +209,4 @@ public class KeyMouseMacroPlayer
|
||||
{
|
||||
return y * 65535 * 1d / WorkingArea.Height;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Windows.Forms;
|
||||
using Vanara.PInvoke;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recorder;
|
||||
|
||||
@@ -16,7 +17,7 @@ public class KeyMouseRecorder
|
||||
{
|
||||
public List<MacroEvent> MacroEvents { get; } = [];
|
||||
|
||||
public DateTime StartTime { get; set; } = DateTime.UtcNow;
|
||||
public uint StartTime { get; set; } = Kernel32.GetTickCount();
|
||||
|
||||
public DateTime LastOrientationDetection { get; set; } = DateTime.UtcNow;
|
||||
|
||||
@@ -34,6 +35,11 @@ public class KeyMouseRecorder
|
||||
|
||||
public string ToJsonMacro()
|
||||
{
|
||||
// MacroEvents 需要以实际时间进行排序
|
||||
MacroEvents.Sort((a, b) => a.Time.CompareTo(b.Time));
|
||||
// 删除为负数的时间
|
||||
MacroEvents.RemoveAll(m => m.Time < 0);
|
||||
|
||||
var rect = TaskContext.Instance().SystemInfo.CaptureAreaRect;
|
||||
// 合并鼠标移动事件
|
||||
var mergedMacroEvents = new List<MacroEvent>();
|
||||
@@ -104,23 +110,23 @@ public class KeyMouseRecorder
|
||||
return JsonSerializer.Serialize(keyMouseScript, JsonOptions);
|
||||
}
|
||||
|
||||
public void KeyDown(KeyEventArgs e)
|
||||
public void KeyDown(KeyEventArgs e, uint time)
|
||||
{
|
||||
MacroEvents.Add(new MacroEvent
|
||||
{
|
||||
Type = MacroEventType.KeyDown,
|
||||
KeyCode = e.KeyValue,
|
||||
Time = (DateTime.UtcNow - StartTime).TotalMilliseconds
|
||||
Time = time - StartTime
|
||||
});
|
||||
}
|
||||
|
||||
public void KeyUp(KeyEventArgs e)
|
||||
public void KeyUp(KeyEventArgs e, uint time)
|
||||
{
|
||||
MacroEvents.Add(new MacroEvent
|
||||
{
|
||||
Type = MacroEventType.KeyUp,
|
||||
KeyCode = e.KeyValue,
|
||||
Time = (DateTime.UtcNow - StartTime).TotalMilliseconds
|
||||
Time = time - StartTime
|
||||
});
|
||||
}
|
||||
|
||||
@@ -132,7 +138,7 @@ public class KeyMouseRecorder
|
||||
MouseX = e.X,
|
||||
MouseY = e.Y,
|
||||
MouseButton = e.Button.ToString(),
|
||||
Time = (DateTime.UtcNow - StartTime).TotalMilliseconds
|
||||
Time = e.Timestamp - StartTime
|
||||
});
|
||||
}
|
||||
|
||||
@@ -144,7 +150,7 @@ public class KeyMouseRecorder
|
||||
MouseX = e.X,
|
||||
MouseY = e.Y,
|
||||
MouseButton = e.Button.ToString(),
|
||||
Time = (DateTime.UtcNow - StartTime).TotalMilliseconds
|
||||
Time = e.Timestamp - StartTime
|
||||
});
|
||||
}
|
||||
|
||||
@@ -155,28 +161,40 @@ public class KeyMouseRecorder
|
||||
Type = MacroEventType.MouseMoveTo,
|
||||
MouseX = e.X,
|
||||
MouseY = e.Y,
|
||||
Time = (DateTime.UtcNow - StartTime).TotalMilliseconds
|
||||
Time = e.Timestamp - StartTime
|
||||
});
|
||||
}
|
||||
|
||||
public void MouseWheel(MouseEventExtArgs e)
|
||||
{
|
||||
MacroEvents.Add(new MacroEvent
|
||||
{
|
||||
Type = MacroEventType.MouseWheel,
|
||||
MouseY = e.Delta, // 120 的倍率
|
||||
Time = e.Timestamp - StartTime
|
||||
});
|
||||
}
|
||||
|
||||
public void MouseMoveBy(MouseState state)
|
||||
public void MouseMoveBy(MouseState state, uint time)
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
int? cao = null;
|
||||
if (TaskContext.Instance().Config.RecordConfig.IsRecordCameraOrientation)
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
if ((now - LastOrientationDetection).TotalMilliseconds > 100.0)
|
||||
{
|
||||
LastOrientationDetection = now;
|
||||
cao = CameraOrientation.Compute(TaskControl.CaptureToRectArea().SrcGreyMat);
|
||||
cao = (int)Math.Round(CameraOrientation.Compute(TaskControl.CaptureToRectArea().SrcMat));
|
||||
}
|
||||
}
|
||||
|
||||
MacroEvents.Add(new MacroEvent
|
||||
{
|
||||
Type = MacroEventType.MouseMoveBy,
|
||||
MouseX = state.X,
|
||||
MouseY = state.Y,
|
||||
Time = (now - StartTime).TotalMilliseconds,
|
||||
Time = time - 5 - StartTime,
|
||||
CameraOrientation = cao,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,5 +22,6 @@ public enum MacroEventType
|
||||
MouseMoveTo,
|
||||
MouseMoveBy,
|
||||
MouseDown,
|
||||
MouseUp
|
||||
MouseUp,
|
||||
MouseWheel
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using BetterGenshinImpact.GameTask.AutoPathing;
|
||||
using BetterGenshinImpact.GameTask.AutoPathing.Model;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Script.Dependence;
|
||||
|
||||
@@ -17,4 +18,14 @@ public class AutoPathingScript(string rootPath)
|
||||
var json = await new LimitedFile(rootPath).ReadText(path);
|
||||
await Run(json);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从已订阅的内容中获取文件
|
||||
/// </summary>
|
||||
/// <param name="path">在 `\User\AutoPathing` 目录下获取文件</param>
|
||||
public async Task RunFileFromUser(string path)
|
||||
{
|
||||
var json = await new LimitedFile(Global.Absolute(@"User\AutoPathing")).ReadText(path);
|
||||
await Run(json);
|
||||
}
|
||||
}
|
||||
@@ -82,11 +82,7 @@ public class Dispatcher
|
||||
return;
|
||||
}
|
||||
var autoFightConfig = TaskContext.Instance().Config.AutoFightConfig;
|
||||
var param = new AutoFightParam(path1)
|
||||
{
|
||||
FightFinishDetectEnabled = autoFightConfig.FightFinishDetectEnabled,
|
||||
PickDropsAfterFightEnabled = autoFightConfig.PickDropsAfterFightEnabled
|
||||
};
|
||||
var param = new AutoFightParam(path1, autoFightConfig);
|
||||
await new AutoFightTask(param).Start(CancellationContext.Instance.Cts.Token);
|
||||
break;
|
||||
|
||||
|
||||
@@ -75,4 +75,73 @@ public class Genshin
|
||||
{
|
||||
await new SwitchPartyTask().Start(partyName, CancellationContext.Instance.Cts.Token);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 自动点击空月祝福
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task BlessingOfTheWelkinMoon()
|
||||
{
|
||||
await new BlessingOfTheWelkinMoonTask().Start(CancellationContext.Instance.Cts.Token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 持续对话并选择目标选项
|
||||
/// </summary>
|
||||
/// <param name="option">选项文本</param>
|
||||
/// <param name="skipTimes">跳过次数</param>
|
||||
/// <param name="isOrange">是否为橙色选项</param>
|
||||
/// <returns></returns>
|
||||
public async Task ChooseTalkOption(string option, int skipTimes = 10, bool isOrange = false)
|
||||
{
|
||||
await new ChooseTalkOptionTask().SingleSelectText(option, CancellationContext.Instance.Cts.Token, skipTimes, isOrange);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 一键领取纪行奖励
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task ClaimBattlePassRewards()
|
||||
{
|
||||
await new ClaimBattlePassRewardsTask().Start(CancellationContext.Instance.Cts.Token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 领取长效历练点奖励
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task ClaimEncounterPointsRewards()
|
||||
{
|
||||
await new ClaimEncounterPointsRewardsTask().Start(CancellationContext.Instance.Cts.Token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 前往冒险家协会领取奖励
|
||||
/// </summary>
|
||||
/// <param name="country">国家名称</param>
|
||||
/// <returns></returns>
|
||||
public async Task GoToAdventurersGuild(string country)
|
||||
{
|
||||
await new GoToAdventurersGuildTask().Start(country, CancellationContext.Instance.Cts.Token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 前往合成台
|
||||
/// </summary>
|
||||
/// <param name="country">国家名称</param>
|
||||
/// <returns></returns>
|
||||
public async Task GoToCraftingBench(string country)
|
||||
{
|
||||
await new GoToCraftingBenchTask().Start(country, CancellationContext.Instance.Cts.Token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回主界面
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task ReturnMainUi()
|
||||
{
|
||||
await new ReturnMainUiTask().Start(CancellationContext.Instance.Cts.Token);
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,7 @@ public partial class ScriptGroupProject : ObservableObject
|
||||
[JsonIgnore]
|
||||
public ScriptProject? Project { get; set; }
|
||||
|
||||
|
||||
public ExpandoObject? JsScriptSettingsObject { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -69,6 +70,12 @@ public partial class ScriptGroupProject : ObservableObject
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public ScriptGroup? GroupInfo { get; set; }
|
||||
/// <summary>
|
||||
/// 下一个从此执行标志
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
[ObservableProperty]
|
||||
public bool? _nextFlag = false;
|
||||
|
||||
public ScriptGroupProject()
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using BetterGenshinImpact.Core.Script.Dependence;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Script.Project;
|
||||
|
||||
@@ -65,6 +66,9 @@ public class ScriptProject
|
||||
|
||||
public async Task ExecuteAsync(dynamic? context = null)
|
||||
{
|
||||
// 默认值
|
||||
GlobalMethod.SetGameMetrics(1920, 1080);
|
||||
// 加载代码
|
||||
var code = await LoadCode();
|
||||
var engine = BuildScriptEngine();
|
||||
if (context != null)
|
||||
|
||||
@@ -451,7 +451,7 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
|
||||
{
|
||||
_webWindow = new WebpageWindow
|
||||
{
|
||||
Title = "enshin Copilot Scripts | BetterGI 脚本本地中央仓库",
|
||||
Title = "Genshin Copilot Scripts | BetterGI 脚本本地中央仓库",
|
||||
Width = 1366,
|
||||
Height = 768,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using Fischless.WindowsInput;
|
||||
using System;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Vanara.PInvoke;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Simulator;
|
||||
|
||||
@@ -13,4 +16,26 @@ public class Simulation
|
||||
{
|
||||
return new PostMessageSimulator(hWnd);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReleaseAllKey()
|
||||
{
|
||||
foreach (User32.VK key in Enum.GetValues(typeof(User32.VK)))
|
||||
{
|
||||
// 检查键是否被按下
|
||||
if (IsKeyDown(key)) // 强制转换 VK 枚举为 int
|
||||
{
|
||||
TaskControl.Logger.LogDebug($"解除{key}的按下状态.");
|
||||
SendInput.Keyboard.KeyUp(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsKeyDown(User32.VK key)
|
||||
{
|
||||
// 获取按键状态
|
||||
var state = User32.GetAsyncKeyState((int)key);
|
||||
|
||||
// 检查高位是否为 1(表示按键被按下)
|
||||
return (state & 0x8000) != 0;
|
||||
}
|
||||
}
|
||||
@@ -9,26 +9,47 @@ public partial class AutoDomainConfig : ObservableObject
|
||||
/// <summary>
|
||||
/// 战斗结束后延迟几秒再开始寻找石化古树,秒
|
||||
/// </summary>
|
||||
[ObservableProperty] private double _fightEndDelay = 5;
|
||||
[ObservableProperty]
|
||||
private double _fightEndDelay = 5;
|
||||
|
||||
/// <summary>
|
||||
/// 寻找古树时,短距离移动,用于识别速度过慢的计算机使用
|
||||
/// </summary>
|
||||
[ObservableProperty] private bool _shortMovement = false;
|
||||
[ObservableProperty]
|
||||
private bool _shortMovement = false;
|
||||
|
||||
/// <summary>
|
||||
/// 寻找古树时,短距离移动,用于识别速度过慢的计算机使用
|
||||
/// </summary>
|
||||
[ObservableProperty] private bool _walkToF = false;
|
||||
[ObservableProperty]
|
||||
private bool _walkToF = true;
|
||||
|
||||
/// <summary>
|
||||
/// 寻找古树时,短距离移动的次数
|
||||
/// </summary>
|
||||
[ObservableProperty] private int _leftRightMoveTimes = 3;
|
||||
[ObservableProperty]
|
||||
private int _leftRightMoveTimes = 3;
|
||||
|
||||
/// <summary>
|
||||
/// 自动吃药
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _autoEat = false;
|
||||
}
|
||||
|
||||
// 刷副本使用的队伍名称
|
||||
[ObservableProperty]
|
||||
private string _partyName = string.Empty;
|
||||
|
||||
// 需要刷取的副本名称
|
||||
[ObservableProperty]
|
||||
private string _domainName = string.Empty;
|
||||
|
||||
// 结束后是否自动分解圣遗物
|
||||
[ObservableProperty]
|
||||
private bool _autoArtifactSalvage = false;
|
||||
|
||||
// 分解圣遗物的最大星级
|
||||
// 1~4
|
||||
[ObservableProperty]
|
||||
private string _maxArtifactStar = "4";
|
||||
}
|
||||
@@ -9,6 +9,19 @@ public class AutoDomainParam : BaseTaskParam
|
||||
|
||||
public string CombatStrategyPath { get; set; }
|
||||
|
||||
// 刷副本使用的队伍名称
|
||||
public string PartyName { get; set; } = string.Empty;
|
||||
|
||||
// 需要刷取的副本名称
|
||||
public string DomainName { get; set; } = string.Empty;
|
||||
|
||||
// 结束后是否自动分解圣遗物
|
||||
public bool AutoArtifactSalvage { get; set; } = false;
|
||||
|
||||
// 分解圣遗物的最大星级
|
||||
// 1~4
|
||||
public string MaxArtifactStar { get; set; } = "4";
|
||||
|
||||
public AutoDomainParam(int domainRoundNum, string path)
|
||||
{
|
||||
DomainRoundNum = domainRoundNum;
|
||||
@@ -16,6 +29,17 @@ public class AutoDomainParam : BaseTaskParam
|
||||
{
|
||||
DomainRoundNum = 9999;
|
||||
}
|
||||
|
||||
CombatStrategyPath = path;
|
||||
SetDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDefault()
|
||||
{
|
||||
var config = TaskContext.Instance().Config.AutoDomainConfig;
|
||||
PartyName = config.PartyName;
|
||||
DomainName = config.DomainName;
|
||||
AutoArtifactSalvage = config.AutoArtifactSalvage;
|
||||
MaxArtifactStar = config.MaxArtifactStar;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,10 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Recognition;
|
||||
using BetterGenshinImpact.GameTask.AutoTrackPath;
|
||||
using BetterGenshinImpact.GameTask.Common.BgiVision;
|
||||
using BetterGenshinImpact.GameTask.Common.Element.Assets;
|
||||
using BetterGenshinImpact.GameTask.Common.Job;
|
||||
using Vanara.PInvoke;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
using static Vanara.PInvoke.Kernel32;
|
||||
@@ -72,16 +75,55 @@ public class AutoDomainTask : ISoloTask
|
||||
Init();
|
||||
NotificationHelper.SendTaskNotificationWithScreenshotUsing(b => b.Domain().Started().Build()); // TODO: 通知后续需要删除迁移
|
||||
|
||||
// 3次复活重试
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
await DoDomain();
|
||||
// 其他场景不重试
|
||||
break;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e.Message.Contains("复活") && !string.IsNullOrEmpty(_taskParam.DomainName))
|
||||
{
|
||||
Logger.LogWarning("自动秘境:{Text}", "复活后重试秘境...");
|
||||
await Delay(2000, ct);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
await Delay(2000, ct);
|
||||
await Bv.WaitForMainUi(_ct, 30);
|
||||
await Delay(2000, ct);
|
||||
|
||||
await ArtifactSalvage();
|
||||
}
|
||||
|
||||
private async Task DoDomain()
|
||||
{
|
||||
// 传送到秘境
|
||||
await TpDomain();
|
||||
// 切换队伍
|
||||
await SwitchParty(_taskParam.PartyName);
|
||||
|
||||
var combatScenes = new CombatScenes().InitializeTeam(CaptureToRectArea());
|
||||
|
||||
// 前置进入秘境
|
||||
EnterDomain();
|
||||
await EnterDomain();
|
||||
|
||||
for (var i = 0; i < _taskParam.DomainRoundNum; i++)
|
||||
{
|
||||
// 0. 关闭秘境提示
|
||||
Logger.LogDebug("0. 关闭秘境提示");
|
||||
CloseDomainTip();
|
||||
await CloseDomainTip();
|
||||
|
||||
// 队伍没初始化成功则重试
|
||||
RetryTeamInit(combatScenes);
|
||||
@@ -166,17 +208,87 @@ public class AutoDomainTask : ISoloTask
|
||||
}
|
||||
}
|
||||
|
||||
private void EnterDomain()
|
||||
private async Task TpDomain()
|
||||
{
|
||||
// 传送到秘境
|
||||
if (!string.IsNullOrEmpty(_taskParam.DomainName))
|
||||
{
|
||||
if (MapLazyAssets.Instance.DomainPositionMap.TryGetValue(_taskParam.DomainName, out var domainPosition))
|
||||
{
|
||||
Logger.LogInformation("自动秘境:传送到秘境{Text}", _taskParam.DomainName);
|
||||
await new TpTask(_ct).Tp(domainPosition.X, domainPosition.Y);
|
||||
await Delay(1000, _ct);
|
||||
await Bv.WaitForMainUi(_ct);
|
||||
await Delay(1000, _ct);
|
||||
|
||||
if ("芬德尼尔之顶".Equals(_taskParam.DomainName))
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyDown(VK.VK_S);
|
||||
Thread.Sleep(3000);
|
||||
Simulation.SendInput.Keyboard.KeyUp(VK.VK_S);
|
||||
}
|
||||
else if ("无妄引咎密宫".Equals(_taskParam.DomainName))
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyDown(VK.VK_W);
|
||||
Thread.Sleep(500);
|
||||
Simulation.SendInput.Keyboard.KeyUp(VK.VK_W);
|
||||
Thread.Sleep(100);
|
||||
Simulation.SendInput.Keyboard.KeyDown(VK.VK_A);
|
||||
Thread.Sleep(1600);
|
||||
Simulation.SendInput.Keyboard.KeyUp(VK.VK_A);
|
||||
}
|
||||
else if ("苍白的遗荣".Equals(_taskParam.DomainName))
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyDown(VK.VK_W);
|
||||
Thread.Sleep(1000);
|
||||
Simulation.SendInput.Keyboard.KeyUp(VK.VK_W);
|
||||
}
|
||||
else
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyDown(VK.VK_W);
|
||||
Thread.Sleep(3000);
|
||||
Simulation.SendInput.Keyboard.KeyUp(VK.VK_W);
|
||||
}
|
||||
|
||||
await Delay(3000, _ct); // 站稳
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogError("自动秘境:未找到对应的秘境{Text}的传送点", _taskParam.DomainName);
|
||||
throw new Exception($"未找到对应的秘境{_taskParam.DomainName}的传送点");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换队伍
|
||||
/// </summary>
|
||||
/// <param name="partyName"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> SwitchParty(string? partyName)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(partyName))
|
||||
{
|
||||
var b = await new SwitchPartyTask().Start(partyName, _ct);
|
||||
await Delay(500, _ct);
|
||||
return b;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task EnterDomain()
|
||||
{
|
||||
var fightAssets = AutoFightContext.Instance.FightAssets;
|
||||
|
||||
// 进入秘境
|
||||
using var fRectArea = CaptureToRectArea().Find(AutoPickAssets.Instance.FRo);
|
||||
if (!fRectArea.IsEmpty())
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyPress(VK.VK_F);
|
||||
Logger.LogInformation("自动秘境:{Text}", "进入秘境");
|
||||
// 秘境开门动画 5s
|
||||
Sleep(5000, _ct);
|
||||
await Delay(5000, _ct);
|
||||
}
|
||||
|
||||
int retryTimes = 0, clickCount = 0;
|
||||
@@ -190,14 +302,14 @@ public class AutoDomainTask : ISoloTask
|
||||
clickCount++;
|
||||
}
|
||||
|
||||
Sleep(1500, _ct);
|
||||
await Delay(1500, _ct);
|
||||
}
|
||||
|
||||
// 载入动画
|
||||
Sleep(3000, _ct);
|
||||
await Delay(3000, _ct);
|
||||
}
|
||||
|
||||
private void CloseDomainTip()
|
||||
private async Task CloseDomainTip()
|
||||
{
|
||||
// 2min的载入时间总够了吧
|
||||
var retryTimes = 0;
|
||||
@@ -207,16 +319,16 @@ public class AutoDomainTask : ISoloTask
|
||||
using var cactRectArea = CaptureToRectArea().Find(AutoFightContext.Instance.FightAssets.ClickAnyCloseTipRa);
|
||||
if (!cactRectArea.IsEmpty())
|
||||
{
|
||||
Sleep(1000, _ct);
|
||||
await Delay(1000, _ct);
|
||||
cactRectArea.Click();
|
||||
break;
|
||||
}
|
||||
|
||||
// todo 添加小地图角标位置检测 防止有人手点了
|
||||
Sleep(1000, _ct);
|
||||
await Delay(1000, _ct);
|
||||
}
|
||||
|
||||
Sleep(1500, _ct);
|
||||
await Delay(1500, _ct);
|
||||
}
|
||||
|
||||
private List<CombatCommand> FindCombatScriptAndSwitchAvatar(CombatScenes combatScenes)
|
||||
@@ -274,7 +386,7 @@ public class AutoDomainTask : ISoloTask
|
||||
Simulation.SendInput.Keyboard.KeyUp(VK.VK_SHIFT);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}), _ct);
|
||||
}
|
||||
|
||||
private Task StartFight(CombatScenes combatScenes, List<CombatCommand> combatCommands)
|
||||
@@ -637,40 +749,12 @@ public class AutoDomainTask : ISoloTask
|
||||
while (!cts.Token.IsCancellationRequested)
|
||||
{
|
||||
using var captureRegion = CaptureToRectArea();
|
||||
var angle = CameraOrientation.Compute(captureRegion.SrcGreyMat);
|
||||
var angle = CameraOrientation.Compute(captureRegion.SrcMat);
|
||||
CameraOrientation.DrawDirection(captureRegion, angle);
|
||||
if (angle is >= 356 or <= 4)
|
||||
{
|
||||
// 算作对准了
|
||||
continuousCount++;
|
||||
}
|
||||
|
||||
if (angle <= 180)
|
||||
{
|
||||
// 左移视角
|
||||
var moveAngle = angle;
|
||||
if (moveAngle > 2)
|
||||
{
|
||||
moveAngle *= 2;
|
||||
}
|
||||
|
||||
Simulation.SendInput.Mouse.MoveMouseBy(-moveAngle, 0);
|
||||
continuousCount = 0;
|
||||
}
|
||||
else if (angle is > 180 and < 360)
|
||||
{
|
||||
// 右移视角
|
||||
var moveAngle = 360 - angle;
|
||||
if (moveAngle > 2)
|
||||
{
|
||||
moveAngle *= 2;
|
||||
}
|
||||
|
||||
Simulation.SendInput.Mouse.MoveMouseBy(moveAngle, 0);
|
||||
continuousCount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 360 度 东方向视角
|
||||
if (continuousCount > 5)
|
||||
{
|
||||
@@ -681,6 +765,33 @@ public class AutoDomainTask : ISoloTask
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
continuousCount = 0;
|
||||
}
|
||||
|
||||
if (angle <= 180)
|
||||
{
|
||||
// 左移视角
|
||||
var moveAngle = (int)Math.Round(angle);
|
||||
if (moveAngle > 2)
|
||||
{
|
||||
moveAngle *= 2;
|
||||
}
|
||||
|
||||
Simulation.SendInput.Mouse.MoveMouseBy(-moveAngle, 0);
|
||||
}
|
||||
else if (angle is > 180 and < 360)
|
||||
{
|
||||
// 右移视角
|
||||
var moveAngle = 360 - (int)Math.Round(angle);
|
||||
if (moveAngle > 2)
|
||||
{
|
||||
moveAngle *= 2;
|
||||
}
|
||||
|
||||
Simulation.SendInput.Mouse.MoveMouseBy(moveAngle, 0);
|
||||
}
|
||||
|
||||
Sleep(100);
|
||||
}
|
||||
@@ -829,4 +940,19 @@ public class AutoDomainTask : ISoloTask
|
||||
Logger.LogInformation("剩余:浓缩树脂 {CondensedResinCount} 脆弱树脂 {FragileResinCount}", condensedResinCount, fragileResinCount);
|
||||
return (condensedResinCount, fragileResinCount);
|
||||
}
|
||||
|
||||
private async Task ArtifactSalvage()
|
||||
{
|
||||
if (!_taskParam.AutoArtifactSalvage)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!int.TryParse(_taskParam.MaxArtifactStar, out var star))
|
||||
{
|
||||
star = 4;
|
||||
}
|
||||
|
||||
await new ArtifactSalvageTask().Start(star, _ct);
|
||||
}
|
||||
}
|
||||
@@ -1620,7 +1620,8 @@
|
||||
"卡齐纳",
|
||||
"卡齐那",
|
||||
"卡其那",
|
||||
"冲天钻钻"
|
||||
"冲天钻钻",
|
||||
"岩莉莉"
|
||||
],
|
||||
"burstCD": 18,
|
||||
"id": "10000100",
|
||||
@@ -1634,7 +1635,8 @@
|
||||
"基尼奇",
|
||||
"Kinich",
|
||||
"基哥",
|
||||
"基尼齐"
|
||||
"基尼齐",
|
||||
"蜘蛛侠"
|
||||
],
|
||||
"burstCD": 18,
|
||||
"id": "10000101",
|
||||
@@ -1684,7 +1686,8 @@
|
||||
"恰斯卡",
|
||||
"Chasca",
|
||||
"武卡",
|
||||
"调停人"
|
||||
"调停人",
|
||||
"鸟人"
|
||||
],
|
||||
"burstCD": 15,
|
||||
"id": "10000104",
|
||||
@@ -1696,9 +1699,10 @@
|
||||
{
|
||||
"alias": [
|
||||
"欧洛伦",
|
||||
"Olorun",
|
||||
"Ororon",
|
||||
"庇笛",
|
||||
"孙子",
|
||||
"大孙子",
|
||||
"蝙蝠侠"
|
||||
],
|
||||
"burstCD": 15,
|
||||
@@ -1707,5 +1711,55 @@
|
||||
"nameEn": "Olorun",
|
||||
"skillCD": 15,
|
||||
"weapon": "12"
|
||||
},
|
||||
{
|
||||
"alias": [
|
||||
"玛薇卡",
|
||||
"Mavuika",
|
||||
"火神",
|
||||
"马薇卡",
|
||||
"玛维卡",
|
||||
"马维卡"
|
||||
],
|
||||
"burstCD": 18,
|
||||
"id": "10000106",
|
||||
"name": "玛薇卡",
|
||||
"nameEn": "Mavuika",
|
||||
"skillCD": 15,
|
||||
"weapon": "11"
|
||||
},
|
||||
{
|
||||
"alias": [
|
||||
"茜特菈莉",
|
||||
"Citlali",
|
||||
"西特菈莉",
|
||||
"西特拉莉",
|
||||
"茜特拉莉",
|
||||
"西特拉利",
|
||||
"黑曜石奶奶",
|
||||
"黑曜石",
|
||||
"奶奶",
|
||||
"老伴"
|
||||
],
|
||||
"burstCD": 15,
|
||||
"id": "10000107",
|
||||
"name": "茜特菈莉",
|
||||
"nameEn": "Citlali",
|
||||
"skillCD": 16,
|
||||
"weapon": "10"
|
||||
},
|
||||
{
|
||||
"alias": [
|
||||
"蓝砚",
|
||||
"蓝燕",
|
||||
"兰砚",
|
||||
"兰燕"
|
||||
],
|
||||
"burstCD": 15,
|
||||
"id": "10000108",
|
||||
"name": "蓝砚",
|
||||
"nameEn": "Lanyan",
|
||||
"skillCD": 16,
|
||||
"weapon": "10"
|
||||
}
|
||||
]
|
||||
@@ -3,6 +3,10 @@ using System;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoFight;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 自动战斗配置
|
||||
/// </summary>
|
||||
@@ -21,10 +25,64 @@ public partial class AutoFightConfig : ObservableObject
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _fightFinishDetectEnabled = true;
|
||||
[Serializable]
|
||||
public partial class FightFinishDetectConfig : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 判断战斗结束读条颜色,不同帧率可能下会有些不同,默认为95,235,255
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _battleEndProgressBarColor = "";
|
||||
|
||||
/// <summary>
|
||||
/// 对于上方颜色地偏差值,即±某个值,例如 6或6,6,6,前者表示所有偏差值都一样,后者则可以分别设置
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _battleEndProgressBarColorTolerance = "";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 快速检查战斗结束,在一轮脚本中,可以每隔一定秒数(默认为5)或指定角色操作后,去检查(在每个角色完成该轮脚本时)。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _fastCheckEnabled = false;
|
||||
|
||||
/// <summary>
|
||||
/// 快速检查战斗结束的参数,可填入数字和人名,多种用分号分隔,例如:15,白术;钟离;,如果是数字(小于等于0则不会根据时间去检查),则指定检查间隔,如果是人名,则该角色执行一轮操作后进行检查。同时每轮结束后检查不变。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _fastCheckParams = "";
|
||||
|
||||
/// <summary>
|
||||
/// 检查战斗结束的延时,即角色,默认为1.5秒。也可以指定特定角色之后延时多少时间检查。格式如:2.5;白术,1.5;钟离,1.0;
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _checkEndDelay = "";
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 战斗结束相关配置
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private FightFinishDetectConfig _finishDetectConfig = new();
|
||||
|
||||
/// <summary>
|
||||
/// 检测战斗结束
|
||||
/// 检测战斗结束,默认为每轮脚本后检查
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _pickDropsAfterFightEnabled = true;
|
||||
|
||||
/// <summary>
|
||||
/// 战斗结束后,如果存在枫原万叶,则使用该角色捡材料
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _kazuhaPickupEnabled = true;
|
||||
|
||||
/// <summary>
|
||||
/// 战斗超时,单位秒
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private int _timeout = 120;
|
||||
|
||||
|
||||
}
|
||||
@@ -2,11 +2,51 @@
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoFight;
|
||||
|
||||
public class AutoFightParam(string path) : BaseTaskParam
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class AutoFightParam : BaseTaskParam
|
||||
{
|
||||
public string CombatStrategyPath { get; set; } = path;
|
||||
public class FightFinishDetectConfig
|
||||
{
|
||||
public string BattleEndProgressBarColor { get; set; }= "";
|
||||
|
||||
public string BattleEndProgressBarColorTolerance { get; set; }= "";
|
||||
public bool FastCheckEnabled = false;
|
||||
public string FastCheckParams = "";
|
||||
public string CheckEndDelay = "";
|
||||
}
|
||||
|
||||
public AutoFightParam(string path, AutoFightConfig autoFightConfig)
|
||||
{
|
||||
CombatStrategyPath = path;
|
||||
Timeout = autoFightConfig.Timeout;
|
||||
FightFinishDetectEnabled = autoFightConfig.FightFinishDetectEnabled;
|
||||
PickDropsAfterFightEnabled = autoFightConfig.PickDropsAfterFightEnabled;
|
||||
KazuhaPickupEnabled = autoFightConfig.KazuhaPickupEnabled;
|
||||
|
||||
FinishDetectConfig.FastCheckEnabled = autoFightConfig.FinishDetectConfig.FastCheckEnabled;
|
||||
FinishDetectConfig.FastCheckParams = autoFightConfig.FinishDetectConfig.FastCheckParams;
|
||||
FinishDetectConfig.CheckEndDelay = autoFightConfig.FinishDetectConfig.CheckEndDelay;
|
||||
|
||||
//下面参数固定,只取自动战斗里面的
|
||||
FinishDetectConfig.BattleEndProgressBarColor = TaskContext.Instance().Config.AutoFightConfig.FinishDetectConfig.BattleEndProgressBarColor;
|
||||
FinishDetectConfig.BattleEndProgressBarColorTolerance = TaskContext.Instance().Config.AutoFightConfig.FinishDetectConfig.BattleEndProgressBarColorTolerance;
|
||||
}
|
||||
|
||||
public FightFinishDetectConfig FinishDetectConfig { get; set; } = new();
|
||||
|
||||
public string CombatStrategyPath { get; set; }
|
||||
|
||||
public bool FightFinishDetectEnabled { get; set; } = false;
|
||||
|
||||
public bool PickDropsAfterFightEnabled { get; set; } = false;
|
||||
}
|
||||
|
||||
public int Timeout { get; set; } = 120;
|
||||
|
||||
public bool KazuhaPickupEnabled = true;
|
||||
|
||||
|
||||
}
|
||||
@@ -5,15 +5,19 @@ using BetterGenshinImpact.GameTask.AutoFight.Script;
|
||||
using BetterGenshinImpact.GameTask.Model.Area;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.GameTask.AutoFight.Assets;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
using BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
using BetterGenshinImpact.GameTask.Common.Job;
|
||||
using OpenCvSharp;
|
||||
using Vanara;
|
||||
using Vanara.PInvoke;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoFight;
|
||||
|
||||
@@ -33,6 +37,133 @@ public class AutoFightTask : ISoloTask
|
||||
|
||||
private readonly double _dpi = TaskContext.Instance().DpiScale;
|
||||
|
||||
|
||||
private class TaskFightFinishDetectConfig
|
||||
{
|
||||
public int DelayTime=1500;
|
||||
public Dictionary<string, int> DelayTimes = new();
|
||||
public double CheckTime = 5;
|
||||
public List<string> CheckNames = new();
|
||||
public bool FastCheckEnabled;
|
||||
public TaskFightFinishDetectConfig(AutoFightParam.FightFinishDetectConfig finishDetectConfig)
|
||||
{
|
||||
FastCheckEnabled=finishDetectConfig.FastCheckEnabled;
|
||||
ParseCheckTimeString(finishDetectConfig.FastCheckParams,out CheckTime,CheckNames);
|
||||
ParseFastCheckEndDelayString(finishDetectConfig.CheckEndDelay,out DelayTime,DelayTimes);
|
||||
BattleEndProgressBarColor = ParseStringToTuple(finishDetectConfig.BattleEndProgressBarColor, (95, 235, 255));
|
||||
BattleEndProgressBarColorTolerance = ParseSingleOrCommaSeparated(finishDetectConfig.BattleEndProgressBarColorTolerance, (6, 6, 6));
|
||||
}
|
||||
|
||||
public (int, int, int) BattleEndProgressBarColor{ get; }
|
||||
public (int, int, int) BattleEndProgressBarColorTolerance{ get; }
|
||||
public static void ParseCheckTimeString(
|
||||
string input,
|
||||
out double checkTime,
|
||||
List<string> names)
|
||||
{
|
||||
checkTime = 5;
|
||||
if (string.IsNullOrEmpty(input))
|
||||
{
|
||||
return; // 直接返回
|
||||
}
|
||||
var uniqueNames = new HashSet<string>(); // 用于临时去重的集合
|
||||
|
||||
// 按分号分割字符串
|
||||
var segments = input.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (var segment in segments)
|
||||
{
|
||||
var trimmedSegment = segment.Trim();
|
||||
|
||||
// 如果是纯数字部分
|
||||
if (double.TryParse(trimmedSegment, NumberStyles.Float, CultureInfo.InvariantCulture, out double number))
|
||||
{
|
||||
checkTime = number; // 更新 CheckTime
|
||||
}
|
||||
else if (!uniqueNames.Contains(trimmedSegment)) // 如果是非数字且不重复
|
||||
{
|
||||
uniqueNames.Add(trimmedSegment); // 添加到集合
|
||||
}
|
||||
}
|
||||
|
||||
names.AddRange(uniqueNames); // 将集合转换为列表
|
||||
}
|
||||
public static void ParseFastCheckEndDelayString(
|
||||
string input,
|
||||
out int delayTime,
|
||||
Dictionary<string, int> nameDelayMap)
|
||||
{
|
||||
delayTime = 1500;
|
||||
|
||||
if (string.IsNullOrEmpty(input))
|
||||
{
|
||||
|
||||
return; // 直接返回
|
||||
}
|
||||
// 分割字符串,以分号为分隔符
|
||||
var segments = input.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (var segment in segments)
|
||||
{
|
||||
var parts = segment.Split(',');
|
||||
|
||||
// 如果是纯数字部分
|
||||
if (parts.Length == 1)
|
||||
{
|
||||
if (double.TryParse(parts[0].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out double number))
|
||||
{
|
||||
delayTime = (int)(number * 1000); // 更新 delayTime
|
||||
}
|
||||
}
|
||||
// 如果是名字,数字格式
|
||||
else if (parts.Length == 2)
|
||||
{
|
||||
string name = parts[0].Trim();
|
||||
if (double.TryParse(parts[1].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out double value))
|
||||
{
|
||||
nameDelayMap[name] = (int)(value * 1000); // 更新字典,取最后一个值
|
||||
}
|
||||
}
|
||||
// 其他格式,跳过不处理
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static bool IsSingleNumber(string input, out int result)
|
||||
{
|
||||
return int.TryParse(input, out result);
|
||||
}
|
||||
|
||||
static (int, int, int) ParseSingleOrCommaSeparated(string input, (int, int, int) defaultValue)
|
||||
{
|
||||
// 如果是单个数字
|
||||
if (IsSingleNumber(input, out var singleNumber))
|
||||
{
|
||||
return (singleNumber, singleNumber, singleNumber);
|
||||
}
|
||||
|
||||
return ParseStringToTuple(input, defaultValue);
|
||||
}
|
||||
|
||||
static (int, int, int) ParseStringToTuple(string input, (int, int, int) defaultValue)
|
||||
{
|
||||
// 尝试按逗号分割字符串
|
||||
var parts = input.Split(',');
|
||||
if (parts.Length == 3 &&
|
||||
int.TryParse(parts[0], out var num1) &&
|
||||
int.TryParse(parts[1], out var num2) &&
|
||||
int.TryParse(parts[2], out var num3))
|
||||
{
|
||||
return (num1, num2, num3);
|
||||
}
|
||||
|
||||
// 如果解析失败,返回默认值
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private TaskFightFinishDetectConfig _finishDetectConfig;
|
||||
public AutoFightTask(AutoFightParam taskParam)
|
||||
{
|
||||
_taskParam = taskParam;
|
||||
@@ -40,10 +171,18 @@ public class AutoFightTask : ISoloTask
|
||||
|
||||
if (_taskParam.FightFinishDetectEnabled)
|
||||
{
|
||||
_predictor = new BgiYoloV8Predictor(@"Assets\Model\World\bgi_world.onnx");
|
||||
_predictor = BgiYoloV8PredictorFactory.GetPredictor(@"Assets\Model\World\bgi_world.onnx");
|
||||
}
|
||||
|
||||
_finishDetectConfig=new TaskFightFinishDetectConfig(_taskParam.FinishDetectConfig);
|
||||
}
|
||||
|
||||
// 方法1:判断是否是单个数字
|
||||
|
||||
/*public int delayTime=1500;
|
||||
public Dictionary<string, int> delayTimes = new();
|
||||
public double checkTime = 5;
|
||||
public List<string> checkNames = new();*/
|
||||
public async Task Start(CancellationToken ct)
|
||||
{
|
||||
_ct = ct;
|
||||
@@ -62,7 +201,19 @@ public class AutoFightTask : ISoloTask
|
||||
ct.Register(cts2.Cancel);
|
||||
|
||||
combatScenes.BeforeTask(cts2.Token);
|
||||
TimeSpan fightTimeout = TimeSpan.FromSeconds(_taskParam.Timeout); // 战斗超时时间
|
||||
Stopwatch timeoutStopwatch = Stopwatch.StartNew();
|
||||
|
||||
Stopwatch checkFightFinishStopwatch = Stopwatch.StartNew();
|
||||
TimeSpan checkFightFinishTime = TimeSpan.FromSeconds(_finishDetectConfig.CheckTime); //检查战斗超时时间的超时时间
|
||||
|
||||
|
||||
//战斗前检查,可做成配置
|
||||
/* if (await CheckFightFinish()) {
|
||||
return;
|
||||
}*/
|
||||
var fightEndFlag = false;
|
||||
string lastFighttName = "";
|
||||
// 战斗操作
|
||||
var fightTask = Task.Run(async () =>
|
||||
{
|
||||
@@ -70,13 +221,63 @@ public class AutoFightTask : ISoloTask
|
||||
{
|
||||
while (!cts2.Token.IsCancellationRequested)
|
||||
{
|
||||
|
||||
// 通用化战斗策略
|
||||
foreach (var command in combatCommands)
|
||||
for (var i = 0; i < combatCommands.Count; i++)
|
||||
{
|
||||
var command = combatCommands[i];
|
||||
if (timeoutStopwatch.Elapsed > fightTimeout)
|
||||
{
|
||||
Logger.LogInformation("战斗超时结束");
|
||||
fightEndFlag = true;
|
||||
break;
|
||||
}
|
||||
|
||||
command.Execute(combatScenes);
|
||||
|
||||
|
||||
lastFighttName = command.Name;
|
||||
if (!fightEndFlag && _taskParam is { FightFinishDetectEnabled: true } )
|
||||
{
|
||||
|
||||
//处于最后一个位置,或者当前执行人和下一个人名字不一样的情况,满足一定条件(开启快速检查,并且检查时间大于0或人名存在配置)检查战斗
|
||||
if (i==combatCommands.Count - 1
|
||||
|| (
|
||||
_finishDetectConfig.FastCheckEnabled && command.Name!=combatCommands[i+1].Name &&
|
||||
((_finishDetectConfig.CheckTime>0 && checkFightFinishStopwatch.Elapsed>checkFightFinishTime)
|
||||
|| _finishDetectConfig.CheckNames.Contains(command.Name))
|
||||
))
|
||||
{
|
||||
|
||||
checkFightFinishStopwatch.Restart();
|
||||
var delayTime = _finishDetectConfig.DelayTime;
|
||||
if (_finishDetectConfig.DelayTimes.TryGetValue(command.Name, out var time))
|
||||
{
|
||||
delayTime = time;
|
||||
Logger.LogInformation($"{command.Name}结束后,延时检查为{delayTime}毫秒");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogInformation($"延时检查为{delayTime}毫秒");
|
||||
}
|
||||
|
||||
/*if (i<combatCommands.Count - 1)
|
||||
{
|
||||
Logger.LogInformation($"{command.Name}下一个人为{combatCommands[i+1].Name}毫秒");
|
||||
}*/
|
||||
fightEndFlag = await CheckFightFinish(delayTime);
|
||||
}
|
||||
}
|
||||
|
||||
if (fightEndFlag)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (await CheckFightFinish())
|
||||
|
||||
if (fightEndFlag)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -86,6 +287,7 @@ public class AutoFightTask : ISoloTask
|
||||
{
|
||||
Debug.WriteLine(e.Message);
|
||||
Debug.WriteLine(e.StackTrace);
|
||||
throw;
|
||||
}
|
||||
}, cts2.Token);
|
||||
|
||||
@@ -121,10 +323,46 @@ public class AutoFightTask : ISoloTask
|
||||
// }, cts2.Token);
|
||||
//
|
||||
// await Task.WhenAll(fightTask, endTask);
|
||||
if (_taskParam.KazuhaPickupEnabled)
|
||||
{
|
||||
// 队伍中存在万叶的时候使用一次长E
|
||||
var kazuha = combatScenes.Avatars.FirstOrDefault(a => a.Name == "枫原万叶");
|
||||
if (kazuha != null)
|
||||
{
|
||||
var time = DateTime.UtcNow - kazuha.LastSkillTime;
|
||||
//当万叶最后一个出招,并且cd大于3时,此时不再触发万叶拾取
|
||||
if (!(lastFighttName== "枫原万叶" && time.TotalSeconds>3))
|
||||
{
|
||||
|
||||
Logger.LogInformation("使用枫原万叶长E拾取掉落物");
|
||||
await Delay(300, ct);
|
||||
if (kazuha.TrySwitch())
|
||||
{
|
||||
if (time.TotalMilliseconds > 0 && time.TotalSeconds <= kazuha.SkillHoldCd)
|
||||
{
|
||||
Logger.LogInformation("枫原万叶长E技能可能处于冷却中,等待 {Time} s",time.TotalSeconds);
|
||||
await Delay((int)Math.Ceiling(time.TotalMilliseconds), ct);
|
||||
}
|
||||
kazuha.UseSkill(true);
|
||||
await Task.Delay(100);
|
||||
Simulation.SendInput.Mouse.LeftButtonClick();
|
||||
await Delay(1500, ct);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogInformation("最后一次由万叶出招,不再重复拾取!");
|
||||
}
|
||||
|
||||
if (_taskParam is { FightFinishDetectEnabled: true, PickDropsAfterFightEnabled: true })
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (_taskParam is { PickDropsAfterFightEnabled: true })
|
||||
{
|
||||
// 执行自动拾取掉落物的功能
|
||||
await new ScanPickTask().Start(ct);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,37 +375,70 @@ public class AutoFightTask : ISoloTask
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> CheckFightFinish()
|
||||
static bool AreDifferencesWithinBounds((int, int, int) a, (int, int, int) b, (int, int, int) c)
|
||||
{
|
||||
// 计算每个位置的差值绝对值并进行比较
|
||||
return Math.Abs(a.Item1 - b.Item1) < c.Item1 &&
|
||||
Math.Abs(a.Item2 - b.Item2) < c.Item2 &&
|
||||
Math.Abs(a.Item3 - b.Item3) < c.Item3;
|
||||
}
|
||||
|
||||
private async Task<bool> CheckFightFinish(int delayTime=1500)
|
||||
{
|
||||
// YOLO 判断血条和怪物位置
|
||||
if (HasFightFlagByYolo(CaptureToRectArea()))
|
||||
{
|
||||
_lastFightFlagTime = DateTime.Now;
|
||||
return false;
|
||||
}
|
||||
// if (HasFightFlagByYolo(CaptureToRectArea()))
|
||||
// {
|
||||
// _lastFightFlagTime = DateTime.Now;
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
|
||||
//Random random = new Random();
|
||||
//double randomFraction = random.NextDouble(); // 生成 0 到 1 之间的随机小数
|
||||
//此处随机数,防止固定招式下,使按L正好处于招式下,导致无法准确判断战斗结束
|
||||
// double randomNumber = 1 + (randomFraction * (3 - 1));
|
||||
|
||||
// 几秒内没有检测到血条和怪物位置,则开始旋转视角重新检测
|
||||
if ((DateTime.Now - _lastFightFlagTime).TotalSeconds > 3)
|
||||
//if ((DateTime.Now - _lastFightFlagTime).TotalSeconds > randomNumber)
|
||||
//{
|
||||
// 旋转完毕后都没有检测到血条和怪物位置,则按L键确认战斗结束
|
||||
/**
|
||||
Simulation.SendInput.Mouse.MiddleButtonClick();
|
||||
await Delay(300, _ct);
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
// 旋转完毕后都没有检测到血条和怪物位置,则按L键确认战斗结束
|
||||
Simulation.SendInput.Mouse.MiddleButtonClick();
|
||||
await Delay(300, _ct);
|
||||
for (var i = 0; i < 8; i++)
|
||||
Simulation.SendInput.Mouse.MoveMouseBy((int)(500 * _dpi), 0);
|
||||
await Delay(800, _ct); // 等待视角稳定
|
||||
if (HasFightFlagByYolo(CaptureToRectArea()))
|
||||
{
|
||||
Simulation.SendInput.Mouse.MoveMouseBy((int)(500 * _dpi), 0);
|
||||
await Delay(800, _ct); // 等待视角稳定
|
||||
if (HasFightFlagByYolo(CaptureToRectArea()))
|
||||
{
|
||||
_lastFightFlagTime = DateTime.Now;
|
||||
return false;
|
||||
}
|
||||
_lastFightFlagTime = DateTime.Now;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
**/
|
||||
|
||||
await Delay(delayTime, _ct);
|
||||
Logger.LogInformation("按L检查战斗是否结束");
|
||||
// 最终方案确认战斗结束
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_L);
|
||||
await Delay(450, _ct);
|
||||
var ra = CaptureToRectArea();
|
||||
var b3 = ra.SrcMat.At<Vec3b>(50, 790);
|
||||
|
||||
// 最终方案确认战斗结束
|
||||
if (AreDifferencesWithinBounds(_finishDetectConfig.BattleEndProgressBarColor, (b3.Item0, b3.Item1, b3.Item2), _finishDetectConfig.BattleEndProgressBarColorTolerance))
|
||||
{
|
||||
Logger.LogInformation("识别到战斗结束");
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_X);
|
||||
return true;
|
||||
}
|
||||
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_X);
|
||||
Logger.LogInformation($"未识别到战斗结束{b3.Item0},{b3.Item1},{b3.Item2}");
|
||||
_lastFightFlagTime = DateTime.Now;
|
||||
return false;
|
||||
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -191,4 +462,4 @@ public class AutoFightTask : ISoloTask
|
||||
// // 要大于 gadgetMat 的 1/2
|
||||
// return list.Any(r => r.Width > gadgetMat.Width / 2 && r.Height > gadgetMat.Height / 2);
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,11 @@ public class Avatar
|
||||
/// 长按元素战技CD
|
||||
/// </summary>
|
||||
public double SkillHoldCd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最近一次使用元素战技的时间
|
||||
/// </summary>
|
||||
public DateTime LastSkillTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 元素爆发CD
|
||||
@@ -357,6 +362,7 @@ public class Avatar
|
||||
{
|
||||
Logger.LogInformation(hold ? "{Name} 长按元素战技,cd:{Cd}" : "{Name} 点按元素战技,cd:{Cd}", Name, cd);
|
||||
// todo 把cd加入执行队列
|
||||
LastSkillTime = DateTime.UtcNow;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public class CombatScenes : IDisposable
|
||||
if (result.TopClass.Name.Name.StartsWith("Qin") || result.TopClass.Name.Name.Contains("Costume"))
|
||||
{
|
||||
// 降低琴和衣装角色的识别率要求
|
||||
if (result.TopClass.Confidence < 0.6)
|
||||
if (result.TopClass.Confidence < 0.51)
|
||||
{
|
||||
Cv2.ImWrite(@"log\avatar_side_classify_error.png", src.ToMat());
|
||||
throw new Exception($"无法识别第{index}位角色,置信度{result.TopClass.Confidence},结果:{result.TopClass.Name.Name}");
|
||||
|
||||
@@ -728,11 +728,13 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
|
||||
{
|
||||
NewRetry.Do(() =>
|
||||
{
|
||||
TaskControl.TrySuspend();
|
||||
if (IsEnabled && !SystemControl.IsGenshinImpactActiveByProcess())
|
||||
{
|
||||
_logger.LogWarning("当前获取焦点的窗口不是原神,暂停");
|
||||
throw new RetryException("当前获取焦点的窗口不是原神");
|
||||
}
|
||||
|
||||
}, TimeSpan.FromSeconds(1), 100);
|
||||
CheckFishingUserInterface(_currContent);
|
||||
Thread.Sleep(millisecondsTimeout);
|
||||
|
||||
@@ -1787,6 +1787,75 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 1214,
|
||||
"nameEn": "mualani",
|
||||
"type": "character",
|
||||
"name": "玛拉妮",
|
||||
"hp": 10,
|
||||
"energy": 2,
|
||||
"element": "水元素",
|
||||
"weapon": "法器",
|
||||
"skills": [
|
||||
{
|
||||
"nameEn": "cooling_treatment",
|
||||
"name": "降温处理",
|
||||
"skillTag": [
|
||||
"普通攻击"
|
||||
],
|
||||
"cost": [
|
||||
{
|
||||
"id": 1102,
|
||||
"nameEn": "hydro",
|
||||
"type": "水元素",
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"id": 1109,
|
||||
"nameEn": "unaligned_element",
|
||||
"type": "无色元素",
|
||||
"count": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"nameEn": "surfshark_wavebreaker",
|
||||
"name": "踏鲨破浪",
|
||||
"skillTag": [
|
||||
"元素战技"
|
||||
],
|
||||
"cost": [
|
||||
{
|
||||
"id": 1102,
|
||||
"nameEn": "hydro",
|
||||
"type": "水元素",
|
||||
"count": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"nameEn": "boomsharkalaka",
|
||||
"name": "爆瀑飞弹",
|
||||
"skillTag": [
|
||||
"元素爆发"
|
||||
],
|
||||
"cost": [
|
||||
{
|
||||
"id": 1102,
|
||||
"nameEn": "hydro",
|
||||
"type": "水元素",
|
||||
"count": 3
|
||||
},
|
||||
{
|
||||
"id": 1110,
|
||||
"nameEn": "energy",
|
||||
"type": "充能",
|
||||
"count": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 1301,
|
||||
"nameEn": "diluc",
|
||||
@@ -3482,6 +3551,75 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 1412,
|
||||
"nameEn": "clorinde",
|
||||
"type": "character",
|
||||
"name": "克洛琳德",
|
||||
"hp": 10,
|
||||
"energy": 2,
|
||||
"element": "雷元素",
|
||||
"weapon": "单手剑",
|
||||
"skills": [
|
||||
{
|
||||
"nameEn": "oath_of_hunting_shadows",
|
||||
"name": "逐影之誓",
|
||||
"skillTag": [
|
||||
"普通攻击"
|
||||
],
|
||||
"cost": [
|
||||
{
|
||||
"id": 1104,
|
||||
"nameEn": "electro",
|
||||
"type": "雷元素",
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"id": 1109,
|
||||
"nameEn": "unaligned_element",
|
||||
"type": "无色元素",
|
||||
"count": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"nameEn": "hunters_vigil",
|
||||
"name": "狩夜之巡",
|
||||
"skillTag": [
|
||||
"元素战技"
|
||||
],
|
||||
"cost": [
|
||||
{
|
||||
"id": 1104,
|
||||
"nameEn": "electro",
|
||||
"type": "雷元素",
|
||||
"count": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"nameEn": "last_lightfall",
|
||||
"name": "残光将终",
|
||||
"skillTag": [
|
||||
"元素爆发"
|
||||
],
|
||||
"cost": [
|
||||
{
|
||||
"id": 1104,
|
||||
"nameEn": "electro",
|
||||
"type": "雷元素",
|
||||
"count": 3
|
||||
},
|
||||
{
|
||||
"id": 1110,
|
||||
"nameEn": "energy",
|
||||
"type": "充能",
|
||||
"count": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 1501,
|
||||
"nameEn": "sucrose",
|
||||
@@ -7220,6 +7358,75 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2603,
|
||||
"nameEn": "golden_wolflord",
|
||||
"type": "character",
|
||||
"name": "黄金王兽",
|
||||
"hp": 10,
|
||||
"energy": 2,
|
||||
"element": "岩元素",
|
||||
"weapon": "其他武器",
|
||||
"skills": [
|
||||
{
|
||||
"nameEn": "wolflords_strike",
|
||||
"name": "王狼直击",
|
||||
"skillTag": [
|
||||
"普通攻击"
|
||||
],
|
||||
"cost": [
|
||||
{
|
||||
"id": 1106,
|
||||
"nameEn": "geo",
|
||||
"type": "岩元素",
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"id": 1109,
|
||||
"nameEn": "unaligned_element",
|
||||
"type": "无色元素",
|
||||
"count": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"nameEn": "howling_riftcall",
|
||||
"name": "兽境轰召",
|
||||
"skillTag": [
|
||||
"元素战技"
|
||||
],
|
||||
"cost": [
|
||||
{
|
||||
"id": 1106,
|
||||
"nameEn": "geo",
|
||||
"type": "岩元素",
|
||||
"count": 3
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"nameEn": "golden_cankerbind",
|
||||
"name": "黄金侵绞",
|
||||
"skillTag": [
|
||||
"元素爆发"
|
||||
],
|
||||
"cost": [
|
||||
{
|
||||
"id": 1106,
|
||||
"nameEn": "geo",
|
||||
"type": "岩元素",
|
||||
"count": 3
|
||||
},
|
||||
{
|
||||
"id": 1110,
|
||||
"nameEn": "energy",
|
||||
"type": "充能",
|
||||
"count": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2701,
|
||||
"nameEn": "jadeplume_terrorshroom",
|
||||
@@ -7450,74 +7657,5 @@
|
||||
"cost": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 4608,
|
||||
"nameEn": "golden_wolflord",
|
||||
"type": "character",
|
||||
"name": "黄金王兽",
|
||||
"hp": 40,
|
||||
"energy": 2,
|
||||
"element": "岩元素",
|
||||
"weapon": "其他武器",
|
||||
"skills": [
|
||||
{
|
||||
"nameEn": "wolflords_strike",
|
||||
"name": "王狼直击",
|
||||
"skillTag": [
|
||||
"普通攻击"
|
||||
],
|
||||
"cost": [
|
||||
{
|
||||
"id": 1106,
|
||||
"nameEn": "geo",
|
||||
"type": "岩元素",
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"id": 1109,
|
||||
"nameEn": "unaligned_element",
|
||||
"type": "无色元素",
|
||||
"count": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"nameEn": "howling_riftcall",
|
||||
"name": "兽境轰召",
|
||||
"skillTag": [
|
||||
"元素战技"
|
||||
],
|
||||
"cost": [
|
||||
{
|
||||
"id": 1106,
|
||||
"nameEn": "geo",
|
||||
"type": "岩元素",
|
||||
"count": 3
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"nameEn": "golden_cankerbind",
|
||||
"name": "黄金侵绞",
|
||||
"skillTag": [
|
||||
"元素爆发"
|
||||
],
|
||||
"cost": [
|
||||
{
|
||||
"id": 1106,
|
||||
"nameEn": "geo",
|
||||
"type": "岩元素",
|
||||
"count": 3
|
||||
},
|
||||
{
|
||||
"id": 1110,
|
||||
"nameEn": "energy",
|
||||
"type": "充能",
|
||||
"count": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -107,12 +107,13 @@ public class GeniusInvokationControl
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TaskControl.TrySuspend();
|
||||
if (!SystemControl.IsGenshinImpactActiveByProcess())
|
||||
{
|
||||
_logger.LogWarning("当前获取焦点的窗口不是原神,暂停");
|
||||
throw new RetryException("当前获取焦点的窗口不是原神");
|
||||
}
|
||||
|
||||
}, TimeSpan.FromSeconds(1), 100);
|
||||
|
||||
if (_ct is { IsCancellationRequested: true })
|
||||
|
||||
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 505 B |
|
After Width: | Height: | Size: 2.5 KiB |
@@ -0,0 +1,46 @@
|
||||
using BetterGenshinImpact.Core.Recognition;
|
||||
using BetterGenshinImpact.GameTask.Model;
|
||||
using BetterGenshinImpact.Helpers.Extensions;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoMusicGame.Assets;
|
||||
|
||||
public class AutoMusicAssets : BaseAssets<AutoMusicAssets>
|
||||
{
|
||||
public RecognitionObject UiLeftTopAlbumIcon;
|
||||
public RecognitionObject BtnPause;
|
||||
public RecognitionObject AlbumMusicComplate;
|
||||
public RecognitionObject BtnList;
|
||||
|
||||
private AutoMusicAssets()
|
||||
{
|
||||
UiLeftTopAlbumIcon = new RecognitionObject
|
||||
{
|
||||
Name = "UiLeftTopAlbumIcon",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage(@"AutoMusicGame", "ui_left_top_album_icon.png"),
|
||||
RegionOfInterest = new Rect(0, 0, (int)(150 * AssetScale), (int)(120 * AssetScale)),
|
||||
}.InitTemplate();
|
||||
BtnPause = new RecognitionObject
|
||||
{
|
||||
Name = "BtnPause",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage(@"AutoMusicGame", "btn_pause.png"),
|
||||
RegionOfInterest = CaptureRect.CutRightTop(0.2, 0.2),
|
||||
}.InitTemplate();
|
||||
AlbumMusicComplate = new RecognitionObject
|
||||
{
|
||||
Name = "AlbumMusicComplate",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage(@"AutoMusicGame", "album_music_complate.png"),
|
||||
RegionOfInterest = new Rect( (int)(900 * AssetScale),(int)(320 * AssetScale), (int)(100 * AssetScale), (int)(80 * AssetScale)),
|
||||
}.InitTemplate();
|
||||
BtnList = new RecognitionObject
|
||||
{
|
||||
Name = "BtnList",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage(@"AutoMusicGame", "btn_list.png"),
|
||||
RegionOfInterest = CaptureRect.CutRightBottom(0.4, 0.2),
|
||||
}.InitTemplate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.GameTask.AutoMusicGame.Assets;
|
||||
using BetterGenshinImpact.GameTask.Common.BgiVision;
|
||||
using BetterGenshinImpact.GameTask.Model.Area;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoMusicGame;
|
||||
|
||||
/// <summary>
|
||||
/// 自动音乐专辑
|
||||
/// </summary>
|
||||
public class AutoAlbumTask(AutoMusicGameParam taskParam) : ISoloTask
|
||||
{
|
||||
public string Name => "自动音游专辑";
|
||||
|
||||
private AutoMusicGameTask _autoMusicGameTask = new AutoMusicGameTask(taskParam);
|
||||
|
||||
public async Task Start(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
AutoMusicGameTask.Init();
|
||||
Logger.LogInformation("开始自动演奏整个专辑未完成的音乐");
|
||||
await StartOneAlbum(ct);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("自动音乐专辑任务异常:{Msg}", e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task StartOneAlbum(CancellationToken ct)
|
||||
{
|
||||
using var iconRa = CaptureToRectArea().Find(AutoMusicAssets.Instance.UiLeftTopAlbumIcon);
|
||||
if (!iconRa.IsExist())
|
||||
{
|
||||
throw new Exception("当前未处于专辑界面,请在专辑界面运行本任务");
|
||||
}
|
||||
|
||||
// 12个音乐
|
||||
for (int i = 0; i < 13; i++)
|
||||
{
|
||||
|
||||
|
||||
using var doneRa = CaptureToRectArea().Find(AutoMusicAssets.Instance.AlbumMusicComplate);
|
||||
if (doneRa.IsExist())
|
||||
{
|
||||
Logger.LogInformation("当前乐曲{Num}所有奖励已领取,切换下一首", i + 1);
|
||||
GameCaptureRegion.GameRegion1080PPosClick(310, 220);
|
||||
await Delay(800, ct);
|
||||
continue;
|
||||
}
|
||||
|
||||
Logger.LogInformation("当前乐曲{Num}存在未领取奖励,前往演奏", i + 1);
|
||||
Bv.ClickWhiteConfirmButton(CaptureToRectArea());
|
||||
await Delay(800, ct);
|
||||
// 点击传说
|
||||
GameCaptureRegion.GameRegion1080PPosClick(1400, 600);
|
||||
await Delay(200, ct);
|
||||
// 演奏
|
||||
Bv.ClickWhiteConfirmButton(CaptureToRectArea());
|
||||
await Delay(500, ct);
|
||||
|
||||
CancellationTokenSource cts = new();
|
||||
ct.Register(cts.Cancel);
|
||||
|
||||
// 演奏结束检查任务
|
||||
var checkTask = Task.Run(async () =>
|
||||
{
|
||||
while (!cts.Token.IsCancellationRequested)
|
||||
{
|
||||
await Delay(5000, ct); // n秒检查一次
|
||||
using var listRa = CaptureToRectArea().Find(AutoMusicAssets.Instance.BtnList);
|
||||
if (listRa.IsExist())
|
||||
{
|
||||
listRa.Click();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, cts.Token);
|
||||
|
||||
// 演奏任务
|
||||
var musicTask = _autoMusicGameTask.StartWithOutInit(cts.Token);
|
||||
|
||||
// 等待任意一个任务完成
|
||||
await Task.WhenAny(checkTask, musicTask);
|
||||
await cts.CancelAsync();
|
||||
Logger.LogInformation("当前乐曲{Num}演奏结束", i + 1);
|
||||
await Delay(2000, ct);
|
||||
|
||||
await Bv.WaitUntilFound(AutoMusicAssets.Instance.UiLeftTopAlbumIcon, ct);
|
||||
Logger.LogInformation("切换下一首");
|
||||
GameCaptureRegion.GameRegion1080PPosClick(310, 220);
|
||||
await Delay(800, ct);
|
||||
}
|
||||
|
||||
Logger.LogInformation("当前专辑所有乐曲演奏结束");
|
||||
}
|
||||
}
|
||||
@@ -15,47 +15,73 @@ public class AutoMusicGameTask(AutoMusicGameParam taskParam) : ISoloTask
|
||||
{
|
||||
public string Name => "自动音游";
|
||||
|
||||
|
||||
// private readonly ConcurrentDictionary<User32.VK, int> _keyX = new()
|
||||
// {
|
||||
// [User32.VK.VK_A] = 417,
|
||||
// [User32.VK.VK_S] = 632,
|
||||
// [User32.VK.VK_D] = 846,
|
||||
// [User32.VK.VK_J] = 1065,
|
||||
// [User32.VK.VK_K] = 1282,
|
||||
// [User32.VK.VK_L] = 1500
|
||||
// };
|
||||
//
|
||||
// private readonly int _keyY = 916;
|
||||
|
||||
|
||||
private readonly ConcurrentDictionary<User32.VK, int> _keyX = new()
|
||||
{
|
||||
[User32.VK.VK_A] = 417,
|
||||
[User32.VK.VK_S] = 632,
|
||||
[User32.VK.VK_D] = 846,
|
||||
[User32.VK.VK_J] = 1065,
|
||||
[User32.VK.VK_K] = 1282,
|
||||
[User32.VK.VK_L] = 1500
|
||||
[User32.VK.VK_S] = 628,
|
||||
[User32.VK.VK_D] = 844,
|
||||
[User32.VK.VK_J] = 1061,
|
||||
[User32.VK.VK_K] = 1277,
|
||||
[User32.VK.VK_L] = 1493
|
||||
};
|
||||
|
||||
private readonly int _keyY = 916;
|
||||
private readonly int _keyY = 921;
|
||||
|
||||
private readonly IntPtr _hWnd = TaskContext.Instance().GameHandle;
|
||||
|
||||
public Task Start(CancellationToken ct)
|
||||
public async Task Start(CancellationToken ct)
|
||||
{
|
||||
Init();
|
||||
|
||||
var assetScale = TaskContext.Instance().SystemInfo.AssetScale;
|
||||
var taskFactory = new TaskFactory();
|
||||
var taskList = new List<Task>();
|
||||
|
||||
// 计算按键位置
|
||||
var gameCaptureRegion = CaptureToRectArea();
|
||||
|
||||
foreach (var keyValuePair in _keyX)
|
||||
{
|
||||
var (x, y) = gameCaptureRegion.ConvertPositionToGameCaptureRegion((int)(keyValuePair.Value * assetScale), (int)(_keyY * assetScale));
|
||||
// 添加任务
|
||||
taskList.Add(taskFactory.StartNew(() => DoWhitePressWin32(ct, keyValuePair.Key, new Point(x, y))));
|
||||
}
|
||||
|
||||
Task.WaitAll([.. taskList]);
|
||||
return Task.CompletedTask;
|
||||
await StartWithOutInit(ct);
|
||||
}
|
||||
|
||||
private void DoWhitePressWin32(CancellationToken ct, User32.VK key, Point point)
|
||||
public async Task StartWithOutInit(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
Logger.LogInformation("开始自动演奏");
|
||||
var assetScale = TaskContext.Instance().SystemInfo.AssetScale;
|
||||
// var taskFactory = new TaskFactory();
|
||||
var taskList = new List<Task>();
|
||||
|
||||
// 计算按键位置
|
||||
var gameCaptureRegion = CaptureToRectArea();
|
||||
|
||||
foreach (var keyValuePair in _keyX)
|
||||
{
|
||||
var (x, y) = gameCaptureRegion.ConvertPositionToGameCaptureRegion((int)(keyValuePair.Value * assetScale), (int)(_keyY * assetScale));
|
||||
// 添加任务
|
||||
taskList.Add(Task.Run(async () => await DoWhitePressWin32(ct, keyValuePair.Key, new Point(x, y)), ct));
|
||||
}
|
||||
|
||||
await Task.WhenAll(taskList);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Simulation.ReleaseAllKey();
|
||||
Logger.LogInformation("结束自动演奏");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DoWhitePressWin32(CancellationToken ct, User32.VK key, Point point)
|
||||
{
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
Thread.Sleep(10);
|
||||
await Task.Delay(5, ct);
|
||||
// Stopwatch sw = new();
|
||||
// sw.Start();
|
||||
var hdc = User32.GetDC(_hWnd);
|
||||
@@ -67,7 +93,7 @@ public class AutoMusicGameTask(AutoMusicGameParam taskParam) : ISoloTask
|
||||
KeyDown(key);
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
Thread.Sleep(10);
|
||||
await Task.Delay(5, ct);
|
||||
hdc = User32.GetDC(_hWnd);
|
||||
c = Gdi32.GetPixel(hdc, point.X, point.Y);
|
||||
Gdi32.DeleteDC(hdc);
|
||||
@@ -76,6 +102,7 @@ public class AutoMusicGameTask(AutoMusicGameParam taskParam) : ISoloTask
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KeyUp(key);
|
||||
}
|
||||
|
||||
@@ -84,6 +111,121 @@ public class AutoMusicGameTask(AutoMusicGameParam taskParam) : ISoloTask
|
||||
}
|
||||
}
|
||||
|
||||
// private async Task DoWhitePressWin32Default(CancellationToken ct, User32.VK key, Point point)
|
||||
// {
|
||||
// while (!ct.IsCancellationRequested)
|
||||
// {
|
||||
// await Task.Delay(10, ct);
|
||||
// var c = GetPixel(point.X, point.Y);
|
||||
//
|
||||
// if (c.G < 220)
|
||||
// {
|
||||
// KeyDown(key);
|
||||
// while (!ct.IsCancellationRequested)
|
||||
// {
|
||||
// Thread.Sleep(10);
|
||||
// c = GetPixel(point.X, point.Y);
|
||||
// if (c.G >= 230 && c.G != 255)
|
||||
// {
|
||||
// if (point.X == 417)
|
||||
// {
|
||||
// Debug.WriteLine("打断颜色:" + c.R + "," + c.G + "," + c.B);
|
||||
// }
|
||||
//
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// KeyUp(key);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// private async Task DoWhitePressWin32Default(CancellationToken ct, User32.VK key, Point point)
|
||||
// {
|
||||
// while (!ct.IsCancellationRequested)
|
||||
// {
|
||||
// await Task.Delay(5, ct);
|
||||
// var color = GetPixel(point.X, point.Y);
|
||||
// int r = color.R, g = color.G, b = color.B;
|
||||
//
|
||||
// if (r >= 140 && r <= 255 && g >= 100 && g <= 170 && b >= 230 && b <= 255)
|
||||
// {
|
||||
// // 按下按键
|
||||
// KeyDown(key);
|
||||
//
|
||||
// int z1 = 0;
|
||||
// while (z1 < 3)
|
||||
// {
|
||||
// await Task.Delay(5, ct);
|
||||
// color = GetPixel(point.X, point.Y);
|
||||
// int r1 = color.R, g1 = color.G, b1 = color.B;
|
||||
// var color2 = GetPixel(point.X + 2, point.Y + 2);
|
||||
// int r11 = color2.R, g11 = color2.G, b11 = color2.B;
|
||||
//
|
||||
// if ((r1 >= 140 && r1 <= 255 && g1 >= 100 && g1 <= 170) || (r11 >= 140 && r11 <= 255 && g11 >= 100 && g11 <= 170))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// z1++;
|
||||
// }
|
||||
//
|
||||
// Console.WriteLine($"{key} purple1 {r} {g} {b}");
|
||||
//
|
||||
// int z2 = 0;
|
||||
// while (z2 < 10)
|
||||
// {
|
||||
// await Task.Delay(5, ct);
|
||||
// color = GetPixel(point.X, point.Y);
|
||||
// int r1 = color.R, g1 = color.G, b1 = color.B;
|
||||
// var color2 = GetPixel(point.X + 2, point.Y + 2);
|
||||
// int r11 = color2.R, g11 = color2.G, b11 = color2.B;
|
||||
//
|
||||
// if (g1 >= 100 && g1 <= 170 || g11 >= 100 && g11 <= 170)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// z2++;
|
||||
// }
|
||||
//
|
||||
// Console.WriteLine($"{key} purple - 紫键结束 {r} {g} {b}");
|
||||
// KeyUp(key);
|
||||
// }
|
||||
//
|
||||
// if (r >= 230 && r <= 255 && g >= 170 && g <= 210 && b >= 50 && b <= 120)
|
||||
// {
|
||||
// KeyDown(key);
|
||||
//
|
||||
// var color2 = GetPixel(point.X, point.Y);
|
||||
// int r2 = color2.R, g2 = color2.G, b2 = color2.B;
|
||||
//
|
||||
//
|
||||
// while (g2 >= 170 && g2 <= 210 && b2 >= 50 && b2 <= 120)
|
||||
// {
|
||||
//
|
||||
// await Task.Delay(5, ct);
|
||||
// color2 = GetPixel(point.X, point.Y);
|
||||
// r2 = color2.R;
|
||||
// g2 = color2.G;
|
||||
// b2 = color2.B;
|
||||
// }
|
||||
//
|
||||
// KeyUp(key);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private COLORREF GetPixel(int x, int y)
|
||||
{
|
||||
var hdc = User32.GetDC(_hWnd);
|
||||
var c = Gdi32.GetPixel(hdc, x, y);
|
||||
Gdi32.DeleteDC(hdc);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
private void KeyUp(User32.VK key)
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyUp(key);
|
||||
@@ -94,17 +236,21 @@ public class AutoMusicGameTask(AutoMusicGameParam taskParam) : ISoloTask
|
||||
Simulation.SendInput.Keyboard.KeyDown(key);
|
||||
}
|
||||
|
||||
private void Init()
|
||||
public static void Init()
|
||||
{
|
||||
LogScreenResolution();
|
||||
}
|
||||
|
||||
private void LogScreenResolution()
|
||||
public static void LogScreenResolution()
|
||||
{
|
||||
var gameScreenSize = SystemControl.GetGameScreenRect(TaskContext.Instance().GameHandle);
|
||||
if (gameScreenSize.Width * 9 != gameScreenSize.Height * 16)
|
||||
{
|
||||
Logger.LogWarning("游戏窗口分辨率不是 16:9 !当前分辨率为 {Width}x{Height} , 非 16:9 分辨率的游戏可能无法正常使用自动活动音游功能 !", gameScreenSize.Width, gameScreenSize.Height);
|
||||
Logger.LogError("游戏窗口分辨率不是 16:9 !当前分辨率为 {Width}x{Height} , 非 16:9 分辨率的游戏无法正常使用自动活动音游功能 !", gameScreenSize.Width, gameScreenSize.Height);
|
||||
throw new Exception("游戏窗口分辨率不是 16:9");
|
||||
}
|
||||
|
||||
Logger.LogInformation("{Name}:回到游戏主界面时记得关闭自动音游任务!", "千音雅集");
|
||||
Logger.LogWarning("{Name}:默认的样式“轻漾涟漪”是{No}的!需要手动完成几首曲目获得{Money}千音币后兑换并使用胡桃样式“{Hutao}”!", "千音雅集", "不可用", 600, "疏影引蝶映梅红");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,9 @@ public class CameraRotateTask(CancellationToken ct)
|
||||
/// <param name="targetOrientation"></param>
|
||||
/// <param name="imageRegion"></param>
|
||||
/// <returns></returns>
|
||||
public int RotateToApproach(int targetOrientation, ImageRegion imageRegion)
|
||||
public float RotateToApproach(float targetOrientation, ImageRegion imageRegion)
|
||||
{
|
||||
var cao = CameraOrientation.Compute(imageRegion.SrcGreyMat);
|
||||
var cao = CameraOrientation.Compute(imageRegion.SrcMat);
|
||||
var diff = (cao - targetOrientation + 180) % 360 - 180;
|
||||
diff += diff < -180 ? 360 : 0;
|
||||
if (diff == 0)
|
||||
|
||||
@@ -12,31 +12,45 @@ namespace BetterGenshinImpact.GameTask.AutoPathing.Handler;
|
||||
|
||||
internal class AutoFightHandler : IActionHandler
|
||||
{
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null)
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null, object? config = null)
|
||||
{
|
||||
await StartFight(ct);
|
||||
await StartFight(ct, config);
|
||||
}
|
||||
|
||||
private async Task StartFight(CancellationToken ct)
|
||||
private async Task StartFight(CancellationToken ct, object? config = null)
|
||||
{
|
||||
TaskControl.Logger.LogInformation("执行 {Text}", "自动战斗");
|
||||
// 爷们要战斗
|
||||
var taskParams = new AutoFightParam(GetFightStrategy())
|
||||
AutoFightParam taskParams = null;
|
||||
if (config != null && config is PathingPartyConfig patyConfig && patyConfig.AutoFightEabled)
|
||||
{
|
||||
FightFinishDetectEnabled = true,
|
||||
PickDropsAfterFightEnabled = true
|
||||
};
|
||||
//替换配置为路径追踪
|
||||
|
||||
taskParams = GetFightAutoFightParam(patyConfig.AutoFightConfig);
|
||||
}
|
||||
else
|
||||
{
|
||||
taskParams = new AutoFightParam(GetFightStrategy(), TaskContext.Instance().Config.AutoFightConfig);
|
||||
}
|
||||
|
||||
var fightSoloTask = new AutoFightTask(taskParams);
|
||||
await fightSoloTask.Start(ct);
|
||||
}
|
||||
|
||||
private string GetFightStrategy()
|
||||
private AutoFightParam GetFightAutoFightParam(AutoFightConfig? config)
|
||||
{
|
||||
var path = Global.Absolute(@"User\AutoFight\" + TaskContext.Instance().Config.AutoFightConfig.StrategyName + ".txt");
|
||||
if ("根据队伍自动选择".Equals(TaskContext.Instance().Config.AutoFightConfig.StrategyName))
|
||||
AutoFightParam autoFightParam = new AutoFightParam(GetFightStrategy(config), config);
|
||||
return autoFightParam;
|
||||
}
|
||||
|
||||
private string GetFightStrategy(AutoFightConfig config)
|
||||
{
|
||||
var path = Global.Absolute(@"User\AutoFight\" + config.StrategyName + ".txt");
|
||||
if ("根据队伍自动选择".Equals(config.StrategyName))
|
||||
{
|
||||
path = Global.Absolute(@"User\AutoFight\");
|
||||
}
|
||||
|
||||
if (!File.Exists(path) && !Directory.Exists(path))
|
||||
{
|
||||
throw new Exception("战斗策略文件不存在");
|
||||
@@ -44,4 +58,9 @@ internal class AutoFightHandler : IActionHandler
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetFightStrategy()
|
||||
{
|
||||
return GetFightStrategy(TaskContext.Instance().Config.AutoFightConfig);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.GameTask.AutoPathing.Model;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
@@ -10,7 +11,7 @@ namespace BetterGenshinImpact.GameTask.AutoPathing.Handler;
|
||||
|
||||
public class CombatScriptHandler : IActionHandler
|
||||
{
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null)
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null, object? config = null)
|
||||
{
|
||||
if (waypointForTrack is { CombatScript: not null })
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.GameTask.AutoFight.Config;
|
||||
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model;
|
||||
using BetterGenshinImpact.GameTask.AutoPathing.Model;
|
||||
@@ -16,7 +17,7 @@ namespace BetterGenshinImpact.GameTask.AutoPathing.Handler;
|
||||
/// </summary>
|
||||
public class ElementalCollectHandler(ElementalType elementalType) : IActionHandler
|
||||
{
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null)
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null, object? config = null)
|
||||
{
|
||||
var combatScenes = await RunnerContext.Instance.GetCombatScenes(ct);
|
||||
if (combatScenes == null)
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.GameTask.AutoPathing.Model;
|
||||
using Vanara.PInvoke;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoPathing.Handler;
|
||||
|
||||
@@ -15,7 +16,7 @@ namespace BetterGenshinImpact.GameTask.AutoPathing.Handler;
|
||||
[Obsolete]
|
||||
public class ElementalSkillHandler : IActionHandler
|
||||
{
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null)
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null, object? config = null)
|
||||
{
|
||||
Logger.LogInformation("执行 {Text}", "释放元素战技");
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_E);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.GameTask.AutoPathing.Model;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoPathing.Handler;
|
||||
|
||||
public interface IActionHandler
|
||||
{
|
||||
Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack=null);
|
||||
Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack=null, object? config = null);
|
||||
}
|
||||
@@ -2,9 +2,11 @@
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.GameTask.AutoFight.Model;
|
||||
using BetterGenshinImpact.GameTask.AutoFight.Script;
|
||||
using BetterGenshinImpact.GameTask.AutoPathing.Model;
|
||||
using BetterGenshinImpact.GameTask.Common.Job;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
|
||||
@@ -22,7 +24,9 @@ public class MiningHandler : IActionHandler
|
||||
坎蒂丝 e(hold)
|
||||
""");
|
||||
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null)
|
||||
private readonly ScanPickTask _scanPickTask = new();
|
||||
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null, object? config = null)
|
||||
{
|
||||
var combatScenes = await RunnerContext.Instance.GetCombatScenes(ct);
|
||||
if (combatScenes == null)
|
||||
@@ -30,14 +34,14 @@ public class MiningHandler : IActionHandler
|
||||
Logger.LogError("队伍识别未初始化成功!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 挖矿
|
||||
Mining(combatScenes);
|
||||
|
||||
|
||||
await Delay(1000, ct);
|
||||
|
||||
|
||||
// 拾取
|
||||
|
||||
await _scanPickTask.Start(ct);
|
||||
}
|
||||
|
||||
private void Mining(CombatScenes combatScenes)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.Core.Simulator;
|
||||
using BetterGenshinImpact.GameTask.AutoPathing.Model;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
@@ -17,7 +18,7 @@ public class NahidaCollectHandler : IActionHandler
|
||||
{
|
||||
private DateTime lastETime = DateTime.MinValue;
|
||||
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null)
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null, object? config = null)
|
||||
{
|
||||
Logger.LogInformation("执行 {Nhd} 长按E转圈拾取", "纳西妲");
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.GameTask.AutoPathing.Model;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoPathing.Handler;
|
||||
|
||||
@@ -14,7 +15,7 @@ namespace BetterGenshinImpact.GameTask.AutoPathing.Handler;
|
||||
[Obsolete]
|
||||
public class NormalAttackHandler : IActionHandler
|
||||
{
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null)
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null, object? config = null)
|
||||
{
|
||||
Logger.LogInformation("执行 {Text}", "普通攻击");
|
||||
Simulation.SendInput.Mouse.LeftButtonClick();
|
||||
|
||||
@@ -1,42 +1,139 @@
|
||||
using System;
|
||||
using System;
|
||||
using BetterGenshinImpact.Core.Simulator;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.GameTask.AutoPathing.Model;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using Vanara.PInvoke;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoPathing.Handler;
|
||||
|
||||
/// <summary>
|
||||
/// 采集任务到达点位后执行拾取操作
|
||||
/// </summary>
|
||||
public class PickAroundHandler : IActionHandler
|
||||
public class PickAroundHandler() : IActionHandler
|
||||
{
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null)
|
||||
private CancellationToken _ct;
|
||||
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null, object? config = null)
|
||||
{
|
||||
var screen = CaptureToRectArea();
|
||||
var angle = 0;
|
||||
CameraRotateTask rotateTask = new(ct);
|
||||
this._ct = ct;
|
||||
Logger.LogInformation("执行 {Text}", "小范围内自动拾取");
|
||||
await rotateTask.WaitUntilRotatedTo(angle, 5);
|
||||
Simulation.SendInput.Keyboard.KeyDown(User32.VK.VK_W);
|
||||
var startTime = DateTime.UtcNow;
|
||||
while (!ct.IsCancellationRequested)
|
||||
|
||||
double speed = 1.1;
|
||||
int turns = 1;
|
||||
if (waypointForTrack is { ActionParams: not null })
|
||||
{
|
||||
angle = (5 + angle) % 360;
|
||||
rotateTask.RotateToApproach(angle, screen);
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_SPACE);
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_F);
|
||||
await Delay(100, ct);
|
||||
if (DateTime.UtcNow - startTime > TimeSpan.FromSeconds(5))
|
||||
{
|
||||
break;
|
||||
}
|
||||
turns = StringUtils.TryParseInt(waypointForTrack.ActionParams, 1);
|
||||
}
|
||||
|
||||
Simulation.SendInput.Keyboard.KeyUp(User32.VK.VK_W);
|
||||
// 无加成幼年为 1, 少年为 1.1, 成年为 1.2, 若有移速加成, 再乘以加成倍率.
|
||||
CircularMotionCalculator calculator = new CircularMotionCalculator(speed);
|
||||
double oldRadiusT = 0;
|
||||
double angle = 0;
|
||||
for (int i = 0; i < turns; i++)
|
||||
{
|
||||
(double edgeT, double radiusT, double endAngle) = calculator.GetCircleInfo(i);
|
||||
await MoveToNextStartPoint(oldRadiusT, radiusT, angle);
|
||||
await MoveCircle(edgeT, 6);
|
||||
oldRadiusT = radiusT;
|
||||
angle = endAngle;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task MoveCircle(double edgeT, int n)
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyDown(User32.VK.VK_A);
|
||||
await Delay(30, _ct);
|
||||
while (n-- > 0)
|
||||
{
|
||||
Simulation.SendInput.Mouse.MiddleButtonClick();
|
||||
await Delay((int)Math.Round(edgeT), _ct);
|
||||
}
|
||||
|
||||
Simulation.SendInput.Keyboard.KeyUp(User32.VK.VK_A);
|
||||
await Delay(200, _ct);
|
||||
}
|
||||
|
||||
public async Task MoveAfterTurn(User32.VK vk, int ms = 0)
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyPress(vk);
|
||||
await Delay(200, _ct);
|
||||
Simulation.SendInput.Mouse.MiddleButtonClick();
|
||||
await Delay(500, _ct);
|
||||
if (ms > 0)
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyDown(User32.VK.VK_W);
|
||||
await Delay(ms, _ct);
|
||||
Simulation.SendInput.Keyboard.KeyUp(User32.VK.VK_W);
|
||||
await Delay(200, _ct);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task MoveToNextStartPoint(double oldRadius, double newRadius, double angle)
|
||||
{
|
||||
double x = newRadius - oldRadius * Math.Cos(angle);
|
||||
double y = oldRadius * Math.Sin(angle);
|
||||
Simulation.SendInput.Mouse.MiddleButtonClick();
|
||||
await Delay(500, _ct);
|
||||
await MoveAfterTurn(User32.VK.VK_S, (int)Math.Round(y) + 200);
|
||||
await MoveAfterTurn(User32.VK.VK_A, (int)Math.Round(x));
|
||||
}
|
||||
}
|
||||
|
||||
public class CircularMotionCalculator
|
||||
{
|
||||
private const int Start = 600;
|
||||
private const int Interval = 400;
|
||||
private const double CircleT = 33000.0;
|
||||
private const double RadiusT = CircleT / (2 * Math.PI);
|
||||
|
||||
private double _speed;
|
||||
private double _viewResetT;
|
||||
private double _mixAngle;
|
||||
private double _mixX;
|
||||
private double _mixY;
|
||||
|
||||
public CircularMotionCalculator(double speed = 1.1)
|
||||
{
|
||||
Speed = speed;
|
||||
}
|
||||
|
||||
public double Speed
|
||||
{
|
||||
get => _speed;
|
||||
set
|
||||
{
|
||||
_speed = value;
|
||||
UpdateSpeed(value);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateSpeed(double speed)
|
||||
{
|
||||
_viewResetT = 350 * speed;
|
||||
_mixAngle = (_viewResetT / CircleT + 1.0 / 4) * 2 * Math.PI;
|
||||
(_mixX, _mixY) = GetArcPoint(_viewResetT / _mixAngle, _mixAngle);
|
||||
}
|
||||
|
||||
private (double, double) GetArcPoint(double radius, double angle)
|
||||
{
|
||||
return (radius * (1 - Math.Cos(angle)), radius * Math.Sin(angle));
|
||||
}
|
||||
|
||||
public (double, double, double) GetCircleInfo(int index)
|
||||
{
|
||||
double edgeT = Start + index * Interval;
|
||||
double angle = (edgeT / CircleT + 1.0 / 4) * Math.PI;
|
||||
var (restX, restY) = GetArcPoint(RadiusT, 2 * angle - _mixAngle);
|
||||
double x = _mixX - restX;
|
||||
double y = _mixY + restY;
|
||||
double smallRadiusT = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) / (2 * Math.Sin(angle));
|
||||
double endAngle = angle - _mixAngle + Math.Atan2(x, y) + Math.PI / 2;
|
||||
return (edgeT / Speed, smallRadiusT / Speed, endAngle);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.Core.Simulator;
|
||||
using BetterGenshinImpact.GameTask.AutoPathing.Model;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -14,7 +15,7 @@ namespace BetterGenshinImpact.GameTask.AutoPathing.Handler;
|
||||
/// </summary>
|
||||
public class UpDownGrabLeaf : IActionHandler
|
||||
{
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null)
|
||||
public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null, object? config = null)
|
||||
{
|
||||
await Delay(500, ct);
|
||||
Logger.LogInformation("开始上下晃动视角抓{Syy}", "四叶印");
|
||||
|
||||
@@ -28,6 +28,7 @@ public class WaypointForTrack : Waypoint
|
||||
Type = waypoint.Type;
|
||||
MoveMode = waypoint.MoveMode;
|
||||
Action = waypoint.Action;
|
||||
ActionParams = waypoint.ActionParams;
|
||||
GameX = waypoint.X;
|
||||
GameY = waypoint.Y;
|
||||
// 坐标系转换
|
||||
|
||||
@@ -24,24 +24,37 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.GameTask.AutoPathing.Suspend;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using Vanara.PInvoke;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
using static BetterGenshinImpact.GameTask.SystemControl;
|
||||
using ActionEnum = BetterGenshinImpact.GameTask.AutoPathing.Model.Enum.ActionEnum;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoPathing;
|
||||
|
||||
public class PathExecutor(CancellationToken ct)
|
||||
public class PathExecutor
|
||||
{
|
||||
private readonly CameraRotateTask _rotateTask = new(ct);
|
||||
private readonly TrapEscaper _trapEscaper = new(ct);
|
||||
private readonly CameraRotateTask _rotateTask;
|
||||
private readonly TrapEscaper _trapEscaper;
|
||||
private readonly BlessingOfTheWelkinMoonTask _blessingOfTheWelkinMoonTask = new();
|
||||
private AutoSkipTrigger? _autoSkipTrigger;
|
||||
|
||||
private PathingPartyConfig? _partyConfig;
|
||||
private CancellationToken ct;
|
||||
private PathExecutorSuspend pathExecutorSuspend;
|
||||
|
||||
public PathExecutor(CancellationToken ct)
|
||||
{
|
||||
_trapEscaper = new(ct);
|
||||
_rotateTask = new(ct);
|
||||
this.ct = ct;
|
||||
pathExecutorSuspend = new PathExecutorSuspend(this);
|
||||
}
|
||||
|
||||
public PathingPartyConfig PartyConfig
|
||||
{
|
||||
get => _partyConfig ?? new PathingPartyConfig();
|
||||
get => _partyConfig ?? PathingPartyConfig.BuildDefault();
|
||||
set => _partyConfig = value;
|
||||
}
|
||||
|
||||
@@ -54,20 +67,198 @@ public class PathExecutor(CancellationToken ct)
|
||||
// private readonly Dictionary<string, string> _actionAvatarIndexMap = new();
|
||||
|
||||
private DateTime _elementalSkillLastUseTime = DateTime.MinValue;
|
||||
private DateTime _useGadgetLastUseTime = DateTime.MinValue;
|
||||
|
||||
private const int RetryTimes = 2;
|
||||
private int _inTrap = 0;
|
||||
|
||||
|
||||
//记录当前相关点位数组
|
||||
public (int, List<WaypointForTrack>) CurWaypoints { get; set; }
|
||||
|
||||
//记录当前点位
|
||||
public (int, WaypointForTrack) CurWaypoint { get; set; }
|
||||
|
||||
//记录恢复点位数组
|
||||
private (int, List<WaypointForTrack>) RecordWaypoints { get; set; }
|
||||
|
||||
//记录恢复点位
|
||||
private (int, WaypointForTrack) RecordWaypoint { get; set; }
|
||||
|
||||
//跳过除走路径以外的操作
|
||||
private bool _skipOtherOperations = false;
|
||||
|
||||
|
||||
//当到达恢复点位
|
||||
public void TryCloseSkipOtherOperations()
|
||||
{
|
||||
// Logger.LogWarning("判断是否跳过路径追踪:" + (CurWaypoint.Item1 < RecordWaypoint.Item1));
|
||||
if (RecordWaypoints == CurWaypoints && CurWaypoint.Item1 < RecordWaypoint.Item1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_skipOtherOperations)
|
||||
{
|
||||
Logger.LogWarning("已到达上次点位,路径追踪功能恢复");
|
||||
}
|
||||
|
||||
_skipOtherOperations = false;
|
||||
}
|
||||
|
||||
//记录点位,方便后面恢复
|
||||
public void StartSkipOtherOperations()
|
||||
{
|
||||
Logger.LogWarning("记录恢复点位,路径追踪将到达上次点位之前将跳过走路之外的操作");
|
||||
_skipOtherOperations = true;
|
||||
RecordWaypoints = CurWaypoints;
|
||||
RecordWaypoint = CurWaypoint;
|
||||
}
|
||||
|
||||
public async Task Pathing(PathingTask task)
|
||||
{
|
||||
// SuspendableDictionary;
|
||||
const string sdKey = "PathExecutor";
|
||||
var sd = RunnerContext.Instance.SuspendableDictionary;
|
||||
sd.Remove(sdKey);
|
||||
|
||||
RunnerContext.Instance.SuspendableDictionary.TryAdd(sdKey, pathExecutorSuspend);
|
||||
|
||||
if (!task.Positions.Any())
|
||||
{
|
||||
Logger.LogWarning("没有路径点,寻路结束");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 切换队伍
|
||||
var pRaList = CaptureToRectArea().FindMulti(AutoFightAssets.Instance.PRa); // 判断是否联机
|
||||
if (!await SwitchPartyBefore(task))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 校验路径是否可以执行
|
||||
if (!await ValidateGameWithTask(task))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
InitializePathing(task);
|
||||
|
||||
// 转换、按传送点分割路径
|
||||
var waypointsList = ConvertWaypointsForTrack(task.Positions);
|
||||
|
||||
await Delay(100, ct);
|
||||
Navigation.WarmUp(); // 提前加载地图特征点
|
||||
|
||||
foreach (var waypoints in waypointsList)
|
||||
{
|
||||
CurWaypoints = (waypointsList.FindIndex(wps => wps == waypoints), waypoints);
|
||||
|
||||
|
||||
for (var i = 0; i < RetryTimes; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
await ResolveAnomalies(); // 异常场景处理
|
||||
foreach (var waypoint in waypoints)
|
||||
{
|
||||
CurWaypoint = (waypoints.FindIndex(wps => wps == waypoint), waypoint);
|
||||
TryCloseSkipOtherOperations();
|
||||
await RecoverWhenLowHp(waypoint); // 低血量恢复
|
||||
if (waypoint.Type == WaypointType.Teleport.Code)
|
||||
{
|
||||
await HandleTeleportWaypoint(waypoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
await BeforeMoveToTarget(waypoint);
|
||||
|
||||
// Path不用走得很近,Target需要接近,但都需要先移动到对应位置
|
||||
await MoveTo(waypoint);
|
||||
|
||||
if (waypoint.Type == WaypointType.Target.Code
|
||||
// 除了 fight mining 之外的 action 都需要接近
|
||||
|| (!string.IsNullOrEmpty(waypoint.Action)
|
||||
&& waypoint.Action != ActionEnum.NahidaCollect.Code
|
||||
&& waypoint.Action != ActionEnum.Fight.Code
|
||||
&& waypoint.Action != ActionEnum.CombatScript.Code
|
||||
&& waypoint.Action != ActionEnum.Mining.Code))
|
||||
{
|
||||
await MoveCloseTo(waypoint);
|
||||
}
|
||||
|
||||
//skipOtherOperations如果重试,则跳过相关操作
|
||||
if (!string.IsNullOrEmpty(waypoint.Action) && !_skipOtherOperations)
|
||||
{
|
||||
// 执行 action
|
||||
await AfterMoveToTarget(waypoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
catch (NormalEndException normalEndException)
|
||||
{
|
||||
Logger.LogInformation(normalEndException.Message);
|
||||
if (RunnerContext.Instance.IsContinuousRunGroup)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (TaskCanceledException e)
|
||||
{
|
||||
if (RunnerContext.Instance.IsContinuousRunGroup)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (RetryException retryException)
|
||||
{
|
||||
StartSkipOtherOperations();
|
||||
Logger.LogWarning(retryException.Message);
|
||||
}
|
||||
catch (RetryNoCountException retryException)
|
||||
{
|
||||
//特殊情况下,重试不消耗次数
|
||||
i--;
|
||||
StartSkipOtherOperations();
|
||||
Logger.LogWarning(retryException.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// 不管咋样,松开所有按键
|
||||
Simulation.SendInput.Keyboard.KeyUp(User32.VK.VK_W);
|
||||
Simulation.SendInput.Mouse.RightButtonUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> SwitchPartyBefore(PathingTask task)
|
||||
{
|
||||
var ra = CaptureToRectArea();
|
||||
|
||||
// 切换队伍前判断是否全队死亡 // 可能队伍切换失败导致的死亡
|
||||
if (Bv.ClickIfInReviveModal(ra))
|
||||
{
|
||||
await Bv.WaitForMainUi(ct); // 等待主界面加载完成
|
||||
Logger.LogInformation("复苏完成");
|
||||
await Delay(4000, ct);
|
||||
// 血量肯定不满,直接去七天神像回血
|
||||
await TpStatueOfTheSeven();
|
||||
}
|
||||
|
||||
var pRaList = ra.FindMulti(AutoFightAssets.Instance.PRa); // 判断是否联机
|
||||
if (pRaList.Count > 0)
|
||||
{
|
||||
Logger.LogInformation("处于联机状态下,不切换队伍");
|
||||
@@ -81,7 +272,7 @@ public class PathExecutor(CancellationToken ct)
|
||||
if (!await SwitchParty(partyName))
|
||||
{
|
||||
Logger.LogError("切换队伍失败,无法执行此路径!请检查路径追踪设置!");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(PartyConfig.PartyName))
|
||||
@@ -89,80 +280,12 @@ public class PathExecutor(CancellationToken ct)
|
||||
if (!await SwitchParty(PartyConfig.PartyName))
|
||||
{
|
||||
Logger.LogError("切换队伍失败,无法执行此路径!请检查配置组中的路径追踪配置!");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 校验路径是否可以执行
|
||||
if (!await ValidateGameWithTask(task))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
InitializePathing(task);
|
||||
|
||||
var waypoints = ConvertWaypointsForTrack(task.Positions);
|
||||
|
||||
await Delay(100, ct);
|
||||
Navigation.WarmUp(); // 提前加载地图特征点
|
||||
|
||||
for (var i = 0; i < RetryTimes; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
await ResolveAnomalies(); // 异常场景处理
|
||||
foreach (var waypoint in waypoints)
|
||||
{
|
||||
await RecoverWhenLowHp(); // 低血量恢复
|
||||
if (waypoint.Type == WaypointType.Teleport.Code)
|
||||
{
|
||||
await HandleTeleportWaypoint(waypoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
await BeforeMoveToTarget(waypoint);
|
||||
|
||||
// Path不用走得很近,Target需要接近,但都需要先移动到对应位置
|
||||
await MoveTo(waypoint);
|
||||
|
||||
if (waypoint.Type == WaypointType.Target.Code
|
||||
// 除了 fight mining 之外的 action 都需要接近
|
||||
|| (!string.IsNullOrEmpty(waypoint.Action)
|
||||
&& waypoint.Action != ActionEnum.NahidaCollect.Code
|
||||
&& waypoint.Action != ActionEnum.Fight.Code
|
||||
&& waypoint.Action != ActionEnum.CombatScript.Code
|
||||
&& waypoint.Action != ActionEnum.Mining.Code))
|
||||
{
|
||||
await MoveCloseTo(waypoint);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(waypoint.Action))
|
||||
{
|
||||
// 执行 action
|
||||
await AfterMoveToTarget(waypoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
catch (NormalEndException normalEndException)
|
||||
{
|
||||
Logger.LogInformation(normalEndException.Message);
|
||||
break;
|
||||
}
|
||||
catch (RetryException retryException)
|
||||
{
|
||||
Logger.LogWarning(retryException.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// 不管咋样,松开所有按键
|
||||
Simulation.SendInput.Keyboard.KeyUp(User32.VK.VK_W);
|
||||
Simulation.SendInput.Mouse.RightButtonUp();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void InitializePathing(PathingTask task)
|
||||
@@ -178,11 +301,13 @@ public class PathExecutor(CancellationToken ct)
|
||||
if (gameScreenSize.Width * 9 != gameScreenSize.Height * 16)
|
||||
{
|
||||
Logger.LogError("游戏窗口分辨率不是 16:9 !当前分辨率为 {Width}x{Height} , 非 16:9 分辨率的游戏无法正常使用路径追踪功能!", gameScreenSize.Width, gameScreenSize.Height);
|
||||
throw new Exception("游戏窗口分辨率不是 16:9 !无法使用路径追踪功能!");
|
||||
}
|
||||
|
||||
if (gameScreenSize.Width < 1920 || gameScreenSize.Height < 1080)
|
||||
{
|
||||
Logger.LogError("游戏窗口分辨率小于 1920x1080 !当前分辨率为 {Width}x{Height} , 小于 1920x1080 的分辨率的游戏路径追踪的效果非常差!", gameScreenSize.Width, gameScreenSize.Height);
|
||||
throw new Exception("游戏窗口分辨率小于 1920x1080 !无法使用路径追踪功能!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,7 +380,7 @@ public class PathExecutor(CancellationToken ct)
|
||||
}
|
||||
|
||||
// 校验角色是否存在
|
||||
if (task.HasAction("nahida_collect"))
|
||||
if (task.HasAction(ActionEnum.NahidaCollect.Code))
|
||||
{
|
||||
var avatar = _combatScenes.SelectAvatar("纳西妲");
|
||||
if (avatar == null)
|
||||
@@ -307,16 +432,97 @@ public class PathExecutor(CancellationToken ct)
|
||||
}
|
||||
}
|
||||
|
||||
private List<WaypointForTrack> ConvertWaypointsForTrack(List<Waypoint> positions)
|
||||
private List<List<WaypointForTrack>> ConvertWaypointsForTrack(List<Waypoint> positions)
|
||||
{
|
||||
// 把 X Y 转换为 MatX MatY
|
||||
return positions.Select(waypoint => new WaypointForTrack(waypoint)).ToList();
|
||||
var allList = positions.Select(waypoint => new WaypointForTrack(waypoint)).ToList();
|
||||
|
||||
// 按照WaypointType.Teleport.Code切割数组
|
||||
var result = new List<List<WaypointForTrack>>();
|
||||
var tempList = new List<WaypointForTrack>();
|
||||
foreach (var waypoint in allList)
|
||||
{
|
||||
if (waypoint.Type == WaypointType.Teleport.Code)
|
||||
{
|
||||
if (tempList.Count > 0)
|
||||
{
|
||||
result.Add(tempList);
|
||||
tempList = new List<WaypointForTrack>();
|
||||
}
|
||||
}
|
||||
|
||||
tempList.Add(waypoint);
|
||||
}
|
||||
|
||||
result.Add(tempList);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task RecoverWhenLowHp()
|
||||
/// <summary>
|
||||
/// 尝试队伍回血,如果单人回血,由于记录检查时是哪位残血,则当作行走位处理。
|
||||
/// </summary>
|
||||
private async Task<bool> TryPartyHealing()
|
||||
{
|
||||
foreach (var avatar in _combatScenes?.Avatars ?? [])
|
||||
{
|
||||
if (avatar.Name == "白术")
|
||||
{
|
||||
if (avatar.TrySwitch())
|
||||
{
|
||||
//1命白术能两次
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_E);
|
||||
await Delay(800, ct);
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_E);
|
||||
await Delay(800, ct);
|
||||
await SwitchAvatar(PartyConfig.MainAvatarIndex);
|
||||
await Delay(4000, ct);
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else if (avatar.Name == "希格雯")
|
||||
{
|
||||
if (avatar.TrySwitch())
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_E);
|
||||
await Delay(11000, ct);
|
||||
await SwitchAvatar(PartyConfig.MainAvatarIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else if (avatar.Name == "珊瑚宫心海")
|
||||
{
|
||||
if (avatar.TrySwitch())
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_E);
|
||||
await Delay(500, ct);
|
||||
//尝试Q全队回血
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_Q);
|
||||
//单人血只给行走位加血
|
||||
await SwitchAvatar(PartyConfig.MainAvatarIndex);
|
||||
await Delay(5000, ct);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private async Task RecoverWhenLowHp(WaypointForTrack waypoint)
|
||||
{
|
||||
if (PartyConfig.OnlyInTeleportRecover && waypoint.Type != WaypointType.Teleport.Code)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using var region = CaptureToRectArea();
|
||||
if (Bv.CurrentAvatarIsLowHp(region))
|
||||
if (Bv.CurrentAvatarIsLowHp(region) && !(await TryPartyHealing() && Bv.CurrentAvatarIsLowHp(region)))
|
||||
{
|
||||
Logger.LogInformation("当前角色血量过低,去须弥七天神像恢复");
|
||||
await TpStatueOfTheSeven();
|
||||
@@ -395,7 +601,16 @@ public class PathExecutor(CancellationToken ct)
|
||||
|
||||
if (distance > 500)
|
||||
{
|
||||
Logger.LogWarning("距离过远,跳过路径点");
|
||||
if (pathExecutorSuspend.CheckAndResetSuspendPoint())
|
||||
{
|
||||
throw new RetryNoCountException("可能暂停导致路径过远,重试一次此路线!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning("距离过远,跳过路径点");
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -475,17 +690,8 @@ public class PathExecutor(CancellationToken ct)
|
||||
}
|
||||
else if (waypoint.MoveMode != MoveModeEnum.Climb.Code) //否则自动短疾跑
|
||||
{
|
||||
if (distance > 20)
|
||||
{
|
||||
if (Math.Abs((fastModeColdTime - now).TotalMilliseconds) > 2500) //冷却时间2.5s,回复体力用
|
||||
{
|
||||
fastModeColdTime = now;
|
||||
Simulation.SendInput.Mouse.RightButtonClick();
|
||||
}
|
||||
}
|
||||
|
||||
// 使用 E 技能
|
||||
if (!string.IsNullOrEmpty(PartyConfig.GuardianAvatarIndex) && double.TryParse(PartyConfig.GuardianElementalSkillSecondInterval, out var s))
|
||||
if (distance > 10 && !string.IsNullOrEmpty(PartyConfig.GuardianAvatarIndex) && double.TryParse(PartyConfig.GuardianElementalSkillSecondInterval, out var s))
|
||||
{
|
||||
if (s < 1)
|
||||
{
|
||||
@@ -507,6 +713,26 @@ public class PathExecutor(CancellationToken ct)
|
||||
_elementalSkillLastUseTime = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
|
||||
// 自动疾跑
|
||||
if (distance > 20)
|
||||
{
|
||||
if (Math.Abs((fastModeColdTime - now).TotalMilliseconds) > 2500) //冷却时间2.5s,回复体力用
|
||||
{
|
||||
fastModeColdTime = now;
|
||||
Simulation.SendInput.Mouse.RightButtonClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 使用小道具
|
||||
if (PartyConfig.UseGadgetIntervalMs > 0)
|
||||
{
|
||||
if ((DateTime.UtcNow - _useGadgetLastUseTime).TotalMilliseconds > PartyConfig.UseGadgetIntervalMs)
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_Z);
|
||||
_useGadgetLastUseTime = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
|
||||
await Delay(100, ct);
|
||||
@@ -632,7 +858,8 @@ public class PathExecutor(CancellationToken ct)
|
||||
|| waypoint.Action == ActionEnum.CombatScript.Code)
|
||||
{
|
||||
var handler = ActionFactory.GetAfterHandler(waypoint.Action);
|
||||
await handler.RunAsync(ct, waypoint);
|
||||
//,PartyConfig
|
||||
await handler.RunAsync(ct, waypoint, PartyConfig);
|
||||
await Delay(1000, ct);
|
||||
}
|
||||
}
|
||||
@@ -681,7 +908,6 @@ public class PathExecutor(CancellationToken ct)
|
||||
* 处理各种异常场景
|
||||
* 需要保证耗时不能太高
|
||||
*/
|
||||
|
||||
private async Task ResolveAnomalies()
|
||||
{
|
||||
// 处理月卡
|
||||
@@ -704,7 +930,10 @@ public class PathExecutor(CancellationToken ct)
|
||||
|
||||
if (_autoSkipTrigger == null)
|
||||
{
|
||||
_autoSkipTrigger = new AutoSkipTrigger();
|
||||
_autoSkipTrigger = new AutoSkipTrigger(new AutoSkipConfig
|
||||
{
|
||||
ClickChatOption = "优先选择最后一个选项",
|
||||
});
|
||||
_autoSkipTrigger.Init();
|
||||
}
|
||||
|
||||
@@ -740,4 +969,4 @@ public class PathExecutor(CancellationToken ct)
|
||||
throw new NormalEndException("达成结束条件,结束路径追踪");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace BetterGenshinImpact.GameTask.AutoPathing.Suspend;
|
||||
|
||||
public interface ISuspendable
|
||||
{
|
||||
void Suspend(); // 暂停操作
|
||||
void Resume(); // 恢复操作
|
||||
bool IsSuspended { get; } // 是否处于暂停状态
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BetterGenshinImpact.GameTask.AutoPathing.Model;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoPathing.Suspend;
|
||||
|
||||
//暂停逻辑相关实现,这里主要用来记录,用来恢复相应操作
|
||||
public class PathExecutorSuspend(PathExecutor pathExecutor) : ISuspendable
|
||||
{
|
||||
private bool _isSuspended;
|
||||
|
||||
//记录当前相关点位数组
|
||||
private (int, List<WaypointForTrack>) _waypoints;
|
||||
|
||||
//记录当前点位
|
||||
private (int, WaypointForTrack) _waypoint;
|
||||
|
||||
public bool IsSuspended => _isSuspended;
|
||||
|
||||
public void Suspend()
|
||||
{
|
||||
_waypoints = pathExecutor.CurWaypoints;
|
||||
_waypoint = pathExecutor.CurWaypoint;
|
||||
_isSuspended = true;
|
||||
}
|
||||
|
||||
//路径过远时,检查路径追踪点位经过暂停(当前点位和后一个点位算经过暂停),并重置状态
|
||||
public bool CheckAndResetSuspendPoint()
|
||||
{
|
||||
if (_isSuspended)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pathExecutor.CurWaypoints == _waypoints && (pathExecutor.CurWaypoint == _waypoint || (pathExecutor.CurWaypoint.Item1 - 1) == _waypoint.Item1))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Resume()
|
||||
{
|
||||
_isSuspended = false;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_waypoints = default;
|
||||
_waypoint = default;
|
||||
}
|
||||
}
|
||||
@@ -26,9 +26,9 @@ public partial class AutoSkipConfig : ObservableObject
|
||||
[ObservableProperty]
|
||||
private bool _quicklySkipConversationsEnabled = true;
|
||||
|
||||
public int ChatOptionTextWidth { get; set; } = 280;
|
||||
|
||||
public int ExpeditionOptionTextWidth { get; set; } = 130;
|
||||
// public int ChatOptionTextWidth { get; set; } = 280;
|
||||
//
|
||||
// public int ExpeditionOptionTextWidth { get; set; } = 130;
|
||||
|
||||
/// <summary>
|
||||
/// 选择选项前的延迟(毫秒)
|
||||
|
||||
@@ -40,6 +40,8 @@ public partial class AutoSkipTrigger : ITaskTrigger
|
||||
public bool IsExclusive => false;
|
||||
|
||||
public bool IsBackgroundRunning { get; private set; }
|
||||
|
||||
public bool UseBackgroundOperation { get; private set; }
|
||||
|
||||
public bool IsUseInteractionKey { get; set; } = false;
|
||||
|
||||
@@ -63,12 +65,25 @@ public partial class AutoSkipTrigger : ITaskTrigger
|
||||
private List<string> _selectList = [];
|
||||
|
||||
private PostMessageSimulator? _postMessageSimulator;
|
||||
|
||||
private readonly bool _isCustomConfiguration;
|
||||
|
||||
public AutoSkipTrigger()
|
||||
{
|
||||
_autoSkipAssets = AutoSkipAssets.Instance;
|
||||
_config = TaskContext.Instance().Config.AutoSkipConfig;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用于内部的其他方法调用
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
public AutoSkipTrigger(AutoSkipConfig config)
|
||||
{
|
||||
_autoSkipAssets = AutoSkipAssets.Instance;
|
||||
_config = config;
|
||||
_isCustomConfiguration = true;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
@@ -77,6 +92,14 @@ public partial class AutoSkipTrigger : ITaskTrigger
|
||||
// IsUseInteractionKey = _config.SelectChatOptionType == SelectChatOptionTypes.UseInteractionKey;
|
||||
_postMessageSimulator = TaskContext.Instance().PostMessageSimulator;
|
||||
|
||||
if (!_isCustomConfiguration)
|
||||
{
|
||||
InitKeyword();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitKeyword()
|
||||
{
|
||||
try
|
||||
{
|
||||
var defaultPauseListJson = Global.ReadAllTextIfExist(@"User\AutoSkip\default_pause_options.json");
|
||||
@@ -138,6 +161,7 @@ public partial class AutoSkipTrigger : ITaskTrigger
|
||||
{
|
||||
return;
|
||||
}
|
||||
UseBackgroundOperation = IsBackgroundRunning && !SystemControl.IsGenshinImpactActive();
|
||||
|
||||
_prevExecute = DateTime.Now;
|
||||
|
||||
@@ -189,7 +213,7 @@ public partial class AutoSkipTrigger : ITaskTrigger
|
||||
|
||||
// 对话选项选择
|
||||
bool hasOption;
|
||||
if (IsBackgroundRunning || IsUseInteractionKey)
|
||||
if (UseBackgroundOperation || IsUseInteractionKey)
|
||||
{
|
||||
hasOption = ChatOptionChooseUseKey(content.CaptureRectArea);
|
||||
}
|
||||
@@ -232,7 +256,7 @@ public partial class AutoSkipTrigger : ITaskTrigger
|
||||
var rate = blackCount * 1d / (grayMat.Width * grayMat.Height);
|
||||
if (rate is >= 0.5 and < 0.98999)
|
||||
{
|
||||
if (IsBackgroundRunning)
|
||||
if (UseBackgroundOperation)
|
||||
{
|
||||
TaskContext.Instance().PostMessageSimulator?.LeftButtonClickBackground();
|
||||
}
|
||||
@@ -331,7 +355,7 @@ public partial class AutoSkipTrigger : ITaskTrigger
|
||||
using var skipRa = captureRegion.Find(_autoSkipAssets.HangoutSkipRo);
|
||||
if (skipRa.IsExist())
|
||||
{
|
||||
if (IsBackgroundRunning && !SystemControl.IsGenshinImpactActive())
|
||||
if (UseBackgroundOperation && !SystemControl.IsGenshinImpactActive())
|
||||
{
|
||||
skipRa.BackgroundClick();
|
||||
}
|
||||
@@ -612,7 +636,7 @@ public partial class AutoSkipTrigger : ITaskTrigger
|
||||
Thread.Sleep(_config.AfterChooseOptionSleepDelay);
|
||||
}
|
||||
|
||||
if (IsBackgroundRunning && !SystemControl.IsGenshinImpactActive())
|
||||
if (UseBackgroundOperation && !SystemControl.IsGenshinImpactActive())
|
||||
{
|
||||
region.BackgroundClick();
|
||||
}
|
||||
@@ -631,7 +655,7 @@ public partial class AutoSkipTrigger : ITaskTrigger
|
||||
Thread.Sleep(_config.AutoHangoutChooseOptionSleepDelay);
|
||||
}
|
||||
|
||||
if (IsBackgroundRunning && !SystemControl.IsGenshinImpactActive())
|
||||
if (UseBackgroundOperation && !SystemControl.IsGenshinImpactActive())
|
||||
{
|
||||
option.BackgroundClick();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public class GiWorldPosition
|
||||
/// 坐标描述
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
public string? Country { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 坐标 x,y,z 三个值,分别代表纵向、高度、横向,采用原神实际的坐标系
|
||||
|
||||
@@ -28,13 +28,12 @@ namespace BetterGenshinImpact.GameTask.AutoTrackPath;
|
||||
public class TpTask(CancellationToken ct)
|
||||
{
|
||||
private readonly QuickTeleportAssets _assets = QuickTeleportAssets.Instance;
|
||||
|
||||
private readonly Rect _captureRect = TaskContext.Instance().SystemInfo.ScaleMax1080PCaptureRect;
|
||||
|
||||
private readonly double _zoomOutMax1080PRatio = TaskContext.Instance().SystemInfo.ZoomOutMax1080PRatio;
|
||||
|
||||
public static double ReviveStatueOfTheSevenPointX = 2296.4;
|
||||
public static double ReviveStatueOfTheSevenPointY = -824.4;
|
||||
public static double currentZoomLevel = -1;
|
||||
|
||||
/// <summary>
|
||||
/// 通过大地图传送到指定坐标最近的传送点,然后移动到指定坐标
|
||||
@@ -42,35 +41,35 @@ public class TpTask(CancellationToken ct)
|
||||
/// <param name="tpX"></param>
|
||||
/// <param name="tpY"></param>
|
||||
/// <param name="force">强制以当前的tpX,tpY坐标进行自动传送</param>
|
||||
public async Task<(double, double)> TpOnce(double tpX, double tpY, bool force = false)
|
||||
/// <param name="initialZoomLevel">地图缩放等级</param>
|
||||
public async Task<(double, double)> TpOnce(double tpX, double tpY, bool force = false, int initialZoomLevel = 4)
|
||||
{
|
||||
var (x, y) = (tpX, tpY);
|
||||
|
||||
string? country = null;
|
||||
if (!force)
|
||||
{
|
||||
// 获取最近的传送点位置
|
||||
(x, y) = GetRecentlyTpPoint(tpX, tpY);
|
||||
(x, y, country) = GetRecentlyTpPoint(tpX, tpY);
|
||||
Logger.LogDebug("({TpX},{TpY}) 最近的传送点位置 ({X},{Y})", $"{tpX:F1}", $"{tpY:F1}", $"{x:F1}", $"{y:F1}");
|
||||
}
|
||||
|
||||
// M 打开地图识别当前位置,中心点为当前位置
|
||||
using var ra1 = CaptureToRectArea();
|
||||
if (!Bv.IsInBigMapUi(ra1))
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_M);
|
||||
await Delay(1000, ct);
|
||||
}
|
||||
|
||||
// 计算传送点位置离哪个地图切换后的中心点最近,切换到该地图
|
||||
await SwitchRecentlyCountryMap(x, y);
|
||||
await SwitchRecentlyCountryMap(x, y, country);
|
||||
|
||||
// 计算坐标后点击
|
||||
var bigMapInAllMapRect = GetBigMapRect();
|
||||
while (!IsPointInBigMapWindow(bigMapInAllMapRect, x, y)) // 左上角 350x400也属于禁止点击区域
|
||||
currentZoomLevel = GetBigMapZoomLevel(CaptureToRectArea());
|
||||
while (currentZoomLevel > 4.5)
|
||||
{
|
||||
await AdjustMapZoomLevel(true);
|
||||
currentZoomLevel--;
|
||||
Logger.LogInformation("当前缩放等级过大,调整为{currentZoomLevel}。", currentZoomLevel);
|
||||
}
|
||||
while (!IsPointInBigMapWindow(bigMapInAllMapRect, x, y) || currentZoomLevel > 2.5) // 左上角 350x400也属于禁止点击区域
|
||||
{
|
||||
Debug.WriteLine($"({x},{y}) 不在 {bigMapInAllMapRect} 内,继续移动");
|
||||
Logger.LogInformation("传送点不在当前大地图范围内,继续移动");
|
||||
await MoveMapTo(x, y);
|
||||
await MoveMapTo(x, y, maxMouseMove:400);
|
||||
await Delay(300, ct); // 等待地图移动完成
|
||||
bigMapInAllMapRect = GetBigMapRect();
|
||||
}
|
||||
@@ -118,7 +117,7 @@ public class TpTask(CancellationToken ct)
|
||||
|
||||
var (clickX, clickY) = ConvertToGameRegionPosition(bigMapInAllMapRect, x, y);
|
||||
// 屏蔽左上角350x400区域
|
||||
if (clickX < 250 * _zoomOutMax1080PRatio && clickY < 400 * _zoomOutMax1080PRatio)
|
||||
if (clickX < 350 * _zoomOutMax1080PRatio && clickY < 400 * _zoomOutMax1080PRatio)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -154,7 +153,22 @@ public class TpTask(CancellationToken ct)
|
||||
|
||||
public async Task<(double, double)> Tp(double tpX, double tpY, bool force = false)
|
||||
{
|
||||
// 重试3次
|
||||
// M 打开地图识别当前位置,中心点为当前位置
|
||||
var ra1 = CaptureToRectArea();
|
||||
if (!Bv.IsInBigMapUi(ra1))
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_M);
|
||||
await Delay(1000, ct);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
ra1 = CaptureToRectArea();
|
||||
if (!Bv.IsInBigMapUi(ra1))
|
||||
{
|
||||
await Delay(500, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
try
|
||||
@@ -183,85 +197,171 @@ public class TpTask(CancellationToken ct)
|
||||
/// 移动地图到指定传送点位置
|
||||
/// 可能会移动不对,所以可以重试此方法
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
public async Task MoveMapTo(double x, double y)
|
||||
/// <param name="x">目标x坐标</param>
|
||||
/// <param name="y">目标y坐标</param>
|
||||
/// <param name="tolerance">允许误差,默认200</param>
|
||||
/// <param name="maxIterations">最大尝试次数,默认30</param>
|
||||
/// <param name="maxMouseMove">单次移动最大距离,默认250</param>
|
||||
public async Task MoveMapTo(double x, double y, double tolerance = 200, int maxIterations = 30, int maxMouseMove = 250)
|
||||
{
|
||||
var bigMapCenterPoint = GetPositionFromBigMap();
|
||||
// 移动部分内容测试移动偏移
|
||||
// 获取当前地图中心点并计算到目标传送点的初始偏移
|
||||
// await AdjustMapZoomLevel(mapZoomLevel);
|
||||
var bigMapCenterPoint = GetPositionFromBigMap(); // 初始中心
|
||||
var newBigMapCenterPoint = bigMapCenterPoint;
|
||||
var (xOffset, yOffset) = (x - bigMapCenterPoint.X, y - bigMapCenterPoint.Y);
|
||||
|
||||
var diffMouseX = 200; // 每次移动的距离
|
||||
if (xOffset < 0)
|
||||
int moveMouseX = 100 * Math.Sign(xOffset);
|
||||
int moveMouseY = 100 * Math.Sign(yOffset);
|
||||
int moveSteps = 10;
|
||||
double totalMoveMouseX = Double.MaxValue;
|
||||
double totalMoveMouseY = Double.MaxValue;
|
||||
for (int iteration = 0; iteration < maxIterations; iteration++)
|
||||
{
|
||||
diffMouseX = -diffMouseX;
|
||||
}
|
||||
|
||||
var diffMouseY = 200; // 每次移动的距离
|
||||
if (yOffset < 0)
|
||||
{
|
||||
diffMouseY = -diffMouseY;
|
||||
}
|
||||
|
||||
// 先移动到屏幕中心附近随机点位置,避免地图移动无效
|
||||
await MouseMoveMapX(diffMouseX);
|
||||
await MouseMoveMapY(diffMouseY);
|
||||
var newBigMapCenterPoint = GetPositionFromBigMap();
|
||||
var diffMapX = Math.Abs(newBigMapCenterPoint.X - bigMapCenterPoint.X);
|
||||
var diffMapY = Math.Abs(newBigMapCenterPoint.Y - bigMapCenterPoint.Y);
|
||||
Debug.WriteLine($"每单位移动的地图距离:({diffMapX},{diffMapY})");
|
||||
|
||||
// 快速移动到目标传送点所在的区域
|
||||
if (diffMapX > 10 && diffMapY > 10)
|
||||
{
|
||||
// // 计算需要移动的次数
|
||||
var moveCount = (int)Math.Abs(xOffset / diffMapX); // 向下取整 本来还要加1的,但是已经移动了一次了
|
||||
Debug.WriteLine("X需要移动的次数:" + moveCount);
|
||||
for (var i = 0; i < moveCount; i++)
|
||||
// 尝试移动鼠标
|
||||
await MouseMoveMap(moveMouseX, moveMouseY, moveSteps);
|
||||
bigMapCenterPoint = newBigMapCenterPoint; // 保存上一次移动的数据
|
||||
try
|
||||
{
|
||||
await MouseMoveMapX(diffMouseX);
|
||||
newBigMapCenterPoint = GetPositionFromBigMap(); // 随循环更新的地图中心
|
||||
}
|
||||
|
||||
moveCount = (int)Math.Abs(yOffset / diffMapY); // 向下取整 本来还要加1的,但是已经移动了一次了
|
||||
Debug.WriteLine("Y需要移动的次数:" + moveCount);
|
||||
for (var i = 0; i < moveCount; i++)
|
||||
catch (Exception)
|
||||
{
|
||||
await MouseMoveMapY(diffMouseY);
|
||||
Logger.LogWarning("中心点识别失败,尝试预测移动的距离。");
|
||||
newBigMapCenterPoint = new Point2f(
|
||||
(float)(bigMapCenterPoint.X + xOffset * moveMouseX / totalMoveMouseX),
|
||||
(float)(bigMapCenterPoint.Y + yOffset * moveMouseY / totalMoveMouseY)
|
||||
); // 利用移动鼠标的距离获取新的中心
|
||||
}
|
||||
// 本次移动的距离
|
||||
double diffMapX = Math.Abs(newBigMapCenterPoint.X - bigMapCenterPoint.X);
|
||||
double diffMapY = Math.Abs(newBigMapCenterPoint.Y - bigMapCenterPoint.Y);
|
||||
|
||||
double moveDistance = Math.Sqrt(diffMapX * diffMapX + diffMapY * diffMapY);
|
||||
|
||||
if (moveDistance > 10) // 移动距离大于10认为本次移动成功
|
||||
{
|
||||
(xOffset, yOffset) = (x - newBigMapCenterPoint.X, y - newBigMapCenterPoint.Y); // 更新目标偏移量
|
||||
totalMoveMouseX = Math.Abs(moveMouseX * xOffset / diffMapX);
|
||||
totalMoveMouseY = Math.Abs(moveMouseY * yOffset / diffMapY);
|
||||
double mouseDistance = Math.Sqrt(totalMoveMouseX * totalMoveMouseX + totalMoveMouseY * totalMoveMouseY);
|
||||
// 调整地图缩放
|
||||
// mapZoomLevel<5 才显示传送锚点和秘境;
|
||||
// mapZoomLevel<3 是为了避免部分锚点过于接近导致选错锚点;
|
||||
// 风龙废墟无法避免,但是目前没有风龙废墟的脚本吧。:)
|
||||
// https://github.com/babalae/better-genshin-impact/issues/318
|
||||
if (mouseDistance < tolerance && currentZoomLevel < 2.5)
|
||||
{
|
||||
Logger.LogInformation($"移动 {iteration} 次鼠标后,已经接近目标点,不再进一步调整。");
|
||||
break;
|
||||
}
|
||||
while (mouseDistance > 5 * tolerance && currentZoomLevel < 4)
|
||||
{ // 缩小地图
|
||||
await AdjustMapZoomLevel(false);
|
||||
totalMoveMouseX *= (currentZoomLevel) / (currentZoomLevel + 1);
|
||||
totalMoveMouseY *= (currentZoomLevel) / (currentZoomLevel + 1);
|
||||
mouseDistance *= (currentZoomLevel) / (currentZoomLevel + 1);
|
||||
currentZoomLevel++;
|
||||
}
|
||||
while (mouseDistance < 2 * tolerance && currentZoomLevel > 2)
|
||||
{ // 放大地图
|
||||
await AdjustMapZoomLevel(true);
|
||||
totalMoveMouseX *= (currentZoomLevel) / (currentZoomLevel - 1);
|
||||
totalMoveMouseY *= (currentZoomLevel) / (currentZoomLevel - 1);
|
||||
mouseDistance *= (currentZoomLevel) / (currentZoomLevel - 1);
|
||||
currentZoomLevel--;
|
||||
}
|
||||
|
||||
// 单次移动最大距离为 maxMouseMove
|
||||
moveMouseX = (int)Math.Min(totalMoveMouseX, maxMouseMove * totalMoveMouseX / mouseDistance) * Math.Sign(xOffset);
|
||||
moveMouseY = (int)Math.Min(totalMoveMouseY, maxMouseMove * totalMoveMouseY / mouseDistance) * Math.Sign(yOffset);
|
||||
double moveMouseLength = Math.Sqrt(moveMouseX * moveMouseX + moveMouseY * moveMouseY);
|
||||
moveSteps = Math.Max((int)moveMouseLength / 10, 3); // 每次移动的步数最小为3,避免除0错误
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogDebug($"第 {iteration} 次移动鼠标失败,可能是点击了传送点或者其他交互对象。");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task MouseMoveMapX(int dx)
|
||||
|
||||
/// <summary>
|
||||
/// 调整地图缩放级别以加速移动
|
||||
/// </summary>
|
||||
/// <param name="zoomIn">是否放大地图</param>
|
||||
/// <param name="zoomLevel">缩放等级:1-6,整数,随着数字变大地图越小,细节越少。</param>
|
||||
public async Task AdjustMapZoomLevel(bool zoomIn)
|
||||
{
|
||||
var moveUnit = dx > 0 ? 20 : -20;
|
||||
GameCaptureRegion.GameRegionMove((rect, _) => (rect.Width / 2d + Random.Shared.Next(-rect.Width / 6, rect.Width / 6), rect.Height / 2d + Random.Shared.Next(-rect.Height / 6, rect.Height / 6)));
|
||||
Simulation.SendInput.Mouse.LeftButtonDown();
|
||||
await Delay(200, ct);
|
||||
for (var i = 0; i < dx / moveUnit; i++)
|
||||
if (zoomIn)
|
||||
{
|
||||
Simulation.SendInput.Mouse.MoveMouseBy(moveUnit, 0).Sleep(60); // 60 保证没有惯性
|
||||
GameCaptureRegion.GameRegionClick((rect, scale) => (50 * scale, 430 * scale));
|
||||
}
|
||||
else
|
||||
{
|
||||
GameCaptureRegion.GameRegionClick((rect, scale) => (50 * scale, 650 * scale));
|
||||
}
|
||||
|
||||
Simulation.SendInput.Mouse.LeftButtonUp();
|
||||
await Delay(200, ct);
|
||||
await Delay(50, ct);
|
||||
}
|
||||
|
||||
public async Task MouseMoveMapY(int dy)
|
||||
public async Task AdjustMapZoomLevel(int zoomLevel)
|
||||
{
|
||||
var moveUnit = dy > 0 ? 20 : -20;
|
||||
GameCaptureRegion.GameRegionMove((rect, _) => (rect.Width / 2d + Random.Shared.Next(-rect.Width / 6, rect.Width / 6), rect.Height / 2d + Random.Shared.Next(-rect.Height / 6, rect.Height / 6)));
|
||||
Simulation.SendInput.Mouse.LeftButtonDown();
|
||||
await Delay(200, ct);
|
||||
// 原神地图在小范围内移动是无效的,所以先随便移动一下,所以肯定少移动一次
|
||||
for (var i = 0; i < dy / moveUnit; i++)
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
Simulation.SendInput.Mouse.MoveMouseBy(0, moveUnit).Sleep(60);
|
||||
await AdjustMapZoomLevel(false);
|
||||
}
|
||||
|
||||
Simulation.SendInput.Mouse.LeftButtonUp();
|
||||
await Delay(200, ct);
|
||||
for (int i = 0; i < 6 - zoomLevel; i++)
|
||||
{
|
||||
await AdjustMapZoomLevel(true);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task MouseMoveMap(int pixelDeltaX, int pixelDeltaY, int steps = 10, int stepIntervalMilliseconds = 10)
|
||||
{
|
||||
// 确保不影响总移动距离
|
||||
int totalX = 0;
|
||||
int totalY = 0;
|
||||
|
||||
// 梯形缩放因子
|
||||
double scaleFactor = 0.75;
|
||||
|
||||
// 计算每一步的位移,从steps/2逐渐减小到0
|
||||
int[] stepX = new int[steps];
|
||||
int[] stepY = new int[steps];
|
||||
for (int i = 0; i < steps; i++)
|
||||
{
|
||||
double factor = ((double)(steps - Math.Max(i, steps / 2)) / (steps / 2)) / scaleFactor;
|
||||
stepX[i] = (int)(pixelDeltaX * factor / steps);
|
||||
stepY[i] = (int)(pixelDeltaY * factor / steps);
|
||||
totalX += stepX[i];
|
||||
totalY += stepY[i];
|
||||
}
|
||||
|
||||
// 均匀分配多余的部分到前半段
|
||||
int remainingX = (int)(pixelDeltaX - totalX);
|
||||
int remainingY = (int)(pixelDeltaY - totalY);
|
||||
for (int i = 0; i < steps / 2 + 1; i++)
|
||||
{
|
||||
stepX[i] += remainingX / (steps / 2 + 1) + ((remainingX % (steps / 2 + 1) > i) ? 0 : 1);
|
||||
stepY[i] += remainingY / (steps / 2 + 1) + ((remainingX % (steps / 2 + 1) > i) ? 0 : 1);
|
||||
}
|
||||
|
||||
// 随机起点以避免地图移动无效
|
||||
GameCaptureRegion.GameRegionMove((rect, _) =>
|
||||
(rect.Width / 2d + Random.Shared.Next(-rect.Width / 6, rect.Width / 6),
|
||||
rect.Height / 2d + Random.Shared.Next(-rect.Height / 6, rect.Height / 6)));
|
||||
|
||||
Simulation.SendInput.Mouse.LeftButtonDown();
|
||||
for (var i = 0; i < steps; i++)
|
||||
{
|
||||
Simulation.SendInput.Mouse.MoveMouseBy(stepX[i], stepY[i]);
|
||||
await Delay(stepIntervalMilliseconds, ct);
|
||||
}
|
||||
Simulation.SendInput.Mouse.LeftButtonUp();
|
||||
}
|
||||
|
||||
|
||||
public Point2f GetPositionFromBigMap()
|
||||
{
|
||||
return GetBigMapCenterPoint();
|
||||
@@ -342,12 +442,13 @@ public class TpTask(CancellationToken ct)
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <returns></returns>
|
||||
public (double x, double y) GetRecentlyTpPoint(double x, double y)
|
||||
public (double x, double y, string? country) GetRecentlyTpPoint(double x, double y)
|
||||
{
|
||||
double recentX = 0;
|
||||
double recentY = 0;
|
||||
string? country = "";
|
||||
var minDistance = double.MaxValue;
|
||||
foreach (var tpPosition in MapAssets.Instance.TpPositions)
|
||||
foreach (var tpPosition in MapLazyAssets.Instance.TpPositions)
|
||||
{
|
||||
var distance = Math.Sqrt(Math.Pow(tpPosition.X - x, 2) + Math.Pow(tpPosition.Y - y, 2));
|
||||
if (distance < minDistance)
|
||||
@@ -355,13 +456,15 @@ public class TpTask(CancellationToken ct)
|
||||
minDistance = distance;
|
||||
recentX = tpPosition.X;
|
||||
recentY = tpPosition.Y;
|
||||
country = tpPosition.Country;
|
||||
}
|
||||
}
|
||||
|
||||
return (recentX, recentY);
|
||||
// todo: 识别当前国家
|
||||
return (recentX, recentY, country);
|
||||
}
|
||||
|
||||
public async Task<bool> SwitchRecentlyCountryMap(double x, double y)
|
||||
public async Task<bool> SwitchRecentlyCountryMap(double x, double y, string? forceCountry = null)
|
||||
{
|
||||
// 可能是地下地图,切换到地上地图
|
||||
using var ra2 = CaptureToRectArea();
|
||||
@@ -387,8 +490,8 @@ public class TpTask(CancellationToken ct)
|
||||
}
|
||||
}
|
||||
|
||||
var minCountry = "当前位置";
|
||||
foreach (var (country, position) in MapAssets.Instance.CountryPositions)
|
||||
string minCountry = "当前位置";
|
||||
foreach (var (country, position) in MapLazyAssets.Instance.CountryPositions)
|
||||
{
|
||||
var distance = Math.Sqrt(Math.Pow(position[0] - x, 2) + Math.Pow(position[1] - y, 2));
|
||||
if (distance < minDistance)
|
||||
@@ -401,6 +504,11 @@ public class TpTask(CancellationToken ct)
|
||||
Logger.LogDebug("离目标传送点最近的区域是:{Country}", minCountry);
|
||||
if (minCountry != "当前位置")
|
||||
{
|
||||
if (forceCountry != null)
|
||||
{
|
||||
minCountry = forceCountry;
|
||||
}
|
||||
|
||||
GameCaptureRegion.GameRegionClick((rect, scale) => (rect.Width - 160 * scale, rect.Height - 60 * scale));
|
||||
await Delay(300, ct);
|
||||
var ra = CaptureToRectArea();
|
||||
@@ -418,6 +526,7 @@ public class TpTask(CancellationToken ct)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public async Task Tp(string name)
|
||||
{
|
||||
// 通过大地图传送到指定传送点
|
||||
@@ -525,4 +634,23 @@ public class TpTask(CancellationToken ct)
|
||||
|
||||
return hasMapChooseIcon;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 给定的映射关系可以表示成 (x, y) 对的形式,其中 x 是输入值,y 是输出值
|
||||
/// 1 - 1
|
||||
/// 0.8 - 2
|
||||
/// 0.6 - 3
|
||||
/// 0.4 - 4
|
||||
/// 0.2 - 5
|
||||
/// 0 - 6
|
||||
/// y=−5x+6
|
||||
/// </summary>
|
||||
/// <param name="region"></param>
|
||||
/// <returns></returns>
|
||||
private double GetBigMapZoomLevel(ImageRegion region)
|
||||
{
|
||||
var s = Bv.GetBigMapScale(region);
|
||||
// 1~6 的缩放等级
|
||||
return (-5 * s) + 6;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Recognition;
|
||||
using BetterGenshinImpact.GameTask.Model.Area;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.Common.BgiVision;
|
||||
|
||||
/// <summary>
|
||||
/// 一些基础图像识别操作
|
||||
/// </summary>
|
||||
public static partial class Bv
|
||||
{
|
||||
/// <summary>
|
||||
/// 等待图像被找到
|
||||
/// </summary>
|
||||
/// <param name="ro">识别对象</param>
|
||||
/// <param name="ct">任务取消令牌</param>
|
||||
/// <param name="retryTimes">重试次数</param>
|
||||
/// <param name="delayMs">重试间隔</param>
|
||||
/// <returns></returns>
|
||||
public static async Task<bool> WaitUntilFound(RecognitionObject ro, CancellationToken ct, int retryTimes = 5, int delayMs = 1000)
|
||||
{
|
||||
return await NewRetry.WaitForAction(() => TaskControl.CaptureToRectArea().Find(ro).IsExist(), ct, retryTimes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="ro"></param>
|
||||
/// <param name="ct"></param>
|
||||
/// <param name="retryTimes"></param>
|
||||
/// <param name="delayMs"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<bool> ClickUntilFound(RecognitionObject ro, CancellationToken ct, int retryTimes = 5, int delayMs = 1000)
|
||||
{
|
||||
return await NewRetry.WaitForAction(() =>
|
||||
{
|
||||
var region = TaskControl.CaptureToRectArea();
|
||||
var foundRa = region.Find(ro);
|
||||
if (foundRa.IsExist())
|
||||
{
|
||||
foundRa.Click();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}, ct, retryTimes);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否找到对应的识别对象
|
||||
/// </summary>
|
||||
/// <param name="region">图像区域</param>
|
||||
/// <param name="ro">识别目标</param>
|
||||
/// <returns></returns>
|
||||
public static bool Find(ImageRegion region, RecognitionObject ro)
|
||||
{
|
||||
return region.Find(ro).IsExist();
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,16 @@ public static partial class Bv
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在任意可以关闭的UI界面(识别关闭按钮)
|
||||
/// </summary>
|
||||
/// <param name="captureRa"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsInAnyClosableUi(ImageRegion captureRa)
|
||||
{
|
||||
return captureRa.Find(QuickTeleportAssets.Instance.MapCloseButtonRo).IsExist();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否在队伍选择界面
|
||||
/// </summary>
|
||||
@@ -101,6 +111,22 @@ public static partial class Bv
|
||||
return captureRa.Find(QuickTeleportAssets.Instance.MapUndergroundSwitchButtonRo).IsExist();
|
||||
}
|
||||
|
||||
public static double GetBigMapScale(ImageRegion region)
|
||||
{
|
||||
var scaleRa = region.Find(QuickTeleportAssets.Instance.MapScaleButtonRo);
|
||||
if (scaleRa.IsEmpty())
|
||||
{
|
||||
throw new Exception("当前未处于大地图界面,不能使用GetBigMapScale方法");
|
||||
}
|
||||
|
||||
// 452 ~ 627 间隔 35 和截图有关的,截图高24
|
||||
var start = QuickTeleportAssets.MapScaleButton1080StartY;
|
||||
var end = QuickTeleportAssets.MapScaleButton1080EndY;
|
||||
var cur = (scaleRa.Y + scaleRa.Height / 2.0) * TaskContext.Instance().SystemInfo.ZoomOutMax1080PRatio; // 转换到1080p坐标系,主要是小于1080p的情况
|
||||
|
||||
return (end * 1.0 - cur) / (end - start);
|
||||
}
|
||||
|
||||
public static MotionStatus GetMotionStatus(ImageRegion captureRa)
|
||||
{
|
||||
var spaceExist = captureRa.Find(ElementAssets.Instance.SpaceKey).IsExist();
|
||||
@@ -214,4 +240,4 @@ public enum MotionStatus
|
||||
Normal, // 正常
|
||||
Fly, // 飞行
|
||||
Climb, // 攀爬
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 15 KiB |
@@ -1,5 +1,6 @@
|
||||
using BetterGenshinImpact.Core.Recognition;
|
||||
using BetterGenshinImpact.GameTask.Model;
|
||||
using BetterGenshinImpact.Helpers.Extensions;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.Common.Element.Assets;
|
||||
@@ -28,6 +29,18 @@ public class ElementAssets : BaseAssets<ElementAssets>
|
||||
|
||||
public RecognitionObject CraftCondensedResin;
|
||||
|
||||
public RecognitionObject BagArtifactUnchecked;
|
||||
public RecognitionObject BagArtifactChecked;
|
||||
public RecognitionObject BtnArtifactSalvage;
|
||||
public RecognitionObject BtnArtifactSalvageConfirm;
|
||||
|
||||
public RecognitionObject BtnClaimEncounterPointsRewards;
|
||||
public RecognitionObject PrimogemRo;
|
||||
|
||||
public RecognitionObject EscMailReward;
|
||||
public RecognitionObject CollectRo;
|
||||
|
||||
|
||||
private ElementAssets()
|
||||
{
|
||||
// 按钮
|
||||
@@ -162,5 +175,78 @@ public class ElementAssets : BaseAssets<ElementAssets>
|
||||
RegionOfInterest = new Rect(CaptureRect.Width / 2, 0, CaptureRect.Width / 2, CaptureRect.Height / 3 * 2),
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
|
||||
// 分解圣遗物
|
||||
BagArtifactUnchecked = new RecognitionObject
|
||||
{
|
||||
Name = "BagArtifactUnchecked",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage(@"Common\Element", "bag_artifact_unchecked.png"),
|
||||
RegionOfInterest = CaptureRect.CutTop(0.1),
|
||||
Threshold = 0.87,
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
BagArtifactChecked = new RecognitionObject
|
||||
{
|
||||
Name = "BagArtifactChecked",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage(@"Common\Element", "bag_artifact_checked.png"),
|
||||
RegionOfInterest = CaptureRect.CutTop(0.1),
|
||||
Threshold = 0.8,
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
BtnArtifactSalvage = new RecognitionObject
|
||||
{
|
||||
Name = "BtnArtifactSalvage",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage(@"Common\Element", "btn_artifact_salvage.png"),
|
||||
RegionOfInterest = CaptureRect.CutBottom(0.1),
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
BtnArtifactSalvageConfirm = new RecognitionObject
|
||||
{
|
||||
Name = "BtnArtifactSalvageConfirm",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage(@"Common\Element", "btn_artifact_salvage_confirm.png"),
|
||||
RegionOfInterest = CaptureRect.CutBottom(0.1),
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
|
||||
// 历练点奖励
|
||||
BtnClaimEncounterPointsRewards = new RecognitionObject
|
||||
{
|
||||
Name = "BtnClaimEncounterPointsRewards",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage(@"Common\Element", "btn_claim_encounter_points_rewards.png"),
|
||||
RegionOfInterest = CaptureRect.CutRightBottom(0.3, 0.5),
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
|
||||
PrimogemRo = new RecognitionObject
|
||||
{
|
||||
Name = "Primogem",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage(@"Common\Element", "primogem.png"),
|
||||
RegionOfInterest = new Rect(0, CaptureRect.Height / 3, CaptureRect.Width, CaptureRect.Height / 3),
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
|
||||
// 邮件
|
||||
EscMailReward = new RecognitionObject
|
||||
{
|
||||
Name = "EscMailReward",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage(@"Common\Element", "esc_mail_reward.png"),
|
||||
RegionOfInterest = CaptureRect.CutLeftBottom(0.1, 0.5)
|
||||
}.InitTemplate();
|
||||
|
||||
CollectRo = new RecognitionObject
|
||||
{
|
||||
Name = "Collect",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage(@"Common\Element", "collect.png"),
|
||||
RegionOfInterest = new Rect(0, CaptureRect.Height - CaptureRect.Height / 3, CaptureRect.Width / 4, CaptureRect.Height / 3),
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"info": {
|
||||
"name": "璃月凯瑟琳",
|
||||
"type": "collect",
|
||||
"author": "½",
|
||||
"version": "1.0",
|
||||
"description": "",
|
||||
"bgiVersion": "0.35.1"
|
||||
},
|
||||
"positions": [
|
||||
{
|
||||
"id": 1,
|
||||
"x": 267.958984375,
|
||||
"y": -665.10888671875,
|
||||
"action": "",
|
||||
"move_mode": "walk",
|
||||
"type": "teleport"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"x": 258.3662109375,
|
||||
"y": -663.82177734375,
|
||||
"type": "path",
|
||||
"move_mode": "walk",
|
||||
"action": ""
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"x": 246.689453125,
|
||||
"y": -662.83740234375,
|
||||
"type": "path",
|
||||
"move_mode": "walk",
|
||||
"action": ""
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"x": 233.8564453125,
|
||||
"y": -661.95849609375,
|
||||
"type": "path",
|
||||
"move_mode": "walk",
|
||||
"action": ""
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"x": 219.0625,
|
||||
"y": -657.271484375,
|
||||
"type": "target",
|
||||
"move_mode": "walk",
|
||||
"action": ""
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"x": 203.84765625,
|
||||
"y": -659.7158203125,
|
||||
"type": "path",
|
||||
"move_mode": "walk",
|
||||
"action": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"info": {
|
||||
"name": "稻妻凯瑟琳",
|
||||
"type": "collect",
|
||||
"author": "½",
|
||||
"version": "1.0",
|
||||
"description": "",
|
||||
"bgiVersion": "0.35.1"
|
||||
},
|
||||
"positions": [
|
||||
{
|
||||
"id": 1,
|
||||
"action": "",
|
||||
"move_mode": "walk",
|
||||
"type": "teleport",
|
||||
"x": -4402.556640625,
|
||||
"y": -3053.041015625
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"x": -4408.984375,
|
||||
"y": -3068.2470703125,
|
||||
"type": "path",
|
||||
"move_mode": "walk",
|
||||
"action": ""
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"x": -4418.185546875,
|
||||
"y": -3086.4326171875,
|
||||
"type": "path",
|
||||
"move_mode": "walk",
|
||||
"action": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"info": {
|
||||
"name": "蒙德凯瑟琳",
|
||||
"type": "collect",
|
||||
"author": "½",
|
||||
"version": "1.0",
|
||||
"description": "",
|
||||
"bgiVersion": "0.35.1"
|
||||
},
|
||||
"positions": [
|
||||
{
|
||||
"id": 1,
|
||||
"x": -867.6884765625,
|
||||
"y": 2281.365966796875,
|
||||
"action": "",
|
||||
"move_mode": "walk",
|
||||
"type": "teleport"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"x": -882.1455078125,
|
||||
"y": 2262.399658203125,
|
||||
"action": "",
|
||||
"move_mode": "walk",
|
||||
"type": "path"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"x": -911.3125,
|
||||
"y": 2240.5625,
|
||||
"action": "",
|
||||
"move_mode": "walk",
|
||||
"type": "path"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"x": -913.5625,
|
||||
"y": 2233.5625,
|
||||
"action": "",
|
||||
"move_mode": "walk",
|
||||
"type": "path"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"info": {
|
||||
"name": "稻妻凯瑟琳-合成台",
|
||||
"type": "collect",
|
||||
"author": "XS",
|
||||
"version": "1.0",
|
||||
"description": "",
|
||||
"bgiVersion": "0.35.1"
|
||||
},
|
||||
"positions": [
|
||||
{
|
||||
"id": 1,
|
||||
"x": -4402.443359375,
|
||||
"y": -3053.1025390625,
|
||||
"action": "",
|
||||
"move_mode": "walk",
|
||||
"type": "teleport"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"x": -4402.888671875,
|
||||
"y": -3060.0810546875,
|
||||
"action": "",
|
||||
"move_mode": "walk",
|
||||
"type": "path"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"x": -4414.158203125,
|
||||
"y": -3076.2705078125,
|
||||
"action": "",
|
||||
"move_mode": "walk",
|
||||
"type": "path"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"x": -4420.93359375,
|
||||
"y": -3084.6572265625,
|
||||
"action": "",
|
||||
"move_mode": "walk",
|
||||
"type": "path"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"x": -4431.484375,
|
||||
"y": -3092.462890625,
|
||||
"action": "",
|
||||
"move_mode": "walk",
|
||||
"type": "path"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"x": -4432.345703125,
|
||||
"y": -3093.796875,
|
||||
"action": "",
|
||||
"move_mode": "walk",
|
||||
"type": "path"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"info": {
|
||||
"name": "蒙德合成台-凯瑟琳",
|
||||
"type": "collect",
|
||||
"author": "XS",
|
||||
"version": "1.0",
|
||||
"description": "",
|
||||
"bgiVersion": "0.35.1"
|
||||
},
|
||||
"positions": [
|
||||
{
|
||||
"id": 1,
|
||||
"action": "",
|
||||
"move_mode": "walk",
|
||||
"type": "teleport",
|
||||
"x": -867.7041015625,
|
||||
"y": 2281.378173828125
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"x": -874.3662109375,
|
||||
"y": 2274.179931640625,
|
||||
"type": "path",
|
||||
"move_mode": "walk",
|
||||
"action": ""
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"x": -886.1494140625,
|
||||
"y": 2263.282958984375,
|
||||
"type": "path",
|
||||
"move_mode": "walk",
|
||||
"action": ""
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"x": -888.1865234375,
|
||||
"y": 2265.906005859375,
|
||||
"type": "path",
|
||||
"move_mode": "walk",
|
||||
"action": ""
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"x": -887.142578125,
|
||||
"y": 2260.765625,
|
||||
"type": "path",
|
||||
"move_mode": "walk",
|
||||
"action": ""
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"x": -892.3271484375,
|
||||
"y": 2249.783203125,
|
||||
"type": "path",
|
||||
"move_mode": "walk",
|
||||
"action": ""
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"x": -909.357421875,
|
||||
"y": 2240.581298828125,
|
||||
"type": "path",
|
||||
"move_mode": "walk",
|
||||
"action": ""
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"x": -888.47,
|
||||
"y": 2267.35,
|
||||
"type": "path",
|
||||
"move_mode": "walk",
|
||||
"action": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -6,40 +6,17 @@ using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.Common.Element.Assets;
|
||||
|
||||
public class MapAssets : BaseAssets<MapAssets>
|
||||
{
|
||||
public Lazy<Mat> MainMap2048BlockMat { get; } = new(() => new Mat(@"E:\HuiTask\更好的原神\地图匹配\有用的素材\5.2\map_52_2048.png", ImreadModes.Grayscale));
|
||||
|
||||
public Lazy<Mat> MainMap256BlockMat { get; } = new(() => new Mat(Global.Absolute(@"Assets\Map\mainMap256Block.png"), ImreadModes.Grayscale));
|
||||
|
||||
// 2048 区块下,存在传送点的最大面积,识别结果比这个大的话,需要点击放大
|
||||
|
||||
// 传送点信息
|
||||
|
||||
public List<GiWorldPosition> TpPositions;
|
||||
|
||||
// 每个地区点击后处于的中心位置
|
||||
public readonly Dictionary<string, double[]> CountryPositions = new()
|
||||
{
|
||||
{ "蒙德", [-876, 2278] },
|
||||
{ "璃月", [270, -666] },
|
||||
{ "稻妻", [-4400, -3050] },
|
||||
{ "须弥", [2877, -374] },
|
||||
{ "枫丹", [4515, 3631] },
|
||||
{ "纳塔", [8973.5, -1879.1] },
|
||||
};
|
||||
|
||||
public Rect MimiMapRect { get; }
|
||||
|
||||
public MapAssets()
|
||||
{
|
||||
var json = File.ReadAllText(Global.Absolute(@"GameTask\AutoTrackPath\Assets\tp.json"));
|
||||
TpPositions = JsonSerializer.Deserialize<List<GiWorldPosition>>(json, ConfigService.JsonOptions) ?? throw new System.Exception("tp.json deserialize failed");
|
||||
|
||||
MimiMapRect = new Rect((int)Math.Round(62 * AssetScale), (int)Math.Round(19 * AssetScale), (int)Math.Round(212 * AssetScale), (int)Math.Round(212 * AssetScale));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.GameTask.AutoTrackPath.Model;
|
||||
using BetterGenshinImpact.Service;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using BetterGenshinImpact.Model;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.Common.Element.Assets;
|
||||
|
||||
public class MapLazyAssets : Singleton<MapLazyAssets>
|
||||
{
|
||||
|
||||
// 2048 区块下,存在传送点的最大面积,识别结果比这个大的话,需要点击放大
|
||||
|
||||
// 传送点信息
|
||||
|
||||
public List<GiWorldPosition> TpPositions;
|
||||
|
||||
// 每个地区点击后处于的中心位置
|
||||
public readonly Dictionary<string, double[]> CountryPositions = new()
|
||||
{
|
||||
{ "蒙德", [-876, 2278] },
|
||||
{ "璃月", [270, -666] },
|
||||
{ "稻妻", [-4400, -3050] },
|
||||
{ "须弥", [2877, -374] },
|
||||
{ "枫丹", [4515, 3631] },
|
||||
{ "纳塔", [8973.5, -1879.1] },
|
||||
};
|
||||
|
||||
public readonly Dictionary<string, GiWorldPosition> DomainPositionMap = new();
|
||||
public readonly List<String> DomainNameList = [];
|
||||
// 反方向行走的副本
|
||||
public readonly List<string> DomainBackwardList = ["无妄引咎密宫", "芬德尼尔之顶"];
|
||||
|
||||
public MapLazyAssets()
|
||||
{
|
||||
var json = File.ReadAllText(Global.Absolute(@"GameTask\AutoTrackPath\Assets\tp.json"));
|
||||
TpPositions = JsonSerializer.Deserialize<List<GiWorldPosition>>(json, ConfigService.JsonOptions) ?? throw new System.Exception("tp.json deserialize failed");
|
||||
|
||||
// 取出秘境 description=Domain
|
||||
foreach (var tp in TpPositions.Where(tp => (tp.Description == "材料本"|| tp.Description == "圣遗物本")))
|
||||
{
|
||||
DomainPositionMap[tp.Name] = tp;
|
||||
DomainNameList.Add(tp.Name);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception; // TODO: change this namespace to BetterGenshinImpact.GameTask.Common.Exception
|
||||
|
||||
public class RetryNoCountException : System.Exception
|
||||
{
|
||||
public RetryNoCountException() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public RetryNoCountException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
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;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.Common.Job;
|
||||
|
||||
/// <summary>
|
||||
/// 圣遗物自动分解
|
||||
/// </summary>
|
||||
public class ArtifactSalvageTask
|
||||
{
|
||||
private readonly ReturnMainUiTask _returnMainUiTask = new();
|
||||
|
||||
public async Task Start(int star, CancellationToken ct)
|
||||
{
|
||||
await _returnMainUiTask.Start(ct);
|
||||
|
||||
// B键打开背包
|
||||
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_B);
|
||||
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.Keyboard.KeyPress(User32.VK.VK_B);
|
||||
}
|
||||
|
||||
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 (ocr.Text.Contains("快速选择"))
|
||||
{
|
||||
ocr.Click();
|
||||
await Delay(500, ct);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 确认选择
|
||||
using var ra4 = CaptureToRectArea();
|
||||
var ocrList2 = ra4.FindMulti(RecognitionObject.Ocr(ra3.ToRect().CutLeft(0.35)));
|
||||
for (var i = 1; i <= star; i++)
|
||||
{
|
||||
foreach (var ocr in ocrList2)
|
||||
{
|
||||
if (ocr.Text.Contains(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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Recognition;
|
||||
using BetterGenshinImpact.GameTask.Common.Element.Assets;
|
||||
using BetterGenshinImpact.GameTask.Model.Area;
|
||||
using BetterGenshinImpact.Helpers.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Vanara.PInvoke;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.Common.Job;
|
||||
|
||||
/// <summary>
|
||||
/// 一键领取纪行
|
||||
/// </summary>
|
||||
public class ClaimBattlePassRewardsTask
|
||||
{
|
||||
private readonly ReturnMainUiTask _returnMainUiTask = new();
|
||||
|
||||
public async Task Start(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
await DoOnce(ct);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogDebug(e, "领取纪行奖励异常");
|
||||
Logger.LogError("领取纪行奖励异常: {Msg}", e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DoOnce(CancellationToken ct)
|
||||
{
|
||||
await _returnMainUiTask.Start(ct);
|
||||
|
||||
await Delay(200, ct);
|
||||
TaskContext.Instance().PostMessageSimulator.KeyPress(User32.VK.VK_F4); // F4 开纪行
|
||||
|
||||
// 领取战令1
|
||||
await Delay(500, ct);
|
||||
await ClaimAll(ct);
|
||||
|
||||
|
||||
// 领取点数
|
||||
await Delay(1000, ct);
|
||||
GameCaptureRegion.GameRegion1080PPosClick(960, 45); // 点中间
|
||||
await Delay(500, ct);
|
||||
await ClaimAll(ct);
|
||||
|
||||
// 领取战令2
|
||||
await Delay(2000, ct); // 等待升级动画
|
||||
// 还可能存在领取到原石的情况
|
||||
if (CaptureToRectArea().Find(ElementAssets.Instance.PrimogemRo).IsExist())
|
||||
{
|
||||
TaskContext.Instance().PostMessageSimulator.KeyPress(User32.VK.VK_ESCAPE);
|
||||
}
|
||||
GameCaptureRegion.GameRegion1080PPosClick(858, 45);
|
||||
await Delay(500, ct);
|
||||
await ClaimAll(ct);
|
||||
|
||||
// 关闭
|
||||
await _returnMainUiTask.Start(ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 一键领取
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> ClaimAll(CancellationToken ct)
|
||||
{
|
||||
using var ra = CaptureToRectArea();
|
||||
var ocrList = ra.FindMulti(RecognitionObject.Ocr(ra.ToRect().CutRightBottom(0.3, 0.18)));
|
||||
var wt = ocrList.FirstOrDefault(txt => txt.Text.Contains("一键"));
|
||||
if (wt != null)
|
||||
{
|
||||
wt.Click();
|
||||
Logger.LogInformation("纪行:{Text}", "一键领取");
|
||||
await Delay(500, ct);
|
||||
using var ra2 = CaptureToRectArea();
|
||||
if (ra2.Find(ElementAssets.Instance.PrimogemRo).IsExist())
|
||||
{
|
||||
TaskContext.Instance().PostMessageSimulator.KeyPress(User32.VK.VK_ESCAPE);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogInformation("纪行:{Text}", "无需领取");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Recognition;
|
||||
using BetterGenshinImpact.Core.Simulator;
|
||||
using BetterGenshinImpact.GameTask.Common.Element.Assets;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Vanara.PInvoke;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.Common.Job;
|
||||
|
||||
/// <summary>
|
||||
/// 领取长效历练点奖励
|
||||
/// </summary>
|
||||
public class ClaimEncounterPointsRewardsTask
|
||||
{
|
||||
private readonly ReturnMainUiTask _returnMainUiTask = new();
|
||||
|
||||
public async Task Start(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
await DoOnce(ct);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogDebug(e, "领取长效历练点奖励异常");
|
||||
Logger.LogError("领取长效历练点奖励异常: {Msg}", e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DoOnce(CancellationToken ct)
|
||||
{
|
||||
await _returnMainUiTask.Start(ct);
|
||||
|
||||
await Delay(200, ct);
|
||||
|
||||
TaskContext.Instance().PostMessageSimulator.KeyPress(User32.VK.VK_F1); // F1 开书
|
||||
|
||||
await Delay(1000, ct);
|
||||
|
||||
var assetScale = TaskContext.Instance().SystemInfo.AssetScale;
|
||||
|
||||
// 找委托按钮
|
||||
var f1Success = await NewRetry.WaitForAction(() =>
|
||||
{
|
||||
using var ra = CaptureToRectArea();
|
||||
|
||||
var ocrList = ra.FindMulti(RecognitionObject.Ocr(0, 0, 360 * assetScale, ra.Height));
|
||||
|
||||
var wt = ocrList.FirstOrDefault(txt => txt.Text.Contains("委托"));
|
||||
|
||||
if (wt != null)
|
||||
{
|
||||
wt.Click();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}, ct, 5);
|
||||
|
||||
if (!f1Success)
|
||||
{
|
||||
Logger.LogError("{F}未找到委托按钮,F1打开冒险之证失败", "历练点:");
|
||||
return;
|
||||
}
|
||||
|
||||
await Delay(1000, ct);
|
||||
|
||||
// 领取
|
||||
using var ra2 = CaptureToRectArea();
|
||||
var claimBtn = ra2.Find(ElementAssets.Instance.BtnClaimEncounterPointsRewards);
|
||||
if (claimBtn.IsExist())
|
||||
{
|
||||
claimBtn.Click();
|
||||
Logger.LogInformation("{F}领取长效历练点奖励", "历练点:");
|
||||
await Delay(1000, ct);
|
||||
// TODO 截图并通知
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogInformation("{F}未找到领取历练点奖励按钮", "历练点:");
|
||||
}
|
||||
|
||||
// 关闭
|
||||
await _returnMainUiTask.Start(ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Recognition;
|
||||
using BetterGenshinImpact.Core.Simulator;
|
||||
using BetterGenshinImpact.GameTask.Common.Element.Assets;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Vanara.PInvoke;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.Common.Job;
|
||||
|
||||
/// <summary>
|
||||
/// 领取邮件奖励
|
||||
/// </summary>
|
||||
public class ClaimMailRewardsTask
|
||||
{
|
||||
private readonly ReturnMainUiTask _returnMainUiTask = new();
|
||||
|
||||
public async Task Start(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
await DoOnce(ct);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogDebug(e, "领取邮件奖励异常");
|
||||
Logger.LogError("领取邮件奖励异常: {Msg}", e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DoOnce(CancellationToken ct)
|
||||
{
|
||||
await _returnMainUiTask.Start(ct);
|
||||
|
||||
await Delay(200, ct);
|
||||
|
||||
TaskContext.Instance().PostMessageSimulator.KeyPress(User32.VK.VK_ESCAPE); // ESC
|
||||
|
||||
await Delay(1300, ct);
|
||||
|
||||
var ra = CaptureToRectArea();
|
||||
var mailIcon = ra.Find(ElementAssets.Instance.EscMailReward);
|
||||
if (mailIcon.IsExist())
|
||||
{
|
||||
mailIcon.Click();
|
||||
await Delay(1000, ct);
|
||||
ra = CaptureToRectArea();
|
||||
var claimAll = ra.Find(ElementAssets.Instance.CollectRo);
|
||||
if (claimAll.IsExist())
|
||||
{
|
||||
claimAll.Click();
|
||||
Logger.LogInformation("邮件:{Text}", "全部领取");
|
||||
await Delay(200, ct);
|
||||
// TODO 截图
|
||||
|
||||
TaskContext.Instance().PostMessageSimulator.KeyPress(User32.VK.VK_ESCAPE); // ESC
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogInformation("邮件:{Text}", "没有邮件奖励");
|
||||
}
|
||||
|
||||
ra.Dispose();
|
||||
|
||||
// 关闭
|
||||
await _returnMainUiTask.Start(ct);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,9 @@ using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Simulator;
|
||||
using BetterGenshinImpact.GameTask.AutoPick.Assets;
|
||||
using BetterGenshinImpact.GameTask.Common.Element.Assets;
|
||||
using Vanara.PInvoke;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
|
||||
@@ -21,13 +24,19 @@ public class GoToAdventurersGuildTask
|
||||
|
||||
private readonly ChooseTalkOptionTask _chooseTalkOptionTask = new();
|
||||
|
||||
public async Task Start(string country, CancellationToken ct)
|
||||
public async Task Start(string country, CancellationToken ct, string? dailyRewardPartyName = null)
|
||||
{
|
||||
Logger.LogInformation("→ {Name} 开始", Name);
|
||||
for (int i = 0; i < _retryTimes; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 如果有好感队伍名称,先切换到好感队伍
|
||||
if (!string.IsNullOrEmpty(dailyRewardPartyName))
|
||||
{
|
||||
await new SwitchPartyTask().Start(dailyRewardPartyName, ct);
|
||||
}
|
||||
|
||||
await DoOnce(country, ct);
|
||||
break;
|
||||
}
|
||||
@@ -62,7 +71,9 @@ public class GoToAdventurersGuildTask
|
||||
Logger.LogInformation("▶ {Text}", "领取『每日委托』奖励!");
|
||||
await Delay(200, ct);
|
||||
await _chooseTalkOptionTask.SelectLastOptionUntilEnd(ct, null, 3); // 点几下
|
||||
await Bv.WaitUntilFound(ElementAssets.Instance.PaimonMenuRo, ct);
|
||||
await Delay(500, ct);
|
||||
TaskContext.Instance().PostMessageSimulator.KeyPress(User32.VK.VK_ESCAPE);
|
||||
await new ReturnMainUiTask().Start(ct);
|
||||
|
||||
// 结束后重新打开
|
||||
@@ -128,10 +139,20 @@ public class GoToAdventurersGuildTask
|
||||
|
||||
await Delay(600, ct);
|
||||
|
||||
using var ra = CaptureToRectArea();
|
||||
if (!Bv.IsInTalkUi(ra))
|
||||
const int retryTalkTimes = 3;
|
||||
for (int i = 0; i < retryTalkTimes; i++)
|
||||
{
|
||||
throw new Exception("未找到与凯瑟琳对话交互按钮");
|
||||
using var ra = CaptureToRectArea();
|
||||
if (!Bv.IsInTalkUi(ra))
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyPress(AutoPickAssets.Instance.PickVk);
|
||||
await Delay(500, ct);
|
||||
|
||||
if (i == retryTalkTimes - 1)
|
||||
{
|
||||
throw new Exception("与凯瑟琳对话失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,8 @@ public class GoToCraftingBenchTask
|
||||
try
|
||||
{
|
||||
await DoOnce(country, ct);
|
||||
// 合成完毕后领取奖励
|
||||
await new ClaimEncounterPointsRewardsTask().Start(ct);
|
||||
break;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Recognition.ONNX;
|
||||
using BetterGenshinImpact.Core.Simulator;
|
||||
using BetterGenshinImpact.GameTask.Model.Area;
|
||||
using BetterGenshinImpact.View.Drawable;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OpenCvSharp;
|
||||
using Vanara.PInvoke;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.Common.Job;
|
||||
|
||||
/// <summary>
|
||||
/// 扫描拾取任务
|
||||
/// 请在安全地区使用
|
||||
/// </summary>
|
||||
public class ScanPickTask
|
||||
{
|
||||
private readonly BgiYoloV8Predictor _predictor = BgiYoloV8PredictorFactory.GetPredictor(@"Assets\Model\World\bgi_world.onnx");
|
||||
private readonly double _dpi = TaskContext.Instance().DpiScale;
|
||||
private readonly RECT _realCaptureRect = TaskContext.Instance().SystemInfo.CaptureAreaRect;
|
||||
|
||||
|
||||
public async Task Start(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
await DoOnce(ct);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogDebug(e, "拾取周边物品异常");
|
||||
Logger.LogError("拾取周边物品异常: {Msg}", e.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
VisionContext.Instance().DrawContent.ClearAll();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DoOnce(CancellationToken ct)
|
||||
{
|
||||
await ResetCamera(ct);
|
||||
|
||||
for (int n = 0; n < 5; n++) // 最多跑5次
|
||||
{
|
||||
var hasDrops = false;
|
||||
|
||||
// 旋转视角
|
||||
for (var i = 0; i < 20; i++)
|
||||
{
|
||||
var ra = CaptureToRectArea();
|
||||
var resultDic = _predictor.Detect(ra);
|
||||
// 过滤出可拾取物品
|
||||
var pickItems = resultDic.Where(x => x.Key is "drops" or "ore")
|
||||
.SelectMany(x => x.Value).ToList();
|
||||
|
||||
|
||||
if (pickItems.Count > 0)
|
||||
{
|
||||
hasDrops = true;
|
||||
// 把鼠标位置和物品位置重合
|
||||
MoveCursorTo(pickItems.First(), ra);
|
||||
await Delay(100, ct);
|
||||
// 物体越小,距离越远
|
||||
await WalkForward(ct);
|
||||
break;
|
||||
}
|
||||
|
||||
Simulation.SendInput.Mouse.MoveMouseBy((int)(300 * _dpi), 0);
|
||||
await Delay(100, ct);
|
||||
}
|
||||
|
||||
if (!hasDrops)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static async Task WalkForward(CancellationToken ct)
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyDown(User32.VK.VK_W);
|
||||
await Delay(1000, ct);
|
||||
Simulation.SendInput.Keyboard.KeyUp(User32.VK.VK_W);
|
||||
}
|
||||
|
||||
private void MoveCursorTo(Rect item, ImageRegion ra)
|
||||
{
|
||||
var centerX = (item.Left + item.Right) / 2;
|
||||
var centerY = (item.Top + item.Bottom) / 2;
|
||||
var dx = centerX - ra.Width / 2;
|
||||
var dy = centerY - ra.Height / 2;
|
||||
var r = _realCaptureRect.Width * 1.0 / ra.Width; // 缩放比例
|
||||
Simulation.SendInput.Mouse.MoveMouseBy((int)(dx * r * _dpi), (int)(dy * r * _dpi));
|
||||
}
|
||||
|
||||
// 回正 并下移视角
|
||||
private async Task ResetCamera(CancellationToken ct)
|
||||
{
|
||||
// Simulation.SendInput.Keyboard.Mouse.MiddleButtonClick();
|
||||
// await Delay(500, ct);
|
||||
Simulation.SendInput.Keyboard.Mouse.MoveMouseBy(0, (int)(500 * _dpi));
|
||||
await Delay(100, ct);
|
||||
}
|
||||
}
|
||||