diff --git a/Server/Json/JsonTest.cs b/Server/Json/JsonTest.cs new file mode 100644 index 0000000..280213b --- /dev/null +++ b/Server/Json/JsonTest.cs @@ -0,0 +1,72 @@ +using Newtonsoft.Json; +using PSO2SERVER.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PSO2SERVER.Json +{ + public class JsonTest + { + public static void JsonReadTest() + { + // 测试数据文件路径 + string jsonFilePath1 = "data\\maps\\lobby\\data.json"; + string jsonFilePath2 = "data\\maps\\lobby\\events\\main_lobby_1\\all_events.json"; + string jsonFilePath3 = "data\\item_attrs.json"; + + // 读取并反序列化 JSON 文件 + var map = DeserializeJson(jsonFilePath1); + var mapEvent = DeserializeJson>(jsonFilePath2)?.FirstOrDefault(); + var attributes = DeserializeJson(jsonFilePath3); + + // 输出 MapData 信息 + if (map != null) + { + Logger.Write($"map_object ID: {map.Mapdata.map_object.ID}"); + Logger.Write($"Zones[0].Name: {map.Zones[0].Name}"); + Logger.Write($"Zones[0].Is_special_zone: {map.Zones[0].Is_special_zone}"); + } + + // 输出 EventData 信息 + if (mapEvent != null) + { + Logger.Write($"map_event zone_id: {mapEvent.zone_id}"); + Logger.Write($"map_event is_active: {mapEvent.is_active}"); + Logger.Write($"map_event objName: {mapEvent.data.objName}"); + } + + // 输出 ItemAttributesPC 信息 + if (attributes != null) + { + Logger.Write($"PC unk1: {attributes.PC.Unk1}"); + ItemAttributesPC.LogWeapons(attributes.PC.Weapons); + ItemAttributesPC.LogData17(attributes.PC.Data17); + } + } + + // 泛型方法:读取并反序列化 JSON 文件 + public static T DeserializeJson(string filePath) + { + if (!File.Exists(filePath)) + { + Logger.Write($"文件不存在: {filePath}"); + return default(T); + } + + try + { + string json = File.ReadAllText(filePath); + return JsonConvert.DeserializeObject(json); + } + catch (Exception ex) + { + Logger.Write($"错误:读取或反序列化文件 {filePath} 时发生异常: {ex.Message}"); + return default(T); + } + } + } +} diff --git a/Server/Models/ItemAttributes.cs b/Server/Models/ItemAttributes.cs index e08c2ec..c19728d 100644 --- a/Server/Models/ItemAttributes.cs +++ b/Server/Models/ItemAttributes.cs @@ -73,6 +73,39 @@ namespace PSO2SERVER.Models public List Data19 { get; set; } = new List(); [JsonProperty("data20")] public List Data20 { get; set; } = new List(); + + + public static void LogWeapons(List weapons) + { + if (weapons == null || weapons.Count == 0) return; + + Logger.Write($"Weapons Count: {weapons.Count}"); + foreach (var weapon in weapons) + { + Logger.Write($"Weapon ID: {weapon.Id}, Range Damage: {weapon.RangeDmg}, Gender: {weapon.Gender}"); + Logger.Write($"weapon.Unk8 Length: {weapon.Unk8.Length}"); + foreach (var un8 in weapon.Unk8) + { + Logger.Write($"Weapon un8: {un8}"); + } + } + } + + // 输出 Data17 列表信息 + public static void LogData17(List data17List) + { + if (data17List == null || data17List.Count == 0) return; + + Logger.Write($"Data17 Count: {data17List.Count}"); + foreach (var data17 in data17List) + { + Logger.Write($"data17.unk Length: {data17.unk.Length}"); + foreach (var value in data17.unk) + { + Logger.Write($"data17 value: {value}"); + } + } + } } // Vita ItemAttributes (Vita client) diff --git a/Server/Program.cs b/Server/Program.cs index 9c7624b..7c817ee 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -92,83 +92,7 @@ namespace PSO2SERVER Console.CancelKeyPress += Exit; AppDomain.CurrentDomain.ProcessExit += Exit; - string jsonFilePath = "data\\maps\\lobby\\data.json"; - - // 读取 JSON 文件 - string json = File.ReadAllText(jsonFilePath); - - // 反序列化为 C# 对象 - MapData map = JsonConvert.DeserializeObject(json); - - // 输出结果 - Logger.Write($"map_object ID: {map.Mapdata.map_object.ID}"); - Logger.Write($"Zones[0].Name: {map.Zones[0].Name}"); - Logger.Write($"Zones[0].Is_special_zone: {map.Zones[0].Is_special_zone}"); - - string jsonFilePath2 = "data\\maps\\lobby\\events\\main_lobby_1\\all_events.json"; - - // 读取 JSON 文件 - string json2 = File.ReadAllText(jsonFilePath2); - - // 反序列化为 C# 对象 - EventData map_event = JsonConvert.DeserializeObject>(json2).FirstOrDefault(); - - // 输出结果 - Logger.Write($"map_event zone_id: {map_event.zone_id}"); - Logger.Write($"map_event is_active: {map_event.is_active}"); - Logger.Write($"map_event objName: {map_event.data.objName}"); - - string jsonFilePath3 = "data\\item_attrs.json"; - - // Ensure the file exists - if (File.Exists(jsonFilePath3)) - { - try - { - // Read the JSON file - string json3 = File.ReadAllText(jsonFilePath3); - - // Deserialize the JSON data into ItemAttributesPC - ItemAttributesRootObject Attributes = JsonConvert.DeserializeObject(json3); - - // 输出 PC 的属性 - Logger.Write($"PC unk1: {Attributes.PC.Unk1}"); - - // 输出武器列表 - Logger.Write($"Weapons Count: {Attributes.PC.Weapons.Count}"); - foreach (var weapon in Attributes.PC.Weapons) - { - Logger.Write($"Weapon ID: {weapon.Id}, Range Damage: {weapon.RangeDmg}, Gender: {weapon.Gender}"); - Logger.Write($"weapon.Unk8 Length: {weapon.Unk8.Length}"); - foreach (var un8 in weapon.Unk8) - { - Logger.Write($"Weapon un8: {un8}"); - - } - } - - - // 输出武器列表 - Logger.Write($"Data17 Count: {Attributes.PC.Data17.Count}"); - foreach (var data17 in Attributes.PC.Data17) - { - Logger.Write($"data17.unk Length: {data17.unk.Length}"); - foreach (var value in data17.unk) - { - - Logger.Write($"data17 value:{value}"); - } - } - } - catch (Exception ex) - { - Logger.Write($"错误:读取或反序列化 JSON 文件时发生异常: {ex.Message}"); - } - } - else - { - Logger.Write("JSON 文件不存在。"); - } + JsonTest.JsonReadTest(); try { @@ -370,5 +294,6 @@ namespace PSO2SERVER // Save the configuration Config.Save(); } + } } \ No newline at end of file diff --git a/Server/Server.csproj b/Server/Server.csproj index e273ada..5b8ff4f 100644 --- a/Server/Server.csproj +++ b/Server/Server.csproj @@ -301,6 +301,7 @@ +