From 657ee823f7e669fdf42f3e3213f0b26bd484523c Mon Sep 17 00:00:00 2001 From: oureveryday Date: Sun, 7 Jul 2024 10:58:52 +0800 Subject: [PATCH] Very Simple RollShop Implement --- Common/Data/Excel/RollShopConfigExcel.cs | 46 +++++++++++++ Common/Data/Excel/RollShopRewardExcel.cs | 26 ++++++++ Common/Data/GameData.cs | 2 + .../Shop/HandlerDoGachaInRollShopCsReq.cs | 66 +++++++++++++++++++ .../Recv/Shop/HandlerGetRollShopInfoCsReq.cs | 21 ++++++ .../Send/Shop/PacketDoGachaInRollShopScRsp.cs | 26 ++++++++ .../Shop/PacketGetRollShopInfoScRsp.cs.cs | 37 +++++++++++ 7 files changed, 224 insertions(+) create mode 100644 Common/Data/Excel/RollShopConfigExcel.cs create mode 100644 Common/Data/Excel/RollShopRewardExcel.cs create mode 100644 GameServer/Server/Packet/Recv/Shop/HandlerDoGachaInRollShopCsReq.cs create mode 100644 GameServer/Server/Packet/Recv/Shop/HandlerGetRollShopInfoCsReq.cs create mode 100644 GameServer/Server/Packet/Send/Shop/PacketDoGachaInRollShopScRsp.cs create mode 100644 GameServer/Server/Packet/Send/Shop/PacketGetRollShopInfoScRsp.cs.cs diff --git a/Common/Data/Excel/RollShopConfigExcel.cs b/Common/Data/Excel/RollShopConfigExcel.cs new file mode 100644 index 00000000..8516bb3d --- /dev/null +++ b/Common/Data/Excel/RollShopConfigExcel.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EggLink.DanhengServer.Data.Excel +{ + [ResourceEntity("RollShopConfig.json")] + public class RollShopConfigExcel : ExcelResource + { + public int RollShopID { get; set; } + public List SpecialGroupList { get; set; } = new List(); + public uint CostItemID { get; set; } + public uint CostItemNum { get; set; } + public uint T1GroupID { get; set; } + public uint T2GroupID { get; set; } + public uint T3GroupID { get; set; } + public uint T4GroupID { get; set; } + public uint SecretGroupID { get; set; } + public string RollShopType { get; set; } + public uint IntroduceID { get; set; } + public ShopName ShopName { get; set; } + + public override int GetId() + { + return RollShopID; + } + + public override void Loaded() + { + GameData.RollShopConfigData.Add(GetId(), this); + } + } + + public class SpecialGroup + { + public string GroupID { get; set; } + public int GroupValue { get; set; } + } + + public class ShopName + { + public int Hash { get; set; } + } +} diff --git a/Common/Data/Excel/RollShopRewardExcel.cs b/Common/Data/Excel/RollShopRewardExcel.cs new file mode 100644 index 00000000..ea14d427 --- /dev/null +++ b/Common/Data/Excel/RollShopRewardExcel.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EggLink.DanhengServer.Data.Excel +{ + [ResourceEntity("RollShopReward.json")] + public class RollShopRewardExcel : ExcelResource + { + public uint GroupID { get; set; } + public uint RewardID { get; set; } + + public override int GetId() + { + return (int)RewardID; + } + + + public override void Loaded() + { + GameData.RollShopRewardData.Add(GetId(), this); + } + } +} diff --git a/Common/Data/GameData.cs b/Common/Data/GameData.cs index e4ba84cc..08733bc7 100644 --- a/Common/Data/GameData.cs +++ b/Common/Data/GameData.cs @@ -128,6 +128,8 @@ namespace EggLink.DanhengServer.Data #region Item Exchange public static Dictionary ShopConfigData { get; private set; } = []; + public static Dictionary RollShopConfigData { get; private set; } = []; + public static Dictionary RollShopRewardData { get; private set; } = []; public static Dictionary ItemComposeConfigData { get; private set; } = []; #endregion diff --git a/GameServer/Server/Packet/Recv/Shop/HandlerDoGachaInRollShopCsReq.cs b/GameServer/Server/Packet/Recv/Shop/HandlerDoGachaInRollShopCsReq.cs new file mode 100644 index 00000000..87360970 --- /dev/null +++ b/GameServer/Server/Packet/Recv/Shop/HandlerDoGachaInRollShopCsReq.cs @@ -0,0 +1,66 @@ +using EggLink.DanhengServer.Data; +using EggLink.DanhengServer.Database.Inventory; +using EggLink.DanhengServer.Proto; +using EggLink.DanhengServer.Server.Packet.Send.Challenge; +using EggLink.DanhengServer.Server.Packet.Send.Gacha; +using EggLink.DanhengServer.Server.Packet.Send.Shop; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EggLink.DanhengServer.Server.Packet.Recv.Shop +{ + [Opcode(CmdIds.DoGachaInRollShopCsReq)] + public class HandlerDoGachaInRollShopCsReq : Handler + { + public override void OnHandle(Connection connection, byte[] header, byte[] data) + { + var req = DoGachaInRollShopCsReq.Parser.ParseFrom(data); + ItemList itemList = new(); + var count = req.JLLODFFJGDM; + uint maxtype = 3; + for (uint i = 0; i < count; i++) + { + Dictionary GroupIds = new(); + Dictionary RewardIds = new(); + + GameData.RollShopConfigData.Values.ToList().ForEach(x => + { + if (x.RollShopID == req.RollShopId) + { + GroupIds.Add(x.T1GroupID,1); + GroupIds.Add(x.T2GroupID,2); + GroupIds.Add(x.T3GroupID,3); + GroupIds.Add(x.T4GroupID,4); + } + }); + GameData.RollShopRewardData.Values.ToList().ForEach(x => + { + GroupIds.Keys.ToList().ForEach(y => + { + if (x.GroupID == y) + { + RewardIds.Add(x.RewardID, GroupIds[y]); + } + }); + }); + var RewardId = RewardIds.Keys.ToList()[new Random().Next(0, RewardIds.Count)]; + var type = RewardIds[RewardId]; + if (type < maxtype) maxtype = type; + var rewardExcel = GameData.RewardDataData[(int)RewardId]; + var rewardItems = rewardExcel.GetItems(); + var itemData = new ItemData() + { + ItemId = rewardItems[0].Item1, + Count = rewardItems[0].Item2 + }; + + itemList.ItemList_.Add(itemData.ToProto()); + connection.Player!.InventoryManager!.RemoveItem(122000, 1); + } + connection.SendPacket(new PacketDoGachaInRollShopScRsp(req.RollShopId, itemList, maxtype)); + } + } +} \ No newline at end of file diff --git a/GameServer/Server/Packet/Recv/Shop/HandlerGetRollShopInfoCsReq.cs b/GameServer/Server/Packet/Recv/Shop/HandlerGetRollShopInfoCsReq.cs new file mode 100644 index 00000000..e13e184d --- /dev/null +++ b/GameServer/Server/Packet/Recv/Shop/HandlerGetRollShopInfoCsReq.cs @@ -0,0 +1,21 @@ +using EggLink.DanhengServer.Proto; +using EggLink.DanhengServer.Server.Packet.Send.Shop; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EggLink.DanhengServer.Server.Packet.Recv.Shop +{ + [Opcode(CmdIds.GetRollShopInfoCsReq)] + public class HandlerGetRollShopInfoCsReq : Handler + { + public override void OnHandle(Connection connection, byte[] header, byte[] data) + { + var req = GetRollShopInfoCsReq.Parser.ParseFrom(data); + + connection.SendPacket(new PacketGetRollShopInfoScRsp(req.RollShopId)); + } + } +} \ No newline at end of file diff --git a/GameServer/Server/Packet/Send/Shop/PacketDoGachaInRollShopScRsp.cs b/GameServer/Server/Packet/Send/Shop/PacketDoGachaInRollShopScRsp.cs new file mode 100644 index 00000000..a1d61b4f --- /dev/null +++ b/GameServer/Server/Packet/Send/Shop/PacketDoGachaInRollShopScRsp.cs @@ -0,0 +1,26 @@ +using EggLink.DanhengServer.Data; +using EggLink.DanhengServer.Proto; +using EggLink.DanhengServer.Proto; +using EggLink.DanhengServer.Server.Packet.Send.Challenge; +using Org.BouncyCastle.Ocsp; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; + + +namespace EggLink.DanhengServer.Server.Packet.Send.Shop +{ + public class PacketDoGachaInRollShopScRsp : BasePacket + { + public PacketDoGachaInRollShopScRsp(uint RollShopId, ItemList reward, uint type) : base(CmdIds.DoGachaInRollShopScRsp) + { + var proto = new DoGachaInRollShopScRsp(); + + proto.RollShopId = RollShopId; + proto.MJCIOJJKGMI = type; //Reward type display + proto.JCPIIANIDML = 0; + proto.Reward = reward; + proto.Retcode = 0; ; + + SetData(proto); + } + } +} diff --git a/GameServer/Server/Packet/Send/Shop/PacketGetRollShopInfoScRsp.cs.cs b/GameServer/Server/Packet/Send/Shop/PacketGetRollShopInfoScRsp.cs.cs new file mode 100644 index 00000000..6e406bfc --- /dev/null +++ b/GameServer/Server/Packet/Send/Shop/PacketGetRollShopInfoScRsp.cs.cs @@ -0,0 +1,37 @@ +using EggLink.DanhengServer.Data; +using EggLink.DanhengServer.Proto; +using Microsoft.OpenApi.Writers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EggLink.DanhengServer.Server.Packet.Send.Shop +{ + public class PacketGetRollShopInfoScRsp : BasePacket + { + public PacketGetRollShopInfoScRsp(uint rollShopId) : base(CmdIds.GetRollShopInfoScRsp) + { + var proto = new GetRollShopInfoScRsp(); + + proto.RollShopId = rollShopId; + proto.GachaRandom = 1; + + foreach (var item in GameData.RollShopConfigData.Values) + { + if (item.RollShopID == rollShopId) + { + proto.NOPNEOADJEI.Add(item.T1GroupID); + proto.NOPNEOADJEI.Add(item.T2GroupID); + proto.NOPNEOADJEI.Add(item.T3GroupID); + proto.NOPNEOADJEI.Add(item.T4GroupID); + } + } + + proto.Retcode = 0; + + SetData(proto); + } + } +}