From efdbad09d0dec9aab8032e2fb3440be566ba4c9a Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Fri, 17 Nov 2023 11:14:42 +0100 Subject: [PATCH] feat: identical to item listing, stats not being calculated in its entirety --- .../PacketHandlers/ChannelSelectionHandler.cs | 27 +++++++++---- .../CharacterDeletionHandler.cs | 4 +- .../ChannelSelectionResponsePacket.cs | 40 ++++++++++--------- .../CharacterCreationResponsePacket.cs | 2 + 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/Server/PacketHandlers/ChannelSelectionHandler.cs b/Server/PacketHandlers/ChannelSelectionHandler.cs index 9e474ff..a515d1e 100644 --- a/Server/PacketHandlers/ChannelSelectionHandler.cs +++ b/Server/PacketHandlers/ChannelSelectionHandler.cs @@ -39,7 +39,7 @@ public class ChannelSelectionHandler : IPacketHandler { ChannelIsFullFlag = 0, Endpoint = "127.0.0.1", - Port = 12345, + Port = 2000, Characters = await _wonderkingContext.Characters.AsNoTracking() .Where(c => c.Account.Id == authSession.AccountId) .Select(c => @@ -54,20 +54,19 @@ public class ChannelSelectionHandler : IPacketHandler Stats = c.BaseStats, Health = c.Health, Mana = c.Mana, - EquippedItems = - c.InventoryItems.Where(item => item.InventoryTab == InventoryTab.WornEquipment) - .Select(item => item.ItemId) - .ToArray(), - EquippedCashItems = c.InventoryItems + EquippedItems = GetItemIDsByInventoryTab(c.InventoryItems + .Where(item => item.InventoryTab == InventoryTab.WornEquipment) + .Select(item => new Tuple(item.ItemId, item.Slot)).ToArray()), + EquippedCashItems = GetItemIDsByInventoryTab(c.InventoryItems .Where(item => item.InventoryTab == InventoryTab.WornCashEquipment) - .Select(item => item.ItemId) - .ToArray() + .Select(item => new Tuple(item.ItemId, item.Slot)).ToArray()), }) .ToArrayAsync().ConfigureAwait(true), }; guildNameResponsePacket.GuildNames = await _wonderkingContext.Characters .Where(c => c.Account.Id == authSession.AccountId) + .Where(c => c.Guild != null) .Select(character => character.Guild.Name).ToArrayAsync().ConfigureAwait(true); } else @@ -88,4 +87,16 @@ public class ChannelSelectionHandler : IPacketHandler authSession.Send(guildNameResponsePacket); } } + + private static ushort[] GetItemIDsByInventoryTab(Tuple[] items) + { + var ids = new ushort[20]; + + for (var i = 0; i < 20; i++) + { + ids[i] = items.FirstOrDefault(item => item.Item2 == i)?.Item1 ?? 0; + } + + return ids; + } } diff --git a/Server/PacketHandlers/CharacterDeletionHandler.cs b/Server/PacketHandlers/CharacterDeletionHandler.cs index 920131a..2c256c0 100644 --- a/Server/PacketHandlers/CharacterDeletionHandler.cs +++ b/Server/PacketHandlers/CharacterDeletionHandler.cs @@ -34,8 +34,8 @@ public class CharacterDeletionHandler : IPacketHandler return; } - _wonderkingContext.Characters.Remove(character); - await _wonderkingContext.SaveChangesAsync().ConfigureAwait(false); + //_wonderkingContext.Characters.Remove(character); + //await _wonderkingContext.SaveChangesAsync().ConfigureAwait(false); authSession.Send(response); } diff --git a/Wonderking/Packets/Outgoing/ChannelSelectionResponsePacket.cs b/Wonderking/Packets/Outgoing/ChannelSelectionResponsePacket.cs index 12b93fc..3245cb2 100644 --- a/Wonderking/Packets/Outgoing/ChannelSelectionResponsePacket.cs +++ b/Wonderking/Packets/Outgoing/ChannelSelectionResponsePacket.cs @@ -29,39 +29,41 @@ public class ChannelSelectionResponsePacket : IPacket // Character Data for (var i = 0; i < Characters.Length; i++) { + int offset = 20 + (i * 132); var character = Characters[i]; - BinaryPrimitives.WriteInt32LittleEndian(data.Slice(20 + (i * 132), 4), i); - Encoding.ASCII.GetBytes(character.Name, data.Slice(24 + (i * 132), 20)); + // Character Data + BinaryPrimitives.WriteInt32LittleEndian(data.Slice(offset, 4), i); + Encoding.ASCII.GetBytes(character.Name, data.Slice(offset + 4, 20)); // Job Data - data[44 + (i * 132)] = character.Job.FirstJob; - data[45 + (i * 132)] = character.Job.SecondJob; - data[46 + (i * 132)] = character.Job.ThirdJob; - data[47 + (i * 132)] = character.Job.FourthJob; + data[offset + 24] = character.Job.FirstJob; + data[offset + 25] = character.Job.SecondJob; + data[offset + 26] = character.Job.ThirdJob; + data[offset + 27] = character.Job.FourthJob; - data[48 + (i * 132)] = (byte)character.Gender; - BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(49 + (i * 132), 2), character.Level); - data[51 + (i * 132)] = (byte)character.Experience; + data[offset + 28] = (byte)character.Gender; + BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(offset + 29, 2), character.Level); + data[offset + 31] = (byte)character.Experience; // Stats - BinaryPrimitives.WriteInt16LittleEndian(data.Slice(52 + (i * 132), 2), character.Stats.Strength); - BinaryPrimitives.WriteInt16LittleEndian(data.Slice(54 + (i * 132), 2), character.Stats.Dexterity); - BinaryPrimitives.WriteInt16LittleEndian(data.Slice(56 + (i * 132), 2), character.Stats.Intelligence); - BinaryPrimitives.WriteInt16LittleEndian(data.Slice(58 + (i * 132), 2), character.Stats.Vitality); - BinaryPrimitives.WriteInt16LittleEndian(data.Slice(60 + (i * 132), 2), character.Stats.Luck); - BinaryPrimitives.WriteInt16LittleEndian(data.Slice(62 + (i * 132), 2), character.Stats.Wisdom); + BinaryPrimitives.WriteInt16LittleEndian(data.Slice(offset + 32, 2), character.Stats.Strength); + BinaryPrimitives.WriteInt16LittleEndian(data.Slice(offset + 34, 2), character.Stats.Dexterity); + BinaryPrimitives.WriteInt16LittleEndian(data.Slice(offset + 36, 2), character.Stats.Intelligence); + BinaryPrimitives.WriteInt16LittleEndian(data.Slice(offset + 38, 2), character.Stats.Vitality); + BinaryPrimitives.WriteInt16LittleEndian(data.Slice(offset + 40, 2), character.Stats.Luck); + BinaryPrimitives.WriteInt16LittleEndian(data.Slice(offset + 42, 2), character.Stats.Wisdom); - BinaryPrimitives.WriteInt32LittleEndian(data.Slice(64 + (i * 132), 4), character.Health); - BinaryPrimitives.WriteInt32LittleEndian(data.Slice(68 + (i * 132), 4), character.Mana); + BinaryPrimitives.WriteInt32LittleEndian(data.Slice(offset + 44, 4), character.Health); + BinaryPrimitives.WriteInt32LittleEndian(data.Slice(offset + 48, 4), character.Mana); for (var j = 0; j < 20; j++) { // Equipped Items - BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(72 + (i * 132) + (j * 2), 2), + BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(offset + 52 + j * 2, 2), character.EquippedItems.Length > j ? character.EquippedItems[j] : (ushort)0); // Equipped Cash Items - BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(112 + (i * 132) + (j * 2), 2), + BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(offset + 92 + j * 2, 2), character.EquippedCashItems.Length > j ? character.EquippedCashItems[j] : (ushort)0); } } diff --git a/Wonderking/Packets/Outgoing/CharacterCreationResponsePacket.cs b/Wonderking/Packets/Outgoing/CharacterCreationResponsePacket.cs index 6419417..cce221c 100644 --- a/Wonderking/Packets/Outgoing/CharacterCreationResponsePacket.cs +++ b/Wonderking/Packets/Outgoing/CharacterCreationResponsePacket.cs @@ -20,6 +20,8 @@ public class CharacterCreationResponsePacket : IPacket { Span data = stackalloc byte[1 + 132]; data[0] = isDuplicate ? (byte)1 : (byte)0; + + // Character Data BinaryPrimitives.WriteInt32LittleEndian(data.Slice(1, 4), Slot); Encoding.ASCII.GetBytes(Character.Name, data.Slice(5, 20));