mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-04-13 20:43:31 +08:00
101 lines
3.1 KiB
C#
101 lines
3.1 KiB
C#
using BetterGenshinImpact.Core.Config;
|
|
using BetterGenshinImpact.GameTask.GameLoading.Assets;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using BetterGenshinImpact.GameTask.Common;
|
|
using BetterGenshinImpact.GameTask.Common.BgiVision;
|
|
using BetterGenshinImpact.GameTask.Common.Element.Assets;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace BetterGenshinImpact.GameTask.GameLoading;
|
|
|
|
public class GameLoadingTrigger : ITaskTrigger
|
|
{
|
|
public string Name => "自动开门";
|
|
|
|
public bool IsEnabled { get; set; }
|
|
|
|
public int Priority => 999;
|
|
|
|
public bool IsExclusive => false;
|
|
|
|
public bool IsBackgroundRunning => true;
|
|
|
|
private readonly GameLoadingAssets _assets;
|
|
|
|
private readonly GenshinStartConfig _config = TaskContext.Instance().Config.GenshinStartConfig;
|
|
|
|
// private int _enterGameClickCount = 0;
|
|
// private int _welkinMoonClickCount = 0;
|
|
// private int _noneClickCount, _wmNoneClickCount;
|
|
|
|
private DateTime _prevExecuteTime = DateTime.MinValue;
|
|
|
|
private DateTime _triggerStartTime = DateTime.Now;
|
|
|
|
public GameLoadingTrigger()
|
|
{
|
|
GameLoadingAssets.DestroyInstance();
|
|
_assets = GameLoadingAssets.Instance;
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
IsEnabled = _config.AutoEnterGameEnabled;
|
|
// // 前面没有联动启动原神,这个任务也不用启动
|
|
// if ((DateTime.Now - TaskContext.Instance().LinkedStartGenshinTime).TotalMinutes >= 5)
|
|
// {
|
|
// IsEnabled = false;
|
|
// }
|
|
}
|
|
|
|
public void OnCapture(CaptureContent content)
|
|
{
|
|
// 2s 一次
|
|
if ((DateTime.Now - _prevExecuteTime).TotalMilliseconds <= 2000)
|
|
{
|
|
return;
|
|
}
|
|
_prevExecuteTime = DateTime.Now;
|
|
// 5min 后自动停止
|
|
if ((DateTime.Now -_triggerStartTime).TotalMinutes >= 5)
|
|
{
|
|
IsEnabled = false;
|
|
return;
|
|
}
|
|
|
|
if (Bv.IsInMainUi(content.CaptureRectArea) || Bv.IsInAnyClosableUi(content.CaptureRectArea))
|
|
{
|
|
IsEnabled = false;
|
|
return;
|
|
}
|
|
|
|
using var ra = content.CaptureRectArea.Find(_assets.EnterGameRo);
|
|
if (!ra.IsEmpty())
|
|
{
|
|
// 随便找个相对点击的位置
|
|
TaskContext.Instance().PostMessageSimulator.LeftButtonClickBackground();
|
|
// TaskControl.Logger.LogInformation("自动开门");
|
|
return;
|
|
}
|
|
|
|
var wmRa = content.CaptureRectArea.Find(_assets.WelkinMoonRo);
|
|
if (!wmRa.IsEmpty())
|
|
{
|
|
TaskContext.Instance().PostMessageSimulator.LeftButtonClickBackground();
|
|
Debug.WriteLine("[GameLoading] Click blessing of the welkin moon");
|
|
// TaskControl.Logger.LogInformation("自动点击月卡");
|
|
return;
|
|
}
|
|
|
|
// 原石
|
|
var ysRa = content.CaptureRectArea.Find(ElementAssets.Instance.PrimogemRo);
|
|
if (!ysRa.IsEmpty())
|
|
{
|
|
TaskContext.Instance().PostMessageSimulator.LeftButtonClickBackground();
|
|
Debug.WriteLine("[GameLoading] 跳过原石");
|
|
return;
|
|
}
|
|
}
|
|
}
|