From 3586e37c69ffbe01de9fe1cc700aef8e64bb5835 Mon Sep 17 00:00:00 2001
From: kaedelcb <57870068+kaedelcb@users.noreply.github.com>
Date: Thu, 16 Apr 2026 23:37:52 +0800
Subject: [PATCH] =?UTF-8?q?=E6=88=98=E6=96=97=E8=BF=87=E7=A8=8B=E5=8D=A1?=
=?UTF-8?q?=E5=88=87=E6=8D=A2=E8=A7=92=E8=89=B2=E4=BC=98=E5=8C=96=20(#3054?=
=?UTF-8?q?)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../GameTask/AutoFight/Model/Avatar.cs | 48 ++++++++++++++++++-
1 file changed, 46 insertions(+), 2 deletions(-)
diff --git a/BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs b/BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs
index a7c07c6d..adc010a2 100644
--- a/BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs
+++ b/BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs
@@ -86,6 +86,19 @@ public class Avatar
/// 战斗场景
///
public CombatScenes CombatScenes { get; set; }
+
+ ///
+ /// 脱困方向数组(前/后/左/右)
+ ///
+ private static readonly GIActions[] UnstuckDirections =
+ {
+ GIActions.MoveForward,
+ GIActions.MoveBackward,
+ GIActions.MoveLeft,
+ GIActions.MoveRight
+ };
+
+ private static readonly Random UnstuckRandom = new();
public Avatar(CombatScenes combatScenes, string name, int index, Rect nameRect, double manualSkillCd = -1)
@@ -229,6 +242,13 @@ public class Avatar
SimulateSwitchAction(Index);
// Debug.WriteLine($"切换到{Index}号位");
// Cv2.ImWrite($"log/切换.png", region.SrcMat);
+
+ // 第13次重试时,战斗状态下执行脱困动作
+ if (i == 10 && AutoFightTask.FightStatusFlag)
+ {
+ PerformUnstuckAction(Ct);
+ }
+
Sleep(250, Ct);
}
}
@@ -259,13 +279,20 @@ public class Avatar
}
else
{
- if (i == tryTimes - 1)
+ if (i == tryTimes - 1 && tryTimes == 4) //默认状态,没有特意设置重试次数的情况下,最后一次重试失败才输出日志
{
Logger.LogWarning("切换角色失败,最后一次尝试,当前角色编号:{CurrentIndex},期望角色编号:{ExpectedIndex}", CombatScenes.GetActiveAvatarIndex(region, context), Index);
}
+ else
+ {
+ // 特意需要脱困情形下,会设置重试次数激活脱困检测,第10次重试时(2.5秒切换失败,超过角色的大招动画时间),如在盾奶位功能中次数会到第十次。
+ if (i == 10 && AutoFightTask.FightStatusFlag)
+ {
+ PerformUnstuckAction(Ct);
+ }
+ }
}
-
SimulateSwitchAction(Index);
Sleep(250, Ct);
@@ -301,6 +328,23 @@ public class Avatar
}
}
+ ///
+ /// 战斗中切换角色卡住时的脱困动作:跳跃 → 随机方向移动+切换 → 攻击 → 释放按键
+ ///
+ private void PerformUnstuckAction(CancellationToken ct)
+ {
+ var direction = UnstuckDirections[UnstuckRandom.Next(4)];
+ Logger.LogWarning("切换角色卡住,执行脱困(方向:{Dir})", direction);
+
+ Simulation.SendInput.SimulateAction(GIActions.Jump);
+ Sleep(200, ct);
+ Simulation.SendInput.SimulateAction(direction, KeyType.KeyDown);
+ SimulateSwitchAction(Index);
+ Sleep(1000, ct);
+ Simulation.SendInput.SimulateAction(GIActions.NormalAttack);
+ Simulation.ReleaseAllKey();
+ }
+
///
/// 切换到本角色
/// 切换cd是1秒,如果切换失败,会尝试再次切换,最多尝试5次