mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-25 10:05:49 +08:00
修复错误信息,改进联机状态处理 更新了 `BetterGenshinImpact.csproj` 文件中的程序集版本号,从 `0.35.2` 更新为 `0.35.4`。 修正了 `ScriptProject.cs` 文件中抛出 `FileNotFoundException` 异常时的错误信息,将 "manifest.json文件存在" 改为 "manifest.json文件不存在"。 在 `AutoFightAssets.cs` 文件中: - 为 `AvatarSideIconRectList` 和 `AvatarIndexRectList` 添加了注释,解释其在非联机状态下的用途。 - 添加了多个新的属性和注释,用于处理联机状态下的角色头像和对应的白色块位置。 - 初始化了 `OnePRa` 和 `PRa` 两个识别对象,用于识别联机状态下的1P和P图标。 在 `Avatar.cs` 文件中: - 修改了角色切换逻辑,使用 `CombatScenes.ExpectedTeamAvatarNum` 替代硬编码的数字。 - 在 `TrySwitch` 方法中添加了 `needLog` 参数,并在切换成功时记录日志。 - 移除了部分注释代码,并在日志中保存了角色切换和索引区域的截图。 - 添加了 `System.Diagnostics` 的引用。 在 `CombatScenes.cs` 文件中: - 将 `Avatars` 初始化为空数组。 - 添加了 `ExpectedTeamAvatarNum` 属性,默认值为4。 - 在 `InitializeTeam` 方法中添加了联机状态的判断和处理逻辑。 - 修改了队伍识别逻辑,使用动态数组替代固定长度的数组。 - 修改了 `CheckTeamInitialized` 方法,使用 `ExpectedTeamAvatarNum` 替代硬编码的数字。 - 修改了 `BuildAvatars` 方法,添加了对联机状态下角色编号位置信息的处理。 - 修改了 `SelectAvatar` 方法,使用 `GetValueOrDefault` 替代 `TryGetValue`。 在 `ScriptControlViewModel.cs` 文件中,设置 `WindowStartupLocation` 为 `WindowStartupLocation.CenterOwner`。 添加了 `1p.png` 和 `p.png` 两个新图像文件,用于识别联机状态下的1P和P图标。
232 lines
12 KiB
C#
232 lines
12 KiB
C#
using BetterGenshinImpact.Core.Recognition;
|
|
using BetterGenshinImpact.GameTask.Model;
|
|
using OpenCvSharp;
|
|
using System.Collections.Generic;
|
|
|
|
namespace BetterGenshinImpact.GameTask.AutoFight.Assets;
|
|
|
|
public class AutoFightAssets : BaseAssets<AutoFightAssets>
|
|
{
|
|
public Rect TeamRectNoIndex;
|
|
public Rect TeamRect;
|
|
public List<Rect> AvatarSideIconRectList; // 侧边栏角色头像 非联机状态下
|
|
public List<Rect> AvatarIndexRectList; // 侧边栏角色头像对应的白色块 非联机状态下
|
|
public Rect ERect;
|
|
public Rect QRect;
|
|
public Rect EndTipsUpperRect; // 挑战达成提示
|
|
public Rect EndTipsRect;
|
|
public RecognitionObject WandererIconRa;
|
|
public RecognitionObject WandererIconNoActiveRa;
|
|
public RecognitionObject ConfirmRa;
|
|
public RecognitionObject ExitRa;
|
|
public RecognitionObject ClickAnyCloseTipRa;
|
|
public RecognitionObject UseCondensedResinRa;
|
|
|
|
// 树脂状态
|
|
public RecognitionObject CondensedResinCountRa;
|
|
|
|
public RecognitionObject FragileResinCountRa;
|
|
|
|
public Dictionary<string, string> AvatarCostumeMap;
|
|
|
|
// 联机
|
|
public RecognitionObject OnePRa;
|
|
|
|
public RecognitionObject PRa;
|
|
public Dictionary<string, List<Rect>> AvatarSideIconRectListMap; // 侧边栏角色头像 联机状态下
|
|
public Dictionary<string, List<Rect>> AvatarIndexRectListMap; // 侧边栏角色头像对应的白色块 联机状态下
|
|
|
|
private AutoFightAssets()
|
|
{
|
|
TeamRectNoIndex = new Rect(CaptureRect.Width - (int)(355 * AssetScale), (int)(220 * AssetScale),
|
|
(int)((355 - 85) * AssetScale), (int)(465 * AssetScale));
|
|
TeamRect = new Rect(CaptureRect.Width - (int)(355 * AssetScale), (int)(220 * AssetScale),
|
|
(int)(355 * AssetScale), (int)(465 * AssetScale));
|
|
ERect = new Rect(CaptureRect.Width - (int)(267 * AssetScale), CaptureRect.Height - (int)(132 * AssetScale),
|
|
(int)(77 * AssetScale), (int)(77 * AssetScale));
|
|
QRect = new Rect(CaptureRect.Width - (int)(157 * AssetScale), CaptureRect.Height - (int)(165 * AssetScale),
|
|
(int)(110 * AssetScale), (int)(110 * AssetScale));
|
|
// 结束提示从中间开始找相对位置
|
|
EndTipsUpperRect = new Rect(CaptureRect.Width / 2 - (int)(100 * AssetScale), (int)(243 * AssetScale),
|
|
(int)(200 * AssetScale), (int)(50 * AssetScale));
|
|
EndTipsRect = new Rect(CaptureRect.Width / 2 - (int)(200 * AssetScale), CaptureRect.Height - (int)(160 * AssetScale),
|
|
(int)(400 * AssetScale), (int)(80 * AssetScale));
|
|
|
|
AvatarIndexRectList =
|
|
[
|
|
new Rect(CaptureRect.Width - (int)(61 * AssetScale), (int)(256 * AssetScale), (int)(28 * AssetScale), (int)(24 * AssetScale)),
|
|
new Rect(CaptureRect.Width - (int)(61 * AssetScale), (int)(352 * AssetScale), (int)(28 * AssetScale), (int)(24 * AssetScale)),
|
|
new Rect(CaptureRect.Width - (int)(61 * AssetScale), (int)(448 * AssetScale), (int)(28 * AssetScale), (int)(24 * AssetScale)),
|
|
new Rect(CaptureRect.Width - (int)(61 * AssetScale), (int)(544 * AssetScale), (int)(28 * AssetScale), (int)(24 * AssetScale)),
|
|
];
|
|
|
|
AvatarSideIconRectList =
|
|
[
|
|
new Rect(CaptureRect.Width - (int)(155 * AssetScale), (int)(225 * AssetScale), (int)(76 * AssetScale), (int)(76 * AssetScale)),
|
|
new Rect(CaptureRect.Width - (int)(155 * AssetScale), (int)(315 * AssetScale), (int)(76 * AssetScale), (int)(76 * AssetScale)),
|
|
new Rect(CaptureRect.Width - (int)(155 * AssetScale), (int)(410 * AssetScale), (int)(76 * AssetScale), (int)(76 * AssetScale)),
|
|
new Rect(CaptureRect.Width - (int)(155 * AssetScale), (int)(500 * AssetScale), (int)(76 * AssetScale), (int)(76 * AssetScale)),
|
|
];
|
|
|
|
AvatarCostumeMap = new Dictionary<string, string>
|
|
{
|
|
{ "Flamme", "殷红终夜" },
|
|
{ "Bamboo", "雨化竹身" },
|
|
{ "Dai", "冷花幽露" },
|
|
{ "Yu", "玄玉瑶芳" },
|
|
{ "Dancer", "帆影游风" },
|
|
{ "Witch", "琪花星烛" },
|
|
{ "Wic", "和谐" },
|
|
{ "Studentin", "叶隐芳名" },
|
|
{ "Fruhling", "花时来信" },
|
|
{ "Highness", "极夜真梦" },
|
|
{ "Feather", "霓裾翩跹" },
|
|
{ "Floral", "纱中幽兰" },
|
|
{ "Summertime", "闪耀协奏" },
|
|
{ "Sea", "海风之梦" },
|
|
};
|
|
|
|
// 联机
|
|
// 1p_2 与 p_2 为同一位置
|
|
// 1p_4 与 p_4 为同一位置
|
|
AvatarSideIconRectListMap = new Dictionary<string, List<Rect>>
|
|
{
|
|
{
|
|
"1p_2", [
|
|
new Rect(CaptureRect.Width - (int)(155 * AssetScale), (int)(375 * AssetScale), (int)(76 * AssetScale), (int)(76 * AssetScale)),
|
|
new Rect(CaptureRect.Width - (int)(155 * AssetScale), (int)(470 * AssetScale), (int)(76 * AssetScale), (int)(76 * AssetScale)),
|
|
]
|
|
},
|
|
{
|
|
"1p_3", [
|
|
new Rect(CaptureRect.Width - (int)(155 * AssetScale), (int)(375 * AssetScale), (int)(76 * AssetScale), (int)(76 * AssetScale)),
|
|
new Rect(CaptureRect.Width - (int)(155 * AssetScale), (int)(470 * AssetScale), (int)(76 * AssetScale), (int)(76 * AssetScale)),
|
|
]
|
|
},
|
|
{ "1p_4", [new Rect(CaptureRect.Width - (int)(155 * AssetScale), (int)(515 * AssetScale), (int)(76 * AssetScale), (int)(76 * AssetScale))] },
|
|
{
|
|
"p_2", [
|
|
new Rect(CaptureRect.Width - (int)(155 * AssetScale), (int)(375 * AssetScale), (int)(76 * AssetScale), (int)(76 * AssetScale)),
|
|
new Rect(CaptureRect.Width - (int)(155 * AssetScale), (int)(470 * AssetScale), (int)(76 * AssetScale), (int)(76 * AssetScale)),
|
|
]
|
|
},
|
|
{ "p_3", [new Rect(CaptureRect.Width - (int)(155 * AssetScale), (int)(475 * AssetScale), (int)(76 * AssetScale), (int)(76 * AssetScale))] },
|
|
{ "p_4", [new Rect(CaptureRect.Width - (int)(155 * AssetScale), (int)(515 * AssetScale), (int)(76 * AssetScale), (int)(76 * AssetScale))] },
|
|
};
|
|
|
|
AvatarIndexRectListMap = new Dictionary<string, List<Rect>>
|
|
{
|
|
{
|
|
"1p_2", [
|
|
new Rect(CaptureRect.Width - (int)(61 * AssetScale), (int)(412 * AssetScale), (int)(28 * AssetScale), (int)(24 * AssetScale)),
|
|
new Rect(CaptureRect.Width - (int)(61 * AssetScale), (int)(508 * AssetScale), (int)(28 * AssetScale), (int)(24 * AssetScale)),
|
|
]
|
|
},
|
|
{
|
|
"1p_3", [
|
|
new Rect(CaptureRect.Width - (int)(61 * AssetScale), (int)(459 * AssetScale), (int)(28 * AssetScale), (int)(24 * AssetScale)),
|
|
new Rect(CaptureRect.Width - (int)(61 * AssetScale), (int)(555 * AssetScale), (int)(28 * AssetScale), (int)(24 * AssetScale)),
|
|
]
|
|
},
|
|
{ "1p_4", [new Rect(CaptureRect.Width - (int)(61 * AssetScale), (int)(552 * AssetScale), (int)(28 * AssetScale), (int)(24 * AssetScale))] },
|
|
{
|
|
"p_2", [
|
|
new Rect(CaptureRect.Width - (int)(61 * AssetScale), (int)(412 * AssetScale), (int)(28 * AssetScale), (int)(24 * AssetScale)),
|
|
new Rect(CaptureRect.Width - (int)(61 * AssetScale), (int)(508 * AssetScale), (int)(28 * AssetScale), (int)(24 * AssetScale)),
|
|
]
|
|
},
|
|
{ "p_3", [new Rect(CaptureRect.Width - (int)(61 * AssetScale), (int)(412 * AssetScale), (int)(28 * AssetScale), (int)(24 * AssetScale))] },
|
|
{ "p_4", [new Rect(CaptureRect.Width - (int)(61 * AssetScale), (int)(507 * AssetScale), (int)(28 * AssetScale), (int)(24 * AssetScale))] },
|
|
};
|
|
|
|
// 左上角的 1P 图标
|
|
OnePRa = new RecognitionObject
|
|
{
|
|
Name = "1P",
|
|
RecognitionType = RecognitionTypes.TemplateMatch,
|
|
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", "1p.png"),
|
|
RegionOfInterest = new Rect(0, 0, CaptureRect.Width / 4, CaptureRect.Height / 7),
|
|
DrawOnWindow = false
|
|
}.InitTemplate();
|
|
// 右侧联机的 P 图标
|
|
PRa = new RecognitionObject
|
|
{
|
|
Name = "P",
|
|
RecognitionType = RecognitionTypes.TemplateMatch,
|
|
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", "p.png"),
|
|
RegionOfInterest = new Rect(CaptureRect.Width - CaptureRect.Width / 7, CaptureRect.Height / 5, CaptureRect.Width / 7, CaptureRect.Height / 2 - CaptureRect.Width / 7),
|
|
DrawOnWindow = false
|
|
}.InitTemplate();
|
|
|
|
WandererIconRa = new RecognitionObject
|
|
{
|
|
Name = "WandererIcon",
|
|
RecognitionType = RecognitionTypes.TemplateMatch,
|
|
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", "wanderer_icon.png"),
|
|
DrawOnWindow = false
|
|
}.InitTemplate();
|
|
WandererIconNoActiveRa = new RecognitionObject
|
|
{
|
|
Name = "WandererIconNoActive",
|
|
RecognitionType = RecognitionTypes.TemplateMatch,
|
|
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", "wanderer_icon_no_active.png"),
|
|
DrawOnWindow = false
|
|
}.InitTemplate();
|
|
|
|
// 右下角的按钮
|
|
ConfirmRa = new RecognitionObject
|
|
{
|
|
Name = "Confirm",
|
|
RecognitionType = RecognitionTypes.TemplateMatch,
|
|
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", "confirm.png"),
|
|
RegionOfInterest = new Rect(CaptureRect.Width / 2, CaptureRect.Height / 2, CaptureRect.Width / 2, CaptureRect.Height / 2),
|
|
DrawOnWindow = false
|
|
}.InitTemplate();
|
|
|
|
// 点击任意处关闭提示
|
|
ClickAnyCloseTipRa = new RecognitionObject
|
|
{
|
|
Name = "ClickAnyCloseTip",
|
|
RecognitionType = RecognitionTypes.TemplateMatch,
|
|
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", "click_any_close_tip.png"),
|
|
RegionOfInterest = new Rect(0, CaptureRect.Height / 2, CaptureRect.Width, CaptureRect.Height / 2),
|
|
DrawOnWindow = false
|
|
}.InitTemplate();
|
|
|
|
UseCondensedResinRa = new RecognitionObject
|
|
{
|
|
Name = "UseCondensedResin",
|
|
RecognitionType = RecognitionTypes.TemplateMatch,
|
|
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", "use_condensed_resin.png"),
|
|
RegionOfInterest = new Rect(0, CaptureRect.Height / 2, CaptureRect.Width / 2, CaptureRect.Height / 2),
|
|
DrawOnWindow = false
|
|
}.InitTemplate();
|
|
|
|
ExitRa = new RecognitionObject
|
|
{
|
|
Name = "Exit",
|
|
RecognitionType = RecognitionTypes.TemplateMatch,
|
|
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", "exit.png"),
|
|
RegionOfInterest = new Rect(0, CaptureRect.Height / 2, CaptureRect.Width / 2, CaptureRect.Height / 2),
|
|
DrawOnWindow = false
|
|
}.InitTemplate();
|
|
|
|
CondensedResinCountRa = new RecognitionObject
|
|
{
|
|
Name = "CondensedResinCount",
|
|
RecognitionType = RecognitionTypes.TemplateMatch,
|
|
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", "condensed_resin_count.png"),
|
|
RegionOfInterest = new Rect(CaptureRect.Width / 2, CaptureRect.Height / 3 * 2, CaptureRect.Width / 2, CaptureRect.Height / 3),
|
|
DrawOnWindow = false
|
|
}.InitTemplate();
|
|
FragileResinCountRa = new RecognitionObject
|
|
{
|
|
Name = "FragileResinCount",
|
|
RecognitionType = RecognitionTypes.TemplateMatch,
|
|
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", "fragile_resin_count.png"),
|
|
RegionOfInterest = new Rect(CaptureRect.Width / 2, CaptureRect.Height / 3 * 2, CaptureRect.Width / 2, CaptureRect.Height / 3),
|
|
DrawOnWindow = false
|
|
}.InitTemplate();
|
|
}
|
|
}
|