public override void Execute(CommandContext context, CallerContext callerContext, Player callingPlayer, string[] args) { context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages( String.Format("There are currently {0} wizards online.", context.World.GetOnlinePlayers().Count), MessageType.Notification)); }
public override void Execute(CommandContext context, CallerContext callerContext, Player callingPlayer, string[] args) { if (args.Length == 0 || String.IsNullOrWhiteSpace(args[0])) throw new InvalidOperationException("...What would you like to get?"); if(callingPlayer.Items.Count > 5) { context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages("...You're pack is too full to accomidate anything else.")); return; } var room = context.World.GetRoom(callingPlayer.RoomReference); var players = context.World.GetOnlinePlayers(room).Where(player => player.Name != callingPlayer.Name).ToList(); var item = room.Items.FirstOrDefault(x => x.Name.StartsWith(String.Join(" ", args).Trim(), StringComparison.OrdinalIgnoreCase)); if(item != null) { room.Items.Remove(item); callingPlayer.Items.Add(item); context.NotificationService.ToPlayers(players, new PlayerMessages(String.Format("{0} grabs {1}.", callingPlayer.Name, item.ToDisplay()))); context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages(String.Format("...You grab {0}.", item.ToDisplay()))); } else context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages("...There's nothing like that around here.")); }
// Commands that require a user name private bool TryHandleCommand(string commandName, string[] args) { ICommand command; if (!TryMatchCommand(commandName, out command)) { throw new InvalidOperationException(String.Format("'{0}' is not a valid command.", commandName)); } var context = new CommandContext { CommandName = commandName, World = _world, NotificationService = _notificationService, }; var callerContext = new CallerContext { ClientId = _clientId, PlayerReference = _playerReference }; command.Execute(context, callerContext, args); return true; }
public override void Execute(CommandContext context, CallerContext callerContext, Player callingPlayer, string[] args) { if (args.Length == 0 || String.IsNullOrWhiteSpace(args[0])) throw new InvalidOperationException("...What would you like to cast?"); var sm = new SpellManager(callingPlayer, context.World, context.NotificationService); sm.TryHandleSpell(args); }
Execute(context, callerContext, player, args); } public abstract void Execute(CommandContext context, CallerContext callerContext, Player callingPlayer, string[] args); } }
public override void Execute(CommandContext context, CallerContext callerContext, Player callingPlayer, string[] args) { if(callingPlayer.Items.Count == 0) context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages("...You're not carrying anything.")); else context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages( String.Format("...You are carrying {0}.", callingPlayer.Items.ToDisplay()))); }
public override void Execute(CommandContext context, CallerContext callerContext, Player callingPlayer, string[] args) { if (args.Length == 0 || String.IsNullOrWhiteSpace(args[0])) throw new InvalidOperationException("...What would you like to say?"); var room = context.World.GetRoom(callingPlayer.RoomReference); var players = context.World.GetOnlinePlayers(room).ExcludePlayer(callingPlayer).ToList(); var message = String.Format("{0} says: {1}", callingPlayer.Name, String.Join(" ", args).Trim()); if (players.Any()) context.NotificationService.ToPlayers(players, new PlayerMessages(message)); context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages("...You said it!")); }
public override void Execute(CommandContext context, CallerContext callerContext, Player callingPlayer, string[] args) { if (args.Length == 0 || String.IsNullOrWhiteSpace(args[0])) throw new InvalidOperationException("...Would you like brief descriptions on or off?"); if (args[0].ToLower().Trim() == "on") { callingPlayer.BriefDescriptions = true; context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages("Ok, brief descriptions from now on.")); } else { callingPlayer.BriefDescriptions = false; context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages("Ok, full descriptions from now on.")); } }
public override void Execute(CommandContext context, CallerContext callerContext, Player callingPlayer, string[] args) { if (args.Length < 1) throw new InvalidOperationException("...You need to whisper to somebody!"); if (args.Length < 2 || String.IsNullOrWhiteSpace(args[1])) throw new InvalidOperationException("...What would you like to whisper?"); var room = context.World.GetRoom(callingPlayer.RoomReference); var players = context.World.GetOnlinePlayers(room).Where(player => player.Name != callingPlayer.Name).ToList(); var to = players.FindByName(args[0]); if (to != null) { context.NotificationService.ToPlayer(to, new PlayerMessages ( new List<PlayerMessage> { new PlayerMessage("***",MessageType.Important), new PlayerMessage(string.Format("{0} whispers: {1}", callingPlayer.Name, String.Join(" ",args.Skip(1)))) })); context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages(String.Format("...{0} hears you!", to.Name))); context.NotificationService.ToPlayers(players.Where(x => x.Name != to.Name), new PlayerMessages(String.Format( "{0} whispers something to {1}.", callingPlayer.Name, to.Name))); } else context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages("...You don't see anybody here by that name.")); }
public override void Execute(CommandContext context, CallerContext callerContext, Player callingPlayer, string[] args) { var room = context.World.GetRoom(callingPlayer.RoomReference); var players = context.World.GetOnlinePlayers(room).Where(player => player.Name != callingPlayer.Name).ToList(); if (args.IsNullOrEmpty()) // Look room { var look = new PlayerMessages(); look.Messages.Add(new PlayerMessage(room.Name, MessageType.Title)); if (!callingPlayer.BriefDescriptions) look.Messages.Add(new PlayerMessage(String.Format(" {0}", room.Description))); if (room.Items.Any()) look.Messages.Add( new PlayerMessage(String.Format("There's {0} laying on the ground.", room.Items.ToDisplay()))); if (players.Any()) look.Messages.Add(new PlayerMessage(players.ToDisplay(), MessageType.Important)); context.NotificationService.ToPlayer(callingPlayer, look); } else // Look at item or player { var lookFor = String.Join(" ", args).Trim(); if (callingPlayer.Name.StartsWith(lookFor, StringComparison.OrdinalIgnoreCase)) // This player context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages(callingPlayer.Description)); else if (players.Count(x => x.Name.StartsWith(lookFor, StringComparison.OrdinalIgnoreCase)) > 0) // Other player { var target = players.First(x => x.Name.StartsWith(lookFor, StringComparison.OrdinalIgnoreCase)); context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages(target.Description)); context.NotificationService.ToPlayer(target, new PlayerMessages(String.Format("{0} is looking you over.", callingPlayer.Name))); context.NotificationService.ToPlayers(players.Where(x => x.Name != target.Name), new PlayerMessages(String.Format("{0} is taking a good look at {1}.", callingPlayer.Name,target.Name))); } else if (callingPlayer.Items.Count(x => x.Name.StartsWith(lookFor, StringComparison.OrdinalIgnoreCase)) > 0) // Item in inventory { context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages( callingPlayer.Items.First( x => x.Name.StartsWith(lookFor, StringComparison. OrdinalIgnoreCase)) .Description)); } else if (room.Items.Count(x => x.Name.StartsWith(lookFor, StringComparison.OrdinalIgnoreCase)) > 0) // Item in room { context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages( room.Items.First( x => x.Name.StartsWith(lookFor, StringComparison. OrdinalIgnoreCase)) .Description)); } else { context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages( "...You don't see anything like that around here")); } } }