From 17af6e01f85fb5d37069d1065d26972d060abfeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89=E9=B8=AD=E8=9B=8B?= Date: Tue, 5 May 2026 00:01:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=88=98=E6=96=97Q=E6=8A=80?= =?UTF-8?q?=E8=83=BD=E5=8A=A0=E5=85=A5CD=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core/Recognition/ONNX/BgiOnnxModel.cs | 8 ++- .../GameTask/AutoFight/Model/Avatar.cs | 57 ++++++++++++++++++- .../AutoFight/Model/BurstReadyState.cs | 9 +++ 3 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 BetterGenshinImpact/GameTask/AutoFight/Model/BurstReadyState.cs diff --git a/BetterGenshinImpact/Core/Recognition/ONNX/BgiOnnxModel.cs b/BetterGenshinImpact/Core/Recognition/ONNX/BgiOnnxModel.cs index 0182b56c..d87369fa 100644 --- a/BetterGenshinImpact/Core/Recognition/ONNX/BgiOnnxModel.cs +++ b/BetterGenshinImpact/Core/Recognition/ONNX/BgiOnnxModel.cs @@ -55,6 +55,12 @@ public class BgiOnnxModel public static readonly BgiOnnxModel BgiAvatarSide = Register("BgiAvatarSide", @"Assets\Model\Common\avatar_side_classify_sim.onnx"); + /// + /// Q技能冷却分类模型 + /// + public static readonly BgiOnnxModel BgiQClassify = + Register("BgiQClassify", @"Assets\Model\Common\q_classify_sim.onnx"); + /// /// paddleOCR V4 检测模型 /// @@ -144,4 +150,4 @@ public class BgiOnnxModel RegisteredModels.Add(model); return model; } -} \ No newline at end of file +} diff --git a/BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs b/BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs index 06db3d6a..14a4bb35 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs @@ -1,4 +1,4 @@ -using BetterGenshinImpact.Core.Recognition.OCR; +using BetterGenshinImpact.Core.Recognition.OCR; using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.Core.Script.Dependence; using BetterGenshinImpact.Core.Simulator; @@ -24,6 +24,10 @@ using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model; using BetterGenshinImpact.GameTask.AutoPathing; using BetterGenshinImpact.GameTask.AutoPathing.Model; using BetterGenshinImpact.GameTask.AutoPathing.Model.Enum; +using BetterGenshinImpact.Core.Recognition.ONNX; +using Compunet.YoloSharp; +using Compunet.YoloSharp.Data; +using Microsoft.Extensions.DependencyInjection; namespace BetterGenshinImpact.GameTask.AutoFight.Model; @@ -99,7 +103,10 @@ public class Avatar }; private static readonly Random UnstuckRandom = new(); - + + private static readonly Lazy QBurstClassifierLazy = new(() => + App.ServiceProvider.GetRequiredService().CreateYoloPredictor(BgiOnnxModel.BgiQClassify)); + public Avatar(CombatScenes combatScenes, string name, int index, Rect nameRect, double manualSkillCd = -1) { @@ -591,6 +598,13 @@ public class Avatar /// public void UseBurst() { + // CD 中立即返回,其余场景尝试释放 + using var region1 = CaptureToRectArea(); + if (IsBurstReadyByClassify(region1) == BurstReadyState.Cooldown) + { + return; + } + for (var i = 0; i < 10; i++) { if (Ct is { IsCancellationRequested: true }) @@ -610,9 +624,46 @@ public class Avatar Sleep(1500, Ct); return; } + else + { + // 找到编号块判断是否进入了CD,四星角色没有大招动画 + if (IsBurstReadyByClassify(region) == BurstReadyState.Cooldown) + { + Sleep(1500, Ct); + return; + } + } } } + private static BurstReadyState IsBurstReadyByClassify(ImageRegion imageRegion) + { + using var qRa = imageRegion.DeriveCrop(AutoFightAssets.Instance.QRect); + var result = QBurstClassifierLazy.Value.Predictor.Classify(qRa.CacheImage); + var topClass = result.GetTopClass(); + var topClassName = topClass.Name.Name; + + // 置信度不足时,直接返回未知,避免误判导致漏放/乱放 + if (topClass.Confidence <= 0.7) + { + Logger.LogDebug("Q技能冷却分类置信度不足:{Confidence:F2},类别:{ClassName}", topClass.Confidence, topClassName); + return BurstReadyState.Unknown; + } + + if (topClassName.Contains("cd_1", StringComparison.OrdinalIgnoreCase)) + { + return BurstReadyState.Cooldown; + } + + if (topClassName.Contains("cd_0", StringComparison.OrdinalIgnoreCase)) + { + return BurstReadyState.Ready; + } + + Logger.LogDebug("Q技能冷却分类出现未知类别:{ClassName},置信度:{Confidence:F2}", topClassName, topClass.Confidence); + return BurstReadyState.Unknown; + } + // /// // /// 元素爆发是否正在CD中 // /// 右下 157x165 @@ -1098,4 +1149,4 @@ public class Avatar return null; } -} \ No newline at end of file +} diff --git a/BetterGenshinImpact/GameTask/AutoFight/Model/BurstReadyState.cs b/BetterGenshinImpact/GameTask/AutoFight/Model/BurstReadyState.cs new file mode 100644 index 00000000..75f2d0fc --- /dev/null +++ b/BetterGenshinImpact/GameTask/AutoFight/Model/BurstReadyState.cs @@ -0,0 +1,9 @@ +namespace BetterGenshinImpact.GameTask.AutoFight.Model; + +public enum BurstReadyState +{ + Ready, + Cooldown, + Unknown +} +