mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-04-14 20:53:30 +08:00
73 lines
2.2 KiB
C#
73 lines
2.2 KiB
C#
using BetterGenshinImpact.Core.Recognition.OpenCv;
|
|
using BetterGenshinImpact.GameTask.AutoSkip.Assets;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using WindowsInput;
|
|
|
|
namespace BetterGenshinImpact.GameTask.AutoSkip;
|
|
|
|
/// <summary>
|
|
/// 自动剧情有选项点击
|
|
/// </summary>
|
|
public class AutoSkipTrigger : ITaskTrigger
|
|
{
|
|
private readonly ILogger<AutoSkipTrigger> _logger = App.GetLogger<AutoSkipTrigger>();
|
|
|
|
public string Name => "自动剧情";
|
|
public bool IsEnabled { get; set; }
|
|
public int Priority => 20;
|
|
public bool IsExclusive => false;
|
|
|
|
private readonly AutoSkipAssets _autoSkipAssets;
|
|
|
|
public AutoSkipTrigger()
|
|
{
|
|
_autoSkipAssets = new AutoSkipAssets();
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
IsEnabled = TaskContext.Instance().Config.AutoSkipConfig.Enabled;
|
|
}
|
|
|
|
public void OnCapture(CaptureContent content)
|
|
{
|
|
if (content.IsReachInterval(TimeSpan.FromMilliseconds(200)))
|
|
{
|
|
return;
|
|
}
|
|
|
|
// 找左上角剧情自动的按钮
|
|
content.CaptureRectArea.Find(_autoSkipAssets.StopAutoButtonRo, (_) =>
|
|
{
|
|
new InputSimulator().Keyboard.KeyPress(VirtualKeyCode.SPACE);
|
|
});
|
|
|
|
// 不存在则找右下的选项按钮
|
|
content.CaptureRectArea.Find(_autoSkipAssets.OptionButtonRo, (optionButtonRectArea) =>
|
|
{
|
|
// 不存在菜单的情况下 剧情在播放中
|
|
var menuRectArea = content.CaptureRectArea.Find(_autoSkipAssets.MenuRo);
|
|
if (menuRectArea.IsEmpty())
|
|
{
|
|
optionButtonRectArea.ClickCenter();
|
|
_logger.LogInformation("点击选项按钮");
|
|
}
|
|
});
|
|
|
|
// 黑屏剧情要点击鼠标(多次) 几乎全黑的时候不用点击
|
|
var grayMat = content.CaptureRectArea.SrcGreyMat;
|
|
var blackCount = OpenCvCommonHelper.CountGrayMatColor(grayMat, 0);
|
|
var rate = blackCount * 1.0 / (grayMat.Width * grayMat.Height);
|
|
if (rate > 0.7 && rate < 0.99)
|
|
{
|
|
new InputSimulator().Mouse.LeftButtonClick();
|
|
Debug.WriteLine($"点击黑屏剧情:{rate}");
|
|
return;
|
|
}
|
|
|
|
// TODO 自动交付材料
|
|
|
|
}
|
|
} |