code cleanup

This commit is contained in:
qhy040404 2024-08-14 18:01:02 +08:00
parent 78ec9d31e8
commit c490d29aa1
No known key found for this signature in database
GPG Key ID: B1E14E493E9BB96C
180 changed files with 645 additions and 886 deletions

View File

@ -20,7 +20,6 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using Wpf.Ui; using Wpf.Ui;
namespace BetterGenshinImpact; namespace BetterGenshinImpact;

View File

@ -1,4 +1,5 @@
using BetterGenshinImpact.GameTask; using BetterGenshinImpact.GameTask;
using BetterGenshinImpact.GameTask.AutoCook;
using BetterGenshinImpact.GameTask.AutoDomain; using BetterGenshinImpact.GameTask.AutoDomain;
using BetterGenshinImpact.GameTask.AutoFight; using BetterGenshinImpact.GameTask.AutoFight;
using BetterGenshinImpact.GameTask.AutoFishing; using BetterGenshinImpact.GameTask.AutoFishing;
@ -13,7 +14,6 @@ using Fischless.GameCapture;
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using BetterGenshinImpact.GameTask.AutoCook;
namespace BetterGenshinImpact.Core.Config; namespace BetterGenshinImpact.Core.Config;

View File

@ -1,7 +1,6 @@
using BetterGenshinImpact.Core.Recorder; using BetterGenshinImpact.Core.Recorder;
using SharpDX.DirectInput; using SharpDX.DirectInput;
using System; using System;
using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -4,10 +4,8 @@ using Sdcb.PaddleInference;
using Sdcb.PaddleOCR; using Sdcb.PaddleOCR;
using Sdcb.PaddleOCR.Models; using Sdcb.PaddleOCR.Models;
using System; using System;
using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using BetterGenshinImpact.GameTask;
namespace BetterGenshinImpact.Core.Recognition.OCR; namespace BetterGenshinImpact.Core.Recognition.OCR;

View File

@ -1,16 +1,12 @@
using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.GameTask;
using Microsoft.ML.OnnxRuntime; using Microsoft.ML.OnnxRuntime;
using Microsoft.ML.OnnxRuntime.Tensors; using Microsoft.ML.OnnxRuntime.Tensors;
using OpenCvSharp; using OpenCvSharp;
using System; using System;
using System.Buffers; using System.Buffers;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;

View File

@ -1,5 +1,5 @@
using System; using OpenCvSharp;
using OpenCvSharp; using System;
namespace BetterGenshinImpact.Core.Recognition.OpenCv; namespace BetterGenshinImpact.Core.Recognition.OpenCv;

View File

@ -1,12 +1,12 @@
using BetterGenshinImpact.Core.Recognition.OpenCv.Model; using BetterGenshinImpact.Core.Recognition.OpenCv.Model;
using BetterGenshinImpact.GameTask.Common.Map;
using BetterGenshinImpact.Helpers; using BetterGenshinImpact.Helpers;
using OpenCvSharp; using OpenCvSharp;
using OpenCvSharp.Features2D;
using OpenCvSharp.XFeatures2D; using OpenCvSharp.XFeatures2D;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using BetterGenshinImpact.GameTask.Common.Map;
using OpenCvSharp.Features2D;
using System.Linq; using System.Linq;
namespace BetterGenshinImpact.Core.Recognition.OpenCv.FeatureMatch; namespace BetterGenshinImpact.Core.Recognition.OpenCv.FeatureMatch;
@ -415,7 +415,7 @@ public class FeatureMatcher
var matches = flnMatcher.KnnMatch(queryDescriptors, _trainDescriptors, k: 2); var matches = flnMatcher.KnnMatch(queryDescriptors, _trainDescriptors, k: 2);
// 应用比例测试来过滤匹配点 // 应用比例测试来过滤匹配点
List<DMatch> goodMatches = new List<DMatch>(); List<DMatch> goodMatches = [];
foreach (var match in matches) foreach (var match in matches)
{ {
if (match.Length == 2 && match[0].Distance < 0.75 * match[1].Distance) if (match.Length == 2 && match[0].Distance < 0.75 * match[1].Distance)

View File

@ -155,7 +155,7 @@ public class MatchTemplateHelper
/// <returns></returns> /// <returns></returns>
public static List<Rect> MatchMultiPicForOnePic(Mat srcMat, List<Mat> imgSubList, double threshold = 0.8) public static List<Rect> MatchMultiPicForOnePic(Mat srcMat, List<Mat> imgSubList, double threshold = 0.8)
{ {
List<Rect> list = new(); List<Rect> list = [];
foreach (var sub in imgSubList) foreach (var sub in imgSubList)
while (true) while (true)
{ {
@ -185,7 +185,7 @@ public class MatchTemplateHelper
/// <returns></returns> /// <returns></returns>
public static List<Rect> MatchOnePicForOnePic(Mat srcMat, Mat dstMat, Mat? maskMat = null, double threshold = 0.8) public static List<Rect> MatchOnePicForOnePic(Mat srcMat, Mat dstMat, Mat? maskMat = null, double threshold = 0.8)
{ {
List<Rect> list = new(); List<Rect> list = [];
while (true) while (true)
{ {
@ -217,7 +217,7 @@ public class MatchTemplateHelper
/// <returns></returns> /// <returns></returns>
public static List<Rect> MatchOnePicForOnePic(Mat srcMat, Mat dstMat, TemplateMatchModes matchMode, Mat? maskMat, double threshold, int maxCount = -1) public static List<Rect> MatchOnePicForOnePic(Mat srcMat, Mat dstMat, TemplateMatchModes matchMode, Mat? maskMat, double threshold, int maxCount = -1)
{ {
List<Rect> list = new(); List<Rect> list = [];
if (maxCount < 0) if (maxCount < 0)
{ {

View File

@ -1,5 +1,5 @@
using System.Collections.Generic; using OpenCvSharp;
using OpenCvSharp; using System.Collections.Generic;
namespace BetterGenshinImpact.Core.Recognition.OpenCv.Model; namespace BetterGenshinImpact.Core.Recognition.OpenCv.Model;
@ -9,7 +9,7 @@ namespace BetterGenshinImpact.Core.Recognition.OpenCv.Model;
/// </summary> /// </summary>
public class KeyPointFeatureBlock public class KeyPointFeatureBlock
{ {
public List<KeyPoint> KeyPointList { get; set; } = new(); public List<KeyPoint> KeyPointList { get; set; } = [];
private KeyPoint[]? keyPointArray; private KeyPoint[]? keyPointArray;
@ -25,7 +25,7 @@ public class KeyPointFeatureBlock
/// <summary> /// <summary>
/// 在完整 KeyPoint[] 中的下标 /// 在完整 KeyPoint[] 中的下标
/// </summary> /// </summary>
public List<int> KeyPointIndexList { get; set; } = new(); public List<int> KeyPointIndexList { get; set; } = [];
public Mat? Descriptor; public Mat? Descriptor;

View File

@ -123,26 +123,26 @@ public class RecognitionObject
/// <summary> /// <summary>
/// 部分文字识别结果不准确,进行替换。可选。 /// 部分文字识别结果不准确,进行替换。可选。
/// </summary> /// </summary>
public Dictionary<string, string[]> ReplaceDictionary { get; set; } = new(); public Dictionary<string, string[]> ReplaceDictionary { get; set; } = [];
/// <summary> /// <summary>
/// 包含匹配 /// 包含匹配
/// 多个值全匹配的情况下才算成功 /// 多个值全匹配的情况下才算成功
/// 复杂情况请用下面的正则匹配 /// 复杂情况请用下面的正则匹配
/// </summary> /// </summary>
public List<string> AllContainMatchText { get; set; } = new(); public List<string> AllContainMatchText { get; set; } = [];
/// <summary> /// <summary>
/// 包含匹配 /// 包含匹配
/// 一个值匹配就算成功 /// 一个值匹配就算成功
/// </summary> /// </summary>
public List<string> OneContainMatchText { get; set; } = new(); public List<string> OneContainMatchText { get; set; } = [];
/// <summary> /// <summary>
/// 正则匹配 /// 正则匹配
/// 多个值全匹配的情况下才算成功 /// 多个值全匹配的情况下才算成功
/// </summary> /// </summary>
public List<string> RegexMatchText { get; set; } = new(); public List<string> RegexMatchText { get; set; } = [];
#endregion OCR文字识别 #endregion OCR文字识别
} }

View File

@ -19,7 +19,7 @@ public class GlobalKeyMouseRecord : Singleton<GlobalKeyMouseRecord>
private KeyMouseRecorder? _recorder; private KeyMouseRecorder? _recorder;
private readonly Dictionary<Keys, bool> _keyDownState = new(); private readonly Dictionary<Keys, bool> _keyDownState = [];
private DirectInputMonitor? _directInputMonitor; private DirectInputMonitor? _directInputMonitor;
@ -147,7 +147,7 @@ public class GlobalKeyMouseRecord : Singleton<GlobalKeyMouseRecord>
return; return;
} }
if (_keyDownState.ContainsKey(e.KeyCode) && _keyDownState[e.KeyCode]) if (_keyDownState.TryGetValue(e.KeyCode, out bool state) && state)
{ {
// Debug.WriteLine($"KeyUp: {e.KeyCode}"); // Debug.WriteLine($"KeyUp: {e.KeyCode}");
_keyDownState[e.KeyCode] = false; _keyDownState[e.KeyCode] = false;

View File

@ -1,6 +1,10 @@
using BetterGenshinImpact.Core.Recorder.Model; using BetterGenshinImpact.Core.Recorder.Model;
using BetterGenshinImpact.Core.Simulator; using BetterGenshinImpact.Core.Simulator;
using BetterGenshinImpact.GameTask;
using BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.GameTask.Common.Map;
using BetterGenshinImpact.Helpers; using BetterGenshinImpact.Helpers;
using Microsoft.Extensions.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
@ -8,10 +12,6 @@ using System.Text.Json;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using BetterGenshinImpact.GameTask;
using BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.GameTask.Common.Map;
using Microsoft.Extensions.Logging;
using Vanara.PInvoke; using Vanara.PInvoke;
namespace BetterGenshinImpact.Core.Recorder; namespace BetterGenshinImpact.Core.Recorder;

View File

@ -1,14 +1,14 @@
using BetterGenshinImpact.Core.Recorder.Model; using BetterGenshinImpact.Core.Recorder.Model;
using BetterGenshinImpact.GameTask;
using BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.GameTask.Common.Map;
using Gma.System.MouseKeyHook; using Gma.System.MouseKeyHook;
using SharpDX.DirectInput;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Windows.Forms; using System.Windows.Forms;
using SharpDX.DirectInput;
using BetterGenshinImpact.GameTask;
using BetterGenshinImpact.GameTask.Common.Map;
using BetterGenshinImpact.GameTask.Common;
namespace BetterGenshinImpact.Core.Recorder; namespace BetterGenshinImpact.Core.Recorder;

View File

@ -1,9 +1,6 @@
using System; using BetterGenshinImpact.Core.Script.Dependence.Model;
using System.Diagnostics;
using BetterGenshinImpact.Core.Script.Dependence.Model;
using BetterGenshinImpact.GameTask; using BetterGenshinImpact.GameTask;
using Microsoft.ClearScript; using System;
using Microsoft.ClearScript.V8;
namespace BetterGenshinImpact.Core.Script.Dependence; namespace BetterGenshinImpact.Core.Script.Dependence;
@ -18,7 +15,7 @@ public class Dispatcher
var realtimeTimer = timer; var realtimeTimer = timer;
if (realtimeTimer == null) if (realtimeTimer == null)
{ {
throw new ArgumentNullException(nameof(RealtimeTimer), "实时任务对象不能为空"); throw new ArgumentNullException(nameof(realtimeTimer), "实时任务对象不能为空");
} }
if (string.IsNullOrEmpty(realtimeTimer.Name)) if (string.IsNullOrEmpty(realtimeTimer.Name))
{ {

View File

@ -1,5 +1,5 @@
using System.Threading.Tasks; using BetterGenshinImpact.GameTask.AutoTrackPath;
using BetterGenshinImpact.GameTask.AutoTrackPath; using System.Threading.Tasks;
namespace BetterGenshinImpact.Core.Script.Dependence; namespace BetterGenshinImpact.Core.Script.Dependence;

View File

@ -1,7 +1,7 @@
using System; using BetterGenshinImpact.Core.Script.Utils;
using System;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using BetterGenshinImpact.Core.Script.Utils;
namespace BetterGenshinImpact.Core.Script.Dependence; namespace BetterGenshinImpact.Core.Script.Dependence;

View File

@ -1,7 +1,6 @@
using BetterGenshinImpact.Core.Script.Dependence; using BetterGenshinImpact.Core.Script.Dependence;
using BetterGenshinImpact.Core.Script.Dependence.Model; using BetterGenshinImpact.Core.Script.Dependence.Model;
using Microsoft.ClearScript; using Microsoft.ClearScript;
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BetterGenshinImpact.Core.Script; namespace BetterGenshinImpact.Core.Script;

View File

@ -1,9 +1,9 @@
using CommunityToolkit.Mvvm.ComponentModel; using BetterGenshinImpact.Service;
using CommunityToolkit.Mvvm.ComponentModel;
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Text.Json; using System.Text.Json;
using BetterGenshinImpact.Service;
namespace BetterGenshinImpact.Core.Script.Group; namespace BetterGenshinImpact.Core.Script.Group;

View File

@ -1,9 +1,8 @@
using System; using BetterGenshinImpact.Service;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text.Json; using System.Text.Json;
using System.Windows.Documents;
using BetterGenshinImpact.Service;
namespace BetterGenshinImpact.Core.Script.Project; namespace BetterGenshinImpact.Core.Script.Project;

View File

@ -125,7 +125,7 @@ public class PostMessageSimulator
//User32.PostMessage(_hWnd, User32.WindowMessage.WM_ACTIVATE, 1, 0); //User32.PostMessage(_hWnd, User32.WindowMessage.WM_ACTIVATE, 1, 0);
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001); User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001);
User32.PostMessage(_hWnd, User32.WindowMessage.WM_CHAR, (nint)vk, 0x1e0001); User32.PostMessage(_hWnd, User32.WindowMessage.WM_CHAR, (nint)vk, 0x1e0001);
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001); User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, unchecked((nint)0xc01e0001));
return this; return this;
} }
@ -134,7 +134,7 @@ public class PostMessageSimulator
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001); User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001);
Thread.Sleep(ms); Thread.Sleep(ms);
User32.PostMessage(_hWnd, User32.WindowMessage.WM_CHAR, (nint)vk, 0x1e0001); User32.PostMessage(_hWnd, User32.WindowMessage.WM_CHAR, (nint)vk, 0x1e0001);
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001); User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, unchecked((nint)0xc01e0001));
return this; return this;
} }
@ -143,7 +143,7 @@ public class PostMessageSimulator
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001); User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001);
Thread.Sleep(1000); Thread.Sleep(1000);
User32.PostMessage(_hWnd, User32.WindowMessage.WM_CHAR, (nint)vk, 0x1e0001); User32.PostMessage(_hWnd, User32.WindowMessage.WM_CHAR, (nint)vk, 0x1e0001);
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001); User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, unchecked((nint)0xc01e0001));
return this; return this;
} }
@ -155,7 +155,7 @@ public class PostMessageSimulator
public PostMessageSimulator KeyUp(User32.VK vk) public PostMessageSimulator KeyUp(User32.VK vk)
{ {
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001); User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, unchecked((nint)0xc01e0001));
return this; return this;
} }
@ -164,7 +164,7 @@ public class PostMessageSimulator
User32.PostMessage(_hWnd, User32.WindowMessage.WM_ACTIVATE, 1, 0); User32.PostMessage(_hWnd, User32.WindowMessage.WM_ACTIVATE, 1, 0);
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001); User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001);
User32.PostMessage(_hWnd, User32.WindowMessage.WM_CHAR, (nint)vk, 0x1e0001); User32.PostMessage(_hWnd, User32.WindowMessage.WM_CHAR, (nint)vk, 0x1e0001);
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001); User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, unchecked((nint)0xc01e0001));
return this; return this;
} }
@ -178,7 +178,7 @@ public class PostMessageSimulator
public PostMessageSimulator KeyUpBackground(User32.VK vk) public PostMessageSimulator KeyUpBackground(User32.VK vk)
{ {
User32.PostMessage(_hWnd, User32.WindowMessage.WM_ACTIVATE, 1, 0); User32.PostMessage(_hWnd, User32.WindowMessage.WM_ACTIVATE, 1, 0);
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001); User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, unchecked((nint)0xc01e0001));
return this; return this;
} }

View File

@ -25,7 +25,6 @@ using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq;
using static BetterGenshinImpact.GameTask.Common.TaskControl; using static BetterGenshinImpact.GameTask.Common.TaskControl;
using static Vanara.PInvoke.User32; using static Vanara.PInvoke.User32;
@ -306,7 +305,7 @@ public class AutoDomainTask
private Task StartFight(CombatScenes combatScenes, List<CombatCommand> combatCommands) private Task StartFight(CombatScenes combatScenes, List<CombatCommand> combatCommands)
{ {
CancellationTokenSource cts = new CancellationTokenSource(); CancellationTokenSource cts = new();
_taskParam.Cts.Token.Register(cts.Cancel); _taskParam.Cts.Token.Register(cts.Cancel);
combatScenes.BeforeTask(cts); combatScenes.BeforeTask(cts);
// 战斗操作 // 战斗操作
@ -412,7 +411,7 @@ public class AutoDomainTask
/// </summary> /// </summary>
private Task FindPetrifiedTree() private Task FindPetrifiedTree()
{ {
CancellationTokenSource treeCts = new CancellationTokenSource(); CancellationTokenSource treeCts = new();
_taskParam.Cts.Token.Register(treeCts.Cancel); _taskParam.Cts.Token.Register(treeCts.Cancel);
// 中键回正视角 // 中键回正视角
Simulation.SendInput.Mouse.MiddleButtonClick(); Simulation.SendInput.Mouse.MiddleButtonClick();

View File

@ -1,7 +1,7 @@
using System.Collections.Generic; using BetterGenshinImpact.Core.Recognition;
using BetterGenshinImpact.Core.Recognition;
using BetterGenshinImpact.GameTask.Model; using BetterGenshinImpact.GameTask.Model;
using OpenCvSharp; using OpenCvSharp;
using System.Collections.Generic;
namespace BetterGenshinImpact.GameTask.AutoFight.Assets; namespace BetterGenshinImpact.GameTask.AutoFight.Assets;

View File

@ -1,9 +1,5 @@
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BetterGenshinImpact.GameTask.AutoFight; namespace BetterGenshinImpact.GameTask.AutoFight;

View File

@ -1,10 +1,5 @@
using BetterGenshinImpact.GameTask.Model; using BetterGenshinImpact.GameTask.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
namespace BetterGenshinImpact.GameTask.AutoFight; namespace BetterGenshinImpact.GameTask.AutoFight;

View File

@ -44,6 +44,6 @@ public class CombatAvatar
/// <summary> /// <summary>
/// 别名 /// 别名
/// </summary> /// </summary>
public List<string> Alias { get; set; } = new(); public List<string> Alias { get; set; } = [];
} }

View File

@ -27,12 +27,7 @@ public class DefaultAutoFightConfig
public static string AvatarAliasToStandardName(string alias) public static string AvatarAliasToStandardName(string alias)
{ {
var avatar = CombatAvatars.Find(x => x.Alias.Contains(alias)); var avatar = CombatAvatars.Find(x => x.Alias.Contains(alias)) ?? throw new Exception($"角色名称校验失败:{alias}");
if (avatar == null)
{
throw new Exception($"角色名称校验失败:{alias}");
}
return avatar.Name; return avatar.Name;
} }
} }

View File

@ -1,19 +1,16 @@
using System; using BetterGenshinImpact.Core.Recognition.OCR;
using System.Diagnostics;
using BetterGenshinImpact.Core.Recognition.OCR;
using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.Core.Recognition.OpenCv;
using BetterGenshinImpact.Core.Simulator; using BetterGenshinImpact.Core.Simulator;
using BetterGenshinImpact.GameTask.AutoFight.Config; using BetterGenshinImpact.GameTask.AutoFight.Config;
using BetterGenshinImpact.GameTask.Model.Area;
using BetterGenshinImpact.Helpers; using BetterGenshinImpact.Helpers;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using OpenCvSharp; using OpenCvSharp;
using System;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
using BetterGenshinImpact.GameTask.Model.Area;
using Vanara.PInvoke; using Vanara.PInvoke;
using static BetterGenshinImpact.GameTask.Common.TaskControl; using static BetterGenshinImpact.GameTask.Common.TaskControl;
using static Vanara.PInvoke.User32;
namespace BetterGenshinImpact.GameTask.AutoFight.Model; namespace BetterGenshinImpact.GameTask.AutoFight.Model;
@ -218,7 +215,7 @@ public class Avatar
if (contours.Length > 0) if (contours.Length > 0)
{ {
var boxes = contours.Select(Cv2.BoundingRect).Where(w => w.Width >= 20 * assetScale && w.Height >= 18 * assetScale).OrderByDescending(w => w.Width).ToList(); var boxes = contours.Select(Cv2.BoundingRect).Where(w => w.Width >= 20 * assetScale && w.Height >= 18 * assetScale).OrderByDescending(w => w.Width).ToList();
if (boxes.Any()) if (boxes.Count is not 0)
{ {
IndexRect = boxes.First(); IndexRect = boxes.First();
return false; return false;

View File

@ -1,9 +1,10 @@
using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Core.Recognition.OCR; using BetterGenshinImpact.Core.Recognition.OCR;
using BetterGenshinImpact.Core.Recognition.ONNX;
using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.Core.Recognition.OpenCv;
using BetterGenshinImpact.GameTask.AutoFight.Assets; using BetterGenshinImpact.GameTask.AutoFight.Assets;
using BetterGenshinImpact.GameTask.AutoFight.Config; using BetterGenshinImpact.GameTask.AutoFight.Config;
using BetterGenshinImpact.GameTask.Model; using BetterGenshinImpact.GameTask.Model.Area;
using BetterGenshinImpact.Helpers; using BetterGenshinImpact.Helpers;
using Compunet.YoloV8; using Compunet.YoloV8;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -18,8 +19,6 @@ using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using BetterGenshinImpact.Core.Recognition.ONNX;
using BetterGenshinImpact.GameTask.Model.Area;
using static BetterGenshinImpact.GameTask.Common.TaskControl; using static BetterGenshinImpact.GameTask.Common.TaskControl;
namespace BetterGenshinImpact.GameTask.AutoFight.Model; namespace BetterGenshinImpact.GameTask.AutoFight.Model;
@ -34,7 +33,7 @@ public class CombatScenes : IDisposable
/// </summary> /// </summary>
public Avatar[] Avatars { get; set; } = new Avatar[1]; public Avatar[] Avatars { get; set; } = new Avatar[1];
public Dictionary<string, Avatar> AvatarMap { get; set; } = new(); public Dictionary<string, Avatar> AvatarMap { get; set; } = [];
public int AvatarCount { get; set; } public int AvatarCount { get; set; }
@ -70,9 +69,9 @@ public class CombatScenes : IDisposable
if (!string.IsNullOrEmpty(pair.Item2)) if (!string.IsNullOrEmpty(pair.Item2))
{ {
var costumeName = pair.Item2; var costumeName = pair.Item2;
if (AutoFightAssets.Instance.AvatarCostumeMap.ContainsKey(costumeName)) if (AutoFightAssets.Instance.AvatarCostumeMap.TryGetValue(costumeName, out string? name))
{ {
costumeName = AutoFightAssets.Instance.AvatarCostumeMap[costumeName]; costumeName = name;
} }
displayNames[i] = $"{pair.Item1}({costumeName})"; displayNames[i] = $"{pair.Item1}({costumeName})";
@ -83,7 +82,7 @@ public class CombatScenes : IDisposable
} }
} }
Logger.LogInformation("识别到的队伍角色:{Text}", string.Join(",", displayNames)); Logger.LogInformation("识别到的队伍角色:{Text}", string.Join(",", displayNames));
Avatars = BuildAvatars(names.ToList()); Avatars = BuildAvatars([.. names]);
AvatarMap = Avatars.ToDictionary(x => x.Name); AvatarMap = Avatars.ToDictionary(x => x.Name);
} }
catch (Exception e) catch (Exception e)
@ -145,7 +144,7 @@ public class CombatScenes : IDisposable
private void InitializeTeamFromConfig(string teamNames) private void InitializeTeamFromConfig(string teamNames)
{ {
var names = teamNames.Split(new[] { "", "," }, StringSplitOptions.TrimEntries); var names = teamNames.Split(["", ","], StringSplitOptions.TrimEntries);
if (names.Length != 4) if (names.Length != 4)
{ {
throw new Exception($"强制指定队伍角色数量不正确必须是4个当前{names.Length}个"); throw new Exception($"强制指定队伍角色数量不正确必须是4个当前{names.Length}个");
@ -159,7 +158,7 @@ public class CombatScenes : IDisposable
Logger.LogInformation("强制指定队伍角色:{Text}", string.Join(",", names)); Logger.LogInformation("强制指定队伍角色:{Text}", string.Join(",", names));
TaskContext.Instance().Config.AutoFightConfig.TeamNames = string.Join(",", names); TaskContext.Instance().Config.AutoFightConfig.TeamNames = string.Join(",", names);
Avatars = BuildAvatars(names.ToList()); Avatars = BuildAvatars([.. names]);
AvatarMap = Avatars.ToDictionary(x => x.Name); AvatarMap = Avatars.ToDictionary(x => x.Name);
} }
@ -232,8 +231,8 @@ public class CombatScenes : IDisposable
[Obsolete] [Obsolete]
private void ParseTeamOcrResult(PaddleOcrResult result, ImageRegion rectArea) private void ParseTeamOcrResult(PaddleOcrResult result, ImageRegion rectArea)
{ {
List<string> names = new(); List<string> names = [];
List<Rect> nameRects = new(); List<Rect> nameRects = [];
foreach (var item in result.Regions) foreach (var item in result.Regions)
{ {
var name = StringUtils.ExtractChinese(item.Text); var name = StringUtils.ExtractChinese(item.Text);

View File

@ -1,18 +1,18 @@
using System; using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.GameTask.AutoFight.Model;
using BetterGenshinImpact.GameTask.AutoFight.Script;
using BetterGenshinImpact.GameTask.Model.Enum;
using BetterGenshinImpact.Model;
using BetterGenshinImpact.Service;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text.Json; using System.Text.Json;
using BetterGenshinImpact.GameTask.AutoFight.Model;
using BetterGenshinImpact.Model;
using System.Threading.Tasks;
using System.Threading; using System.Threading;
using BetterGenshinImpact.Core.Config; using System.Threading.Tasks;
using static BetterGenshinImpact.GameTask.Common.TaskControl; using static BetterGenshinImpact.GameTask.Common.TaskControl;
using BetterGenshinImpact.GameTask.AutoFight.Script;
using BetterGenshinImpact.GameTask.Model.Enum;
using BetterGenshinImpact.Service;
using Microsoft.Extensions.Logging;
namespace BetterGenshinImpact.GameTask.AutoFight; namespace BetterGenshinImpact.GameTask.AutoFight;
@ -193,7 +193,7 @@ public class OneKeyFightTask : Singleton<OneKeyFightTask>
var avatarMacros = JsonSerializer.Deserialize<List<AvatarMacro>>(json, ConfigService.JsonOptions); var avatarMacros = JsonSerializer.Deserialize<List<AvatarMacro>>(json, ConfigService.JsonOptions);
if (avatarMacros == null) if (avatarMacros == null)
{ {
return new Dictionary<string, List<CombatCommand>>(); return [];
} }
var result = new Dictionary<string, List<CombatCommand>>(); var result = new Dictionary<string, List<CombatCommand>>();
foreach (var avatarMacro in avatarMacros) foreach (var avatarMacro in avatarMacros)

View File

@ -2,7 +2,6 @@
using BetterGenshinImpact.Helpers; using BetterGenshinImpact.Helpers;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Input;
using TimeSpan = System.TimeSpan; using TimeSpan = System.TimeSpan;
namespace BetterGenshinImpact.GameTask.AutoFight.Script; namespace BetterGenshinImpact.GameTask.AutoFight.Script;

View File

@ -1,7 +1,7 @@
using System; using BetterGenshinImpact.GameTask.AutoFight.Model;
using BetterGenshinImpact.GameTask.AutoFight.Model;
using System.Collections.Generic;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using static BetterGenshinImpact.GameTask.Common.TaskControl; using static BetterGenshinImpact.GameTask.Common.TaskControl;
namespace BetterGenshinImpact.GameTask.AutoFight.Script; namespace BetterGenshinImpact.GameTask.AutoFight.Script;

View File

@ -50,7 +50,7 @@ public class CombatScriptParser
public static CombatScript Parse(string path) public static CombatScript Parse(string path)
{ {
var script = File.ReadAllText(path); var script = File.ReadAllText(path);
var lines = script.Split(new[] { "\r\n", "\r", "\n", ";" }, StringSplitOptions.RemoveEmptyEntries); var lines = script.Split(["\r\n", "\r", "\n", ";"], StringSplitOptions.RemoveEmptyEntries);
var result = new List<string>(); var result = new List<string>();
foreach (var line in lines) foreach (var line in lines)
{ {
@ -58,7 +58,7 @@ public class CombatScriptParser
.Replace("", "(") .Replace("", "(")
.Replace(")", ")") .Replace(")", ")")
.Replace("", ","); .Replace("", ",");
if (l.StartsWith("//") || l.StartsWith("#") || string.IsNullOrEmpty(l)) if (l.StartsWith("//") || l.StartsWith('#') || string.IsNullOrEmpty(l))
{ {
continue; continue;
} }
@ -74,8 +74,8 @@ public class CombatScriptParser
public static CombatScript Parse(List<string> lines) public static CombatScript Parse(List<string> lines)
{ {
List<CombatCommand> combatCommands = new(); List<CombatCommand> combatCommands = [];
HashSet<string> combatAvatarNames = new(); HashSet<string> combatAvatarNames = [];
foreach (var line in lines) foreach (var line in lines)
{ {
var oneLineCombatCommands = ParseLine(line, combatAvatarNames); var oneLineCombatCommands = ParseLine(line, combatAvatarNames);
@ -120,7 +120,7 @@ public class CombatScriptParser
continue; continue;
} }
if (command.Contains("(") && !command.Contains(")")) if (command.Contains('(') && !command.Contains(')'))
{ {
var j = i + 1; var j = i + 1;
// 括号被逗号分隔,需要合并 // 括号被逗号分隔,需要合并
@ -133,7 +133,7 @@ public class CombatScriptParser
throw new Exception("战斗脚本格式错误,指令括号无法配对"); throw new Exception("战斗脚本格式错误,指令括号无法配对");
} }
if (command.Contains(")")) if (command.Contains(')'))
{ {
i = j; i = j;
break; break;
@ -142,7 +142,7 @@ public class CombatScriptParser
j++; j++;
} }
if (!(command.Contains("(") && command.Contains(")"))) if (!(command.Contains('(') && command.Contains(')')))
{ {
Logger.LogError("战斗脚本格式错误,指令 {Cmd} 括号不完整", command); Logger.LogError("战斗脚本格式错误,指令 {Cmd} 括号不完整", command);
throw new Exception("战斗脚本格式错误,指令括号不完整"); throw new Exception("战斗脚本格式错误,指令括号不完整");

View File

@ -1,36 +1,36 @@
using System; using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using static BetterGenshinImpact.GameTask.Common.TaskControl; using static BetterGenshinImpact.GameTask.Common.TaskControl;
namespace BetterGenshinImpact.GameTask.AutoFight.Script; namespace BetterGenshinImpact.GameTask.AutoFight.Script;
public class Method public class Method
{ {
public static readonly Method Skill = new(new() { "skill", "e" }); public static readonly Method Skill = new(["skill", "e"]);
public static readonly Method Burst = new(new() { "burst", "q" }); public static readonly Method Burst = new(["burst", "q"]);
public static readonly Method Attack = new(new() { "attack", "普攻", "普通攻击" }); public static readonly Method Attack = new(["attack", "普攻", "普通攻击"]);
public static readonly Method Charge = new(new() { "charge", "重击" }); public static readonly Method Charge = new(["charge", "重击"]);
public static readonly Method Wait = new(new() { "wait", "after", "等待" }); public static readonly Method Wait = new(["wait", "after", "等待"]);
public static readonly Method Walk = new(new() { "walk", "行走" }); public static readonly Method Walk = new(["walk", "行走"]);
public static readonly Method W = new(new() { "w" }); public static readonly Method W = new(["w"]);
public static readonly Method A = new(new() { "a" }); public static readonly Method A = new(["a"]);
public static readonly Method S = new(new() { "s" }); public static readonly Method S = new(["s"]);
public static readonly Method D = new(new() { "d" }); public static readonly Method D = new(["d"]);
public static readonly Method Aim = new(new() { "aim", "r", "瞄准" }); public static readonly Method Aim = new(["aim", "r", "瞄准"]);
public static readonly Method Dash = new(new() { "dash", "冲刺" }); public static readonly Method Dash = new(["dash", "冲刺"]);
public static readonly Method Jump = new(new() { "jump", "j", "跳跃" }); public static readonly Method Jump = new(["jump", "j", "跳跃"]);
// 宏 // 宏
public static readonly Method MouseDown = new(new() { "mousedown" }); public static readonly Method MouseDown = new(["mousedown"]);
public static readonly Method MouseUp = new(new() { "mouseup" }); public static readonly Method MouseUp = new(["mouseup"]);
public static readonly Method Click = new(new() { "click" }); public static readonly Method Click = new(["click"]);
public static readonly Method MoveBy = new(new() { "moveby" }); public static readonly Method MoveBy = new(["moveby"]);
public static readonly Method KeyDown = new(new() { "keydown" }); public static readonly Method KeyDown = new(["keydown"]);
public static readonly Method KeyUp = new(new() { "keyup" }); public static readonly Method KeyUp = new(["keyup"]);
public static readonly Method KeyPress = new(new() { "keypress" }); public static readonly Method KeyPress = new(["keypress"]);
public static IEnumerable<Method> Values public static IEnumerable<Method> Values
{ {

View File

@ -1,6 +1,5 @@
using OpenCvSharp; using CommunityToolkit.Mvvm.ComponentModel;
using System; using System;
using CommunityToolkit.Mvvm.ComponentModel;
namespace BetterGenshinImpact.GameTask.AutoFishing; namespace BetterGenshinImpact.GameTask.AutoFishing;

View File

@ -2,18 +2,16 @@
using BetterGenshinImpact.Core.Recognition; using BetterGenshinImpact.Core.Recognition;
using BetterGenshinImpact.Core.Recognition.OCR; using BetterGenshinImpact.Core.Recognition.OCR;
using BetterGenshinImpact.Core.Recognition.ONNX; using BetterGenshinImpact.Core.Recognition.ONNX;
using BetterGenshinImpact.Core.Recognition.OpenCv;
using BetterGenshinImpact.Core.Simulator; using BetterGenshinImpact.Core.Simulator;
using BetterGenshinImpact.GameTask.AutoFishing.Assets; using BetterGenshinImpact.GameTask.AutoFishing.Assets;
using BetterGenshinImpact.GameTask.AutoFishing.Model; using BetterGenshinImpact.GameTask.AutoFishing.Model;
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
using BetterGenshinImpact.GameTask.Common; using BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.GameTask.Common.BgiVision;
using BetterGenshinImpact.GameTask.Model.Area;
using BetterGenshinImpact.Helpers; using BetterGenshinImpact.Helpers;
using BetterGenshinImpact.Helpers.Extensions; using BetterGenshinImpact.Helpers.Extensions;
using BetterGenshinImpact.Model;
using BetterGenshinImpact.View.Drawable; using BetterGenshinImpact.View.Drawable;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using Compunet.YoloV8; using Compunet.YoloV8;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using OpenCvSharp; using OpenCvSharp;
@ -23,8 +21,6 @@ using System.Diagnostics;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using BetterGenshinImpact.GameTask.Common.BgiVision;
using BetterGenshinImpact.GameTask.Model.Area;
using static Vanara.PInvoke.User32; using static Vanara.PInvoke.User32;
using Color = System.Drawing.Color; using Color = System.Drawing.Color;
using Pen = System.Drawing.Pen; using Pen = System.Drawing.Pen;

View File

@ -1,6 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Xml.Linq;
namespace BetterGenshinImpact.GameTask.AutoFishing.Model; namespace BetterGenshinImpact.GameTask.AutoFishing.Model;

View File

@ -44,7 +44,7 @@ public class FishType
public static readonly FishType MaintenanceMekPlatinumCollection = new("maintenance mek- platinum collection", "flashing maintenance mek bait", "维护机关·白金典藏型"); public static readonly FishType MaintenanceMekPlatinumCollection = new("maintenance mek- platinum collection", "flashing maintenance mek bait", "维护机关·白金典藏型");
public static readonly FishType MaintenanceMekSituationController = new("maintenance mek- situation controller", "flashing maintenance mek bait", "维护机关·态势控制者"); public static readonly FishType MaintenanceMekSituationController = new("maintenance mek- situation controller", "flashing maintenance mek bait", "维护机关·态势控制者");
public static readonly FishType MaintenanceMekWaterBodyCleaner = new("maintenance mek- water body cleaner", "flashing maintenance mek bait", "维护机关·水域清理者"); public static readonly FishType MaintenanceMekWaterBodyCleaner = new("maintenance mek- water body cleaner", "flashing maintenance mek bait", "维护机关·水域清理者");
public static readonly FishType MaintenanceMekWaterGoldLeader = new ("maintenance mek- gold leader", "flashing maintenance mek bait", "维护机关·澄金领队型"); public static readonly FishType MaintenanceMekWaterGoldLeader = new("maintenance mek- gold leader", "flashing maintenance mek bait", "维护机关·澄金领队型");
public static IEnumerable<FishType> Values public static IEnumerable<FishType> Values

View File

@ -1,10 +1,9 @@
using System; using BetterGenshinImpact.Core.Recognition.OpenCv;
using System.Collections.Generic;
using System.Linq;
using BetterGenshinImpact.Core.Recognition.OpenCv;
using Compunet.YoloV8.Data; using Compunet.YoloV8.Data;
using OpenCvSharp; using OpenCvSharp;
using static OpenCvSharp.Cv2; using System;
using System.Collections.Generic;
using System.Linq;
namespace BetterGenshinImpact.GameTask.AutoFishing.Model; namespace BetterGenshinImpact.GameTask.AutoFishing.Model;
@ -23,7 +22,7 @@ public class Fishpond
/// <summary> /// <summary>
/// 鱼池中的鱼 /// 鱼池中的鱼
/// </summary> /// </summary>
public List<OneFish> Fishes { get; set; } = new(); public List<OneFish> Fishes { get; set; } = [];
public Fishpond(DetectionResult result) public Fishpond(DetectionResult result)
{ {
@ -45,7 +44,7 @@ public class Fishpond
} }
// 可信度最高的鱼放在最前面 // 可信度最高的鱼放在最前面
Fishes = Fishes.OrderByDescending(fish => fish.Confidence).ToList(); Fishes = [.. Fishes.OrderByDescending(fish => fish.Confidence)];
FishpondRect = CalculateFishpondRect(); FishpondRect = CalculateFishpondRect();
} }
@ -98,7 +97,7 @@ public class Fishpond
/// <returns></returns> /// <returns></returns>
public List<OneFish> FilterByBaitName(string baitName) public List<OneFish> FilterByBaitName(string baitName)
{ {
return Fishes.Where(fish => fish.FishType.BaitName == baitName).OrderByDescending(fish => fish.Confidence).ToList(); return [.. Fishes.Where(fish => fish.FishType.BaitName == baitName).OrderByDescending(fish => fish.Confidence)];
} }
public OneFish? FilterByBaitNameAndRecently(string baitName, Rect prevTargetFishRect) public OneFish? FilterByBaitNameAndRecently(string baitName, Rect prevTargetFishRect)
@ -132,10 +131,10 @@ public class Fishpond
/// <returns></returns> /// <returns></returns>
public string MostMatchBait() public string MostMatchBait()
{ {
Dictionary<string, int> dict = new(); Dictionary<string, int> dict = [];
foreach (var fish in Fishes) foreach (var fish in Fishes)
{ {
if (dict.ContainsKey(fish.FishType.BaitName)) if (dict.TryGetValue(fish.FishType.BaitName, out _))
{ {
dict[fish.FishType.BaitName]++; dict[fish.FishType.BaitName]++;
} }

View File

@ -1,20 +1,14 @@
using System; namespace BetterGenshinImpact.GameTask.AutoFishing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BetterGenshinImpact.GameTask.AutoFishing;
public record RodInput public record RodInput
{ {
public double rod_x1; public double rod_x1;
public double rod_x2; public double rod_x2;
public double rod_y1; public double rod_y1;
public double rod_y2; public double rod_y2;
public double fish_x1; public double fish_x1;
public double fish_x2; public double fish_x2;
public double fish_y1; public double fish_y1;
public double fish_y2; public double fish_y2;
public int fish_label; public int fish_label;
} }

View File

@ -1,6 +1,6 @@
using System; using OpenCvSharp;
using System;
using System.Linq; using System.Linq;
using OpenCvSharp;
namespace BetterGenshinImpact.GameTask.AutoFishing; namespace BetterGenshinImpact.GameTask.AutoFishing;
@ -11,10 +11,10 @@ public class RodNet
{ {
const double alpha = 1734.34 / 2.5; const double alpha = 1734.34 / 2.5;
static readonly double[] dz = { 0.561117562965, 0.637026851288, 0.705579317577, static readonly double[] dz = [ 0.561117562965, 0.637026851288, 0.705579317577,
1.062734463845, 0.949307580751, 1.015620474332, 1.062734463845, 0.949307580751, 1.015620474332,
1.797904203405, 1.513476738412, 1.013873007495, 1.797904203405, 1.513476738412, 1.013873007495,
1.159949954831, 1.353650974146, 1.302893195071 }; 1.159949954831, 1.353650974146, 1.302893195071 ];
static readonly double[,] theta = { static readonly double[,] theta = {
{-0.262674397633, 0.317025388945, -0.457150765450, 0.174522158281, {-0.262674397633, 0.317025388945, -0.457150765450, 0.174522158281,
@ -31,10 +31,10 @@ public class RodNet
-1.285988918494} -1.285988918494}
}; };
static readonly double[] B = { 1.241950004386, 3.051113640564, -3.848898190087 }; static readonly double[] B = [1.241950004386, 3.051113640564, -3.848898190087];
static readonly double[] offset = { 0.4, 0.2, 0.4, 0, 0.3, 0.3, static readonly double[] offset = [ 0.4, 0.2, 0.4, 0, 0.3, 0.3,
0.3, 0.15, 0.5, 0.5, 0.5, 0.5 }; 0.3, 0.15, 0.5, 0.5, 0.5, 0.5 ];
static void F(double[] dst, double[] x, double[] y) static void F(double[] dst, double[] x, double[] y)
{ {
@ -124,9 +124,7 @@ public class RodNet
if (a < b) if (a < b)
{ {
double temp = a; (b, a) = (a, b);
a = b;
b = temp;
} }
v0 = (288 - (input.rod_y1 + input.rod_y2) / 2) / alpha; v0 = (288 - (input.rod_y1 + input.rod_y2) / 2) / alpha;
@ -135,8 +133,8 @@ public class RodNet
v = (288 - (input.fish_y1 + input.fish_y2) / 2) / alpha; v = (288 - (input.fish_y1 + input.fish_y2) / 2) / alpha;
double[] y0z0t = new double[3]; double[] y0z0t = new double[3];
double[] abv0 = { a, b, v0 }; double[] abv0 = [a, b, v0];
double[] init = { 30, 15, 1 }; double[] init = [30, 15, 1];
bool solveSuccess = NewtonRaphson(F, DfInv, y0z0t, abv0, init, 3, 1000, 1e-6); bool solveSuccess = NewtonRaphson(F, DfInv, y0z0t, abv0, init, 3, 1000, 1e-6);
@ -166,7 +164,7 @@ public class RodNet
public static int GetRodState(Rect rod, Rect fish, int fishTypeIndex) public static int GetRodState(Rect rod, Rect fish, int fishTypeIndex)
{ {
RodInput input = new RodInput RodInput input = new()
{ {
rod_x1 = rod.Left, rod_x1 = rod.Left,
rod_x2 = rod.Right, rod_x2 = rod.Right,

View File

@ -1,11 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using OpenCvSharp;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenCvSharp;
using BetterGenshinImpact.Core.Config;
namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation; namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation;
@ -19,12 +15,12 @@ public partial class AutoGeniusInvokationConfig : ObservableObject
[ObservableProperty] private int _sleepDelay = 0; [ObservableProperty] private int _sleepDelay = 0;
public List<Rect> DefaultCharacterCardRects { get; set; } = new() public List<Rect> DefaultCharacterCardRects { get; set; } =
{ [
new(667, 632, 165, 282), new(667, 632, 165, 282),
new(877, 632, 165, 282), new(877, 632, 165, 282),
new(1088, 632, 165, 282) new(1088, 632, 165, 282)
}; ];
/// <summary> /// <summary>

View File

@ -1,10 +1,4 @@
using System; using BetterGenshinImpact.Helpers.Extensions;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model;
using static Vanara.PInvoke.Gdi32;
namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation; namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation;
@ -16,6 +10,6 @@ public class AutoGeniusInvokationTask
// 读取策略信息 // 读取策略信息
var duel = ScriptParser.Parse(taskParam.StrategyContent); var duel = ScriptParser.Parse(taskParam.StrategyContent);
SystemControl.ActivateWindow(); SystemControl.ActivateWindow();
duel.RunAsync(taskParam); duel.RunAsync(taskParam).SafeForget();
} }
} }

View File

@ -1,8 +1,8 @@
using System; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model;
using System.Collections.Generic;
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model;
using BetterGenshinImpact.GameTask.Common; using BetterGenshinImpact.GameTask.Common;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Config; namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Config;
@ -47,12 +47,12 @@ public class SkillsItem
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public List<string> SkillTag { get; set; } = new(); public List<string> SkillTag { get; set; } = [];
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public List<CostItem> Cost { get; set; } = new(); public List<CostItem> Cost { get; set; } = [];
} }
[Serializable] [Serializable]
@ -101,7 +101,7 @@ public class CharacterCard
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public List<SkillsItem> Skills { get; set; } = new(); public List<SkillsItem> Skills { get; set; } = [];
public static void CopyCardProperty(Character source, CharacterCard characterCard) public static void CopyCardProperty(Character source, CharacterCard characterCard)
{ {

View File

@ -5,6 +5,8 @@ using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Assets;
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model;
using BetterGenshinImpact.GameTask.Common; using BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.GameTask.Model.Area;
using BetterGenshinImpact.Helpers;
using BetterGenshinImpact.Helpers.Extensions; using BetterGenshinImpact.Helpers.Extensions;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using OpenCvSharp; using OpenCvSharp;
@ -12,12 +14,10 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BetterGenshinImpact.GameTask.Model.Area;
using Point = OpenCvSharp.Point;
using static BetterGenshinImpact.GameTask.Common.TaskControl; using static BetterGenshinImpact.GameTask.Common.TaskControl;
using Point = OpenCvSharp.Point;
namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation; namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation;
@ -1041,7 +1041,7 @@ public class GeniusInvokationControl
var srcMat = CaptureGameMat(); var srcMat = CaptureGameMat();
int halfHeight = srcMat.Height / 2; int halfHeight = srcMat.Height / 2;
Mat bottomMat = new Mat(srcMat, new Rect(0, halfHeight, srcMat.Width, srcMat.Height - halfHeight)); Mat bottomMat = new(srcMat, new Rect(0, halfHeight, srcMat.Width, srcMat.Height - halfHeight));
var lowPurple = new Scalar(239, 239, 239); var lowPurple = new Scalar(239, 239, 239);
var highPurple = new Scalar(255, 255, 255); var highPurple = new Scalar(255, 255, 255);
@ -1056,10 +1056,11 @@ public class GeniusInvokationControl
if (contours.Length > 0) if (contours.Length > 0)
{ {
// .Where(w => w.Width > 1 && w.Height >= 5) // .Where(w => w.Width > 1 && w.Height >= 5)
var rects = contours.Select(Cv2.BoundingRect).ToList(); var rects = contours
.Select(Cv2.BoundingRect)
// 按照Y轴高度排序 // 按照Y轴高度排序
rects = rects.OrderBy(r => r.Y).ToList(); .OrderBy(r => r.Y)
.ToList();
// 第一个和角色卡重叠的矩形 // 第一个和角色卡重叠的矩形
foreach (var rect in rects) foreach (var rect in rects)
@ -1142,7 +1143,7 @@ public class GeniusInvokationControl
if (!string.IsNullOrWhiteSpace(text)) if (!string.IsNullOrWhiteSpace(text))
{ {
var hp = -2; var hp = -2;
if (Regex.IsMatch(text, @"^[0-9]+$")) if (RegexHelper.FullNumberRegex().IsMatch(text))
{ {
hp = int.Parse(text); hp = int.Parse(text);
} }
@ -1223,7 +1224,7 @@ public class GeniusInvokationControl
#endif #endif
return -10; return -10;
} }
else if (Regex.IsMatch(text, @"^[0-9]+$")) else if (RegexHelper.FullNumberRegex().IsMatch(text))
{ {
_logger.LogInformation("通过OCR识别当前骰子数量: {Text}", text); _logger.LogInformation("通过OCR识别当前骰子数量: {Text}", text);
return int.Parse(text); return int.Parse(text);

View File

@ -1,5 +1,5 @@
using System.Threading; using BetterGenshinImpact.GameTask.Model;
using BetterGenshinImpact.GameTask.Model; using System.Threading;
namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation; namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation;

View File

@ -7,7 +7,7 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model
/// <summary> /// <summary>
/// 角色 /// 角色
/// </summary> /// </summary>
public Character Character { get; set; } public Character Character { get; set; } = default!;
public ActionEnum Action { get; set; } public ActionEnum Action { get; set; }
@ -16,7 +16,7 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model
/// </summary> /// </summary>
public int TargetIndex { get; set; } public int TargetIndex { get; set; }
public override string ToString() public override string? ToString()
{ {
if (Action == ActionEnum.UseSkill) if (Action == ActionEnum.UseSkill)
{ {

View File

@ -12,34 +12,24 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model
public static ActionEnum ChineseToActionEnum(this string type) public static ActionEnum ChineseToActionEnum(this string type)
{ {
type = type.ToLower(); type = type.ToLower();
switch (type) return type switch
{ {
case "出战": "出战" => /* ActionEnum.ChooseFirst, */ throw new ArgumentOutOfRangeException(nameof(type), type, null),
//return ActionEnum.ChooseFirst; "切换" => /* ActionEnum.SwitchLater, */ throw new ArgumentOutOfRangeException(nameof(type), type, null),
throw new ArgumentOutOfRangeException(nameof(type), type, null); "使用" => ActionEnum.UseSkill,
case "切换": _ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
//return ActionEnum.SwitchLater; };
throw new ArgumentOutOfRangeException(nameof(type), type, null);
case "使用":
return ActionEnum.UseSkill;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
} }
public static string ToChinese(this ActionEnum type) public static string ToChinese(this ActionEnum type)
{ {
switch (type) return type switch
{ {
case ActionEnum.ChooseFirst: ActionEnum.ChooseFirst => "出战",
return "出战"; ActionEnum.SwitchLater => "切换",
case ActionEnum.SwitchLater: ActionEnum.UseSkill => "使用",
return "切换"; _ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
case ActionEnum.UseSkill: };
return "使用";
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
} }
} }
} }

View File

@ -1,9 +1,9 @@
using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.Core.Recognition.OpenCv;
using BetterGenshinImpact.Helpers.Extensions; using BetterGenshinImpact.Helpers.Extensions;
using Microsoft.Extensions.Logging;
using OpenCvSharp; using OpenCvSharp;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Microsoft.Extensions.Logging;
namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model
{ {
@ -16,9 +16,9 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model
/// </summary> /// </summary>
public int Index { get; set; } public int Index { get; set; }
public string Name { get; set; } public string Name { get; set; } = default!;
public ElementalType Element { get; set; } public ElementalType Element { get; set; }
public Skill[] Skills { get; set; } public Skill[] Skills { get; set; } = default!;
/// <summary> /// <summary>
@ -46,7 +46,7 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model
/// <summary> /// <summary>
/// 角色身上的负面状态 /// 角色身上的负面状态
/// </summary> /// </summary>
public List<CharacterStatusEnum> StatusList { get; set; } = new List<CharacterStatusEnum>(); public List<CharacterStatusEnum> StatusList { get; set; } = [];
/// <summary> /// <summary>
/// 角色区域 /// 角色区域
@ -60,7 +60,7 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model
public override string ToString() public override string ToString()
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new();
sb.Append($"角色{Index}"); sb.Append($"角色{Index}");
if (Hp != -2) if (Hp != -2)
{ {

View File

@ -2,7 +2,7 @@
{ {
public enum CharacterStatusEnum public enum CharacterStatusEnum
{ {
Frozen, Frozen,
Dizziness Dizziness
} }
} }

View File

@ -9,7 +9,6 @@ using Microsoft.Extensions.Logging;
using OpenCvSharp; using OpenCvSharp;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -22,13 +21,13 @@ public class Duel
{ {
private readonly ILogger<Duel> _logger = App.GetLogger<Duel>(); private readonly ILogger<Duel> _logger = App.GetLogger<Duel>();
public Character CurrentCharacter { get; set; } public Character CurrentCharacter { get; set; } = default!;
public Character[] Characters { get; set; } = new Character[4]; public Character[] Characters { get; set; } = new Character[4];
/// <summary> /// <summary>
/// 行动指令队列 /// 行动指令队列
/// </summary> /// </summary>
public List<ActionCommand> ActionCommandQueue { get; set; } = new List<ActionCommand>(); public List<ActionCommand> ActionCommandQueue { get; set; } = [];
/// <summary> /// <summary>
/// 当前回合数 /// 当前回合数
@ -38,7 +37,7 @@ public class Duel
/// <summary> /// <summary>
/// 角色牌位置 /// 角色牌位置
/// </summary> /// </summary>
public List<Rect> CharacterCardRects { get; set; } public List<Rect> CharacterCardRects { get; set; } = default!;
/// <summary> /// <summary>
/// 手牌数量 /// 手牌数量
@ -50,7 +49,7 @@ public class Duel
/// </summary> /// </summary>
public int CurrentDiceCount { get; set; } = 0; public int CurrentDiceCount { get; set; } = 0;
public CancellationTokenSource Cts { get; set; } public CancellationTokenSource Cts { get; set; } = default!;
private int _keqingECount = 0; private int _keqingECount = 0;
@ -95,7 +94,7 @@ public class Duel
if (CharacterCardRects is not { Count: 3 }) if (CharacterCardRects is not { Count: 3 })
{ {
CharacterCardRects = new List<Rect>(); CharacterCardRects = [];
var defaultCharacterCardRects = TaskContext.Instance().Config.AutoGeniusInvokationConfig.DefaultCharacterCardRects; var defaultCharacterCardRects = TaskContext.Instance().Config.AutoGeniusInvokationConfig.DefaultCharacterCardRects;
var assetScale = TaskContext.Instance().SystemInfo.AssetScale; var assetScale = TaskContext.Instance().SystemInfo.AssetScale;
for (var i = 0; i < defaultCharacterCardRects.Count; i++) for (var i = 0; i < defaultCharacterCardRects.Count; i++)
@ -135,7 +134,7 @@ public class Duel
var elementSet = PredictionDiceType(); var elementSet = PredictionDiceType();
// 0 投骰子 // 0 投骰子
GeniusInvokationControl.GetInstance().ReRollDice(elementSet.ToArray()); GeniusInvokationControl.GetInstance().ReRollDice([.. elementSet]);
// 等待到我的回合 // 投骰子动画时间是不确定的 // 可能是对方先手 // 等待到我的回合 // 投骰子动画时间是不确定的 // 可能是对方先手
GeniusInvokationControl.GetInstance().WaitForMyTurn(this, 1000); GeniusInvokationControl.GetInstance().WaitForMyTurn(this, 1000);
@ -429,7 +428,7 @@ public class Duel
/// <returns></returns> /// <returns></returns>
public List<int> GetCharacterSwitchOrder() public List<int> GetCharacterSwitchOrder()
{ {
List<int> orderList = new List<int>(); List<int> orderList = [];
for (var i = 0; i < ActionCommandQueue.Count; i++) for (var i = 0; i < ActionCommandQueue.Count; i++)
{ {
if (!orderList.Contains(ActionCommandQueue[i].Character.Index)) if (!orderList.Contains(ActionCommandQueue[i].Character.Index))

View File

@ -19,83 +19,56 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model
public static ElementalType ToElementalType(this string type) public static ElementalType ToElementalType(this string type)
{ {
type = type.ToLower(); type = type.ToLower();
switch (type) return type switch
{ {
case "omni": "omni" => ElementalType.Omni,
return ElementalType.Omni; "cryo" => ElementalType.Cryo,
case "cryo": "hydro" => ElementalType.Hydro,
return ElementalType.Cryo; "pyro" => ElementalType.Pyro,
case "hydro": "electro" => ElementalType.Electro,
return ElementalType.Hydro; "dendro" => ElementalType.Dendro,
case "pyro": "anemo" => ElementalType.Anemo,
return ElementalType.Pyro; "geo" => ElementalType.Geo,
case "electro": _ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
return ElementalType.Electro; };
case "dendro":
return ElementalType.Dendro;
case "anemo":
return ElementalType.Anemo;
case "geo":
return ElementalType.Geo;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
} }
public static ElementalType ChineseToElementalType(this string type) public static ElementalType ChineseToElementalType(this string type)
{ {
type = type.ToLower(); type = type.ToLower();
switch (type) return type switch
{ {
case "全": "全" => ElementalType.Omni,
return ElementalType.Omni; "冰" => ElementalType.Cryo,
case "冰": "水" => ElementalType.Hydro,
return ElementalType.Cryo; "火" => ElementalType.Pyro,
case "水": "雷" => ElementalType.Electro,
return ElementalType.Hydro; "草" => ElementalType.Dendro,
case "火": "风" => ElementalType.Anemo,
return ElementalType.Pyro; "岩" => ElementalType.Geo,
case "雷": _ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
return ElementalType.Electro; };
case "草":
return ElementalType.Dendro;
case "风":
return ElementalType.Anemo;
case "岩":
return ElementalType.Geo;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
} }
public static string ToChinese(this ElementalType type) public static string ToChinese(this ElementalType type)
{ {
switch (type) return type switch
{ {
case ElementalType.Omni: ElementalType.Omni => "全",
return "全"; ElementalType.Cryo => "冰",
case ElementalType.Cryo: ElementalType.Hydro => "水",
return "冰"; ElementalType.Pyro => "火",
case ElementalType.Hydro: ElementalType.Electro => "雷",
return "水"; ElementalType.Dendro => "草",
case ElementalType.Pyro: ElementalType.Anemo => "风",
return "火"; ElementalType.Geo => "岩",
case ElementalType.Electro: _ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
return "雷"; };
case ElementalType.Dendro:
return "草";
case ElementalType.Anemo:
return "风";
case ElementalType.Geo:
return "岩";
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
} }
public static string ToLowerString(this ElementalType type) public static string ToLowerString(this ElementalType type)
{ {
return type.ToString().ToLower(); return type.ToString().ToLower();
} }
} }
} }

View File

@ -13,7 +13,7 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model
/// 元素类型 /// 元素类型
/// </summary> /// </summary>
public ElementalType Type { get; set; } public ElementalType Type { get; set; }
/// <summary> /// <summary>
/// 中心点位置 /// 中心点位置
/// </summary> /// </summary>

View File

@ -6,19 +6,19 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model;
[Obsolete] [Obsolete]
public class RoundStrategy public class RoundStrategy
{ {
public List<string> RawCommandList { get; set; } = new List<string>(); public List<string> RawCommandList { get; set; } = [];
public List<ActionCommand> ActionCommands { get; set; } = new List<ActionCommand>(); public List<ActionCommand> ActionCommands { get; set; } = [];
public List<ElementalType> MaybeNeedElement(Duel duel) public List<ElementalType> MaybeNeedElement(Duel duel)
{ {
List<ElementalType> result = new List<ElementalType>(); List<ElementalType> result = [];
for (int i = 0; i < ActionCommands.Count; i++) for (int i = 0; i < ActionCommands.Count; i++)
{ {
if (ActionCommands[i].Action == ActionEnum.SwitchLater if (ActionCommands[i].Action == ActionEnum.SwitchLater
&& i != ActionCommands.Count-1 && i != ActionCommands.Count - 1
&& ActionCommands[i+1].Action == ActionEnum.UseSkill) && ActionCommands[i + 1].Action == ActionEnum.UseSkill)
{ {
result.Add(duel.Characters[ActionCommands[i].TargetIndex].Element); result.Add(duel.Characters[ActionCommands[i].TargetIndex].Element);
} }

View File

@ -1,12 +1,12 @@
using System; using BetterGenshinImpact.GameTask.AutoFight.Config;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using BetterGenshinImpact.GameTask.AutoFight.Config;
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Config; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Config;
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model;
using BetterGenshinImpact.Helpers;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation; namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation;
@ -16,7 +16,7 @@ public class ScriptParser
public static Duel Parse(string script) public static Duel Parse(string script)
{ {
var lines = script.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); var lines = script.Split(["\r\n", "\r", "\n"], StringSplitOptions.None);
var result = new List<string>(); var result = new List<string>();
foreach (var line in lines) foreach (var line in lines)
{ {
@ -29,7 +29,7 @@ public class ScriptParser
public static Duel Parse(List<string> lines) public static Duel Parse(List<string> lines)
{ {
Duel duel = new Duel(); Duel duel = new();
string stage = ""; string stage = "";
int i = 0; int i = 0;
@ -38,7 +38,7 @@ public class ScriptParser
for (i = 0; i < lines.Count; i++) for (i = 0; i < lines.Count; i++)
{ {
var line = lines[i]; var line = lines[i];
if (line.Contains(":")) if (line.Contains(':'))
{ {
stage = line; stage = line;
continue; continue;
@ -58,7 +58,7 @@ public class ScriptParser
{ {
MyAssert(duel.Characters[3] != null, "角色未定义"); MyAssert(duel.Characters[3] != null, "角色未定义");
string[] actionParts = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); string[] actionParts = line.Split(" ", StringSplitOptions.RemoveEmptyEntries);
MyAssert(actionParts.Length == 3, "策略中的行动命令解析错误"); MyAssert(actionParts.Length == 3, "策略中的行动命令解析错误");
MyAssert(actionParts[1] == "使用", "策略中的行动命令解析错误"); MyAssert(actionParts[1] == "使用", "策略中的行动命令解析错误");
@ -79,7 +79,7 @@ public class ScriptParser
MyAssert(j <= 3, "策略中的行动命令解析错误:角色名称无法从角色定义中匹配到"); MyAssert(j <= 3, "策略中的行动命令解析错误:角色名称无法从角色定义中匹配到");
int skillNum = int.Parse(Regex.Replace(actionParts[2], @"[^0-9]+", "")); int skillNum = int.Parse(RegexHelper.ExcludeNumberRegex().Replace(actionParts[2], ""));
MyAssert(skillNum < 5, "策略中的行动命令解析错误:技能编号错误"); MyAssert(skillNum < 5, "策略中的行动命令解析错误:技能编号错误");
actionCommand.TargetIndex = skillNum; actionCommand.TargetIndex = skillNum;
duel.ActionCommandQueue.Add(actionCommand); duel.ActionCommandQueue.Add(actionCommand);
@ -96,7 +96,7 @@ public class ScriptParser
{ {
MyLogger.LogError($"解析脚本错误,行号:{i + 1},错误信息:{ex}"); MyLogger.LogError($"解析脚本错误,行号:{i + 1},错误信息:{ex}");
MessageBox.Show($"解析脚本错误,行号:{i + 1},错误信息:{ex}", "策略解析失败", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show($"解析脚本错误,行号:{i + 1},错误信息:{ex}", "策略解析失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null; return default!;
} }
return duel; return duel;
@ -117,14 +117,14 @@ public class ScriptParser
var characterAndSkill = line.Split('{'); var characterAndSkill = line.Split('{');
var parts = characterAndSkill[0].Split('='); var parts = characterAndSkill[0].Split('=');
character.Index = int.Parse(Regex.Replace(parts[0], @"[^0-9]+", "")); character.Index = int.Parse(RegexHelper.ExcludeNumberRegex().Replace(parts[0], ""));
MyAssert(character.Index >= 1 && character.Index <= 3, "角色序号必须在1-3之间"); MyAssert(character.Index >= 1 && character.Index <= 3, "角色序号必须在1-3之间");
if (parts[1].Contains("|")) if (parts[1].Contains('|'))
{ {
var nameAndElement = parts[1].Split('|'); var nameAndElement = parts[1].Split('|');
character.Name = nameAndElement[0]; character.Name = nameAndElement[0];
character.Element = nameAndElement[1].Substring(0, 1).ChineseToElementalType(); character.Element = nameAndElement[1][..1].ChineseToElementalType();
// 技能 // 技能
string skillStr = characterAndSkill[1].Replace("}", ""); string skillStr = characterAndSkill[1].Replace("}", "");
@ -136,7 +136,7 @@ public class ScriptParser
skills[skill.Index] = skill; skills[skill.Index] = skill;
} }
character.Skills = skills.ToArray(); character.Skills = [.. skills];
} }
else else
{ {
@ -172,16 +172,16 @@ public class ScriptParser
{ {
var skill = new Skill(); var skill = new Skill();
var parts = oneSkillStr.Split('='); var parts = oneSkillStr.Split('=');
skill.Index = short.Parse(Regex.Replace(parts[0], @"[^0-9]+", "")); skill.Index = short.Parse(RegexHelper.ExcludeNumberRegex().Replace(parts[0], ""));
MyAssert(skill.Index >= 1 && skill.Index <= 5, "技能序号必须在1-5之间"); MyAssert(skill.Index >= 1 && skill.Index <= 5, "技能序号必须在1-5之间");
var costStr = parts[1]; var costStr = parts[1];
var costParts = costStr.Split('+'); var costParts = costStr.Split('+');
skill.SpecificElementCost = int.Parse(costParts[0].Substring(0, 1)); skill.SpecificElementCost = int.Parse(costParts[0][..1]);
skill.Type = costParts[0].Substring(1, 1).ChineseToElementalType(); skill.Type = costParts[0].Substring(1, 1).ChineseToElementalType();
// 杂色骰子在+号右边 // 杂色骰子在+号右边
if (costParts.Length > 1) if (costParts.Length > 1)
{ {
skill.AnyElementCost = int.Parse(costParts[1].Substring(0, 1)); skill.AnyElementCost = int.Parse(costParts[1][..1]);
} }
skill.AllCost = skill.SpecificElementCost + skill.AnyElementCost; skill.AllCost = skill.SpecificElementCost + skill.AnyElementCost;

View File

@ -1,5 +1,5 @@
using System.Threading; using BetterGenshinImpact.GameTask.Model;
using BetterGenshinImpact.GameTask.Model; using System.Threading;
namespace BetterGenshinImpact.GameTask.AutoMusicGame; namespace BetterGenshinImpact.GameTask.AutoMusicGame;

View File

@ -1,7 +1,9 @@
using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Core.Recognition;
using BetterGenshinImpact.Core.Recognition.OCR; using BetterGenshinImpact.Core.Recognition.OCR;
using BetterGenshinImpact.Core.Recognition.ONNX.SVTR; using BetterGenshinImpact.Core.Recognition.ONNX.SVTR;
using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.Core.Recognition.OpenCv;
using BetterGenshinImpact.Core.Script.Dependence.Model.TimerConfig;
using BetterGenshinImpact.Core.Simulator; using BetterGenshinImpact.Core.Simulator;
using BetterGenshinImpact.GameTask.AutoPick.Assets; using BetterGenshinImpact.GameTask.AutoPick.Assets;
using BetterGenshinImpact.Helpers; using BetterGenshinImpact.Helpers;
@ -14,14 +16,11 @@ using System.Diagnostics;
using System.Text.Json; using System.Text.Json;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Forms; using System.Windows.Forms;
using BetterGenshinImpact.Core.Recognition;
using Vanara.PInvoke; using Vanara.PInvoke;
using System.Windows.Input;
using BetterGenshinImpact.Core.Script.Dependence.Model.TimerConfig;
namespace BetterGenshinImpact.GameTask.AutoPick; namespace BetterGenshinImpact.GameTask.AutoPick;
public class AutoPickTrigger : ITaskTrigger public partial class AutoPickTrigger : ITaskTrigger
{ {
private readonly ILogger<AutoPickTrigger> _logger = App.GetLogger<AutoPickTrigger>(); private readonly ILogger<AutoPickTrigger> _logger = App.GetLogger<AutoPickTrigger>();
private readonly ITextInference _pickTextInference = TextInferenceFactory.Pick; private readonly ITextInference _pickTextInference = TextInferenceFactory.Pick;
@ -36,12 +35,12 @@ public class AutoPickTrigger : ITaskTrigger
/// <summary> /// <summary>
/// 拾取黑名单 /// 拾取黑名单
/// </summary> /// </summary>
private List<string> _blackList = new(); private List<string> _blackList = [];
/// <summary> /// <summary>
/// 拾取白名单 /// 拾取白名单
/// </summary> /// </summary>
private List<string> _whiteList = new(); private List<string> _whiteList = [];
// 自定义拾取按键 // 自定义拾取按键
private string _pickKeyName = "F"; private string _pickKeyName = "F";
@ -200,7 +199,7 @@ public class AutoPickTrigger : ITaskTrigger
speedTimer.Record("文字识别"); speedTimer.Record("文字识别");
if (!string.IsNullOrEmpty(text)) if (!string.IsNullOrEmpty(text))
{ {
text = Regex.Replace(text, @"^[\p{P} ]+|[\p{P} ]+$", ""); text = PunctuationAndSpacesRegex().Replace(text, "");
// 唯一一个动态拾取项,特殊处理,不拾取 // 唯一一个动态拾取项,特殊处理,不拾取
if (text.Contains("生长时间")) if (text.Contains("生长时间"))
{ {
@ -273,4 +272,7 @@ public class AutoPickTrigger : ITaskTrigger
_lastText = text; _lastText = text;
_prevClickFrameIndex = content.FrameIndex; _prevClickFrameIndex = content.FrameIndex;
} }
[GeneratedRegex(@"^[\p{P} ]+|[\p{P} ]+$")]
private static partial Regex PunctuationAndSpacesRegex();
} }

View File

@ -1,10 +1,10 @@
using System; using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Model; using BetterGenshinImpact.Model;
using BetterGenshinImpact.Service;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text.Json; using System.Text.Json;
using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Service;
namespace BetterGenshinImpact.GameTask.AutoSkip.Assets; namespace BetterGenshinImpact.GameTask.AutoSkip.Assets;

View File

@ -29,7 +29,7 @@ namespace BetterGenshinImpact.GameTask.AutoSkip;
/// <summary> /// <summary>
/// 自动剧情有选项点击 /// 自动剧情有选项点击
/// </summary> /// </summary>
public class AutoSkipTrigger : ITaskTrigger public partial class AutoSkipTrigger : ITaskTrigger
{ {
private readonly ILogger<AutoSkipTrigger> _logger = App.GetLogger<AutoSkipTrigger>(); private readonly ILogger<AutoSkipTrigger> _logger = App.GetLogger<AutoSkipTrigger>();
@ -47,17 +47,17 @@ public class AutoSkipTrigger : ITaskTrigger
/// <summary> /// <summary>
/// 不自动点击的选项,优先级低于橙色文字点击 /// 不自动点击的选项,优先级低于橙色文字点击
/// </summary> /// </summary>
private List<string> _defaultPauseList = new(); private List<string> _defaultPauseList = [];
/// <summary> /// <summary>
/// 不自动点击的选项 /// 不自动点击的选项
/// </summary> /// </summary>
private List<string> _pauseList = new(); private List<string> _pauseList = [];
/// <summary> /// <summary>
/// 优先自动点击的选项 /// 优先自动点击的选项
/// </summary> /// </summary>
private List<string> _selectList = new(); private List<string> _selectList = [];
private PostMessageSimulator? _postMessageSimulator; private PostMessageSimulator? _postMessageSimulator;
@ -78,7 +78,7 @@ public class AutoSkipTrigger : ITaskTrigger
var defaultPauseListJson = Global.ReadAllTextIfExist(@"User\AutoSkip\default_pause_options.json"); var defaultPauseListJson = Global.ReadAllTextIfExist(@"User\AutoSkip\default_pause_options.json");
if (!string.IsNullOrEmpty(defaultPauseListJson)) if (!string.IsNullOrEmpty(defaultPauseListJson))
{ {
_defaultPauseList = JsonSerializer.Deserialize<List<string>>(defaultPauseListJson, ConfigService.JsonOptions) ?? new List<string>(); _defaultPauseList = JsonSerializer.Deserialize<List<string>>(defaultPauseListJson, ConfigService.JsonOptions) ?? [];
} }
} }
catch (Exception e) catch (Exception e)
@ -92,7 +92,7 @@ public class AutoSkipTrigger : ITaskTrigger
var pauseListJson = Global.ReadAllTextIfExist(@"User\AutoSkip\pause_options.json"); var pauseListJson = Global.ReadAllTextIfExist(@"User\AutoSkip\pause_options.json");
if (!string.IsNullOrEmpty(pauseListJson)) if (!string.IsNullOrEmpty(pauseListJson))
{ {
_pauseList = JsonSerializer.Deserialize<List<string>>(pauseListJson, ConfigService.JsonOptions) ?? new List<string>(); _pauseList = JsonSerializer.Deserialize<List<string>>(pauseListJson, ConfigService.JsonOptions) ?? [];
} }
} }
catch (Exception e) catch (Exception e)
@ -106,7 +106,7 @@ public class AutoSkipTrigger : ITaskTrigger
var selectListJson = Global.ReadAllTextIfExist(@"User\AutoSkip\select_options.json"); var selectListJson = Global.ReadAllTextIfExist(@"User\AutoSkip\select_options.json");
if (!string.IsNullOrEmpty(selectListJson)) if (!string.IsNullOrEmpty(selectListJson))
{ {
_selectList = JsonSerializer.Deserialize<List<string>>(selectListJson, ConfigService.JsonOptions) ?? new List<string>(); _selectList = JsonSerializer.Deserialize<List<string>>(selectListJson, ConfigService.JsonOptions) ?? [];
} }
} }
catch (Exception e) catch (Exception e)
@ -390,7 +390,8 @@ public class AutoSkipTrigger : ITaskTrigger
}); });
} }
private readonly Regex _enOrNumRegex = new(@"^[a-zA-Z0-9]+$"); [GeneratedRegex(@"^[a-zA-Z0-9]+$")]
private static partial Regex EnOrNumRegex();
/// <summary> /// <summary>
/// 新的对话选项选择 /// 新的对话选项选择
@ -420,7 +421,7 @@ public class AutoSkipTrigger : ITaskTrigger
if (chatOptionResultList.Count > 0) if (chatOptionResultList.Count > 0)
{ {
// 第一个元素就是最下面的 // 第一个元素就是最下面的
chatOptionResultList = chatOptionResultList.OrderByDescending(r => r.Y).ToList(); chatOptionResultList = [.. chatOptionResultList.OrderByDescending(r => r.Y)];
// 通过最下面的气泡框来文字识别 // 通过最下面的气泡框来文字识别
var lowest = chatOptionResultList[0]; var lowest = chatOptionResultList[0];
@ -438,11 +439,11 @@ public class AutoSkipTrigger : ITaskTrigger
// 删除为空的结果 和 纯英文的结果 // 删除为空的结果 和 纯英文的结果
var rs = new List<Region>(); var rs = new List<Region>();
// 按照y坐标排序 // 按照y坐标排序
ocrResList = ocrResList.OrderBy(r => r.Y).ToList(); ocrResList = [.. ocrResList.OrderBy(r => r.Y)];
for (var i = 0; i < ocrResList.Count; i++) for (var i = 0; i < ocrResList.Count; i++)
{ {
var item = ocrResList[i]; var item = ocrResList[i];
if (string.IsNullOrEmpty(item.Text) || (item.Text.Length < 5 && _enOrNumRegex.IsMatch(item.Text))) if (string.IsNullOrEmpty(item.Text) || (item.Text.Length < 5 && EnOrNumRegex().IsMatch(item.Text)))
{ {
continue; continue;
} }

View File

@ -4,25 +4,23 @@ using BetterGenshinImpact.Core.Recognition.OpenCv;
using BetterGenshinImpact.Core.Simulator; using BetterGenshinImpact.Core.Simulator;
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
using BetterGenshinImpact.GameTask.AutoSkip.Model; using BetterGenshinImpact.GameTask.AutoSkip.Model;
using BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.GameTask.Common.BgiVision;
using BetterGenshinImpact.GameTask.Common.Element.Assets; using BetterGenshinImpact.GameTask.Common.Element.Assets;
using BetterGenshinImpact.GameTask.Model; using BetterGenshinImpact.GameTask.Model;
using BetterGenshinImpact.GameTask.Model.Area;
using BetterGenshinImpact.GameTask.QuickTeleport.Assets; using BetterGenshinImpact.GameTask.QuickTeleport.Assets;
using BetterGenshinImpact.Helpers; using BetterGenshinImpact.Helpers;
using BetterGenshinImpact.Service.Notification;
using BetterGenshinImpact.View.Drawable; using BetterGenshinImpact.View.Drawable;
using BetterGenshinImpact.ViewModel.Pages;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using OpenCvSharp; using OpenCvSharp;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.GameTask.Common.BgiVision;
using BetterGenshinImpact.GameTask.Model.Area;
using BetterGenshinImpact.ViewModel.Pages;
using Vanara.PInvoke; using Vanara.PInvoke;
using static BetterGenshinImpact.GameTask.Common.TaskControl; using static BetterGenshinImpact.GameTask.Common.TaskControl;
using WinRT;
namespace BetterGenshinImpact.GameTask.AutoSkip; namespace BetterGenshinImpact.GameTask.AutoSkip;
@ -285,7 +283,7 @@ public class AutoTrackTask(AutoTrackParam param) : BaseIndependentTask
foreach (var textRa in textRaList) foreach (var textRa in textRaList)
{ {
if (textRa.Text.Length < 8 && (textRa.Text.Contains("m") || textRa.Text.Contains("M"))) if (textRa.Text.Length < 8 && textRa.Text.Contains('m', StringComparison.OrdinalIgnoreCase))
{ {
_missionDistanceRect = textRa.ConvertSelfPositionToGameCaptureRegion(); _missionDistanceRect = textRa.ConvertSelfPositionToGameCaptureRegion();
return StringUtils.TryExtractPositiveInt(textRa.Text); return StringUtils.TryExtractPositiveInt(textRa.Text);

View File

@ -4,7 +4,6 @@ using BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.View.Drawable; using BetterGenshinImpact.View.Drawable;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using OpenCvSharp; using OpenCvSharp;
using OpenCvSharp.Extensions;
using Sdcb.PaddleOCR; using Sdcb.PaddleOCR;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -23,7 +22,7 @@ namespace BetterGenshinImpact.GameTask.AutoSkip;
[Obsolete] [Obsolete]
public class ExpeditionTask public class ExpeditionTask
{ {
private static readonly List<string> ExpeditionCharacterList = new(); private static readonly List<string> ExpeditionCharacterList = [];
private int _expeditionCount = 0; private int _expeditionCount = 0;
@ -129,12 +128,7 @@ public class ExpeditionTask
var cards = GetCharacterCards(result); var cards = GetCharacterCards(result);
if (cards.Count > 0) if (cards.Count > 0)
{ {
var card = cards.FirstOrDefault(c => c.Idle && c.Name != null && ExpeditionCharacterList.Contains(c.Name)); var card = cards.FirstOrDefault(c => c.Idle && c.Name != null && ExpeditionCharacterList.Contains(c.Name)) ?? cards.First(c => c.Idle);
if (card == null)
{
card = cards.First(c => c.Idle);
}
var rect = card.Rects.First(); var rect = card.Rects.First();
using var ra = content.CaptureRectArea.Derive(rect); using var ra = content.CaptureRectArea.Derive(rect);
@ -158,9 +152,12 @@ public class ExpeditionTask
var captureRect = TaskContext.Instance().SystemInfo.CaptureAreaRect; var captureRect = TaskContext.Instance().SystemInfo.CaptureAreaRect;
var assetScale = TaskContext.Instance().SystemInfo.AssetScale; var assetScale = TaskContext.Instance().SystemInfo.AssetScale;
var ocrResultRects = result.Regions.Select(x => x.ToOcrResultRect()).ToList(); var ocrResultRects = result.Regions
ocrResultRects = ocrResultRects.Where(r => r.Rect.X + r.Rect.Width < captureRect.Width / 2) .Select(x => x.ToOcrResultRect())
.OrderBy(r => r.Rect.Y).ThenBy(r => r.Rect.X).ToList(); .Where(r => r.Rect.X + r.Rect.Width < captureRect.Width / 2)
.OrderBy(r => r.Rect.Y)
.ThenBy(r => r.Rect.X)
.ToList();
var cards = new List<ExpeditionCharacterCard>(); var cards = new List<ExpeditionCharacterCard>();
foreach (var ocrResultRect in ocrResultRects) foreach (var ocrResultRect in ocrResultRects)

View File

@ -1,5 +1,5 @@
using System.Threading; using BetterGenshinImpact.GameTask.Model;
using BetterGenshinImpact.GameTask.Model; using System.Threading;
namespace BetterGenshinImpact.GameTask.AutoSkip.Model; namespace BetterGenshinImpact.GameTask.AutoSkip.Model;

View File

@ -12,7 +12,7 @@ public class ExpeditionCharacterCard
public string? Addition { get; set; } public string? Addition { get; set; }
public List<Rect> Rects { get; set; } = new(); public List<Rect> Rects { get; set; } = [];
//public ExpeditionCharacterCard(string name,string addition, bool idle) //public ExpeditionCharacterCard(string name,string addition, bool idle)
//{ //{

View File

@ -1,5 +1,5 @@
using System.Threading; using BetterGenshinImpact.GameTask.Model;
using BetterGenshinImpact.GameTask.Model; using System.Threading;
namespace BetterGenshinImpact.GameTask.AutoTrackPath; namespace BetterGenshinImpact.GameTask.AutoTrackPath;

View File

@ -1,16 +1,15 @@
using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Core.Recognition;
using BetterGenshinImpact.Core.Recognition.OpenCv;
using BetterGenshinImpact.Core.Simulator; using BetterGenshinImpact.Core.Simulator;
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
using BetterGenshinImpact.GameTask.AutoTrackPath.Model; using BetterGenshinImpact.GameTask.AutoTrackPath.Model;
using BetterGenshinImpact.GameTask.Common; using BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.GameTask.Common.BgiVision;
using BetterGenshinImpact.GameTask.Common.Element.Assets; using BetterGenshinImpact.GameTask.Common.Element.Assets;
using BetterGenshinImpact.GameTask.Common.Map; using BetterGenshinImpact.GameTask.Common.Map;
using BetterGenshinImpact.GameTask.Model.Area; using BetterGenshinImpact.GameTask.Model.Area;
using BetterGenshinImpact.GameTask.Model.Enum; using BetterGenshinImpact.GameTask.Model.Enum;
using BetterGenshinImpact.GameTask.QuickTeleport.Assets;
using BetterGenshinImpact.Helpers; using BetterGenshinImpact.Helpers;
using BetterGenshinImpact.Helpers.Extensions;
using BetterGenshinImpact.Service; using BetterGenshinImpact.Service;
using BetterGenshinImpact.View.Drawable; using BetterGenshinImpact.View.Drawable;
using BetterGenshinImpact.ViewModel.Pages; using BetterGenshinImpact.ViewModel.Pages;
@ -21,16 +20,11 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq;
using System.Text.Json; using System.Text.Json;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BetterGenshinImpact.GameTask.Common.BgiVision;
using BetterGenshinImpact.Helpers.Extensions;
using Vanara.PInvoke; using Vanara.PInvoke;
using static BetterGenshinImpact.GameTask.Common.TaskControl; using static BetterGenshinImpact.GameTask.Common.TaskControl;
using static Vanara.PInvoke.Gdi32;
using Point = OpenCvSharp.Point;
namespace BetterGenshinImpact.GameTask.AutoTrackPath; namespace BetterGenshinImpact.GameTask.AutoTrackPath;
@ -122,11 +116,7 @@ public class AutoTrackPathTask
NewRetry.Do((Action)(() => NewRetry.Do((Action)(() =>
{ {
var ra = TaskControl.CaptureToRectArea(); var ra = TaskControl.CaptureToRectArea();
var miniMapMat = GetMiniMapMat(ra); var miniMapMat = GetMiniMapMat(ra) ?? throw new RetryException("等待传送完成");
if (miniMapMat == null)
{
throw new RetryException("等待传送完成");
}
}), TimeSpan.FromSeconds(1), 100); }), TimeSpan.FromSeconds(1), 100);
Logger.LogInformation("传送完成"); Logger.LogInformation("传送完成");
Sleep(1000); Sleep(1000);
@ -218,11 +208,7 @@ public class AutoTrackPathTask
while (!_taskParam.Cts.IsCancellationRequested) while (!_taskParam.Cts.IsCancellationRequested)
{ {
var ra = CaptureToRectArea(); var ra = CaptureToRectArea();
var miniMapMat = GetMiniMapMat(ra); var miniMapMat = GetMiniMapMat(ra) ?? throw new InvalidOperationException("当前不在主界面");
if (miniMapMat == null)
{
throw new InvalidOperationException("当前不在主界面");
}
// 注意游戏坐标系的角度是顺时针的 // 注意游戏坐标系的角度是顺时针的
var currMapImageAvatarPos = EntireMap.Instance.GetMiniMapPositionByFeatureMatch(miniMapMat); var currMapImageAvatarPos = EntireMap.Instance.GetMiniMapPositionByFeatureMatch(miniMapMat);
@ -356,12 +342,7 @@ public class AutoTrackPathTask
public int GetCharacterOrientationAngle() public int GetCharacterOrientationAngle()
{ {
var ra = CaptureToRectArea(); var ra = CaptureToRectArea();
var miniMapMat = GetMiniMapMat(ra); var miniMapMat = GetMiniMapMat(ra) ?? throw new InvalidOperationException("当前不在主界面");
if (miniMapMat == null)
{
throw new InvalidOperationException("当前不在主界面");
}
var angle = CharacterOrientation.Compute(miniMapMat); var angle = CharacterOrientation.Compute(miniMapMat);
Logger.LogInformation("当前角度:{Angle}", angle); Logger.LogInformation("当前角度:{Angle}", angle);
// CameraOrientation.DrawDirection(ra, angle); // CameraOrientation.DrawDirection(ra, angle);

View File

@ -1,15 +1,15 @@
using System; using BetterGenshinImpact.Helpers;
using OpenCvSharp;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using BetterGenshinImpact.Helpers;
using OpenCvSharp;
namespace BetterGenshinImpact.GameTask.AutoTrackPath.Model; namespace BetterGenshinImpact.GameTask.AutoTrackPath.Model;
[Serializable] [Serializable]
public class GiPath public class GiPath
{ {
public List<GiPathPoint> WayPointList { get; set; } = new(); public List<GiPathPoint> WayPointList { get; set; } = [];
public void AddPoint(Point2f point) public void AddPoint(Point2f point)
{ {

View File

@ -1,7 +1,6 @@
using System; using BetterGenshinImpact.GameTask.Common.Map;
using BetterGenshinImpact.Core.Recognition.OpenCv;
using BetterGenshinImpact.GameTask.Common.Map;
using OpenCvSharp; using OpenCvSharp;
using System;
namespace BetterGenshinImpact.GameTask.AutoTrackPath.Model; namespace BetterGenshinImpact.GameTask.AutoTrackPath.Model;

View File

@ -1,10 +1,4 @@
using System; using BetterGenshinImpact.Core.Config;
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.Core.Recognition.OpenCv;
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
using BetterGenshinImpact.GameTask.AutoTrackPath.Model; using BetterGenshinImpact.GameTask.AutoTrackPath.Model;
@ -16,6 +10,12 @@ using BetterGenshinImpact.Model;
using BetterGenshinImpact.Service; using BetterGenshinImpact.Service;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using OpenCvSharp; using OpenCvSharp;
using System;
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using static BetterGenshinImpact.GameTask.Common.TaskControl; using static BetterGenshinImpact.GameTask.Common.TaskControl;
namespace BetterGenshinImpact.GameTask.AutoTrackPath; namespace BetterGenshinImpact.GameTask.AutoTrackPath;

View File

@ -6,6 +6,7 @@ using BetterGenshinImpact.GameTask.Common.Element.Assets;
using BetterGenshinImpact.GameTask.Common.Map; using BetterGenshinImpact.GameTask.Common.Map;
using BetterGenshinImpact.GameTask.Model.Area; using BetterGenshinImpact.GameTask.Model.Area;
using BetterGenshinImpact.GameTask.QuickTeleport.Assets; using BetterGenshinImpact.GameTask.QuickTeleport.Assets;
using BetterGenshinImpact.Helpers.Extensions;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using OpenCvSharp; using OpenCvSharp;
using System; using System;
@ -13,7 +14,6 @@ using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BetterGenshinImpact.Helpers.Extensions;
using Vanara.PInvoke; using Vanara.PInvoke;
using static BetterGenshinImpact.GameTask.Common.TaskControl; using static BetterGenshinImpact.GameTask.Common.TaskControl;
@ -24,8 +24,6 @@ namespace BetterGenshinImpact.GameTask.AutoTrackPath;
/// </summary> /// </summary>
public class TpTask(CancellationTokenSource cts) public class TpTask(CancellationTokenSource cts)
{ {
private static readonly Random _rd = new Random();
private readonly QuickTeleportAssets _assets = QuickTeleportAssets.Instance; private readonly QuickTeleportAssets _assets = QuickTeleportAssets.Instance;
/// <summary> /// <summary>
@ -145,7 +143,7 @@ public class TpTask(CancellationTokenSource cts)
public async Task MouseMoveMapX(int dx) public async Task MouseMoveMapX(int dx)
{ {
var moveUnit = dx > 0 ? 20 : -20; var moveUnit = dx > 0 ? 20 : -20;
GameCaptureRegion.GameRegionMove((rect, _) => (rect.Width / 2d + _rd.Next(-rect.Width / 6, rect.Width / 6), rect.Height / 2d + _rd.Next(-rect.Height / 6, rect.Height / 6))); 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(); Simulation.SendInput.Mouse.LeftButtonDown();
await Delay(200, cts); await Delay(200, cts);
for (var i = 0; i < dx / moveUnit; i++) for (var i = 0; i < dx / moveUnit; i++)
@ -160,7 +158,7 @@ public class TpTask(CancellationTokenSource cts)
public async Task MouseMoveMapY(int dy) public async Task MouseMoveMapY(int dy)
{ {
var moveUnit = dy > 0 ? 20 : -20; var moveUnit = dy > 0 ? 20 : -20;
GameCaptureRegion.GameRegionMove((rect, _) => (rect.Width / 2d + _rd.Next(-rect.Width / 6, rect.Width / 6), rect.Height / 2d + _rd.Next(-rect.Height / 6, rect.Height / 6))); 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(); Simulation.SendInput.Mouse.LeftButtonDown();
await Delay(200, cts); await Delay(200, cts);
// 原神地图在小范围内移动是无效的,所以先随便移动一下,所以肯定少移动一次 // 原神地图在小范围内移动是无效的,所以先随便移动一下,所以肯定少移动一次
@ -365,7 +363,7 @@ public class TpTask(CancellationTokenSource cts)
// 按高度排序 // 按高度排序
if (rResultList.Count > 0) if (rResultList.Count > 0)
{ {
rResultList = rResultList.OrderBy(x => x.Y).ToList(); rResultList = [.. rResultList.OrderBy(x => x.Y)];
// 点击最高的 // 点击最高的
foreach (var iconRect in rResultList) foreach (var iconRect in rResultList)
{ {

View File

@ -16,7 +16,7 @@ public class AutoWoodAssets : BaseAssets<AutoWoodAssets>
// 木头数量 // 木头数量
public Rect WoodCountUpperRect; public Rect WoodCountUpperRect;
private AutoWoodAssets() private AutoWoodAssets()
{ {

View File

@ -151,8 +151,8 @@ public partial class AutoWoodTask
private bool _firstWoodOcr = true; private bool _firstWoodOcr = true;
private string _firstWoodOcrText = ""; private string _firstWoodOcrText = "";
private readonly Dictionary<string, int> _woodMetricsDict = new(); private readonly Dictionary<string, int> _woodMetricsDict = [];
private readonly Dictionary<string, bool> _woodNotPrintDict = new(); private readonly Dictionary<string, bool> _woodNotPrintDict = [];
// from:https://api-static.mihoyo.com/common/blackboard/ys_obc/v1/home/content/list?app_sn=ys_obc&channel_id=13 // from:https://api-static.mihoyo.com/common/blackboard/ys_obc/v1/home/content/list?app_sn=ys_obc&channel_id=13
private static readonly List<string> ExistWoods = private static readonly List<string> ExistWoods =

View File

@ -1,6 +1,5 @@
using System; using BetterGenshinImpact.GameTask.Model;
using System.Threading; using System.Threading;
using BetterGenshinImpact.GameTask.Model;
namespace BetterGenshinImpact.GameTask.AutoWood; namespace BetterGenshinImpact.GameTask.AutoWood;

View File

@ -1,5 +1,4 @@
using BetterGenshinImpact.GameTask.Common.Element.Assets; using BetterGenshinImpact.GameTask.Common.Element.Assets;
using BetterGenshinImpact.GameTask.Model;
using BetterGenshinImpact.GameTask.Model.Area; using BetterGenshinImpact.GameTask.Model.Area;
namespace BetterGenshinImpact.GameTask.Common.BgiVision; namespace BetterGenshinImpact.GameTask.Common.BgiVision;

View File

@ -1,11 +1,9 @@
using System; using BetterGenshinImpact.Core.Recognition.OpenCv;
using System.Diagnostics;
using BetterGenshinImpact.Core.Recognition.OpenCv;
using BetterGenshinImpact.Core.Recognition.OpenCv.FeatureMatch; using BetterGenshinImpact.Core.Recognition.OpenCv.FeatureMatch;
using BetterGenshinImpact.GameTask.Common.Element.Assets; using BetterGenshinImpact.GameTask.Common.Element.Assets;
using BetterGenshinImpact.Helpers.Extensions;
using BetterGenshinImpact.Model; using BetterGenshinImpact.Model;
using OpenCvSharp; using OpenCvSharp;
using System.Diagnostics;
namespace BetterGenshinImpact.GameTask.Common.Map; namespace BetterGenshinImpact.GameTask.Common.Map;

View File

@ -104,17 +104,14 @@ public class CameraOrientation
// }; // };
// VisionContext.Instance().DrawContent.PutLine("camera", line); // VisionContext.Instance().DrawContent.PutLine("camera", line);
if (pen == null) pen ??= new Pen(Color.Yellow, 1);
{
pen = new Pen(Color.Yellow, 1);
}
region.DrawLine(center.X, center.Y, (int)x1, (int)y1, name, pen); region.DrawLine(center.X, center.Y, (int)x1, (int)y1, name, pen);
} }
static List<int> FindPeaks(float[] data) static List<int> FindPeaks(float[] data)
{ {
List<int> peakIndices = new List<int>(); List<int> peakIndices = [];
for (int i = 1; i < data.Length - 1; i++) for (int i = 1; i < data.Length - 1; i++)
{ {

View File

@ -1,14 +1,9 @@
using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.Core.Recognition.OpenCv.FeatureMatch;
using BetterGenshinImpact.Core.Recognition.OpenCv.FeatureMatch; using BetterGenshinImpact.Helpers.Extensions;
using BetterGenshinImpact.GameTask.Common.Element.Assets;
using BetterGenshinImpact.Model; using BetterGenshinImpact.Model;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using OpenCvSharp; using OpenCvSharp;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using BetterGenshinImpact.Helpers.Extensions;
using Point = OpenCvSharp.Point;
using Size = OpenCvSharp.Size; using Size = OpenCvSharp.Size;
namespace BetterGenshinImpact.GameTask.Common.Map; namespace BetterGenshinImpact.GameTask.Common.Map;
@ -19,7 +14,7 @@ public class EntireMap : Singleton<EntireMap>
public static readonly Size TemplateSize = new(240, 135); public static readonly Size TemplateSize = new(240, 135);
// 对无用部分进行裁剪左160上80下96 // 对无用部分进行裁剪左160上80下96
public static readonly Rect TemplateSizeRoi = new Rect(20, 10, TemplateSize.Width - 20, TemplateSize.Height - 22); public static readonly Rect TemplateSizeRoi = new(20, 10, TemplateSize.Width - 20, TemplateSize.Height - 22);
/// <summary> /// <summary>
/// 主要地图缩小1024的模板 /// 主要地图缩小1024的模板

View File

@ -1,8 +1,8 @@
using System; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
namespace BetterGenshinImpact.GameTask.Common; namespace BetterGenshinImpact.GameTask.Common;

View File

@ -1,12 +1,11 @@
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
using BetterGenshinImpact.GameTask.Model; using BetterGenshinImpact.GameTask.Model.Area;
using Fischless.GameCapture; using Fischless.GameCapture;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using System.Drawing; using System.Drawing;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BetterGenshinImpact.GameTask.Model.Area;
namespace BetterGenshinImpact.GameTask.Common; namespace BetterGenshinImpact.GameTask.Common;

View File

@ -1,9 +1,4 @@
using BetterGenshinImpact.Core.Config; namespace BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.Model;
using Compunet.YoloV8;
using System;
namespace BetterGenshinImpact.GameTask.Common;
// [Obsolete] // [Obsolete]
// public class YoloManager : Singleton<YoloManager>, IDisposable // public class YoloManager : Singleton<YoloManager>, IDisposable

View File

@ -1,11 +1,5 @@
using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.Core.Recognition.OpenCv;
using CommunityToolkit.Mvvm.Messaging.Messages;
using CommunityToolkit.Mvvm.Messaging;
using OpenCvSharp;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using BetterGenshinImpact.Core.Script.Dependence.Model.TimerConfig; using BetterGenshinImpact.Core.Script.Dependence.Model.TimerConfig;
using BetterGenshinImpact.GameTask.AutoFight.Assets; using BetterGenshinImpact.GameTask.AutoFight.Assets;
using BetterGenshinImpact.GameTask.AutoFishing.Assets; using BetterGenshinImpact.GameTask.AutoFishing.Assets;
@ -20,7 +14,13 @@ using BetterGenshinImpact.GameTask.Placeholder;
using BetterGenshinImpact.GameTask.QuickSereniteaPot.Assets; using BetterGenshinImpact.GameTask.QuickSereniteaPot.Assets;
using BetterGenshinImpact.GameTask.QuickTeleport.Assets; using BetterGenshinImpact.GameTask.QuickTeleport.Assets;
using BetterGenshinImpact.View.Drawable; using BetterGenshinImpact.View.Drawable;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using OpenCvSharp;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace BetterGenshinImpact.GameTask; namespace BetterGenshinImpact.GameTask;
@ -63,7 +63,7 @@ internal class GameTaskManager
loadedTriggers.ForEach(i => i.IsEnabled = true); loadedTriggers.ForEach(i => i.IsEnabled = true);
} }
loadedTriggers = loadedTriggers.OrderByDescending(i => i.Priority).ToList(); loadedTriggers = [.. loadedTriggers.OrderByDescending(i => i.Priority)];
return loadedTriggers; return loadedTriggers;
} }

View File

@ -1,5 +1,4 @@
using BetterGenshinImpact.GameTask.Model.Area; using BetterGenshinImpact.GameTask.Model.Area;
using BetterGenshinImpact.Helpers;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;

View File

@ -1,5 +1,5 @@
using System; using OpenCvSharp;
using OpenCvSharp; using System;
namespace BetterGenshinImpact.GameTask.Model.Area.Converter; namespace BetterGenshinImpact.GameTask.Model.Area.Converter;

View File

@ -2,7 +2,6 @@
using BetterGenshinImpact.View.Drawable; using BetterGenshinImpact.View.Drawable;
using OpenCvSharp; using OpenCvSharp;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Threading; using System.Threading;

View File

@ -1,6 +1,5 @@
using BetterGenshinImpact.Model; using BetterGenshinImpact.Model;
using OpenCvSharp; using OpenCvSharp;
using System.Threading;
namespace BetterGenshinImpact.GameTask.Model; namespace BetterGenshinImpact.GameTask.Model;

View File

@ -1,5 +1,4 @@
using BetterGenshinImpact.Helpers; using Vanara.PInvoke;
using Vanara.PInvoke;
namespace BetterGenshinImpact.GameTask.Model; namespace BetterGenshinImpact.GameTask.Model;

View File

@ -1,5 +1,5 @@
using System.Threading; using BetterGenshinImpact.GameTask.Model.Enum;
using BetterGenshinImpact.GameTask.Model.Enum; using System.Threading;
namespace BetterGenshinImpact.GameTask.Model; namespace BetterGenshinImpact.GameTask.Model;

View File

@ -1,8 +1,8 @@
using BetterGenshinImpact.GameTask.Model.Area; using BetterGenshinImpact.GameTask.Model.Area;
using BetterGenshinImpact.Helpers; using BetterGenshinImpact.Helpers;
using OpenCvSharp;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using OpenCvSharp;
using Vanara.PInvoke; using Vanara.PInvoke;
using Size = System.Drawing.Size; using Size = System.Drawing.Size;

View File

@ -1,5 +1,5 @@
using System.Threading; using BetterGenshinImpact.GameTask.Model.Enum;
using BetterGenshinImpact.GameTask.Model.Enum; using System.Threading;
namespace BetterGenshinImpact.GameTask.Model; namespace BetterGenshinImpact.GameTask.Model;

View File

@ -1,16 +1,8 @@
using BetterGenshinImpact.Core.Recognition.OpenCv; using OpenCvSharp;
using BetterGenshinImpact.GameTask.Common.Map;
using BetterGenshinImpact.View.Drawable;
using OpenCvSharp;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.GameTask.Common.BgiVision;
using BetterGenshinImpact.GameTask.Common.Element.Assets;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using Point = OpenCvSharp.Point; using Point = OpenCvSharp.Point;
using Size = OpenCvSharp.Size; using Size = OpenCvSharp.Size;
@ -313,7 +305,7 @@ public class TestTrigger : ITaskTrigger
static List<int> FindPeaks(float[] data) static List<int> FindPeaks(float[] data)
{ {
List<int> peakIndices = new List<int>(); List<int> peakIndices = [];
for (int i = 1; i < data.Length - 1; i++) for (int i = 1; i < data.Length - 1; i++)
{ {

View File

@ -1,10 +1,4 @@
using System; namespace BetterGenshinImpact.GameTask.QuickForge
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BetterGenshinImpact.GameTask.QuickForge
{ {
internal class QuickForgeTask internal class QuickForgeTask
{ {

View File

@ -25,8 +25,8 @@ public class QuickTeleportAssets : BaseAssets<QuickTeleportAssets>
(int)(100 * AssetScale), (int)(100 * AssetScale),
(int)(50 * AssetScale), (int)(50 * AssetScale),
CaptureRect.Height - (int)(200 * AssetScale)); CaptureRect.Height - (int)(200 * AssetScale));
MapChooseIconRoList = new List<RecognitionObject> MapChooseIconRoList =
{ [
BuildMapChooseIconRo("TeleportWaypoint.png"), BuildMapChooseIconRo("TeleportWaypoint.png"),
BuildMapChooseIconRo("StatueOfTheSeven.png"), BuildMapChooseIconRo("StatueOfTheSeven.png"),
BuildMapChooseIconRo("Domain.png"), BuildMapChooseIconRo("Domain.png"),
@ -34,7 +34,7 @@ public class QuickTeleportAssets : BaseAssets<QuickTeleportAssets>
BuildMapChooseIconRo("PortableWaypoint.png"), BuildMapChooseIconRo("PortableWaypoint.png"),
BuildMapChooseIconRo("Mansion.png"), BuildMapChooseIconRo("Mansion.png"),
BuildMapChooseIconRo("SubSpaceWaypoint.png"), BuildMapChooseIconRo("SubSpaceWaypoint.png"),
}; ];
MapChooseIconGreyMatList = MapChooseIconRoList.ConvertAll(x => x.TemplateImageGreyMat ?? new Mat()); MapChooseIconGreyMatList = MapChooseIconRoList.ConvertAll(x => x.TemplateImageGreyMat ?? new Mat());
// 传送按钮宽泛的识别区域 // 传送按钮宽泛的识别区域

View File

@ -1,16 +1,15 @@
using BetterGenshinImpact.Core.Recognition.OCR; using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Core.Recognition;
using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.Core.Recognition.OpenCv;
using BetterGenshinImpact.GameTask.Common; using BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.GameTask.Model.Area;
using BetterGenshinImpact.GameTask.QuickTeleport.Assets; using BetterGenshinImpact.GameTask.QuickTeleport.Assets;
using BetterGenshinImpact.Model;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using OpenCvSharp; using OpenCvSharp;
using System; using System;
using System.Linq; using System.Linq;
using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Model;
using System.Windows.Forms; using System.Windows.Forms;
using BetterGenshinImpact.Core.Recognition;
using BetterGenshinImpact.GameTask.Model.Area;
namespace BetterGenshinImpact.GameTask.QuickTeleport; namespace BetterGenshinImpact.GameTask.QuickTeleport;
@ -129,7 +128,7 @@ internal class QuickTeleportTrigger : ITaskTrigger
// 按高度排序 // 按高度排序
if (rResultList.Count > 0) if (rResultList.Count > 0)
{ {
rResultList = rResultList.OrderBy(x => x.Y).ToList(); rResultList = [.. rResultList.OrderBy(x => x.Y)];
// 点击最高的 // 点击最高的
foreach (var iconRect in rResultList) foreach (var iconRect in rResultList)
{ {

View File

@ -1,7 +1,6 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Vanara.PInvoke; using Vanara.PInvoke;
@ -62,7 +61,7 @@ public class SystemControl
foreach (var name in names) foreach (var name in names)
{ {
var pros = Process.GetProcessesByName(name); var pros = Process.GetProcessesByName(name);
if (pros.Any()) if (pros.Length is not 0)
{ {
return pros[0].MainWindowHandle; return pros[0].MainWindowHandle;
} }

View File

@ -1,11 +1,11 @@
using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Core.Simulator;
using BetterGenshinImpact.GameTask.Model; using BetterGenshinImpact.GameTask.Model;
using BetterGenshinImpact.Genshin.Settings; using BetterGenshinImpact.Genshin.Settings;
using BetterGenshinImpact.Helpers; using BetterGenshinImpact.Helpers;
using BetterGenshinImpact.Service; using BetterGenshinImpact.Service;
using System; using System;
using System.Threading; using System.Threading;
using BetterGenshinImpact.Core.Simulator;
namespace BetterGenshinImpact.GameTask namespace BetterGenshinImpact.GameTask
{ {

View File

@ -2,10 +2,15 @@
using BetterGenshinImpact.GameTask.AutoDomain; using BetterGenshinImpact.GameTask.AutoDomain;
using BetterGenshinImpact.GameTask.AutoFight; using BetterGenshinImpact.GameTask.AutoFight;
using BetterGenshinImpact.GameTask.AutoGeniusInvokation; using BetterGenshinImpact.GameTask.AutoGeniusInvokation;
using BetterGenshinImpact.GameTask.AutoMusicGame;
using BetterGenshinImpact.GameTask.AutoSkip;
using BetterGenshinImpact.GameTask.AutoSkip.Model;
using BetterGenshinImpact.GameTask.AutoTrackPath;
using BetterGenshinImpact.GameTask.AutoWood; using BetterGenshinImpact.GameTask.AutoWood;
using BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.GameTask.Model; using BetterGenshinImpact.GameTask.Model;
using BetterGenshinImpact.GameTask.Model.Area;
using BetterGenshinImpact.GameTask.Model.Enum; using BetterGenshinImpact.GameTask.Model.Enum;
using BetterGenshinImpact.Genshin.Settings;
using BetterGenshinImpact.Helpers; using BetterGenshinImpact.Helpers;
using BetterGenshinImpact.View; using BetterGenshinImpact.View;
using Fischless.GameCapture; using Fischless.GameCapture;
@ -21,13 +26,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BetterGenshinImpact.GameTask.AutoSkip;
using BetterGenshinImpact.GameTask.AutoSkip.Model;
using Vanara.PInvoke; using Vanara.PInvoke;
using BetterGenshinImpact.GameTask.AutoMusicGame;
using BetterGenshinImpact.GameTask.AutoTrackPath;
using BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.GameTask.Model.Area;
namespace BetterGenshinImpact.GameTask namespace BetterGenshinImpact.GameTask
{ {
@ -65,9 +64,9 @@ namespace BetterGenshinImpact.GameTask
private static readonly object _bitmapLocker = new(); private static readonly object _bitmapLocker = new();
private static readonly object _triggerListLocker = new(); private static readonly object _triggerListLocker = new();
public event EventHandler UiTaskStopTickEvent; public event EventHandler? UiTaskStopTickEvent;
public event EventHandler UiTaskStartTickEvent; public event EventHandler? UiTaskStartTickEvent;
public TaskTriggerDispatcher() public TaskTriggerDispatcher()
{ {
@ -229,7 +228,10 @@ namespace BetterGenshinImpact.GameTask
} }
} }
public void Dispose() => Stop(); public void Dispose()
{
Stop();
}
public void Tick(object? sender, EventArgs e) public void Tick(object? sender, EventArgs e)
{ {
@ -256,7 +258,7 @@ namespace BetterGenshinImpact.GameTask
_logger.LogInformation("游戏已退出BetterGI 自动停止截图器"); _logger.LogInformation("游戏已退出BetterGI 自动停止截图器");
} }
UiTaskStopTickEvent.Invoke(sender, e); UiTaskStopTickEvent?.Invoke(sender, e);
maskWindow.Invoke(maskWindow.Hide); maskWindow.Invoke(maskWindow.Hide);
return; return;
} }
@ -270,7 +272,7 @@ namespace BetterGenshinImpact.GameTask
if (TaskContext.Instance().SystemInfo.GameProcess.HasExited) if (TaskContext.Instance().SystemInfo.GameProcess.HasExited)
{ {
_logger.LogInformation("游戏已退出BetterGI 自动停止截图器"); _logger.LogInformation("游戏已退出BetterGI 自动停止截图器");
UiTaskStopTickEvent.Invoke(sender, e); UiTaskStopTickEvent?.Invoke(sender, e);
return; return;
} }
@ -426,8 +428,8 @@ namespace BetterGenshinImpact.GameTask
&& !SizeIsZero(_gameRect) && !SizeIsZero(currentRect)) && !SizeIsZero(_gameRect) && !SizeIsZero(currentRect))
{ {
_logger.LogError("► 游戏窗口大小发生变化 {W}x{H}->{CW}x{CH}, 自动重启截图器中...", _gameRect.Width, _gameRect.Height, currentRect.Width, currentRect.Height); _logger.LogError("► 游戏窗口大小发生变化 {W}x{H}->{CW}x{CH}, 自动重启截图器中...", _gameRect.Width, _gameRect.Height, currentRect.Width, currentRect.Height);
UiTaskStopTickEvent.Invoke(null, EventArgs.Empty); UiTaskStopTickEvent?.Invoke(null, EventArgs.Empty);
UiTaskStartTickEvent.Invoke(null, EventArgs.Empty); UiTaskStartTickEvent?.Invoke(null, EventArgs.Empty);
_logger.LogInformation("► 游戏窗口大小发生变化,截图器重启完成!"); _logger.LogInformation("► 游戏窗口大小发生变化,截图器重启完成!");
} }

View File

@ -1,10 +1,4 @@
using System; namespace BetterGenshinImpact.GameTask.UseActiveCode
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BetterGenshinImpact.GameTask.UseActiveCode
{ {
internal class UseActiveCodeTask internal class UseActiveCodeTask
{ {

View File

@ -1,26 +1,29 @@
using System; using BetterGenshinImpact.GameTask.Common;
using Microsoft.Extensions.Logging;
using Microsoft.Win32; using Microsoft.Win32;
using System;
using System.Collections.Frozen;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using BetterGenshinImpact.GameTask.Common;
using Microsoft.Extensions.Logging;
namespace BetterGenshinImpact.Genshin.Paths; namespace BetterGenshinImpact.Genshin.Paths;
internal class GameExePath internal partial class GameExePath
{ {
public static readonly FrozenSet<string> GameRegistryPaths = FrozenSet.ToFrozenSet(
[
@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\原神",
@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Genshin Impact",
// @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\云·原神",
]);
/// <summary> /// <summary>
/// 游戏路径(云原神除外) /// 游戏路径(云原神除外)
/// </summary> /// </summary>
public static string? GetWithoutCloud() public static string? GetWithoutCloud()
{ {
return new[] return GameRegistryPaths.Select(regKey => GetGameExePathFromRegistry(regKey, false)).FirstOrDefault(exePath => !string.IsNullOrEmpty(exePath));
{
@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\原神",
@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Genshin Impact",
// @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\云·原神",
}.Select(regKey => GetGameExePathFromRegistry(regKey, false)).FirstOrDefault(exePath => !string.IsNullOrEmpty(exePath));
} }
/// <summary> /// <summary>
@ -49,8 +52,8 @@ internal class GameExePath
if (File.Exists(configPath)) if (File.Exists(configPath))
{ {
var str = File.ReadAllText(configPath); var str = File.ReadAllText(configPath);
var installPath = Regex.Match(str, @"game_install_path=(.+)").Groups[1].Value.Trim(); var installPath = GameInstallPathRegex().Match(str).Groups[1].Value.Trim();
var exeName = Regex.Match(str, @"game_start_name=(.+)").Groups[1].Value.Trim(); var exeName = GameStartNameRegex().Match(str).Groups[1].Value.Trim();
var exePath = Path.GetFullPath(exeName, installPath); var exePath = Path.GetFullPath(exeName, installPath);
if (File.Exists(exePath)) if (File.Exists(exePath))
{ {
@ -66,4 +69,10 @@ internal class GameExePath
return null; return null;
} }
[GeneratedRegex(@"game_install_path=(.+)")]
private static partial Regex GameInstallPathRegex();
[GeneratedRegex(@"game_start_name=(.+)")]
private static partial Regex GameStartNameRegex();
} }

View File

@ -1,11 +1,11 @@
using Microsoft.Win32; using BetterGenshinImpact.GameTask.Common;
using Microsoft.Extensions.Logging;
using Microsoft.Win32;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using BetterGenshinImpact.GameTask.Common;
using Microsoft.Extensions.Logging;
namespace BetterGenshinImpact.Genshin.Settings; namespace BetterGenshinImpact.Genshin.Settings;

View File

@ -1,5 +1,4 @@
using BetterGenshinImpact.Service; using BetterGenshinImpact.Service;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Collections.Specialized; using System.Collections.Specialized;
@ -83,7 +82,7 @@ public class JsonCrudHelper<T> : ICrudHelper<T> where T : class
{ {
if (!File.Exists(_filePath)) if (!File.Exists(_filePath))
{ {
return new ObservableCollection<T>(); return [];
} }
var json = File.ReadAllText(_filePath); var json = File.ReadAllText(_filePath);

View File

@ -1,8 +1,7 @@
using System.Drawing; using OpenCvSharp;
using System.Drawing.Imaging; using System.Drawing;
using System.IO; using System.IO;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using OpenCvSharp;
namespace BetterGenshinImpact.Helpers.Extensions namespace BetterGenshinImpact.Helpers.Extensions
{ {

View File

@ -1,7 +1,6 @@
using BetterGenshinImpact.Core.Simulator; using BetterGenshinImpact.Core.Simulator;
using OpenCvSharp;
using System;
using Fischless.WindowsInput; using Fischless.WindowsInput;
using OpenCvSharp;
namespace BetterGenshinImpact.Helpers.Extensions; namespace BetterGenshinImpact.Helpers.Extensions;

Some files were not shown because too many files have changed in this diff Show More