refactor: early return + itemids as span
This commit is contained in:
parent
c4905b8cba
commit
ec155ecab1
1 changed files with 11 additions and 7 deletions
|
@ -29,19 +29,23 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
|
|||
|
||||
public async Task HandleAsync(CharacterCreationPacket packet, TcpSession session)
|
||||
{
|
||||
var authSession = session as AuthSession;
|
||||
if (authSession is null)
|
||||
if (session is not AuthSession authSession)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var account = await _wonderkingContext.Accounts.FirstOrDefaultAsync(a => a.Id == authSession.AccountId);
|
||||
|
||||
if (account is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var firstJobConfig = SelectFirstJobConfig(packet.FirstJob);
|
||||
var items = CreateDefaultItems(packet, firstJobConfig);
|
||||
|
||||
var toBeAddedCharacter = CreateDefaultCharacter(packet, account, items, firstJobConfig);
|
||||
account?.Characters.Add(toBeAddedCharacter);
|
||||
account.Characters.Add(toBeAddedCharacter);
|
||||
await _wonderkingContext.SaveChangesAsync();
|
||||
|
||||
var character =
|
||||
|
@ -92,7 +96,7 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
|
|||
private static Character CreateDefaultCharacter(CharacterCreationPacket packet, Account account,
|
||||
InventoryItem[] items, JobSpecificMapping firstJobConfig)
|
||||
{
|
||||
return new Character
|
||||
return new Character()
|
||||
{
|
||||
Account = account,
|
||||
MapId = 300,
|
||||
|
@ -154,8 +158,8 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
|
|||
|
||||
private static ushort[] GetItemIDsByInventoryTab(IEnumerable<Tuple<ushort, byte>> items)
|
||||
{
|
||||
var ids = new ushort[20];
|
||||
ids.AsSpan().Clear();
|
||||
Span<ushort> ids = stackalloc ushort[20];
|
||||
ids.Clear();
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
|
@ -167,6 +171,6 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
|
|||
ids[item.Item2] = item.Item1;
|
||||
}
|
||||
|
||||
return ids;
|
||||
return ids.ToArray();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue