Example #1
0
 /// <summary>
 /// Add a proceedural rule to this command that invokes the before acting rulebook.
 /// </summary>
 /// <returns>This command</returns>
 public CommandEntry BeforeActing()
 {
     ProceduralRules.AddRule(new Rule <PerformResult> {
         BodyClause      = RuleDelegateWrapper <PerformResult> .MakeWrapper <PossibleMatch, Actor>((match, actor) => Core.GlobalRules.ConsiderMatchBasedPerformRule("before acting", match, actor)),
         DescriptiveName = "Before acting procedural rule."
     });
     return(this);
 }
Example #2
0
 /// <summary>
 /// Add a proceedural rule to this command that invokes the before acting rulebook.
 /// </summary>
 /// <returns>This command</returns>
 public CommandEntry BeforeActing()
 {
     GeneratedManual.AppendLine("Consider the before acting rules.");
     ProceduralRules.AddRule(new Rule <PerformResult> {
         BodyClause      = RuleDelegateWrapper <PerformResult> .MakeWrapper <PossibleMatch, MudObject>((match, actor) => Core.GlobalRules.ConsiderMatchBasedPerformRule("before acting", match, actor)),
         DescriptiveName = "Before acting procedural rule."
     });
     return(this);
 }
Example #3
0
        /// <summary>
        /// Add a procedural rule to this command.
        /// </summary>
        /// <param name="Rule"></param>
        /// <param name="Name"></param>
        /// <returns>This command</returns>
        public CommandEntry ProceduralRule(Func <PossibleMatch, Actor, PerformResult> Rule, String Name = "an unamed procedural rule")
        {
            GeneratedManual.AppendLine("Consider " + Name);

            var rule = new Rule <PerformResult>
            {
                BodyClause      = RuleDelegateWrapper <PerformResult> .MakeWrapper(Rule),
                DescriptiveName = Name
            };

            ProceduralRules.AddRule(rule);
            return(this);
        }
Example #4
0
        /// <summary>
        /// Add a proceedural rule to this command that considers the specified perform rule. Unlike Perform above,
        /// if the perform rule returns stop, the proceedural rules will also be stopped.
        /// </summary>
        /// <param name="RuleName"></param>
        /// <param name="RuleArguments"></param>
        /// <returns>This command</returns>
        public CommandEntry AbideBy(String RuleName, params String[] RuleArguments)
        {
            GeneratedManual.AppendLine("Consider the perform rulebook '" + RuleName + "' with arguments " + String.Join(", ", RuleArguments) + " and abide by the result.");

            var rule = new Rule <PerformResult>
            {
                BodyClause = RuleDelegateWrapper <PerformResult> .MakeWrapper <PossibleMatch, Actor>(
                    (match, actor) =>
                    Core.GlobalRules.ConsiderPerformRule(RuleName, RuleArguments.Select(a => match.ValueOrDefault(a)).ToArray())
                    ),
                DescriptiveName = "Procedural rule to abide by " + RuleName
            };

            ProceduralRules.AddRule(rule);
            return(this);
        }
Example #5
0
 public RuleBuilder <TR> When(Func <bool> Clause)
 {
     if (Rule.WhenClause != null)
     {
         var oldClause = Rule.WhenClause;
         Rule.WhenClause = RuleDelegateWrapper <bool> .MakeWrapper(
             new Func <bool>(() => {
             return(oldClause.Invoke(null) && Clause());
         })
             );
     }
     else
     {
         Rule.WhenClause = RuleDelegateWrapper <bool> .MakeWrapper(Clause);
     }
     return(this);
 }
Example #6
0
        /// <summary>
        /// Add a procedural rule to this command that marks the locale of the actor that entered the command
        /// for update.
        /// </summary>
        /// <returns>This command</returns>
        public CommandEntry MarkLocaleForUpdate()
        {
            GeneratedManual.AppendLine("Consider the mark locale for update rule");

            var rule = new Rule <PerformResult>
            {
                BodyClause = RuleDelegateWrapper <PerformResult> .MakeWrapper <PossibleMatch, Actor>(
                    (match, actor) =>
                {
                    Core.MarkLocaleForUpdate(match["ACTOR"] as MudObject);
                    return(PerformResult.Continue);
                }),
                DescriptiveName = "Procedural rule to mark locale for update."
            };

            ProceduralRules.AddRule(rule);
            return(this);
        }
Example #7
0
        /// <summary>
        /// Add a new procedural rule to this command that invokes a check rule. If the checkrule fails,
        /// processing of the proceedural rules is stopped.
        /// </summary>
        /// <param name="RuleName"></param>
        /// <param name="RuleArguments"></param>
        /// <returns>This command</returns>
        public CommandEntry Check(String RuleName, params String[] RuleArguments)
        {
            GeneratedManual.AppendLine("Consider the check rulebook '" + RuleName + "' with arguments " + String.Join(", ", RuleArguments));

            var rule = new Rule <PerformResult>
            {
                BodyClause = RuleDelegateWrapper <PerformResult> .MakeWrapper <PossibleMatch, Actor>(
                    (match, actor) =>
                {
                    if (Core.GlobalRules.ConsiderCheckRule(RuleName, RuleArguments.Select(a => match.ValueOrDefault(a)).ToArray()) == CheckResult.Allow)
                    {
                        return(PerformResult.Continue);
                    }
                    return(PerformResult.Stop);
                }),
                DescriptiveName = "Procedural rule to check " + RuleName
            };

            ProceduralRules.AddRule(rule);
            return(this);
        }
Example #8
0
        public RuleBuilder <TR> Do(Func <TR> Clause)
        {
            Rule.BodyClause = RuleDelegateWrapper <TR> .MakeWrapper(Clause);

            return(this);
        }