Ejemplo n.º 1
0
 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));
 }
Ejemplo n.º 2
0
        // 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;
        }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
0
        // 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);
        }
Ejemplo n.º 5
0
        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 drop?");
            }

            var room    = context.World.GetRoom(callingPlayer.RoomReference);
            var players = context.World.GetOnlinePlayers(room).Where(player => player.Name != callingPlayer.Name).ToList();
            var item    = callingPlayer.Items.FirstOrDefault(x => x.Name.StartsWith(String.Join(" ", args).Trim(), StringComparison.OrdinalIgnoreCase));

            if (item != null)
            {
                callingPlayer.Items.Remove(item);

                context.NotificationService.ToPlayers(players,
                                                      new PlayerMessages(String.Format("{0} drops {1}.", callingPlayer.Name, item.ToDisplay())));
                context.NotificationService.ToPlayer(callingPlayer,
                                                     new PlayerMessages(String.Format("...You drop {0}.", item.ToDisplay())));

                if (room.Items.Count < context.World.Settings.MaxItemsInRoom)
                {
                    room.Items.Add(item);
                }
                else
                {
                    context.NotificationService.ToRoom(room,
                                                       new PlayerMessages(String.Format("The {0} vanishes in a brilliant flash of light!", item.Name)));
                }
            }
            else
            {
                context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages("...You're not carrying anything like that."));
            }
        }
Ejemplo n.º 6
0
        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."));
        }
Ejemplo n.º 7
0
        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."));
            }
        }
Ejemplo n.º 8
0
            Execute(context, callerContext, player, args);
        }

        public abstract void Execute(CommandContext context, CallerContext callerContext, Player callingPlayer, string[] args);
    }
}
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        public override void Execute(CommandContext context, CallerContext callerContext, Player callingPlayer, string[] args)
        {
            //context.World.CreateWorld();

            context.NotificationService.ToPlayer(callingPlayer, new PlayerMessages("World created!"));

            //context.NotificationService.ToPlayer(callingUser);
        }
Ejemplo n.º 11
0
        void ICommand.Execute(CommandContext context, CallerContext callerContext, string[] args)
        {
            Player player = context.World.GetPlayer(callerContext.PlayerReference);

            player.LastCommand = DateTime.Now;

            Execute(context, callerContext, player, args);
        }
Ejemplo n.º 12
0
        public override void Execute(CommandContext context, CallerContext callerContext, Player callingUser, string[] args)
        {
            if (!callingUser.IsAdmin)
            {
                throw new InvalidOperationException("...Huh?");
            }

            ExecuteAdminOperation(context, callerContext, callingUser, args);
        }
Ejemplo n.º 13
0
 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())));
 }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        public override void ExecuteAdminOperation(CommandContext context, CallerContext callerContext, Player callingUser, string[] args)
        {
            string messageText = String.Join(" ", args).Trim();

            if (String.IsNullOrEmpty(messageText))
            {
                throw new InvalidOperationException("What did you want to broadcast?");
            }

            context.NotificationService.ToAll(new PlayerMessages(messageText, MessageType.Notification));
        }
Ejemplo n.º 16
0
 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())));
     }
 }
Ejemplo n.º 17
0
        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!"));
        }
Ejemplo n.º 18
0
        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."));
            }
        }
Ejemplo n.º 19
0
        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."));
            }
        }
Ejemplo n.º 20
0
        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!"));
        }
Ejemplo n.º 21
0
        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."));
            }
        }
Ejemplo n.º 22
0
        public override void Execute(CommandContext context, CallerContext callerContext, Player callingPlayer, string[] args)
        {
            var direction   = context.CommandName[0];
            var leavingRoom = callingPlayer.RoomReference;

            context.World.Move(callingPlayer, direction);

            context.NotificationService.LeaveRoom(callingPlayer, leavingRoom,
                                                  new PlayerMessages(String.Format("...{0} leaves to the {1}.",
                                                                                   callingPlayer.Name,
                                                                                   direction.ToDirection())));

            context.NotificationService.EnterRoom(callingPlayer,
                                                  new PlayerMessages(String.Format("...{0} arrives from the {1}.",
                                                                                   callingPlayer.Name,
                                                                                   direction.ToOppositeDirection())));

            var lookCmd = new LookCommand();

            lookCmd.Execute(context, callerContext, callingPlayer, null);
        }
Ejemplo n.º 23
0
        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."));
        }
Ejemplo n.º 24
0
        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"));
                }
            }
        }
Ejemplo n.º 25
0

        
Ejemplo n.º 26
0
 public abstract void Execute(CommandContext context, CallerContext callerContext, Player callingPlayer, string[] args);
Ejemplo n.º 27
0
 public abstract void ExecuteAdminOperation(CommandContext context, CallerContext callerContext, Player callingUser, string[] args);
Ejemplo n.º 28
0
        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"));
                }
            }
        }