Beispiel #1
0
        /// <summary>
        /// Creates a new instance of the RdlCommand object using the specified RdlCommonCommand as the TypeName value.
        /// </summary>
        /// <param name="commonCommand">The RdlCommonCommand used as the TypeName value of the CMD tag.</param>
        /// <returns>A new RdlCommand instance.</returns>
        public static RdlCommand FromCommonCommand(RdlCommonCommand commonCommand)
        {
            RdlCommand cmd = new RdlCommand(commonCommand.ToString());

            switch (commonCommand)
            {
            case RdlCommonCommand.QUIT:
                break;

            case RdlCommonCommand.HELP:
                break;

            case RdlCommonCommand.BUG:
                break;

            case RdlCommonCommand.SAY:
                break;

            case RdlCommonCommand.SHOUT:
                break;

            case RdlCommonCommand.TELL:
                break;

            case RdlCommonCommand.LOOK:
                break;

            case RdlCommonCommand.MOVE:
                break;

            case RdlCommonCommand.ATTACK:
                break;

            case RdlCommonCommand.CAST:
                break;

            case RdlCommonCommand.GET:
                break;

            case RdlCommonCommand.DROP:
                break;
            }
            return(cmd);
        }
Beispiel #2
0
        /// <summary>
        /// Attempts to parse the input string into an RDL command.
        /// </summary>
        /// <param name="input">The input from a chat or command console.</param>
        /// <param name="command">An RdlCommand instance representing the parsed input.</param>
        /// <param name="errorType">The RdlCommandParserErrorType value of any parsing errors.</param>
        /// <returns>True if the input was successfully parsed; otherwise false. If false the errorType
        /// parameter will contain information regarding the reason parsing failed.</returns>
        public static bool TryParse(string input, out RdlCommand command, out RdlCommandParserErrorType errorType)
        {
            bool result = false;

            errorType = RdlCommandParserErrorType.None;
            command   = new RdlCommand();
            if (!input.StartsWith("/"))
            {
                input = String.Concat("/SAY ", input);
            }

            string[] words = input.Split(' ');
            if (words != null && words.Length > 0)
            {
                // First word is the command, minus the "/"
                command.TypeName = words[0].Replace("/", "").ToUpper();

                // Command shortcuts.
                if (command.TypeName == "'")
                {
                    command.TypeName = "SAY";
                }
                if (command.TypeName == "\"")
                {
                    command.TypeName = "SHOUT";
                }
                if (command.TypeName == ":")
                {
                    command.TypeName = "EMOTE";
                }
                if (command.TypeName == ";")
                {
                    command.TypeName = "EMOTE";
                }
                if (command.TypeName == "r")
                {
                    command.TypeName = "REPLY";
                }

                // Handle parsing of the command arguments based on common commands.
                switch (command.TypeName)
                {
                //case "SAY":
                //case "SHOUT":
                //case "EMOTE":
                //    // The remainder of the words should be re-joined to form the text of the message.
                //    if (words.Length >= 2)
                //    {
                //        command.Args.Add(JoinWords(words, 1));
                //        result = true;
                //    }
                //    else
                //    {
                //        errorType = RdlCommandParserErrorType.InvalidNumberOfArguments;
                //    }
                //    break;
                case "TELL":
                case "REPLY":
                    // The next word is the name of the TELL target, the words following can be joined
                    // to form the text of the message.
                    if (words.Length >= 2)
                    {
                        if (words.Length >= 3)
                        {
                            command.Args.Add(words[1]);
                            command.Args.Add(JoinWords(words, 2));
                            result = true;
                        }
                        else
                        {
                            errorType = RdlCommandParserErrorType.InvalidNumberOfArguments;
                        }
                    }
                    else
                    {
                        errorType = RdlCommandParserErrorType.NoTargetForTell;
                    }
                    break;

                default:
                    //// Just parse all the words as separate args.
                    //if (words.Length > 1)
                    //{
                    //    for (int i = 1; i < words.Length; i++)
                    //    {
                    //        command.Args.Add(words[i]);
                    //    }
                    //}

                    // The remainder of the words should be re-joined to form the text of the message.
                    if (words.Length >= 2)
                    {
                        command.Args.Add(JoinWords(words, 1));
                    }

                    // Allow no arguments.
                    result = true;
                    break;
                }
            }
            else
            {
                errorType = RdlCommandParserErrorType.NoArgumentsSpecified;
            }
            return(result);
        }