feat: update creation to also set slots etc.

This commit is contained in:
Timothy Schenk 2023-11-19 15:07:43 +01:00
parent 8b294dd1ca
commit 6bcf90bc87

View file

@ -28,8 +28,13 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
public async Task HandleAsync(CharacterCreationPacket packet, TcpSession session) public async Task HandleAsync(CharacterCreationPacket packet, TcpSession session)
{ {
var authSession = session as AuthSession; var authSession = session as AuthSession;
if (authSession is null)
{
return;
}
var account = 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 var mappedDefaultItems = _characterStatsMapping.DefaultCharacterMapping.Items
.Select(i => _itemObjectPoolService.GetBaseInventoryItem(i.Id, i.Quantity)).ToArray(); .Select(i => _itemObjectPoolService.GetBaseInventoryItem(i.Id, i.Quantity)).ToArray();
@ -83,10 +88,10 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
await _wonderkingContext.SaveChangesAsync().ConfigureAwait(true); await _wonderkingContext.SaveChangesAsync().ConfigureAwait(true);
var amountOfCharacters = await _wonderkingContext.Characters.AsNoTrackingWithIdentityResolution() 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() 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 => .Select(c =>
new CharacterData new CharacterData
{ {
@ -99,13 +104,12 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
Health = c.Health, Health = c.Health,
Mana = c.Mana, Mana = c.Mana,
EquippedItems = EquippedItems =
c.InventoryItems.Where(item => item.InventoryTab == InventoryTab.WornEquipment) GetItemIDsByInventoryTab(c.InventoryItems
.Select(item => item.ItemId) .Where(item => item.InventoryTab == InventoryTab.WornEquipment)
.ToArray(), .Select(item => new Tuple<ushort, byte>(item.ItemId, item.Slot)).ToArray()),
EquippedCashItems = c.InventoryItems EquippedCashItems = GetItemIDsByInventoryTab(c.InventoryItems
.Where(item => item.InventoryTab == InventoryTab.WornCashEquipment) .Where(item => item.InventoryTab == InventoryTab.WornCashEquipment)
.Select(item => item.ItemId) .Select(item => new Tuple<ushort, byte>(item.ItemId, item.Slot)).ToArray()),
.ToArray(),
}).FirstAsync().ConfigureAwait(true); }).FirstAsync().ConfigureAwait(true);
await authSession.SendAsync(new CharacterCreationResponsePacket await authSession.SendAsync(new CharacterCreationResponsePacket
{ {
@ -126,4 +130,16 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
return (int)((level - 1) * firstJobConfig.DynamicStats.ManaPerLevel + return (int)((level - 1) * firstJobConfig.DynamicStats.ManaPerLevel +
firstJobConfig.BaseStats.Wisdom * firstJobConfig.DynamicStats.ManaPerWisdom); firstJobConfig.BaseStats.Wisdom * firstJobConfig.DynamicStats.ManaPerWisdom);
} }
private static ushort[] GetItemIDsByInventoryTab(Tuple<ushort, byte>[] 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;
}
} }