Files
better-genshin-impact/BetterGenshinImpact/GameTask/AutoPathing/Model/PathingTask.cs
辉鸭蛋 94aae80046 auto pathing: optimize switch avatar
删除 `BetterGenshinImpact.csproj` 中的无用文件夹包含项。
将 `PathingConfig.cs` 中部分属性类型从 `int` 改为 `string`,并调整默认值。
在 `ScriptRepoUpdater.cs` 中用 `MessageBox` 替换 `ContentDialog`。
简化 `ElementalSkillHandler.cs` 和 `NormalAttackHandler.cs` 中的代码。
删除 `NahidaCollectHandler.cs` 中的切换角色代码。
在 `PathingTask.cs` 中添加 `HasAction` 方法。
在 `PathExecutor.cs` 中添加 `_actionAvatarIndexMap` 字典和多个新方法。
新增 `ReturnMainUiTask.cs` 任务类。
2024-10-24 23:05:52 +08:00

64 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.GameTask.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Xml.Linq;
using Microsoft.Extensions.Logging;
namespace BetterGenshinImpact.GameTask.AutoPathing.Model;
[Serializable]
public class PathingTask
{
/// <summary>
/// 实际存储的文件名
/// </summary>
[JsonIgnore]
public string FileName { get; set; } = string.Empty;
/// <summary>
/// 实际存储的文件路径
/// </summary>
[JsonIgnore]
public string FullPath { get; set; } = string.Empty;
public PathingTaskInfo Info { get; set; } = new();
public List<Waypoint> Positions { get; set; } = [];
public bool HasAction(string actionName)
{
return Positions.Exists(p => p.Action == actionName);
}
public static PathingTask BuildFromFilePath(string filePath)
{
var json = File.ReadAllText(filePath);
var task = JsonSerializer.Deserialize<PathingTask>(json, PathRecorder.JsonOptions) ?? throw new Exception("Failed to deserialize PathingTask");
task.FileName = Path.GetFileName(filePath);
task.FullPath = filePath;
// 比较版本号大小 BgiVersion
if (!string.IsNullOrWhiteSpace(task.Info.BgiVersion) && Global.IsNewVersion(task.Info.BgiVersion))
{
TaskControl.Logger.LogError("路径追踪任务 {Name} 版本号要求 {BgiVersion} 大于当前 BetterGI 版本号 {CurrentVersion} 脚本可能无法正常工作,请更新 BetterGI 版本!", task.FileName, task.Info.BgiVersion, Global.Version);
}
return task;
}
public static PathingTask BuildFromJson(string json)
{
var task = JsonSerializer.Deserialize<PathingTask>(json, PathRecorder.JsonOptions) ?? throw new Exception("Failed to deserialize PathingTask");
return task;
}
public void SaveToFile(string filePath)
{
var json = JsonSerializer.Serialize(this, PathRecorder.JsonOptions);
File.WriteAllText(filePath, json, Encoding.UTF8);
}
}