From eac3e558d45bb4b348ddcae1d6b7e96ad3e505bd Mon Sep 17 00:00:00 2001 From: rfi Date: Sun, 24 Dec 2023 18:29:17 +0700 Subject: [PATCH] =?UTF-8?q?it's=20done=20lolol=20=F0=9F=A4=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AscNet.Common/Database/Inventory.cs | 6 ++- AscNet.GameServer/Game/DrawManager.cs | 7 +-- AscNet.GameServer/Handlers/DrawModule.cs | 55 ++++++++++++++++++++++++ README.md | 3 +- 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/AscNet.Common/Database/Inventory.cs b/AscNet.Common/Database/Inventory.cs index 3dd363a6..5fe346a3 100644 --- a/AscNet.Common/Database/Inventory.cs +++ b/AscNet.Common/Database/Inventory.cs @@ -1,4 +1,6 @@ using AscNet.Common.MsgPack; +using AscNet.Common.Util; +using AscNet.Table.V2.share.item; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver; @@ -72,7 +74,9 @@ namespace AscNet.Common.Database public Item Do(int itemId, int amount) { Item? item = Items.FirstOrDefault(x => x.Id == itemId); - if (item is not null) + ItemTable? itemTable = TableReaderV2.Parse().Find(x => x.Id == itemId); + + if (item is not null && itemTable is not null && itemTable.MaxCount <= item.Count + amount) { item.Count += amount; item.RefreshTime = DateTimeOffset.Now.ToUnixTimeSeconds(); diff --git a/AscNet.GameServer/Game/DrawManager.cs b/AscNet.GameServer/Game/DrawManager.cs index 5eee9ea9..1f468c95 100644 --- a/AscNet.GameServer/Game/DrawManager.cs +++ b/AscNet.GameServer/Game/DrawManager.cs @@ -78,7 +78,7 @@ namespace AscNet.GameServer.Game { Id = x.Id, UseItemId = Inventory.FreeGem, - UseItemCount = 1, + UseItemCount = 250, GroupId = GroupArrivalConstruct, BtnDrawCount = { 1, 10 }, Banner = "Assets/Product/Ui/Scene3DPrefab/UiMain3dXiahuo.prefab", @@ -96,7 +96,7 @@ namespace AscNet.GameServer.Game { Id = x.Id, UseItemId = Inventory.FreeGem, - UseItemCount = 1, + UseItemCount = 250, GroupId = GroupMemberTarget, BtnDrawCount = { 1, 10 }, Banner = "Assets/Product/Ui/Scene3DPrefab/UiMain3dXiahuo.prefab", @@ -138,7 +138,7 @@ namespace AscNet.GameServer.Game { case 1: // Character - if (random >= 0.98f) + if (random >= 0.972f) { // S Character float rate = Random.Shared.NextSingle(); @@ -345,6 +345,7 @@ namespace AscNet.GameServer.Game { RewardType = (int)RewardType.Character, Quality = characterQuality?.Quality ?? 0, + Count = 1, TemplateId = rand }); } diff --git a/AscNet.GameServer/Handlers/DrawModule.cs b/AscNet.GameServer/Handlers/DrawModule.cs index 42d45db9..a907b2e0 100644 --- a/AscNet.GameServer/Handlers/DrawModule.cs +++ b/AscNet.GameServer/Handlers/DrawModule.cs @@ -1,5 +1,7 @@ using AscNet.Common.MsgPack; +using AscNet.Common.Util; using AscNet.GameServer.Game; +using AscNet.Table.V2.share.character; using MessagePack; namespace AscNet.GameServer.Handlers @@ -157,9 +159,62 @@ namespace AscNet.GameServer.Handlers rsp.RewardGoodsList.AddRange(DrawManager.DrawDraw(request.DrawId)); } + // Post-processing and adding items to user's db + NotifyItemDataList notifyItemData = new(); + NotifyEquipDataList notifyEquipData = new(); + NotifyCharacterDataList notifyCharacterData = new(); + FashionSyncNotify fashionSync = new(); + foreach (var item in rsp.RewardGoodsList) + { + switch ((RewardType)item.RewardType) + { + case RewardType.Item: + notifyItemData.ItemDataList.Add(session.inventory.Do(item.TemplateId, item.Count)); + break; + case RewardType.Equip: + notifyEquipData.EquipDataList.Add(session.character.AddEquip((uint)item.TemplateId)); + break; + case RewardType.Character: + if (session.character.Characters.Any(x => x.Id == item.TemplateId)) + { + CharacterTable? characterData = TableReaderV2.Parse().Find(x => x.Id == item.TemplateId); + if (characterData is not null) + { + item.ConvertFrom = characterData.Id; + item.TemplateId = characterData.ItemId; + item.Count = 18; + item.RewardType = (int)RewardType.Item; + notifyItemData.ItemDataList.Add(session.inventory.Do(item.TemplateId, item.Count)); + } + } + else + { + var ret = session.character.AddCharacter((uint)item.TemplateId); + notifyCharacterData.CharacterDataList.Add(ret.Character); + fashionSync.FashionList.Add(ret.Fashion); + notifyEquipData.EquipDataList.Add(ret.Equip); + } + break; + default: + break; + } + } + DrawInfo? drawInfo = DrawManager.GetDrawInfosByGroup(DrawManager.GetGroupByDrawId(request.DrawId)).Find(x => x.Id == request.DrawId); if (drawInfo is not null) + { rsp.ClientDrawInfo = drawInfo; + notifyItemData.ItemDataList.Add(session.inventory.Do(drawInfo.UseItemId, drawInfo.UseItemCount * -1)); + } + + if (notifyItemData.ItemDataList.Count > 0) + session.SendPush(notifyItemData); + if (notifyEquipData.EquipDataList.Count > 0) + session.SendPush(notifyEquipData); + if (fashionSync.FashionList.Count > 0) + session.SendPush(fashionSync); + if (notifyCharacterData.CharacterDataList.Count > 0) + session.SendPush(notifyCharacterData); session.SendResponse(rsp, packet.Id); } diff --git a/README.md b/README.md index 161dcee0..e3b62219 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# AscNet \ No newline at end of file +# AscNet +A private server emulator for 战双帕弥什 (Punishing: Gray Raven) \ No newline at end of file