Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f24e839b65 | ||
|
|
01c06b134a | ||
|
|
5fefcc2047 | ||
|
|
808dbec396 | ||
|
|
5681cb436c | ||
|
|
71e71c5d6b | ||
|
|
e94614a3a9 | ||
|
|
547b4a4929 | ||
|
|
dc04c22473 | ||
|
|
e779aab20b | ||
|
|
eeb6bb320b | ||
|
|
94e50307a5 | ||
|
|
99502ed35b | ||
|
|
2ecacc0eeb | ||
|
|
6f2b9ae95f | ||
|
|
fe21f945ab | ||
|
|
efc60de8df | ||
|
|
6d6f1b5153 | ||
|
|
ba2ae75556 | ||
|
|
6cba5a031b | ||
|
|
b4b9e0c8c0 | ||
|
|
b8fb06c839 | ||
|
|
48b88ab7de | ||
|
|
db0bde53a3 | ||
|
|
a124c7959e |
No files matched your search
@@ -63,7 +63,9 @@ public partial class App : Application
|
||||
.WriteTo.File(logFile,
|
||||
outputTemplate:
|
||||
"[{Timestamp:HH:mm:ss.fff}] [{Level:u3}] {SourceContext}{NewLine}{Message}{NewLine}{Exception}{NewLine}",
|
||||
rollingInterval: RollingInterval.Day)
|
||||
rollingInterval: RollingInterval.Day,
|
||||
retainedFileCountLimit: 31,
|
||||
retainedFileTimeLimit: TimeSpan.FromDays(21))
|
||||
.WriteTo.Console(outputTemplate:
|
||||
"[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
|
||||
.MinimumLevel.Debug()
|
||||
@@ -83,6 +85,9 @@ public partial class App : Application
|
||||
services.AddNavigationViewPageProvider();
|
||||
// App Host
|
||||
services.AddHostedService<ApplicationHostService>();
|
||||
// HTTP Server Service
|
||||
services.AddHostedService<HttpServerService>();
|
||||
|
||||
// Page resolver service
|
||||
services.AddSingleton<INavigationService, NavigationService>();
|
||||
services.AddSingleton<IUpdateService, UpdateService>();
|
||||
@@ -132,6 +137,9 @@ public partial class App : Application
|
||||
services.AddSingleton<HutaoNamedPipe>();
|
||||
services.AddSingleton<BgiOnnxFactory>();
|
||||
services.AddSingleton<OcrFactory>();
|
||||
|
||||
services.AddSingleton(TimeProvider.System);
|
||||
services.AddSingleton<IServerTimeProvider, ServerTimeProvider>();
|
||||
|
||||
// Configuration
|
||||
//services.Configure<AppConfig>(context.Configuration.GetSection(nameof(AppConfig)));
|
||||
@@ -179,6 +187,7 @@ public partial class App : Application
|
||||
ConsoleHelper.AllocateConsole("BetterGI Console");
|
||||
RegisterEvents();
|
||||
await _host.StartAsync();
|
||||
ServerTimeHelper.Initialize(_host.Services.GetRequiredService<IServerTimeProvider>());
|
||||
await UrlProtocolHelper.RegisterAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<AssemblyName>BetterGI</AssemblyName>
|
||||
<Version>0.51.0</Version>
|
||||
<Version>0.51.1-alpha.1</Version>
|
||||
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
|
||||
@@ -53,6 +53,8 @@
|
||||
<PackageReference Include="Emoji.Wpf" Version="0.3.4" />
|
||||
<PackageReference Include="LibGit2Sharp" Version="0.31.0" />
|
||||
<PackageReference Include="Meziantou.Framework.Win32.CredentialManager" Version="1.7.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Localization" Version="9.0.4" />
|
||||
|
||||
@@ -235,6 +235,11 @@ public partial class AllConfig : ObservableObject
|
||||
/// </summary>
|
||||
public HardwareAccelerationConfig HardwareAccelerationConfig { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// HTTP 服务器配置
|
||||
/// </summary>
|
||||
public HttpServerConfig HttpServerConfig { get; set; } = new();
|
||||
|
||||
[JsonIgnore]
|
||||
public Action? OnAnyChangedAction { get; set; }
|
||||
|
||||
@@ -267,6 +272,7 @@ public partial class AllConfig : ObservableObject
|
||||
PathingConditionConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
DevConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
HardwareAccelerationConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
HttpServerConfig.PropertyChanged += OnAnyPropertyChanged;
|
||||
}
|
||||
|
||||
public void OnAnyPropertyChanged(object? sender, EventArgs args)
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
|
||||
/// <summary>
|
||||
/// HTTP 服务器配置
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public partial class HttpServerConfig : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否启用 HTTP 服务器
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _enabled = false;
|
||||
|
||||
/// <summary>
|
||||
/// HTTP 服务器端口
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private int _port = 30648;
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用 CORS
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _enableCors = true;
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用 WebSocket 支持
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _enableWebSocket = true;
|
||||
|
||||
/// <summary>
|
||||
/// API 访问令牌(可选,用于安全验证)
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _accessToken = Guid.NewGuid().ToString("N");
|
||||
|
||||
// /// <summary>
|
||||
// /// 是否启用 Swagger 文档
|
||||
// /// </summary>
|
||||
// [ObservableProperty]
|
||||
// private bool _enableSwagger = true;
|
||||
|
||||
/// <summary>
|
||||
/// 监听地址
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _host = "localhost";
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
@@ -120,7 +122,8 @@ public partial class OneDragonFlowConfig : ObservableObject
|
||||
{
|
||||
if (WeeklyDomainEnabled)
|
||||
{
|
||||
var dayOfWeek = (DateTime.Now.Hour >= 4 ? DateTime.Today : DateTime.Today.AddDays(-1)).DayOfWeek;
|
||||
var serverTime = ServerTimeHelper.GetServerTimeNow();
|
||||
var dayOfWeek = (serverTime.Hour >= 4 ? serverTime : serverTime.AddDays(-1)).DayOfWeek;
|
||||
return dayOfWeek switch
|
||||
{
|
||||
DayOfWeek.Monday => (MondayPartyName, MondayDomainName,SundaySelectedValue),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using BetterGenshinImpact.Core.Recognition;
|
||||
using BetterGenshinImpact.Model;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
@@ -14,6 +15,9 @@ public partial class OtherConfig : ObservableObject
|
||||
//自动领取派遣任务城市
|
||||
[ObservableProperty]
|
||||
private string _autoFetchDispatchAdventurersGuildCountry = "无";
|
||||
//服务器时区偏移量
|
||||
[ObservableProperty]
|
||||
private TimeSpan _serverTimeZoneOffset = TimeSpan.FromHours(8);
|
||||
[ObservableProperty]
|
||||
private AutoRestart _autoRestartConfig = new();
|
||||
//锄地规划
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
@@ -10,9 +11,13 @@ public partial class PathingPartyTaskCycleConfig : ObservableObject
|
||||
[ObservableProperty]
|
||||
private bool _enable = false;
|
||||
|
||||
//周期分界时间点
|
||||
//周期分界时间点(小时),如果负数则不启用
|
||||
[ObservableProperty]
|
||||
private int _boundaryTime = 0;
|
||||
// 分界时间是否基于服务器时间(否则基于本地时间)
|
||||
[ObservableProperty]
|
||||
private bool _isBoundaryTimeBasedOnServerTime = false;
|
||||
|
||||
|
||||
//不同材料有不同的周期,按需配置,如矿石类是3、突破材料是2,或按照自已想几天执行一次配置即可
|
||||
[ObservableProperty]
|
||||
@@ -25,7 +30,7 @@ public partial class PathingPartyTaskCycleConfig : ObservableObject
|
||||
private int _index = 1;
|
||||
|
||||
|
||||
public int GetExecutionOrder(DateTime now)
|
||||
public int GetExecutionOrder(DateTimeOffset now)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -55,5 +60,11 @@ public partial class PathingPartyTaskCycleConfig : ObservableObject
|
||||
}
|
||||
|
||||
}
|
||||
public int GetExecutionOrder()
|
||||
{
|
||||
return GetExecutionOrder(IsBoundaryTimeBasedOnServerTime
|
||||
? ServerTimeHelper.GetServerTimeNow()
|
||||
: DateTimeOffset.Now);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,9 @@ public partial class TaskCompletionSkipRuleConfig:ObservableObject
|
||||
//周期分界时间点,如果负数则不启用,主要适用于固定时间的刷新物品适用
|
||||
[ObservableProperty]
|
||||
private int _boundaryTime = 4;
|
||||
// 分界时间是否基于服务器时间(否则基于本地时间)
|
||||
[ObservableProperty]
|
||||
private bool _isBoundaryTimeBasedOnServerTime = false;
|
||||
|
||||
//上一次执行间隔时间,出于精度考虑,这里使用秒为单位
|
||||
[ObservableProperty]
|
||||
|
||||
@@ -195,4 +195,6 @@ public class Det(BgiOnnxModel model, OcrVersionConfig config, BgiOnnxFactory bgi
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
public string GetConfigName => config.Name;
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -201,7 +200,7 @@ public class PaddleOcrService : IOcrService, IDisposable
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 中英文优先使用V4模型,其他语言使用V5模型
|
||||
/// </summary>
|
||||
@@ -342,4 +341,15 @@ public class PaddleOcrService : IOcrService, IDisposable
|
||||
_localDetModel.Dispose();
|
||||
_localRecModel.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回(DetConfigName, RecConfigName)
|
||||
/// </summary>
|
||||
public (string, string) GetConfigName
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this._localDetModel.GetConfigName, this._localRecModel.GetConfigName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,4 +181,6 @@ public class Rec(
|
||||
}
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
public string GetConfigName => config.Name;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Script.Dependence;
|
||||
|
||||
public static class ServerTime
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取服务器时区偏移量
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// 以毫秒为单位的偏移量
|
||||
/// 该值可直接在JavaScript中使用:`new Date(Date.now() + offset)`
|
||||
/// </returns>
|
||||
public static int GetServerTimeZoneOffset()
|
||||
{
|
||||
return (int)ServerTimeHelper.GetServerTimeOffset().TotalMilliseconds;
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,8 @@ public class EngineExtend
|
||||
|
||||
engine.AddHostObject("OpenCvSharp", new HostTypeCollection("OpenCvSharp"));
|
||||
|
||||
|
||||
engine.AddHostType("ServerTime", typeof(ServerTime));
|
||||
|
||||
|
||||
|
||||
// 添加C#的类型
|
||||
|
||||
@@ -19,6 +19,7 @@ using BetterGenshinImpact.GameTask.AutoPathing.Model.Enum;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.GameTask.FarmingPlan;
|
||||
using BetterGenshinImpact.GameTask.LogParse;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Script.Group;
|
||||
@@ -167,6 +168,10 @@ public partial class ScriptGroupProject : ObservableObject
|
||||
//执行记录
|
||||
ExecutionRecord executionRecord = new ExecutionRecord()
|
||||
{
|
||||
ServerStartTime =
|
||||
GroupInfo?.Config.PathingConfig.TaskCompletionSkipRuleConfig.IsBoundaryTimeBasedOnServerTime ?? false
|
||||
? ServerTimeHelper.GetServerTimeNow()
|
||||
: DateTimeOffset.Now,
|
||||
StartTime = DateTime.Now,
|
||||
GroupName = GroupInfo?.Name ?? "",
|
||||
FolderName = FolderName,
|
||||
@@ -280,6 +285,10 @@ public partial class ScriptGroupProject : ObservableObject
|
||||
executionRecord.IsSuccessful = true;
|
||||
}
|
||||
|
||||
executionRecord.ServerEndTime =
|
||||
GroupInfo?.Config.PathingConfig.TaskCompletionSkipRuleConfig.IsBoundaryTimeBasedOnServerTime ?? false
|
||||
? ServerTimeHelper.GetServerTimeNow()
|
||||
: DateTimeOffset.Now;
|
||||
executionRecord.EndTime = DateTime.Now;
|
||||
ExecutionRecordStorage.SaveExecutionRecord(executionRecord);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ using BetterGenshinImpact.GameTask.AutoDomain.Model;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using Compunet.YoloSharp;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using BetterGenshinImpact.GameTask.AutoFight;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoDomain;
|
||||
|
||||
@@ -390,8 +391,8 @@ public class AutoDomainTask : ISoloTask
|
||||
Logger.LogInformation("自动秘境:{Text}", "检测到秘境限时全开");
|
||||
}
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
if ((now.DayOfWeek == DayOfWeek.Sunday && now.Hour >= 4 || now.DayOfWeek == DayOfWeek.Monday && now.Hour < 4) || limitedFullyStringRaocrListdone != null)
|
||||
var serverTime = ServerTimeHelper.GetServerTimeNow();
|
||||
if (serverTime is { DayOfWeek: DayOfWeek.Sunday, Hour: >= 4 } || serverTime is { DayOfWeek: DayOfWeek.Monday, Hour: < 4 } || limitedFullyStringRaocrListdone != null)
|
||||
{
|
||||
using var artifactArea = CaptureToRectArea().Find(fightAssets.ArtifactAreaRa); //检测是否为圣遗物副本
|
||||
if (artifactArea.IsEmpty())
|
||||
@@ -646,6 +647,7 @@ public class AutoDomainTask : ISoloTask
|
||||
{
|
||||
try
|
||||
{
|
||||
AutoFightTask.FightStatusFlag = true;
|
||||
while (!cts.Token.IsCancellationRequested)
|
||||
{
|
||||
// 通用化战斗策略
|
||||
@@ -668,6 +670,7 @@ public class AutoDomainTask : ISoloTask
|
||||
{
|
||||
Logger.LogInformation("自动战斗线程结束");
|
||||
Simulation.ReleaseAllKey();
|
||||
AutoFightTask.FightStatusFlag = false;
|
||||
}
|
||||
}, cts.Token);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using BetterGenshinImpact.Helpers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using BetterGenshinImpact.GameTask.AutoPick;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoDomain.Model;
|
||||
|
||||
@@ -77,7 +78,7 @@ public class ResinStatus
|
||||
if (condensedResinRes.IsExist())
|
||||
{
|
||||
// 找出 icon 的位置 + 25 ~ icon 的位置+45 就是浓缩树脂的数字,数字宽20
|
||||
var condensedResinCountRect = new Rect(crop2.X + condensedResinRes.Right + (int)(20 * assetScale), (int)(37 * assetScale), (int)(70 * assetScale), (int)(24 * assetScale));
|
||||
var condensedResinCountRect = new Rect(crop2.X + condensedResinRes.Right + (int)(20 * assetScale), crop2.Y + condensedResinRes.Y, (int)(30 * assetScale), condensedResinRes.Height);
|
||||
using ImageRegion countRegion = region.DeriveCrop(condensedResinCountRect);
|
||||
using Mat threshold = countRegion.CacheGreyMat.Threshold(180, 255, ThresholdTypes.Binary);
|
||||
using Mat bitwiseNot = new Mat();
|
||||
|
||||
@@ -40,6 +40,8 @@ public class AutoFightTask : ISoloTask
|
||||
private readonly double _dpi = TaskContext.Instance().DpiScale;
|
||||
|
||||
public static OtherConfig Config { get; set; } = TaskContext.Instance().Config.OtherConfig;
|
||||
|
||||
public static bool FightStatusFlag { get; set; } = false;
|
||||
|
||||
private class TaskFightFinishDetectConfig
|
||||
{
|
||||
@@ -287,6 +289,8 @@ public class AutoFightTask : ISoloTask
|
||||
{
|
||||
try
|
||||
{
|
||||
FightStatusFlag = true;
|
||||
|
||||
while (!cts2.Token.IsCancellationRequested)
|
||||
{
|
||||
// 所有战斗角色都可以被取消
|
||||
@@ -442,6 +446,7 @@ public class AutoFightTask : ISoloTask
|
||||
finally
|
||||
{
|
||||
Simulation.ReleaseAllKey();
|
||||
FightStatusFlag = false;
|
||||
}
|
||||
}, cts2.Token);
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@ public class Avatar
|
||||
NameRect = nameRect;
|
||||
CombatAvatar = DefaultAutoFightConfig.CombatAvatarMap[name];
|
||||
ManualSkillCd = manualSkillCd;
|
||||
AutoFightTask.FightStatusFlag = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -291,7 +292,7 @@ public class Avatar
|
||||
private void Offset60Fix(int i)
|
||||
{
|
||||
// 3次失败考虑是否偏移出现问题,修改偏移位置
|
||||
if (i <= 2)
|
||||
if (i <= 2 || AutoFightTask.FightStatusFlag)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -300,18 +301,18 @@ public class Avatar
|
||||
{
|
||||
foreach (var avatar in CombatScenes.GetAvatars())
|
||||
{
|
||||
var rect1 = avatar.IndexRect;
|
||||
rect1.Y += 14;
|
||||
var originalRect = AutoFightAssets.Instance.AvatarIndexRectList[avatar.Index - 1];
|
||||
var rect1 = new Rect(originalRect.X, originalRect.Y, originalRect.Width, originalRect.Height);
|
||||
avatar.IndexRect = rect1;
|
||||
}
|
||||
|
||||
CombatScenes.IndexRectOffset60Fix = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var avatar in CombatScenes.GetAvatars())
|
||||
{
|
||||
var rect1 = avatar.IndexRect;
|
||||
var originalRect = AutoFightAssets.Instance.AvatarIndexRectList[avatar.Index - 1];
|
||||
var rect1 = new Rect(originalRect.X, originalRect.Y, originalRect.Width, originalRect.Height);
|
||||
rect1.Y -= 14;
|
||||
avatar.IndexRect = rect1;
|
||||
}
|
||||
|
||||
@@ -96,15 +96,15 @@ public class CombatScenes : IDisposable
|
||||
Logger.LogInformation("当前处于联机状态,且在别人世界中,联机人数{Num}人", num);
|
||||
}
|
||||
|
||||
avatarSideIconRectList = AutoFightAssets.Instance.AvatarSideIconRectListMap[$"{p}_{num}"];
|
||||
avatarIndexRectList = AutoFightAssets.Instance.AvatarIndexRectListMap[$"{p}_{num}"];
|
||||
avatarSideIconRectList = new List<Rect>(AutoFightAssets.Instance.AvatarSideIconRectListMap[$"{p}_{num}"]);
|
||||
avatarIndexRectList = new List<Rect>(AutoFightAssets.Instance.AvatarIndexRectListMap[$"{p}_{num}"]);
|
||||
|
||||
ExpectedTeamAvatarNum = avatarSideIconRectList.Count;
|
||||
}
|
||||
else
|
||||
{
|
||||
avatarSideIconRectList = AutoFightAssets.Instance.AvatarSideIconRectList;
|
||||
avatarIndexRectList = AutoFightAssets.Instance.AvatarIndexRectList;
|
||||
avatarSideIconRectList = new List<Rect>(AutoFightAssets.Instance.AvatarSideIconRectList);
|
||||
avatarIndexRectList = new List<Rect>(AutoFightAssets.Instance.AvatarIndexRectList);
|
||||
}
|
||||
|
||||
// 6.0 版本 队伍下的 草露 进度条 导致位置偏移
|
||||
@@ -158,7 +158,7 @@ public class CombatScenes : IDisposable
|
||||
{
|
||||
// 角色序号 左上角 坐标偏移(+2, -5)后存在3个白色点,则认为存在 草露 进度条
|
||||
// 存在 草露 进度条时候整体上移 14 个像素
|
||||
int whitePointCount = 0;
|
||||
var whitePointCount = 0;
|
||||
foreach (var rectIndex in avatarIndexRectList)
|
||||
{
|
||||
int x = rectIndex.X + 2;
|
||||
@@ -170,47 +170,28 @@ public class CombatScenes : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
if (whitePointCount >= 3)
|
||||
if (whitePointCount < 3)
|
||||
{
|
||||
Logger.LogInformation("检测到右侧队伍上偏移,进行位置偏移");
|
||||
|
||||
for (int i = 0; i < avatarSideIconRectList.Count; i++)
|
||||
{
|
||||
var rect = avatarSideIconRectList[i];
|
||||
rect.Y -= 14;
|
||||
avatarSideIconRectList[i] = rect;
|
||||
}
|
||||
|
||||
for (int i = 0; i < avatarIndexRectList.Count; i++)
|
||||
{
|
||||
var rect = avatarIndexRectList[i];
|
||||
rect.Y -= 14;
|
||||
avatarIndexRectList[i] = rect;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (whitePointCount <= 1) //发现有时候识别到一个白点
|
||||
{
|
||||
Logger.LogInformation("检测到右侧队伍下偏移,进行位置偏移");
|
||||
for (int i = 0; i < avatarSideIconRectList.Count; i++)
|
||||
{
|
||||
var rect = avatarSideIconRectList[i];
|
||||
rect.Y += 14;
|
||||
avatarSideIconRectList[i] = rect;
|
||||
}
|
||||
|
||||
for (int i = 0; i < avatarIndexRectList.Count; i++)
|
||||
{
|
||||
var rect = avatarIndexRectList[i];
|
||||
rect.Y += 14;
|
||||
avatarIndexRectList[i] = rect;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Logger.LogInformation("检测到右侧队伍上偏移,进行位置偏移");
|
||||
|
||||
for (var i = 0; i < avatarSideIconRectList.Count; i++)
|
||||
{
|
||||
var rect = avatarSideIconRectList[i];
|
||||
rect.Y -= 14;
|
||||
avatarSideIconRectList[i] = rect;
|
||||
}
|
||||
|
||||
for (var i = 0; i < avatarIndexRectList.Count; i++)
|
||||
{
|
||||
var rect = avatarIndexRectList[i];
|
||||
rect.Y -= 14;
|
||||
avatarIndexRectList[i] = rect;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1101,7 +1101,7 @@ public class PathExecutor
|
||||
return null;
|
||||
}
|
||||
|
||||
var success = avatar.TrySwitch();
|
||||
var success = avatar.TrySwitch(5);//多切换一次,否则如果切人纠正要等下一个循环
|
||||
if (success)
|
||||
{
|
||||
await Delay(100, ct);
|
||||
|
||||
@@ -246,7 +246,7 @@ public partial class AutoPickTrigger : ITaskTrigger
|
||||
else
|
||||
{
|
||||
var textMat = new Mat(content.CaptureRectArea.SrcMat, textRect);
|
||||
var boundingRect = TextRectExtractor.GetTextBoundingRect(textMat, out var bin);
|
||||
var boundingRect = TextRectExtractor.GetTextBoundingRect(textMat);
|
||||
// 如果找到有效区域
|
||||
if (boundingRect.X <20 && boundingRect.Width > 5 && boundingRect.Height > 5)
|
||||
{
|
||||
@@ -283,22 +283,8 @@ public partial class AutoPickTrigger : ITaskTrigger
|
||||
{
|
||||
// 处理OCR识别结果,清理无效字符并确保引号配对
|
||||
text = ProcessOcrText(text);
|
||||
|
||||
// 唯一一个动态拾取项,特殊处理,不拾取
|
||||
if (text.Contains("长时间"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 纳塔部落中文名特殊处理,不拾取
|
||||
if (text.Contains("我在") && (text.Contains("声望") || text.Contains("回声") || text.Contains("悬木人") ||
|
||||
text.Contains("流泉")))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// 挪德卡莱聚所中文名特殊处理,不拾取
|
||||
if (text.Contains("聚所") && (text.Contains("霜月") || text.Contains("叮铃") ||
|
||||
text.Contains("眶螂") || text.Contains("蛋卷") || text.Contains("坊")))
|
||||
if (DoNotPick(text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -336,6 +322,41 @@ public partial class AutoPickTrigger : ITaskTrigger
|
||||
}
|
||||
|
||||
speedTimer.DebugPrint();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private bool DoNotPick(string text)
|
||||
{
|
||||
// 唯一一个动态拾取项,特殊处理,不拾取
|
||||
if (text.Contains("长时间"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 纳塔部落中文名特殊处理,不拾取
|
||||
if (text.Contains("我在") && (text.Contains("声望") || text.Contains("回声") || text.Contains("悬木人") ||
|
||||
text.Contains("流泉")))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// 挪德卡莱聚所中文名特殊处理,不拾取
|
||||
if (text.Contains("聚所"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (text.Contains("霜月") && text.Contains("坊"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (text.Contains("叮铃") || text.Contains("眶螂") || (text.Contains("蛋卷") && text.Contains("坊")))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Rect GetWhiteTextBoundingRect(Mat textMat)
|
||||
|
||||
@@ -11,12 +11,17 @@ public static class TextRectExtractor
|
||||
/// 从图片中提取文字范围(假定文字从最左边贴边开始,向右连续)
|
||||
/// 结果矩形固定 x=0,y=0,h=原图高度,只计算连续文字宽度。
|
||||
/// </summary>
|
||||
public static Rect GetTextBoundingRect(Mat textMat, out Mat bin)
|
||||
/// <param name="textMat">文字图片</param>
|
||||
/// <param name="min">二值化阈值</param>
|
||||
/// <param name="max">二值化阈值</param>
|
||||
/// <returns></returns>
|
||||
public static Rect GetTextBoundingRect(Mat textMat, double min = 160, double max = 255)
|
||||
{
|
||||
// 转换为灰度图
|
||||
Mat gray = new Mat();
|
||||
Mat gray;
|
||||
if (textMat.Channels() == 3)
|
||||
{
|
||||
gray = new Mat();
|
||||
Cv2.CvtColor(textMat, gray, ColorConversionCodes.BGR2GRAY);
|
||||
}
|
||||
else
|
||||
@@ -25,8 +30,8 @@ public static class TextRectExtractor
|
||||
}
|
||||
|
||||
// 使用阈值160进行二值化处理
|
||||
bin = new Mat();
|
||||
Cv2.Threshold(gray, bin, 160, 255, ThresholdTypes.Binary);
|
||||
using var bin = new Mat();
|
||||
Cv2.Threshold(gray, bin, min, max, ThresholdTypes.Binary);
|
||||
|
||||
// 形态学操作:先腐蚀后膨胀,去除噪点并保持文字完整
|
||||
Mat kernel = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(3, 3));
|
||||
@@ -37,7 +42,46 @@ public static class TextRectExtractor
|
||||
return ProjectionRect(textMat, bin);
|
||||
}
|
||||
|
||||
private static Rect ProjectionRect(Mat textMat, Mat bin)
|
||||
public static Rect GetNumberBoundingRect(Mat textMat, double min = 180, double max = 255)
|
||||
{
|
||||
// 转换为灰度图
|
||||
Mat gray;
|
||||
if (textMat.Channels() == 3)
|
||||
{
|
||||
gray = new Mat();
|
||||
Cv2.CvtColor(textMat, gray, ColorConversionCodes.BGR2GRAY);
|
||||
}
|
||||
else
|
||||
{
|
||||
gray = textMat.Clone();
|
||||
}
|
||||
|
||||
// 使用阈值160进行二值化处理
|
||||
using var bin = new Mat();
|
||||
Cv2.Threshold(gray, bin, min, max, ThresholdTypes.Binary);
|
||||
|
||||
// 形态学操作:直接膨胀
|
||||
Cv2.Dilate(bin, bin, new Mat(), iterations: 2);
|
||||
gray.Dispose();
|
||||
var rect = ProjectionRect(textMat, bin);
|
||||
// 数字后面加点宽度
|
||||
if (rect != new Rect())
|
||||
{
|
||||
var newWidth = rect.Width + 10;
|
||||
rect.Width = newWidth > textMat.Width ? textMat.Width : newWidth;
|
||||
}
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 投影, 获取连续文字的边界矩形
|
||||
/// </summary>
|
||||
/// <param name="textMat"></param>
|
||||
/// <param name="bin"></param>
|
||||
/// <param name="maxGap">允许的最大连续空列数</param>
|
||||
/// <returns></returns>
|
||||
public static Rect ProjectionRect(Mat textMat, Mat bin, int maxGap = 30)
|
||||
{
|
||||
// 投影:对行做 ReduceSum,得到 1 x width 的列和
|
||||
using var projection = new Mat();
|
||||
@@ -45,7 +89,6 @@ public static class TextRectExtractor
|
||||
int width = projection.Cols;
|
||||
projection.GetArray(out int[] colSums);
|
||||
|
||||
int maxGap = 30; // 允许的最大连续空列数
|
||||
int gapCount = 0;
|
||||
int lastNonEmpty = -1;
|
||||
|
||||
@@ -66,7 +109,7 @@ public static class TextRectExtractor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (lastNonEmpty == -1)
|
||||
{
|
||||
// 没有检测到文字
|
||||
@@ -76,4 +119,4 @@ public static class TextRectExtractor
|
||||
Rect boundingRect = new Rect(0, 0, lastNonEmpty, textMat.Height);
|
||||
return boundingRect;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
using static Vanara.PInvoke.User32;
|
||||
using BetterGenshinImpact.GameTask.AutoFight;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoStygianOnslaught;
|
||||
|
||||
@@ -67,7 +68,18 @@ public class AutoStygianOnslaughtTask : ISoloTask
|
||||
Init();
|
||||
Notify.Event(NotificationEvent.DomainStart).Success($"{Name}启动");
|
||||
|
||||
await DoDomain();
|
||||
try
|
||||
{
|
||||
await DoDomain();
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogInformation(e.Message);
|
||||
}
|
||||
|
||||
await Delay(3000, ct);
|
||||
|
||||
@@ -223,7 +235,7 @@ public class AutoStygianOnslaughtTask : ISoloTask
|
||||
await Delay(800, _ct);
|
||||
|
||||
// 等待传送完成
|
||||
await page.Locator(ElementAssets.Instance.PaimonMenuRo).WaitFor();
|
||||
await page.Locator(ElementAssets.Instance.PaimonMenuRo).WaitFor(60000);
|
||||
_logger.LogInformation($"{Name}:传送完成");
|
||||
|
||||
await Delay(2000, _ct);
|
||||
@@ -307,6 +319,7 @@ public class AutoStygianOnslaughtTask : ISoloTask
|
||||
{
|
||||
try
|
||||
{
|
||||
AutoFightTask.FightStatusFlag = true;
|
||||
while (!cts.Token.IsCancellationRequested)
|
||||
{
|
||||
// 通用化战斗策略
|
||||
@@ -330,6 +343,7 @@ public class AutoStygianOnslaughtTask : ISoloTask
|
||||
_logger.LogInformation("自动战斗线程结束");
|
||||
Simulation.ReleaseAllKey();
|
||||
Simulation.SendInput.Mouse.LeftButtonUp();
|
||||
AutoFightTask.FightStatusFlag = false;
|
||||
}
|
||||
}, cts.Token);
|
||||
|
||||
@@ -535,11 +549,7 @@ public class AutoStygianOnslaughtTask : ISoloTask
|
||||
|
||||
private async Task ExitDomain()
|
||||
{
|
||||
Simulation.SendInput.Keyboard.KeyPress(VK.VK_ESCAPE);
|
||||
await Delay(500, _ct);
|
||||
Simulation.SendInput.Keyboard.KeyPress(VK.VK_ESCAPE);
|
||||
await Delay(800, _ct);
|
||||
Bv.ClickBlackConfirmButton(CaptureToRectArea());
|
||||
await ExitDomain(new BvPage(_ct));
|
||||
}
|
||||
|
||||
private bool PressUseResin(ImageRegion ra, string resinName)
|
||||
@@ -624,7 +634,7 @@ public class AutoStygianOnslaughtTask : ISoloTask
|
||||
await page.Locator(ElementAssets.Instance.BtnExitDoor.Value).Click();
|
||||
|
||||
// 等待传送完成
|
||||
await page.Locator(ElementAssets.Instance.PaimonMenuRo).WaitFor();
|
||||
await page.Locator(ElementAssets.Instance.PaimonMenuRo).WaitFor(60000);
|
||||
|
||||
await Delay(3000, _ct);
|
||||
}
|
||||
|
||||
@@ -878,7 +878,11 @@ public class TpTask
|
||||
var list = ra.FindMulti(new RecognitionObject
|
||||
{
|
||||
RecognitionType = RecognitionTypes.Ocr,
|
||||
RegionOfInterest = new Rect(ra.Width / 2, 0, ra.Width / 2, ra.Height)
|
||||
RegionOfInterest = new Rect(ra.Width / 2, 0, ra.Width / 2, ra.Height),
|
||||
ReplaceDictionary = new Dictionary<string, string[]>
|
||||
{
|
||||
["渊下宫"] = ["渊下宮"],
|
||||
},
|
||||
});
|
||||
string minCountryLocalized = this.stringLocalizer.WithCultureGet(this.cultureInfo, areaName);
|
||||
Region? matchRect = list.OrderByDescending(r => r.Y).FirstOrDefault(r => r.Text.Contains(minCountryLocalized));
|
||||
|
||||
@@ -3,6 +3,7 @@ using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.GameTask.Model.Area;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
|
||||
@@ -15,13 +16,12 @@ public class BlessingOfTheWelkinMoonTask
|
||||
{
|
||||
public string Name => "自动点击空月祝福";
|
||||
|
||||
|
||||
public async Task Start(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 4点全程触发
|
||||
if (DateTime.Now.Hour == 4)
|
||||
if (ServerTimeHelper.GetServerTimeNow().Hour == 4)
|
||||
{
|
||||
using var ra = CaptureToRectArea();
|
||||
if (Bv.IsInBlessingOfTheWelkinMoon(ra))
|
||||
|
||||
@@ -476,8 +476,8 @@ internal class GoToSereniteaPotTask
|
||||
Logger.LogInformation("领取尘歌壶奖励:{text}", "未配置购买商店物品");
|
||||
return;
|
||||
}
|
||||
DateTime now = DateTime.Now;
|
||||
DayOfWeek currentDayOfWeek = now.Hour >= 4 ? now.DayOfWeek : now.AddDays(-1).DayOfWeek;
|
||||
DateTimeOffset serverTime = ServerTimeHelper.GetServerTimeNow();
|
||||
DayOfWeek currentDayOfWeek = serverTime.Hour >= 4 ? serverTime.DayOfWeek : serverTime.AddDays(-1).DayOfWeek;
|
||||
DayOfWeek? configDayOfWeek = GetDayOfWeekFromConfig(SelectedConfig.SecretTreasureObjects.First());
|
||||
if (configDayOfWeek.HasValue || SelectedConfig.SecretTreasureObjects.First() == "每天重复" && SelectedConfig.SecretTreasureObjects.Count > 1)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.GameTask.AutoPathing.Model;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.GameTask.LogParse;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
@@ -212,8 +213,8 @@ public static class FarmingStatsRecorder
|
||||
public static DailyFarmingData ReadDailyFarmingData()
|
||||
{
|
||||
// 确定统计日期(以凌晨4点为分界)
|
||||
DateTime now = DateTime.Now;
|
||||
DateTime statsDate = CalculateStatsDate(now);
|
||||
DateTimeOffset now = ServerTimeHelper.GetServerTimeNow();
|
||||
DateTimeOffset statsDate = CalculateStatsDate(now);
|
||||
string dateString = statsDate.ToString("yyyyMMdd");
|
||||
|
||||
// 确保目录存在
|
||||
@@ -228,7 +229,7 @@ public static class FarmingStatsRecorder
|
||||
/// <summary>
|
||||
/// 计算统计日期(凌晨4点为分界)
|
||||
/// </summary>
|
||||
private static DateTime CalculateStatsDate(DateTime currentTime)
|
||||
private static DateTime CalculateStatsDate(DateTimeOffset currentTime)
|
||||
{
|
||||
// 如果当前时间在4点之前,则算作前一天
|
||||
return currentTime.Hour < 4 ? currentTime.Date.AddDays(-1) : currentTime.Date;
|
||||
|
||||
@@ -345,6 +345,7 @@ public class GameLoadingTrigger : ITaskTrigger
|
||||
var wmRa = content.CaptureRectArea.Find(_assets.WelkinMoonRo);
|
||||
if (!wmRa.IsEmpty())
|
||||
{
|
||||
GameCaptureRegion.GameRegion1080PPosMove(100, 100);
|
||||
TaskContext.Instance().PostMessageSimulator.LeftButtonClickBackground();
|
||||
Debug.WriteLine("[GameLoading] Click blessing of the welkin moon");
|
||||
// TaskControl.Logger.LogInformation("自动点击月卡");
|
||||
@@ -355,7 +356,7 @@ public class GameLoadingTrigger : ITaskTrigger
|
||||
var ysRa = content.CaptureRectArea.Find(ElementAssets.Instance.PrimogemRo);
|
||||
if (!ysRa.IsEmpty())
|
||||
{
|
||||
GameCaptureRegion.GameRegion1080PPosMove(10, 10);
|
||||
GameCaptureRegion.GameRegion1080PPosMove(100, 100);
|
||||
TaskContext.Instance().PostMessageSimulator.LeftButtonClickBackground();
|
||||
Debug.WriteLine("[GameLoading] 跳过原石");
|
||||
return;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.LogParse;
|
||||
@@ -12,13 +13,25 @@ public class ExecutionRecord
|
||||
[JsonProperty("type")] public string Type = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 执行开始时间
|
||||
/// 执行开始时间(服务器时间,包含时区信息)
|
||||
/// </summary>
|
||||
[JsonProperty("server_start_time")]
|
||||
public DateTimeOffset? ServerStartTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 执行开始时间的本地时间表示(用于向后兼容的统计显示)
|
||||
/// </summary>
|
||||
[JsonProperty("start_time")]
|
||||
public DateTime StartTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 执行结束时间
|
||||
/// 执行结束时间(服务器时间,包含时区信息)
|
||||
/// </summary>
|
||||
[JsonProperty("server_end_time")]
|
||||
public DateTimeOffset? ServerEndTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 执行结束时间的本地时间表示(用于向后兼容的统计显示)
|
||||
/// </summary>
|
||||
[JsonProperty("end_time")]
|
||||
public DateTime EndTime { get; set; }
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.Core.Script.Group;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.LogParse;
|
||||
@@ -140,16 +141,19 @@ public class ExecutionRecordStorage
|
||||
/// <summary>
|
||||
/// 根据自定义的一天开始时间判断日期是否属于"今天"
|
||||
/// </summary>
|
||||
/// <param name="boundaryHour">分界时间(小时),0-23之间</param>
|
||||
/// <param name="targetDate">要判断的日期</param>
|
||||
/// <returns>如果属于"今天"则返回true,否则返回false</returns>
|
||||
private static bool IsTodayByBoundary(int boundaryHour, DateTime targetDate)
|
||||
/// <param name="boundaryHour">分界时间(小时),0-23之间,基于<paramref name="isBoundaryTimeBasedOnServerTime"/>参数决定的时间参考系</param>
|
||||
/// <param name="targetDate">要判断的日期(本地时间)</param>
|
||||
/// <param name="isBoundaryTimeBasedOnServerTime">true表示使用服务器时间计算,false表示使用本地时间计算</param>
|
||||
/// <returns>如果目标日期在根据分界时间定义的"今天"范围内则返回true,否则返回false</returns>
|
||||
private static bool IsTodayByBoundary(int boundaryHour, DateTimeOffset targetDate, bool isBoundaryTimeBasedOnServerTime)
|
||||
{
|
||||
// 验证分界时间是否有效
|
||||
if (boundaryHour < 0 || boundaryHour > 23)
|
||||
throw new ArgumentOutOfRangeException(nameof(boundaryHour), "分界时间必须在0-23之间");
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
DateTimeOffset now = isBoundaryTimeBasedOnServerTime
|
||||
? ServerTimeHelper.GetServerTimeNow()
|
||||
: DateTimeOffset.Now;
|
||||
|
||||
// 计算今天的开始时间(根据分界时间)
|
||||
DateTime todayStart;
|
||||
@@ -237,7 +241,10 @@ public class ExecutionRecordStorage
|
||||
if (boundaryTimeEnable)
|
||||
{
|
||||
// 如果记录不在"今天",则跳过
|
||||
if (!IsTodayByBoundary(config.BoundaryTime, record.StartTime)) continue;
|
||||
if (!IsTodayByBoundary(config.BoundaryTime,
|
||||
record.ServerStartTime ??
|
||||
new DateTimeOffset(record.StartTime).ToOffset(ServerTimeHelper.GetServerTimeOffset()),
|
||||
config.IsBoundaryTimeBasedOnServerTime)) continue;
|
||||
}
|
||||
|
||||
bool isMatchFound = false;
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Wpf.Ui.Violeta.Controls;
|
||||
|
||||
@@ -67,14 +68,14 @@ public class TravelsDiaryDetailManager
|
||||
}
|
||||
private static List<(int year, int month)> GetMonthPairs()
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
DateTimeOffset now = ServerTimeHelper.GetServerTimeNow();
|
||||
|
||||
List<(int year, int month)> result = new List<(int, int)>();
|
||||
|
||||
if (now.Day == 1 && now.Hour < 4)
|
||||
{
|
||||
// 上个月
|
||||
DateTime lastMonth = now.AddMonths(-1);
|
||||
DateTimeOffset lastMonth = now.AddMonths(-1);
|
||||
result.Add((lastMonth.Year, lastMonth.Month));
|
||||
}
|
||||
|
||||
@@ -90,10 +91,10 @@ public class TravelsDiaryDetailManager
|
||||
{
|
||||
//正序的
|
||||
var sortedList = loadAllActionItems(gameInfo, GetMonthPairs());
|
||||
DateTime now = DateTime.Now;
|
||||
DateTime today4am = now.Date.AddHours(4);
|
||||
DateTimeOffset now = ServerTimeHelper.GetServerTimeNow();
|
||||
DateTimeOffset today4am = new DateTimeOffset(now.Year, now.Month, now.Day, 4, 0, 0, now.Offset);
|
||||
|
||||
DateTime startTime, endTime;
|
||||
DateTimeOffset startTime, endTime;
|
||||
|
||||
if (now < today4am)
|
||||
{
|
||||
@@ -231,11 +232,14 @@ public class TravelsDiaryDetailManager
|
||||
throw new FileNotFoundException("文件未找到", filePath);
|
||||
}
|
||||
|
||||
DateTime lastModified = File.GetLastWriteTime(filePath);
|
||||
|
||||
// File.GetLastWriteTime 返回 DateTime 类型为 DateTimeKind.Local
|
||||
DateTimeOffset lastModified =
|
||||
new DateTimeOffset(File.GetLastWriteTime(filePath)).ToOffset(ServerTimeHelper.GetServerTimeOffset());
|
||||
|
||||
// 获取当前月份的开始和结束日期
|
||||
DateTime startOfMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
|
||||
DateTime endOfMonth = startOfMonth.AddMonths(1).AddDays(-1);
|
||||
DateTimeOffset now = ServerTimeHelper.GetServerTimeNow();
|
||||
DateTimeOffset startOfMonth = new DateTimeOffset(now.Year, now.Month, 1, 0, 0, 0, now.Offset);
|
||||
DateTimeOffset endOfMonth = startOfMonth.AddMonths(1).AddDays(-1);
|
||||
|
||||
// 判断文件最后修改时间是否在本月
|
||||
return lastModified >= startOfMonth && lastModified <= endOfMonth;
|
||||
@@ -244,7 +248,7 @@ public class TravelsDiaryDetailManager
|
||||
static List<(int year, int month)> GetCurrentAndPreviousTwoMonths()
|
||||
{
|
||||
List<(int year, int month)> months = new List<(int year, int month)>();
|
||||
DateTime now = DateTime.Now;
|
||||
DateTimeOffset now = ServerTimeHelper.GetServerTimeNow();
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
|
||||
@@ -193,7 +193,7 @@ public class ImageRegion : Region
|
||||
{
|
||||
foreach (var replaceStr in entry.Value)
|
||||
{
|
||||
text = text.Replace(entry.Key, replaceStr);
|
||||
text = text.Replace(replaceStr, entry.Key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -305,7 +305,7 @@
|
||||
// {
|
||||
// foreach (var replaceStr in entry.Value)
|
||||
// {
|
||||
// text = text.Replace(entry.Key, replaceStr);
|
||||
// text = text.Replace(replaceStr, entry.Key);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
|
||||
@@ -16,8 +16,9 @@ public class QuickBuyAssets : BaseAssets<QuickBuyAssets>
|
||||
Name = "SereniteaPotCoin",
|
||||
RecognitionType = RecognitionTypes.TemplateMatch,
|
||||
TemplateImageMat = GameTaskManager.LoadAssetImage("QuickBuy", "SereniteaPotCoin.png"),
|
||||
RegionOfInterest = new Rect((int)(1620 * AssetScale),(int)(30 * AssetScale),(int)(50 * AssetScale),(int)(40 * AssetScale)),
|
||||
DrawOnWindow = false
|
||||
RegionOfInterest = new Rect((int)(1610 * AssetScale),(int)(28 * AssetScale),(int)(160 * AssetScale),(int)(45 * AssetScale)),
|
||||
Use3Channels = true,
|
||||
DrawOnWindow = true
|
||||
}.InitTemplate();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using BetterGenshinImpact.Core.Simulator;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.GameTask.Model.Area;
|
||||
using BetterGenshinImpact.GameTask.QuickBuy.Assets;
|
||||
using BetterGenshinImpact.View.Drawable;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Wpf.Ui.Violeta.Controls;
|
||||
|
||||
@@ -52,6 +53,7 @@ public class QuickBuyTask
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 点击购买/兑换 右下225x60
|
||||
GameCaptureRegion.GameRegionClick((size, scale) => (size.Width - 225 * scale, size.Height - 60 * scale));
|
||||
TaskControl.CheckAndSleep(100); // 等待窗口弹出
|
||||
@@ -78,5 +80,9 @@ public class QuickBuyTask
|
||||
{
|
||||
TaskControl.Logger.LogWarning(e.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
VisionContext.Instance().DrawContent.ClearAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
|
||||
namespace BetterGenshinImpact.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// 提供配置的服务器时区的当前时间
|
||||
/// </summary>
|
||||
public interface IServerTimeProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取调整到服务器时区偏移量的当前时间
|
||||
/// </summary>
|
||||
/// <returns>表示当前服务器时间的 <see cref="DateTimeOffset"/></returns>
|
||||
DateTimeOffset GetServerTimeNow();
|
||||
|
||||
/// <summary>
|
||||
/// 获取服务器时区偏移量
|
||||
/// </summary>
|
||||
/// <returns>表示服务器时区偏移量的 <see cref="TimeSpan"/></returns>
|
||||
TimeSpan GetServerTimeOffset();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IServerTimeProvider"/>
|
||||
/// <remarks>
|
||||
/// 此实现使用 <see cref="TimeProvider"/> 获取当前UTC时间,
|
||||
/// 然后应用配置的服务器时区偏移量
|
||||
/// </remarks>
|
||||
public class ServerTimeProvider : IServerTimeProvider
|
||||
{
|
||||
private readonly TimeProvider _timeProvider;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化 <see cref="ServerTimeProvider"/> 类的新实例
|
||||
/// </summary>
|
||||
/// <param name="timeProvider">用于获取基准UTC时间的 <see cref="TimeProvider"/></param>
|
||||
public ServerTimeProvider(TimeProvider timeProvider)
|
||||
{
|
||||
_timeProvider = timeProvider;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTimeOffset GetServerTimeNow()
|
||||
{
|
||||
var serverOffset = GetServerTimeOffset();
|
||||
return _timeProvider.GetUtcNow().ToOffset(serverOffset);
|
||||
}
|
||||
|
||||
public TimeSpan GetServerTimeOffset()
|
||||
{
|
||||
try
|
||||
{
|
||||
return TaskContext.Instance().Config.OtherConfig.ServerTimeZoneOffset;
|
||||
}
|
||||
// throw new Exception("Config未初始化"); in TaskContext.cs
|
||||
catch (Exception)
|
||||
{
|
||||
// 如果配置未加载,假定为北京时间用于核心开发者测试
|
||||
return TimeSpan.FromHours(8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提供静态外观以便轻松访问服务器时间
|
||||
/// </summary>
|
||||
public static class ServerTimeHelper
|
||||
{
|
||||
private static IServerTimeProvider? _serverTimeProvider;
|
||||
|
||||
/// <summary>
|
||||
/// 使用具体的 <see cref="IServerTimeProvider"/> 实现初始化静态辅助类
|
||||
/// 此方法必须在应用程序启动期间调用一次
|
||||
/// </summary>
|
||||
/// <param name="serverTimeProvider">用于检索服务器时间的提供程序</param>
|
||||
/// <exception cref="ArgumentNullException">当 <paramref name="serverTimeProvider"/> 为 null 时抛出</exception>
|
||||
public static void Initialize(IServerTimeProvider serverTimeProvider)
|
||||
{
|
||||
_serverTimeProvider = serverTimeProvider ?? throw new ArgumentNullException(nameof(serverTimeProvider));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取调整到服务器时区偏移量的当前时间
|
||||
/// </summary>
|
||||
/// <returns>表示当前服务器时间的 <see cref="DateTimeOffset"/></returns>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// 如果尚未调用 <see cref="Initialize"/> 则抛出
|
||||
/// </exception>
|
||||
public static DateTimeOffset GetServerTimeNow()
|
||||
{
|
||||
if (_serverTimeProvider is null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"{nameof(ServerTimeHelper)} 尚未初始化。请先调用 {nameof(Initialize)}。");
|
||||
}
|
||||
|
||||
return _serverTimeProvider.GetServerTimeNow();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取服务器时区偏移量
|
||||
/// </summary>
|
||||
/// <returns>表示服务器时区偏移量的 <see cref="TimeSpan"/></returns>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// 如果尚未调用 <see cref="Initialize"/> 则抛出
|
||||
/// </exception>
|
||||
public static TimeSpan GetServerTimeOffset()
|
||||
{
|
||||
if (_serverTimeProvider is null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"{nameof(ServerTimeHelper)} 尚未初始化。请先调用 {nameof(Initialize)}。");
|
||||
}
|
||||
|
||||
return _serverTimeProvider.GetServerTimeOffset();
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,6 @@ public static class MirrorChyanHelper
|
||||
|
||||
private static void OpenMirrorChyanWebsite()
|
||||
{
|
||||
Launcher.LaunchUriAsync(new Uri($"https://mirrorchyan.com/zh/get-start?source=bgi-{Global.Version}"));
|
||||
Launcher.LaunchUriAsync(new Uri($"https://mirrorchyan.com/zh/get-start?source=bgi-desktop-{Global.Version}"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.Service.Interface;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BetterGenshinImpact.Service;
|
||||
|
||||
/// <summary>
|
||||
/// HTTP 服务器服务
|
||||
/// </summary>
|
||||
public class HttpServerService : IHostedService, IDisposable
|
||||
{
|
||||
private readonly ILogger<HttpServerService> _logger;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private WebApplication? _webApp;
|
||||
private readonly HttpServerConfig _config;
|
||||
private CancellationTokenSource? _cancellationTokenSource;
|
||||
|
||||
public HttpServerService(
|
||||
ILogger<HttpServerService> logger,
|
||||
IConfigService configService,
|
||||
IServiceProvider serviceProvider)
|
||||
{
|
||||
_logger = logger;
|
||||
_serviceProvider = serviceProvider;
|
||||
_config = configService.Get().HttpServerConfig;
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (!_config.Enabled)
|
||||
{
|
||||
_logger.LogInformation("HTTP 服务器未启用");
|
||||
return;
|
||||
}
|
||||
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
await StartWebServer();
|
||||
}
|
||||
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (_webApp != null)
|
||||
{
|
||||
await _webApp.StopAsync(cancellationToken);
|
||||
await _webApp.DisposeAsync();
|
||||
_webApp = null;
|
||||
}
|
||||
|
||||
_cancellationTokenSource?.Cancel();
|
||||
_cancellationTokenSource?.Dispose();
|
||||
_logger.LogInformation("HTTP 服务器已停止");
|
||||
}
|
||||
|
||||
private async Task StartWebServer()
|
||||
{
|
||||
try
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder();
|
||||
|
||||
// 配置 Kestrel 服务器
|
||||
builder.WebHost.ConfigureKestrel(options =>
|
||||
{
|
||||
options.ListenAnyIP(_config!.Port);
|
||||
});
|
||||
|
||||
// 添加服务
|
||||
builder.Services.AddCors();
|
||||
|
||||
if (_config!.EnableWebSocket)
|
||||
{
|
||||
builder.Services.AddSignalR();
|
||||
}
|
||||
|
||||
// if (_config.EnableSwagger)
|
||||
// {
|
||||
// builder.Services.AddEndpointsApiExplorer();
|
||||
// // builder.Services.AddSwaggerGen();
|
||||
// }
|
||||
|
||||
// 添加现有服务的引用
|
||||
builder.Services.AddSingleton(_serviceProvider.GetService<IConfigService>()!);
|
||||
|
||||
_webApp = builder.Build();
|
||||
|
||||
// 配置中间件
|
||||
if (_config.EnableCors)
|
||||
{
|
||||
_webApp.UseCors(policy =>
|
||||
{
|
||||
policy.AllowAnyOrigin()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader();
|
||||
});
|
||||
}
|
||||
|
||||
// if (_config.EnableSwagger)
|
||||
// {
|
||||
// // _webApp.UseSwagger();
|
||||
// // _webApp.UseSwaggerUI();
|
||||
// }
|
||||
|
||||
// 配置路由
|
||||
ConfigureRoutes(_webApp);
|
||||
|
||||
if (_config.EnableWebSocket)
|
||||
{
|
||||
_webApp.MapHub<BgiHub>("/bgi-hub");
|
||||
}
|
||||
|
||||
// 启动服务器
|
||||
await _webApp.StartAsync(_cancellationTokenSource!.Token);
|
||||
|
||||
var url = $"http://{_config.Host}:{_config.Port}";
|
||||
_logger.LogInformation("HTTP 服务器已启动: {Url}", url);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "启动 HTTP 服务器失败");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void ConfigureRoutes(WebApplication app)
|
||||
{
|
||||
// 健康检查
|
||||
app.MapGet("/health", () => new { status = "healthy", timestamp = DateTime.UtcNow })
|
||||
.WithTags("System")
|
||||
.WithSummary("健康检查");
|
||||
|
||||
// 获取应用状态
|
||||
app.MapGet("/api/status", () =>
|
||||
{
|
||||
})
|
||||
.WithTags("Application")
|
||||
.WithSummary("获取应用状态");
|
||||
|
||||
// 获取配置
|
||||
app.MapGet("/api/config", (IConfigService configService) =>
|
||||
{
|
||||
var config = configService.Get();
|
||||
return Results.Json(config, ConfigService.JsonOptions);
|
||||
})
|
||||
.WithTags("Configuration")
|
||||
.WithSummary("获取应用配置");
|
||||
|
||||
// 更新配置(仅部分配置)
|
||||
app.MapPost("/api/config", async (HttpContext context, IConfigService configService) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var jsonDoc = await JsonDocument.ParseAsync(context.Request.Body);
|
||||
var config = configService.Get();
|
||||
configService.Save();
|
||||
return Results.Ok(new { message = "配置更新成功" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Results.BadRequest(new { error = ex.Message });
|
||||
}
|
||||
})
|
||||
.WithTags("Configuration")
|
||||
.WithSummary("更新应用配置");
|
||||
|
||||
// 启动/停止任务
|
||||
app.MapPost("/api/tasks/{action}", (string action) =>
|
||||
{
|
||||
|
||||
})
|
||||
.WithTags("Tasks")
|
||||
.WithSummary("启动或停止任务");
|
||||
|
||||
// 获取任务列表(脚本)
|
||||
app.MapGet("/api/scripts", () =>
|
||||
{
|
||||
// 这里可以返回可用的脚本列表
|
||||
// 具体实现根据你的脚本管理逻辑
|
||||
return Results.Ok(new { scripts = new List<object>() });
|
||||
})
|
||||
.WithTags("Scripts")
|
||||
.WithSummary("获取可用脚本列表");
|
||||
|
||||
// // 静态文件服务(可选)
|
||||
// app.MapGet("/", () => Results.Redirect("/swagger"));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_webApp?.DisposeAsync().AsTask().Wait();
|
||||
_cancellationTokenSource?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SignalR Hub,用于 WebSocket 通信
|
||||
/// </summary>
|
||||
public class BgiHub : Hub
|
||||
{
|
||||
private readonly ILogger<BgiHub> _logger;
|
||||
|
||||
public BgiHub(ILogger<BgiHub> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override async Task OnConnectedAsync()
|
||||
{
|
||||
_logger.LogInformation("WebSocket 客户端已连接: {ConnectionId}", Context.ConnectionId);
|
||||
await Groups.AddToGroupAsync(Context.ConnectionId, "BgiClients");
|
||||
await base.OnConnectedAsync();
|
||||
}
|
||||
|
||||
public override async Task OnDisconnectedAsync(Exception? exception)
|
||||
{
|
||||
_logger.LogInformation("WebSocket 客户端已断开: {ConnectionId}", Context.ConnectionId);
|
||||
await Groups.RemoveFromGroupAsync(Context.ConnectionId, "BgiClients");
|
||||
await base.OnDisconnectedAsync(exception);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向所有连接的客户端发送消息
|
||||
/// </summary>
|
||||
public async Task BroadcastMessage(string message, object? data = null)
|
||||
{
|
||||
await Clients.Group("BgiClients").SendAsync("ReceiveMessage", new
|
||||
{
|
||||
message,
|
||||
data,
|
||||
timestamp = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -276,4 +276,14 @@ public partial class NotificationConfig : ObservableObject
|
||||
/// Discord Webhook 图像编码
|
||||
/// </summary>
|
||||
[ObservableProperty] private string _discordWebhookImageEncoder = "Jpeg";
|
||||
|
||||
/// <summary>
|
||||
/// ServerChan通知是否启用
|
||||
/// </summary>
|
||||
[ObservableProperty] private bool _serverChanNotificationEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// ServerChan SendKey
|
||||
/// </summary>
|
||||
[ObservableProperty] private string _serverChanSendKey = string.Empty;
|
||||
}
|
||||
@@ -107,6 +107,7 @@ public class NotificationService : IHostedService, IDisposable
|
||||
InitializeTelegramNotifier();
|
||||
InitializeXxtuiNotifier();
|
||||
InitializeDiscordWebhookNotifier();
|
||||
InitializeServerChanNotifier();
|
||||
|
||||
// 添加新通知渠道时,在此处添加对应的初始化方法调用
|
||||
}
|
||||
@@ -300,6 +301,19 @@ public class NotificationService : IHostedService, IDisposable
|
||||
));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化 ServerChan 通知器
|
||||
/// </summary>
|
||||
private void InitializeServerChanNotifier()
|
||||
{
|
||||
if (_notificationConfig?.ServerChanNotificationEnabled != true) return;
|
||||
|
||||
_notifierManager.RegisterNotifier(new ServerChanNotifier(
|
||||
_notifyHttpClient,
|
||||
_notificationConfig.ServerChanSendKey
|
||||
));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析信息推送通知渠道配置
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Service.Notification.Model;
|
||||
using BetterGenshinImpact.Service.Notifier.Exception;
|
||||
using BetterGenshinImpact.Service.Notifier.Interface;
|
||||
|
||||
namespace BetterGenshinImpact.Service.Notifier;
|
||||
|
||||
/// <summary>
|
||||
/// ServerChan通知器
|
||||
/// </summary>
|
||||
public class ServerChanNotifier : INotifier
|
||||
{
|
||||
public string Name { get; set; } = "ServerChan";
|
||||
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly string _sendKey;
|
||||
|
||||
|
||||
public ServerChanNotifier(HttpClient httpClient, string sendKey)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_sendKey = sendKey;
|
||||
}
|
||||
|
||||
public async Task SendAsync(BaseNotificationData content)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_sendKey))
|
||||
{
|
||||
throw new NotifierException("ServerChan SendKey为空");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 获取正确的API URL
|
||||
string apiUrl = GetServerChanApiUrl(_sendKey);
|
||||
|
||||
// 生成通知标题和内容
|
||||
string title = $"BetterGI·更好的原神";
|
||||
string desp = GenerateDescription(content);
|
||||
|
||||
// 准备表单数据
|
||||
var postData = $"title={Uri.EscapeDataString(title)}&desp={Uri.EscapeDataString(desp)}";
|
||||
|
||||
// 创建请求
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, apiUrl);
|
||||
request.Content = new StringContent(postData, Encoding.UTF8, "application/x-www-form-urlencoded");
|
||||
|
||||
// 发送请求
|
||||
var response = await _httpClient.SendAsync(request);
|
||||
|
||||
// 检查响应状态
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
throw new NotifierException($"ServerChan调用失败,状态码: {response.StatusCode}");
|
||||
}
|
||||
}
|
||||
catch (NotifierException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
throw new NotifierException($"Error sending ServerChan message: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据sendKey格式获取正确的API URL
|
||||
/// </summary>
|
||||
private string GetServerChanApiUrl(string key)
|
||||
{
|
||||
// 判断sendkey是否以"sctp"开头并提取数字部分
|
||||
if (key.StartsWith("sctp"))
|
||||
{
|
||||
var match = Regex.Match(key, @"^sctp(\d+)t");
|
||||
if (match.Success)
|
||||
{
|
||||
var num = match.Groups[1].Value;
|
||||
return $"https://{num}.push.ft07.com/send/{key}.send";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Invalid key format for sctp.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"https://sctapi.ftqq.com/{key}.send";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成通知描述内容
|
||||
/// </summary>
|
||||
private string GenerateDescription(BaseNotificationData data)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
// 添加事件时间
|
||||
sb.AppendLine($"**时间**: {data.Timestamp.ToString("yyyy-MM-dd HH:mm:ss")}");
|
||||
|
||||
// 添加事件消息
|
||||
if (!string.IsNullOrEmpty(data.Message))
|
||||
{
|
||||
sb.AppendLine();
|
||||
sb.AppendLine($"**消息**: {data.Message}");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public partial class ScriptService : IScriptService
|
||||
var tcc = project.GroupInfo.Config.PathingConfig.TaskCycleConfig;
|
||||
if (tcc.Enable)
|
||||
{
|
||||
int index = tcc.GetExecutionOrder(DateTime.Now);
|
||||
int index = tcc.GetExecutionOrder();
|
||||
if (index == -1)
|
||||
{
|
||||
_logger.LogInformation($"{project.Name}周期配置参数错误,配置将不生效,任务正常执行!");
|
||||
@@ -578,11 +578,12 @@ public partial class ScriptService : IScriptService
|
||||
{
|
||||
if (!homePageViewModel.TaskDispatcherEnabled || !TaskContext.Instance().IsInitialized)
|
||||
{
|
||||
await Task.Delay(500);
|
||||
continue;
|
||||
}
|
||||
|
||||
var content = TaskControl.CaptureToRectArea();
|
||||
if (Bv.IsInMainUi(content) || Bv.IsInAnyClosableUi(content))
|
||||
if (Bv.IsInMainUi(content) || Bv.IsInAnyClosableUi(content) || Bv.IsInDomain(content))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -472,6 +472,142 @@
|
||||
<ui:ToggleSwitch Margin="0,0,36,0" IsChecked="{Binding Config.CommonConfig.ExitToTray, Mode=TwoWay}" />
|
||||
</ui:CardControl>
|
||||
|
||||
<!-- HTTP服务器设置 -->
|
||||
<ui:CardExpander Margin="0,0,0,12" ContentPadding="0" Icon="{ui:SymbolIcon Globe24}">
|
||||
<ui:CardExpander.Header>
|
||||
<Grid>
|
||||
<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="BetterGI HTTP 服务器设置"
|
||||
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,24,0"
|
||||
IsChecked="{Binding Config.HttpServerConfig.Enabled, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
</ui:CardExpander.Header>
|
||||
<StackPanel>
|
||||
<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="端口号"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="HTTP服务器监听的端口号,范围1-65535"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBox Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
MinWidth="90"
|
||||
Margin="0,0,36,0"
|
||||
Text="{Binding Config.HttpServerConfig.Port, Mode=TwoWay,
|
||||
ValidatesOnNotifyDataErrors=True}" />
|
||||
</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="启用跨域请求(CORS)"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="允许来自不同域名的Web应用访问API"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:ToggleSwitch Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,36,0"
|
||||
IsChecked="{Binding Config.HttpServerConfig.EnableCors, 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="API访问令牌"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="可选的安全验证令牌,留空则不启用验证"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBox Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
MinWidth="170"
|
||||
Margin="0,0,36,0"
|
||||
Text="{Binding Config.HttpServerConfig.AccessToken, 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="启用WebSocket支持"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="启用WebSocket实时双向通信功能"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:ToggleSwitch Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,36,0"
|
||||
IsChecked="{Binding Config.HttpServerConfig.EnableWebSocket, Mode=TwoWay}" />
|
||||
</Grid>-->
|
||||
</StackPanel>
|
||||
</ui:CardExpander>
|
||||
|
||||
<ui:TextBlock Margin="0,0,0,8"
|
||||
FontTypography="BodyStrong"
|
||||
@@ -1026,6 +1162,35 @@
|
||||
Margin="0,0,36,0"
|
||||
IsChecked="{Binding Config.OtherConfig.RestoreFocusOnLostEnabled, 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="服务器时区设置"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="设置游戏服务器的时区,用于计算基于服务器时间的每日重置时间等任务调度。JS脚本可手动使用此设置来处理不同区域服务器的时区。"
|
||||
TextWrapping="Wrap" />
|
||||
<ComboBox Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
MinWidth="100"
|
||||
Margin="0,0,36,0"
|
||||
ItemsSource="{Binding ServerTimeZones}"
|
||||
SelectedValue="{Binding Config.OtherConfig.ServerTimeZoneOffset}"
|
||||
SelectedValuePath="Item1"
|
||||
DisplayMemberPath="Item2" />
|
||||
</Grid>
|
||||
<ui:CardExpander Margin="0,0,0,12"
|
||||
ContentPadding="0"
|
||||
Icon="{ui:SymbolIcon SquareHintSparkles24}">
|
||||
|
||||
@@ -2003,5 +2003,93 @@
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ui:CardExpander>
|
||||
<!-- ServerChan通知 -->
|
||||
<ui:CardExpander Margin="0,0,0,12"
|
||||
ContentPadding="0"
|
||||
Icon="{ui:SymbolIcon ChatMultiple24}">
|
||||
<ui:CardExpander.Header>
|
||||
<Grid>
|
||||
<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="启用 ServerChan 通知"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="ServerChan 推送通知相关设置"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:ToggleSwitch Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,24,0"
|
||||
IsChecked="{Binding Config.NotificationConfig.ServerChanNotificationEnabled, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
</ui:CardExpander.Header>
|
||||
<StackPanel>
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="3*" />
|
||||
<ColumnDefinition Width="2*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="SendKey"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="填写 ServerChan 的 SendKey"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBox Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
MinWidth="180"
|
||||
MaxWidth="800"
|
||||
Margin="0,0,36,0"
|
||||
Text="{Binding Config.NotificationConfig.ServerChanSendKey, Mode=TwoWay}"
|
||||
TextWrapping="NoWrap" />
|
||||
</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="测试 ServerChan 通知"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="发送测试通知"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:Button Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,36,0"
|
||||
Command="{Binding TestServerChanNotificationCommand}"
|
||||
Content="发送" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ui:CardExpander>
|
||||
</StackPanel>
|
||||
</Page>
|
||||
@@ -416,6 +416,31 @@
|
||||
MinWidth="120"
|
||||
Text="{Binding PathingConfig.TaskCycleConfig.BoundaryTime}" />
|
||||
</Grid>
|
||||
<Grid Margin="16,0,16,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="分界时间参考服务器时区"
|
||||
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.TaskCycleConfig.IsBoundaryTimeBasedOnServerTime}" />
|
||||
</Grid>
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
@@ -591,6 +616,31 @@
|
||||
MinWidth="120"
|
||||
Text="{Binding PathingConfig.TaskCompletionSkipRuleConfig.BoundaryTime}" />
|
||||
</Grid>
|
||||
<Grid Margin="16,0,16,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="分界时间参考服务器时区"
|
||||
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.TaskCompletionSkipRuleConfig.IsBoundaryTimeBasedOnServerTime}" />
|
||||
</Grid>
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
|
||||
@@ -50,6 +50,13 @@ public partial class CommonSettingsPageViewModel : ViewModel
|
||||
|
||||
private string _selectedCountry = string.Empty;
|
||||
[ObservableProperty] private List<string> _adventurersGuildCountry = ["无", "枫丹", "稻妻", "璃月", "蒙德"];
|
||||
|
||||
[ObservableProperty] private List<Tuple<TimeSpan, string>> _serverTimeZones =
|
||||
[
|
||||
Tuple.Create(TimeSpan.FromHours(8), "其他 UTC+08"),
|
||||
Tuple.Create(TimeSpan.FromHours(1), "欧服 UTC+01"),
|
||||
Tuple.Create(TimeSpan.FromHours(-5), "美服 UTC-05")
|
||||
];
|
||||
|
||||
public CommonSettingsPageViewModel(IConfigService configService, INavigationService navigationService,
|
||||
NotificationService notificationService)
|
||||
@@ -66,7 +73,7 @@ public partial class CommonSettingsPageViewModel : ViewModel
|
||||
public AllConfig Config { get; set; }
|
||||
public ObservableCollection<string> CountryList { get; } = new();
|
||||
public ObservableCollection<string> Areas { get; } = new();
|
||||
|
||||
|
||||
public ObservableCollection<string> MapPathingTypes { get; } = ["SIFT", "TemplateMatch"];
|
||||
|
||||
[ObservableProperty] private FrozenDictionary<string, string> _languageDict =
|
||||
@@ -106,11 +113,11 @@ public partial class CommonSettingsPageViewModel : ViewModel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<PaddleOcrModelConfig> PaddleOcrModelConfigs { get; } = new(Enum.GetValues(typeof(PaddleOcrModelConfig)).Cast<PaddleOcrModelConfig>());
|
||||
|
||||
[ObservableProperty]
|
||||
private PaddleOcrModelConfig _selectedPaddleOcrModelConfig;
|
||||
public ObservableCollection<PaddleOcrModelConfig> PaddleOcrModelConfigs { get; } =
|
||||
new(Enum.GetValues(typeof(PaddleOcrModelConfig)).Cast<PaddleOcrModelConfig>());
|
||||
|
||||
[ObservableProperty] private PaddleOcrModelConfig _selectedPaddleOcrModelConfig;
|
||||
|
||||
[RelayCommand]
|
||||
public void OnQuestionButtonOnClick()
|
||||
@@ -127,10 +134,11 @@ public partial class CommonSettingsPageViewModel : ViewModel
|
||||
cookieWin.NavigateToHtml(TravelsDiaryDetailManager.generHtmlMessage());
|
||||
cookieWin.Show();
|
||||
}
|
||||
|
||||
private void InitializeMiyousheCookie()
|
||||
{
|
||||
OtherConfig.Miyoushe mcfg = TaskContext.Instance().Config.OtherConfig.MiyousheConfig;
|
||||
if (mcfg.Cookie == string.Empty&&
|
||||
if (mcfg.Cookie == string.Empty &&
|
||||
mcfg.LogSyncCookie)
|
||||
{
|
||||
var config = LogParse.LoadConfig();
|
||||
@@ -339,6 +347,7 @@ public partial class CommonSettingsPageViewModel : ViewModel
|
||||
{
|
||||
await App.ServiceProvider.GetRequiredService<OcrFactory>().Unload();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task OnPaddleOcrModelConfigChanged(PaddleOcrModelConfig value)
|
||||
{
|
||||
|
||||
@@ -49,6 +49,8 @@ public partial class NotificationSettingsPageViewModel : ObservableObject, IView
|
||||
nameof(DiscordWebhookNotifier.ImageEncoderEnum.WebP)
|
||||
];
|
||||
|
||||
[ObservableProperty] private string _serverChanStatus = string.Empty;
|
||||
|
||||
public NotificationSettingsPageViewModel(IConfigService configService, NotificationService notificationService)
|
||||
{
|
||||
Config = configService.Get();
|
||||
@@ -284,4 +286,23 @@ public partial class NotificationSettingsPageViewModel : ObservableObject, IView
|
||||
|
||||
IsLoading = false;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task OnTestServerChanNotification()
|
||||
{
|
||||
IsLoading = true;
|
||||
ServerChanStatus = string.Empty;
|
||||
|
||||
var res = await _notificationService.TestNotifierAsync<ServerChanNotifier>();
|
||||
|
||||
ServerChanStatus = res.Message;
|
||||
|
||||
// 添加Toast提示
|
||||
if (res.IsSuccess)
|
||||
Toast.Success(res.Message);
|
||||
else
|
||||
Toast.Error(res.Message);
|
||||
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public partial class ScriptGroupConfigViewModel : ObservableObject, IViewModel
|
||||
[RelayCommand]
|
||||
public void OnGetExecutionOrder()
|
||||
{
|
||||
var index = _pathingConfig.TaskCycleConfig.GetExecutionOrder(DateTime.Now);
|
||||
var index = _pathingConfig.TaskCycleConfig.GetExecutionOrder();
|
||||
if (index == -1)
|
||||
{
|
||||
Toast.Error("计算失败,请检查参数!");
|
||||
|
||||
@@ -20,7 +20,7 @@ echo [build app using vs2022]
|
||||
cd /d %~dp0
|
||||
rd /s /q ..\BetterGenshinImpact\bin\x64\Release\net8.0-windows10.0.22621.0\publish\win-x64\
|
||||
cd ..\
|
||||
dotnet publish -c Release -p:PublishProfile=FolderProfile
|
||||
dotnet publish -c Release -p:PublishProfile=FolderProfile -p:SelfContained=true
|
||||
|
||||
echo [pack app using 7z]
|
||||
cd /d %~dp0
|
||||
|
||||
Submodule Test/BetterGenshinImpact.UnitTest/Assets updated: 3df550ad83...1ac6fa0960.
+3
-3
@@ -11,19 +11,19 @@ namespace BetterGenshinImpact.UnitTest.CoreTests.RecognitionTests.OCRTests
|
||||
|
||||
public PaddleOcrService Get(string cultureInfoName = "zh-Hans", string version = "V5")
|
||||
{
|
||||
return _paddleOcrServices.GetOrAdd(cultureInfoName, name =>
|
||||
return _paddleOcrServices.GetOrAdd(cultureInfoName + "_" + version, _ =>
|
||||
{
|
||||
lock (_paddleOcrServices)
|
||||
{
|
||||
if (version == "V5")
|
||||
{
|
||||
return new PaddleOcrService(new BgiOnnxFactory(new FakeLogger<BgiOnnxFactory>()),
|
||||
PaddleOcrService.PaddleOcrModelType.FromCultureInfo(new CultureInfo(name)) ?? PaddleOcrService.PaddleOcrModelType.V5);
|
||||
PaddleOcrService.PaddleOcrModelType.FromCultureInfo(new CultureInfo(cultureInfoName)) ?? PaddleOcrService.PaddleOcrModelType.V5);
|
||||
}
|
||||
else if (version == "V4")
|
||||
{
|
||||
return new PaddleOcrService(new BgiOnnxFactory(new FakeLogger<BgiOnnxFactory>()),
|
||||
PaddleOcrService.PaddleOcrModelType.FromCultureInfoV4(new CultureInfo(name)) ?? PaddleOcrService.PaddleOcrModelType.V4);
|
||||
PaddleOcrService.PaddleOcrModelType.FromCultureInfoV4(new CultureInfo(cultureInfoName)) ?? PaddleOcrService.PaddleOcrModelType.V4);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+14
-1
@@ -1,4 +1,4 @@
|
||||
using OpenCvSharp;
|
||||
using OpenCvSharp;
|
||||
using System.Drawing;
|
||||
using BetterGenshinImpact.Core.Recognition.OCR.Paddle;
|
||||
using OpenCvSharp.Extensions;
|
||||
@@ -72,5 +72,18 @@ namespace BetterGenshinImpact.UnitTest.CoreTests.RecognitionTests.OCRTests
|
||||
Assert.Matches(pattern, actual);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PaddleOcrService_Version_ShouldBeCorrect()
|
||||
{
|
||||
//
|
||||
var ocrV4 = this.paddle.Get("zh-Hans", "V4");
|
||||
var ocrV5 = this.paddle.Get("zh-Hans", "V5");
|
||||
//
|
||||
Assert.EndsWith("V4", ocrV4.GetConfigName.Item1, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.EndsWith("V4", ocrV4.GetConfigName.Item2, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.EndsWith("V5", ocrV5.GetConfigName.Item1, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.EndsWith("V5", ocrV5.GetConfigName.Item2, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,12 +21,14 @@ namespace BetterGenshinImpact.UnitTest.GameTaskTests.AutoDomainTests
|
||||
this.paddle = paddle;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(@"AutoDomain\SelectRevitalization.png", 21, 0, 2, 1)]
|
||||
[InlineData(@"AutoDomain\SelectRevitalizationOcrV4.png", 11, 0, 1, 149, "V4")]
|
||||
/// <summary>
|
||||
/// 测试识别四种树脂数量,数量应正确
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData(@"AutoDomain\SelectRevitalization.png", 21, 0, 2, 1)]
|
||||
[InlineData(@"AutoDomain\SelectRevitalizationOcrV4.png", 11, 0, 1, 149, "V4")]
|
||||
[InlineData(@"AutoDomain\SelectRevitalizationOcrV4_NSSZ1.png", 20, 1, 1, 0, "V4")]
|
||||
[InlineData(@"AutoDomain\SelectRevitalizationOcrV4_NSSZ1.png", 20, 1, 1, 0)]
|
||||
public void RecogniseFromRegion_ResinStatusShouldBeRight(string screenshot1080p, int originalResinCount, int fragileResinCount, int condensedResinCount, int transientResinCount, string ocrVersion = "V5")
|
||||
{
|
||||
//
|
||||
@@ -35,7 +37,7 @@ namespace BetterGenshinImpact.UnitTest.GameTaskTests.AutoDomainTests
|
||||
FakeSystemInfo systemInfo = new FakeSystemInfo(new Vanara.PInvoke.RECT(0, 0, mat.Width, mat.Height), 1);
|
||||
|
||||
//
|
||||
var result = ResinStatus.RecogniseFromRegion(imageRegion, systemInfo, this.paddle.Get(version: ocrVersion)); // todo:System.Exception : 未找到原粹树脂图标
|
||||
var result = ResinStatus.RecogniseFromRegion(imageRegion, systemInfo, this.paddle.Get(version: ocrVersion));
|
||||
|
||||
//
|
||||
Assert.Equal(originalResinCount, result.OriginalResinCount);
|
||||
|
||||
Reference in new issue
Block a user