feat: add in game command handler

This commit is contained in:
Naruse
2025-06-14 14:13:48 +08:00
parent 684eab933b
commit 07ec2f9abf
10 changed files with 201 additions and 34 deletions

View File

@@ -1,5 +1,6 @@
using KianaBH.Enums.Player;
using KianaBH.GameServer.Game.Player;
using KianaBH.GameServer.Server.Packet.Send.Chat;
using KianaBH.Util;
namespace KianaBH.GameServer.Command;
@@ -31,7 +32,7 @@ public class PlayerCommandSender(PlayerInstance player) : ICommandSender
public async ValueTask SendMsg(string msg)
{
// TODO SEND MSG
await Player.SendPacket(new PacketRecvChatMsgNotify(msg));
}
public int GetSender()

View File

@@ -0,0 +1,52 @@
using KianaBH.Enums.Player;
using KianaBH.Internationalization;
using KianaBH.Util.Extensions;
namespace KianaBH.GameServer.Command.Commands;
[CommandInfo("help", "Game.Command.Help.Desc", "Game.Command.Help.Usage", ["h"], [PermEnum.Support, PermEnum.Trial])]
public class CommandHelp : ICommands
{
[CommandDefault]
public async static ValueTask Help(CommandArg arg)
{
if (arg.Args.Count == 1)
{
var cmd = arg.Args[0];
if (CommandManager.CommandInfo == null || !CommandManager.CommandInfo.TryGetValue(cmd, out var command))
{
await arg.SendMsg(I18NManager.Translate("Game.Command.Notice.CommandNotFound"));
return;
}
var msg =
$"/{command.Name} - {I18NManager.Translate(command.Description)}\n{I18NManager.Translate(command.Usage)}";
if (command.Alias.Length > 0)
msg +=
$"\n{I18NManager.Translate("Game.Command.Help.CommandAlias")} {command.Alias.ToList().ToArrayString()}";
if (command.Perm != null)
msg += $"\n{I18NManager.Translate("Game.Command.Help.CommandPermission")} {string.Join(", ", command.Perm.Select(perm => perm.ToString()))}";
await arg.SendMsg(msg + "\n");
return;
}
else
{
await arg.SendMsg(I18NManager.Translate("Game.Command.Help.Commands"));
if (CommandManager.CommandInfo == null) return;
foreach (var command in CommandManager.CommandInfo.Values)
{
var msg =
$"/{command.Name} - {I18NManager.Translate(command.Description)}\n{I18NManager.Translate(command.Usage)}";
if (command.Alias.Length > 0)
msg +=
$"\n{I18NManager.Translate("Game.Command.Help.CommandAlias")} {command.Alias.ToList().ToArrayString()}";
if (command.Perm != null)
msg += $"\n{I18NManager.Translate("Game.Command.Help.CommandPermission")} {string.Join(", ", command.Perm.Select(perm => perm.ToString()))}";
await arg.SendMsg(msg + "\n");
}
}
}
}