Compare commits
20
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c8210c3b5 | ||
|
|
ad4125510b | ||
|
|
ffd87f2b11 | ||
|
|
dca422de8e | ||
|
|
2ea663b0ff | ||
|
|
bbf1be3de9 | ||
|
|
3586e37c69 | ||
|
|
4896d0344a | ||
|
|
c1d0a53110 | ||
|
|
0eedfb6969 | ||
|
|
d0c02717e8 | ||
|
|
2a53fb9742 | ||
|
|
bd8451a190 | ||
|
|
ee500b2971 | ||
|
|
b0a1715ba3 | ||
|
|
33760242ea | ||
|
|
7d91fba327 | ||
|
|
8956c306c2 | ||
|
|
a7dac95468 | ||
|
|
dea40ce177 |
No files matched your search
@@ -4,12 +4,23 @@ title: "[bug] "
|
||||
labels:
|
||||
- BUG
|
||||
body:
|
||||
- type: checkboxes
|
||||
id: checks
|
||||
attributes:
|
||||
label: 提交确认 / Checklist
|
||||
description: Checklist before submitting
|
||||
options:
|
||||
- label: 我已经搜索过现有 issue,确认这不是重复问题 / I have searched existing issues and confirmed this is not a duplicate
|
||||
required: true
|
||||
- label: "我已阅读过[文档](https://www.bettergi.com/doc.html),确认文档的内容无法解决我的问题 / I have read the [documentation](https://www.bettergi.com/doc.html) and confirmed it does not solve my problem"
|
||||
required: true
|
||||
- label: 我愿意为了解决这个问题尽自己所能 / I am willing to do my part to help resolve this issue
|
||||
- type: textarea
|
||||
id: environment
|
||||
attributes:
|
||||
label: 系统环境
|
||||
description: System Environment,例如系统版本、运行环境
|
||||
placeholder: Win11 / BetterGI 0.58.0 / .NET 8
|
||||
description: System environment,例如操作系统版本、运行时版本、显卡驱动版本
|
||||
placeholder: Windows 11 24H2 (26100.3775) / .NET Desktop Runtime 8.0.15 / NVIDIA 572.83
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
@@ -17,15 +28,23 @@ body:
|
||||
attributes:
|
||||
label: BetterGI 版本号
|
||||
description: BetterGI Version
|
||||
placeholder: 0.58.0
|
||||
placeholder: e.g. 0.58.0
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: 问题描述
|
||||
description: Description of the issue
|
||||
placeholder: 请详细描述你遇到的问题,可直接粘贴日志并附带截图
|
||||
description: Describe the actual behavior and impact
|
||||
placeholder: 请描述实际出现的问题,以及这个问题对使用造成了什么影响 / Describe the actual behavior and impact
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: expected
|
||||
attributes:
|
||||
label: 期望结果
|
||||
description: Expected behavior
|
||||
placeholder: 请描述你期望出现的正确行为或结果 / Describe the expected behavior or result
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
@@ -34,8 +53,22 @@ body:
|
||||
label: 复现步骤
|
||||
description: Reproduction steps
|
||||
placeholder: |-
|
||||
1. 打开……
|
||||
2. 点击……
|
||||
3. 出现……
|
||||
1. 打开…… / Open ...
|
||||
2. 点击…… / Click ...
|
||||
3. 出现…… / Observe ...
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: 日志与附件
|
||||
description: Logs and attachments,可直接拖拽上传日志文件、压缩包、截图或视频
|
||||
placeholder: |-
|
||||
可在这里补充日志和附件说明 / Add logs and attachment notes here:
|
||||
- 可直接粘贴关键日志片段 / Paste key log snippets directly
|
||||
- 可拖拽上传日志文件或压缩包 / Drag and drop log files or archives
|
||||
- 可拖拽上传截图、录屏或演示视频 / Drag and drop screenshots or videos
|
||||
- 若附件较多,请说明对应的时间点、任务名称或异常现象 / If there are many files, explain the relevant timestamps or symptoms
|
||||
- 提交前请注意移除账号、路径等隐私信息 / Remove private information before submitting
|
||||
validations:
|
||||
required: false
|
||||
@@ -1,9 +1,9 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: 官方文档 / Document
|
||||
url: https://bgi.huiyadan.com/doc.html
|
||||
url: https://www.bettergi.com/doc.html
|
||||
about: 请在提出问题前阅读文档 / Read the document before submit the issue
|
||||
|
||||
- name: 常见问题 / FAQ
|
||||
url: https://bgi.huiyadan.com/faq.html
|
||||
url: https://www.bettergi.com/faq.html
|
||||
about: 常见的用户提出的问题 / Common questions asked by users
|
||||
@@ -4,12 +4,26 @@ title: "[feature] "
|
||||
labels:
|
||||
- 功能建议
|
||||
body:
|
||||
- type: checkboxes
|
||||
id: checks
|
||||
attributes:
|
||||
label: 提交确认 / Checklist
|
||||
description: Please confirm the following before submitting
|
||||
options:
|
||||
- label: 我已经搜索过现有 issue,确认这不是重复建议 / I have searched existing issues and confirmed this is not a duplicate request
|
||||
required: true
|
||||
- label: 我已确认当前版本中尚未提供该功能,或至少没有等价实现 / I have confirmed this feature, or an equivalent one, is not already available in the current version
|
||||
required: true
|
||||
- label: 我认为这个需求能为更多用户带来明确收益,而不仅仅是个人偏好 / I believe this request provides clear value to a broader group of users, not just my personal preference
|
||||
required: true
|
||||
- label: 我理解这个需求可能因实现成本、维护成本或项目方向而暂不采纳 / I understand this request may not be accepted due to implementation cost, maintenance cost, or project direction
|
||||
required: true
|
||||
- type: textarea
|
||||
id: request
|
||||
attributes:
|
||||
label: 功能请求
|
||||
description: Feature Request
|
||||
placeholder: 请简要说明你希望新增什么能力
|
||||
placeholder: 请简要说明你希望新增什么能力 / Briefly describe the capability you want to add
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
@@ -17,7 +31,15 @@ body:
|
||||
attributes:
|
||||
label: 使用场景
|
||||
description: Use Case
|
||||
placeholder: 这个功能要解决什么问题?在哪些场景下使用?
|
||||
placeholder: 这个功能要解决什么问题?在哪些场景下使用? / What problem does this feature solve, and when would it be used?
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: impact
|
||||
attributes:
|
||||
label: 潜在影响
|
||||
description: Potential Impact
|
||||
placeholder: 请说明这个功能是否可能带来新的问题、维护成本、使用门槛或兼容性影响;如果没有,请填写“无” / Describe any potential downsides such as new issues, maintenance cost, usability barriers, or compatibility impact. Write "None" if there are no obvious downsides.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
@@ -25,6 +47,6 @@ body:
|
||||
attributes:
|
||||
label: 补充信息
|
||||
description: Optional
|
||||
placeholder: 可选,补充示意图、参考方案或限制条件
|
||||
placeholder: "可选,补充示意图、交互草图、参考链接或相关背景信息 / Optional: add mockups, interaction sketches, reference links, or other background information"
|
||||
validations:
|
||||
required: false
|
||||
@@ -2,11 +2,21 @@ name: Feel free to express / 自由描述
|
||||
description: 记录你想反馈的内容 / Share general feedback
|
||||
title: "[feedback] "
|
||||
body:
|
||||
- type: checkboxes
|
||||
id: checks
|
||||
attributes:
|
||||
label: 提交确认 / Checklist
|
||||
description: Please confirm the following before submitting
|
||||
options:
|
||||
- label: 我已经搜索过现有 issue,确认这不是重复反馈 / I have searched existing issues and confirmed this is not duplicate feedback
|
||||
required: true
|
||||
- label: "我已阅读过[文档](https://www.bettergi.com/doc.html),确认文档的内容无法解决我的问题或覆盖我的反馈 / I have read the [documentation](https://www.bettergi.com/doc.html) and confirmed it does not solve my problem or cover my feedback"
|
||||
required: true
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: 描述
|
||||
description: Description
|
||||
placeholder: 请描述你想反馈的内容
|
||||
placeholder: 请描述你想反馈的内容 / Describe what you want to share
|
||||
validations:
|
||||
required: true
|
||||
@@ -4,12 +4,22 @@ title: "[question] "
|
||||
labels:
|
||||
- 问题咨询
|
||||
body:
|
||||
- type: checkboxes
|
||||
id: checks
|
||||
attributes:
|
||||
label: 提交确认 / Checklist
|
||||
description: Please confirm the following before submitting
|
||||
options:
|
||||
- label: 我已经搜索过现有 issue,确认这不是重复问题 / I have searched existing issues and confirmed this is not a duplicate question
|
||||
required: true
|
||||
- label: "我已阅读过[文档](https://www.bettergi.com/doc.html),确认文档的内容无法解决我的问题 / I have read the [documentation](https://www.bettergi.com/doc.html) and confirmed it does not solve my problem"
|
||||
required: true
|
||||
- type: textarea
|
||||
id: question
|
||||
attributes:
|
||||
label: 问题描述
|
||||
description: Problem Description
|
||||
placeholder: 请清楚描述你的问题
|
||||
placeholder: 请清楚描述你的问题 / Clearly describe your question
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
@@ -17,6 +27,6 @@ body:
|
||||
attributes:
|
||||
label: 已尝试内容
|
||||
description: Screenshots / logs / what you already tried
|
||||
placeholder: 可附上截图、日志,以及你已经尝试过的排查过程
|
||||
placeholder: 可附上截图、日志,以及你已经尝试过的排查过程 / Add screenshots, logs, and what you have already tried
|
||||
validations:
|
||||
required: true
|
||||
@@ -4,12 +4,22 @@ title: "[suggestion] "
|
||||
labels:
|
||||
- 功能建议
|
||||
body:
|
||||
- type: checkboxes
|
||||
id: checks
|
||||
attributes:
|
||||
label: 提交确认 / Checklist
|
||||
description: Please confirm the following before submitting
|
||||
options:
|
||||
- label: 我已经搜索过现有 issue,确认这不是重复建议 / I have searched existing issues and confirmed this is not a duplicate suggestion
|
||||
required: true
|
||||
- label: "我已阅读过[文档](https://www.bettergi.com/doc.html),确认文档的内容无法解决我的问题或覆盖我的建议 / I have read the [documentation](https://www.bettergi.com/doc.html) and confirmed it does not solve my problem or cover my suggestion"
|
||||
required: true
|
||||
- type: textarea
|
||||
id: suggestion
|
||||
attributes:
|
||||
label: 建议内容
|
||||
description: Suggestion
|
||||
placeholder: 请描述你的建议内容
|
||||
placeholder: 请描述你的建议内容 / Describe your suggestion
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
@@ -17,6 +27,6 @@ body:
|
||||
attributes:
|
||||
label: 预期收益
|
||||
description: Expected Benefit
|
||||
placeholder: 这个建议会给用户或项目带来什么帮助?
|
||||
placeholder: 这个建议会给用户或项目带来什么帮助? / What benefits would this suggestion bring to users or the project?
|
||||
validations:
|
||||
required: true
|
||||
@@ -6,7 +6,7 @@ providers:
|
||||
openAiCompatible:
|
||||
enabled: true
|
||||
baseUrl: https://api.openai.com/v1
|
||||
model: gpt-5.2-codex
|
||||
model: gpt-5.4
|
||||
apiStyle: responses
|
||||
timeoutMs: 30000
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<AssemblyName>BetterGI</AssemblyName>
|
||||
<Version>0.60.0</Version>
|
||||
<Version>0.60.2-alpha.1</Version>
|
||||
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
|
||||
|
||||
@@ -311,6 +311,17 @@ public class BgiOnnxFactory
|
||||
: new BgiYoloPredictor(model, cached, CreateSessionOptions(model, false));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据模型创建一个 RedNet 分类预测器
|
||||
/// </summary>
|
||||
/// <param name="model">模型</param>
|
||||
/// <param name="labelRelativePath">标签文件相对路径,可选,支持 .txt/.json</param>
|
||||
/// <returns>BgiRedNetPredictor</returns>
|
||||
public BgiRedNetPredictor CreateRedNetPredictor(BgiOnnxModel model, string? labelRelativePath = null)
|
||||
{
|
||||
return new BgiRedNetPredictor(model, CreateInferenceSession(model), labelRelativePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据模型创建一个onnx运行时的InferenceSession
|
||||
/// </summary>
|
||||
@@ -407,11 +418,11 @@ public class BgiOnnxFactory
|
||||
break;
|
||||
case ProviderType.Cpu:
|
||||
sessionOptions.AppendExecutionProvider_CPU();
|
||||
if (model.Name.Contains("PpOcr") || model.Name.Contains("Yap"))
|
||||
{
|
||||
sessionOptions.IntraOpNumThreads = 2; // 限制算子内部并行线程数
|
||||
sessionOptions.InterOpNumThreads = 1; // 限制算子间并行线程数(顺序执行)
|
||||
}
|
||||
// if (model.Name.Contains("PpOcr") || model.Name.Contains("Yap"))
|
||||
// {
|
||||
// sessionOptions.IntraOpNumThreads = 2; // 限制算子内部并行线程数
|
||||
// sessionOptions.InterOpNumThreads = 1; // 限制算子间并行线程数(顺序执行)
|
||||
// }
|
||||
break;
|
||||
case ProviderType.Dnnl:
|
||||
sessionOptions.AppendExecutionProvider_Dnnl();
|
||||
@@ -582,4 +593,4 @@ public class BgiOnnxFactory
|
||||
result["enable_opencl_throttling"] = "true";
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,12 @@ public class BgiOnnxModel
|
||||
public static readonly BgiOnnxModel BgiAvatarSide =
|
||||
Register("BgiAvatarSide", @"Assets\Model\Common\avatar_side_classify_sim.onnx");
|
||||
|
||||
/// <summary>
|
||||
/// 角色识别(RedNet-110)
|
||||
/// </summary>
|
||||
public static readonly BgiOnnxModel BgiPickRedNet110 =
|
||||
Register("BgiPickRedNet110", @"Assets\Model\Common\resnet_pick.onnx");
|
||||
|
||||
/// <summary>
|
||||
/// paddleOCR V4 检测模型
|
||||
/// </summary>
|
||||
@@ -139,4 +145,4 @@ public class BgiOnnxModel
|
||||
RegisteredModels.Add(model);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using Microsoft.ML.OnnxRuntime;
|
||||
using Microsoft.ML.OnnxRuntime.Tensors;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recognition.ONNX;
|
||||
|
||||
public sealed class BgiRedNetPredictor : IDisposable
|
||||
{
|
||||
private const int DefaultInputSize = 224;
|
||||
|
||||
private static readonly float[] ImagenetMean = [0.485f, 0.456f, 0.406f];
|
||||
private static readonly float[] ImagenetStd = [0.229f, 0.224f, 0.225f];
|
||||
|
||||
private readonly InferenceSession _session;
|
||||
private readonly string[]? _labels;
|
||||
private readonly string _inputName;
|
||||
private readonly int _inputWidth;
|
||||
private readonly int _inputHeight;
|
||||
|
||||
/// <summary>
|
||||
/// 使用 BgiOnnxFactory 创建这个类的实例
|
||||
/// </summary>
|
||||
internal BgiRedNetPredictor(BgiOnnxModel model, InferenceSession session, string? labelRelativePath = null)
|
||||
{
|
||||
_session = session;
|
||||
|
||||
var input = _session.InputMetadata.FirstOrDefault();
|
||||
if (input.Key is null || input.Value is null)
|
||||
{
|
||||
throw new InvalidDataException("ONNX 模型输入信息为空");
|
||||
}
|
||||
|
||||
_inputName = input.Key;
|
||||
var dimensions = input.Value.Dimensions;
|
||||
if (dimensions.Length < 4)
|
||||
{
|
||||
throw new InvalidDataException($"ONNX 模型输入维度不正确,预期 >=4,实际 {dimensions.Length}");
|
||||
}
|
||||
|
||||
_inputHeight = dimensions[^2] > 0 ? dimensions[^2] : DefaultInputSize;
|
||||
_inputWidth = dimensions[^1] > 0 ? dimensions[^1] : DefaultInputSize;
|
||||
_labels = LoadLabels(labelRelativePath ?? Path.ChangeExtension(model.ModelRelativePath, ".labels.txt"));
|
||||
}
|
||||
|
||||
public RedNetPrediction Predict(Image<Rgb24> image)
|
||||
{
|
||||
using var resized = image.Clone(ctx => ctx.Resize(_inputWidth, _inputHeight));
|
||||
var tensorInput = BuildInputTensor(resized);
|
||||
using var results = _session.Run([
|
||||
NamedOnnxValue.CreateFromTensor(_inputName, tensorInput)
|
||||
]);
|
||||
|
||||
var logits = results.First().AsEnumerable<float>().ToArray();
|
||||
if (logits.Length == 0)
|
||||
{
|
||||
throw new InvalidDataException("ONNX 模型输出为空");
|
||||
}
|
||||
|
||||
var probabilities = Softmax(logits);
|
||||
var maxIndex = 0;
|
||||
var maxValue = probabilities[0];
|
||||
for (var i = 1; i < probabilities.Length; i++)
|
||||
{
|
||||
if (probabilities[i] <= maxValue) continue;
|
||||
maxValue = probabilities[i];
|
||||
maxIndex = i;
|
||||
}
|
||||
|
||||
var label = maxIndex >= 0 && _labels is not null && maxIndex < _labels.Length
|
||||
? _labels[maxIndex]
|
||||
: $"Class_{maxIndex}";
|
||||
return new RedNetPrediction(maxIndex, label, maxValue);
|
||||
}
|
||||
|
||||
private DenseTensor<float> BuildInputTensor(Image<Rgb24> image)
|
||||
{
|
||||
var tensor = new DenseTensor<float>([1, 3, _inputHeight, _inputWidth]);
|
||||
for (var y = 0; y < _inputHeight; y++)
|
||||
{
|
||||
for (var x = 0; x < _inputWidth; x++)
|
||||
{
|
||||
var pixel = image[x, y];
|
||||
var r = pixel.R / 255f;
|
||||
var g = pixel.G / 255f;
|
||||
var b = pixel.B / 255f;
|
||||
|
||||
tensor[0, 0, y, x] = (r - ImagenetMean[0]) / ImagenetStd[0];
|
||||
tensor[0, 1, y, x] = (g - ImagenetMean[1]) / ImagenetStd[1];
|
||||
tensor[0, 2, y, x] = (b - ImagenetMean[2]) / ImagenetStd[2];
|
||||
}
|
||||
}
|
||||
|
||||
return tensor;
|
||||
}
|
||||
|
||||
private static float[] Softmax(float[] logits)
|
||||
{
|
||||
var max = logits.Max();
|
||||
var result = new float[logits.Length];
|
||||
var sum = 0d;
|
||||
|
||||
for (var i = 0; i < logits.Length; i++)
|
||||
{
|
||||
var value = Math.Exp(logits[i] - max);
|
||||
result[i] = (float)value;
|
||||
sum += value;
|
||||
}
|
||||
|
||||
if (sum <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
for (var i = 0; i < result.Length; i++)
|
||||
{
|
||||
result[i] = (float)(result[i] / sum);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string[]? LoadLabels(string labelRelativePath)
|
||||
{
|
||||
var labelAbsolutePath = Core.Config.Global.Absolute(labelRelativePath);
|
||||
if (!File.Exists(labelAbsolutePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var ext = Path.GetExtension(labelAbsolutePath);
|
||||
if (ext.Equals(".json", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var labels = JsonSerializer.Deserialize<string[]>(File.ReadAllText(labelAbsolutePath));
|
||||
return labels is { Length: > 0 } ? labels : null;
|
||||
}
|
||||
|
||||
var lines = File.ReadAllLines(labelAbsolutePath)
|
||||
.Where(t => !string.IsNullOrWhiteSpace(t))
|
||||
.Select(t => t.Trim())
|
||||
.ToArray();
|
||||
return lines.Length > 0 ? lines : null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_session.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public readonly record struct RedNetPrediction(int ClassIndex, string ClassLabel, float Confidence);
|
||||
@@ -9,13 +9,12 @@ using BetterGenshinImpact.Service.Notification.Model.Enum;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
using static Vanara.PInvoke.User32;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoEat;
|
||||
|
||||
/// <summary>
|
||||
/// 自动吃药触发器
|
||||
/// 检测红血状态时自动使用Recovery.png,检测到Resurrection.png时按z复活
|
||||
/// 检测红血状态时自动使用Recovery.png,检测到Resurrection.png时按快捷使用小道具键复活
|
||||
/// </summary>
|
||||
public class AutoEatTrigger : ITaskTrigger
|
||||
{
|
||||
@@ -94,8 +93,8 @@ public class AutoEatTrigger : ITaskTrigger
|
||||
// 检查复活CD(2秒)
|
||||
if ((now - _lastResurrectionTime).TotalSeconds >= 2)
|
||||
{
|
||||
// 按z键复活
|
||||
Simulation.SendInput.Keyboard.KeyPress(VK.VK_Z);
|
||||
// 走原神动作映射,跟随“快捷使用小道具”键位配置
|
||||
Simulation.SendInput.SimulateAction(GIActions.QuickUseGadget);
|
||||
_lastResurrectionTime = now;
|
||||
_logger.LogInformation("检测到复活图标,自动复活");
|
||||
}
|
||||
@@ -140,4 +139,4 @@ public class AutoEatTrigger : ITaskTrigger
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
@@ -1,8 +1,12 @@
|
||||
using BetterGenshinImpact.Core.Recognition;
|
||||
using BetterGenshinImpact.GameTask.Model;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoFight.Assets;
|
||||
@@ -45,6 +49,11 @@ public class AutoFightAssets : BaseAssets<AutoFightAssets>
|
||||
|
||||
public RecognitionObject AbnormalIconRa;
|
||||
|
||||
/// <summary>
|
||||
/// 经验值模板识别对象列表,用于检测怪物死亡时掉落的经验值数字图标
|
||||
/// </summary>
|
||||
public IReadOnlyList<RecognitionObject> ExperienceRecognitionObjects { get; private set; } = Array.Empty<RecognitionObject>();
|
||||
|
||||
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑添加 "required" 修饰符或声明为可为 null。
|
||||
private AutoFightAssets() : base()
|
||||
{
|
||||
@@ -264,5 +273,56 @@ public class AutoFightAssets : BaseAssets<AutoFightAssets>
|
||||
RegionOfInterest = new Rect(0, (int)(CaptureRect.Height * 0.08), (int)(CaptureRect.Width * 0.04), (int)(CaptureRect.Height * 0.07)),
|
||||
DrawOnWindow = false
|
||||
}.InitTemplate();
|
||||
|
||||
// 加载经验值模板图片(用于检测精英怪死亡时的经验值数字图标)
|
||||
try
|
||||
{
|
||||
LoadExperienceRecognitionObjects();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// 经验值模板加载失败不应阻止 AutoFightAssets 初始化
|
||||
ExperienceRecognitionObjects = Array.Empty<RecognitionObject>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载经验值模板图片,文件缺失时跳过,不影响其他功能
|
||||
/// </summary>
|
||||
private void LoadExperienceRecognitionObjects()
|
||||
{
|
||||
var experienceValues = new[] { 57, 58, 60 };
|
||||
var threshold = CaptureRect.Width > 1920 ? 0.6 : 0.9;
|
||||
var roi = new Rect(
|
||||
(int)(CaptureRect.Width * 0.145),
|
||||
(int)(CaptureRect.Height * 0.5),
|
||||
(int)(CaptureRect.Width * 0.02),
|
||||
(int)(CaptureRect.Height * 0.22));
|
||||
|
||||
var list = new List<RecognitionObject>();
|
||||
foreach (var exp in experienceValues)
|
||||
{
|
||||
var fileName = $"experience_{exp}.png";
|
||||
try
|
||||
{
|
||||
var ro = new RecognitionObject
|
||||
{
|
||||
Name = $"Experience_{exp}",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage("AutoFight", fileName, this.systemInfo),
|
||||
RegionOfInterest = roi,
|
||||
UseMask = true,
|
||||
Threshold = threshold,
|
||||
DrawOnWindow = true,
|
||||
}.InitTemplate();
|
||||
list.Add(ro);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// 构造阶段 Logger 可能不可用,静默跳过缺失的模板
|
||||
}
|
||||
}
|
||||
|
||||
ExperienceRecognitionObjects = list.AsReadOnly();
|
||||
}
|
||||
}
|
||||
@@ -157,6 +157,12 @@ public partial class AutoFightConfig : ObservableObject
|
||||
[ObservableProperty]
|
||||
private bool _swimmingEnabled = false;
|
||||
|
||||
/// <summary>
|
||||
/// 基于经验值判断是否执行战后拾取(检测到精英怪经验值图标时才拾取)
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _expBasedPickupEnabled = false;
|
||||
|
||||
/// <summary>
|
||||
/// 战斗超时,单位秒
|
||||
/// </summary>
|
||||
|
||||
@@ -56,6 +56,7 @@ public class AutoFightParam : BaseTaskParam<AutoFightTask>
|
||||
RotaryFactor = autoFightConfig.FinishDetectConfig.RotaryFactor;
|
||||
QinDoublePickUp = autoFightConfig.QinDoublePickUp;
|
||||
SwimmingEnabled = autoFightConfig.SwimmingEnabled;
|
||||
ExpBasedPickupEnabled = autoFightConfig.ExpBasedPickupEnabled;
|
||||
}
|
||||
|
||||
public FightFinishDetectConfig FinishDetectConfig { get; set; } = new();
|
||||
@@ -84,6 +85,11 @@ public class AutoFightParam : BaseTaskParam<AutoFightTask>
|
||||
public bool QinDoublePickUp { get; set; } = false;
|
||||
public static bool SwimmingEnabled { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 基于经验值判断是否执行战后拾取
|
||||
/// </summary>
|
||||
public bool ExpBasedPickupEnabled { get; set; } = false;
|
||||
|
||||
public AutoFightParam(string? strategyName = null) : base(null, null)
|
||||
{
|
||||
SetCombatStrategyPath(strategyName);
|
||||
@@ -140,5 +146,6 @@ public class AutoFightParam : BaseTaskParam<AutoFightTask>
|
||||
GuardianAvatarHold = autoFightConfig.GuardianAvatarHold;
|
||||
SwimmingEnabled = autoFightConfig.SwimmingEnabled;
|
||||
QinDoublePickUp = autoFightConfig.QinDoublePickUp;
|
||||
ExpBasedPickupEnabled = autoFightConfig.ExpBasedPickupEnabled;
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ using BetterGenshinImpact.GameTask.AutoPick.Assets;
|
||||
using BetterGenshinImpact.Core.Recognition;
|
||||
using BetterGenshinImpact.GameTask.Common.Element.Assets;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.GameTask.AutoFight.Assets;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoFight;
|
||||
|
||||
@@ -299,6 +300,16 @@ public class AutoFightTask : ISoloTask
|
||||
|
||||
AutoFightSeek.RotationCount= 0; // 重置旋转次数
|
||||
|
||||
// 基于经验值的战后拾取检测:在战斗过程中异步检测精英怪经验值图标
|
||||
// 仅在万叶拾取总开关开启时才启动经验值检测
|
||||
ExperienceDetector? expDetector = null;
|
||||
if (_taskParam.KazuhaPickupEnabled && _taskParam.ExpBasedPickupEnabled)
|
||||
{
|
||||
var expRos = AutoFightAssets.Instance.ExperienceRecognitionObjects;
|
||||
expDetector = new ExperienceDetector(expRos, cts2.Token);
|
||||
expDetector.Start();
|
||||
}
|
||||
|
||||
// 战斗操作
|
||||
var fightTask = Task.Run(async () =>
|
||||
{
|
||||
@@ -489,6 +500,50 @@ public class AutoFightTask : ISoloTask
|
||||
}, cts2.Token);
|
||||
|
||||
await fightTask;
|
||||
|
||||
try
|
||||
{
|
||||
// 基于经验值检测结果的拾取判断
|
||||
if (_taskParam.KazuhaPickupEnabled && _taskParam.ExpBasedPickupEnabled && expDetector != null)
|
||||
{
|
||||
// 战斗结束与怪物死亡可能几乎同时发生,检测器可能还没来得及捕获经验值图标
|
||||
// 保持检测器运行,每 100ms 轮询一次结果,最多等待 1.1 秒
|
||||
if (!expDetector.HasDetectedExperience)
|
||||
{
|
||||
Logger.LogInformation("基于经验值判断:等待经验值检测结果");
|
||||
var waitMs = 1100;
|
||||
while (!expDetector.HasDetectedExperience && waitMs > 0)
|
||||
{
|
||||
await Delay(100, ct);
|
||||
waitMs -= 100;
|
||||
}
|
||||
}
|
||||
|
||||
await expDetector.StopAsync();
|
||||
var shouldPickup = expDetector.HasDetectedExperience;
|
||||
Logger.LogInformation("基于经验值判断:{Result} 战后拾取", shouldPickup ? "执行" : "不执行");
|
||||
|
||||
if (!shouldPickup)
|
||||
{
|
||||
// 经验值检测未通过,跳过拾取(但仍执行扫描拾取逻辑)
|
||||
if (_taskParam is { PickDropsAfterFightEnabled: true })
|
||||
{
|
||||
await new ScanPickTask().Start(ct);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// 确保检测器在任何路径(异常/取消/正常)都被停止和释放
|
||||
if (expDetector != null)
|
||||
{
|
||||
await expDetector.StopAsync();
|
||||
expDetector.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
if (_taskParam.BattleThresholdForLoot>=2 && countFight < _taskParam.BattleThresholdForLoot)
|
||||
{
|
||||
Logger.LogInformation($"战斗人次({countFight})低于配置人次({_taskParam.BattleThresholdForLoot}),跳过此次拾取!");
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
using BetterGenshinImpact.Core.Recognition;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.GameTask.Model.Area;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoFight;
|
||||
|
||||
/// <summary>
|
||||
/// 经验值检测器:在战斗过程中异步检测屏幕上怪物死亡时掉落的经验值数字图标,
|
||||
/// 用于判断是否有精英怪被击杀,从而决定战后是否执行拾取。
|
||||
/// </summary>
|
||||
public sealed class ExperienceDetector : IDisposable
|
||||
{
|
||||
private static readonly ILogger Logger = TaskControl.Logger;
|
||||
|
||||
/// <summary>
|
||||
/// 经验值图标左侧特征像素的水平偏移量(相对于模板匹配位置)
|
||||
/// </summary>
|
||||
private const int ExpIconPixelOffsetX = -147;
|
||||
|
||||
/// <summary>
|
||||
/// 经验值图标特征颜色 BGR 范围(用于二次验证模板匹配结果)
|
||||
/// </summary>
|
||||
private static readonly Vec3b ExpColorMin = new(200, 200, 150);
|
||||
private static readonly Vec3b ExpColorMax = new(255, 255, 200);
|
||||
|
||||
/// <summary>
|
||||
/// 检测循环间隔(毫秒)
|
||||
/// </summary>
|
||||
private const int DetectionIntervalMs = 100;
|
||||
|
||||
private readonly IReadOnlyList<RecognitionObject> _experienceRos;
|
||||
private readonly CancellationTokenSource _linkedCts;
|
||||
private readonly TaskCompletionSource<bool> _resultTcs;
|
||||
private Task? _detectionTask;
|
||||
private bool _disposed;
|
||||
|
||||
/// <summary>
|
||||
/// 获取检测结果:是否检测到经验值图标
|
||||
/// </summary>
|
||||
public bool HasDetectedExperience =>
|
||||
_resultTcs.Task.IsCompletedSuccessfully && _resultTcs.Task.Result;
|
||||
|
||||
public ExperienceDetector(
|
||||
IReadOnlyList<RecognitionObject> experienceRos,
|
||||
CancellationToken externalToken)
|
||||
{
|
||||
_experienceRos = experienceRos ?? throw new ArgumentNullException(nameof(experienceRos));
|
||||
_linkedCts = CancellationTokenSource.CreateLinkedTokenSource(externalToken);
|
||||
_resultTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启动后台经验值检测循环
|
||||
/// </summary>
|
||||
public void
|
||||
Start()
|
||||
{
|
||||
if (_experienceRos.Count == 0)
|
||||
{
|
||||
Logger.LogWarning("经验值检测:无可用模板,跳过检测");
|
||||
return;
|
||||
}
|
||||
|
||||
_detectionTask = Task.Run(() => DetectionLoop(_linkedCts.Token), _linkedCts.Token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止检测并等待后台任务结束
|
||||
/// </summary>
|
||||
public async Task StopAsync()
|
||||
{
|
||||
_linkedCts.Cancel();
|
||||
if (_detectionTask != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _detectionTask.ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// 正常取消,忽略
|
||||
}
|
||||
}
|
||||
|
||||
// 确保结果有值(未检测到时设为 false)
|
||||
_resultTcs.TrySetResult(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 后台检测循环:截屏 → 模板匹配 → 像素颜色验证
|
||||
/// </summary>
|
||||
private void DetectionLoop(CancellationToken ct)
|
||||
{
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var capture = TaskControl.CaptureToRectArea();
|
||||
|
||||
foreach (var ro in _experienceRos)
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
|
||||
var matchResult = capture.Find(ro);
|
||||
if (!matchResult.IsExist())
|
||||
continue;
|
||||
|
||||
// 模板匹配成功,执行像素颜色二次验证
|
||||
if (ValidateExpPixelColor(capture, matchResult))
|
||||
{
|
||||
Logger.LogInformation("基于经验值判断:检测到 {Name} 经验值图标,启用战后拾取", ro.Name.Replace("Experience_", ""));
|
||||
_resultTcs.TrySetResult(true);
|
||||
return; // 检测到后退出循环
|
||||
}
|
||||
}
|
||||
|
||||
// 短暂等待后继续下一轮检测
|
||||
Thread.Sleep(DetectionIntervalMs);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, "经验值检测循环中发生异常,继续下一轮");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 像素颜色验证:检查匹配位置左侧偏移处的像素是否符合经验值图标特征色
|
||||
/// </summary>
|
||||
private static bool ValidateExpPixelColor(ImageRegion capture, Region matchResult)
|
||||
{
|
||||
var checkX = matchResult.X + ExpIconPixelOffsetX;
|
||||
var checkY = matchResult.Y;
|
||||
|
||||
// 边界检查
|
||||
if (checkX < 0 || checkX >= capture.SrcMat.Cols || checkY < 0 || checkY >= capture.SrcMat.Rows)
|
||||
return false;
|
||||
|
||||
var pixel = capture.SrcMat.At<Vec3b>(checkY, checkX);
|
||||
return pixel[0] >= ExpColorMin[0] && pixel[0] <= ExpColorMax[0] // B
|
||||
&& pixel[1] >= ExpColorMin[1] && pixel[1] <= ExpColorMax[1] // G
|
||||
&& pixel[2] >= ExpColorMin[2] && pixel[2] <= ExpColorMax[2]; // R
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed) return;
|
||||
_disposed = true;
|
||||
|
||||
_linkedCts.Cancel();
|
||||
_linkedCts.Dispose();
|
||||
_resultTcs.TrySetResult(false);
|
||||
_detectionTask = null;
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,19 @@ public class Avatar
|
||||
/// 战斗场景
|
||||
/// </summary>
|
||||
public CombatScenes CombatScenes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 脱困方向数组(前/后/左/右)
|
||||
/// </summary>
|
||||
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,14 +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);
|
||||
region.SrcMat.SaveImage($"log/{Name}_切换失败.png");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 特意需要脱困情形下,会设置重试次数激活脱困检测,第10次重试时(2.5秒切换失败,超过角色的大招动画时间),如在盾奶位功能中次数会到第十次。
|
||||
if (i == 9 && AutoFightTask.FightStatusFlag)
|
||||
{
|
||||
PerformUnstuckAction(Ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SimulateSwitchAction(Index);
|
||||
|
||||
Sleep(250, Ct);
|
||||
@@ -302,6 +328,23 @@ public class Avatar
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 战斗中切换角色卡住时的脱困动作:跳跃 → 随机方向移动+切换 → 攻击 → 释放按键
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换到本角色
|
||||
/// 切换cd是1秒,如果切换失败,会尝试再次切换,最多尝试5次
|
||||
|
||||
@@ -407,7 +407,8 @@ public class PartyAvatarSideIndexHelper
|
||||
// 方法3:使用更加靠谱的差值识别(-1是未识别),但是不支持非满队
|
||||
if (mats.Length == 4)
|
||||
{
|
||||
return ImageDifferenceDetector.FindMostDifferentImage(mats);
|
||||
var result = ImageDifferenceDetector.FindMostDifferentImage(mats);
|
||||
return result >= 0 ? result + 1 : -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+1540
-1492
File diff suppressed because it is too large.
Load diff
@@ -1715,6 +1715,27 @@
|
||||
"strategy": "蒙德7-达达乌帕谷",
|
||||
"steps": 6,
|
||||
"order": 6
|
||||
},
|
||||
{
|
||||
"x": -155,
|
||||
"y": 3324,
|
||||
"strategy": "蒙德8-风车镇",
|
||||
"steps": 3,
|
||||
"order": 1
|
||||
},
|
||||
{
|
||||
"x": -256,
|
||||
"y": 3295,
|
||||
"strategy": "蒙德8-风车镇",
|
||||
"steps": 3,
|
||||
"order": 2
|
||||
},
|
||||
{
|
||||
"x": -330,
|
||||
"y": 3226,
|
||||
"strategy": "蒙德8-风车镇",
|
||||
"steps": 3,
|
||||
"order": 3
|
||||
}
|
||||
],
|
||||
"须弥": [
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"info": {
|
||||
"authors": [
|
||||
{
|
||||
"links": "",
|
||||
"name": "ddaodan"
|
||||
}
|
||||
],
|
||||
"bgi_version": "0.60.0",
|
||||
"description": "",
|
||||
"enable_monster_loot_split": false,
|
||||
"last_modified_time": 1775792800230,
|
||||
"map_match_method": "SIFT",
|
||||
"map_name": "Teyvat",
|
||||
"name": "蒙德8-风车镇-1",
|
||||
"tags": [],
|
||||
"type": "collect",
|
||||
"version": "1.0"
|
||||
},
|
||||
"positions": [
|
||||
{
|
||||
"id": 1,
|
||||
"x": -155.69140625,
|
||||
"y": 3324.93212890625,
|
||||
"type": "target",
|
||||
"move_mode": "walk"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"info": {
|
||||
"authors": [
|
||||
{
|
||||
"links": "",
|
||||
"name": "ddaodan"
|
||||
}
|
||||
],
|
||||
"bgi_version": "0.60.0",
|
||||
"description": "",
|
||||
"enable_monster_loot_split": false,
|
||||
"last_modified_time": 1775792896742,
|
||||
"map_match_method": "SIFT",
|
||||
"map_name": "Teyvat",
|
||||
"name": "蒙德8-风车镇-2",
|
||||
"tags": [],
|
||||
"type": "collect",
|
||||
"version": "1.0"
|
||||
},
|
||||
"positions": [
|
||||
{
|
||||
"id": 1,
|
||||
"x": -256.87890625,
|
||||
"y": 3295.62060546875,
|
||||
"type": "target",
|
||||
"move_mode": "walk"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"info": {
|
||||
"authors": [
|
||||
{
|
||||
"links": "",
|
||||
"name": "ddaodan"
|
||||
}
|
||||
],
|
||||
"bgi_version": "0.60.0",
|
||||
"description": "",
|
||||
"enable_monster_loot_split": false,
|
||||
"last_modified_time": 1775793214341,
|
||||
"map_match_method": "SIFT",
|
||||
"map_name": "Teyvat",
|
||||
"name": "蒙德8-风车镇-3",
|
||||
"tags": [],
|
||||
"type": "collect",
|
||||
"version": "1.0"
|
||||
},
|
||||
"positions": [
|
||||
{
|
||||
"id": 1,
|
||||
"x": -330.87890625,
|
||||
"y": 3226.130859375,
|
||||
"type": "target",
|
||||
"move_mode": "walk"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"info": {
|
||||
"authors": [
|
||||
{
|
||||
"links": "",
|
||||
"name": "ddaodan"
|
||||
}
|
||||
],
|
||||
"bgi_version": "0.60.0",
|
||||
"description": "",
|
||||
"enable_monster_loot_split": false,
|
||||
"last_modified_time": 1775792800230,
|
||||
"map_match_method": "SIFT",
|
||||
"map_name": "Teyvat",
|
||||
"name": "蒙德8-风车镇-1",
|
||||
"tags": [],
|
||||
"type": "collect",
|
||||
"version": "1.0"
|
||||
},
|
||||
"positions": [
|
||||
{
|
||||
"action": "",
|
||||
"action_params": "",
|
||||
"id": 1,
|
||||
"move_mode": "walk",
|
||||
"type": "teleport",
|
||||
"x": -82.462890625,
|
||||
"y": 3309.48583984375
|
||||
},
|
||||
{
|
||||
"action": "stop_flying",
|
||||
"action_params": "",
|
||||
"id": 2,
|
||||
"locked": false,
|
||||
"move_mode": "fly",
|
||||
"type": "path",
|
||||
"x": -155.69140625,
|
||||
"y": 3324.93212890625
|
||||
},
|
||||
{
|
||||
"action": "",
|
||||
"action_params": "",
|
||||
"id": 3,
|
||||
"move_mode": "walk",
|
||||
"type": "target",
|
||||
"x": -155.69140625,
|
||||
"y": 3324.93212890625
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"info": {
|
||||
"authors": [
|
||||
{
|
||||
"links": "",
|
||||
"name": "ddaodan"
|
||||
}
|
||||
],
|
||||
"bgi_version": "0.60.0",
|
||||
"description": "",
|
||||
"enable_monster_loot_split": false,
|
||||
"last_modified_time": 1775792896742,
|
||||
"map_match_method": "SIFT",
|
||||
"map_name": "Teyvat",
|
||||
"name": "蒙德8-风车镇-2",
|
||||
"tags": [],
|
||||
"type": "collect",
|
||||
"version": "1.0"
|
||||
},
|
||||
"positions": [
|
||||
{
|
||||
"action": "",
|
||||
"action_params": "",
|
||||
"id": 1,
|
||||
"move_mode": "dash",
|
||||
"type": "path",
|
||||
"x": -193.931640625,
|
||||
"y": 3335.927734375
|
||||
},
|
||||
{
|
||||
"action": "",
|
||||
"action_params": "",
|
||||
"id": 2,
|
||||
"move_mode": "dash",
|
||||
"type": "target",
|
||||
"x": -256.87890625,
|
||||
"y": 3295.62060546875
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"info": {
|
||||
"authors": [
|
||||
{
|
||||
"links": "",
|
||||
"name": "ddaodan"
|
||||
}
|
||||
],
|
||||
"bgi_version": "0.60.0",
|
||||
"description": "",
|
||||
"enable_monster_loot_split": false,
|
||||
"last_modified_time": 1775793214341,
|
||||
"map_match_method": "SIFT",
|
||||
"map_name": "Teyvat",
|
||||
"name": "蒙德8-风车镇-3",
|
||||
"tags": [],
|
||||
"type": "collect",
|
||||
"version": "1.0"
|
||||
},
|
||||
"positions": [
|
||||
{
|
||||
"action": "",
|
||||
"action_params": "",
|
||||
"id": 1,
|
||||
"move_mode": "dash",
|
||||
"type": "path",
|
||||
"x": -273.49609375,
|
||||
"y": 3291.94677734375
|
||||
},
|
||||
{
|
||||
"action": "",
|
||||
"action_params": "",
|
||||
"id": 2,
|
||||
"move_mode": "dash",
|
||||
"type": "target",
|
||||
"x": -330.87890625,
|
||||
"y": 3226.130859375
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoPick
|
||||
@@ -37,6 +37,14 @@ namespace BetterGenshinImpact.GameTask.AutoPick
|
||||
[ObservableProperty]
|
||||
private string _ocrEngine = PickOcrEngineEnum.Paddle.ToString();
|
||||
|
||||
/// <summary>
|
||||
/// 拾取识别模式
|
||||
/// - Ocr: 通过OCR识别物品名
|
||||
/// - RedNet: 通过分类模型直接识别物品名
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _recognitionMode = PickRecognitionModeEnum.Ocr.ToString();
|
||||
|
||||
/// <summary>
|
||||
/// 急速模式
|
||||
/// 无视文字识别结果,直接拾取
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.Core.Recognition;
|
||||
using BetterGenshinImpact.Core.Recognition.ONNX;
|
||||
using BetterGenshinImpact.Core.Recognition.OCR;
|
||||
using BetterGenshinImpact.Core.Recognition.ONNX.SVTR;
|
||||
using BetterGenshinImpact.Core.Script.Dependence.Model.TimerConfig;
|
||||
@@ -8,6 +9,7 @@ using BetterGenshinImpact.GameTask.AutoPick.Assets;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using BetterGenshinImpact.Service;
|
||||
using BetterGenshinImpact.View.Windows;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
@@ -49,9 +51,14 @@ public partial class AutoPickTrigger : ITaskTrigger
|
||||
private HashSet<string> _whiteList = [];
|
||||
|
||||
private RecognitionObject _pickRo;
|
||||
private readonly Lazy<BgiRedNetPredictor> _pickRedNetPredictor = new(() =>
|
||||
App.ServiceProvider.GetRequiredService<BgiOnnxFactory>().CreateRedNetPredictor(BgiOnnxModel.BgiPickRedNet110));
|
||||
|
||||
// 外部配置
|
||||
private AutoPickExternalConfig? _externalConfig;
|
||||
|
||||
double scale = TaskContext.Instance().SystemInfo.AssetScale;
|
||||
AutoPickConfig config = TaskContext.Instance().Config.AutoPickConfig;
|
||||
|
||||
public AutoPickTrigger()
|
||||
{
|
||||
@@ -192,8 +199,7 @@ public partial class AutoPickTrigger : ITaskTrigger
|
||||
return;
|
||||
}
|
||||
|
||||
var scale = TaskContext.Instance().SystemInfo.AssetScale;
|
||||
var config = TaskContext.Instance().Config.AutoPickConfig;
|
||||
|
||||
|
||||
// 存在 L 键位是千星奇遇,无需拾取
|
||||
using var lKeyRa = content.CaptureRectArea.Find(_autoPickAssets.LRo);
|
||||
@@ -204,9 +210,10 @@ public partial class AutoPickTrigger : ITaskTrigger
|
||||
|
||||
// 识别到拾取键,开始识别物品图标
|
||||
var isExcludeIcon = false;
|
||||
_autoPickAssets.ChatIconRo.RegionOfInterest = new Rect(
|
||||
var iconRect = new Rect(
|
||||
foundRectArea.X + (int)(config.ItemIconLeftOffset * scale), foundRectArea.Y,
|
||||
(int)((config.ItemTextLeftOffset - config.ItemIconLeftOffset) * scale), foundRectArea.Height);
|
||||
_autoPickAssets.ChatIconRo.RegionOfInterest = iconRect;
|
||||
using var chatIconRa = content.CaptureRectArea.Find(_autoPickAssets.ChatIconRo);
|
||||
speedTimer.Record("识别聊天图标");
|
||||
if (!chatIconRa.IsEmpty())
|
||||
@@ -251,66 +258,15 @@ public partial class AutoPickTrigger : ITaskTrigger
|
||||
// return;
|
||||
//}
|
||||
|
||||
// 这类文字识别比较特殊,都是针对某个场景的文字识别,所以暂时未抽象到识别对象中
|
||||
// 计算出文字区域
|
||||
var textRect = new Rect(foundRectArea.X + (int)(config.ItemTextLeftOffset * scale), foundRectArea.Y,
|
||||
(int)((config.ItemTextRightOffset - config.ItemTextLeftOffset) * scale), foundRectArea.Height);
|
||||
if (textRect.X + textRect.Width > content.CaptureRectArea.CacheGreyMat.Width
|
||||
|| textRect.Y + textRect.Height > content.CaptureRectArea.CacheGreyMat.Height)
|
||||
{
|
||||
Debug.WriteLine("AutoPickTrigger: 文字区域 out of range");
|
||||
return;
|
||||
}
|
||||
|
||||
using var gradMat = new Mat(content.CaptureRectArea.CacheGreyMat,
|
||||
new Rect(textRect.X, textRect.Y, textRect.Width, Math.Min(textRect.Height, 3)));
|
||||
var avgGrad = gradMat.Sobel(MatType.CV_32F, 1, 0).Mean().Val0;
|
||||
if (avgGrad < -3)
|
||||
{
|
||||
Debug.WriteLine($"AutoPickTrigger: 已在拾取中,跳过本次拾取 {avgGrad}");
|
||||
return;
|
||||
}
|
||||
|
||||
string text;
|
||||
if (config.OcrEngine == nameof(PickOcrEngineEnum.Yap))
|
||||
if (config.RecognitionMode == nameof(PickRecognitionModeEnum.RedNet))
|
||||
{
|
||||
var textMat = new Mat(content.CaptureRectArea.CacheGreyMat, textRect);
|
||||
text = TextInferenceFactory.Pick.Value.Inference(textMat);
|
||||
text = RecognizePickTextByRedNet(content, foundRectArea);
|
||||
}
|
||||
else
|
||||
{
|
||||
using var textMat = new Mat(content.CaptureRectArea.SrcMat, textRect);
|
||||
var boundingRect = TextRectExtractor.GetTextBoundingRect(textMat);
|
||||
// var boundingRect = new Rect(); // 不使用自己写的文字区域提取
|
||||
// 如果找到有效区域
|
||||
if (boundingRect.X < 20 && boundingRect.Width > 5 && boundingRect.Height > 5)
|
||||
{
|
||||
// 截取只包含文字的区域
|
||||
using var textOnlyMat = new Mat(textMat, new Rect(0, 0,
|
||||
boundingRect.Right + 5 < textMat.Width ? boundingRect.Right + 5 : textMat.Width, textMat.Height));
|
||||
text = OcrFactory.Paddle.OcrWithoutDetector(textOnlyMat);
|
||||
|
||||
// if (RuntimeHelper.IsDebug)
|
||||
// {
|
||||
// // 如果不等于正确文字,则保存图片
|
||||
// if (text != "烹饪")
|
||||
// {
|
||||
// var path = Global.Absolute("log/pick");
|
||||
// Directory.CreateDirectory(path);
|
||||
// var str = $"{DateTime.Now:yyyyMMddHHmmssfff}";
|
||||
// // textMat.SaveImage(Path.Combine(path, $"pick_ocr_ori_{str}.png"));
|
||||
// // 画上 boundingRect
|
||||
// Cv2.Rectangle(textMat, boundingRect, new Scalar(0, 0, 255), 1);
|
||||
// textMat.SaveImage(Path.Combine(path, $"pick_ocr_rect_{str}.png"));
|
||||
// bin.SaveImage(Path.Combine(path, $"bin_{str}.png"));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine("-- 无法识别到有效文字区域,尝试直接OCR DET");
|
||||
text = OcrFactory.Paddle.Ocr(textMat);
|
||||
}
|
||||
text = RecognizePickTextByOcr(content, foundRectArea, config.OcrEngine);
|
||||
}
|
||||
|
||||
speedTimer.Record("文字识别");
|
||||
@@ -370,6 +326,90 @@ public partial class AutoPickTrigger : ITaskTrigger
|
||||
speedTimer.DebugPrint();
|
||||
}
|
||||
|
||||
private string RecognizePickTextByRedNet(CaptureContent content, Region foundRectArea)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 32x32 图片
|
||||
var iconRect = new Rect(foundRectArea.X + (int)((config.ItemIconLeftOffset + 10) * scale), foundRectArea.Y, (int)(32 * scale), (int)(32 * scale));
|
||||
using var imageRegion = content.CaptureRectArea.DeriveCrop(iconRect);
|
||||
imageRegion.SrcMat.SaveImage(@"log/pick/rednet_input.png");
|
||||
var prediction = _pickRedNetPredictor.Value.Predict(imageRegion.CacheImage);
|
||||
// Debug.WriteLine($"AutoPickTrigger: RedNet预测结果 {prediction.ClassLabel} 置信度 {prediction.Confidence}");
|
||||
if (prediction.Confidence < 0.47)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return prediction.ClassLabel;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogWarning(e, "AutoPick RedNet推理失败,回退OCR");
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private string RecognizePickTextByOcr(CaptureContent content, Region foundRectArea, string ocrEngine)
|
||||
{
|
||||
// 这类文字识别比较特殊,都是针对某个场景的文字识别,所以暂时未抽象到识别对象中
|
||||
// 计算出文字区域
|
||||
var textRect = new Rect(foundRectArea.X + (int)(config.ItemTextLeftOffset * scale), foundRectArea.Y,
|
||||
(int)((config.ItemTextRightOffset - config.ItemTextLeftOffset) * scale), foundRectArea.Height);
|
||||
if (textRect.X + textRect.Width > content.CaptureRectArea.CacheGreyMat.Width
|
||||
|| textRect.Y + textRect.Height > content.CaptureRectArea.CacheGreyMat.Height)
|
||||
{
|
||||
Debug.WriteLine("AutoPickTrigger: 文字区域 out of range");
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
using var gradMat = new Mat(content.CaptureRectArea.CacheGreyMat,
|
||||
new Rect(textRect.X, textRect.Y, textRect.Width, Math.Min(textRect.Height, 3)));
|
||||
var avgGrad = gradMat.Sobel(MatType.CV_32F, 1, 0).Mean().Val0;
|
||||
if (avgGrad < -3)
|
||||
{
|
||||
Debug.WriteLine($"AutoPickTrigger: 已在拾取中,跳过本次拾取 {avgGrad}");
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (ocrEngine == nameof(PickOcrEngineEnum.Yap))
|
||||
{
|
||||
using var textMat = new Mat(content.CaptureRectArea.CacheGreyMat, textRect);
|
||||
return TextInferenceFactory.Pick.Value.Inference(textMat);
|
||||
}
|
||||
|
||||
using var paddleMat = new Mat(content.CaptureRectArea.SrcMat, textRect);
|
||||
var boundingRect = TextRectExtractor.GetTextBoundingRect(paddleMat);
|
||||
// var boundingRect = new Rect(); // 不使用自己写的文字区域提取
|
||||
// 如果找到有效区域
|
||||
if (boundingRect.X < 20 && boundingRect.Width > 5 && boundingRect.Height > 5)
|
||||
{
|
||||
// 截取只包含文字的区域
|
||||
using var textOnlyMat = new Mat(paddleMat, new Rect(0, 0,
|
||||
boundingRect.Right + 5 < paddleMat.Width ? boundingRect.Right + 5 : paddleMat.Width, paddleMat.Height));
|
||||
return OcrFactory.Paddle.OcrWithoutDetector(textOnlyMat);
|
||||
|
||||
// if (RuntimeHelper.IsDebug)
|
||||
// {
|
||||
// // 如果不等于正确文字,则保存图片
|
||||
// if (text != "烹饪")
|
||||
// {
|
||||
// var path = Global.Absolute("log/pick");
|
||||
// Directory.CreateDirectory(path);
|
||||
// var str = $"{DateTime.Now:yyyyMMddHHmmssfff}";
|
||||
// // textMat.SaveImage(Path.Combine(path, $"pick_ocr_ori_{str}.png"));
|
||||
// // 画上 boundingRect
|
||||
// Cv2.Rectangle(textMat, boundingRect, new Scalar(0, 0, 255), 1);
|
||||
// textMat.SaveImage(Path.Combine(path, $"pick_ocr_rect_{str}.png"));
|
||||
// bin.SaveImage(Path.Combine(path, $"bin_{str}.png"));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
Debug.WriteLine("-- 无法识别到有效文字区域,尝试直接OCR DET");
|
||||
return OcrFactory.Paddle.Ocr(paddleMat);
|
||||
}
|
||||
|
||||
private bool DoNotPick(string text)
|
||||
{
|
||||
// 唯一一个动态拾取项,特殊处理,不拾取
|
||||
@@ -576,4 +616,4 @@ public partial class AutoPickTrigger : ITaskTrigger
|
||||
|
||||
return cleanedSpan.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace BetterGenshinImpact.GameTask.AutoPick;
|
||||
namespace BetterGenshinImpact.GameTask.AutoPick;
|
||||
|
||||
public enum PickOcrEngineEnum
|
||||
{
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace BetterGenshinImpact.GameTask.AutoPick;
|
||||
|
||||
public enum PickRecognitionModeEnum
|
||||
{
|
||||
Ocr,
|
||||
RedNet
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public class AutoStygianOnslaughtTask : StateMachineBase<StygianState, BvPage>,
|
||||
(StygianState.EventMenu, [StygianState.StygianOnslaughtPage]),
|
||||
(StygianState.StygianOnslaughtPage, [StygianState.TeleportMap, StygianState.DomainEntrance]),
|
||||
(StygianState.TeleportMap, [StygianState.DomainEntrance]),
|
||||
(StygianState.DomainEntrance, [StygianState.DifficultySelect]),
|
||||
(StygianState.DomainEntrance, [StygianState.DomainEntrance, StygianState.DifficultySelect]),
|
||||
(StygianState.DifficultySelect, [StygianState.DomainLobby]),
|
||||
(StygianState.DomainLobby, [StygianState.BossSelect, StygianState.LeylineFlowerPrompt]),
|
||||
|
||||
@@ -369,10 +369,10 @@ public class AutoStygianOnslaughtTask : StateMachineBase<StygianState, BvPage>,
|
||||
await Delay(500, _ct);
|
||||
|
||||
// 2. 在列表区域内查找"幽境危战"并点击
|
||||
var listItem = page.GetByText("幽境危战").WithRoi(listRegion);
|
||||
if (listItem.IsExist())
|
||||
var target = page.GetByText("幽境危战").WithRoi(listRegion).FindAll().FirstOrDefault();
|
||||
if (target != null)
|
||||
{
|
||||
listItem.FindAll().FirstOrDefault()?.Click();
|
||||
target.Click();
|
||||
await Delay(300, _ct);
|
||||
return StateHandlerResult.Success; // 等待转换到 StygianOnslaughtPage
|
||||
}
|
||||
@@ -382,15 +382,20 @@ public class AutoStygianOnslaughtTask : StateMachineBase<StygianState, BvPage>,
|
||||
|
||||
// 如果两次都没找到,可能"幽境危战"已经被选中,直接尝试检测下一状态
|
||||
Logger.LogWarning($"{Name}:未找到幽境危战,可能已被选中,尝试检测 StygianOnslaughtPage");
|
||||
page.GetByText("幽境危战").WithRoi(listRegion).FindAll().FirstOrDefault()?.Click();
|
||||
await Delay(300, _ct);
|
||||
return StateHandlerResult.Success; // 等待转换到 StygianOnslaughtPage
|
||||
return StateHandlerResult.Success; // 让状态机继续等待邻接状态出现
|
||||
}
|
||||
|
||||
private async Task<StateHandlerResult> HandleStygianOnslaughtPageState(BvPage page)
|
||||
{
|
||||
Logger.LogInformation($"{Name}:点击前往挑战");
|
||||
page.GetByText("前往挑战").WithRoi(r => r.CutRight(0.5)).FindAll().FirstOrDefault()?.Click();
|
||||
var challengeButton = page.GetByText("前往挑战").WithRoi(r => r.CutRight(0.5)).FindAll().FirstOrDefault();
|
||||
if (challengeButton == null)
|
||||
{
|
||||
Logger.LogWarning($"{Name}:未找到前往挑战按钮");
|
||||
return StateHandlerResult.Retry;
|
||||
}
|
||||
|
||||
challengeButton.Click();
|
||||
await Delay(300, _ct);
|
||||
return StateHandlerResult.Success; // 等待转换到 TeleportMap 或 DomainEntrance
|
||||
}
|
||||
@@ -398,7 +403,14 @@ public class AutoStygianOnslaughtTask : StateMachineBase<StygianState, BvPage>,
|
||||
private async Task<StateHandlerResult> HandleTeleportMapState(BvPage page)
|
||||
{
|
||||
Logger.LogInformation($"{Name}:点击传送");
|
||||
page.Locator(QuickTeleportAssets.Instance.TeleportButtonRo).FindAll().FirstOrDefault()?.Click();
|
||||
var teleportButton = page.Locator(QuickTeleportAssets.Instance.TeleportButtonRo).FindAll().FirstOrDefault();
|
||||
if (teleportButton == null)
|
||||
{
|
||||
Logger.LogWarning($"{Name}:未找到传送按钮");
|
||||
return StateHandlerResult.Retry;
|
||||
}
|
||||
|
||||
teleportButton.Click();
|
||||
await Delay(300, _ct);
|
||||
return StateHandlerResult.Success; // 等待转换到 DomainEntrance
|
||||
}
|
||||
@@ -421,6 +433,12 @@ public class AutoStygianOnslaughtTask : StateMachineBase<StygianState, BvPage>,
|
||||
// 点击确认进入
|
||||
using var ra = CaptureToRectArea();
|
||||
var btn = ra.Find(ElementAssets.Instance.BtnWhiteConfirm);
|
||||
if (btn.IsEmpty())
|
||||
{
|
||||
Logger.LogWarning($"{Name}:未找到进入确认按钮");
|
||||
return StateHandlerResult.Retry;
|
||||
}
|
||||
|
||||
btn.Click();
|
||||
await Delay(300, _ct);
|
||||
return StateHandlerResult.Success; // 等待转换到 DomainLobby
|
||||
|
||||
@@ -1007,7 +1007,7 @@ public class TpTask
|
||||
if (matchRect == null)
|
||||
{
|
||||
Logger.LogWarning("切换区域失败:{Country}", areaName);
|
||||
if (areaName == MapTypes.TheChasm.GetDescription() || areaName == MapTypes.Enkanomiya.GetDescription() || areaName == MapTypes.SeaOfBygoneEras.GetDescription() || areaName == MapTypes.AncientSacredMountain.GetDescription())
|
||||
if (areaName == MapTypes.TheChasm.GetDescription() || areaName == MapTypes.Enkanomiya.GetDescription() || areaName == MapTypes.SeaOfBygoneEras.GetDescription() || areaName == MapTypes.AncientSacredMountain.GetDescription() || areaName == MapTypes.TempleOfSpace.GetDescription())
|
||||
{
|
||||
throw new Exception($"切换独立地图区域[{areaName}]失败");
|
||||
}
|
||||
|
||||
@@ -19,4 +19,7 @@ public enum DisplayMapTypes
|
||||
|
||||
[Description("远古圣山")]
|
||||
AncientSacredMountain,
|
||||
|
||||
[Description("空之神殿")]
|
||||
TempleOfSpace,
|
||||
}
|
||||
@@ -18,7 +18,10 @@ public enum MapTypes
|
||||
SeaOfBygoneEras,
|
||||
|
||||
[Description("远古圣山")]
|
||||
AncientSacredMountain
|
||||
AncientSacredMountain,
|
||||
|
||||
[Description("空之神殿")]
|
||||
TempleOfSpace,
|
||||
}
|
||||
public static class MapTypesExtensions
|
||||
{
|
||||
|
||||
@@ -58,6 +58,7 @@ public static class MapManager
|
||||
MapTypes.Enkanomiya => new EnkanomiyaMap(),
|
||||
MapTypes.AncientSacredMountain => new AncientSacredMountainMap(),
|
||||
MapTypes.SeaOfBygoneEras => new SeaOfBygoneErasMap(),
|
||||
MapTypes.TempleOfSpace => new TempleOfSpaceMap(),
|
||||
_ => throw new System.ArgumentException($"未知的地图类型: {mapType}", nameof(mapType))
|
||||
};
|
||||
}
|
||||
@@ -70,6 +71,7 @@ public static class MapManager
|
||||
MapTypes.Enkanomiya => new EnkanomiyaMapTest(),
|
||||
MapTypes.AncientSacredMountain => new AncientSacredMountainMap(),
|
||||
MapTypes.SeaOfBygoneEras => new SeaOfBygoneErasMap(),
|
||||
MapTypes.TempleOfSpace => new TempleOfSpaceMap(),
|
||||
_ => throw new System.ArgumentException($"未知的地图类型: {mapType}", nameof(mapType))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.GameTask.Common.Map.Maps.Base;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.Common.Map.Maps;
|
||||
|
||||
/// <summary>
|
||||
/// 空之神殿
|
||||
/// </summary>
|
||||
public class TempleOfSpaceMap : SceneBaseMap
|
||||
{
|
||||
#region 每次地图扩大都要更新的参数
|
||||
|
||||
static readonly int GameMapRows = 4; // 游戏坐标下地图块的行数
|
||||
static readonly int GameMapCols = 3; // 游戏坐标下地图块的列数
|
||||
static readonly int GameMapUpRows = 1; // 游戏坐标下 左上角离地图原点的行数(注意原点在0_0块的右下角)
|
||||
static readonly int GameMapLeftCols = 1; // 游戏坐标下 左上角离地图原点的列数(注意原点在0_0块的右下角)
|
||||
|
||||
#endregion 每次地图扩大都要更新的参数
|
||||
|
||||
static readonly int TempleOfSpaceMapImageBlockWidth = 1024;
|
||||
|
||||
public TempleOfSpaceMap() : base(type: MapTypes.TempleOfSpace,
|
||||
mapSize: new Size(GameMapCols * TempleOfSpaceMapImageBlockWidth, GameMapRows * TempleOfSpaceMapImageBlockWidth),
|
||||
mapOriginInImageCoordinate: new Point2f((GameMapLeftCols + 1) * TempleOfSpaceMapImageBlockWidth, (GameMapUpRows + 1) * TempleOfSpaceMapImageBlockWidth),
|
||||
mapImageBlockWidth: TempleOfSpaceMapImageBlockWidth,
|
||||
splitRow: 0,
|
||||
splitCol: 0)
|
||||
{
|
||||
ExtractAndSaveFeature(Global.Absolute("Assets/Map/TempleOfSpace/TempleOfSpace_0_1024.png"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -315,7 +315,7 @@ namespace BetterGenshinImpact.GameTask
|
||||
PictureInPictureService.Hide(resetManual: true);
|
||||
// if (!_prevGameActive)
|
||||
// {
|
||||
maskWindow.Invoke(() =>
|
||||
maskWindow.BeginInvoke(() =>
|
||||
{
|
||||
if (maskWindow.IsExist())
|
||||
{
|
||||
|
||||
@@ -163,7 +163,7 @@
|
||||
},
|
||||
{
|
||||
"name": "胡桃",
|
||||
"scriptContent1": "charge(0.3),wait(0.1),dash,wait(0.1),charge(0.3),wait(0.1),dash,wait(0.1),charge(0.3),wait(0.1),j,wait(0.52)",
|
||||
"scriptContent1": "click,wait(0.25),click,wait(0.05),mousedown,wait(0.265),mouseup,click(right),wait(0.02),keypress(S),wait(0.02),keypress(w),wait(0.35)",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
|
||||
@@ -441,6 +441,20 @@ public partial class MaskWindow : Window
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void BeginInvoke(Action action)
|
||||
{
|
||||
try
|
||||
{
|
||||
Dispatcher.BeginInvoke(action);
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void HideSelf()
|
||||
{
|
||||
|
||||
@@ -1102,6 +1102,36 @@
|
||||
</Grid>
|
||||
<Separator Margin="-18,0"
|
||||
BorderThickness="0,1,0,0" />
|
||||
|
||||
<Grid Margin="16,16,16,16"
|
||||
Visibility="{Binding Config.AutoFightConfig.KazuhaPickupEnabled, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="基于经验值判断拾取(经验值57/58/60,不含传奇120等数字)"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="战斗中检测精英怪死亡经验值图标,未检测到时跳过拾取,避免无价值战斗后浪费时间"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:ToggleSwitch Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,36,0"
|
||||
IsChecked="{Binding Config.AutoFightConfig.ExpBasedPickupEnabled, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
<Separator Margin="-18,0"
|
||||
BorderThickness="0,1,0,0"
|
||||
Visibility="{Binding Config.AutoFightConfig.KazuhaPickupEnabled, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||
|
||||
<Grid Margin="16,16,16,16">
|
||||
<Grid.RowDefinitions>
|
||||
|
||||
@@ -92,12 +92,39 @@
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="选择自动拾取文字识别引擎"
|
||||
Text="选择自动拾取识别模式"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="Paddle可识别所有文字,速度慢,消耗少;Yap可识别部分文字,快且准,消耗大"
|
||||
Text="Ocr: 通过OCR识别物品名; RedNet: 直接推理拾取图像识别物品名"
|
||||
TextWrapping="Wrap" />
|
||||
<ComboBox Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Width="100"
|
||||
Margin="0,0,8,0"
|
||||
ItemsSource="{Binding PickRecognitionModeNames}"
|
||||
SelectedItem="{Binding Config.AutoPickConfig.RecognitionMode, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="选择OCR引擎"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="仅在识别模式为 Ocr 时生效:Paddle可识别所有文字,速度慢,消耗少;Yap可识别部分文字,快且准,消耗大"
|
||||
TextWrapping="Wrap" />
|
||||
<ComboBox Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
|
||||
@@ -1482,6 +1482,41 @@
|
||||
Text="二次拾取"
|
||||
TextWrapping="Wrap" />
|
||||
</Grid>
|
||||
<Grid Margin="16">
|
||||
<Grid.Style>
|
||||
<Style TargetType="Grid">
|
||||
<Setter Property="Visibility" Value="Visible"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding PathingConfig.AutoFightConfig.KazuhaPickupEnabled}" Value="False">
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Grid.Style>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="基于经验值判断拾取(经验值57/58/60,不含传奇120等数字)"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="战斗中检测精英怪死亡经验数字值图标,未检测到时跳过拾取,避免无价值战斗后浪费时间"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:ToggleSwitch Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,36,0"
|
||||
IsChecked="{Binding PathingConfig.AutoFightConfig.ExpBasedPickupEnabled, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
|
||||
@@ -30,6 +30,8 @@ public partial class TriggerSettingsPageViewModel : ViewModel
|
||||
|
||||
[ObservableProperty] private string[] _selectChatOptionTypeNames = [SelectChatOptionTypes.UseMouse, SelectChatOptionTypes.UseInteractionKey];
|
||||
|
||||
[ObservableProperty] private string[] _pickRecognitionModeNames = [PickRecognitionModeEnum.Ocr.ToString(), PickRecognitionModeEnum.RedNet.ToString()];
|
||||
|
||||
[ObservableProperty] private string[] _pickOcrEngineNames = [PickOcrEngineEnum.Paddle.ToString(), PickOcrEngineEnum.Yap.ToString()];
|
||||
|
||||
[ObservableProperty] private List<string> _pickButtonNames;
|
||||
|
||||
@@ -106,6 +106,10 @@ public partial class MapViewerViewModel : ObservableObject
|
||||
{
|
||||
_mapImage = new Mat(Global.Absolute(@"Assets/Map/AncientSacredMountain/AncientSacredMountain_0_1024.png"));
|
||||
}
|
||||
else if (mapName == MapTypes.TempleOfSpace.ToString())
|
||||
{
|
||||
_mapImage = new Mat(Global.Absolute(@"Assets/Map/TempleOfSpace/TempleOfSpace_0_1024.png"));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("暂时不支持展示路径的地图类型:" + mapName);
|
||||
|
||||
Reference in new issue
Block a user