mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-23 09:55:48 +08:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -55,6 +55,12 @@ public class BgiOnnxModel
|
||||
public static readonly BgiOnnxModel BgiAvatarSide =
|
||||
Register("BgiAvatarSide", @"Assets\Model\Common\avatar_side_classify_sim.onnx");
|
||||
|
||||
/// <summary>
|
||||
/// Q技能冷却分类模型
|
||||
/// </summary>
|
||||
public static readonly BgiOnnxModel BgiQClassify =
|
||||
Register("BgiQClassify", @"Assets\Model\Common\q_classify_sim.onnx");
|
||||
|
||||
/// <summary>
|
||||
/// paddleOCR V4 检测模型
|
||||
/// </summary>
|
||||
@@ -144,4 +150,4 @@ public class BgiOnnxModel
|
||||
RegisteredModels.Add(model);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,6 +216,11 @@ public class Genshin
|
||||
{
|
||||
return GetPositionFromMap(MapTypes.Teyvat.ToString());
|
||||
}
|
||||
|
||||
public Point2f? GetPositionFromMapWithMatchingMethod(string matchingMethod)
|
||||
{
|
||||
return GetPositionFromMapWithMatchingMethod(nameof(MapTypes.Teyvat), matchingMethod);
|
||||
}
|
||||
|
||||
public float GetCameraOrientation()
|
||||
{
|
||||
@@ -230,14 +235,18 @@ public class Genshin
|
||||
/// <param name="cacheTimeMs">缓存时间,单位毫秒,默认900ms</param>
|
||||
/// <returns>包含X和Y坐标的Point2f结构体</returns>
|
||||
public Point2f? GetPositionFromMap(string mapName, int cacheTimeMs = 900)
|
||||
{
|
||||
var matchingMethod = TaskContext.Instance().Config.PathingConditionConfig.MapMatchingMethod;
|
||||
return GetPositionFromMapWithMatchingMethod(mapName,matchingMethod, cacheTimeMs);
|
||||
}
|
||||
|
||||
public Point2f? GetPositionFromMapWithMatchingMethod(string mapName, string matchingMethod, int cacheTimeMs = 900)
|
||||
{
|
||||
var imageRegion = CaptureToRectArea();
|
||||
if (!Bv.IsInMainUi(imageRegion))
|
||||
{
|
||||
throw new InvalidOperationException("不在主界面,无法识别小地图坐标");
|
||||
}
|
||||
|
||||
var matchingMethod = TaskContext.Instance().Config.PathingConditionConfig.MapMatchingMethod;
|
||||
return MapManager.GetMap(mapName, matchingMethod)
|
||||
.ConvertImageCoordinatesToGenshinMapCoordinates(LazyNavigationInstance.Value
|
||||
.GetPositionStableByCache(imageRegion, mapName, matchingMethod, cacheTimeMs));
|
||||
|
||||
@@ -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<BgiYoloPredictor> QBurstClassifierLazy = new(() =>
|
||||
App.ServiceProvider.GetRequiredService<BgiOnnxFactory>().CreateYoloPredictor(BgiOnnxModel.BgiQClassify));
|
||||
|
||||
|
||||
public Avatar(CombatScenes combatScenes, string name, int index, Rect nameRect, double manualSkillCd = -1)
|
||||
{
|
||||
@@ -591,6 +598,13 @@ public class Avatar
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// 元素爆发是否正在CD中
|
||||
// /// 右下 157x165
|
||||
@@ -1098,4 +1149,4 @@ public class Avatar
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace BetterGenshinImpact.GameTask.AutoFight.Model;
|
||||
|
||||
public enum BurstReadyState
|
||||
{
|
||||
Ready,
|
||||
Cooldown,
|
||||
Unknown
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user