From 47b14f5c07f75ab34af4d8935bc55485da17aeca Mon Sep 17 00:00:00 2001
From: Naruse <71993948+DevilProMT@users.noreply.github.com>
Date: Sat, 14 Jun 2025 21:23:14 +0800
Subject: [PATCH] feat: add giveall command
---
.../Message/LanguageEN.cs | 16 ++++++++++-
GameServer/Command/Commands/CommandGiveAll.cs | 22 +++++++++++++++
GameServer/Game/Player/PlayerInstance.cs | 5 ++++
KianaBH/Tool/HandbookGenerator.cs | 28 ++++++++++---------
4 files changed, 57 insertions(+), 14 deletions(-)
create mode 100644 GameServer/Command/Commands/CommandGiveAll.cs
diff --git a/Common/Internationalization/Message/LanguageEN.cs b/Common/Internationalization/Message/LanguageEN.cs
index 9c5a58f..0854c75 100644
--- a/Common/Internationalization/Message/LanguageEN.cs
+++ b/Common/Internationalization/Message/LanguageEN.cs
@@ -40,7 +40,7 @@ public class WordTextEN
public string Material => "Material";
public string Pet => "Pet";
public string Relic => "Relic";
- public string Equipment => "Light Cone";
+ public string Weapon => "Weapon";
public string Talent => "Talent";
public string Banner => "Gacha";
public string Activity => "Activity";
@@ -120,6 +120,7 @@ public class CommandTextEN
public NoticeTextEN Notice { get; } = new();
public HelpTextEN Help { get; } = new();
public ValkTextEN Valk { get; } = new();
+ public GiveAllTextEN GiveAll { get; } = new();
}
#endregion
@@ -238,6 +239,19 @@ public class ValkTextEN
public string ValkSetSkillLevel => "Set character {0}'s skill levels to max!";
}
+///
+/// path: Game.Command.GiveAll
+///
+public class GiveAllTextEN
+{
+ public string Desc => "Give all items of specified type\n" +
+ "weapon: weapons";
+
+ public string Usage =>
+ "Usage: /giveall weapon";
+
+ public string GiveAllItems => "Granted all {0}";
+}
#endregion
diff --git a/GameServer/Command/Commands/CommandGiveAll.cs b/GameServer/Command/Commands/CommandGiveAll.cs
new file mode 100644
index 0000000..a225e9e
--- /dev/null
+++ b/GameServer/Command/Commands/CommandGiveAll.cs
@@ -0,0 +1,22 @@
+using KianaBH.Data;
+using KianaBH.Enums.Item;
+using KianaBH.Enums.Player;
+using KianaBH.Internationalization;
+
+namespace KianaBH.GameServer.Command.Commands;
+
+[CommandInfo("giveall", "Game.Command.GiveAll.Desc", "Game.Command.GiveAll.Usage", ["ga"], [PermEnum.Admin, PermEnum.Support])]
+public class CommandGiveall : ICommands
+{
+ [CommandMethod("weapon")]
+ public async ValueTask GiveWeapon(CommandArg arg)
+ {
+ if (!await arg.CheckOnlineTarget()) return;
+ foreach (var conf in GameData.WeaponData.Values.Where(weapon => weapon.Rarity == weapon.MaxRarity))
+ {
+ var item = await arg.Target!.Player!.InventoryManager!.AddItem(conf.ID, 1, ItemMainTypeEnum.Weapon, conf.MaxLv, sync:false);
+ }
+ await arg.Target!.Player!.SyncWeapon();
+ await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems", I18NManager.Translate("Word.Weapon")));
+ }
+}
diff --git a/GameServer/Game/Player/PlayerInstance.cs b/GameServer/Game/Player/PlayerInstance.cs
index c55f773..f87cf47 100644
--- a/GameServer/Game/Player/PlayerInstance.cs
+++ b/GameServer/Game/Player/PlayerInstance.cs
@@ -111,6 +111,11 @@ public class PlayerInstance(PlayerData data)
return Data.ToProto();
}
+ public async ValueTask SyncWeapon()
+ {
+ await SendPacket(new PacketGetEquipmentDataRsp(this));
+ }
+
public async ValueTask SyncValk()
{
await SendPacket(new PacketGetAvatarDataRsp(AvatarManager!.AvatarData!.Avatars!.ToList(), true));
diff --git a/KianaBH/Tool/HandbookGenerator.cs b/KianaBH/Tool/HandbookGenerator.cs
index dad1c7e..8038d68 100644
--- a/KianaBH/Tool/HandbookGenerator.cs
+++ b/KianaBH/Tool/HandbookGenerator.cs
@@ -4,6 +4,7 @@ using KianaBH.Internationalization;
using KianaBH.Util;
using Newtonsoft.Json;
using System.Text;
+using System.Text.Json.Serialization;
namespace KianaBH.KianaBH.Tool;
@@ -40,8 +41,7 @@ public static class HandbookGenerator
public static void Generate(string lang)
{
var textMapPath = ConfigManager.Config.Path.ResourcePath + "/TextMap/TextMap" + lang + ".json";
- var fallbackTextMapPath = ConfigManager.Config.Path.ResourcePath + "/TextMap/TextMap" +
- ConfigManager.Config.ServerOption.FallbackLanguage + ".json";
+
if (!File.Exists(textMapPath))
{
Logger.GetByClassName().Error(I18NManager.Translate("Server.ServerInfo.FailedToReadItem", textMapPath,
@@ -49,18 +49,9 @@ public static class HandbookGenerator
return;
}
- if (!File.Exists(fallbackTextMapPath))
- {
- Logger.GetByClassName().Error(I18NManager.Translate("Server.ServerInfo.FailedToReadItem", textMapPath,
- I18NManager.Translate("Word.NotFound")));
- return;
- }
+ List textMap = JsonConvert.DeserializeObject>(File.ReadAllText(textMapPath))!;
- var textMap = JsonConvert.DeserializeObject>(File.ReadAllText(textMapPath));
- var fallbackTextMap =
- JsonConvert.DeserializeObject>(File.ReadAllText(fallbackTextMapPath));
-
- if (textMap == null || fallbackTextMap == null)
+ if (textMap == null)
{
Logger.GetByClassName().Error(I18NManager.Translate("Server.ServerInfo.FailedToReadItem", textMapPath,
I18NManager.Translate("Word.Error")));
@@ -92,4 +83,15 @@ public static class HandbookGenerator
{
File.WriteAllText($"{ConfigManager.Config.Path.HandbookPath}/Handbook{lang}.txt", content);
}
+}
+
+public class TextMapEntry
+{
+ [JsonPropertyName("value")] public ValueEntry? Value { get; set; }
+ [JsonPropertyName("text")] public string? Text { get; set; }
+}
+
+public class ValueEntry
+{
+ [JsonPropertyName("hash")] public int Hash { get; set; }
}
\ No newline at end of file