mirror of
https://github.com/babalae/better-genshin-impact
synced 2025-01-07 03:17:16 +08:00
impl js run task
This commit is contained in:
parent
a1cdf15c7e
commit
4725af5491
@ -4,6 +4,10 @@ using BetterGenshinImpact.ViewModel.Pages;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.GameTask.AutoDomain;
|
||||
using BetterGenshinImpact.GameTask.AutoFight;
|
||||
using BetterGenshinImpact.GameTask.AutoWood;
|
||||
using BetterGenshinImpact.GameTask.Model.Enum;
|
||||
using BetterGenshinImpact.GameTask.AutoGeniusInvokation;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Script.Dependence;
|
||||
|
||||
@ -61,15 +65,29 @@ public class Dispatcher
|
||||
switch (soloTask.Name)
|
||||
{
|
||||
case "AutoGeniusInvokation":
|
||||
taskSettingsPageViewModel.SwitchAutoGeniusInvokationCommand.Execute(null);
|
||||
if (taskSettingsPageViewModel.GetTcgStrategy(out var content))
|
||||
{
|
||||
return;
|
||||
}
|
||||
await new AutoGeniusInvokationTask(new GeniusInvokationTaskParam(content)).Start(CancellationContext.Instance.Cts.Token);
|
||||
break;
|
||||
|
||||
case "AutoWood":
|
||||
taskSettingsPageViewModel.SwitchAutoWoodCommand.Execute(null);
|
||||
await new AutoWoodTask(new WoodTaskParam(taskSettingsPageViewModel.AutoWoodRoundNum, taskSettingsPageViewModel.AutoWoodDailyMaxCount)).Start(CancellationContext.Instance.Cts.Token);
|
||||
break;
|
||||
|
||||
case "AutoFight":
|
||||
taskSettingsPageViewModel.SwitchAutoFightCommand.Execute(null);
|
||||
if (taskSettingsPageViewModel.GetFightStrategy(out var path1))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var autoFightConfig = TaskContext.Instance().Config.AutoFightConfig;
|
||||
var param = new AutoFightParam(path1)
|
||||
{
|
||||
FightFinishDetectEnabled = autoFightConfig.FightFinishDetectEnabled,
|
||||
PickDropsAfterFightEnabled = autoFightConfig.PickDropsAfterFightEnabled
|
||||
};
|
||||
await new AutoFightTask(param).Start(CancellationContext.Instance.Cts.Token);
|
||||
break;
|
||||
|
||||
case "AutoDomain":
|
||||
@ -80,9 +98,9 @@ public class Dispatcher
|
||||
await new AutoDomainTask(new AutoDomainParam(0, path)).Start(CancellationContext.Instance.Cts.Token);
|
||||
break;
|
||||
|
||||
case "AutoMusicGame":
|
||||
taskSettingsPageViewModel.SwitchAutoMusicGameCommand.Execute(null);
|
||||
break;
|
||||
// case "AutoMusicGame":
|
||||
// taskSettingsPageViewModel.SwitchAutoMusicGameCommand.Execute(null);
|
||||
// break;
|
||||
|
||||
default:
|
||||
throw new ArgumentException($"未知的任务名称: {soloTask.Name}", nameof(soloTask.Name));
|
||||
|
@ -36,24 +36,53 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
|
||||
private CancellationTokenSource? _cts;
|
||||
private static readonly object _locker = new();
|
||||
|
||||
[ObservableProperty] private string[] _strategyList;
|
||||
[ObservableProperty] private bool _switchAutoGeniusInvokationEnabled;
|
||||
[ObservableProperty] private string _switchAutoGeniusInvokationButtonText = "启动";
|
||||
[ObservableProperty]
|
||||
private string[] _strategyList;
|
||||
|
||||
[ObservableProperty] private int _autoWoodRoundNum;
|
||||
[ObservableProperty] private int _autoWoodDailyMaxCount = 2000;
|
||||
[ObservableProperty] private bool _switchAutoWoodEnabled;
|
||||
[ObservableProperty] private string _switchAutoWoodButtonText = "启动";
|
||||
[ObservableProperty]
|
||||
private bool _switchAutoGeniusInvokationEnabled;
|
||||
|
||||
[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 string _switchAutoMusicGameButtonText = "启动";
|
||||
[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 string _switchAutoMusicGameButtonText = "启动";
|
||||
|
||||
public TaskSettingsPageViewModel(IConfigService configService, INavigationService navigationService, TaskTriggerDispatcher taskTriggerDispatcher)
|
||||
{
|
||||
@ -81,6 +110,7 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
|
||||
{
|
||||
strategyName = strategyName[1..];
|
||||
}
|
||||
|
||||
strategyList[i] = strategyName;
|
||||
}
|
||||
}
|
||||
@ -131,10 +161,24 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
|
||||
[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;
|
||||
return true;
|
||||
}
|
||||
|
||||
var path = Global.Absolute(@"User\AutoGeniusInvokation\" + Config.AutoGeniusInvokationConfig.StrategyName + ".txt");
|
||||
@ -142,15 +186,11 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
Toast.Error("策略文件不存在");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
var content = await File.ReadAllTextAsync(path);
|
||||
|
||||
SwitchAutoGeniusInvokationEnabled = true;
|
||||
await new TaskRunner(DispatcherTimerOperationEnum.UseSelfCaptureImage)
|
||||
.RunSoloTaskAsync(new AutoGeniusInvokationTask(new GeniusInvokationTaskParam(content)));
|
||||
SwitchAutoGeniusInvokationEnabled = false;
|
||||
content = File.ReadAllText(path);
|
||||
return false;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@ -207,6 +247,7 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SwitchAutoDomainEnabled = true;
|
||||
await new TaskRunner(DispatcherTimerOperationEnum.UseCacheImage)
|
||||
.RunSoloTaskAsync(new AutoDomainTask(new AutoDomainParam(AutoDomainRoundNum, path)));
|
||||
@ -220,6 +261,7 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
|
||||
{
|
||||
path = Global.Absolute(@"User\AutoFight\");
|
||||
}
|
||||
|
||||
if (!File.Exists(path) && !Directory.Exists(path))
|
||||
{
|
||||
Toast.Error("战斗策略文件不存在");
|
||||
|
Loading…
Reference in New Issue
Block a user