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

View file

@ -21,7 +21,7 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
_itemObjectPoolService = itemObjectPoolService;
}
public Task HandleAsync(CharacterCreationPacket packet, TcpSession session)
public async Task HandleAsync(CharacterCreationPacket packet, TcpSession session)
{
var authSession = session as AuthSession;
var account =
@ -59,9 +59,9 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
Health = 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)
.Select(c =>
new CharacterData
@ -82,8 +82,7 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
.Where(item => item.InventoryTab == InventoryTab.WornCashEquipment)
.Select(item => item.ItemId)
.ToArray(),
}).FirstOrDefault();
}).FirstOrDefaultAsync().ConfigureAwait(true);
authSession?.Send(new CharacterCreationResponsePacket { Character = character });
return Task.CompletedTask;
}
}