예제 #1
0
        public DisambigCommandHandler(
            MudObject Actor,
            CommandParser.MatchedCommand MatchedCommand,
            ParserCommandHandler ParentHandler)
        {
            this.ParentHandler  = ParentHandler;
            this.MatchedCommand = MatchedCommand;

            // Find an object parameter such that
            //  a) each match has a parameter with that name
            //  b) at least one match has a value different from the others

            var foundAmbiguousArgument = false;

            // Note that we iterate only over the arguments in the first match. If the first match doesn't have the
            // argument, that argument can't satisfy condition a above.
            foreach (var argument in MatchedCommand.Matches[0])
            {
                // It's only possible to disambiguate on MudObjects. If any match - including the first one - has
                // a value for that argument that is not a MudObject, disambiguation will fail.
                if (argument.Value is MudObject)
                {
                    var uniqueMatchables = new List <MudObject>();
                    var rejected         = false;

                    foreach (var match in MatchedCommand.Matches)
                    {
                        if (match.ContainsKey(argument.Key) &&
                            match[argument.Key] is MudObject)
                        {
                            var matchableObject = match[argument.Key] as MudObject;
                            if (!uniqueMatchables.Contains(matchableObject))
                            {
                                uniqueMatchables.Add(matchableObject);
                            }
                        }
                        else
                        {
                            rejected = true;
                            break;
                        }
                    }

                    if (!rejected && uniqueMatchables.Count > 1)
                    {
                        // Disambiguate on this object.
                        DisambigArgument = argument.Key;
                        DisambigObjects  = uniqueMatchables;

                        foundAmbiguousArgument = true;
                        break;
                    }
                }
            }

            if (foundAmbiguousArgument)
            {
                var response = new StringBuilder();
                response.Append("Which did you mean?\r\n");
                for (var i = 0; i < DisambigObjects.Count; ++i)
                {
                    response.Append(String.Format("{0}: {1}\r\n", i, Core.GlobalRules.ConsiderValueRule <String>("printed name", Actor, DisambigObjects[i], "the")));
                }
                Core.SendMessage(Actor, response.ToString());
            }
            else
            {
                Core.SendMessage(Actor, "I couldn't figure out how to disambiguate that command.");
            }
        }
예제 #2
0
        public DisambigCommandHandler(
            Actor Actor, 
            CommandParser.MatchedCommand MatchedCommand, 
            ParserCommandHandler ParentHandler)
        {
            this.ParentHandler = ParentHandler;
            this.MatchedCommand = MatchedCommand;

            // Find an object parameter such that
            //  a) each match has a parameter with that name
            //  b) at least one match has a value different from the others

            var foundAmbiguousArgument = false;

            // Note that we iterate only over the arguments in the first match. If the first match doesn't have the
            // argument, that argument can't satisfy condition a above.
            foreach (var argument in MatchedCommand.Matches[0])
            {
                // It's only possible to disambiguate on MudObjects. If any match - including the first one - has
                // a value for that argument that is not a MudObject, disambiguation will fail.
                if (argument.Value is MudObject)
                {
                    var uniqueMatchables = new List<MudObject>();
                    var rejected = false;

                    foreach (var match in MatchedCommand.Matches)
                    {
                        if (match.ContainsKey(argument.Key) &&
                            match[argument.Key] is MudObject)
                        {
                            var matchableObject = match[argument.Key] as MudObject;
                            if (!uniqueMatchables.Contains(matchableObject))
                                uniqueMatchables.Add(matchableObject);
                        }
                        else
                        {
                            rejected = true;
                            break;
                        }
                    }

                    if (!rejected && uniqueMatchables.Count > 1)
                    {
                        // Disambiguate on this object.
                        DisambigArgument = argument.Key;
                        DisambigObjects = uniqueMatchables;

                        foundAmbiguousArgument = true;
                        break;
                    }
                }
            }

            if (foundAmbiguousArgument)
            {
                var response = new StringBuilder();
                response.Append("Which did you mean?\r\n");
                for (var i = 0; i < DisambigObjects.Count; ++i)
                    response.Append(String.Format("{0}: {1}\r\n", i, Core.GlobalRules.ConsiderValueRule<String>("printed name", Actor, DisambigObjects[i], "the")));
                MudObject.SendMessage(Actor, response.ToString());
            }
            else
            {
                MudObject.SendMessage(Actor, "I couldn't figure out how to disambiguate that command.");
            }
        }