Пример #1
0
        private void TryExecuteCommand(string input)
        {
            var commandContext = CommandContext.Create(input);
            var player         = Server.Current.Database.Get <Player>(Session.Player.Key);
            var commandInfo    = Server.Current.CommandLookup.FindCommand(commandContext.CommandName, player);

            TryExecuteCommand(commandContext, commandInfo);
        }
Пример #2
0
        private bool TryExecuteCommand(string input)
        {
            bool reprint = true;

            var commandContext = CommandContext.Create(input);
            var player         = Server.Current.Database.Get <Player>(Session.Player.Key);
            var commandInfo    = Server.Current.CommandLookup.FindCommand(commandContext.CommandName, player);

            // switch case for add/remove/exit/cancel/etc
            switch (commandContext.CommandName.ToLower())
            {
            case "add":
            case "a":
                Add(commandContext);
                break;

            case "remove":
            case "r":
                Remove(commandContext);
                break;

            case "gold":
            case "g":
                Gold(commandContext);
                break;

            case "ok":
            case "o":
                Approve(commandContext);
                reprint = false;
                break;

            case "cancel":
            case "c":
                Cancel();
                reprint = false;
                break;

            case "help":
            case "h":
                PrintHelp();
                reprint = false;
                break;

            case "print":
            case "p":
                Session.WriteLine(this);
                reprint = false;
                break;

            default:
                Session.WriteLine("`rCommand not recognized.");
                reprint = false;
                break;
            }

            return(reprint);
        }
Пример #3
0
        public override void Execute(Session session, CommandContext context)
        {
            var room = RoomHelper.GetRoom(context.ArgumentString);

            if (room != null)
            {
                // remove player from current room
                var currentRoom = RoomHelper.GetRoom(session.Player.Location);
                if (currentRoom != null)
                {
                    currentRoom.RemovePlayer(session.Player);
                }

                room.AddPlayer(session.Player);
                session.Player.Location = context.ArgumentString;
            }

            var commandInfo = Server.Current.CommandLookup.FindCommand("look", session.Player);

            commandInfo.Command.Execute(session, CommandContext.Create("look"));
        }
Пример #4
0
        public override void Execute(Session session, CommandContext context)
        {
            if (session.Player.Status != GameStatus.Standing)
            {
                switch (session.Player.Status)
                {
                    case GameStatus.Dead:
                        session.WriteLine("You're dead.");
                        break;
                    case GameStatus.Fighting:
                        session.WriteLine("You're fighting.");
                        break;
                    case GameStatus.Incapacitated:
                        session.WriteLine("You're incapacitated.");
                        break;
                    case GameStatus.MortallyWounded:
                        session.WriteLine("You're mortally wounded.");
                        break;
                    case GameStatus.Sitting:
                        session.WriteLine("You're sitting.");
                        break;
                    case GameStatus.Sleeping:
                        session.WriteLine("You're sleeping.");
                        break;
                    default:
                        session.WriteLine("You can't leave right now.");
                        break;
                }
                
                return;
            }

            var room = Server.Current.Database.Get<Room>(session.Player.Location);

            if (room == null)
            {
                LookCommand.WriteNullRoomDescription(session);
                return;
            }

            if (room.HasExit(direction))
            {
                var exitTo = room.GetExit(direction);
                var newRoom = Server.Current.Database.Get<Room>(exitTo.LeadsTo);

                if (exitTo.IsDoor && !exitTo.IsOpen)
                {
                    session.WriteLine("The door is closed.");
                    return;
                }

                room.RemovePlayer(session.Player);
                newRoom.AddPlayer(session.Player);
                session.Player.Location = newRoom.Key;

                room.SendPlayers("%d heads " + direction + ".", session.Player, null, session.Player);
                newRoom.SendPlayers("%d arrives.", session.Player, null, session.Player);
                session.Player.Send("you head " + direction + ".\n", session.Player);

                // emit "event" for aggro mobs
                Server.Current.CombatHandler.EnterRoom(session.Player, newRoom);
                var commandInfo = Server.Current.CommandLookup.FindCommand("look", session.Player);
                commandInfo.Command.Execute(session, CommandContext.Create("look"));
            }
            else
            {
                session.WriteLine("You can't go that way.");
            }
        }
Пример #5
0
        private void TryExecuteCommand(string input)
        {
            if (input.ToLower() == "exitmapping")
            {
                Session.PopState();
                return;
            }

            var room = RoomHelper.GetPlayerRoom(Session.Player);

            if (_status == MappingStatus.Walking)
            {
                var direction = DirectionHelper.GetDirectionWord(input);

                if (string.IsNullOrEmpty(direction))
                {
                    Session.WriteLine("That's not a direction.");
                    return;
                }

                if (room.HasExit(direction))
                {
                    var commandInfo = Server.Current.CommandLookup.FindCommand(direction, Session.Player);
                    commandInfo.Command.Execute(Session, CommandContext.Create(direction));
                    return;
                }

                // set mode to request title
                Session.WriteLine("`RCreating exit, Please enter a title...");
                _status    = MappingStatus.NeedsTitle;
                _direction = direction;
            }
            else
            {
                // user is inputting a title
                var checkRoom     = Server.Current.Database.Get <Room>(input.ToLower());
                var calculatedKey = input.ToLower();

                if (checkRoom != null)
                {
                    calculatedKey = RoomHelper.GenerateKey(input);
                    Session.WriteLine("`RRoom already exists. Using title: `G{0}`R.", calculatedKey);
                }

                var newRoom = new Room()
                {
                    Area        = room.Area,
                    Description = RoomHelper.GetDefaultRoomDescription(),
                    Key         = calculatedKey.ToLower(),
                    Title       = input,
                };

                newRoom.Exits.Add(DirectionHelper.GetOppositeDirection(_direction), new RoomExit()
                {
                    IsDoor  = false,
                    IsOpen  = true,
                    LeadsTo = room.Key
                });

                Server.Current.Database.Save(newRoom);

                room.Exits.Add(_direction, new RoomExit()
                {
                    IsDoor  = false,
                    IsOpen  = true,
                    LeadsTo = newRoom.Key
                });

                Server.Current.Database.Save(room);

                var commandInfo = Server.Current.CommandLookup.FindCommand(_direction, Session.Player);
                commandInfo.Command.Execute(Session, CommandContext.Create(_direction));
                _status = MappingStatus.Walking;
            }
        }
Пример #6
0
        public override void Execute(Session session, CommandContext context)
        {
            if (string.IsNullOrEmpty(context.ArgumentString))
            {
                PrintSyntax(session);
                return;
            }

            var player = Server.Current.Database.Get <Player>(context.ArgumentString.ToLower());

            if (player == null)
            {
                session.WriteLine("Couldn't find {0}.", context.ArgumentString.ToLower());
                return;
            }

            if (player.Approved)
            {
                session.WriteLine("{0} doesn't need authorization right now.");
                return;
            }

            player.Approved = true;

            var srcRoom = RoomHelper.GetRoom(player.Location);
            var dstRoom = RoomHelper.GetRoom(Server.StartRoom);

            srcRoom.RemovePlayer(player);
            player.Location = dstRoom.Key;
            dstRoom.AddPlayer(player);
            dstRoom.SendPlayers(string.Format("{0} arrives in a blinding column of light.", player.Forename),
                                player, null, player);

            player.Experience = ExperienceResolver.FirstLevel;
            Server.Current.Database.Save(player);
            var commandInfo = Server.Current.CommandLookup.FindCommand("look", player);

            commandInfo.Command.Execute(Server.Current.SessionMonitor.GetPlayerSession(player), CommandContext.Create("look"));
            player.WritePrompt();
        }