Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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)));
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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)));
 }
Ejemplo n.º 19
0
 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));
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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) }
                       ));
        }
Ejemplo n.º 22
0
 public List<PossibleMatch> Match(PossibleMatch State, MatchContext Context)
 {
     return MatchFunc(State, Context);
 }
Ejemplo n.º 23
0
 override protected List <PossibleMatch> ImplementMatch(PossibleMatch State, MatchContext Context)
 {
     return(MatchFunc(State, Context));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 25
0
 public List<MudObject> GetObjects(PossibleMatch State, MatchContext Context)
 {
     return new List<MudObject>(ChatChannel.ChatChannels);
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 27
0
 public List<MudObject> GetObjects(PossibleMatch State, MatchContext Context)
 {
     return new List<MudObject>(Context.ObjectsInScope);
 }
Ejemplo n.º 28
0
 public List <MudObject> GetObjects(PossibleMatch State, MatchContext Context)
 {
     return(new List <MudObject>(Context.ObjectsInScope));
 }
Ejemplo n.º 29
0
 public List <PossibleMatch> Match(PossibleMatch State, MatchContext Context)
 {
     return(MatchFunc(State, Context));
 }
Ejemplo n.º 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);
        }