PSO2SERVER/Server/Json/JsonTest.cs

95 lines
3.4 KiB
C#
Raw Normal View History

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