From 225f78b769123c2d7d3ca97b5eadbfad44055e7d Mon Sep 17 00:00:00 2001 From: mfkvfhpdx Date: Mon, 19 May 2025 23:32:22 +0800 Subject: [PATCH 01/25] =?UTF-8?q?=E6=88=98=E6=96=97=E5=90=8E=E6=8B=BE?= =?UTF-8?q?=E5=8F=96=E6=94=AF=E6=8C=81=E6=A0=B9=E6=8D=AE=E7=82=B9=E4=BD=8D?= =?UTF-8?q?=E6=A0=87=E8=AE=B0=E6=98=AF=E5=90=A6=E7=B2=BE=E8=8B=B1=EF=BC=8C?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=85=B3=E9=97=AD=E6=8B=BE=E5=8F=96=20(#1616?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修改调度器任务和部分独立任务失去焦点时,强制切换回游戏窗口,如果用常规的方式无法激活窗口,则第10次会尝试最小化所有窗口后激活游戏。 * 去除未引入的类引用 * 修正战斗结束后,大概率打开队伍界面的问题 * 修复有些电脑上因未知原因,战斗0秒打断 * 把失焦激活放入了设置-通用设置-其他设置中,默认关闭。暂停恢复时,重置移动的起始时间,防止因暂停而导致超时放弃任务。 * 在调度器里面的任务之前,增加月卡处理,解决4点如果未进入任务会卡住的问题。增加了日志分析小怪详细。解决日志分析兜底结束日期不生效的问题。 * 在设置=》其他设置中 增加调度器任务传送过程中自动领取探索奖励功能配置。 * 调整自动派遣后恢复原任务的逻辑 * 自动领取派遣奖励时,跳过异常,防止整个配置组任务被打断。 * 把打开大地图方法从TpTask中抽出为公共方法,自动领取派遣代码调整到了调度器中。 * 去除了未使用的引用 * 暂停恢复逻辑增加恢复中条件和非空判断 * 增加了临时暂停自动拾取的逻辑(RunnerContext.AutoPickTriggerStopCount 为0时不限制,大于0时停止,多次暂停会累加该值,每次恢复-1),支持嵌套情况的暂停,在自动派遣(和结束后5秒)或暂停调度器任务时,同时暂停自动拾取功能。 * 调整暂停拾取方法 * 调整个日志输出 * 路径追踪复苏时,暂停拾取 * 增加根据点位配置,支持能在点位未识别情况下,使用大地图中心点的方式来定位,从而支持像铜锁小岛处这种小地图无法识别的点位。调整了对未识别点位的默认逻辑,未配置点位配置情况下,未识别点位,会取上一个识别的点位,从而支持在某些地方断续小地图能识别情况下的脚本。 * Changes * 修复暂停后,距离过远,小地图无法识别时,无限取当前一个坐标,导致无法正常恢复的问题。调度器管理增加了按天为单位的周期配置,适用于批量执行时,无需人工判断当天执行哪个任务。 * 调度器配置增加,或开启万叶拾取,并且不存在万叶,但配置了万叶队伍情况下,会切换队伍进行拾取。 * 调度器配置,增加了 只拾取精英掉落模式 ,根据编辑器点位配置,可设定非标记精英或传奇的点位跳过拾取。 --- .../GameTask/AutoFight/AutoFightConfig.cs | 8 ++++- .../GameTask/AutoFight/AutoFightParam.cs | 2 ++ .../AutoPathing/Handler/AutoFightHandler.cs | 35 +++++++++++++++++-- .../AutoPathing/Model/WaypointForTrack.cs | 3 ++ .../GameTask/AutoPathing/PathExecutor.cs | 1 + .../Pages/View/ScriptGroupConfigView.xaml | 29 +++++++++++++++ .../Pages/View/ScriptGroupConfigViewModel.cs | 10 +++++- 7 files changed, 83 insertions(+), 5 deletions(-) diff --git a/BetterGenshinImpact/GameTask/AutoFight/AutoFightConfig.cs b/BetterGenshinImpact/GameTask/AutoFight/AutoFightConfig.cs index 40bda6a5..ce34d262 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/AutoFightConfig.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/AutoFightConfig.cs @@ -31,7 +31,13 @@ public partial class AutoFightConfig : ObservableObject /// 多种用分号分隔,例如:白术;钟离,12;,如果人名,则用内置cd检查,如果是人名和数字,则把数字当做出招cd(秒)。 /// [ObservableProperty] private string _actionSchedulerByCd = ""; - + /// + /// 只拾取精英掉落 + /// Closed :关闭功能 + /// AllowAutoPickupForNonElite: 非精英允许自动拾取:战斗过程中掉落脚下的可以自动拾取,但不会执行万叶拾取和拾取配置逻辑。 + /// DisableAutoPickupForNonElite: 非精英关闭拾取:战斗过程中掉落到脚下的也不会自动拾取。 + /// + [ObservableProperty] private string _onlyPickEliteDropsMode = "Closed"; [Serializable] public partial class FightFinishDetectConfig : ObservableObject { diff --git a/BetterGenshinImpact/GameTask/AutoFight/AutoFightParam.cs b/BetterGenshinImpact/GameTask/AutoFight/AutoFightParam.cs index 7b663eda..afa11bf6 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/AutoFightParam.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/AutoFightParam.cs @@ -35,6 +35,7 @@ public class AutoFightParam : BaseTaskParam FinishDetectConfig.CheckEndDelay = autoFightConfig.FinishDetectConfig.CheckEndDelay; FinishDetectConfig.BeforeDetectDelay = autoFightConfig.FinishDetectConfig.BeforeDetectDelay; KazuhaPartyName = autoFightConfig.KazuhaPartyName; + OnlyPickEliteDropsMode = autoFightConfig.OnlyPickEliteDropsMode; //下面参数固定,只取自动战斗里面的 FinishDetectConfig.BattleEndProgressBarColor = TaskContext.Instance().Config.AutoFightConfig.FinishDetectConfig.BattleEndProgressBarColor; FinishDetectConfig.BattleEndProgressBarColorTolerance = TaskContext.Instance().Config.AutoFightConfig.FinishDetectConfig.BattleEndProgressBarColorTolerance; @@ -53,6 +54,7 @@ public class AutoFightParam : BaseTaskParam public bool KazuhaPickupEnabled = true; public string ActionSchedulerByCd = ""; public string KazuhaPartyName; + public string OnlyPickEliteDropsMode=""; } \ No newline at end of file diff --git a/BetterGenshinImpact/GameTask/AutoPathing/Handler/AutoFightHandler.cs b/BetterGenshinImpact/GameTask/AutoPathing/Handler/AutoFightHandler.cs index 214747bd..fb28d241 100644 --- a/BetterGenshinImpact/GameTask/AutoPathing/Handler/AutoFightHandler.cs +++ b/BetterGenshinImpact/GameTask/AutoPathing/Handler/AutoFightHandler.cs @@ -12,21 +12,22 @@ namespace BetterGenshinImpact.GameTask.AutoPathing.Handler; internal class AutoFightHandler : IActionHandler { + private readonly ILogger _logger = App.GetLogger(); public async Task RunAsyncByScript(CancellationToken ct, WaypointForTrack? waypointForTrack = null, object? config = null) { if (!(config != null && config is PathingPartyConfig patyConfig && patyConfig is {AutoFightEnabled:true,JsScriptUseEnabled:true,SoloTaskUseFightEnabled:true} )) { config = null; } - await StartFight(ct, config); + await StartFight(ct, config,waypointForTrack); } public async Task RunAsync(CancellationToken ct, WaypointForTrack? waypointForTrack = null, object? config = null) { - await StartFight(ct, config); + await StartFight(ct, config,waypointForTrack); } - private async Task StartFight(CancellationToken ct, object? config = null) + private async Task StartFight(CancellationToken ct, object? config = null , WaypointForTrack? waypointForTrack = null) { TaskControl.Logger.LogInformation("执行 {Text}", "自动战斗"); // 爷们要战斗 @@ -42,6 +43,34 @@ internal class AutoFightHandler : IActionHandler taskParams = new AutoFightParam(GetFightStrategy(), TaskContext.Instance().Config.AutoFightConfig); } + //根据怪物标签,调整拾取配置 + if (waypointForTrack!=null) + { + // normal 小怪,elite 精英,legendary 传奇 + //不为精英或者小怪 + if (!(waypointForTrack.MonsterTag == "elite" || waypointForTrack.MonsterTag == "legendary")) + { + + if (taskParams.OnlyPickEliteDropsMode == "AllowAutoPickupForNonElite" || taskParams.OnlyPickEliteDropsMode == "DisableAutoPickupForNonElite") + { + //允许自动拾取,即只关闭配置上的拾取即刻 + taskParams.KazuhaPickupEnabled = false; + taskParams.PickDropsAfterFightEnabled = false; + _logger.LogInformation("当前非精英或传奇点位,关闭战斗拾取配置!"); + //禁止自动拾取,除了关闭配置拾取外,连自动拾取都关掉 + if (taskParams.OnlyPickEliteDropsMode == "DisableAutoPickupForNonElite") + { + await RunnerContext.Instance.StopAutoPickRunTask( + async () => await new AutoFightTask(taskParams).Start(ct), + 5); + return; + } + } + + } + + } + var fightSoloTask = new AutoFightTask(taskParams); await fightSoloTask.Start(ct); } diff --git a/BetterGenshinImpact/GameTask/AutoPathing/Model/WaypointForTrack.cs b/BetterGenshinImpact/GameTask/AutoPathing/Model/WaypointForTrack.cs index 5a76a6e2..4e0ba2d7 100644 --- a/BetterGenshinImpact/GameTask/AutoPathing/Model/WaypointForTrack.cs +++ b/BetterGenshinImpact/GameTask/AutoPathing/Model/WaypointForTrack.cs @@ -22,6 +22,9 @@ public class WaypointForTrack : Waypoint public string MapName { get; set; } //异常识别 public Misidentification Misidentification { get; set; } = new(); + + //怪物标签 + public string MonsterTag { get; set; } =""; /// /// 存在 combat_script 的 action 的话,这个值会存在 diff --git a/BetterGenshinImpact/GameTask/AutoPathing/PathExecutor.cs b/BetterGenshinImpact/GameTask/AutoPathing/PathExecutor.cs index 95d96a63..c7cfb3e2 100644 --- a/BetterGenshinImpact/GameTask/AutoPathing/PathExecutor.cs +++ b/BetterGenshinImpact/GameTask/AutoPathing/PathExecutor.cs @@ -496,6 +496,7 @@ public class PathExecutor { WaypointForTrack wft=new WaypointForTrack(waypoint, task.Info.MapName); wft.Misidentification=waypoint.PointExtParams.Misidentification; + wft.MonsterTag = waypoint.PointExtParams.MonsterTag; return wft; }).ToList(); diff --git a/BetterGenshinImpact/View/Pages/View/ScriptGroupConfigView.xaml b/BetterGenshinImpact/View/Pages/View/ScriptGroupConfigView.xaml index 065e0b7a..18866f8e 100644 --- a/BetterGenshinImpact/View/Pages/View/ScriptGroupConfigView.xaml +++ b/BetterGenshinImpact/View/Pages/View/ScriptGroupConfigView.xaml @@ -878,6 +878,35 @@ Margin="0,0,36,0" IsChecked="{Binding PathingConfig.AutoFightConfig.KazuhaPickupEnabled, Mode=TwoWay}" /> + + + + + + + + + + + + + + diff --git a/BetterGenshinImpact/ViewModel/Pages/View/ScriptGroupConfigViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/View/ScriptGroupConfigViewModel.cs index 7253fc04..8bf71441 100644 --- a/BetterGenshinImpact/ViewModel/Pages/View/ScriptGroupConfigViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/View/ScriptGroupConfigViewModel.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.Core.Script.Group; using BetterGenshinImpact.View.Windows; @@ -24,7 +26,13 @@ public partial class ScriptGroupConfigViewModel : ObservableObject, IViewModel [ObservableProperty] private bool _enableShellConfig; - + [ObservableProperty] + private ObservableCollection> _onlyPickEliteDropsSource = new() + { + new KeyValuePair("Closed", "关闭功能"), + new KeyValuePair("AllowAutoPickupForNonElite", "非精英允许自动拾取"), + new KeyValuePair("DisableAutoPickupForNonElite", "非精英关闭自动拾取") + }; public ScriptGroupConfigViewModel(AllConfig config, ScriptGroupConfig scriptGroupConfig) { ScriptGroupConfig = scriptGroupConfig; From d3eed426de873aa86b2fc282efe0d146fe24f625 Mon Sep 17 00:00:00 2001 From: mfkvfhpdx Date: Sat, 24 May 2025 11:17:37 +0800 Subject: [PATCH 02/25] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E4=B8=BB=E7=95=8C=E9=9D=A2=E6=97=B6=EF=BC=8C=E5=8D=A1=E5=A4=8D?= =?UTF-8?q?=E6=B4=BB=E7=95=8C=E9=9D=A2=E7=9A=84=E9=97=AE=E9=A2=98=20(#1625?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修改调度器任务和部分独立任务失去焦点时,强制切换回游戏窗口,如果用常规的方式无法激活窗口,则第10次会尝试最小化所有窗口后激活游戏。 * 去除未引入的类引用 * 修正战斗结束后,大概率打开队伍界面的问题 * 修复有些电脑上因未知原因,战斗0秒打断 * 把失焦激活放入了设置-通用设置-其他设置中,默认关闭。暂停恢复时,重置移动的起始时间,防止因暂停而导致超时放弃任务。 * 在调度器里面的任务之前,增加月卡处理,解决4点如果未进入任务会卡住的问题。增加了日志分析小怪详细。解决日志分析兜底结束日期不生效的问题。 * 在设置=》其他设置中 增加调度器任务传送过程中自动领取探索奖励功能配置。 * 调整自动派遣后恢复原任务的逻辑 * 自动领取派遣奖励时,跳过异常,防止整个配置组任务被打断。 * 把打开大地图方法从TpTask中抽出为公共方法,自动领取派遣代码调整到了调度器中。 * 去除了未使用的引用 * 暂停恢复逻辑增加恢复中条件和非空判断 * 增加了临时暂停自动拾取的逻辑(RunnerContext.AutoPickTriggerStopCount 为0时不限制,大于0时停止,多次暂停会累加该值,每次恢复-1),支持嵌套情况的暂停,在自动派遣(和结束后5秒)或暂停调度器任务时,同时暂停自动拾取功能。 * 调整暂停拾取方法 * 调整个日志输出 * 路径追踪复苏时,暂停拾取 * 增加根据点位配置,支持能在点位未识别情况下,使用大地图中心点的方式来定位,从而支持像铜锁小岛处这种小地图无法识别的点位。调整了对未识别点位的默认逻辑,未配置点位配置情况下,未识别点位,会取上一个识别的点位,从而支持在某些地方断续小地图能识别情况下的脚本。 * Changes * 修复暂停后,距离过远,小地图无法识别时,无限取当前一个坐标,导致无法正常恢复的问题。调度器管理增加了按天为单位的周期配置,适用于批量执行时,无需人工判断当天执行哪个任务。 * 调度器配置增加,或开启万叶拾取,并且不存在万叶,但配置了万叶队伍情况下,会切换队伍进行拾取。 * 调度器配置,增加了 只拾取精英掉落模式 ,根据编辑器点位配置,可设定非标记精英或传奇的点位跳过拾取。 * 解决卡换成复活形式的任务卡死 * 判断主界面时,复活界面返回false * 完全跳过的配置组,不发送通知。给周期配置增加说明。 --- .../GameTask/Common/BgiVision/BvStatus.cs | 5 ++++- BetterGenshinImpact/Service/ScriptService.cs | 17 ++++++++++++++--- .../View/Pages/View/ScriptGroupConfigView.xaml | 4 ++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/BetterGenshinImpact/GameTask/Common/BgiVision/BvStatus.cs b/BetterGenshinImpact/GameTask/Common/BgiVision/BvStatus.cs index 16d879e4..49bcb3f2 100644 --- a/BetterGenshinImpact/GameTask/Common/BgiVision/BvStatus.cs +++ b/BetterGenshinImpact/GameTask/Common/BgiVision/BvStatus.cs @@ -7,10 +7,12 @@ using System.Linq; using System.Threading.Tasks; using BetterGenshinImpact.Core.Recognition; using System.Threading; + using BetterGenshinImpact.GameTask.AutoFight.Assets; using BetterGenshinImpact.GameTask.AutoSkip.Assets; using BetterGenshinImpact.GameTask.GameLoading.Assets; + namespace BetterGenshinImpact.GameTask.Common.BgiVision; /// @@ -21,6 +23,7 @@ namespace BetterGenshinImpact.GameTask.Common.BgiVision; /// public static partial class Bv { + public static string WhichGameUi() { throw new NotImplementedException(); @@ -33,7 +36,7 @@ public static partial class Bv /// public static bool IsInMainUi(ImageRegion captureRa) { - return captureRa.Find(ElementAssets.Instance.PaimonMenuRo).IsExist(); + return captureRa.Find(ElementAssets.Instance.PaimonMenuRo).IsExist() && !IsInRevivePrompt(captureRa); } /// diff --git a/BetterGenshinImpact/Service/ScriptService.cs b/BetterGenshinImpact/Service/ScriptService.cs index bc10665e..e231f385 100644 --- a/BetterGenshinImpact/Service/ScriptService.cs +++ b/BetterGenshinImpact/Service/ScriptService.cs @@ -101,8 +101,8 @@ public partial class ScriptService : IScriptService // var timerOperation = hasTimer ? DispatcherTimerOperationEnum.UseCacheImageWithTriggerEmpty : DispatcherTimerOperationEnum.UseSelfCaptureImage; - Notify.Event(NotificationEvent.GroupStart).Success($"配置组{groupName}启动"); - + + bool fisrt = true; await new TaskRunner() .RunThreadAsync(async () => { @@ -128,6 +128,12 @@ public partial class ScriptService : IScriptService break; } + + if (fisrt) + { + fisrt = false; + Notify.Event(NotificationEvent.GroupStart).Success($"配置组{groupName}启动"); + } for (var i = 0; i < project.RunNum; i++) { try @@ -184,7 +190,12 @@ public partial class ScriptService : IScriptService _logger.LogInformation("配置组 {Name} 执行结束", groupName); } - Notify.Event(NotificationEvent.GroupEnd).Success($"配置组{groupName}结束"); + if (!fisrt) + { + Notify.Event(NotificationEvent.GroupEnd).Success($"配置组{groupName}结束"); + } + + } private List ReloadScriptProjects(IEnumerable projectList) diff --git a/BetterGenshinImpact/View/Pages/View/ScriptGroupConfigView.xaml b/BetterGenshinImpact/View/Pages/View/ScriptGroupConfigView.xaml index 18866f8e..77d37e58 100644 --- a/BetterGenshinImpact/View/Pages/View/ScriptGroupConfigView.xaml +++ b/BetterGenshinImpact/View/Pages/View/ScriptGroupConfigView.xaml @@ -459,7 +459,7 @@ Date: Sun, 25 May 2025 08:44:35 -0500 Subject: [PATCH 03/25] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E9=92=93=E9=B1=BC=E6=8B=89=E6=9D=A1=E6=97=B6=E6=B8=B8=E6=A0=87?= =?UTF-8?q?=E5=BC=B9=E5=87=BA=E7=9B=AE=E6=A0=87=E5=8C=BA=E9=97=B4=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=BD=A2=20(#1628)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: autofishing remove abnormal detection * revert logic change --- .../GameTask/AutoFishing/Behaviours.cs | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/BetterGenshinImpact/GameTask/AutoFishing/Behaviours.cs b/BetterGenshinImpact/GameTask/AutoFishing/Behaviours.cs index d134c1b1..8661f767 100644 --- a/BetterGenshinImpact/GameTask/AutoFishing/Behaviours.cs +++ b/BetterGenshinImpact/GameTask/AutoFishing/Behaviours.cs @@ -847,7 +847,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing logger.LogInformation("拉扯开始"); } - private MOUSEEVENTF _prevMouseEvent = 0x0; + private MOUSEEVENTF _prevMouseEvent = MOUSEEVENTF.MOUSEEVENTF_LEFTUP; protected override BehaviourStatus Update(ImageRegion imageRegion) { @@ -867,24 +867,30 @@ namespace BetterGenshinImpact.GameTask.AutoFishing rects.RemoveRange(3, rects.Count - 3); } - Rect _cur, _left, _right; //Debug.WriteLine($"识别到{rects.Count} 个矩形"); if (rects.Count == 2) { + // 游标矩形不在区间内或恰在区间两端时只会检测到两个矩形 + Rect _cursor, _target; if (rects[0].Width < rects[1].Width) { - _cur = rects[0]; - _left = rects[1]; + _cursor = rects[0]; + _target = rects[1]; } else { - _cur = rects[1]; - _left = rects[0]; + _cursor = rects[1]; + _target = rects[0]; + } + logger.LogInformation($"识别到2个矩形,主:{_target}, 中:{_cursor}"); + if (_target.Width < _cursor.Width * 10) // 异常:当目标矩形明显不够长时视为无效检测,不作为 + { + return BehaviourStatus.Running; } - PutRects(imageRegion, _left, _cur, new Rect()); + PutRects(imageRegion, _target, _cursor, new Rect()); - if (_cur.X < _left.X) + if (_cursor.X < _target.X) { if (_prevMouseEvent != MOUSEEVENTF.MOUSEEVENTF_LEFTDOWN) { @@ -907,13 +913,15 @@ namespace BetterGenshinImpact.GameTask.AutoFishing } else if (rects.Count == 3) { + // 游标矩形在区间内会检测到三个矩形,即目标区间被游标分割成左半和右半 + Rect _cursor, _left, _right; rects.Sort((a, b) => a.X.CompareTo(b.X)); _left = rects[0]; - _cur = rects[1]; + _cursor = rects[1]; _right = rects[2]; - PutRects(imageRegion, _left, _cur, _right); + PutRects(imageRegion, _left, _cursor, _right); - if (_right.X + _right.Width - (_cur.X + _cur.Width) <= _cur.X - _left.X) + if (_right.X + _right.Width - (_cursor.X + _cursor.Width) <= _cursor.X - _left.X) { if (_prevMouseEvent == MOUSEEVENTF.MOUSEEVENTF_LEFTDOWN) { @@ -955,7 +963,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing // 没有矩形视为已经完成钓鱼 drawContent.RemoveRect("FishBox"); - _prevMouseEvent = 0x0; + _prevMouseEvent = MOUSEEVENTF.MOUSEEVENTF_LEFTUP; logger.LogInformation(" 拉扯结束"); logger.LogInformation(@"└------------------------┘"); From 9c458c24434df14e868066832ca2d0b75e4a2bc1 Mon Sep 17 00:00:00 2001 From: Scarlet Date: Sun, 25 May 2025 09:03:47 -0500 Subject: [PATCH 04/25] feat: chasca slower charging aim (#1630) --- .../GameTask/AutoFight/Model/Avatar.cs | 49 ++++++++++++++++--- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs b/BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs index 89a74f7d..99c19a43 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs @@ -720,7 +720,7 @@ public class Avatar { var dpi = TaskContext.Instance().DpiScale; Simulation.SendInput.SimulateAction(GIActions.NormalAttack, KeyType.KeyDown); - int cnt = 0; + int tick = -4; // 起飞那一刻需要多一点点时间用来矫正视角高度 while (ms >= 0) { if (Ct is { IsCancellationRequested: true }) @@ -728,12 +728,47 @@ public class Avatar return; } - // 恰在蓄力时快速转动会把视角趋向于水平,所以在回正的时候不做额外Y轴移动 - double rate = cnt % 10 < 5 ? 0 : 4.5; //每500ms做一轮上下移动。 - cnt++; - Simulation.SendInput.Mouse.MoveMouseBy((int)(500 * dpi), (int)(rate * 100 * dpi)); - ms -= 50; - Sleep(50); + // 恰在蓄力时转得越快越容易把视角趋向于水平 + // 基于上面这个特性,如果我们用同一个鼠标方向向量,大致能在所有设备上控制视角高低(只要帧率不太低) + + // 恰的子弹上膛机制:怪物要在HUD准星框内超过一定时长(体感0.2-0.3秒)才能让子弹上膛。所以搜索敌人要低速。不然敌人体型小或者远就很容易锁不上。 + const double lowspeed = 0.7, highspeed = 50; + double rateX, rateY; + if (tick < 3) + { + rateX = highspeed; + rateY = highspeed * 0.23; + } + else if (tick < 40) + { + rateX = lowspeed * 0.7; + rateY = 0; + } + else if (tick < 43) + { + rateX = highspeed; + rateY = highspeed * 0.4; + } + else if (tick < 70) + { + rateX = lowspeed * 0.9; + rateY = 0; + } + else if (tick < 73) + { + rateX = highspeed; + rateY = highspeed; + } + else + { + rateX = lowspeed; + rateY = 0; + } + Simulation.SendInput.Mouse.MoveMouseBy((int)(rateX * 50 * dpi), (int)(rateY * 50 * dpi)); + + tick = (tick + 1) % 100; + Sleep(25); + ms -= 25; } Simulation.SendInput.SimulateAction(GIActions.NormalAttack, KeyType.KeyUp); From 0cfa46bd9aaccb31456efe9c4e0e29aaab1db46e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B7=E4=B8=AA=E5=90=8D=E5=AD=97=E5=A5=BD=E9=9A=BE?= =?UTF-8?q?=E7=9A=84=E5=96=B5?= <25520958+MisakaAldrich@users.noreply.github.com> Date: Mon, 26 May 2025 16:19:29 +0800 Subject: [PATCH 05/25] =?UTF-8?q?fix:=20=E5=A4=A7=E5=89=91=E6=8C=96?= =?UTF-8?q?=E7=9F=BF=20(#1633)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 大剑挖矿 * feat: 挖矿e(hold)CD等待 --- .../AutoPathing/Handler/MiningHandler.cs | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/BetterGenshinImpact/GameTask/AutoPathing/Handler/MiningHandler.cs b/BetterGenshinImpact/GameTask/AutoPathing/Handler/MiningHandler.cs index db26fda9..94665ec7 100644 --- a/BetterGenshinImpact/GameTask/AutoPathing/Handler/MiningHandler.cs +++ b/BetterGenshinImpact/GameTask/AutoPathing/Handler/MiningHandler.cs @@ -17,28 +17,28 @@ namespace BetterGenshinImpact.GameTask.AutoPathing.Handler; public class MiningHandler : IActionHandler { private readonly CombatScript _miningCombatScript = CombatScriptParser.ParseContext(""" - 卡齐娜 e(hold),keydown(s),wait(0.4),keyup(s),attack(0.2),attack(0.2),attack(0.2),attack(0.2),attack(0.2),attack(0.2) - 坎蒂丝 e(hold) - 雷泽 e(hold) - 钟离 e(hold) - 凝光 attack(0.4),attack(0.4),attack(0.4),attack(0.4) - 荒泷一斗 attack(0.4),attack(0.4),attack(0.4),attack(0.25) - 迪希雅 attack(0.4),attack(0.4),attack(0.4),attack(0.25) - 玛薇卡 attack(0.4),attack(0.4),attack(0.4),attack(0.25) - 基尼奇 attack(0.4),attack(0.4),attack(0.4),attack(0.25) - 娜维娅 attack(0.4),attack(0.4),attack(0.4),attack(0.25) - 菲米尼 attack(0.4),attack(0.4),attack(0.4),attack(0.25) - 迪卢克 attack(0.4),attack(0.4),attack(0.4),attack(0.25) - 诺艾尔 attack(0.4),attack(0.4),attack(0.4),attack(0.25) - 多莉 attack(0.4),attack(0.4),attack(0.4),attack(0.25) - 卡维 attack(0.4),attack(0.4),attack(0.4),attack(0.25) - 早柚 attack(0.4),attack(0.4),attack(0.4),attack(0.25) - 雷泽 attack(0.4),attack(0.4),attack(0.4),attack(0.25) - 优菈 attack(0.4),attack(0.4),attack(0.4),attack(0.25) - 嘉明 attack(0.4),attack(0.4),attack(0.4),attack(0.25) - 辛焱 attack(0.4),attack(0.4),attack(0.4),attack(0.25) - 重云 attack(0.4),attack(0.4),attack(0.4),attack(0.25) - 北斗 attack(0.4),attack(0.4),attack(0.4),attack(0.25) + 荒泷一斗 attack(1.5) + 迪希雅 attack(1.5) + 玛薇卡 attack(1.5) + 基尼奇 attack(1.5) + 娜维娅 attack(1.5) + 菲米尼 attack(1.5) + 迪卢克 attack(1.5) + 诺艾尔 attack(1.5) + 多莉 attack(1.5) + 卡维 attack(1.5) + 早柚 attack(1.5) + 雷泽 attack(1.5) + 优菈 attack(1.5) + 嘉明 attack(1.5) + 辛焱 attack(1.5) + 重云 attack(1.5) + 北斗 attack(1.5) + 卡齐娜 e(hold,wait),keydown(s),wait(0.4),keyup(s),attack(1.5) + 坎蒂丝 e(hold,wait) + 雷泽 e(hold,wait) + 钟离 e(hold,wait) + 凝光 attack(2.0) """); private readonly ScanPickTask _scanPickTask = new(); From 9db31c8d45727ff18db80239420740d96bd72611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B7=E4=B8=AA=E5=90=8D=E5=AD=97=E5=A5=BD=E9=9A=BE?= =?UTF-8?q?=E7=9A=84=E5=96=B5?= <25520958+MisakaAldrich@users.noreply.github.com> Date: Tue, 27 May 2025 14:33:01 +0800 Subject: [PATCH 06/25] =?UTF-8?q?fix:=20=E6=8C=96=E7=9F=BF=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E5=8D=A1=E9=BD=90=E5=A8=9C=EF=BC=8C=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=A4=A7=E5=89=91=E6=8C=96=E7=9F=BF=E6=94=BB=E5=87=BB=E6=97=B6?= =?UTF-8?q?=E9=97=B4=20(#1640)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AutoPathing/Handler/MiningHandler.cs | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/BetterGenshinImpact/GameTask/AutoPathing/Handler/MiningHandler.cs b/BetterGenshinImpact/GameTask/AutoPathing/Handler/MiningHandler.cs index 94665ec7..48898dc1 100644 --- a/BetterGenshinImpact/GameTask/AutoPathing/Handler/MiningHandler.cs +++ b/BetterGenshinImpact/GameTask/AutoPathing/Handler/MiningHandler.cs @@ -17,28 +17,27 @@ namespace BetterGenshinImpact.GameTask.AutoPathing.Handler; public class MiningHandler : IActionHandler { private readonly CombatScript _miningCombatScript = CombatScriptParser.ParseContext(""" - 荒泷一斗 attack(1.5) - 迪希雅 attack(1.5) - 玛薇卡 attack(1.5) - 基尼奇 attack(1.5) - 娜维娅 attack(1.5) - 菲米尼 attack(1.5) - 迪卢克 attack(1.5) - 诺艾尔 attack(1.5) - 多莉 attack(1.5) - 卡维 attack(1.5) - 早柚 attack(1.5) - 雷泽 attack(1.5) - 优菈 attack(1.5) - 嘉明 attack(1.5) - 辛焱 attack(1.5) - 重云 attack(1.5) - 北斗 attack(1.5) - 卡齐娜 e(hold,wait),keydown(s),wait(0.4),keyup(s),attack(1.5) + 荒泷一斗 attack(2.0) + 迪希雅 attack(2.0) + 玛薇卡 attack(2.0) + 基尼奇 attack(2.0) + 娜维娅 attack(2.0) + 菲米尼 attack(2.0) + 迪卢克 attack(2.0) + 诺艾尔 attack(2.0) + 卡维 attack(2.0) + 雷泽 attack(2.0) + 优菈 attack(2.0) + 嘉明 attack(2.0) + 辛焱 attack(2.0) + 重云 attack(2.0) + 多莉 attack(2.0) + 北斗 attack(2.5) + 早柚 attack(2.5) 坎蒂丝 e(hold,wait) 雷泽 e(hold,wait) 钟离 e(hold,wait) - 凝光 attack(2.0) + 凝光 attack(4.0) """); private readonly ScanPickTask _scanPickTask = new(); From 5fbd2e700bce0a8333f58e045075674715b9a94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89=E9=B8=AD=E8=9B=8B?= Date: Wed, 28 May 2025 23:47:30 +0800 Subject: [PATCH 07/25] =?UTF-8?q?#1628=20=E5=88=A0=E9=99=A4=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BetterGenshinImpact/GameTask/AutoFishing/Behaviours.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/BetterGenshinImpact/GameTask/AutoFishing/Behaviours.cs b/BetterGenshinImpact/GameTask/AutoFishing/Behaviours.cs index 8661f767..4d4a0e46 100644 --- a/BetterGenshinImpact/GameTask/AutoFishing/Behaviours.cs +++ b/BetterGenshinImpact/GameTask/AutoFishing/Behaviours.cs @@ -882,7 +882,6 @@ namespace BetterGenshinImpact.GameTask.AutoFishing _cursor = rects[1]; _target = rects[0]; } - logger.LogInformation($"识别到2个矩形,主:{_target}, 中:{_cursor}"); if (_target.Width < _cursor.Width * 10) // 异常:当目标矩形明显不够长时视为无效检测,不作为 { return BehaviourStatus.Running; From 48045aec2a578b80acc02857c5237ad9bc02768e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89=E9=B8=AD=E8=9B=8B?= Date: Thu, 29 May 2025 22:47:44 +0800 Subject: [PATCH 08/25] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=88=E6=88=90?= =?UTF-8?q?=E5=8F=B0=E6=89=93=E5=BC=80=E5=90=8E=EF=BC=8C=E7=AD=89=E5=BE=85?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E8=BF=87=E7=9F=AD=E5=AF=BC=E8=87=B4=E5=90=88?= =?UTF-8?q?=E6=88=90=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98=20BV1Sfj?= =?UTF-8?q?9z8ESG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GameTask/Common/Job/GoToCraftingBenchTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BetterGenshinImpact/GameTask/Common/Job/GoToCraftingBenchTask.cs b/BetterGenshinImpact/GameTask/Common/Job/GoToCraftingBenchTask.cs index d4670324..7a4b8397 100644 --- a/BetterGenshinImpact/GameTask/Common/Job/GoToCraftingBenchTask.cs +++ b/BetterGenshinImpact/GameTask/Common/Job/GoToCraftingBenchTask.cs @@ -83,7 +83,7 @@ public class GoToCraftingBenchTask await _chooseTalkOptionTask.SelectLastOptionUntilEnd(ct, region => region.Find(ElementAssets.Instance.BtnWhiteConfirm).IsExist() ); - await Delay(200, ct); + await Delay(800, ct); // 判断浓缩树脂是否存在 // TODO 满的情况是怎么样子的 From 2f148e06bfafa469135ffc96372e7d7b7afb802d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89=E9=B8=AD=E8=9B=8B?= Date: Sat, 31 May 2025 23:23:23 +0800 Subject: [PATCH 09/25] fix: update RunTask method to support nullable CancellationTokenSource and add linked cancellation token methods --- .../Core/Script/Dependence/Dispatcher.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs b/BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs index e5e1b19d..99b5026a 100644 --- a/BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs +++ b/BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs @@ -93,7 +93,7 @@ public class Dispatcher /// 自定义取消令牌源,允许从JS控制任务取消 /// /// - public async Task RunTask(SoloTask soloTask, System.Threading.CancellationTokenSource customCts = null) + public async Task RunTask(SoloTask soloTask, CancellationTokenSource? customCts = null) { if (soloTask == null) { @@ -107,7 +107,7 @@ public class Dispatcher } // 创建一个链接的取消令牌源,同时监听自定义令牌和全局令牌 - CancellationTokenSource linkedCts = null; + CancellationTokenSource? linkedCts = null; CancellationToken cancellationToken; if (customCts != null) @@ -171,4 +171,16 @@ public class Dispatcher linkedCts?.Dispose(); } } -} \ No newline at end of file + + public CancellationTokenSource GetLinkedCancellationTokenSource() + { + // 创建一个新的链接令牌源,链接到全局令牌 + return CancellationTokenSource.CreateLinkedTokenSource(CancellationContext.Instance.Cts.Token); + } + + + public CancellationToken GetLinkedCancellationToken() + { + return GetLinkedCancellationTokenSource().Token; + } +} From 119c294f0107aaebb0036f1663fcf0f4a77da8e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89=E9=B8=AD=E8=9B=8B?= Date: Sat, 31 May 2025 23:33:56 +0800 Subject: [PATCH 10/25] fix: enhance RunTask method to support nullable CancellationToken and add linked cancellation token functionality --- .../Core/Script/Dependence/Dispatcher.cs | 98 +++++++++---------- 1 file changed, 47 insertions(+), 51 deletions(-) diff --git a/BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs b/BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs index 99b5026a..9a281126 100644 --- a/BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs +++ b/BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs @@ -79,6 +79,15 @@ public class Dispatcher } } + public async Task RunTask(SoloTask soloTask, CancellationTokenSource customCts) + { + // 创建链接的取消令牌源,任何一个取消都会触发 + CancellationTokenSource linkedCts = CancellationTokenSource.CreateLinkedTokenSource( + customCts.Token, + CancellationContext.Instance.Cts.Token); + await RunTask(soloTask, linkedCts.Token); + } + /// /// 运行独立任务 @@ -90,10 +99,10 @@ public class Dispatcher /// - AutoFight: 启动自动战斗任务 /// - AutoDomain: 启动自动秘境任务 /// - /// 自定义取消令牌源,允许从JS控制任务取消 + /// 自定义取消令牌,允许从JS控制任务取消 /// /// - public async Task RunTask(SoloTask soloTask, CancellationTokenSource? customCts = null) + public async Task RunTask(SoloTask soloTask, CancellationToken? customCt = null) { if (soloTask == null) { @@ -106,69 +115,56 @@ public class Dispatcher throw new ArgumentNullException(nameof(taskSettingsPageViewModel), "内部视图模型对象为空"); } - // 创建一个链接的取消令牌源,同时监听自定义令牌和全局令牌 - CancellationTokenSource? linkedCts = null; + CancellationToken cancellationToken; - if (customCts != null) + if (customCt != null) { - // 创建链接的取消令牌源,任何一个取消都会触发 - linkedCts = CancellationTokenSource.CreateLinkedTokenSource( - customCts.Token, - CancellationContext.Instance.Cts.Token); - cancellationToken = linkedCts.Token; + cancellationToken = customCt.Value; } else { // 如果没有自定义令牌,就使用全局令牌 cancellationToken = CancellationContext.Instance.Cts.Token; } - - try + + // 根据名称执行任务 + switch (soloTask.Name) { - // 根据名称执行任务 - switch (soloTask.Name) - { - case "AutoGeniusInvokation": - if (taskSettingsPageViewModel.GetTcgStrategy(out var content)) - { - return; - } + case "AutoGeniusInvokation": + if (taskSettingsPageViewModel.GetTcgStrategy(out var content)) + { + return; + } - await new AutoGeniusInvokationTask(new GeniusInvokationTaskParam(content)).Start(cancellationToken); - break; + await new AutoGeniusInvokationTask(new GeniusInvokationTaskParam(content)).Start(cancellationToken); + break; - case "AutoWood": - await new AutoWoodTask(new WoodTaskParam(taskSettingsPageViewModel.AutoWoodRoundNum, - taskSettingsPageViewModel.AutoWoodDailyMaxCount)).Start(cancellationToken); - break; + case "AutoWood": + await new AutoWoodTask(new WoodTaskParam(taskSettingsPageViewModel.AutoWoodRoundNum, + taskSettingsPageViewModel.AutoWoodDailyMaxCount)).Start(cancellationToken); + break; - case "AutoFight": - await new AutoFightHandler().RunAsyncByScript(cancellationToken, null, _config); - break; + case "AutoFight": + await new AutoFightHandler().RunAsyncByScript(cancellationToken, null, _config); + break; - case "AutoDomain": - if (taskSettingsPageViewModel.GetFightStrategy(out var path)) - { - return; - } + case "AutoDomain": + if (taskSettingsPageViewModel.GetFightStrategy(out var path)) + { + return; + } - await new AutoDomainTask(new AutoDomainParam(0, path)).Start(cancellationToken); - break; + await new AutoDomainTask(new AutoDomainParam(0, path)).Start(cancellationToken); + break; - case "AutoFishing": - await new AutoFishingTask(AutoFishingTaskParam.BuildFromSoloTaskConfig(soloTask.Config)).Start( - cancellationToken); - break; + case "AutoFishing": + await new AutoFishingTask(AutoFishingTaskParam.BuildFromSoloTaskConfig(soloTask.Config)).Start( + cancellationToken); + break; - default: - throw new ArgumentException($"未知的任务名称: {soloTask.Name}", nameof(soloTask.Name)); - } - } - finally - { - // 释放链接的取消令牌源 - linkedCts?.Dispose(); + default: + throw new ArgumentException($"未知的任务名称: {soloTask.Name}", nameof(soloTask.Name)); } } @@ -177,10 +173,10 @@ public class Dispatcher // 创建一个新的链接令牌源,链接到全局令牌 return CancellationTokenSource.CreateLinkedTokenSource(CancellationContext.Instance.Cts.Token); } - - + + public CancellationToken GetLinkedCancellationToken() { return GetLinkedCancellationTokenSource().Token; } -} +} \ No newline at end of file From 57914bb661cc5213f152e186cc49cf82c9327502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89=E9=B8=AD=E8=9B=8B?= Date: Sat, 31 May 2025 23:55:14 +0800 Subject: [PATCH 11/25] =?UTF-8?q?=E5=BC=BA=E5=88=B6=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E5=8C=85=E7=89=88=E6=9C=AC=EF=BC=8C=E8=A7=A3=E5=86=B3Rider?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=A0=87=E7=BA=A2=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BetterGenshinImpact - Backup.csproj | 148 ------------------ .../BetterGenshinImpact.csproj | 2 +- .../Fischless.GameCapture.csproj | 1 + 3 files changed, 2 insertions(+), 149 deletions(-) delete mode 100644 BetterGenshinImpact/BetterGenshinImpact - Backup.csproj diff --git a/BetterGenshinImpact/BetterGenshinImpact - Backup.csproj b/BetterGenshinImpact/BetterGenshinImpact - Backup.csproj deleted file mode 100644 index 1bb2b60c..00000000 --- a/BetterGenshinImpact/BetterGenshinImpact - Backup.csproj +++ /dev/null @@ -1,148 +0,0 @@ - - - - WinExe - net8.0-windows10.0.22621.0 - enable - true - true - 12.0 - true - Assets\Images\logo.ico - BetterGI - 0.36.2 - x64 - embedded - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PreserveNewest - - - PreserveNewest - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - - - - - - - - \ No newline at end of file diff --git a/BetterGenshinImpact/BetterGenshinImpact.csproj b/BetterGenshinImpact/BetterGenshinImpact.csproj index 2a01904c..05c5b0bd 100644 --- a/BetterGenshinImpact/BetterGenshinImpact.csproj +++ b/BetterGenshinImpact/BetterGenshinImpact.csproj @@ -72,7 +72,7 @@ - + diff --git a/Fischless.GameCapture/Fischless.GameCapture.csproj b/Fischless.GameCapture/Fischless.GameCapture.csproj index 2e118352..eff51ae4 100644 --- a/Fischless.GameCapture/Fischless.GameCapture.csproj +++ b/Fischless.GameCapture/Fischless.GameCapture.csproj @@ -22,6 +22,7 @@ + \ No newline at end of file From 467fd6d9111d2a73fbfd9161830b459ea1f275e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89=E9=B8=AD=E8=9B=8B?= Date: Sun, 1 Jun 2025 00:18:52 +0800 Subject: [PATCH 12/25] =?UTF-8?q?=E7=81=B0=E5=BA=A6=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BetterGenshinImpact/Helpers/DeviceIdHelper.cs | 33 +++++++++++++++++++ BetterGenshinImpact/Model/Notice.cs | 4 ++- BetterGenshinImpact/Service/UpdateService.cs | 9 ++++- .../ViewModel/MainWindowViewModel.cs | 17 ++-------- 4 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 BetterGenshinImpact/Helpers/DeviceIdHelper.cs diff --git a/BetterGenshinImpact/Helpers/DeviceIdHelper.cs b/BetterGenshinImpact/Helpers/DeviceIdHelper.cs new file mode 100644 index 00000000..ede49a32 --- /dev/null +++ b/BetterGenshinImpact/Helpers/DeviceIdHelper.cs @@ -0,0 +1,33 @@ +using System; +using DeviceId; +using Microsoft.Extensions.Logging; + +namespace BetterGenshinImpact.Helpers; + +public class DeviceIdHelper +{ + private static readonly ILogger _logger = App.GetLogger(); + private static readonly Lazy _lazyDeviceId = new(InitializeDeviceId); + + public static string DeviceId => _lazyDeviceId.Value; + + private static string InitializeDeviceId() + { + try + { + return new DeviceIdBuilder() + .OnWindows(windows => windows + .AddMacAddressFromWmi(excludeWireless: true, excludeNonPhysical: true) + .AddProcessorId() + .AddMotherboardSerialNumber() + ) + .ToString(); + } + catch (Exception e) + { + _logger.LogDebug("获取设备ID异常:" + e.Source + "\r\n--" + Environment.NewLine + e.StackTrace + "\r\n---" + + Environment.NewLine + e.Message); + return string.Empty; + } + } +} \ No newline at end of file diff --git a/BetterGenshinImpact/Model/Notice.cs b/BetterGenshinImpact/Model/Notice.cs index f86d6b68..29bac704 100644 --- a/BetterGenshinImpact/Model/Notice.cs +++ b/BetterGenshinImpact/Model/Notice.cs @@ -3,4 +3,6 @@ public class Notice { public string Version { get; set; } = string.Empty; -} \ No newline at end of file + public int Gray { get; set; } = 10; +} + diff --git a/BetterGenshinImpact/Service/UpdateService.cs b/BetterGenshinImpact/Service/UpdateService.cs index aae45524..b4697a16 100644 --- a/BetterGenshinImpact/Service/UpdateService.cs +++ b/BetterGenshinImpact/Service/UpdateService.cs @@ -142,10 +142,17 @@ public class UpdateService : IUpdateService { using HttpClient httpClient = new(); Notice? notice = await httpClient.GetFromJsonAsync(NoticeUrl); + string deviceId = DeviceIdHelper.DeviceId; if (notice != null) { - return notice.Version; + // 灰度发布逻辑:deviceId做hash取余 + int hash = deviceId.GetHashCode(); + int mod = Math.Abs(hash % 10); + if (mod < notice.Gray) + { + return notice.Version; + } } } catch (Exception e) diff --git a/BetterGenshinImpact/ViewModel/MainWindowViewModel.cs b/BetterGenshinImpact/ViewModel/MainWindowViewModel.cs index b2b4067e..1e139318 100644 --- a/BetterGenshinImpact/ViewModel/MainWindowViewModel.cs +++ b/BetterGenshinImpact/ViewModel/MainWindowViewModel.cs @@ -288,21 +288,10 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel private void OnceRun() { - string deviceId = "default"; - try + string deviceId = DeviceIdHelper.DeviceId; + if (string.IsNullOrWhiteSpace(deviceId)) { - deviceId = new DeviceIdBuilder() - .OnWindows(windows => windows - .AddMacAddressFromWmi(excludeWireless: true, excludeNonPhysical: true) - .AddProcessorId() - .AddMotherboardSerialNumber() - ) - .ToString(); - } - catch (Exception e) - { - _logger.LogDebug("获取设备ID异常:" + e.Source + "\r\n--" + Environment.NewLine + e.StackTrace + "\r\n---" + - Environment.NewLine + e.Message); + deviceId = "default"; // 如果获取设备ID失败,使用默认值 } // 每个设备只运行一次 From eae02d6c137677631205a61ac28a126b8b2623df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89=E9=B8=AD=E8=9B=8B?= Date: Sun, 1 Jun 2025 01:31:04 +0800 Subject: [PATCH 13/25] feat: add update check functionality and enhance update options in UI --- .../Assets/Strings/md2html.html | 2 +- BetterGenshinImpact/Service/UpdateService.cs | 122 ++++++++++-------- .../View/Pages/CommonSettingsPage.xaml | 66 +++++++++- .../View/Windows/CheckUpdateWindow.xaml | 106 ++++++++++++++- 4 files changed, 233 insertions(+), 63 deletions(-) diff --git a/BetterGenshinImpact/Assets/Strings/md2html.html b/BetterGenshinImpact/Assets/Strings/md2html.html index 29d1d4a7..f559099d 100644 --- a/BetterGenshinImpact/Assets/Strings/md2html.html +++ b/BetterGenshinImpact/Assets/Strings/md2html.html @@ -33,7 +33,7 @@ } - +