diff --git a/src/GameServer/RemoteView/ItemSerializerHelper.cs b/src/GameServer/RemoteView/ItemSerializerHelper.cs index 36e6fa98a..6ba2f7b45 100644 --- a/src/GameServer/RemoteView/ItemSerializerHelper.cs +++ b/src/GameServer/RemoteView/ItemSerializerHelper.cs @@ -195,7 +195,7 @@ public static void ReadSockets(Span socketBytes, IContext persistenceConte var sphereLevel = socketByte / MaximumSocketOptions; var optionIndex = socketByte % MaximumSocketOptions; - var indexOffset = SocketOptionIndexOffsets.First(offset => offset <= optionIndex); + var indexOffset = SocketOptionIndexOffsets.Last(offset => offset <= optionIndex); var elementType = Array.IndexOf(SocketOptionIndexOffsets, indexOffset); var optionNumber = optionIndex - indexOffset; diff --git a/tests/MUnique.OpenMU.Tests/ItemSerializerTests.cs b/tests/MUnique.OpenMU.Tests/ItemSerializerTests.cs index 2d9bbde5c..675b0383d 100644 --- a/tests/MUnique.OpenMU.Tests/ItemSerializerTests.cs +++ b/tests/MUnique.OpenMU.Tests/ItemSerializerTests.cs @@ -180,7 +180,7 @@ public void AncientWithoutBonus() [Test] public void Sockets() { - var tuple = this.SerializeAndDeserializeFlamberge(); + var tuple = this.SerializeAndDeserializeBraveHelm(); var item = tuple.Item1; var deserializedItem = tuple.Item2; Assert.That(deserializedItem.ItemOptions.Count, Is.EqualTo(item.ItemOptions.Count)); @@ -196,21 +196,38 @@ public void Sockets() Assert.That(deserializedItem.SocketCount, Is.EqualTo(item.SocketCount)); } - private Tuple SerializeAndDeserializeFlamberge() + private Tuple SerializeAndDeserializeBraveHelm() { using var context = this._contextProvider.CreateNewContext(this._gameConfiguration); var item = context.CreateNew(); - item.Definition = this._gameConfiguration.Items.First(i => i.Group == 0 && i.Number == 26); - item.Level = 15; + item.Definition = this._gameConfiguration.Items.First(i => i.Group == 7 && i.Number == 46); + item.Level = 3; item.Durability = 100; - item.HasSkill = true; - item.SocketCount = 3; + item.SocketCount = 2; + + var option = context.CreateNew(); + option.ItemOption = item.Definition.PossibleItemOptions.SelectMany(def => + def.PossibleOptions.Where(p => p.OptionType == ItemOptionTypes.Option)).First(); + option.Level = 4; + item.ItemOptions.Add(option); + + + for (var i = 0; i < item.SocketCount; i++) + { + var socketOption = context.CreateNew(); + socketOption.ItemOption = item.Definition.PossibleItemOptions + .SelectMany(o => o.PossibleOptions) + .Where(o => o.OptionType == ItemOptionTypes.SocketOption) + .Skip(i) + .First(); + socketOption.Index = i; + socketOption.Level = 1; + item.ItemOptions.Add(socketOption); + } - var socketOption = context.CreateNew(); - socketOption.ItemOption = this._gameConfiguration.ItemOptions.SelectMany(o => o.PossibleOptions).FirstOrDefault(o => o.OptionType == ItemOptionTypes.SocketOption); - socketOption.Index = 1; - socketOption.Level = 1; - item.ItemOptions.Add(socketOption); + var bonusOption = context.CreateNew(); + bonusOption.ItemOption = item.Definition.PossibleItemOptions.SelectMany(o => o.PossibleOptions).First(o => o.OptionType == ItemOptionTypes.SocketBonusOption); + item.ItemOptions.Add(bonusOption); var array = new byte[this._itemSerializer.NeededSpace]; this._itemSerializer.SerializeItem(array, item);