From d289d5022162f4f5c3e522069413175bd2dd0590 Mon Sep 17 00:00:00 2001 From: rfi Date: Wed, 13 Dec 2023 09:18:07 +0700 Subject: [PATCH] backgroundsss --- AscNet.Common/Database/Player.cs | 3 + AscNet.GameServer/Handlers/AccountModule.cs | 9 ++- .../Handlers/PhotographModule.cs | 55 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 AscNet.GameServer/Handlers/PhotographModule.cs diff --git a/AscNet.Common/Database/Player.cs b/AscNet.Common/Database/Player.cs index 2098085c..242b3c41 100644 --- a/AscNet.Common/Database/Player.cs +++ b/AscNet.Common/Database/Player.cs @@ -112,6 +112,9 @@ namespace AscNet.Common.Database [BsonElement("gather_rewards")] public List GatherRewards { get; set; } = new(); + [BsonElement("use_background_id")] + public int UseBackgroundId { get; set; } = 14000001; + [BsonElement("team_groups")] [BsonRequired] [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] diff --git a/AscNet.GameServer/Handlers/AccountModule.cs b/AscNet.GameServer/Handlers/AccountModule.cs index 6d075fd3..3347268c 100644 --- a/AscNet.GameServer/Handlers/AccountModule.cs +++ b/AscNet.GameServer/Handlers/AccountModule.cs @@ -3,6 +3,7 @@ using AscNet.Common.MsgPack; using AscNet.Common.Util; using AscNet.Table.V2.share.chat; using AscNet.Table.V2.share.guide; +using AscNet.Table.V2.share.photomode; using MessagePack; using System.Diagnostics; @@ -138,7 +139,7 @@ namespace AscNet.GameServer.Handlers FubenMainLineData = new(), FubenChapterExtraLoginData = new(), FubenUrgentEventData = new(), - UseBackgroundId = 14000001 // main ui theme, table still failed to dump + UseBackgroundId = session.player.UseBackgroundId }; if (notifyLogin.PlayerData.DisplayCharIdList.Count < 1) notifyLogin.PlayerData.DisplayCharIdList.Add(notifyLogin.PlayerData.DisplayCharId); @@ -206,6 +207,11 @@ namespace AscNet.GameServer.Handlers ItemDataList = session.inventory.Items }; + NotifyBackgroundLoginData notifyBackground = new() + { + HaveBackgroundIds = TableReaderV2.Parse().Select(x => (uint)x.Id).ToList() + }; + session.SendPush(notifyLogin); session.SendPush(notifyStageData); session.SendPush(notifyCharacterData); @@ -213,6 +219,7 @@ namespace AscNet.GameServer.Handlers session.SendPush(notifyAssistData); session.SendPush(notifyChatLoginData); session.SendPush(notifyItemDataList); + session.SendPush(notifyBackground); #region DisclamerMail NotifyMails notifyMails = new(); diff --git a/AscNet.GameServer/Handlers/PhotographModule.cs b/AscNet.GameServer/Handlers/PhotographModule.cs new file mode 100644 index 00000000..7c35c2e3 --- /dev/null +++ b/AscNet.GameServer/Handlers/PhotographModule.cs @@ -0,0 +1,55 @@ +using AscNet.Common.MsgPack; +using AscNet.Common.Util; +using AscNet.Table.V2.share.fashion; +using MessagePack; + +namespace AscNet.GameServer.Handlers +{ + #region MsgPackScheme +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + [MessagePackObject(true)] + public class ChangeDisplayRequest + { + public int FashionId; + public int CharId; + public int BackgroundId; + } + + [MessagePackObject(true)] + public class ChangeDisplayResponse + { + public int Code; + public List DisplayCharIdList; + } +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + #endregion + + internal class PhotographModule + { + [RequestPacketHandler("ChangeDisplayRequest")] + public static void ChangeDisplayRequestHandler(Session session, Packet.Request packet) + { + ChangeDisplayRequest request = packet.Deserialize(); + + session.player.UseBackgroundId = request.BackgroundId; + if (!session.player.PlayerData.DisplayCharIdList.Contains(request.CharId)) + { + session.player.PlayerData.DisplayCharId = request.CharId; + session.player.PlayerData.DisplayCharIdList.Add(request.CharId); + } + + NotifyCharacterDataList.CharacterData? character = session.character.Characters.Find(x => x.Id == request.CharId); + if (character is not null && character.FashionId != request.FashionId && TableReaderV2.Parse().Any(x => x.CharacterId == request.CharId && x.Id == request.FashionId)) + { + character.FashionId = (uint)request.FashionId; + + NotifyCharacterDataList notifyCharacterData = new(); + notifyCharacterData.CharacterDataList.Add(character); + + session.SendPush(notifyCharacterData); + } + + session.SendResponse(new ChangeDisplayResponse() { DisplayCharIdList = session.player.PlayerData.DisplayCharIdList }, packet.Id); + } + } +}