diff --git a/Common/Database/Inventory/InventoryData.cs b/Common/Database/Inventory/InventoryData.cs index db9888c..02cbf50 100644 --- a/Common/Database/Inventory/InventoryData.cs +++ b/Common/Database/Inventory/InventoryData.cs @@ -56,6 +56,7 @@ public abstract class GrowableItemInfo : BaseGameItemInfo public new uint Level { get; set; } public new uint Exp { get; set; } public uint Break { get; set; } + public uint Evolue { get; set; } public uint EquipAvatarId { get; set; } } @@ -73,7 +74,8 @@ public class GameWeaponInfo : GrowableItemInfo { Level = Level, Exp = Exp, - Break = Break + Break = Break, + Evolue = Evolue } }; return proto; diff --git a/GameServer/Server/CallGS/Handlers/Weapon/Weapon_Evolution.cs b/GameServer/Server/CallGS/Handlers/Weapon/Weapon_Evolution.cs new file mode 100644 index 0000000..bf8f9f1 --- /dev/null +++ b/GameServer/Server/CallGS/Handlers/Weapon/Weapon_Evolution.cs @@ -0,0 +1,77 @@ +using MikuSB.Database; +using MikuSB.Proto; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace MikuSB.GameServer.Server.CallGS.Handlers.Weapon; + +// s2c: function(sErr) — send "null" on success +// Id = target weapon UniqueId +// nItemId = material item UniqueId (weapon or supply item to consume) +[CallGSApi("Weapon_Evolution")] +public class Weapon_Evolution : ICallGSHandler +{ + public async Task Handle(Connection connection, string param, ushort seqNo) + { + var player = connection.Player!; + var req = JsonSerializer.Deserialize(param); + if (req == null || req.WeaponId == 0 || req.MaterialId == 0) + { + await CallGSRouter.SendScript(connection, "Weapon_Evolution", "\"error.BadParam\""); + return; + } + + var weapon = player.InventoryManager.InventoryData.Weapons.GetValueOrDefault((uint)req.WeaponId); + if (weapon == null) + { + await CallGSRouter.SendScript(connection, "Weapon_Evolution", "\"error.BadParam\""); + return; + } + + var syncItems = new List(); + + // Material can be a weapon or a regular item + if (player.InventoryManager.InventoryData.Weapons.TryGetValue((uint)req.MaterialId, out var matWeapon)) + { + player.InventoryManager.InventoryData.Weapons.Remove((uint)req.MaterialId); + var removed = matWeapon.ToProto(); + removed.Count = 0; + syncItems.Add(removed); + } + else if (player.InventoryManager.InventoryData.Items.TryGetValue((uint)req.MaterialId, out var matItem)) + { + matItem.ItemCount--; + var proto = matItem.ToProto(); + if (matItem.ItemCount == 0) + { + player.InventoryManager.InventoryData.Items.Remove(matItem.UniqueId); + proto.Count = 0; + } + syncItems.Add(proto); + } + else + { + await CallGSRouter.SendScript(connection, "Weapon_Evolution", "\"tip.not_material\""); + return; + } + + weapon.Evolue++; + syncItems.Add(weapon.ToProto()); + + DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData); + + var sync = new NtfSyncPlayer(); + sync.Items.AddRange(syncItems); + + await CallGSRouter.SendScript(connection, "Weapon_Evolution", "null", sync); + } +} + +internal sealed class WeaponEvolutionParam +{ + [JsonPropertyName("Id")] + public int WeaponId { get; set; } + + [JsonPropertyName("nItemId")] + public int MaterialId { get; set; } +} diff --git a/version.txt b/version.txt index ae6845b..45e88f8 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v=1.3 \ No newline at end of file +v=1.4 \ No newline at end of file