diff --git a/Server/PacketHandlers/CharacterCreationHandler.cs b/Server/PacketHandlers/CharacterCreationHandler.cs index 99fdd20..a7e8faa 100644 --- a/Server/PacketHandlers/CharacterCreationHandler.cs +++ b/Server/PacketHandlers/CharacterCreationHandler.cs @@ -28,8 +28,13 @@ public class CharacterCreationHandler : IPacketHandler public async Task HandleAsync(CharacterCreationPacket packet, TcpSession session) { var authSession = session as AuthSession; + if (authSession is null) + { + return; + } + var account = - _wonderkingContext.Accounts.FirstOrDefault(a => authSession != null && a.Id == authSession.AccountId); + _wonderkingContext.Accounts.FirstOrDefault(a => a.Id == authSession.AccountId); var mappedDefaultItems = _characterStatsMapping.DefaultCharacterMapping.Items .Select(i => _itemObjectPoolService.GetBaseInventoryItem(i.Id, i.Quantity)).ToArray(); @@ -83,10 +88,10 @@ public class CharacterCreationHandler : IPacketHandler await _wonderkingContext.SaveChangesAsync().ConfigureAwait(true); var amountOfCharacters = await _wonderkingContext.Characters.AsNoTrackingWithIdentityResolution() - .CountAsync(c => authSession != null && c.Account.Id == authSession.AccountId).ConfigureAwait(true); + .CountAsync(c => c.Account.Id == authSession.AccountId).ConfigureAwait(true); var character = await _wonderkingContext.Characters.AsNoTrackingWithIdentityResolution() - .Where(c => authSession != null && c.Account.Id == authSession.AccountId && c.Name == packet.Name) + .Where(c => c.Account.Id == authSession.AccountId && c.Name == packet.Name) .Select(c => new CharacterData { @@ -99,13 +104,12 @@ public class CharacterCreationHandler : IPacketHandler Health = c.Health, Mana = c.Mana, EquippedItems = - c.InventoryItems.Where(item => item.InventoryTab == InventoryTab.WornEquipment) - .Select(item => item.ItemId) - .ToArray(), - EquippedCashItems = c.InventoryItems + 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()), }).FirstAsync().ConfigureAwait(true); await authSession.SendAsync(new CharacterCreationResponsePacket { @@ -126,4 +130,16 @@ public class CharacterCreationHandler : IPacketHandler return (int)((level - 1) * firstJobConfig.DynamicStats.ManaPerLevel + firstJobConfig.BaseStats.Wisdom * firstJobConfig.DynamicStats.ManaPerWisdom); } + + 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; + } }