diff --git a/AscNet.Common/Database/Player.cs b/AscNet.Common/Database/Player.cs index 8c69df5..2098085 100644 --- a/AscNet.Common/Database/Player.cs +++ b/AscNet.Common/Database/Player.cs @@ -109,6 +109,9 @@ namespace AscNet.Common.Database [BsonRequired] public List HeadPortraits { get; set; } + [BsonElement("gather_rewards")] + public List GatherRewards { get; set; } = new(); + [BsonElement("team_groups")] [BsonRequired] [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] diff --git a/AscNet.Common/MsgPack/Types.cs b/AscNet.Common/MsgPack/Types.cs index 7517533..56995c9 100644 --- a/AscNet.Common/MsgPack/Types.cs +++ b/AscNet.Common/MsgPack/Types.cs @@ -1025,6 +1025,13 @@ namespace AscNet.Common.MsgPack } + [global::MessagePack.MessagePackObject(true)] + public class NotifyGatherReward + { + public Int32 Id { get; set; } + } + + [global::MessagePack.MessagePackObject(true)] public class NotifyDrawTicketData { diff --git a/AscNet.GameServer/Handlers/ExhibitionModule.cs b/AscNet.GameServer/Handlers/ExhibitionModule.cs new file mode 100644 index 0000000..50a1c94 --- /dev/null +++ b/AscNet.GameServer/Handlers/ExhibitionModule.cs @@ -0,0 +1,76 @@ +using MessagePack; +using AscNet.Common.MsgPack; +using AscNet.Table.V2.share.exhibition; +using AscNet.Common.Util; +using AscNet.Table.V2.share.reward; + +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 GatherRewardRequest + { + public int Id; + } + + [MessagePackObject(true)] + public class GatherRewardResponse + { + public int Code; + public List RewardGoods { get; set; } = new(); + } +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + #endregion + + internal class ExhibitionModule + { + [RequestPacketHandler("GatherRewardRequest")] + public static void HandleGatherRewardRequestHandler(Session session, Packet.Request packet) + { + GatherRewardRequest req = MessagePackSerializer.Deserialize(packet.Content); + ExhibitionRewardTable? exhibitionReward = TableReaderV2.Parse().Find(x => x.Id == req.Id); + IEnumerable rewards = TableReaderV2.Parse().Where(x => (TableReaderV2.Parse().Find(x => x.Id == exhibitionReward?.RewardId)?.SubIds ?? new List()).Contains(x.Id)); + + GatherRewardResponse rsp = new(); + foreach (var rewardGoods in rewards) + { + int rewardTypeVal = (int)MathF.Floor((rewardGoods.TemplateId > 0 ? rewardGoods.TemplateId : rewardGoods.Id) / 1000000) + 1; + RewardType rewardType = RewardType.Item; + try + { + rewardType = (RewardType)Enum.ToObject(typeof(RewardType), rewardTypeVal); + } + catch (Exception) + { + session.log.Error($"Failed to convert {rewardTypeVal} to {nameof(RewardType)} enum object!"); + } + + rsp.RewardGoods.Add(new() + { + Id = rewardGoods.Id, + TemplateId = rewardGoods.TemplateId, + Count = rewardGoods.Count, + RewardType = rewardTypeVal + }); + + switch (rewardType) + { + case RewardType.Item: + NotifyItemDataList notifyItemData = new() + { + ItemDataList = { session.inventory.Do(rewardGoods.TemplateId, rewardGoods.Count) } + }; + session.SendPush(notifyItemData); + break; + default: + break; + } + } + + session.player.GatherRewards.Add(req.Id); + session.SendPush(new NotifyGatherReward() { Id = req.Id }); + session.SendResponse(rsp, packet.Id); + } + } +}