Files
better-genshin-impact/BetterGenshinImpact/GameTask/Model/SystemInfo.cs
FishmanTheMurloc 57d33c4312 又一波钓鱼优化 (#1301)
* GetFishBarRect方法添加更复杂的算法,并为其配备独立的单元测试,和分离难度较大的测试用例(未熟练时两侧出现黄色动态折线的情况);GetFishBoxArea行为去掉拉条框初始位置必须位于屏幕中轴线的条件,并添加其后续Fishing行为的单元测试来验证可行性;EnterFishingMode行为使用结束时间来代替Sleep,并添加整体超时时间;添加一个鱼咬钩的假阳性测试用例仅供娱乐

* 补充GetFishBarRect算法,使通过遗漏的测试"20250314002439020_Fishing_Succeeded.png"

* 拉条增加1秒未检测持续时间以应对瞬间丢失拉条框的情况;新增一个检查提竿结果的行为;新增一个检查开始钓一条鱼的初始状态的方法,以应对行为状态错配的情况;一些行为将Sleep优化为DateTime;修改上述改动对应的单元测试

* 解决合并冲突剩余问题,删掉ImageRegion的Bitmap构造函数重载

* 提供给测试用例初始化的 SystemInfo、TaskContext 方法,使用 InitForTest 即可

* InitForTest

* 和鸭蛋昨夜的提交撞车了。。。抽象了ISystemInto供单元测试实例化Fake类;给BaseAssets类定义了成员字段systemInfo(我想,既然都是图片模板数据集,如此定义是合理的),供继承类AutoFishingAssets使用,并定义了其在单元测试的派生类;添加了一个900p的选取鱼饵测试用例;blackboard改为负责携带AutoFishingAssets,并将其实例化时机挪到独立任务的Start方法中,避免由于TaskContext尚未初始化导致获取到的SystemInfo为空

* 一个特殊的测试用例:抛竿的瞬间、开始检测咬杆时遇到了假阳性

* Revert "InitForTest"

This reverts commit 225e9783a7.

* Revert "提供给测试用例初始化的 SystemInfo、TaskContext 方法,使用 InitForTest 即可"

This reverts commit 610c57263a.

* 为始终没有找到落点的情况添加计数,在第3次时直接退出,并添加此情况的单元测试

---------

Co-authored-by: 辉鸭蛋 <huiyadanli@gmail.com>
2025-03-18 19:51:42 +08:00

104 lines
3.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using BetterGenshinImpact.GameTask.Model.Area;
using BetterGenshinImpact.Helpers;
using OpenCvSharp;
using System;
using System.Diagnostics;
using Vanara.PInvoke;
using Size = System.Drawing.Size;
namespace BetterGenshinImpact.GameTask.Model
{
public class SystemInfo : ISystemInfo
{
/// <summary>
/// 显示器分辨率 无缩放
/// </summary>
public Size DisplaySize { get; }
/// <summary>
/// 游戏窗口内分辨率
/// </summary>
public RECT GameScreenSize { get; }
/// <summary>
/// 以1080P为标准的素材缩放比例,不会大于1
/// 与 ZoomOutMax1080PRatio 相等
/// </summary>
public double AssetScale { get; } = 1;
/// <summary>
/// 游戏区域比1080P缩小的比例
/// 最大值为1
/// </summary>
public double ZoomOutMax1080PRatio { get; } = 1;
/// <summary>
/// 捕获游戏区域缩放至1080P的比例
/// </summary>
public double ScaleTo1080PRatio { get; }
/// <summary>
/// 捕获窗口区域 和实际游戏画面一致
/// CaptureAreaRect = GameScreenSize or GameWindowRect
/// </summary>
public RECT CaptureAreaRect { get; set; }
/// <summary>
/// 捕获窗口区域 大于1080P则为1920x1080
/// </summary>
public Rect ScaleMax1080PCaptureRect { get; set; }
public Process GameProcess { get; }
public string GameProcessName { get; }
public int GameProcessId { get; }
public DesktopRegion DesktopRectArea { get; }
public SystemInfo(IntPtr hWnd)
{
var p = SystemControl.GetProcessByHandle(hWnd);
GameProcess = p ?? throw new ArgumentException("通过句柄获取游戏进程失败");
GameProcessName = GameProcess.ProcessName;
GameProcessId = GameProcess.Id;
DisplaySize = PrimaryScreen.WorkingArea;
DesktopRectArea = new DesktopRegion();
// 判断最小化
if (User32.IsIconic(hWnd))
{
throw new ArgumentException("游戏窗口不能最小化");
}
// 注意截图区域要和游戏窗口实际区域一致
// todo 窗口移动后?
GameScreenSize = SystemControl.GetGameScreenRect(hWnd);
if (GameScreenSize.Width < 800 || GameScreenSize.Height < 600)
{
throw new ArgumentException("游戏窗口分辨率不得小于 800x600 ");
}
// 0.28 改动,素材缩放比例不可以超过 1也就是图像识别时分辨率大于 1920x1080 的情况下直接进行缩放
if (GameScreenSize.Width < 1920)
{
ZoomOutMax1080PRatio = GameScreenSize.Width / 1920d;
AssetScale = ZoomOutMax1080PRatio;
}
ScaleTo1080PRatio = GameScreenSize.Width / 1920d; // 1080P 为标准
CaptureAreaRect = SystemControl.GetCaptureRect(hWnd);
if (CaptureAreaRect.Width > 1920)
{
var scale = CaptureAreaRect.Width / 1920d;
ScaleMax1080PCaptureRect = new Rect(CaptureAreaRect.X, CaptureAreaRect.Y, 1920, (int)(CaptureAreaRect.Height / scale));
}
else
{
ScaleMax1080PCaptureRect = new Rect(CaptureAreaRect.X, CaptureAreaRect.Y, CaptureAreaRect.Width, CaptureAreaRect.Height);
}
}
}
}