所以在我的遊戲服務器上我們有服務器端命令。我想知道是否有可能把這個返回一個字符串數組?
public string Command
{
get { return "g"; }
}
弄成這個樣子
public string Command
{
get { return "g", "guild", "group"; }
}
這裏的命令接口代碼
internal interface ICommand
{
string Command { get; }
int RequiredRank { get; }
void Execute(Player player, string[] args);
}
這裏的命令處理程序的代碼
第1部分:
ProcessCmd(x[0].Trim('/'), x.Skip(1).ToArray());
第2部分:
private void ProcessCmd(string cmd, string[] args)
{
if (cmds == null)
{
cmds = new Dictionary<string, ICommand>();
var t = typeof (ICommand);
foreach (var i in t.Assembly.GetTypes())
if (t.IsAssignableFrom(i) && i != t)
{
var instance = (ICommand) Activator.CreateInstance(i);
cmds.Add(instance.Command, instance);
}
}
ICommand command;
if (!cmds.TryGetValue(cmd, out command))
{
psr.SendPacket(new TextPacket
{
BubbleTime = 0,
Stars = -1,
Name = "*Error*",
Text = "Unknown Command!"
});
return;
}
try
{
ExecCmd(command, args);
}
catch (Exception e)
{
Console.Out.WriteLine(e);
psr.SendPacket(new TextPacket
{
BubbleTime = 0,
Stars = -1,
Name = "*Error*",
Text = "Error when executing the command!"
});
}
}
你可以命令屬性更改爲字符串[] –
你可以更改界面? –
我真的不知道關於這個問題,但它聽起來那麼簡單,用'字符串替換字符串'Command' [] – Habib