Files
better-genshin-impact/BetterGenshinImpact/GameTask/AutoPathing/Handler/AutoFightHandler.cs
辉鸭蛋 c15cb33c2c rename variables and properties, refactor code, add new configuration options
重命名变量和属性,重构代码,添加新配置选项

主要更改:
* 将 `AutoFightConfig` 和 `AutoFightParam` 类中的字段和属性重命名,以提高名称的清晰度和一致性。
* 移除不必要的 `using` 语句,并调整顺序。
* 重构 `AutoFightTask` 和 `AutoFightHandler` 类中的条件判断和方法逻辑。
* 调整 `CameraRotateTask` 类中的参数值。
* 在 `PathExecutor` 类中添加 `_rotateTask` 字段,并修改相关方法调用。
* 在 `TaskSettingsPage.xaml` 中添加新的配置选项。
* 在 `HotKeyPageViewModel` 类中添加 `using` 语句,并修改热键回调逻辑。
* 修改 `TaskSettingsPageViewModel` 类中 `AutoFightParam` 的初始化。
2024-09-30 13:42:11 +08:00

44 lines
1.3 KiB
C#

using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.GameTask.AutoFight;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace BetterGenshinImpact.GameTask.AutoPathing.Handler;
internal class AutoFightHandler : IActionHandler
{
public async Task RunAsync(CancellationTokenSource cts)
{
await StartFight(cts);
}
private async Task StartFight(CancellationTokenSource cts)
{
// 爷们要战斗
var taskParams = new AutoFightParam(GetFightStrategy())
{
FightFinishDetectEnabled = true,
PickDropsAfterFightEnabled = true
};
var fightSoloTask = new AutoFightTask(taskParams);
await fightSoloTask.Start(cts);
}
private string GetFightStrategy()
{
var path = Global.Absolute(@"User\AutoFight\" + TaskContext.Instance().Config.AutoFightConfig.StrategyName + ".txt");
if ("根据队伍自动选择".Equals(TaskContext.Instance().Config.AutoFightConfig.StrategyName))
{
path = Global.Absolute(@"User\AutoFight\");
}
if (!File.Exists(path) && !Directory.Exists(path))
{
throw new Exception("战斗策略文件不存在");
}
return path;
}
}