Skip to content

Commit 15b772a

Browse files
committed
适配 菈乌玛退队后队伍UI不会还原,但是跨地图传送后UI还原 的场景
1 parent 86d2027 commit 15b772a

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,21 @@ public void Switch()
175175
break;
176176
}
177177

178+
// 6.0 特殊逻辑
179+
if (i > 3 && CombatScenes.IndexRectOffset60Fix)
180+
{
181+
// 3次失败考虑是否偏移出现问题,修改偏移位置
182+
// 只有 草露 角色离队,然后跨地图传送后,会出现这个场景。也就是只有 偏移 -> 原始 的场景
183+
foreach (var avatar in CombatScenes.GetAvatars())
184+
{
185+
var rect1 = avatar.IndexRect;
186+
rect1.Y += 14;
187+
avatar.IndexRect = rect1;
188+
}
189+
190+
CombatScenes.IndexRectOffset60Fix = false;
191+
}
192+
178193
// Debug.WriteLine($"切换到{Index}号位");
179194
// Cv2.ImWrite($"log/切换.png", region.SrcMat);
180195
Sleep(250, Ct);
@@ -294,19 +309,23 @@ public bool IsActive(ImageRegion region)
294309
}
295310
else
296311
{
297-
// 剪裁出IndexRect区域
298-
var indexRa = region.DeriveCrop(IndexRect);
299-
// Cv2.ImWrite($"log/indexRa_{Name}.png", indexRa.SrcMat);
300-
var count = OpenCvCommonHelper.CountGrayMatColor(indexRa.CacheGreyMat, 251, 255);
301-
if (count * 1.0 / (IndexRect.Width * IndexRect.Height) > 0.5)
302-
{
303-
return false;
304-
}
305-
else
306-
{
307-
return true;
308-
}
312+
var white = IsIndexRectWhite(region, IndexRect);
313+
return !white;
314+
}
315+
}
316+
317+
private bool IsIndexRectWhite(ImageRegion region, Rect rect)
318+
{
319+
// 剪裁出IndexRect区域
320+
var indexRa = region.DeriveCrop(rect);
321+
var mat = indexRa.CacheGreyMat;
322+
var count = OpenCvCommonHelper.CountGrayMatColor(mat, 251, 255);
323+
if (count * 1.0 / (mat.Width * mat.Height) > 0.5)
324+
{
325+
return true;
309326
}
327+
328+
return false;
310329
}
311330

312331
/// <summary>

BetterGenshinImpact/GameTask/AutoFight/Model/CombatScenes.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ public class CombatScenes : IDisposable
4040
App.ServiceProvider.GetRequiredService<BgiOnnxFactory>().CreateYoloPredictor(BgiOnnxModel.BgiAvatarSide);
4141

4242
public int ExpectedTeamAvatarNum { get; private set; } = 4;
43+
44+
45+
/// <summary>
46+
/// 6.0 UI偏移标识
47+
/// </summary>
48+
public bool IndexRectOffset60Fix { get; set; }
4349

4450
/// <summary>
4551
/// 获取一个只读的Avatars
@@ -102,7 +108,7 @@ public CombatScenes InitializeTeam(ImageRegion imageRegion)
102108
}
103109

104110
// 6.0 版本 队伍下的 草露 进度条 导致位置偏移
105-
AvatarSideFixOffset(imageRegion, avatarSideIconRectList, avatarIndexRectList);
111+
IndexRectOffset60Fix = AvatarSideFixOffset(imageRegion, avatarSideIconRectList, avatarIndexRectList);
106112

107113
// 识别队伍
108114
var names = new string[avatarSideIconRectList.Count];
@@ -148,7 +154,7 @@ public CombatScenes InitializeTeam(ImageRegion imageRegion)
148154
/// <param name="imageRegion"></param>
149155
/// <param name="avatarSideIconRectList"></param>
150156
/// <param name="avatarIndexRectList"></param>
151-
public void AvatarSideFixOffset(ImageRegion imageRegion, List<Rect> avatarSideIconRectList, List<Rect> avatarIndexRectList)
157+
public bool AvatarSideFixOffset(ImageRegion imageRegion, List<Rect> avatarSideIconRectList, List<Rect> avatarIndexRectList)
152158
{
153159
// 角色序号 左上角 坐标偏移(+2, -5)后存在3个白色点,则认为存在 草露 进度条
154160
// 存在 草露 进度条时候整体上移 14 个像素
@@ -180,7 +186,11 @@ public void AvatarSideFixOffset(ImageRegion imageRegion, List<Rect> avatarSideIc
180186
rect.Y -= 14;
181187
avatarIndexRectList[i] = rect;
182188
}
189+
190+
return true;
183191
}
192+
193+
return false;
184194
}
185195

186196

0 commit comments

Comments
 (0)