From 2883ac3d41b331305b5f72d91ae808d85be93f80 Mon Sep 17 00:00:00 2001 From: Naruse <71993948+DevilProMT@users.noreply.github.com> Date: Thu, 30 Apr 2026 17:18:23 +0800 Subject: [PATCH] add weapon parts --- Common/Data/Excel/WeaponPartsExcel.cs | 24 ++++++++++ Common/Data/GameData.cs | 1 + Common/Database/Inventory/InventoryData.cs | 2 + .../Message/LanguageCHS.cs | 2 + .../Message/LanguageCHT.cs | 2 + .../Message/LanguageEN.cs | 2 + GameServer/Command/Commands/CommandGiveAll.cs | 36 ++++++++++++++ GameServer/Game/Inventory/InventoryManager.cs | 21 +++++++++ .../Handlers/Girl/GirlSkinParts_Update.cs | 7 +-- .../Handlers/Weapon/Weapon_ReplacePart.cs | 47 +++++++++++++++++++ .../Handlers/Weapon/Weapon_ShowDefaultPart.cs | 43 +++++++++++++++++ Proxy/ProxyServer.cs | 2 +- 12 files changed, 182 insertions(+), 7 deletions(-) create mode 100644 Common/Data/Excel/WeaponPartsExcel.cs create mode 100644 GameServer/Server/CallGS/Handlers/Weapon/Weapon_ReplacePart.cs create mode 100644 GameServer/Server/CallGS/Handlers/Weapon/Weapon_ShowDefaultPart.cs diff --git a/Common/Data/Excel/WeaponPartsExcel.cs b/Common/Data/Excel/WeaponPartsExcel.cs new file mode 100644 index 0000000..45a2a0f --- /dev/null +++ b/Common/Data/Excel/WeaponPartsExcel.cs @@ -0,0 +1,24 @@ +using Newtonsoft.Json; + +namespace MikuSB.Data.Excel; + +[ResourceEntity("weapon_parts.json")] +public class WeaponPartsExcel : ExcelResource +{ + public uint Genre { get; set; } + public uint Detail { get; set; } + public uint Particular { get; set; } + public uint Level { get; set; } + public uint Icon { get; set; } + public int AppearID { get; set; } + public string I18n { get; set; } = ""; + public override uint GetId() + { + return (uint)I18n.GetHashCode(); + } + + public override void Loaded() + { + GameData.WeaponPartsData.Add(GetId(), this); + } +} \ No newline at end of file diff --git a/Common/Data/GameData.cs b/Common/Data/GameData.cs index 1a90c0c..8e538e2 100644 --- a/Common/Data/GameData.cs +++ b/Common/Data/GameData.cs @@ -25,6 +25,7 @@ public static class GameData public static Dictionary ProfileData { get; private set; } = []; public static Dictionary CardSkinPartsData { get; private set; } = []; public static Dictionary CallItemData { get; private set; } = []; + public static Dictionary WeaponPartsData { get; private set; } = []; } public static class GameResourceTemplateId diff --git a/Common/Database/Inventory/InventoryData.cs b/Common/Database/Inventory/InventoryData.cs index 3d1f89e..4c3125c 100644 --- a/Common/Database/Inventory/InventoryData.cs +++ b/Common/Database/Inventory/InventoryData.cs @@ -62,6 +62,7 @@ public abstract class GrowableItemInfo : BaseGameItemInfo public class GameWeaponInfo : GrowableItemInfo { + [SugarColumn(IsJson = true)] public Dictionary PartSlots { get; set; } = []; public override Item ToProto() { var proto = new Item @@ -78,6 +79,7 @@ public class GameWeaponInfo : GrowableItemInfo Evolue = Evolue } }; + foreach (var (slot, uid) in PartSlots) proto.Slots[slot] = uid; return proto; } } diff --git a/Common/Internationalization/Message/LanguageCHS.cs b/Common/Internationalization/Message/LanguageCHS.cs index f9f5ac4..36db113 100644 --- a/Common/Internationalization/Message/LanguageCHS.cs +++ b/Common/Internationalization/Message/LanguageCHS.cs @@ -35,6 +35,7 @@ public class ServerTextCHS /// public class WordTextCHS { + public string WeaponPart => "武器部件"; public string CallItem => "召唤道具"; public string SkinPart => "皮肤部件"; public string Profile => "个人资料"; @@ -246,6 +247,7 @@ public class GiveAllTextCHS "用法:/giveall card -p<特定> -l<等級>" + "用法:/giveall profile -g<类型> -p<特定> -l<等级>" + "用法:/giveall skinpart -g<類型> -p<特定> -l<等級>" + + "用法:/giveall weaponpart -g<類型> -p<特定> -l<等級>" + "用法:/giveall call -g<類型> -p<特定> -l<等級>"; public string NotFound => "未找到 {0}!"; public string GiveAllItems => "已向玩家添加 {0} 个 {1}!"; diff --git a/Common/Internationalization/Message/LanguageCHT.cs b/Common/Internationalization/Message/LanguageCHT.cs index 8ad0653..4a956d9 100644 --- a/Common/Internationalization/Message/LanguageCHT.cs +++ b/Common/Internationalization/Message/LanguageCHT.cs @@ -35,6 +35,7 @@ public class ServerTextCHT /// public class WordTextCHT { + public string WeaponPart => "武器部件"; public string CallItem => "召喚道具"; public string SkinPart => "外觀部件"; public string Profile => "個人資料"; @@ -246,6 +247,7 @@ public class GiveAllTextCHT "用法:/giveall card -p<特定> -l<等級>" + "用法:/giveall profile -g<類型> -p<特定> -l<等級>" + "用法:/giveall skinpart -g<類型> -p<特定> -l<等級>" + + "用法:/giveall weaponpart -g<類型> -p<特定> -l<等級>" + "用法:/giveall call -g<類型> -p<特定> -l<等級>"; public string NotFound => "未找到 {0}!"; public string GiveAllItems => "已向玩家添加 {0} 個 {1}!"; diff --git a/Common/Internationalization/Message/LanguageEN.cs b/Common/Internationalization/Message/LanguageEN.cs index 03d4f66..6e25631 100644 --- a/Common/Internationalization/Message/LanguageEN.cs +++ b/Common/Internationalization/Message/LanguageEN.cs @@ -35,6 +35,7 @@ public class ServerTextEN /// public class WordTextEN { + public string WeaponPart => "Weapon Part"; public string CallItem => "Call Item"; public string SkinPart => "Skin Part"; public string Profile => "Profile"; @@ -212,6 +213,7 @@ public class GiveAllTextEN "Usage: /giveall card -p -l" + "Usage: /giveall profile -g -p -l" + "Usage: /giveall skinpart -g -p -l" + + "Usage: /giveall weaponpart -g -p -l" + "Usage: /giveall call -g -p -l"; public string NotFound => "{0} not found!"; public string GiveAllItems => "Added {0} {1} to player!"; diff --git a/GameServer/Command/Commands/CommandGiveAll.cs b/GameServer/Command/Commands/CommandGiveAll.cs index 161fae9..52c39cf 100644 --- a/GameServer/Command/Commands/CommandGiveAll.cs +++ b/GameServer/Command/Commands/CommandGiveAll.cs @@ -222,4 +222,40 @@ public class CommandGiveAll : ICommands await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems", I18NManager.Translate("Word.CallItem"), callItems.Count.ToString())); } + + [CommandMethod("weaponpart")] + public async ValueTask GiveAllWeaponPart(CommandArg arg) + { + if (!await arg.CheckOnlineTarget()) return; + if (await arg.GetOption('p') is not int particular) return; + if (await arg.GetOption('l') is not int level) return; + if (await arg.GetOption('g') is not int genre) return; + + var detail = arg.GetInt(0); + var player = arg.Target!.Player!; + List weaponPartItems = []; + if (detail == -1) + { + // add all + foreach (var config in GameData.WeaponPartsData.Values) + { + var weaponPart = await player.InventoryManager! + .AddWeaponPartItem((ItemTypeEnum)config.Genre, config.Detail, config.Particular, config.Level, false); + if (weaponPart != null) weaponPartItems.Add(weaponPart); + } + } + else + { + var weaponPart = await player.InventoryManager!.AddWeaponPartItem((ItemTypeEnum)genre, (uint)detail, (uint)particular, (uint)level, false); + if (weaponPart == null) + { + await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.NotFound", I18NManager.Translate("Word.WeaponPart"))); + return; + } + weaponPartItems.Add(weaponPart); + } + if (weaponPartItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(weaponPartItems)); + await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems", + I18NManager.Translate("Word.WeaponPart"), weaponPartItems.Count.ToString())); + } } \ No newline at end of file diff --git a/GameServer/Game/Inventory/InventoryManager.cs b/GameServer/Game/Inventory/InventoryManager.cs index 27a8915..9300984 100644 --- a/GameServer/Game/Inventory/InventoryManager.cs +++ b/GameServer/Game/Inventory/InventoryManager.cs @@ -312,4 +312,25 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player) return callInfo; } + + public async ValueTask AddWeaponPartItem(ItemTypeEnum genre, uint detail, uint particular, uint level = 1, bool sendPacket = true) + { + if (genre != ItemTypeEnum.TYPE_WEAPON_PART) return null; + var weaponPartData = GameData.WeaponPartsData.Values.FirstOrDefault(x => x.Genre == (int)genre && x.Detail == detail && x.Particular == particular && x.Level == level); + if (weaponPartData == null) return null; + var templateId = GameResourceTemplateId.FromGdpl((uint)genre, detail, particular, level); + if (InventoryData.Items.Values.Any(x => x.TemplateId == templateId)) return null; + var weaponPartInfo = new BaseGameItemInfo + { + TemplateId = templateId, + UniqueId = InventoryData.NextUniqueUid++, + ItemType = genre, + ItemCount = 1 + }; + InventoryData.Items[weaponPartInfo.UniqueId] = weaponPartInfo; + + if (sendPacket) await Player.SendPacket(new PacketNtfCallScript([weaponPartInfo])); + + return weaponPartInfo; + } } \ No newline at end of file diff --git a/GameServer/Server/CallGS/Handlers/Girl/GirlSkinParts_Update.cs b/GameServer/Server/CallGS/Handlers/Girl/GirlSkinParts_Update.cs index f4e7f43..db21a5b 100644 --- a/GameServer/Server/CallGS/Handlers/Girl/GirlSkinParts_Update.cs +++ b/GameServer/Server/CallGS/Handlers/Girl/GirlSkinParts_Update.cs @@ -1,12 +1,7 @@ -using Azure; -using MikuSB.Data; -using MikuSB.Database; +using MikuSB.Data; using MikuSB.Database.Inventory; -using MikuSB.Enums.Item; -using MikuSB.GameServer.Game.Player; using MikuSB.Proto; using System.Text.Json; -using System.Text.Json.Nodes; using System.Text.Json.Serialization; namespace MikuSB.GameServer.Server.CallGS.Handlers.Girl; diff --git a/GameServer/Server/CallGS/Handlers/Weapon/Weapon_ReplacePart.cs b/GameServer/Server/CallGS/Handlers/Weapon/Weapon_ReplacePart.cs new file mode 100644 index 0000000..d06e715 --- /dev/null +++ b/GameServer/Server/CallGS/Handlers/Weapon/Weapon_ReplacePart.cs @@ -0,0 +1,47 @@ +using MikuSB.Proto; +using System.Text.Json; + +namespace MikuSB.GameServer.Server.CallGS.Handlers.Girl; + +[CallGSApi("Weapon_ReplacePart")] +public class Weapon_ReplacePart : ICallGSHandler +{ + public async Task Handle(Connection connection, string param, ushort seqNo) + { + var req = JsonSerializer.Deserialize(param); + if (req == null) + { + await CallGSRouter.SendScript(connection, "Weapon_ReplacePart", "{\"sErr\":\"error.BadParam\"}"); + return; + } + + var player = connection.Player!; + var weaponData = player.InventoryManager.GetWeaponItem(req.Id); + if (weaponData == null) + { + await CallGSRouter.SendScript(connection, "Weapon_ReplacePart", "{}"); + return; + } + + uint partId = 0; + if (req.PartId != -1) + { + var partData = player.InventoryManager.GetNormalItem((uint)req.PartId); + if (partData != null) partId = partData.UniqueId; + } + + weaponData.PartSlots[req.Type] = partId; + var sync = new NtfSyncPlayer + { + Items = { weaponData.ToProto() } + }; + await CallGSRouter.SendScript(connection, "Weapon_ReplacePart", "null", sync); + } +} + +internal sealed class WeaponPartReplaceParam +{ + public int PartId { get; set; } + public uint Type { get; set; } + public uint Id { get; set; } +} \ No newline at end of file diff --git a/GameServer/Server/CallGS/Handlers/Weapon/Weapon_ShowDefaultPart.cs b/GameServer/Server/CallGS/Handlers/Weapon/Weapon_ShowDefaultPart.cs new file mode 100644 index 0000000..76b46fe --- /dev/null +++ b/GameServer/Server/CallGS/Handlers/Weapon/Weapon_ShowDefaultPart.cs @@ -0,0 +1,43 @@ +using MikuSB.Enums.Item; +using MikuSB.Proto; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace MikuSB.GameServer.Server.CallGS.Handlers.Girl; + +[CallGSApi("Weapon_ShowDefaultPart")] +public class Weapon_ShowDefaultPart : ICallGSHandler +{ + public async Task Handle(Connection connection, string param, ushort seqNo) + { + var req = JsonSerializer.Deserialize(param); + if (req == null) + { + await CallGSRouter.SendScript(connection, "Weapon_ShowDefaultPart", "{\"sErr\":\"error.BadParam\"}"); + return; + } + + var player = connection.Player!; + var weaponData = player.InventoryManager.GetWeaponItem(req.Id); + if (weaponData == null) + { + await CallGSRouter.SendScript(connection, "Weapon_ShowDefaultPart", "{}"); + return; + } + + if (req.Flag == 1) weaponData.Flag = ItemFlagEnum.FLAG_WEAPON_DEFAULT; + else weaponData.Flag = ItemFlagEnum.FLAG_READED; + + var sync = new NtfSyncPlayer + { + Items = { weaponData.ToProto() } + }; + await CallGSRouter.SendScript(connection, "Weapon_ShowDefaultPart", "null", sync); + } +} + +internal sealed class WeaponShowDefaultPartParam +{ + [JsonPropertyName("nFlag")] public int Flag { get; set; } + public uint Id { get; set; } +} \ No newline at end of file diff --git a/Proxy/ProxyServer.cs b/Proxy/ProxyServer.cs index 68785c4..085702f 100644 --- a/Proxy/ProxyServer.cs +++ b/Proxy/ProxyServer.cs @@ -198,7 +198,7 @@ public sealed class ProxyServer( { var pathAndQuery = request.GetPathAndQuery(); var uri = new Uri($"http://{ServerHost}:{_options.ServerHttpPort}{pathAndQuery}"); - logger.Info($"Redirect: {request.Method} {request.HostOverride ?? request.Host}{pathAndQuery} -> {uri}"); + if (ConfigManager.Config.HttpServer.EnableLog) logger.Info($"Redirect: {request.Method} {request.HostOverride ?? request.Host}{pathAndQuery} -> {uri}"); await SendHttpRequestAsync(clientStream, request, uri, true, cancellationToken); }