M Core/NosSmooth.Game/PacketHandlers/Relations/MatesInitResponder.cs => Core/NosSmooth.Game/PacketHandlers/Relations/MatesInitResponder.cs +11 -11
@@ 174,11 174,11 @@ public class MatesInitResponder : IPacketResponder<ScPPacket>, IPacketResponder<
packet.MorphVNum,
packet.IsSummonable,
#pragma warning disable SA1118
- packet.SpSubPacket?.ItemVNum is not null
+ packet.SpSubPacket.Value is not null
? new PartnerSp
(
- packet.SpSubPacket.ItemVNum.Value,
- packet.SpSubPacket.AgilityPercentage,
+ packet.SpSubPacket.Value.ItemVNum,
+ packet.SpSubPacket.Value.AgilityPercentage,
await CreateSkill(packet.Skill1SubPacket, ct),
await CreateSkill(packet.Skill2SubPacket, ct),
await CreateSkill(packet.Skill3SubPacket, ct)
@@ 318,25 318,25 @@ public class MatesInitResponder : IPacketResponder<ScPPacket>, IPacketResponder<
private async Task<UpgradeableItem?> CreatePartnerItem(ScNEquipmentSubPacket? packet, CancellationToken ct)
{
- if (packet is null || packet.ItemVNum is null)
+ if (packet is null)
{
return null;
}
- var itemInfoResult = await _infoService.GetItemInfoAsync(packet.ItemVNum.Value, ct);
+ var itemInfoResult = await _infoService.GetItemInfoAsync(packet.ItemVNum, ct);
if (!itemInfoResult.IsDefined(out var itemInfo))
{
_logger.LogWarning
(
"Could not obtain an item info for vnum {vnum}: {error}",
- packet.ItemVNum.Value,
+ packet.ItemVNum,
itemInfoResult.ToFullString()
);
}
return new UpgradeableItem
(
- packet.ItemVNum.Value,
+ packet.ItemVNum,
itemInfo,
packet.ItemUpgrade,
packet.ItemRare,
@@ 346,22 346,22 @@ public class MatesInitResponder : IPacketResponder<ScPPacket>, IPacketResponder<
private async Task<PartnerSkill?> CreateSkill(ScNSkillSubPacket? packet, CancellationToken ct)
{
- if (packet is null || packet.SkillVNum is null)
+ if (packet is null)
{
return null;
}
- var skillInfoResult = await _infoService.GetSkillInfoAsync(packet.SkillVNum.Value, ct);
+ var skillInfoResult = await _infoService.GetSkillInfoAsync(packet.SkillVNum, ct);
if (!skillInfoResult.IsDefined(out var skillInfo))
{
_logger.LogWarning
(
"Could not obtain a skill info for vnum {vnum}: {error}",
- packet.SkillVNum.Value,
+ packet.SkillVNum,
skillInfoResult.ToFullString()
);
}
- return new PartnerSkill(packet.SkillVNum.Value, packet.Rank, skillInfo);
+ return new PartnerSkill(packet.SkillVNum, packet.Rank, skillInfo);
}
}=
\ No newline at end of file
M Packets/NosSmooth.PacketSerializer.Abstractions/NullableWrapper.cs => Packets/NosSmooth.PacketSerializer.Abstractions/NullableWrapper.cs +1 -1
@@ 17,7 17,7 @@ namespace NosSmooth.PacketSerializer.Abstractions;
/// <param name="Value">The value.</param>
/// <typeparam name="T">The underlying type.</typeparam>
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1313:Parameter names should begin with lower-case letter", Justification = "Fix this, this should not happen.")]
-public record struct NullableWrapper<T>(T? Value)
+public record NullableWrapper<T>(T? Value)
{
/// <summary>
/// Unwrap the underlying value.
M Packets/NosSmooth.PacketSerializer/Converters/Common/NullableWrapperConverter.cs => Packets/NosSmooth.PacketSerializer/Converters/Common/NullableWrapperConverter.cs +9 -9
@@ 16,21 16,21 @@ namespace NosSmooth.PacketSerializer.Converters.Common;
/// <typeparam name="T">The underlying type.</typeparam>
public class NullableWrapperConverter<T> : BaseStringConverter<NullableWrapper<T>>
{
- private readonly StringConverterRepository _converterRepository;
+ private readonly IStringConverterRepository _converterRepository;
/// <summary>
/// Initializes a new instance of the <see cref="NullableWrapperConverter{T}"/> class.
/// </summary>
/// <param name="converterRepository">The converter repository.</param>
- public NullableWrapperConverter(StringConverterRepository converterRepository)
+ public NullableWrapperConverter(IStringConverterRepository converterRepository)
{
_converterRepository = converterRepository;
}
/// <inheritdoc />
- public override Result Serialize(NullableWrapper<T> obj, PacketStringBuilder builder)
+ public override Result Serialize(NullableWrapper<T>? obj, PacketStringBuilder builder)
{
- if (obj.Value is null)
+ if (obj is null || obj.Value is null)
{
builder.Append("-1");
}
@@ 49,29 49,29 @@ public class NullableWrapperConverter<T> : BaseStringConverter<NullableWrapper<T
}
/// <inheritdoc />
- public override Result<NullableWrapper<T>> Deserialize(ref PacketStringEnumerator stringEnumerator)
+ public override Result<NullableWrapper<T>?> Deserialize(ref PacketStringEnumerator stringEnumerator)
{
var tokenResult = stringEnumerator.GetNextToken(out var packetToken, false);
if (!tokenResult.IsSuccess)
{
- return Result<NullableWrapper<T>>.FromError(tokenResult);
+ return Result<NullableWrapper<T>?>.FromError(tokenResult);
}
if (packetToken.Token.Length == 2 && packetToken.Token.StartsWith("-1"))
{
- return Result<NullableWrapper<T>>.FromSuccess(new NullableWrapper<T>(default));
+ return Result<NullableWrapper<T>?>.FromSuccess(new NullableWrapper<T>(default));
}
var converterResult = _converterRepository.GetTypeConverter<T>();
if (!converterResult.IsDefined(out var converter))
{
- return Result<NullableWrapper<T>>.FromError(converterResult);
+ return Result<NullableWrapper<T>?>.FromError(converterResult);
}
var deserializationResult = converter.Deserialize(ref stringEnumerator);
if (!deserializationResult.IsDefined(out var deserialization))
{
- return Result<NullableWrapper<T>>.FromError(deserializationResult);
+ return Result<NullableWrapper<T>?>.FromError(deserializationResult);
}
return new NullableWrapper<T>(deserialization);
M Packets/NosSmooth.PacketSerializer/Extensions/ServiceCollectionExtensions.cs => Packets/NosSmooth.PacketSerializer/Extensions/ServiceCollectionExtensions.cs +1 -0
@@ 77,6 77,7 @@ public static class ServiceCollectionExtensions
.AddStringConverterFactory<ListStringConverterFactory>()
.AddStringConverterFactory<NullableStringConverterFactory>()
.AddStringConverterFactory<EnumStringConverterFactory>()
+ .AddStringConverterFactory<NullableWrapperConverterFactory>()
.AddStringConverter<IntStringConverter>()
.AddStringConverter<BoolStringConverter>()
.AddStringConverter<UIntStringConverter>()