add GetBigMapZoomLevel

This commit is contained in:
辉鸭蛋 2024-12-28 21:29:42 +08:00
parent 71f2c2f52e
commit b83017f52e
4 changed files with 74 additions and 22 deletions

View File

@ -34,6 +34,7 @@ public class TpTask(CancellationToken ct)
public static double ReviveStatueOfTheSevenPointX = 2296.4;
public static double ReviveStatueOfTheSevenPointY = -824.4;
public static int currentZoomLevel = 4;
/// <summary>
/// 通过大地图传送到指定坐标最近的传送点,然后移动到指定坐标
/// </summary>
@ -52,14 +53,13 @@ public class TpTask(CancellationToken ct)
}
// 计算传送点位置离哪个地图切换后的中心点最近,切换到该地图
await SwitchRecentlyCountryMap(x, y, country);
// 计算坐标后点击
var bigMapInAllMapRect = GetBigMapRect();
while (!IsPointInBigMapWindow(bigMapInAllMapRect, x, y) || currentZoomLevel>2) // 左上角 350x400也属于禁止点击区域
while (!IsPointInBigMapWindow(bigMapInAllMapRect, x, y) || currentZoomLevel > 2) // 左上角 350x400也属于禁止点击区域
{
Debug.WriteLine($"({x},{y}) 不在 {bigMapInAllMapRect} 内,继续移动");
Logger.LogInformation("传送点不在当前大地图范围内,继续移动");
@ -89,6 +89,7 @@ public class TpTask(CancellationToken ct)
break;
}
}
Logger.LogInformation("传送完成");
return (x, y);
}
@ -153,6 +154,7 @@ public class TpTask(CancellationToken ct)
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_M);
await Delay(1000, ct);
}
await AdjustMapZoomLevel(initialZoomLevel);
currentZoomLevel = initialZoomLevel;
Logger.LogInformation($"调整缩放等级为{initialZoomLevel},地图移动过程中不要操作鼠标中键。");
@ -192,7 +194,7 @@ public class TpTask(CancellationToken ct)
{
// 获取当前地图中心点并计算到目标传送点的初始偏移
// await AdjustMapZoomLevel(mapZoomLevel);
var bigMapCenterPoint = GetPositionFromBigMap(); // 初始中心
var bigMapCenterPoint = GetPositionFromBigMap(); // 初始中心
var newBigMapCenterPoint = bigMapCenterPoint;
var (xOffset, yOffset) = (x - bigMapCenterPoint.X, y - bigMapCenterPoint.Y);
// double distance = Math.Sqrt(xOffset * xOffset + yOffset * yOffset);
@ -214,11 +216,12 @@ public class TpTask(CancellationToken ct)
catch (Exception)
{
newBigMapCenterPoint = new Point2f(
(float)(bigMapCenterPoint.X + xOffset * moveMouseX / totalMoveMouseX),
(float)(bigMapCenterPoint.Y + yOffset * moveMouseY / totalMoveMouseY)
);
(float)(bigMapCenterPoint.X + xOffset * moveMouseX / totalMoveMouseX),
(float)(bigMapCenterPoint.Y + yOffset * moveMouseY / totalMoveMouseY)
);
// 利用移动鼠标的距离获取新的中心
}
// 本次移动的距离
double diffMapX = Math.Abs(newBigMapCenterPoint.X - bigMapCenterPoint.X);
double diffMapY = Math.Abs(newBigMapCenterPoint.Y - bigMapCenterPoint.Y);
@ -240,8 +243,10 @@ public class TpTask(CancellationToken ct)
Debug.WriteLine($"在 {iteration} 迭代后,已经接近目标点,不再进一步调整。");
break;
}
while (mouseDistance < 200 && currentZoomLevel > 2)
{ // 放大地图
{
// 放大地图
await AdjustMapZoomLevel(true);
totalMoveMouseX *= (currentZoomLevel) / (currentZoomLevel - 1);
totalMoveMouseY *= (currentZoomLevel) / (currentZoomLevel - 1);
@ -278,16 +283,19 @@ public class TpTask(CancellationToken ct)
{
GameCaptureRegion.GameRegionClick((rect, scale) => (50 * scale, 650 * scale));
}
await Delay(50, ct);
}
public async Task AdjustMapZoomLevel(int zoomLevel)
{
for (int i = 0; i < 5; i++)
{
await AdjustMapZoomLevel(false);
}
await Delay(200, ct);
for (int i = 0; i < 6-zoomLevel; i++)
for (int i = 0; i < 6 - zoomLevel; i++)
{
await AdjustMapZoomLevel(true);
}
@ -330,7 +338,7 @@ public class TpTask(CancellationToken ct)
// 随机起点以避免地图移动无效
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)));
rect.Height / 2d + Random.Shared.Next(-rect.Height / 6, rect.Height / 6)));
Simulation.SendInput.Mouse.LeftButtonDown();
for (var i = 0; i < steps; i++)
@ -338,11 +346,11 @@ public class TpTask(CancellationToken ct)
Simulation.SendInput.Mouse.MoveMouseBy(stepX[i], stepY[i]);
await Delay(stepIntervalMilliseconds, ct);
}
Simulation.SendInput.Mouse.LeftButtonUp();
}
public Point2f GetPositionFromBigMap()
{
return GetBigMapCenterPoint();
@ -440,6 +448,7 @@ public class TpTask(CancellationToken ct)
country = tpPosition.Country;
}
}
// todo: 识别当前国家
return (recentX, recentY, country);
}
@ -469,6 +478,7 @@ public class TpTask(CancellationToken ct)
return false;
}
}
string minCountry = "当前位置";
foreach (var (country, position) in MapLazyAssets.Instance.CountryPositions)
{
@ -483,10 +493,11 @@ public class TpTask(CancellationToken ct)
Logger.LogDebug("离目标传送点最近的区域是:{Country}", minCountry);
if (minCountry != "当前位置")
{
if(forceCountry != null)
if (forceCountry != null)
{
minCountry = forceCountry;
}
GameCaptureRegion.GameRegionClick((rect, scale) => (rect.Width - 160 * scale, rect.Height - 60 * scale));
await Delay(300, ct);
var ra = CaptureToRectArea();
@ -505,7 +516,6 @@ public class TpTask(CancellationToken ct)
}
public async Task Tp(string name)
{
// 通过大地图传送到指定传送点
@ -610,6 +620,26 @@ public class TpTask(CancellationToken ct)
break;
}
}
return hasMapChooseIcon;
}
}
/// <summary>
/// 给定的映射关系可以表示成 (x, y) 对的形式,其中 x 是输入值y 是输出值
/// 1 - 1
/// 0.8 - 2
/// 0.6 - 3
/// 0.4 - 4
/// 0.2 - 5
/// 0 - 6
/// y=5x+6
/// </summary>
/// <param name="region"></param>
/// <returns></returns>
private int GetBigMapZoomLevel(ImageRegion region)
{
var s = Bv.GetBigMapScale(region);
// 1~6 的缩放等级
return (int)(-5 * s) + 6;
}
}

View File

@ -58,7 +58,7 @@ public static partial class Bv
return false;
}
/// <summary>
/// 在任意可以关闭的UI界面识别关闭按钮
/// </summary>
@ -111,6 +111,22 @@ public static partial class Bv
return captureRa.Find(QuickTeleportAssets.Instance.MapUndergroundSwitchButtonRo).IsExist();
}
public static double GetBigMapScale(ImageRegion region)
{
var scaleRa = region.Find(QuickTeleportAssets.Instance.MapScaleButtonRo);
if (scaleRa.IsEmpty())
{
throw new Exception("当前未处于大地图界面不能使用GetBigMapScale方法");
}
// 452 ~ 627 间隔 35 和截图有关的截图高24
var start = QuickTeleportAssets.MapScaleButton1080StartY;
var end = QuickTeleportAssets.MapScaleButton1080EndY;
var cur = (scaleRa.Y + scaleRa.Height / 2.0) * TaskContext.Instance().SystemInfo.ZoomOutMax1080PRatio; // 转换到1080p坐标系,主要是小于1080p的情况
return (end * 1.0 - cur) / (end - start);
}
public static MotionStatus GetMotionStatus(ImageRegion captureRa)
{
var spaceExist = captureRa.Find(ElementAssets.Instance.SpaceKey).IsExist();
@ -224,4 +240,4 @@ public enum MotionStatus
Normal, // 正常
Fly, // 飞行
Climb, // 攀爬
}
}

View File

@ -18,6 +18,9 @@ public class QuickTeleportAssets : BaseAssets<QuickTeleportAssets>
public RecognitionObject MapUndergroundSwitchButtonRo;
public RecognitionObject MapUndergroundToGroundButtonRo;
public const int MapScaleButton1080StartY = 452;
public const int MapScaleButton1080EndY = 627;
private QuickTeleportAssets()
{

View File

@ -29,6 +29,7 @@ using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using BetterGenshinImpact.GameTask.Model.Area;
using BetterGenshinImpact.GameTask.QuickTeleport.Assets;
using Vanara.PInvoke;
using HotKeySettingModel = BetterGenshinImpact.Model.HotKeySettingModel;
@ -581,13 +582,15 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel
// 拾取物品
// Task.Run(async () => { await new ScanPickTask().Start(new CancellationToken()); });
Simulation.SendInput.Keyboard.KeyDown(false, User32.VK.VK_LMENU);
// TaskContext.Instance().PostMessageSimulator.KeyDown(User32.VK.VK_MENU);
Thread.Sleep(500);
GameCaptureRegion.GameRegion1080PPosMove(200, 100);
Thread.Sleep(500);
// TaskContext.Instance().PostMessageSimulator.KeyUp(User32.VK.VK_MENU);
Simulation.SendInput.Keyboard.KeyUp(false, User32.VK.VK_LMENU);
// Simulation.SendInput.Keyboard.KeyDown(false, User32.VK.VK_LMENU);
// // TaskContext.Instance().PostMessageSimulator.KeyDown(User32.VK.VK_MENU);
// Thread.Sleep(500);
// GameCaptureRegion.GameRegion1080PPosMove(200, 100);
// Thread.Sleep(500);
// // TaskContext.Instance().PostMessageSimulator.KeyUp(User32.VK.VK_MENU);
// Simulation.SendInput.Keyboard.KeyUp(false, User32.VK.VK_LMENU);
TaskControl.Logger.LogInformation("大地图界面缩放按钮位置:{Position}", Bv.GetBigMapScale( TaskControl.CaptureToRectArea()));
}
));
debugDirectory.Children.Add(new HotKeySettingModel(