Files
better-genshin-impact/BetterGenshinImpact/GameTask/AutoTrackPath/PathPointRecorder.cs
辉鸭蛋 9e41808326 独立与分层地图支持 (#1503)
* 抽象基础类

* 修改定义

* 抽象出Feature2D相关能力

* 新增地图基类实现

* 临时提交

* 迁移坐标计算

* 加载分层特征数据

* 新增独立地图 层岩巨渊,渊下宫,旧日之海

* 支持不切分特征点匹配

* 添加远古圣山,修改地图参数

* 提瓦特大陆的大地图匹配

* 提瓦特大陆地图大地图位置获取使用256级别的地图

* 替换大地图匹配类 BigMap.cs

* 替换小地图匹配类 EntireMap

* 修改tp的入参方式,删除无用类

* 兼容新提交的内容

* 修复类方法覆盖不生效的问题

* 修复定位问题,迁移部分 MapCoordinate 的代码。MapCoordinate 标记为废弃

* 更多坐标方法的迁移

* 修复不正确的坐标转换

* 是用正确的特征匹配

* 体积较小的地图动态生成特征

* 路径追踪窗体支持多地图

* 传送时切换独立地图地区

* 更新传送点信息

* 修改独立地图相关命名,使用 Scene(场景) 命名,和原神内部命名保持一致

* 录制支持多独立地图

* 修复地区切换失败的问题
2025-05-03 21:59:37 +08:00

102 lines
3.1 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.Core.Config;
using BetterGenshinImpact.Core.Recognition.OpenCv;
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
using BetterGenshinImpact.GameTask.AutoTrackPath.Model;
using BetterGenshinImpact.GameTask.Common.Element.Assets;
using BetterGenshinImpact.GameTask.Common.Map;
using BetterGenshinImpact.Helpers.Extensions;
using BetterGenshinImpact.Model;
using BetterGenshinImpact.Service;
using Microsoft.Extensions.Logging;
using OpenCvSharp;
using System;
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using BetterGenshinImpact.GameTask.Common.Map.Maps;
using BetterGenshinImpact.GameTask.Common.Map.Maps.Base;
using static BetterGenshinImpact.GameTask.Common.TaskControl;
namespace BetterGenshinImpact.GameTask.AutoTrackPath;
[Obsolete]
public class PathPointRecorder : Singleton<PathPointRecorder>
{
private Task? _recordTask;
private CancellationTokenSource? _recordTaskCts;
public void Switch()
{
try
{
if (_recordTask == null)
{
_recordTaskCts = new CancellationTokenSource();
_recordTask = RecordTask(_recordTaskCts.Token);
_recordTask.Start();
}
else
{
_recordTaskCts?.Cancel();
_recordTask = null;
}
}
catch (NormalEndException)
{
Logger.LogInformation("关闭路线录制");
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
public Task RecordTask(CancellationToken ct)
{
return new Task(() =>
{
GiPath way = new();
while (!ct.IsCancellationRequested)
{
try
{
Sleep(10, ct);
var ra = CaptureToRectArea();
// 小地图匹配
var tar = ElementAssets.Instance.PaimonMenuRo.TemplateImageGreyMat!;
var p = MatchTemplateHelper.MatchTemplate(ra.SrcGreyMat, tar, TemplateMatchModes.CCoeffNormed, null, 0.9);
if (p.X == 0 || p.Y == 0)
{
Sleep(50, ct);
continue;
}
var p2 = MapManager.GetMap(MapTypes.Teyvat).GetMiniMapPosition(new Mat(ra.SrcGreyMat, new Rect(p.X + 24, p.Y - 15, 210, 210)));
if (!p2.IsEmpty())
{
way.AddPoint(p2);
Debug.WriteLine($"AddPoint: {p2}");
}
else
{
Sleep(50, ct);
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
#if DEBUG
File.WriteAllText(Global.Absolute($@"log\way\{DateTime.Now:yyyy-MM-dd HHmmssffff}.json"), JsonSerializer.Serialize(way, ConfigService.JsonOptions));
#endif
Logger.LogInformation("路线录制结束");
}, ct);
}
}