From 75097db095e08864c5d07bc0ee39c84e478ef552 Mon Sep 17 00:00:00 2001 From: sven-n Date: Thu, 2 Jan 2025 12:11:41 +0100 Subject: [PATCH] Removed code duplication in item serializer --- .../RemoteView/ItemSerializerExtended.cs | 71 ------------------- .../RemoteView/ItemSerializerHelper.cs | 10 +-- 2 files changed, 5 insertions(+), 76 deletions(-) diff --git a/src/GameServer/RemoteView/ItemSerializerExtended.cs b/src/GameServer/RemoteView/ItemSerializerExtended.cs index c9d50ecb0..634b63c63 100644 --- a/src/GameServer/RemoteView/ItemSerializerExtended.cs +++ b/src/GameServer/RemoteView/ItemSerializerExtended.cs @@ -26,24 +26,6 @@ namespace MUnique.OpenMU.GameServer.RemoteView; [MinimumClient(106, 3, ClientLanguage.Invariant)] public class ItemSerializerExtended : IItemSerializer { - private const byte EmptySocket = 0xFE; - private const byte BlackFenrirFlag = 0x01; - private const byte BlueFenrirFlag = 0x02; - private const byte GoldFenrirFlag = 0x04; - private const byte MaximumSocketOptions = 50; - - /// - /// The socket seed index offsets, where the key is the numerical value of a - /// and the value is the first index of this corresponding elemental seed. - /// - /// - /// Webzen decided to put every possible socket option of each elemental seed type into one big list, - /// which may contain up to elements. - /// I couldn't figure out a pattern, but found these index offsets by trial and error. - /// Their list contains holes, so expect that index 9 doesn't define an option. - /// - private static readonly byte[] SocketOptionIndexOffsets = { 0, 10, 16, 21, 29, 36 }; - [Flags] private enum OptionFlags : byte { @@ -174,59 +156,6 @@ public Item DeserializeItem(Span array, GameConfiguration gameConfiguratio return item; } - private static byte GetHarmonyByte(Item item) - { - byte result = 0; - var harmonyOption = item.ItemOptions.FirstOrDefault(o => o.ItemOption?.OptionType == ItemOptionTypes.HarmonyOption); - if (harmonyOption?.ItemOption is not null) - { - result = (byte)(harmonyOption.ItemOption.Number << 4); - result |= (byte)harmonyOption.Level; - } - - return result; - } - - private static byte GetSocketBonusByte(Item item) - { - if (item.SocketCount == 0) - { - return 0; - } - - var bonusOption = item.ItemOptions.FirstOrDefault(o => o.ItemOption?.OptionType == ItemOptionTypes.SocketBonusOption); - if (bonusOption?.ItemOption != null) - { - return (byte)bonusOption.ItemOption.Number; - } - - return 0xFF; - } - - private static void SetSocketBytes(Span target, Item item) - { - for (int i = 0; i < item.SocketCount; i++) - { - target[i] = GetSocketByte(i); - } - - byte GetSocketByte(int socketSlot) - { - var optionLink = item.ItemOptions.FirstOrDefault(o => o.ItemOption?.OptionType == ItemOptionTypes.SocketOption && o.Index == socketSlot); - if (optionLink is null) - { - return EmptySocket; - } - - var sphereLevel = optionLink.Level; - var elementType = optionLink.ItemOption!.SubOptionType; - var elementOption = optionLink.ItemOption.Number; - var optionIndex = SocketOptionIndexOffsets[elementType] + elementOption; - - return (byte)((sphereLevel * MaximumSocketOptions) + optionIndex); - } - } - private OptionFlags GetOptionFlags(Item item) { OptionFlags result = default; diff --git a/src/GameServer/RemoteView/ItemSerializerHelper.cs b/src/GameServer/RemoteView/ItemSerializerHelper.cs index 6ba2f7b45..8b80f22fd 100644 --- a/src/GameServer/RemoteView/ItemSerializerHelper.cs +++ b/src/GameServer/RemoteView/ItemSerializerHelper.cs @@ -125,6 +125,11 @@ public static byte GetSocketBonusByte(Item item) /// The item. public static void SetSocketBytes(Span target, Item item) { + for (int i = 0; i < MaximumSockets; i++) + { + target[i] = i < item.SocketCount ? GetSocketByte(i) : NoSocket; + } + byte GetSocketByte(int socketSlot) { var optionLink = item.ItemOptions.FirstOrDefault(o => o.ItemOption?.OptionType == ItemOptionTypes.SocketOption && o.Index == socketSlot); @@ -140,11 +145,6 @@ byte GetSocketByte(int socketSlot) return (byte)((sphereLevel * MaximumSocketOptions) + optionIndex); } - - for (int i = 0; i < MaximumSockets; i++) - { - target[i] = i < item.SocketCount ? GetSocketByte(i) : NoSocket; - } } ///