diff --git a/Common/Database/Inventory/InventoryData.cs b/Common/Database/Inventory/InventoryData.cs index ad76a9e..57fc0ff 100644 --- a/Common/Database/Inventory/InventoryData.cs +++ b/Common/Database/Inventory/InventoryData.cs @@ -1,6 +1,6 @@ -using KianaBH.Proto; +using KianaBH.Data; +using KianaBH.Proto; using SqlSugar; -using static System.Runtime.InteropServices.JavaScript.JSType; namespace KianaBH.Database.Inventory; @@ -65,14 +65,14 @@ public class ItemData { return new Stigmata { - Id= (uint)ItemId, - UniqueId= (uint)UniqueId, - Level= (uint)Level, - Exp= (uint)Exp, + Id = (uint)ItemId, + UniqueId = (uint)UniqueId, + Level = (uint)Level, + Exp = (uint)Exp, SlotNum = (uint)SlotNum, RefineValue = (uint)RefineValue, PromoteTimes = (uint)PromoteTimes, - IsProtected= IsLocked, + IsProtected = IsLocked, IsAffixIdentify = IsAffixIdentify, RuneList = { @@ -97,7 +97,7 @@ public class ItemData UniqueId = (uint)x.UniqueId, RuneList = { - RuneLists.Select(l => new StigmataRune + x.RuneLists.Select(l => new StigmataRune { RuneId = (uint)l.RuneId, StrengthPercent = (uint)l.Strength, @@ -107,6 +107,46 @@ public class ItemData } }; } + + public List ToWaitSelectRuneGroup() + { + return WaitSelectRuneGroupLists.Select(x => new StigmataRuneGroup + { + UniqueId = (uint)x.UniqueId, + RuneList = + { + x.RuneLists.Select(l => new StigmataRune + { + RuneId = (uint)l.RuneId, + StrengthPercent = (uint)l.Strength, + }) + } + }).ToList(); + } + + public StigmataRune AddRune(int min = 1, int max = 4) + { + var proto = new StigmataRune + { + RuneId = GenerateAffixId(), + StrengthPercent = GenerateAffixStrength() + }; + return proto; + } + + private uint GenerateAffixId() + { + Random _random = new Random(); + var affixKeys = GameData.AffixListData.Keys.ToList(); + int affixBase = affixKeys[_random.Next(affixKeys.Count)]; + return (uint)affixBase; + } + + private uint GenerateAffixStrength(int min = 1, int max = 101) + => (uint)(new Random().Next( + min > 0 && min < max ? min : 1, max > min && max < 102 ? max : 101 + )); + } public class RuneGroup diff --git a/GameServer/Game/Inventory/InventoryManager.cs b/GameServer/Game/Inventory/InventoryManager.cs index 6e296d0..b63049c 100644 --- a/GameServer/Game/Inventory/InventoryManager.cs +++ b/GameServer/Game/Inventory/InventoryManager.cs @@ -4,6 +4,7 @@ using KianaBH.Database.Inventory; using KianaBH.Enums.Item; using KianaBH.GameServer.Game.Player; using KianaBH.GameServer.Server.Packet.Send.Item; +using KianaBH.Proto; using KianaBH.Util; namespace KianaBH.GameServer.Game.Inventory; @@ -200,4 +201,99 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player) await Player.SyncValk(); } + + public async ValueTask GenerateRune(int uniqueId, StigmataRefineType type, StigmataRefineTimesType times, int lockRuneIndex) + { + var item = Data.StigmataItems.Find(x => x.UniqueId == uniqueId); + if (item == null) return; + + + var proto = new StigmataRuneGroup + { + UniqueId = (uint)uniqueId, + }; + + switch (type) + { + case StigmataRefineType.StigmataRefineAddSlot: + if (item.SlotNum >= 2) return; + item.SlotNum++; + proto.RuneList.Add(item.AddRune()); + item.WaitSelectRuneGroupLists.Add(new RuneGroup + { + UniqueId = uniqueId, + RuneLists = proto.RuneList.Select(x => new Rune + { + RuneId = (int)x.RuneId, + Strength = (int)x.StrengthPercent, + }).ToList() + }); + break; + case StigmataRefineType.StigmataRefineNormal: + item.WaitSelectRuneGroupLists.Clear(); + if (times == StigmataRefineTimesType.StigmataRefineTimesTen) + { + for (int i = 0; i < 10; i++) + { + var runeList = new List + { + item.AddRune(), + item.AddRune(), + }; + + proto.RuneList.AddRange(runeList); + + item.WaitSelectRuneGroupLists.Add(new RuneGroup + { + UniqueId = uniqueId++, + RuneLists = runeList.Select(x => new Rune + { + RuneId = (int)x.RuneId, + Strength = (int)x.StrengthPercent, + }).ToList() + }); + } + } + else // One Time + { + if (item.SlotNum < 2 && new Random().Next(0, 10) == 9) item.SlotNum++; + if (item.SlotNum >= 1) proto.RuneList.Add(item.AddRune()); + if (item.SlotNum == 2) proto.RuneList.Add(item.AddRune()); + + item.WaitSelectRuneGroupLists.Add(new RuneGroup + { + UniqueId = uniqueId++, + RuneLists = proto.RuneList.Select(x => new Rune + { + RuneId = (int)x.RuneId, + Strength = (int)x.StrengthPercent, + }).ToList() + }); + } + break; + } + await Player.SyncInventory(); + } + + + public async ValueTask SelectRune(int uniqueId, int selectUniqueId) + { + var item = Data.StigmataItems.Find(x => x.UniqueId == uniqueId); + if (item == null) return; + + var select = item.WaitSelectRuneGroupLists.Find(x => x.UniqueId == selectUniqueId); + if (select == null) return; + + item.RuneLists.Clear(); + item.RuneLists.AddRange( + select.RuneLists.Select(x => new Rune + { + RuneId = x.RuneId, + Strength = x.Strength + }) + ); + item.WaitSelectRuneGroupLists.Clear(); + + await Player.SyncInventory(); + } } \ No newline at end of file diff --git a/GameServer/Server/Packet/Recv/Item/HandlerRefineStigmataRuneReq.cs b/GameServer/Server/Packet/Recv/Item/HandlerRefineStigmataRuneReq.cs new file mode 100644 index 0000000..5b4866a --- /dev/null +++ b/GameServer/Server/Packet/Recv/Item/HandlerRefineStigmataRuneReq.cs @@ -0,0 +1,17 @@ +using KianaBH.GameServer.Server.Packet.Send.Item; +using KianaBH.Proto; + +namespace KianaBH.GameServer.Server.Packet.Recv.Item; + +[Opcode(CmdIds.RefineStigmataRuneReq)] +public class HandlerRefineStigmataRuneReq : Handler +{ + public override async Task OnHandle(Connection connection, byte[] header, byte[] data) + { + var req = RefineStigmataRuneReq.Parser.ParseFrom(data); + var player = connection.Player!; + + await player.InventoryManager!.GenerateRune((int)req.UniqueId,req.Type,req.TimesType,(int)req.LockRuneIndex); + await connection.SendPacket(new PacketRefineStigmataRuneRsp(player,(int)req.UniqueId, req.TimesType)); + } +} diff --git a/GameServer/Server/Packet/Recv/Item/HandlerSelectNewStigmataRuneReq.cs b/GameServer/Server/Packet/Recv/Item/HandlerSelectNewStigmataRuneReq.cs new file mode 100644 index 0000000..c119aff --- /dev/null +++ b/GameServer/Server/Packet/Recv/Item/HandlerSelectNewStigmataRuneReq.cs @@ -0,0 +1,21 @@ +using KianaBH.GameServer.Server.Packet.Send.Item; +using KianaBH.Proto; + +namespace KianaBH.GameServer.Server.Packet.Recv.Item; + +[Opcode(CmdIds.SelectNewStigmataRuneReq)] +public class HandlerSelectNewStigmataRuneReq : Handler +{ + public override async Task OnHandle(Connection connection, byte[] header, byte[] data) + { + var req = SelectNewStigmataRuneReq.Parser.ParseFrom(data); + var player = connection.Player!; + + if (req.IsSelect && req.SelectUniqueId > 0) + { + await player.InventoryManager!.SelectRune((int)req.UniqueId, (int)req.SelectUniqueId); + } + + await connection.SendPacket(new PacketSelectNewStigmataRuneRsp(req.SelectUniqueId,req.IsSelect)); + } +} diff --git a/GameServer/Server/Packet/Recv/Test/HandlerRefineStigmataRuneReq.cs b/GameServer/Server/Packet/Recv/Test/HandlerRefineStigmataRuneReq.cs deleted file mode 100644 index 63ee138..0000000 --- a/GameServer/Server/Packet/Recv/Test/HandlerRefineStigmataRuneReq.cs +++ /dev/null @@ -1,13 +0,0 @@ -using KianaBH.GameServer.Server.Packet.Send.Test; -using KianaBH.Proto; - -namespace KianaBH.GameServer.Server.Packet.Recv.Test; - -[Opcode(CmdIds.RefineStigmataRuneReq)] -public class HandlerRefineStigmataRuneReq : Handler -{ - public override async Task OnHandle(Connection connection, byte[] header, byte[] data) - { - await connection.SendPacket(new PacketRefineStigmataRuneRsp()); - } -} diff --git a/GameServer/Server/Packet/Recv/Test/HandlerSelectNewStigmataRuneReq.cs b/GameServer/Server/Packet/Recv/Test/HandlerSelectNewStigmataRuneReq.cs deleted file mode 100644 index 281ecc5..0000000 --- a/GameServer/Server/Packet/Recv/Test/HandlerSelectNewStigmataRuneReq.cs +++ /dev/null @@ -1,13 +0,0 @@ -using KianaBH.GameServer.Server.Packet.Send.Test; -using KianaBH.Proto; - -namespace KianaBH.GameServer.Server.Packet.Recv.Test; - -[Opcode(CmdIds.SelectNewStigmataRuneReq)] -public class HandlerSelectNewStigmataRuneReq : Handler -{ - public override async Task OnHandle(Connection connection, byte[] header, byte[] data) - { - await connection.SendPacket(new PacketSelectNewStigmataRuneRsp()); - } -} diff --git a/GameServer/Server/Packet/Send/Test/PacketRefineStigmataRuneRsp.cs b/GameServer/Server/Packet/Send/Test/PacketRefineStigmataRuneRsp.cs index f22c7f0..441902a 100644 --- a/GameServer/Server/Packet/Send/Test/PacketRefineStigmataRuneRsp.cs +++ b/GameServer/Server/Packet/Send/Test/PacketRefineStigmataRuneRsp.cs @@ -1,15 +1,17 @@ +using KianaBH.GameServer.Game.Player; using KianaBH.KcpSharp; using KianaBH.Proto; -namespace KianaBH.GameServer.Server.Packet.Send.Test; +namespace KianaBH.GameServer.Server.Packet.Send.Item; public class PacketRefineStigmataRuneRsp : BasePacket { - public PacketRefineStigmataRuneRsp() : base(CmdIds.RefineStigmataRuneRsp) + public PacketRefineStigmataRuneRsp(PlayerInstance player,int uniqueId, StigmataRefineTimesType type) : base(CmdIds.RefineStigmataRuneRsp) { var proto = new RefineStigmataRuneRsp { - + RuneGroupList = { player.InventoryManager!.Data!.StigmataItems.Find(x => x.UniqueId == uniqueId)!.ToWaitSelectRuneGroup() }, + TimesType = type }; SetData(proto); diff --git a/GameServer/Server/Packet/Send/Test/PacketSelectNewStigmataRuneRsp.cs b/GameServer/Server/Packet/Send/Test/PacketSelectNewStigmataRuneRsp.cs index dddae1c..6730cc2 100644 --- a/GameServer/Server/Packet/Send/Test/PacketSelectNewStigmataRuneRsp.cs +++ b/GameServer/Server/Packet/Send/Test/PacketSelectNewStigmataRuneRsp.cs @@ -1,15 +1,16 @@ using KianaBH.KcpSharp; using KianaBH.Proto; -namespace KianaBH.GameServer.Server.Packet.Send.Test; +namespace KianaBH.GameServer.Server.Packet.Send.Item; public class PacketSelectNewStigmataRuneRsp : BasePacket { - public PacketSelectNewStigmataRuneRsp() : base(CmdIds.SelectNewStigmataRuneRsp) + public PacketSelectNewStigmataRuneRsp(uint selectUniqueId, bool isSelect) : base(CmdIds.SelectNewStigmataRuneRsp) { var proto = new SelectNewStigmataRuneRsp { - + SelectUniqueId = selectUniqueId, + IsSelect = isSelect }; SetData(proto);