-
Notifications
You must be signed in to change notification settings - Fork 9
command handler
mtanksl edited this page Dec 11, 2023
·
4 revisions
Commands
can be intercepted and changed as they pass through Pipeline
of Command Handlers
before executing.
Let's intercept the PlayerSayCommand
, which occurs when any player says anything on the default chat window. If the message starts with /me
, a magic effect command is dispatched.
public class DisplayMagicEffectHandler : CommandHandler<PlayerSayCommand>
{
public override Promise Handle(Func<Promise> next, PlayerSayCommand command)
{
if (command.Message.StartsWith("/me ") && int.TryParse(command.Message.Substring(4), out int id) && id >= 1 && id <= 70 && command.Player.Rank == Rank.Gamemaster)
{
return Context.AddCommand(new ShowMagicEffectCommand(command.Player.Tile.Position, (MagicEffectType)id) );
}
return next();
}
}