예제 #1
0
파일: Parser.cs 프로젝트: ramseur/PolaMUD
        /// <summary>
        /// Retrieves the appropriate argument from the given input string, optionally retrieving 
        /// an object reference based on what you're looking for (Player, Room, etc.)
        /// </summary>
        /// <param name="line">The input string</param>
        /// <param name="index">The index of the desired argument (1 is always the command itself)</param>
        /// <returns></returns>
        public static Argument GetArgument(string line, int index)
        {
            string arg = GetArgumentString(line, index, false);
            Argument argObj = new Argument();
            argObj.Index = 1;
            argObj.Count = 1;
            argObj.Text = arg;
            int temp = -1;

            temp = arg.IndexOf('*');

            if (temp > 0)
            {
                try
                {
                    argObj.Count = Convert.ToInt32(arg.Substring(0, temp));
                    argObj.Text = arg.Substring(temp+1);
                }
                catch (Exception e)
                {
                    return null;
                }
            }

            temp = arg.IndexOf('.');
            if (temp > 0)
            {
                try
                {
                    argObj.Index = Convert.ToInt32(arg.Substring(0, temp));
                    argObj.Text = arg.Substring(temp+1);
                }
                catch (Exception e)
                {
                    return null;
                }
            }

            return argObj;
        }
예제 #2
0
파일: Parser.cs 프로젝트: ramseur/PolaMUD
 /// <summary>
 /// Retrieves a string argument from the given input string. This argument should always 
 /// be the last argument in the line, as this will retrieve the rest of the input string 
 /// after all previous arguments.
 /// </summary>
 /// <param name="line">The input string</param>
 /// <param name="index">The index of the desired argument (1 is always the command itself)</param>
 /// <returns></returns>
 public static Argument GetStringArgument(string line, int index)
 {
     Argument argument = new Argument();
     argument.Index = 1;
     argument.Count = 1;
     argument.Text = GetArgumentString(line, index, true);
     return argument;
 }