// Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License. using Microsoft.EntityFrameworkCore; using Server.DB; using Server.DB.Documents; using Wonderking.Game.Data.Character; using Wonderking.Packets.Outgoing.Data; namespace Server.PacketHandlers; public partial class ChannelSelectionHandler { private static readonly Func> _accountExists = EF.CompileAsyncQuery( (WonderkingContext context, Guid accountId) => context.Accounts.AsNoTracking().Any(a => a.Id == accountId)); private static readonly Func> _getAmountOfCharacters = EF.CompileAsyncQuery((WonderkingContext context, Guid accountId) => context.Characters.AsNoTracking() .Where(c => c.Account.Id == accountId).Take(3) .Count()); private static readonly Func> _getGuildNames = EF.CompileAsyncQuery((WonderkingContext context, Guid accountId) => context.Characters.AsNoTracking() .Where(c => c.Account.Id == accountId && c.Guild != null) .Select(c => c.Guild.Name).Take(3)); private static readonly Func> _getCharacters = EF.CompileAsyncQuery((WonderkingContext context, Guid accountId) => context.Characters.AsNoTracking().AsSplitQuery() .Where(c => c.Account.Id == accountId) .Select(c => new CharacterDataProjection( c.Name, c.JobData, c.Gender, c.Level, c.Experience, c.BaseStats, c.Health, c.Mana, c.InventoryItems.Select(i => new InventoryItemProjection(i.ItemId, i.Slot, i.InventoryTab)) )).Take(3)); private sealed record InventoryItemProjection(ushort ItemId, byte Slot, InventoryTab InventoryTab); private sealed record CharacterDataProjection( string Name, JobData JobData, Gender Gender, ushort Level, long Experience, BaseStats BaseStats, int Health, int Mana, IEnumerable InventoryItems); }