feature/84-character-creation #88

Merged
rainote merged 60 commits from feature/84-character-creation into master 2023-11-17 07:29:21 +00:00
2 changed files with 12 additions and 15 deletions
Showing only changes of commit 5abe7f7564 - Show all commits

View file

@ -29,22 +29,22 @@ public class ChannelSelectionHandler : IPacketHandler<ChannelSelectionPacket>
{ {
} }
public Task HandleAsync(ChannelSelectionPacket packet, TcpSession session) public async Task HandleAsync(ChannelSelectionPacket packet, TcpSession session)
{ {
var authSession = (AuthSession)session; var authSession = (AuthSession)session;
ChannelSelectionResponsePacket responsePacket; ChannelSelectionResponsePacket responsePacket;
var guildNameResponsePacket = new CharacterSelectionSetGuildNamePacket { GuildNames = Array.Empty<string>() }; var guildNameResponsePacket = new CharacterSelectionSetGuildNamePacket { GuildNames = Array.Empty<string>() };
var hasCharacters = this._wonderkingContext.Accounts.Include(account => account.Characters) var account = await this._wonderkingContext.Accounts.Include(account => account.Characters)
.FirstOrDefault(a => a.Id == authSession.AccountId)?.Characters.Count > 0; .FirstOrDefaultAsync(a => a.Id == authSession.AccountId).ConfigureAwait(true);
if (hasCharacters) if (account != null && account.Characters.Count > 0)
{ {
responsePacket = new ChannelSelectionResponsePacket responsePacket = new ChannelSelectionResponsePacket
{ {
ChannelIsFullFlag = 0, ChannelIsFullFlag = 0,
Endpoint = "127.0.0.1", Endpoint = "127.0.0.1",
Port = 12345, Port = 12345,
Characters = this._wonderkingContext.Characters.AsNoTracking() Characters = await _wonderkingContext.Characters.AsNoTracking()
.Where(c => c.Account.Id == authSession.AccountId) .Where(c => c.Account.Id == authSession.AccountId)
.Select(c => .Select(c =>
new CharacterData new CharacterData
@ -67,12 +67,12 @@ public class ChannelSelectionHandler : IPacketHandler<ChannelSelectionPacket>
.Select(item => item.ItemId) .Select(item => item.ItemId)
.ToArray() .ToArray()
}) })
.ToArray(), .ToArrayAsync().ConfigureAwait(true),
}; };
guildNameResponsePacket.GuildNames = this._wonderkingContext.Characters guildNameResponsePacket.GuildNames = await _wonderkingContext.Characters
.Where(c => c.Account.Id == authSession.AccountId) .Where(c => c.Account.Id == authSession.AccountId)
.Select(character => character.Guild.Name).ToArray(); .Select(character => character.Guild.Name).ToArrayAsync().ConfigureAwait(true);
} }
else else
{ {
@ -87,7 +87,5 @@ public class ChannelSelectionHandler : IPacketHandler<ChannelSelectionPacket>
authSession.Send(responsePacket); authSession.Send(responsePacket);
authSession.Send(guildNameResponsePacket); authSession.Send(guildNameResponsePacket);
return Task.CompletedTask;
} }
} }

View file

@ -21,7 +21,7 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
_itemObjectPoolService = itemObjectPoolService; _itemObjectPoolService = itemObjectPoolService;
} }
public Task HandleAsync(CharacterCreationPacket packet, TcpSession session) public async Task HandleAsync(CharacterCreationPacket packet, TcpSession session)
{ {
var authSession = session as AuthSession; var authSession = session as AuthSession;
var account = var account =
@ -59,9 +59,9 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
Health = 250, Health = 250,
Mana = 250, Mana = 250,
}); });
_wonderkingContext.SaveChanges(); await _wonderkingContext.SaveChangesAsync().ConfigureAwait(false);
var character = this._wonderkingContext.Characters.AsNoTracking() var character = await _wonderkingContext.Characters.AsNoTracking()
.Where(c => authSession != null && c.Account.Id == authSession.AccountId && c.Name == packet.Name) .Where(c => authSession != null && c.Account.Id == authSession.AccountId && c.Name == packet.Name)
.Select(c => .Select(c =>
new CharacterData new CharacterData
@ -82,8 +82,7 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
.Where(item => item.InventoryTab == InventoryTab.WornCashEquipment) .Where(item => item.InventoryTab == InventoryTab.WornCashEquipment)
.Select(item => item.ItemId) .Select(item => item.ItemId)
.ToArray(), .ToArray(),
}).FirstOrDefault(); }).FirstOrDefaultAsync().ConfigureAwait(true);
authSession?.Send(new CharacterCreationResponsePacket { Character = character }); authSession?.Send(new CharacterCreationResponsePacket { Character = character });
return Task.CompletedTask;
} }
} }