mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-04-22 03:59:35 +08:00

* 更换任务计划实现方式;修改自定义 Json 转换器基类 * RunTimeController 添加 HTTPClient(WebSocket)支持;SQL 查询修改为参数化,防止注入
92 lines
3.7 KiB
C#
92 lines
3.7 KiB
C#
using System.Text.Json;
|
|
using Milimoe.FunGame.Core.Api.Utility;
|
|
using Milimoe.FunGame.Core.Entity;
|
|
using Milimoe.FunGame.Core.Library.Common.Architecture;
|
|
using Milimoe.FunGame.Core.Library.Constant;
|
|
|
|
namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
|
{
|
|
public class EquipSlotConverter : BaseEntityConverter<EquipSlot>
|
|
{
|
|
public override EquipSlot NewInstance()
|
|
{
|
|
return new();
|
|
}
|
|
|
|
public override void ReadPropertyName(ref Utf8JsonReader reader, string propertyName, JsonSerializerOptions options, ref EquipSlot result, Dictionary<string, object> convertingContext)
|
|
{
|
|
Item temp;
|
|
switch (propertyName)
|
|
{
|
|
case nameof(EquipSlot.MagicCardPack):
|
|
temp = NetworkUtility.JsonDeserialize<Item>(ref reader, options) ?? new();
|
|
if (temp.EquipSlotType == EquipSlotType.MagicCardPack)
|
|
{
|
|
result.MagicCardPack = temp;
|
|
}
|
|
break;
|
|
case nameof(EquipSlot.Weapon):
|
|
temp = NetworkUtility.JsonDeserialize<Item>(ref reader, options) ?? new();
|
|
if (temp.EquipSlotType == EquipSlotType.Weapon)
|
|
{
|
|
result.Weapon = temp;
|
|
}
|
|
break;
|
|
case nameof(EquipSlot.Armor):
|
|
temp = NetworkUtility.JsonDeserialize<Item>(ref reader, options) ?? new();
|
|
if (temp.EquipSlotType == EquipSlotType.Armor)
|
|
{
|
|
result.Armor = temp;
|
|
}
|
|
break;
|
|
case nameof(EquipSlot.Shoes):
|
|
temp = NetworkUtility.JsonDeserialize<Item>(ref reader, options) ?? new();
|
|
if (temp.EquipSlotType == EquipSlotType.Shoes)
|
|
{
|
|
result.Shoes = temp;
|
|
}
|
|
break;
|
|
case nameof(EquipSlot.Accessory1):
|
|
temp = NetworkUtility.JsonDeserialize<Item>(ref reader, options) ?? new();
|
|
if (temp.EquipSlotType == EquipSlotType.Accessory1)
|
|
{
|
|
result.Accessory1 = temp;
|
|
}
|
|
break;
|
|
case nameof(EquipSlot.Accessory2):
|
|
temp = NetworkUtility.JsonDeserialize<Item>(ref reader, options) ?? new();
|
|
if (temp.EquipSlotType == EquipSlotType.Accessory2)
|
|
{
|
|
result.Accessory2 = temp;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
public override void Write(Utf8JsonWriter writer, EquipSlot value, JsonSerializerOptions options)
|
|
{
|
|
writer.WriteStartObject();
|
|
|
|
writer.WritePropertyName(nameof(value.MagicCardPack));
|
|
JsonSerializer.Serialize(writer, value.MagicCardPack, options);
|
|
|
|
writer.WritePropertyName(nameof(value.Weapon));
|
|
JsonSerializer.Serialize(writer, value.Weapon, options);
|
|
|
|
writer.WritePropertyName(nameof(value.Armor));
|
|
JsonSerializer.Serialize(writer, value.Armor, options);
|
|
|
|
writer.WritePropertyName(nameof(value.Shoes));
|
|
JsonSerializer.Serialize(writer, value.Shoes, options);
|
|
|
|
writer.WritePropertyName(nameof(value.Accessory1));
|
|
JsonSerializer.Serialize(writer, value.Accessory1, options);
|
|
|
|
writer.WritePropertyName(nameof(value.Accessory2));
|
|
JsonSerializer.Serialize(writer, value.Accessory2, options);
|
|
|
|
writer.WriteEndObject();
|
|
}
|
|
}
|
|
}
|