mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-21 09:45:48 +08:00
walk to start domain
This commit is contained in:
@@ -29,4 +29,6 @@ public partial class HotKeyConfig : ObservableObject
|
||||
[ObservableProperty] private string _autoGeniusInvokation = "";
|
||||
|
||||
[ObservableProperty] private string _autoWoodHotkey = "";
|
||||
|
||||
[ObservableProperty] private string _autoDomainHotkey = "";
|
||||
}
|
||||
@@ -65,6 +65,12 @@ public class PostMessageSimulator
|
||||
return this;
|
||||
}
|
||||
|
||||
public PostMessageSimulator KeyDown(User32.VK vk)
|
||||
{
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PostMessageSimulator KeyUp(User32.VK vk)
|
||||
{
|
||||
User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001);
|
||||
|
||||
23
BetterGenshinImpact/GameTask/AutoDomain/AutoDomainParam.cs
Normal file
23
BetterGenshinImpact/GameTask/AutoDomain/AutoDomainParam.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using BetterGenshinImpact.GameTask.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoDomain;
|
||||
|
||||
public class AutoDomainParam : BaseTaskParam
|
||||
{
|
||||
|
||||
public int DomainRoundNum { get; set; }
|
||||
public AutoDomainParam(CancellationTokenSource cts, int domainRoundNum) : base(cts)
|
||||
{
|
||||
DomainRoundNum = domainRoundNum;
|
||||
if (domainRoundNum == 0)
|
||||
{
|
||||
DomainRoundNum = 9999;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,83 @@
|
||||
using System;
|
||||
using BetterGenshinImpact.GameTask.AutoSkip.Assets;
|
||||
using BetterGenshinImpact.View.Drawable;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Simulator;
|
||||
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
|
||||
using BetterGenshinImpact.GameTask.AutoWood.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Vanara.PInvoke;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
using BetterGenshinImpact.GameTask.AutoPick.Assets;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using static Vanara.PInvoke.User32;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoDomain;
|
||||
|
||||
public class AutoDomainTask
|
||||
{
|
||||
private readonly AutoPickAssets _autoPickAssets = new();
|
||||
|
||||
private AutoDomainParam _taskParam;
|
||||
|
||||
private readonly PostMessageSimulator _postMessage;
|
||||
|
||||
public AutoDomainTask(AutoDomainParam taskParam)
|
||||
{
|
||||
_taskParam = taskParam;
|
||||
_postMessage = Simulation.PostMessage(TaskContext.Instance().GameHandle);
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
try
|
||||
{
|
||||
Logger.LogInformation("→ {Text} 设置总次数:{Cnt}", "自动秘境,启动!", _taskParam.DomainRoundNum);
|
||||
SystemControl.ActivateWindow();
|
||||
// 1. 走到钥匙处启动
|
||||
WalkToStartDomain();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogInformation(e.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
VisionContext.Instance().DrawContent.ClearAll();
|
||||
TaskTriggerDispatcher.Instance().StartTimer();
|
||||
}
|
||||
}
|
||||
|
||||
private async void WalkToStartDomain()
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
_postMessage.KeyDown(VK.VK_W);
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var content = CaptureToContent();
|
||||
var fRectArea = content.CaptureRectArea.Find(_autoPickAssets.FRo);
|
||||
if (fRectArea.IsEmpty())
|
||||
{
|
||||
Sleep(100, _taskParam.Cts);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogInformation("检测到F,启动秘境");
|
||||
Simulation.SendInputEx.Keyboard.KeyPress(VK.VK_F);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_postMessage.KeyUp(VK.VK_W);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class TaskControl
|
||||
{
|
||||
if (cts.IsCancellationRequested)
|
||||
{
|
||||
throw new NormalEndException("取消自动伐木任务");
|
||||
throw new NormalEndException("取消自动任务");
|
||||
}
|
||||
if (millisecondsTimeout <= 0)
|
||||
{
|
||||
@@ -51,7 +51,7 @@ public class TaskControl
|
||||
{
|
||||
if (cts.IsCancellationRequested)
|
||||
{
|
||||
throw new NormalEndException("取消自动伐木任务");
|
||||
throw new NormalEndException("取消自动任务");
|
||||
}
|
||||
if (!SystemControl.IsGenshinImpactActiveByProcess())
|
||||
{
|
||||
@@ -62,7 +62,7 @@ public class TaskControl
|
||||
Thread.Sleep(millisecondsTimeout);
|
||||
if (cts.IsCancellationRequested)
|
||||
{
|
||||
throw new NormalEndException("取消自动伐木任务");
|
||||
throw new NormalEndException("取消自动任务");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,5 @@ public enum IndependentTaskEnum
|
||||
|
||||
AutoGeniusInvokation,
|
||||
AutoWood,
|
||||
AutoDomain,
|
||||
}
|
||||
@@ -13,6 +13,7 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using BetterGenshinImpact.GameTask.AutoDomain;
|
||||
using Vanara.PInvoke;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask
|
||||
@@ -43,14 +44,21 @@ namespace BetterGenshinImpact.GameTask
|
||||
//_timer.Tick += Tick;
|
||||
}
|
||||
|
||||
public static TaskTriggerDispatcher Instance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
throw new Exception("请先在启动页启动BetterGI,如果已经启动请重启");
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public static IGameCapture GlobalGameCapture
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
throw new Exception("请先在启动页启动BetterGI,如果已经启动请重启");
|
||||
}
|
||||
_instance = Instance();
|
||||
|
||||
if (_instance.GameCapture == null)
|
||||
{
|
||||
@@ -168,6 +176,10 @@ namespace BetterGenshinImpact.GameTask
|
||||
{
|
||||
Task.Run(() => { new AutoWoodTask().Start((WoodTaskParam)param); });
|
||||
}
|
||||
else if (taskType == IndependentTaskEnum.AutoDomain)
|
||||
{
|
||||
Task.Run(() => { new AutoDomainTask((AutoDomainParam)param).Start(); });
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() => Stop();
|
||||
|
||||
@@ -260,6 +260,97 @@
|
||||
</StackPanel>
|
||||
</ui:CardExpander>
|
||||
|
||||
<ui:CardExpander Margin="0,0,0,12"
|
||||
ContentPadding="0"
|
||||
Icon="{ui:SymbolIcon Dumbbell24}">
|
||||
<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="自动秘境"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
TextWrapping="Wrap">
|
||||
自动刷秘境 -
|
||||
<Hyperlink Command="{Binding GoToAutoWoodUrlCommand}" Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}">
|
||||
点击查看使用教程
|
||||
</Hyperlink>
|
||||
</ui:TextBlock>
|
||||
<ui:Button Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,24,0"
|
||||
Command="{Binding SwitchAutoDomainCommand}"
|
||||
Content="{Binding SwitchAutoDomainButtonText}" />
|
||||
</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="循环秘境多少次,输入 0 则为用光所有树脂为止,优先使用浓缩树脂"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBox Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
MinWidth="90"
|
||||
Margin="0,0,36,0"
|
||||
Text="{Binding AutoDomainRoundNum, 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="暂时无用"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBox Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
MinWidth="90"
|
||||
Margin="0,0,36,0"
|
||||
Text="{Binding Config.AutoWoodConfig.AfterZSleepDelay, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ui:CardExpander>
|
||||
|
||||
<!--<ui:CardExpander Margin="0,0,0,12" ContentPadding="0" Icon="{ui:SymbolIcon Accessibility24}">
|
||||
<ui:CardExpander.Header>
|
||||
<Grid>
|
||||
|
||||
@@ -149,6 +149,13 @@ public partial class HotKeyPageViewModel : ObservableObject
|
||||
Config.HotKeyConfig.AutoWoodHotkey,
|
||||
(_, _) => { _taskSettingsPageViewModel.OnSwitchAutoWood(); }
|
||||
));
|
||||
|
||||
HotKeySettingModels.Add(new HotKeySettingModel(
|
||||
"启动/停止自动秘境",
|
||||
nameof(Config.HotKeyConfig.AutoDomainHotkey),
|
||||
Config.HotKeyConfig.AutoDomainHotkey,
|
||||
(_, _) => { _taskSettingsPageViewModel.OnSwitchAutoDomain(); }
|
||||
));
|
||||
}
|
||||
|
||||
private string ToChinese(bool enabled)
|
||||
|
||||
@@ -9,6 +9,7 @@ using CommunityToolkit.Mvvm.Input;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using BetterGenshinImpact.GameTask.AutoDomain;
|
||||
using BetterGenshinImpact.GameTask.AutoWood;
|
||||
using Wpf.Ui;
|
||||
using Wpf.Ui.Controls;
|
||||
@@ -32,6 +33,9 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
|
||||
[ObservableProperty] private int _autoWoodRoundNum;
|
||||
[ObservableProperty] private string _switchAutoWoodButtonText;
|
||||
|
||||
[ObservableProperty] private int _autoDomainRoundNum;
|
||||
[ObservableProperty] private string _switchAutoDomainButtonText = "启动";
|
||||
|
||||
|
||||
public TaskSettingsPageViewModel(IConfigService configService, INavigationService navigationService, TaskTriggerDispatcher taskTriggerDispatcher)
|
||||
{
|
||||
@@ -43,7 +47,6 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
|
||||
_switchAutoGeniusInvokationButtonText = "启动";
|
||||
|
||||
_switchAutoWoodButtonText = "启动";
|
||||
|
||||
}
|
||||
|
||||
private string[] LoadCustomScript()
|
||||
@@ -100,6 +103,7 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
|
||||
}
|
||||
|
||||
var content = File.ReadAllText(path);
|
||||
_cts?.Cancel();
|
||||
_cts = new CancellationTokenSource();
|
||||
var param = new GeniusInvokationTaskParam(_cts, _taskDispatcher, content);
|
||||
_taskDispatcher.StartIndependentTask(IndependentTaskEnum.AutoGeniusInvokation, param);
|
||||
@@ -130,6 +134,7 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
|
||||
{
|
||||
if (SwitchAutoWoodButtonText == "启动")
|
||||
{
|
||||
_cts?.Cancel();
|
||||
_cts = new CancellationTokenSource();
|
||||
var param = new WoodTaskParam(_cts, _taskDispatcher, AutoWoodRoundNum);
|
||||
_taskDispatcher.StartIndependentTask(IndependentTaskEnum.AutoWood, param);
|
||||
@@ -153,6 +158,40 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
|
||||
Process.Start(new ProcessStartInfo("https://bgi.huiyadan.com/doc.html#%E8%87%AA%E5%8A%A8%E4%BC%90%E6%9C%A8") { UseShellExecute = true });
|
||||
}
|
||||
|
||||
|
||||
[RelayCommand]
|
||||
public void OnSwitchAutoDomain()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (SwitchAutoDomainButtonText == "启动")
|
||||
{
|
||||
_cts?.Cancel();
|
||||
_cts = new CancellationTokenSource();
|
||||
var param = new AutoDomainParam(_cts, AutoWoodRoundNum);
|
||||
_taskDispatcher.StartIndependentTask(IndependentTaskEnum.AutoDomain, param);
|
||||
SwitchAutoDomainButtonText = "停止";
|
||||
}
|
||||
else
|
||||
{
|
||||
_cts?.Cancel();
|
||||
SwitchAutoDomainButtonText = "启动";
|
||||
}
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void OnGoToAutoDomainUrl()
|
||||
{
|
||||
Process.Start(new ProcessStartInfo("https://bgi.huiyadan.com/doc.html#%E8%87%AA%E5%8A%A8%E4%BC%90%E6%9C%A8") { UseShellExecute = true });
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void SetSwitchAutoGeniusInvokationButtonText(bool running)
|
||||
{
|
||||
var instance = App.GetService<TaskSettingsPageViewModel>();
|
||||
|
||||
Reference in New Issue
Block a user