using Microsoft.EntityFrameworkCore; using NetCoreServer; using Server.DB; using Server.DB.Documents; using Server.Services; using Wonderking.Game.Data.Character; using Wonderking.Packets.Incoming; using Wonderking.Packets.Outgoing; using Wonderking.Packets.Outgoing.Data; namespace Server.PacketHandlers; public class CharacterCreationHandler : IPacketHandler { private readonly WonderkingContext _wonderkingContext; private readonly ItemObjectPoolService _itemObjectPoolService; public CharacterCreationHandler(WonderkingContext wonderkingContext, ItemObjectPoolService itemObjectPoolService) { _wonderkingContext = wonderkingContext; _itemObjectPoolService = itemObjectPoolService; } public Task HandleAsync(CharacterCreationPacket packet, TcpSession session) { var authSession = session as AuthSession; var account = _wonderkingContext.Accounts.FirstOrDefault(a => authSession != null && a.Id == authSession.AccountId); var items = new List { _itemObjectPoolService.GetBaseInventoryItem(25), _itemObjectPoolService.GetBaseInventoryItem(764), _itemObjectPoolService.GetBaseInventoryItem(766), _itemObjectPoolService.GetBaseInventoryItem(763), _itemObjectPoolService.GetBaseInventoryItem(767) }; account?.Characters.Add(new Character { Account = account, MapId = 300, Name = packet.Name, LastXCoordinate = 113, LastYCoordinate = 0, PvPLevel = PvPLevel.None, Gender = Gender.None, Experience = 0, Level = 1, InventoryItems = items, BaseStats = new BaseStats { Strength = 5, Dexterity = 5, Intelligence = 5, Vitality = 5, Luck = 5, Wisdom = 5 }, JobData = new JobData { FirstJob = packet.FirstJob, SecondJob = 0, ThirdJob = 0, FourthJob = 0 }, Health = 250, Mana = 250, }); _wonderkingContext.SaveChanges(); var character = this._wonderkingContext.Characters.AsNoTracking() .Where(c => authSession != null && c.Account.Id == authSession.AccountId && c.Name == packet.Name) .Select(c => new CharacterData { Name = c.Name, Job = c.JobData, Gender = c.Gender, Level = c.Level, Experience = 0, Stats = c.BaseStats, Health = c.Health, Mana = c.Mana, EquippedItems = c.InventoryItems.Where(item => item.InventoryTab == InventoryTab.WornEquipment) .Select(item => item.ItemId) .ToArray(), EquippedCashItems = c.InventoryItems .Where(item => item.InventoryTab == InventoryTab.WornCashEquipment) .Select(item => item.ItemId) .ToArray(), }).FirstOrDefault(); authSession?.Send(new CharacterCreationResponsePacket { Character = character }); return Task.CompletedTask; } }