using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.Core.Script; using BetterGenshinImpact.GameTask; using BetterGenshinImpact.GameTask.AutoDomain; using BetterGenshinImpact.GameTask.AutoFight; using BetterGenshinImpact.GameTask.AutoGeniusInvokation; using BetterGenshinImpact.GameTask.AutoMusicGame; using BetterGenshinImpact.GameTask.AutoSkip.Model; using BetterGenshinImpact.GameTask.AutoTrackPath; using BetterGenshinImpact.GameTask.AutoWood; using BetterGenshinImpact.GameTask.Model; using BetterGenshinImpact.Service.Interface; using BetterGenshinImpact.View.Pages; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Threading; using System.Threading.Tasks; using Windows.System; using BetterGenshinImpact.GameTask.Common.Element.Assets; using BetterGenshinImpact.GameTask.Model.Enum; using Wpf.Ui; using Wpf.Ui.Controls; using Wpf.Ui.Violeta.Controls; using BetterGenshinImpact.ViewModel.Pages.View; namespace BetterGenshinImpact.ViewModel.Pages; public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAware, IViewModel { public AllConfig Config { get; set; } private readonly INavigationService _navigationService; private readonly TaskTriggerDispatcher _taskDispatcher; private CancellationTokenSource? _cts; private static readonly object _locker = new(); // [ObservableProperty] // private string[] _strategyList; [ObservableProperty] private bool _switchAutoGeniusInvokationEnabled; [ObservableProperty] private string _switchAutoGeniusInvokationButtonText = "启动"; [ObservableProperty] private int _autoWoodRoundNum; [ObservableProperty] private int _autoWoodDailyMaxCount = 2000; [ObservableProperty] private bool _switchAutoWoodEnabled; [ObservableProperty] private string _switchAutoWoodButtonText = "启动"; //[ObservableProperty] //private string[] _combatStrategyList; [ObservableProperty] private int _autoDomainRoundNum; [ObservableProperty] private bool _switchAutoDomainEnabled; [ObservableProperty] private string _switchAutoDomainButtonText = "启动"; [ObservableProperty] private bool _switchAutoFightEnabled; [ObservableProperty] private string _switchAutoFightButtonText = "启动"; [ObservableProperty] private string _switchAutoTrackButtonText = "启动"; [ObservableProperty] private string _switchAutoTrackPathButtonText = "启动"; [ObservableProperty] private bool _switchAutoMusicGameEnabled; [ObservableProperty] private string _switchAutoMusicGameButtonText = "启动"; [ObservableProperty] private List _domainNameList; [ObservableProperty] private List _artifactSalvageStarList = ["4", "3", "2", "1"]; [ObservableProperty] private AutoFightViewModel? _autoFightViewModel; public TaskSettingsPageViewModel(IConfigService configService, INavigationService navigationService, TaskTriggerDispatcher taskTriggerDispatcher) { Config = configService.Get(); _navigationService = navigationService; _taskDispatcher = taskTriggerDispatcher; //_strategyList = LoadCustomScript(Global.Absolute(@"User\AutoGeniusInvokation")); //_combatStrategyList = ["根据队伍自动选择", .. LoadCustomScript(Global.Absolute(@"User\AutoFight"))]; _domainNameList = MapLazyAssets.Instance.DomainNameList; _autoFightViewModel=new AutoFightViewModel(Config); } [RelayCommand] private async Task OnStopSoloTask() { CancellationContext.Instance.Cancel(); SwitchAutoGeniusInvokationEnabled = false; SwitchAutoWoodEnabled = false; SwitchAutoDomainEnabled = false; SwitchAutoFightEnabled = false; SwitchAutoMusicGameEnabled = false; await Task.Delay(800); } [RelayCommand] private void OnStrategyDropDownOpened(string type) { _autoFightViewModel.OnStrategyDropDownOpened(type); } public void OnNavigatedTo() { } public void OnNavigatedFrom() { } [RelayCommand] public void OnGoToHotKeyPage() { _navigationService.Navigate(typeof(HotKeyPage)); } [RelayCommand] public async Task OnSwitchAutoGeniusInvokation() { if (GetTcgStrategy(out var content)) { return; } SwitchAutoGeniusInvokationEnabled = true; await new TaskRunner(DispatcherTimerOperationEnum.UseSelfCaptureImage) .RunSoloTaskAsync(new AutoGeniusInvokationTask(new GeniusInvokationTaskParam(content))); SwitchAutoGeniusInvokationEnabled = false; } public bool GetTcgStrategy(out string content) { content = string.Empty; if (string.IsNullOrEmpty(Config.AutoGeniusInvokationConfig.StrategyName)) { Toast.Warning("请先选择策略"); return true; } var path = Global.Absolute(@"User\AutoGeniusInvokation\" + Config.AutoGeniusInvokationConfig.StrategyName + ".txt"); if (!File.Exists(path)) { Toast.Error("策略文件不存在"); return true; } content = File.ReadAllText(path); return false; } [RelayCommand] public async Task OnGoToAutoGeniusInvokationUrlAsync() { await Launcher.LaunchUriAsync(new Uri("https://bgi.huiyadan.com/feats/task/tcg.html")); } [RelayCommand] public async Task OnSwitchAutoWood() { SwitchAutoWoodEnabled = true; await new TaskRunner(DispatcherTimerOperationEnum.UseSelfCaptureImage) .RunSoloTaskAsync(new AutoWoodTask(new WoodTaskParam(AutoWoodRoundNum, AutoWoodDailyMaxCount))); SwitchAutoWoodEnabled = false; } [RelayCommand] public async Task OnGoToAutoWoodUrlAsync() { await Launcher.LaunchUriAsync(new Uri("https://bgi.huiyadan.com/feats/task/felling.html")); } [RelayCommand] public async Task OnSwitchAutoFight() { if (GetFightStrategy(out var path)) { return; } var param = new AutoFightParam(path, Config.AutoFightConfig); SwitchAutoFightEnabled = true; await new TaskRunner(DispatcherTimerOperationEnum.UseCacheImageWithTrigger) .RunSoloTaskAsync(new AutoFightTask(param)); SwitchAutoFightEnabled = false; } [RelayCommand] public async Task OnGoToAutoFightUrlAsync() { await Launcher.LaunchUriAsync(new Uri("https://bgi.huiyadan.com/feats/task/domain.html")); } [RelayCommand] public async Task OnSwitchAutoDomain() { if (GetFightStrategy(out var path)) { return; } SwitchAutoDomainEnabled = true; await new TaskRunner(DispatcherTimerOperationEnum.UseCacheImage) .RunSoloTaskAsync(new AutoDomainTask(new AutoDomainParam(AutoDomainRoundNum, path))); SwitchAutoDomainEnabled = false; } public bool GetFightStrategy(out string path) { path = Global.Absolute(@"User\AutoFight\" + Config.AutoFightConfig.StrategyName + ".txt"); if ("根据队伍自动选择".Equals(Config.AutoFightConfig.StrategyName)) { path = Global.Absolute(@"User\AutoFight\"); } if (!File.Exists(path) && !Directory.Exists(path)) { Toast.Error("战斗策略文件不存在"); return true; } return false; } [RelayCommand] public async Task OnGoToAutoDomainUrlAsync() { await Launcher.LaunchUriAsync(new Uri("https://bgi.huiyadan.com/feats/task/domain.html")); } [RelayCommand] public void OnOpenFightFolder() { _autoFightViewModel?.OnOpenFightFolder(); } [Obsolete] [RelayCommand] public void OnSwitchAutoTrack() { // try // { // lock (_locker) // { // if (SwitchAutoTrackButtonText == "启动") // { // _cts?.Cancel(); // _cts = new CancellationTokenSource(); // var param = new AutoTrackParam(_cts); // _taskDispatcher.StartIndependentTask(IndependentTaskEnum.AutoTrack, param); // SwitchAutoTrackButtonText = "停止"; // } // else // { // _cts?.Cancel(); // SwitchAutoTrackButtonText = "启动"; // } // } // } // catch (Exception ex) // { // MessageBox.Error(ex.Message); // } } [RelayCommand] public async Task OnGoToAutoTrackUrlAsync() { await Launcher.LaunchUriAsync(new Uri("https://bgi.huiyadan.com/feats/task/track.html")); } [Obsolete] [RelayCommand] public void OnSwitchAutoTrackPath() { // try // { // lock (_locker) // { // if (SwitchAutoTrackPathButtonText == "启动") // { // _cts?.Cancel(); // _cts = new CancellationTokenSource(); // var param = new AutoTrackPathParam(_cts); // _taskDispatcher.StartIndependentTask(IndependentTaskEnum.AutoTrackPath, param); // SwitchAutoTrackPathButtonText = "停止"; // } // else // { // _cts?.Cancel(); // SwitchAutoTrackPathButtonText = "启动"; // } // } // } // catch (Exception ex) // { // MessageBox.Error(ex.Message); // } } [RelayCommand] public async Task OnGoToAutoTrackPathUrlAsync() { await Launcher.LaunchUriAsync(new Uri("https://bgi.huiyadan.com/feats/task/track.html")); } [RelayCommand] public async Task OnSwitchAutoMusicGame() { SwitchAutoMusicGameEnabled = true; await new TaskRunner(DispatcherTimerOperationEnum.UseSelfCaptureImage) .RunSoloTaskAsync(new AutoMusicGameTask(new AutoMusicGameParam())); SwitchAutoMusicGameEnabled = false; } [RelayCommand] public async Task OnGoToAutoMusicGameUrlAsync() { await Launcher.LaunchUriAsync(new Uri("https://bgi.huiyadan.com/feats/task/music.html")); } [RelayCommand] public void OnOpenLocalScriptRepo() { _autoFightViewModel.OnOpenLocalScriptRepo(); } }