private static void AddPlayerCommands(AlphaTrie<CommandHandler> _)
{
_.Insert(
"say",
new CommandHandler(
new CommandHandler.PlayerCheckDelegate[] {
CheckPlayerIsAlive
},
delegate(Player p, string[] words) {
if (words.Length < 2) {
p.SendMessage("What did you want to <say>, exactly?");
p.SendPrompt();
}
else {
Event.Send(new { Type = EventType.Say, Sender = p, Text = string.Join(" ", words, 1, words.Length - 1) });
}
return null;
}));
_.Insert(
"emote",
new CommandHandler(
new CommandHandler.PlayerCheckDelegate[] {
CheckPlayerIsAlive
},
delegate(Player p, string[] words) {
if (words.Length < 2) {
p.SendMessage("What were you trying to do?");
p.SendPrompt();
}
else {
Event.Send(new { Type = EventType.Emote, Sender = p, Text = string.Join(" ", words, 1, words.Length - 1) });
}
return null;
}));
_.Insert(
"tell",
new CommandHandler(
new CommandHandler.PlayerCheckDelegate[] {
CheckPlayerIsAlive
},
delegate(Player p, string[] words) {
if (words.Length < 3) {
p.SendMessage("Who did you want to <tell> what?");
p.SendPrompt();
}
else {
string name = words[1];
IEntity to = p.Location.ResolveName(name);
if (to != null) {
Event.Send(new { Type = EventType.Tell, Sender = p, Recipient = to, Text = string.Join(" ", words, 2, words.Length - 2) });
}
else {
p.SendMessage("Who do you think you're talking to? There's nobody named {0} here.", name);
p.SendPrompt();
}
}
return null;
}));
_.Insert(
"look",
new CommandHandler(
new CommandHandler.PlayerCheckDelegate[] {
},
delegate(Player p, string[] words) {
p.PerformLook(words);
p.SendPrompt();
return null;
}));
_.Insert(
"go",
new CommandHandler(
new CommandHandler.PlayerCheckDelegate[] {
CheckPlayerIsAlive
},
delegate(Player p, string[] words) {
try {
string exitText = string.Join(" ", words, 1, words.Length - 1).Trim().ToLower();
Action<Exit> go = (exit) => {
if (World.Locations.ContainsKey(exit.Target.ToLower()))
p.Location = World.Locations[exit.Target.ToLower()];
else {
Console.WriteLine("Warning: '{0}' exit '{1}' leads to undefined location '{2}'.", p.Location.Name, exit.Description, exit.Target);
p.SendMessage("Your attempt to leave via {0} is thwarted by a mysterious force.", exit.Description);
p.SendPrompt();
}
};
foreach (var e in p.Location.Exits) {
if (e.Description.ToLower().Contains(exitText)) {
go(e);
break;
}
}
}
catch {
p.SendMessage("You can't find that exit.");
p.SendPrompt();
}
return null;
}));
_.Insert(
"kill",
new CommandHandler(
new CommandHandler.PlayerCheckDelegate[] {
CheckPlayerIsAlive
},
delegate(Player p, string[] words) {
if (words.Length < 2) {
p.SendMessage("Who did you want to kill?");
p.SendPrompt();
}
else if (p.InCombat) {
p.SendMessage("You're already busy fighting!");
p.SendPrompt();
}
else {
string name = words[1];
IEntity to = p.Location.ResolveName(name);
if (to == p) {
p.SendMessage("You don't really want to kill yourself, you're just looking for attention.");
p.SendPrompt();
}
else if (to != null) {
if (to is CombatEntity) {
CombatEntity cto = to as CombatEntity;
if (cto.InCombat == false) {
p.StartCombat(cto);
cto.StartCombat(p);
Event.Send(new { Type = EventType.CombatStart, Sender = p, Target = cto });
}
else {
p.SendMessage("They're already in combat, and you don't want to interfere.");
p.SendPrompt();
}
}
else {
p.SendMessage("You don't think that's such a great idea.");
p.SendPrompt();
}
}
else {
p.SendMessage("Who are you trying to kill, exactly? There's nobody named {0} here.", name);
p.SendPrompt();
}
}
return null;
}));
_.Insert(
"quit",
new CommandHandler(
new CommandHandler.PlayerCheckDelegate[] {
},
delegate(Player p, string[] words) {
p.Client.Dispose();
return null;
}));
_.Insert(
"commands",
new CommandHandler(
new CommandHandler.PlayerCheckDelegate[] {
},
delegate(Player p, string[] words) {
p.SendMessage("Commands:");
foreach (var Command in p._Commands.Traverse())
p.SendMessage(" {0}", Command.Key);
return null;
}));
_.Insert(
"help",
new CommandHandler(
new CommandHandler.PlayerCheckDelegate[] {
CheckPlayerIsAlive
},
delegate(Player p, string[] words) {
p.SendMessage("You can <say> things to those nearby, if you feel like chatting.");
p.SendMessage("You can also <tell> somebody things if you wish to speak privately.");
p.SendMessage("You can also <emote> within sight of others.");
p.SendMessage("If you're feeling lost, try taking a <look> around.");
p.SendMessage("To move somewhere either <go> there, or enter the name of the exit.");
p.SendMessage("Looking to make trouble? Try to <kill> someone!");
p.SendMessage("If you get bored you can always <quit> the game.");
p.SendPrompt();
return null;
}));
}