Skip to content

Commit 4a745f2

Browse files
committed
如果首个点是非TP点位,强制设置在这个点位附近优先做局部匹配
1 parent 37493d0 commit 4a745f2

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

BetterGenshinImpact/GameTask/AutoPathing/PathExecutor.cs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public PathingPartyConfig PartyConfig
9494

9595
//跳过除走路径以外的操作
9696
private bool _skipOtherOperations = false;
97-
97+
9898
// 最近一次获取派遣奖励的时间
9999
private DateTime _lastGetExpeditionRewardsTime = DateTime.MinValue;
100100

@@ -169,6 +169,13 @@ public async Task Pathing(PathingTask task)
169169
try
170170
{
171171
await ResolveAnomalies(); // 异常场景处理
172+
173+
// 如果首个点是非TP点位,强制设置在这个点位附近优先做局部匹配
174+
if (waypoints[0].Type != WaypointType.Teleport.Code)
175+
{
176+
Navigation.SetPrevPosition((float)waypoints[0].X, (float)waypoints[0].Y);
177+
}
178+
172179
foreach (var waypoint in waypoints) // 一条路径
173180
{
174181
CurWaypoint = (waypoints.FindIndex(wps => wps == waypoint), waypoint);
@@ -189,7 +196,7 @@ public async Task Pathing(PathingTask task)
189196
// 考虑到方位点大概率是作为执行action的最后一个点,所以放在此处处理,不和传送点一样单独处理
190197
await FaceTo(waypoint);
191198
}
192-
else if(waypoint.Action != ActionEnum.UpDownGrabLeaf.Code)
199+
else if (waypoint.Action != ActionEnum.UpDownGrabLeaf.Code)
193200
{
194201
await MoveTo(waypoint);
195202
}
@@ -202,7 +209,8 @@ public async Task Pathing(PathingTask task)
202209
}
203210

204211
//skipOtherOperations如果重试,则跳过相关操作,
205-
if ((!string.IsNullOrEmpty(waypoint.Action) && !_skipOtherOperations) || waypoint.Action == ActionEnum.CombatScript.Code)
212+
if ((!string.IsNullOrEmpty(waypoint.Action) && !_skipOtherOperations) ||
213+
waypoint.Action == ActionEnum.CombatScript.Code)
206214
{
207215
// 执行 action
208216
await AfterMoveToTarget(waypoint);
@@ -264,7 +272,7 @@ private bool IsTargetPoint(WaypointForTrack waypoint)
264272
{
265273
return false;
266274
}
267-
275+
268276

269277
var action = ActionEnum.GetEnumByCode(waypoint.Action);
270278
if (action is not null && action.UseWaypointTypeEnum != ActionUseWaypointTypeEnum.Custom)
@@ -333,13 +341,15 @@ private void LogScreenResolution()
333341
var gameScreenSize = SystemControl.GetGameScreenRect(TaskContext.Instance().GameHandle);
334342
if (gameScreenSize.Width * 9 != gameScreenSize.Height * 16)
335343
{
336-
Logger.LogError("游戏窗口分辨率不是 16:9 !当前分辨率为 {Width}x{Height} , 非 16:9 分辨率的游戏无法正常使用地图追踪功能!", gameScreenSize.Width, gameScreenSize.Height);
344+
Logger.LogError("游戏窗口分辨率不是 16:9 !当前分辨率为 {Width}x{Height} , 非 16:9 分辨率的游戏无法正常使用地图追踪功能!",
345+
gameScreenSize.Width, gameScreenSize.Height);
337346
throw new Exception("游戏窗口分辨率不是 16:9 !无法使用地图追踪功能!");
338347
}
339348

340349
if (gameScreenSize.Width < 1920 || gameScreenSize.Height < 1080)
341350
{
342-
Logger.LogError("游戏窗口分辨率小于 1920x1080 !当前分辨率为 {Width}x{Height} , 小于 1920x1080 的分辨率的游戏地图追踪的效果非常差!", gameScreenSize.Width, gameScreenSize.Height);
351+
Logger.LogError("游戏窗口分辨率小于 1920x1080 !当前分辨率为 {Width}x{Height} , 小于 1920x1080 的分辨率的游戏地图追踪的效果非常差!",
352+
gameScreenSize.Width, gameScreenSize.Height);
343353
throw new Exception("游戏窗口分辨率小于 1920x1080 !无法使用地图追踪功能!");
344354
}
345355
}
@@ -456,7 +466,8 @@ private async Task<bool> ValidateGameWithTask(PathingTask task)
456466
return true;
457467
}
458468

459-
private bool ValidateElementalActionAvatarIndex(PathingTask task, string action, ElementalType el, CombatScenes combatScenes)
469+
private bool ValidateElementalActionAvatarIndex(PathingTask task, string action, ElementalType el,
470+
CombatScenes combatScenes)
460471
{
461472
if (task.HasAction(action))
462473
{
@@ -468,7 +479,8 @@ private bool ValidateElementalActionAvatarIndex(PathingTask task, string action,
468479
}
469480
}
470481

471-
Logger.LogError("此路径存在 {El}元素采集 动作,队伍中没有对应元素角色:{Names},无法执行此路径!", el.ToChinese(), string.Join(",", ElementalCollectAvatarConfigs.GetAvatarNameList(el)));
482+
Logger.LogError("此路径存在 {El}元素采集 动作,队伍中没有对应元素角色:{Names},无法执行此路径!", el.ToChinese(),
483+
string.Join(",", ElementalCollectAvatarConfigs.GetAvatarNameList(el)));
472484
return false;
473485
}
474486
else
@@ -603,7 +615,7 @@ private async Task<bool> TryGetExpeditionRewardsDispatch(TpTask? tpTask = null)
603615
{
604616
tpTask = new TpTask(ct);
605617
}
606-
618+
607619
// 最小5分钟间隔
608620
if ((DateTime.UtcNow - _lastGetExpeditionRewardsTime).TotalMinutes < 5)
609621
{
@@ -629,7 +641,9 @@ private async Task<bool> TryGetExpeditionRewardsDispatch(TpTask? tpTask = null)
629641
try
630642
{
631643
RunnerContext.Instance.isAutoFetchDispatch = true;
632-
await RunnerContext.Instance.StopAutoPickRunTask(async () => await new GoToAdventurersGuildTask().Start(adventurersGuildCountry, ct, null, true), 5);
644+
await RunnerContext.Instance.StopAutoPickRunTask(
645+
async () => await new GoToAdventurersGuildTask().Start(adventurersGuildCountry, ct, null, true),
646+
5);
633647
Logger.LogInformation("自动领取派遣结束,回归原任务!");
634648
}
635649
catch (Exception e)
@@ -653,7 +667,8 @@ private async Task HandleTeleportWaypoint(WaypointForTrack waypoint)
653667
TpTask tpTask = new TpTask(ct);
654668
await TryGetExpeditionRewardsDispatch(tpTask);
655669
var (tpX, tpY) = await tpTask.Tp(waypoint.GameX, waypoint.GameY, waypoint.MapName, forceTp);
656-
var (tprX, tprY) = MapManager.GetMap(waypoint.MapName).ConvertGenshinMapCoordinatesToImageCoordinates((float)tpX, (float)tpY);
670+
var (tprX, tprY) = MapManager.GetMap(waypoint.MapName)
671+
.ConvertGenshinMapCoordinatesToImageCoordinates((float)tpX, (float)tpY);
657672
Navigation.SetPrevPosition(tprX, tprY); // 通过上一个位置直接进行局部特征匹配
658673
await Delay(500, ct); // 多等一会
659674
}
@@ -820,7 +835,8 @@ public async Task MoveTo(WaypointForTrack waypoint)
820835
else if (waypoint.MoveMode != MoveModeEnum.Climb.Code) //否则自动短疾跑
821836
{
822837
// 使用 E 技能
823-
if (distance > 10 && !string.IsNullOrEmpty(PartyConfig.GuardianAvatarIndex) && double.TryParse(PartyConfig.GuardianElementalSkillSecondInterval, out var s))
838+
if (distance > 10 && !string.IsNullOrEmpty(PartyConfig.GuardianAvatarIndex) &&
839+
double.TryParse(PartyConfig.GuardianElementalSkillSecondInterval, out var s))
824840
{
825841
if (s < 1)
826842
{
@@ -832,7 +848,8 @@ public async Task MoveTo(WaypointForTrack waypoint)
832848
if ((DateTime.UtcNow - _elementalSkillLastUseTime).TotalMilliseconds > ms)
833849
{
834850
// 可能刚切过人在冷却时间内
835-
if (num <= 5 && (!string.IsNullOrEmpty(PartyConfig.MainAvatarIndex) && PartyConfig.GuardianAvatarIndex != PartyConfig.MainAvatarIndex))
851+
if (num <= 5 && (!string.IsNullOrEmpty(PartyConfig.MainAvatarIndex) &&
852+
PartyConfig.GuardianAvatarIndex != PartyConfig.MainAvatarIndex))
836853
{
837854
await Delay(800, ct); // 总共1s
838855
}

0 commit comments

Comments
 (0)