Пример #1
0
 public List<PossibleMatch> Match(PossibleMatch State, MatchContext Context)
 {
     var R = new List<PossibleMatch>();
     R.AddRange(Sub.Match(State, Context));
     if (R.Count == 0) R.Add(State);
     return R;
 }
Пример #2
0
 public List<PossibleMatch> Match(PossibleMatch State, MatchContext Context)
 {
     var R = new List<PossibleMatch>();
     R.AddRange(Sub.Match(State, Context));
     if (R.Count == 0) throw new CommandParser.MatchAborted(Message);
     return R;
 }
Пример #3
0
 public List<PossibleMatch> Match(PossibleMatch State, MatchContext Context)
 {
     var Matches = new List<PossibleMatch>();
     foreach (var Matcher in Matchers)
         Matches.AddRange(Matcher.Match(State, Context));
     return Matches;
 }
Пример #4
0
 public List<PossibleMatch> Match(PossibleMatch State, MatchContext Context)
 {
     var r = new List<PossibleMatch>();
     if (State.Next != null)
         r.Add(State.AdvanceWith(ArgumentName, State.Next.Value));
     return r;
 }
Пример #5
0
 public List<PossibleMatch> Match(PossibleMatch State, MatchContext Context)
 {
     if (Test(State, Context)) throw new CommandParser.MatchAborted(Message);
     var r = new List<PossibleMatch>();
     r.Add(State);
     return r;
 }
Пример #6
0
 public List<PossibleMatch> Match(PossibleMatch State, MatchContext Context)
 {
     var R = new List<PossibleMatch>();
     if (Context.ExecutingActor.Rank >= RequiredRank)
         R.Add(State);
     //else
     //    throw new CommandParser.MatchAborted("You do not have sufficient rank to use that command.");
     return R;
 }
Пример #7
0
 public List<PossibleMatch> Match(PossibleMatch State, MatchContext Context)
 {
     var R = new List<PossibleMatch>();
     if (State.Next != null && State.Next.Value.ToUpper() == Word)
         R.Add(State.Advance());
     else if (Optional) //Greedy match
         R.Add(State);
     return R;
 }
Пример #8
0
        public List<PossibleMatch> Match(PossibleMatch State, MatchContext Context)
        {
            var r = new List<PossibleMatch>();
            if (State.Next == null) return r;

            if (Link.IsCardinal(State.Next.Value.ToUpper()))
                r.Add(State.AdvanceWith(ArgumentName, Link.ToCardinal(State.Next.Value.ToUpper())));

            return r;
        }
Пример #9
0
        public MatchedCommand ParseCommand(PendingCommand Command)
        {
            var tokens = new LinkedList<String>(Command.RawCommand.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries));

            var rootMatch = new PossibleMatch(tokens.First);
            rootMatch.Upsert("ACTOR", Command.Actor);
            rootMatch.Upsert("LOCATION", Command.Actor == null ? null : Command.Actor.Location);

            // A pending command can have some properties set when it is queued. For example, the 'go' action
            // generates a 'look' command after processing. It will give the 'look' command a property named
            // 'auto' to indicate that the look command was generated. Rules can then use this property to
            // implement behavior. From the same example, 'look' may emit a brief description if it is generated
            // by the 'go' action, but emit a more detailed description if the player enters the command 'look'.
            //      See StandardActions.Go
            if (Command.PreSettings != null)
                foreach (var setting in Command.PreSettings)
                    rootMatch.Upsert(setting.Key.ToUpper(), setting.Value);

            var matchContext = new MatchContext { ExecutingActor = Command.Actor };

            // Try every single command defined, until one matches.
            foreach (var command in Commands)
            {
                IEnumerable<PossibleMatch> matches;

                try
                {
                    matches = command.Matcher.Match(rootMatch, matchContext);
                }
                catch (MatchAborted ma)
                {
                    // The match didn't fail; it generated an error. These means the match progressed to a point
                    // where the author of the command felt that the input could not logically match any other
                    // command, however, the input was still malformed in some way. Abort matching, and dummy up
                    // a command entry to display the error message to the player.
                    return new MatchedCommand(
                        new CommandEntry().ProceduralRule((match, actor) =>
                        {
                            MudObject.SendMessage(actor, ma.Message);
                            return PerformResult.Continue;
                        }),
                        // We need a fake match just so it can be passed to the procedural rule.
                        new PossibleMatch[] { new PossibleMatch(null) });
                }

                // Only accept matches that consumed all of the input.
                matches = matches.Where(m => m.Next == null);

                // If we did consume all of the input, we will assume this match is successful. Note it is
                // possible for a command to generate multiple matches, but not possible to match multiple commands.
                if (matches.Count() > 0)
                    return new MatchedCommand(command, matches);
            }
            return null;
        }
Пример #10
0
        public List<PossibleMatch> Match(PossibleMatch State, MatchContext Context)
        {
            var r = new List<PossibleMatch>();
            if (State.Next == null) return r;

            int value = 0;
            if (Int32.TryParse(State.Next.Value, out value))
                r.Add(State.AdvanceWith(ArgumentName, value));

            return r;
        }
Пример #11
0
 public List<PossibleMatch> Match(PossibleMatch State, MatchContext Context)
 {
     var r = Sub.Match(State, Context);
     var highestScoreFound = MatchPreference.VeryUnlikely;
     foreach (var match in r)
     {
         var score = GetScore(match, ScoreArgument );
         if (score > highestScoreFound) highestScoreFound = score;
     }
     return new List<PossibleMatch>(r.Where(m => highestScoreFound == GetScore(m, ScoreArgument)));
 }
Пример #12
0
 public List<PossibleMatch> Match(PossibleMatch State, MatchContext Context)
 {
     var Matches = new List<PossibleMatch>();
     Matches.Add(State);
     foreach (var Matcher in Matchers)
     {
         var NextMatches = new List<PossibleMatch>();
         foreach (var Match in Matches)
             NextMatches.AddRange(Matcher.Match(Match, Context));
         Matches = NextMatches;
         if (Matches.Count == 0) return Matches; //Shortcircuit for when no matches are found.
     }
     return Matches;
 }
Пример #13
0
        public List<MudObject> GetObjects(PossibleMatch State, MatchContext Context)
        {
            NPC source = null;
            if (!String.IsNullOrEmpty(LocutorArgument))
                source = State[LocutorArgument] as NPC;
            else if (Context.ExecutingActor.HasProperty<NPC>("interlocutor"))
                source = Context.ExecutingActor.GetProperty<NPC>("interlocutor");

            if (source != null)
                if (source.HasProperty<List<MudObject>>("conversation-topics"))
                    return new List<MudObject>(source.GetProperty<List<MudObject>>("conversation-topics").Where(t => Core.GlobalRules.ConsiderCheckRuleSilently("topic available?", Context.ExecutingActor, source, t) == CheckResult.Allow));

            return new List<MudObject>();
        }
        internal MatchedCommand ParseCommand(String Command, Actor Actor)
        {
			var tokens = new LinkedList<String>(Command.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries));
			var rootMatch = new PossibleMatch(tokens.First);

			//Find all objects in scope
			var matchContext = new MatchContext { ExecutingActor = Actor };

			foreach (var command in Commands)
			{
				var matches = command.Matcher.Match(rootMatch, matchContext);
				var firstGoodMatch = matches.Find(m => m.Next == null);
				if (firstGoodMatch != null) return new MatchedCommand(command, firstGoodMatch);
			}
            return null;
        }
Пример #15
0
        public List<PossibleMatch> Match(PossibleMatch State, MatchContext Context)
        {
            var r = new List<PossibleMatch>();
            if (State.Next == null) return r;

            var word = State.Next.Value.ToUpper();
            if (word == "ON")
                r.Add(State.AdvanceWith(ArgumentName, RelativeLocations.On));
            else  if (word == "IN")
                r.Add(State.AdvanceWith(ArgumentName, RelativeLocations.In));
            else if (word == "UNDER")
                r.Add(State.AdvanceWith(ArgumentName, RelativeLocations.Under));
            else if (word == "BEHIND")
                r.Add(State.AdvanceWith(ArgumentName, RelativeLocations.Behind));
            return r;
        }
Пример #16
0
        public List<PossibleMatch> Match(PossibleMatch State, MatchContext Context)
        {
            var r = new List<PossibleMatch>();

            if (State.Next != null)
            {
                var builder = new StringBuilder();
                var node = State.Next;
                for (; node != null; node = node.Next)
                {
                    builder.Append(node.Value);
                    builder.Append(" ");
                }

                builder.Remove(builder.Length - 1, 1);
                r.Add(State.EndWith(ArgumentName, builder.ToString()));
            }

            return r;
        }
Пример #17
0
        override protected List <PossibleMatch> ImplementMatch(PossibleMatch State, MatchContext Context)
        {
            var useObjectScoring = ScoreResults != null;

            var R = new List <PossibleMatch>();

            if (State.Next == null)
            {
                return(R);
            }

            if ((Settings & ObjectMatcherSettings.UnderstandMe) == ObjectMatcherSettings.UnderstandMe)
            {
                if (State.Next.Value.ToUpper() == "ME")
                {
                    var possibleMatch = State.Advance();
                    possibleMatch.Upsert(CaptureName, Context.ExecutingActor);
                    possibleMatch.Upsert(CaptureName + "-SOURCE", "ME");
                    R.Add(possibleMatch);
                }
            }

            foreach (var matchableMudObject in ObjectSource.GetObjects(State, Context))
            {
                PossibleMatch possibleMatch = State;
                bool          matched       = false;
                while (possibleMatch.Next != null && matchableMudObject.GetProperty <NounList>("nouns").Match(possibleMatch.Next.Value.ToUpper(), Context.ExecutingActor))
                {
                    if (matched == false)
                    {
                        possibleMatch = State.Clone();
                    }
                    matched            = true;
                    possibleMatch.Next = possibleMatch.Next.Next;
                }

                if (matched)
                {
                    possibleMatch.Upsert(CaptureName, matchableMudObject);

                    if (useObjectScoring)
                    {
                        var score = ScoreResults(Context.ExecutingActor, matchableMudObject);
                        possibleMatch.Upsert(CaptureName + "-SCORE", score);

                        var insertIndex = 0;
                        for (insertIndex = 0; insertIndex < R.Count; ++insertIndex)
                        {
                            if (score > (R[insertIndex][CaptureName + "-SCORE"] as MatchPreference?).Value)
                            {
                                break;
                            }
                        }

                        R.Insert(insertIndex, possibleMatch);
                    }
                    else
                    {
                        R.Add(possibleMatch);
                    }
                }
            }
            return(R);
        }
 public List <MudObject> GetObjects(PossibleMatch State, MatchContext Context)
 {
     return(new List <MudObject>(Clients.ConnectedClients.Where(c => c is NetworkClient && (c as NetworkClient).IsLoggedOn).Select(c => c.Player)));
 }
 public List<MudObject> GetObjects(PossibleMatch State, MatchContext Context)
 {
     return new List<MudObject>(Clients.ConnectedClients.Where(c => c is NetworkClient && (c as NetworkClient).IsLoggedOn).Select(c => c.Player));
 }
Пример #20
0
        public List<PossibleMatch> Match(PossibleMatch State, MatchContext Context)
        {
            var useObjectScoring = ScoreResults != null;

            var R = new List<PossibleMatch>();
            if (State.Next == null) return R;

            if ((Settings & ObjectMatcherSettings.UnderstandMe) == ObjectMatcherSettings.UnderstandMe)
            {
                if (State.Next.Value.ToUpper() == "ME")
                {
                    var possibleMatch = State.Advance();
                    possibleMatch.Upsert(CaptureName, Context.ExecutingActor);
                    possibleMatch.Upsert(CaptureName + "-SOURCE", "ME");
                    R.Add(possibleMatch);
                }
            }

            foreach (var matchableMudObject in ObjectSource.GetObjects(State, Context))
            {
                PossibleMatch possibleMatch = State;
                bool matched = false;
                while (possibleMatch.Next != null && matchableMudObject.Nouns.Match(possibleMatch.Next.Value.ToUpper(), Context.ExecutingActor))
                {
                    if (matched == false) possibleMatch = State.Clone();
                    matched = true;
                    possibleMatch.Next = possibleMatch.Next.Next;
                }

                if (matched)
                {
                    possibleMatch.Upsert(CaptureName, matchableMudObject);

                    if (useObjectScoring)
                    {
                        var score = ScoreResults(Context.ExecutingActor, matchableMudObject);
                        possibleMatch.Upsert(CaptureName + "-SCORE", score);

                        var insertIndex = 0;
                        for (insertIndex = 0; insertIndex < R.Count; ++insertIndex)
                        {
                            if (score > (R[insertIndex][CaptureName + "-SCORE"] as MatchPreference?).Value) break;
                        }

                        R.Insert(insertIndex, possibleMatch);
                    }
                    else
                    {
                        R.Add(possibleMatch);
                    }
                }
            }
            return R;
        }
Пример #21
0
        public MatchedCommand ParseCommand(PendingCommand Command)
        {
            var tokens = new LinkedList <String>(Command.RawCommand.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries));

            var rootMatch = new PossibleMatch(tokens.First);

            rootMatch.Upsert("ACTOR", Command.Actor);
            rootMatch.Upsert("LOCATION", Command.Actor == null ? null : Command.Actor.Location);

            // A pending command can have some properties set when it is queued. For example, the 'go' action
            // generates a 'look' command after processing. It will give the 'look' command a property named
            // 'auto' to indicate that the look command was generated. Rules can then use this property to
            // implement behavior. From the same example, 'look' may emit a brief description if it is generated
            // by the 'go' action, but emit a more detailed description if the player enters the command 'look'.
            //      See StandardActions.Go
            if (Command.PreSettings != null)
            {
                foreach (var setting in Command.PreSettings)
                {
                    rootMatch.Upsert(setting.Key.ToUpper(), setting.Value);
                }
            }

            var matchContext = new MatchContext {
                ExecutingActor = Command.Actor
            };

            // Try every single command defined, until one matches.
            foreach (var command in Commands)
            {
                IEnumerable <PossibleMatch> matches;
                matchContext.CurrentParseCommand = command;

                try
                {
                    matches = command.Matcher.Match(rootMatch, matchContext);
                }
                catch (MatchAborted ma)
                {
                    // The match didn't fail; it generated an error. This usually represents an oversite in the command's grammar.
                    // Abort matching, and dummy up a command entry to display the error message to the player.
                    return(new MatchedCommand(
                               new CommandEntry().ProceduralRule((match, actor) =>
                    {
                        Core.SendMessage(actor, ma.Message);
                        return PerformResult.Continue;
                    }),
                               // We need a fake match just so it can be passed to the procedural rule.
                               new PossibleMatch[] { new PossibleMatch(null) }));
                }

                // Only accept matches that consumed all of the input as valid, successful matches.
                matches = matches.Where(m => m.Next == null);

                // If we did consume all of the input, we will assume this match is successful. Note it is
                // possible for a command to generate multiple matches, but not possible to match multiple commands.
                if (matches.Count() > 0)
                {
                    return(new MatchedCommand(command, matches));
                }
            }

            // No command matched; lets return a dummy command that display's the huh? text.
            return(new MatchedCommand(
                       new CommandEntry()
                       .ProceduralRule((match, actor) =>
            {
                // Todo: Expand match arguments into error message.
                if (matchContext.BestFailedCommand != null && matchContext.BestFailedMatch.ParseDepth > 0)
                {
                    Core.SendMessage(actor, "That's the name of a command, but I couldn't figure out what you meant.");
                    Core.SendMessage(actor, "The best failed match was " + matchContext.BestFailedCommand.ManualName + ", which reached a depth of " + matchContext.BestFailedMatch.ParseDepth);
                    if (!String.IsNullOrEmpty(matchContext.BestFailedParseStageDescription))
                    {
                        Core.SendMessage(actor, Core.FormatParserMessage(actor, matchContext.BestFailedParseStageDescription, matchContext.BestFailedMatch));
                    }
                }
                else
                {
                    Core.SendMessage(actor, "I don't think that is a command I know. I could not parse any of it.");
                }

                return PerformResult.Continue;
            }),
                       new PossibleMatch[] { new PossibleMatch(null) }
                       ));
        }
Пример #22
0
 public List<PossibleMatch> Match(PossibleMatch State, MatchContext Context)
 {
     return MatchFunc(State, Context);
 }
Пример #23
0
 override protected List <PossibleMatch> ImplementMatch(PossibleMatch State, MatchContext Context)
 {
     return(MatchFunc(State, Context));
 }
Пример #24
0
 /// <summary>
 /// Find all possible matches. Matches returned should be ordered best to worst.
 /// </summary>
 /// <param name="State"></param>
 /// <param name="Context"></param>
 /// <returns>An empty list if no match, otherwise a list of possible matches</returns>
 public List <PossibleMatch> Match(PossibleMatch State, MatchContext Context)
 {
     Context.ParseStage(State, ParseStageDescription);
     return(ImplementMatch(State, Context));
 }
Пример #25
0
 public List<MudObject> GetObjects(PossibleMatch State, MatchContext Context)
 {
     return new List<MudObject>(ChatChannel.ChatChannels);
 }
Пример #26
0
 /// <summary>
 /// Find all possible matches. Matches returned should be ordered best to worst.
 /// </summary>
 /// <param name="State"></param>
 /// <param name="Context"></param>
 /// <returns>An empty list if no match, otherwise a list of possible matches</returns>
 protected virtual List <PossibleMatch> ImplementMatch(PossibleMatch State, MatchContext Context)
 {
     throw new NotImplementedException();
 }
Пример #27
0
 public List<MudObject> GetObjects(PossibleMatch State, MatchContext Context)
 {
     return new List<MudObject>(Context.ObjectsInScope);
 }
Пример #28
0
 public List <MudObject> GetObjects(PossibleMatch State, MatchContext Context)
 {
     return(new List <MudObject>(Context.ObjectsInScope));
 }
Пример #29
0
 public List <PossibleMatch> Match(PossibleMatch State, MatchContext Context)
 {
     return(MatchFunc(State, Context));
 }
Пример #30
0
        public MatchedCommand ParseCommand(PendingCommand Command)
        {
            var tokens = new LinkedList <String>(Command.RawCommand.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries));

            var rootMatch = new PossibleMatch(tokens.First);

            rootMatch.Upsert("ACTOR", Command.Actor);
            rootMatch.Upsert("LOCATION", Command.Actor == null ? null : Command.Actor.Location);

            // A pending command can have some properties set when it is queued. For example, the 'go' action
            // generates a 'look' command after processing. It will give the 'look' command a property named
            // 'auto' to indicate that the look command was generated. Rules can then use this property to
            // implement behavior. From the same example, 'look' may emit a brief description if it is generated
            // by the 'go' action, but emit a more detailed description if the player enters the command 'look'.
            //      See StandardActions.Go
            if (Command.PreSettings != null)
            {
                foreach (var setting in Command.PreSettings)
                {
                    rootMatch.Upsert(setting.Key.ToUpper(), setting.Value);
                }
            }

            var matchContext = new MatchContext {
                ExecutingActor = Command.Actor
            };

            // Try every single command defined, until one matches.
            foreach (var command in Commands)
            {
                IEnumerable <PossibleMatch> matches;

                try
                {
                    matches = command.Matcher.Match(rootMatch, matchContext);
                }
                catch (MatchAborted ma)
                {
                    // The match didn't fail; it generated an error. These means the match progressed to a point
                    // where the author of the command felt that the input could not logically match any other
                    // command, however, the input was still malformed in some way. Abort matching, and dummy up
                    // a command entry to display the error message to the player.
                    return(new MatchedCommand(
                               new CommandEntry().ProceduralRule((match, actor) =>
                    {
                        MudObject.SendMessage(actor, ma.Message);
                        return PerformResult.Continue;
                    }),
                               // We need a fake match just so it can be passed to the procedural rule.
                               new PossibleMatch[] { new PossibleMatch(null) }));
                }

                // Only accept matches that consumed all of the input.
                matches = matches.Where(m => m.Next == null);

                // If we did consume all of the input, we will assume this match is successful. Note it is
                // possible for a command to generate multiple matches, but not possible to match multiple commands.
                if (matches.Count() > 0)
                {
                    return(new MatchedCommand(command, matches));
                }
            }
            return(null);
        }