mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-04-05 11:25:20 +08:00
* 记录一次对hutaofisher的访谈,帮助开发者理解其算法
* 本地化HelloWorld
* .csproj取消windows版本号,此处导致了IDE在新建代码文件和自动生成代码时,默认命名空间丢失的问题。已知VisualStudio和ReSharper存在这个问题。
* 优化扩展方法写法,改为从localizer扩展;Converter优化写法,避免冲突;新增两种语言,待测试ocr效果
* Revert ".csproj取消windows版本号,此处导致了IDE在新建代码文件和自动生成代码时,默认命名空间丢失的问题。已知VisualStudio和ReSharper存在这个问题。"
This reverts commit 8bd7ee74c5.
* localizer改为由构造函数传入以支持单元测试;一个英语上钩的单元测试
* 传送任务支持英语游戏界面;本地化参数挪至OtherConfig类下,但界面位置暂不挪动,待定
* 调整resx位置风格,放在直接使用字符串的类下;一条龙合成树脂及领取每日奖励支持游戏内中英双语
* 删除无用碎片文件
* 删去两个不必要的Sdcb包引用
* Paddle服务类去掉分类模型;检测和识别新增支持繁中和法语,配有单元测试;因小语种识别效果不理想,使用正则匹配替换多处识别文本相等或包含判断;钓鱼、一条龙合成树脂及领取每日奖励支持游戏内繁中和法语;
* 检查今日奖励任务的多语言化;右侧联机的P图标检测区域宽度缩减,避免英语角色名被误识别成P
* AutoDomainTask的游戏多语言化,由于我的游戏账号无法测试,仅配一些测试用例
* 修复有3个Mizuki导致异常的bug,临时用拼音代替新角色英文名,并为该数据初始化方法添加单元测试
* 瓦雷莎删去别名“牛牛”,因荒泷一斗已占用此别名;别名加载和读取优化
* 加个锁避免单元测试中多线程初始化paddle崩溃
443 lines
13 KiB
C#
443 lines
13 KiB
C#
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.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Windows.System;
|
|
using BetterGenshinImpact.GameTask.AutoFishing;
|
|
using BetterGenshinImpact.GameTask.Common.Element.Assets;
|
|
|
|
using BetterGenshinImpact.Helpers;
|
|
using Wpf.Ui;
|
|
using Wpf.Ui.Controls;
|
|
using Wpf.Ui.Violeta.Controls;
|
|
using BetterGenshinImpact.ViewModel.Pages.View;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using Vanara.Extensions;
|
|
using System.Collections.Frozen;
|
|
using System.Globalization;
|
|
using Microsoft.Extensions.Localization;
|
|
using BetterGenshinImpact.View.Converters;
|
|
using BetterGenshinImpact.Core.Recognition.OCR;
|
|
|
|
namespace BetterGenshinImpact.ViewModel.Pages;
|
|
|
|
public partial class TaskSettingsPageViewModel : ViewModel
|
|
{
|
|
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 bool _switchAutoAlbumEnabled;
|
|
|
|
[ObservableProperty]
|
|
private string _switchAutoAlbumButtonText = "启动";
|
|
|
|
[ObservableProperty]
|
|
private List<string> _domainNameList;
|
|
|
|
public static List<string> ArtifactSalvageStarList = ["4", "3", "2", "1"];
|
|
|
|
[ObservableProperty]
|
|
private List<string> _autoMusicLevelList = ["传说", "大师", "困难", "普通", "所有"];
|
|
|
|
[ObservableProperty]
|
|
private AutoFightViewModel? _autoFightViewModel;
|
|
|
|
[ObservableProperty]
|
|
private bool _switchAutoFishingEnabled;
|
|
|
|
[ObservableProperty]
|
|
private string _switchAutoFishingButtonText = "启动";
|
|
|
|
[ObservableProperty]
|
|
private FrozenDictionary<Enum, string> _fishingTimePolicyDict = Enum.GetValues(typeof(FishingTimePolicy))
|
|
.Cast<FishingTimePolicy>()
|
|
.ToFrozenDictionary(
|
|
e => (Enum)e,
|
|
e => e.GetType()
|
|
.GetField(e.ToString())?
|
|
.GetCustomAttribute<DescriptionAttribute>()?
|
|
.Description ?? e.ToString());
|
|
|
|
[ObservableProperty]
|
|
private FrozenDictionary<string, string> _languageDict = new string[] { "zh-Hans", "zh-Hant", "en", "fr" }
|
|
.ToFrozenDictionary(
|
|
c => c,
|
|
c =>
|
|
{
|
|
CultureInfo.CurrentUICulture = new CultureInfo(c);
|
|
var stringLocalizer = App.GetService<IStringLocalizer<CultureInfoNameToKVPConverter>>() ?? throw new NullReferenceException();
|
|
return stringLocalizer["简体中文"].ToString();
|
|
}
|
|
);
|
|
|
|
private bool saveScreenshotOnKeyTick;
|
|
public bool SaveScreenshotOnKeyTick
|
|
{
|
|
get => Config.CommonConfig.ScreenshotEnabled && saveScreenshotOnKeyTick;
|
|
set => SetProperty(ref saveScreenshotOnKeyTick, value);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void OnGoToHotKeyPage()
|
|
{
|
|
_navigationService.Navigate(typeof(HotKeyPage));
|
|
}
|
|
|
|
[RelayCommand]
|
|
public async Task OnSwitchAutoGeniusInvokation()
|
|
{
|
|
if (GetTcgStrategy(out var content))
|
|
{
|
|
return;
|
|
}
|
|
|
|
SwitchAutoGeniusInvokationEnabled = true;
|
|
await new TaskRunner()
|
|
.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://bettergi.com/feats/task/tcg.html"));
|
|
}
|
|
|
|
[RelayCommand]
|
|
public async Task OnSwitchAutoWood()
|
|
{
|
|
SwitchAutoWoodEnabled = true;
|
|
await new TaskRunner()
|
|
.RunSoloTaskAsync(new AutoWoodTask(new WoodTaskParam(AutoWoodRoundNum, AutoWoodDailyMaxCount)));
|
|
SwitchAutoWoodEnabled = false;
|
|
}
|
|
|
|
[RelayCommand]
|
|
public async Task OnGoToAutoWoodUrlAsync()
|
|
{
|
|
await Launcher.LaunchUriAsync(new Uri("https://bettergi.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()
|
|
.RunSoloTaskAsync(new AutoFightTask(param));
|
|
SwitchAutoFightEnabled = false;
|
|
}
|
|
|
|
[RelayCommand]
|
|
public async Task OnGoToAutoFightUrlAsync()
|
|
{
|
|
await Launcher.LaunchUriAsync(new Uri("https://bettergi.com/feats/task/domain.html"));
|
|
}
|
|
|
|
[RelayCommand]
|
|
public async Task OnSwitchAutoDomain()
|
|
{
|
|
if (GetFightStrategy(out var path))
|
|
{
|
|
return;
|
|
}
|
|
|
|
SwitchAutoDomainEnabled = true;
|
|
await new TaskRunner()
|
|
.RunSoloTaskAsync(new AutoDomainTask(new AutoDomainParam(AutoDomainRoundNum, path)));
|
|
SwitchAutoDomainEnabled = false;
|
|
}
|
|
|
|
public bool GetFightStrategy(out string path)
|
|
{
|
|
if (string.IsNullOrEmpty(Config.AutoFightConfig.StrategyName))
|
|
{
|
|
UIDispatcherHelper.Invoke(() => { Toast.Warning("请先在【独立任务——自动战斗】下拉列表配置中选择战斗策略!"); });
|
|
path = string.Empty;
|
|
return true;
|
|
}
|
|
|
|
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))
|
|
{
|
|
UIDispatcherHelper.Invoke(() => { Toast.Error("当前选择的自动战斗策略文件不存在"); });
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
[RelayCommand]
|
|
public async Task OnGoToAutoDomainUrlAsync()
|
|
{
|
|
await Launcher.LaunchUriAsync(new Uri("https://bettergi.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://bettergi.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]
|
|
private async Task OnGoToAutoTrackPathUrlAsync()
|
|
{
|
|
await Launcher.LaunchUriAsync(new Uri("https://bettergi.com/feats/task/track.html"));
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task OnSwitchAutoMusicGame()
|
|
{
|
|
SwitchAutoMusicGameEnabled = true;
|
|
await new TaskRunner()
|
|
.RunSoloTaskAsync(new AutoMusicGameTask(new AutoMusicGameParam()));
|
|
SwitchAutoMusicGameEnabled = false;
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task OnGoToAutoMusicGameUrlAsync()
|
|
{
|
|
await Launcher.LaunchUriAsync(new Uri("https://bettergi.com/feats/task/music.html"));
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task OnSwitchAutoAlbum()
|
|
{
|
|
SwitchAutoAlbumEnabled = true;
|
|
await new TaskRunner()
|
|
.RunSoloTaskAsync(new AutoAlbumTask(new AutoMusicGameParam()));
|
|
SwitchAutoAlbumEnabled = false;
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task OnSwitchAutoFishing()
|
|
{
|
|
SwitchAutoFishingEnabled = true;
|
|
var param = AutoFishingTaskParam.BuildFromConfig(TaskContext.Instance().Config.AutoFishingConfig, SaveScreenshotOnKeyTick);
|
|
await new TaskRunner()
|
|
.RunSoloTaskAsync(new AutoFishingTask(param));
|
|
SwitchAutoFishingEnabled = false;
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task OnGoToAutoFishingUrlAsync()
|
|
{
|
|
await Launcher.LaunchUriAsync(new Uri("https://bettergi.com/feats/task/fish.html"));
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void OnOpenLocalScriptRepo()
|
|
{
|
|
_autoFightViewModel.OnOpenLocalScriptRepo();
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task OnGameLangSelectionChanged(KeyValuePair<string, string> type)
|
|
{
|
|
await OcrFactory.ChangeCulture(type.Key);
|
|
}
|
|
} |