using Google.Protobuf.Compiler; using Newtonsoft.Json; using PSO2SERVER.Models; using PSO2SERVER.Protocol.Packets; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; 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"; string jsonFilePath4 = "data\\quests\\Story Quests\\EP1\\700000 - An Encounter with Xion\\data.json"; // 读取并反序列化 JSON 文件 var map = JsonRead.DeserializeJson(jsonFilePath1); var mapEvent = JsonRead.DeserializeJson>(jsonFilePath2)?.FirstOrDefault(); var attributes = JsonRead.DeserializeJson(jsonFilePath3); var quest = JsonRead.DeserializeJson(jsonFilePath4); var quests = new List(); quests.Add(quest); var avaq = QuestAvailablePacket.Load(quests); // 获取类型信息 Type type = avaq.GetType(); // 获取所有公共属性 PropertyInfo[] properties = type.GetProperties(); Logger.Write("属性:"); foreach (var property in properties) { // 获取属性的值 var value = property.GetValue(avaq); Logger.Write($"{property.Name}: {value}"); } // 获取所有字段(包括私有字段) FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); Logger.Write("\n字段:"); foreach (var field in fields) { // 获取字段的值 var value = field.GetValue(avaq); Logger.Write($"{field.Name}: {value}"); } //// 输出 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); //} // 输出 MapData 信息 if (quest != null) { Logger.Write($"quest date: {quest.QuestDefiniton.Date}"); Logger.Write($"quest party_type: {quest.QuestDefiniton.PartyType}"); } } } }