Files
DanhengServer-OpenSource/Common/Data/Config/Task/PropStateExecute.cs
Somebody 72ddae8940 [BREAK CHANGE] Feature: Implement the basic task system
- Support for the 2.0&2.1 mission
- The story line is still not working
2024-07-16 14:15:07 +08:00

47 lines
1.7 KiB
C#

using EggLink.DanhengServer.Enums.Scene;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EggLink.DanhengServer.Data.Config.Task
{
public class PropStateExecute : TaskConfigInfo
{
public TargetEvaluator TargetType { get; set; } = new();
[JsonConverter(typeof(StringEnumConverter))]
public PropStateEnum PropState { get; set; } = PropStateEnum.Closed;
public List<TaskConfigInfo> Execute { get; set; } = [];
public static new TaskConfigInfo LoadFromJsonObject(JObject obj)
{
var info = new PropStateExecute();
info.Type = obj[nameof(Type)]!.ToObject<string>()!;
if (obj.ContainsKey(nameof(TargetType)))
{
var targetType = obj[nameof(TargetType)] as JObject;
var classType = System.Type.GetType($"EggLink.DanhengServer.Data.Config.Task.{targetType?["Type"]?.ToString().Replace("RPG.GameCore.", "")}");
classType ??= System.Type.GetType($"EggLink.DanhengServer.Data.Config.Task.TargetEvaluator");
info.TargetType = (targetType!.ToObject(classType!) as TargetEvaluator)!;
}
if (obj.ContainsKey(nameof(PropState)))
{
info.PropState = obj[nameof(PropState)]?.ToObject<PropStateEnum>() ?? PropStateEnum.Closed;
}
foreach (var item in obj[nameof(Execute)]?.Select(x => TaskConfigInfo.LoadFromJsonObject((x as JObject)!)) ?? [])
{
info.Execute.Add(item);
}
return info;
}
}
}