Example #1
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.Perform<PossibleMatch, Actor>("after acting")
                .Do((match, actor) =>
                {
                    if (actor.GetProperty<MudObject>("active-quest") != null)
                    {
                        var quest = actor.GetProperty<MudObject>("active-quest");

                        if (GlobalRules.ConsiderValueRule<bool>("quest complete?", actor, quest))
                        {
                            actor.RemoveProperty("active-quest");
                            GlobalRules.ConsiderPerformRule("quest completed", actor, quest);
                        }
                        else if (GlobalRules.ConsiderValueRule<bool>("quest failed?", actor, quest))
                        {
                            actor.RemoveProperty("active-quest");
                            GlobalRules.ConsiderPerformRule("quest failed", actor, quest);
                        }
                    }

                    return PerformResult.Continue;
                })
                .Name("Check quest status after acting rule.");

            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("quest reset", "[quest, thing] : The quest is being reset. Quests can call this on objects they interact with.", "quest", "item");

            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("quest accepted", "[actor, quest] : Handle accepting a quest.", "actor", "quest");
            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("quest completed", "[actor, quest] : Handle when a quest is completed.", "actor", "quest");
            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("quest failed", "[actor, quest] : Handle when a quest is failed.", "actor", "quest");
            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("quest abandoned", "[actor, quest] : Handle when a quest is abandoned.", "actor", "quest");

            GlobalRules.Perform<MudObject, MudObject>("quest abandoned")
                .Last
                .Do((actor, quest) =>
                {
                    return GlobalRules.ConsiderPerformRule("quest failed", actor, quest);
                })
                .Name("Abandoning a quest is failure rule.");

            GlobalRules.DeclareValueRuleBook<MudObject, MudObject, bool>("quest available?", "[actor, quest -> bool] : Is the quest available to this actor?", "actor", "quest");

            GlobalRules.Value<MudObject, MudObject, bool>("quest available?")
                .Do((Actor, quest) => false)
                .Name("Quests unavailable by default rule.");

            GlobalRules.DeclareValueRuleBook<MudObject, MudObject, bool>("quest complete?", "[actor, quest -> bool] : Has this actor completed this quest?", "actor", "quest");

            GlobalRules.Value<MudObject, MudObject, bool>("quest complete?")
                .Do((actor, quest) => false)
                .Name("Quests incomplete by default rule.");

            GlobalRules.DeclareValueRuleBook<MudObject, MudObject, bool>("quest failed?", "[actor, quest -> bool] : Has this actor failed this quest?", "actor", "quest");

            GlobalRules.Value<MudObject, MudObject, bool>("quest failed?")
                .Do((actor, quest) => false)
                .Name("Quests can't fail by default rule.");
        }
Example #2
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.Perform <PossibleMatch, Actor>("after acting")
            .Do((match, actor) =>
            {
                if (actor.GetProperty <MudObject>("active-quest") != null)
                {
                    var quest = actor.GetProperty <MudObject>("active-quest");

                    if (GlobalRules.ConsiderValueRule <bool>("quest complete?", actor, quest))
                    {
                        actor.RemoveProperty("active-quest");
                        GlobalRules.ConsiderPerformRule("quest completed", actor, quest);
                    }
                    else if (GlobalRules.ConsiderValueRule <bool>("quest failed?", actor, quest))
                    {
                        actor.RemoveProperty("active-quest");
                        GlobalRules.ConsiderPerformRule("quest failed", actor, quest);
                    }
                }

                return(PerformResult.Continue);
            })
            .Name("Check quest status after acting rule.");

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("quest reset", "[quest, thing] : The quest is being reset. Quests can call this on objects they interact with.", "quest", "item");

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("quest accepted", "[actor, quest] : Handle accepting a quest.", "actor", "quest");
            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("quest completed", "[actor, quest] : Handle when a quest is completed.", "actor", "quest");
            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("quest failed", "[actor, quest] : Handle when a quest is failed.", "actor", "quest");
            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("quest abandoned", "[actor, quest] : Handle when a quest is abandoned.", "actor", "quest");

            GlobalRules.Perform <MudObject, MudObject>("quest abandoned")
            .Last
            .Do((actor, quest) =>
            {
                return(GlobalRules.ConsiderPerformRule("quest failed", actor, quest));
            })
            .Name("Abandoning a quest is failure rule.");

            GlobalRules.DeclareValueRuleBook <MudObject, MudObject, bool>("quest available?", "[actor, quest -> bool] : Is the quest available to this actor?", "actor", "quest");

            GlobalRules.Value <MudObject, MudObject, bool>("quest available?")
            .Do((Actor, quest) => false)
            .Name("Quests unavailable by default rule.");

            GlobalRules.DeclareValueRuleBook <MudObject, MudObject, bool>("quest complete?", "[actor, quest -> bool] : Has this actor completed this quest?", "actor", "quest");

            GlobalRules.Value <MudObject, MudObject, bool>("quest complete?")
            .Do((actor, quest) => false)
            .Name("Quests incomplete by default rule.");

            GlobalRules.DeclareValueRuleBook <MudObject, MudObject, bool>("quest failed?", "[actor, quest -> bool] : Has this actor failed this quest?", "actor", "quest");

            GlobalRules.Value <MudObject, MudObject, bool>("quest failed?")
            .Do((actor, quest) => false)
            .Name("Quests can't fail by default rule.");
        }
Example #3
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareValueRuleBook<MudObject, MudObject, String, String>("printed name", "[Viewer, Object, Article -> String] : Find the name that should be displayed for an object.", "actor", "item", "article");

            GlobalRules.Value<MudObject, MudObject, String, String>("printed name")
               .Last
               .Do((viewer, thing, article) => (String.IsNullOrEmpty(article) ? (thing.Short) : (article + " " + thing.Short)))
               .Name("Default name of a thing.");
        }
Example #4
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareValueRuleBook<MudObject, LightingLevel>("light level", "[item] -> LightingLevel, How much light does the item emit?", "item");

            GlobalRules.Value<MudObject, LightingLevel>("light level")
                .Do(item => LightingLevel.Dark)
                .Name("Items emit no light by default rule.");

            GlobalRules.Perform<Room>("update")
                .Do(room =>
                {
                    room.UpdateLighting();
                    return PerformResult.Continue;
                })
                .Name("Update room lighting rule.");
        }
Example #5
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("not lockable", "I don't think the concept of 'locked' applies to that.");
            Core.StandardMessage("you lock", "You lock <the0>.");
            Core.StandardMessage("they lock", "^<the0> locks <the1> with <the2>.");

            GlobalRules.DeclareValueRuleBook<MudObject, bool>("lockable?", "[Item] : Can this item be locked?", "item");

            GlobalRules.Value<MudObject, bool>("lockable?").Do(item => false).Name("Things not lockable by default rule.");

            GlobalRules.DeclareCheckRuleBook<MudObject, MudObject, MudObject>("can lock?", "[Actor, Item, Key] : Can the item be locked by the actor with the key?", "actor", "item", "key");

            GlobalRules.Check<MudObject, MudObject, MudObject>("can lock?")
                .Do((actor, item, key) => MudObject.CheckIsVisibleTo(actor, item))
                .Name("Item must be visible to lock it.");

            GlobalRules.Check<MudObject, MudObject, MudObject>("can lock?")
                .Do((actor, item, key) => MudObject.CheckIsHolding(actor, key))
                .Name("Key must be held rule.");

            GlobalRules.Check<MudObject, MudObject, MudObject>("can lock?")
                .When((actor, item, key) => !GlobalRules.ConsiderValueRule<bool>("lockable?", item))
                .Do((a, b, c) =>
                {
                    MudObject.SendMessage(a, "@not lockable");
                    return CheckResult.Disallow;
                })
                .Name("Can't lock the unlockable rule.");

            GlobalRules.Check<MudObject, MudObject, MudObject>("can lock?")
                .Do((a, b, c) => CheckResult.Allow)
                .Name("Default allow locking rule.");

            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject, MudObject>("locked", "[Actor, Item, Key] : Handle the actor locking the item with the key.", "actor", "item", "key");

            GlobalRules.Perform<MudObject, MudObject, MudObject>("locked").Do((actor, target, key) =>
            {
                MudObject.SendMessage(actor, "@you lock", target);
                MudObject.SendExternalMessage(actor, "@they lock", actor, target, key);
                return PerformResult.Continue;
            });
        }
Example #6
0
File: Lock.cs Project: SinaC/RMUD
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("not lockable", "I don't think the concept of 'locked' applies to that.");
            Core.StandardMessage("you lock", "You lock <the0>.");
            Core.StandardMessage("they lock", "^<the0> locks <the1> with <the2>.");

            GlobalRules.DeclareValueRuleBook <MudObject, bool>("lockable?", "[Item] : Can this item be locked?", "item");

            GlobalRules.Value <MudObject, bool>("lockable?").Do(item => false).Name("Things not lockable by default rule.");

            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject, MudObject>("can lock?", "[Actor, Item, Key] : Can the item be locked by the actor with the key?", "actor", "item", "key");

            GlobalRules.Check <MudObject, MudObject, MudObject>("can lock?")
            .Do((actor, item, key) => MudObject.CheckIsVisibleTo(actor, item))
            .Name("Item must be visible to lock it.");

            GlobalRules.Check <MudObject, MudObject, MudObject>("can lock?")
            .Do((actor, item, key) => MudObject.CheckIsHolding(actor, key))
            .Name("Key must be held rule.");

            GlobalRules.Check <MudObject, MudObject, MudObject>("can lock?")
            .When((actor, item, key) => !GlobalRules.ConsiderValueRule <bool>("lockable?", item))
            .Do((a, b, c) =>
            {
                MudObject.SendMessage(a, "@not lockable");
                return(CheckResult.Disallow);
            })
            .Name("Can't lock the unlockable rule.");

            GlobalRules.Check <MudObject, MudObject, MudObject>("can lock?")
            .Do((a, b, c) => CheckResult.Allow)
            .Name("Default allow locking rule.");

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject, MudObject>("locked", "[Actor, Item, Key] : Handle the actor locking the item with the key.", "actor", "item", "key");

            GlobalRules.Perform <MudObject, MudObject, MudObject>("locked").Do((actor, target, key) =>
            {
                MudObject.SendMessage(actor, "@you lock", target);
                MudObject.SendExternalMessage(actor, "@they lock", actor, target, key);
                return(PerformResult.Continue);
            });
        }
Example #7
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook<MudObject, MudObject>("can introduce?", "[Actor A, Actor B] : Can A introduce B?", "actor", "itroductee");

            GlobalRules.Check<MudObject, MudObject>("can introduce?")
                .When((a, b) => !(b is Actor))
                .Do((a, b) =>
                {
                    MudObject.SendMessage(a, "That just sounds silly.");
                    return CheckResult.Disallow;
                })
                .Name("Can only introduce actors rule.");

            GlobalRules.Check<MudObject, MudObject>("can introduce?")
                .Do((a, b) => MudObject.CheckIsVisibleTo(a, b))
                .Name("Introducee must be visible rule.");

            GlobalRules.Check<MudObject, MudObject>("can introduce?")
                .When((a, b) => !GlobalRules.ConsiderValueRule<bool>("actor knows actor?", a, b))
                .Do((a, b) =>
                {
                    MudObject.SendMessage(a, "How can you introduce <the0> when you don't know them yourself?", b);
                    return CheckResult.Disallow;
                })
                .Name("Can't introduce who you don't know rule.");

            GlobalRules.Perform<MudObject, Actor>("describe")
                .First
                .When((viewer, actor) => GlobalRules.ConsiderValueRule<bool>("actor knows actor?", viewer, actor))
                .Do((viewer, actor) =>
                {
                    MudObject.SendMessage(viewer, "^<the0>, a " + (actor.Gender == Gender.Male ? "man." : "woman."), actor);
                    return PerformResult.Continue;
                })
                .Name("Report gender of known actors rule.");

            #region Perform and report rules

            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("introduce", "[Actor A, Actor B] : Handle A introducing B.", "actor", "introductee");

            GlobalRules.Perform<MudObject, MudObject>("introduce")
                .Do((actor, introductee) =>
                {
                    var locale = MudObject.FindLocale(introductee);
                    if (locale != null)
                        foreach (var player in MudObject.EnumerateObjectTree(locale).Where(o => o is Player).Select(o => o as Player))
                            GlobalRules.ConsiderPerformRule("introduce to", introductee, player);

                    MudObject.SendExternalMessage(actor, "^<the0> introduces <the1>.", actor, introductee);
                    MudObject.SendMessage(actor, "You introduce <the0>.", introductee);
                    return PerformResult.Continue;
                })
                .Name("Report introduction rule.");

            GlobalRules.DeclarePerformRuleBook<Actor>("introduce self", "[Introductee] : Introduce the introductee");

            GlobalRules.Perform<Actor>("introduce self")
                .Do((introductee) =>
                {
                    var locale = MudObject.FindLocale(introductee);
                    if (locale != null)
                        foreach (var player in MudObject.EnumerateObjectTree(locale).Where(o => o is Player).Select(o => o as Player))
                            GlobalRules.ConsiderPerformRule("introduce to", introductee, player);

                    MudObject.SendExternalMessage(introductee, "^<the0> introduces themselves.", introductee);
                    MudObject.SendMessage(introductee, "You introduce yourself.");

                    return PerformResult.Continue;
                })
                .Name("Introduce an actor to everyone present rule.");

            #endregion

            #region Printed name rules

            GlobalRules.Value<Player, Actor, String, String>("printed name")
                .When((viewer, thing, article) => GlobalRules.ConsiderValueRule<bool>("actor knows actor?", viewer, thing))
                .Do((viewer, actor, article) => actor.Short)
                .Name("Name of introduced actor.");

            GlobalRules.Value<MudObject, MudObject, String, String>("printed name")
                .When((viewer, thing, article) => thing is Actor && (thing as Actor).Gender == Gender.Male)
                .Do((viewer, actor, article) => article + " man")
                .Name("Default name for unintroduced male actor.");

            GlobalRules.Value<MudObject, MudObject, String, String>("printed name")
                .When((viewer, thing, article) => thing is Actor && (thing as Actor).Gender == Gender.Female)
                .Do((viewer, actor, article) => article + " woman")
                .Name("Default name for unintroduced female actor.");

            #endregion

            #region Knowledge management rules

            GlobalRules.DeclareValueRuleBook<Actor, Actor, bool>("actor knows actor?", "[Player, Whom] : Does the player know the actor?");

            GlobalRules.Value<Player, Actor, bool>("actor knows actor?")
                .Do((player, whom) => player.Recall<bool>(whom, "knows"))
                .Name("Use player memory to recall actors rule.");

            GlobalRules.Value<Actor, Actor, bool>("actor knows actor?")
                .Do((player, whom) => false)
                .Name("Actors that aren't players don't know anybody rule.");

            GlobalRules.DeclarePerformRuleBook<Actor, Actor>("introduce to", "[Introductee, ToWhom] : Introduce the introductee to someone");

            GlobalRules.Perform<Actor, Player>("introduce to")
                .Do((introductee, player) =>
                {
                    player.Remember(introductee, "knows", true);
                    return PerformResult.Continue;
                })
                .Name("Players remember actors rule.");

            #endregion
        }
Example #8
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareValueRuleBook<MudObject, bool>("silly?", "[Thing -> bool] : Determine if an object is silly.", "item");
            GlobalRules.Value<MudObject, bool>("silly?").Last.Do((thing) => false).Name("Things are serious by default rule.");

            GlobalRules.DeclareCheckRuleBook<MudObject, MudObject>("can silly?", "[Actor, Target] : Can the actor make the target silly?", "actor", "item");

            GlobalRules.Check<MudObject, MudObject>("can silly?").First
                .When((actor, target) => !(target is Actor))
                .Do((actor, target) =>
                {
                    MudObject.SendMessage(actor, "That just sounds silly.");
                    return CheckResult.Disallow;
                })
                .Name("Can only silly actors rule.");

            GlobalRules.Check<MudObject, MudObject>("can silly?")
                .Do((actor, target) => MudObject.CheckIsVisibleTo(actor, target))
                .Name("Silly target must be visible.");

            GlobalRules.Check<MudObject, MudObject>("can silly?")
                .When((actor, target) => GlobalRules.ConsiderValueRule<bool>("silly?", target))
                .Do((actor, target) =>
                {
                    MudObject.SendMessage(actor, "^<the0> is already silly.", target);
                    return CheckResult.Disallow;
                })
                .Name("Can't silly if already silly rule.");

            GlobalRules.Check<MudObject, MudObject>("can silly?")
                .Last
                .Do((actor, target) => CheckResult.Allow)
                .Name("Let the silliness ensue rule.");

            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("silly", "[Actor, Target] : Apply silly status to the target.", "actor", "item");

            GlobalRules.Perform<MudObject, MudObject>("silly")
                .Do((actor, target) =>
                {
                    MudObject.SendExternalMessage(actor, "^<the0> applies extra silly to <the1>.", actor, target);
                    MudObject.SendMessage(actor, "You apply extra silly to <the0>.", target);

                    var ruleID = Guid.NewGuid();
                    var counter = 100;

                    target.Nouns.Add("silly");

                    target.Value<MudObject, bool>("silly?").Do((thing) => true).ID(ruleID.ToString())
                        .Name("Silly things are silly rule.");

                    target.Value<MudObject, MudObject, String, String>("printed name")
                        .Do((viewer, thing, article) =>
                        {
                            return "silly " + thing.Short;
                        })
                        .Name("Silly things have silly names rule.")
                        .ID(ruleID.ToString());

                    GlobalRules.Perform("heartbeat")
                        .Do(() =>
                        {
                            counter -= 1;
                            if (counter <= 0)
                            {
                                MudObject.SendExternalMessage(target, "^<the0> is serious now.", target);
                                target.Nouns.Remove("silly");
                                target.Rules.DeleteAll(ruleID.ToString());
                                GlobalRules.DeleteRule("heartbeat", ruleID.ToString());
                            }
                            return PerformResult.Continue;
                        })
                        .ID(ruleID.ToString())
                        .Name("Countdown to seriousness rule.");

                    return PerformResult.Continue;
                })
                .Name("Apply sillyness rule.");

            GlobalRules.DeclareCheckRuleBook<MudObject>("can dance?", "[Actor] : Can the actor dance?", "actor");

            GlobalRules.Check<MudObject>("can dance?")
                .When(actor => !GlobalRules.ConsiderValueRule<bool>("silly?", actor))
                .Do(actor =>
                {
                    MudObject.SendMessage(actor, "You don't feel silly enough for that.");
                    return CheckResult.Disallow;
                })
                .Name("Your friends don't dance rule.");

            GlobalRules.Check<MudObject>("can dance?")
                .Last
                .Do(actor => CheckResult.Allow)
                .Name("You can dance if you want to rule.");

            GlobalRules.DeclarePerformRuleBook<MudObject>("dance", "[Actor] : Perform a silly dance.", "actor");

            GlobalRules.Perform<MudObject>("dance")
                .Do(actor =>
                {
                    MudObject.SendExternalMessage(actor, "^<the0> does a very silly dance.", actor);
                    MudObject.SendMessage(actor, "You do a very silly dance.");
                    return PerformResult.Continue;
                })
                .Name("They aren't no friends of mine rule.");
        }
Example #9
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject>("can introduce?", "[Actor A, Actor B] : Can A introduce B?", "actor", "itroductee");

            GlobalRules.Check <MudObject, MudObject>("can introduce?")
            .When((a, b) => !(b is Actor))
            .Do((a, b) =>
            {
                MudObject.SendMessage(a, "That just sounds silly.");
                return(CheckResult.Disallow);
            })
            .Name("Can only introduce actors rule.");

            GlobalRules.Check <MudObject, MudObject>("can introduce?")
            .Do((a, b) => MudObject.CheckIsVisibleTo(a, b))
            .Name("Introducee must be visible rule.");

            GlobalRules.Check <MudObject, MudObject>("can introduce?")
            .When((a, b) => !GlobalRules.ConsiderValueRule <bool>("actor knows actor?", a, b))
            .Do((a, b) =>
            {
                MudObject.SendMessage(a, "How can you introduce <the0> when you don't know them yourself?", b);
                return(CheckResult.Disallow);
            })
            .Name("Can't introduce who you don't know rule.");

            GlobalRules.Perform <MudObject, Actor>("describe")
            .First
            .When((viewer, actor) => GlobalRules.ConsiderValueRule <bool>("actor knows actor?", viewer, actor))
            .Do((viewer, actor) =>
            {
                MudObject.SendMessage(viewer, "^<the0>, a " + (actor.Gender == Gender.Male ? "man." : "woman."), actor);
                return(PerformResult.Continue);
            })
            .Name("Report gender of known actors rule.");

            #region Perform and report rules

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("introduce", "[Actor A, Actor B] : Handle A introducing B.", "actor", "introductee");

            GlobalRules.Perform <MudObject, MudObject>("introduce")
            .Do((actor, introductee) =>
            {
                var locale = MudObject.FindLocale(introductee);
                if (locale != null)
                {
                    foreach (var player in MudObject.EnumerateObjectTree(locale).Where(o => o is Player).Select(o => o as Player))
                    {
                        GlobalRules.ConsiderPerformRule("introduce to", introductee, player);
                    }
                }

                MudObject.SendExternalMessage(actor, "^<the0> introduces <the1>.", actor, introductee);
                MudObject.SendMessage(actor, "You introduce <the0>.", introductee);
                return(PerformResult.Continue);
            })
            .Name("Report introduction rule.");

            GlobalRules.DeclarePerformRuleBook <Actor>("introduce self", "[Introductee] : Introduce the introductee");

            GlobalRules.Perform <Actor>("introduce self")
            .Do((introductee) =>
            {
                var locale = MudObject.FindLocale(introductee);
                if (locale != null)
                {
                    foreach (var player in MudObject.EnumerateObjectTree(locale).Where(o => o is Player).Select(o => o as Player))
                    {
                        GlobalRules.ConsiderPerformRule("introduce to", introductee, player);
                    }
                }

                MudObject.SendExternalMessage(introductee, "^<the0> introduces themselves.", introductee);
                MudObject.SendMessage(introductee, "You introduce yourself.");

                return(PerformResult.Continue);
            })
            .Name("Introduce an actor to everyone present rule.");

            #endregion

            #region Printed name rules

            GlobalRules.Value <Player, Actor, String, String>("printed name")
            .When((viewer, thing, article) => GlobalRules.ConsiderValueRule <bool>("actor knows actor?", viewer, thing))
            .Do((viewer, actor, article) => actor.Short)
            .Name("Name of introduced actor.");

            GlobalRules.Value <MudObject, MudObject, String, String>("printed name")
            .When((viewer, thing, article) => thing is Actor && (thing as Actor).Gender == Gender.Male)
            .Do((viewer, actor, article) => article + " man")
            .Name("Default name for unintroduced male actor.");

            GlobalRules.Value <MudObject, MudObject, String, String>("printed name")
            .When((viewer, thing, article) => thing is Actor && (thing as Actor).Gender == Gender.Female)
            .Do((viewer, actor, article) => article + " woman")
            .Name("Default name for unintroduced female actor.");

            #endregion

            #region Knowledge management rules

            GlobalRules.DeclareValueRuleBook <Actor, Actor, bool>("actor knows actor?", "[Player, Whom] : Does the player know the actor?");

            GlobalRules.Value <Player, Actor, bool>("actor knows actor?")
            .Do((player, whom) => player.Recall <bool>(whom, "knows"))
            .Name("Use player memory to recall actors rule.");

            GlobalRules.Value <Actor, Actor, bool>("actor knows actor?")
            .Do((player, whom) => false)
            .Name("Actors that aren't players don't know anybody rule.");

            GlobalRules.DeclarePerformRuleBook <Actor, Actor>("introduce to", "[Introductee, ToWhom] : Introduce the introductee to someone");

            GlobalRules.Perform <Actor, Player>("introduce to")
            .Do((introductee, player) =>
            {
                player.Remember(introductee, "knows", true);
                return(PerformResult.Continue);
            })
            .Name("Players remember actors rule.");

            #endregion
        }
Example #10
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareValueRuleBook <MudObject, bool>("silly?", "[Thing -> bool] : Determine if an object is silly.", "item");
            GlobalRules.Value <MudObject, bool>("silly?").Last.Do((thing) => false).Name("Things are serious by default rule.");

            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject>("can silly?", "[Actor, Target] : Can the actor make the target silly?", "actor", "item");

            GlobalRules.Check <MudObject, MudObject>("can silly?").First
            .When((actor, target) => !(target is Actor))
            .Do((actor, target) =>
            {
                MudObject.SendMessage(actor, "That just sounds silly.");
                return(CheckResult.Disallow);
            })
            .Name("Can only silly actors rule.");

            GlobalRules.Check <MudObject, MudObject>("can silly?")
            .Do((actor, target) => MudObject.CheckIsVisibleTo(actor, target))
            .Name("Silly target must be visible.");

            GlobalRules.Check <MudObject, MudObject>("can silly?")
            .When((actor, target) => GlobalRules.ConsiderValueRule <bool>("silly?", target))
            .Do((actor, target) =>
            {
                MudObject.SendMessage(actor, "^<the0> is already silly.", target);
                return(CheckResult.Disallow);
            })
            .Name("Can't silly if already silly rule.");

            GlobalRules.Check <MudObject, MudObject>("can silly?")
            .Last
            .Do((actor, target) => CheckResult.Allow)
            .Name("Let the silliness ensue rule.");

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("silly", "[Actor, Target] : Apply silly status to the target.", "actor", "item");

            GlobalRules.Perform <MudObject, MudObject>("silly")
            .Do((actor, target) =>
            {
                MudObject.SendExternalMessage(actor, "^<the0> applies extra silly to <the1>.", actor, target);
                MudObject.SendMessage(actor, "You apply extra silly to <the0>.", target);

                var ruleID  = Guid.NewGuid();
                var counter = 100;

                target.Nouns.Add("silly");

                target.Value <MudObject, bool>("silly?").Do((thing) => true).ID(ruleID.ToString())
                .Name("Silly things are silly rule.");

                target.Value <MudObject, MudObject, String, String>("printed name")
                .Do((viewer, thing, article) =>
                {
                    return("silly " + thing.Short);
                })
                .Name("Silly things have silly names rule.")
                .ID(ruleID.ToString());

                GlobalRules.Perform("heartbeat")
                .Do(() =>
                {
                    counter -= 1;
                    if (counter <= 0)
                    {
                        MudObject.SendExternalMessage(target, "^<the0> is serious now.", target);
                        target.Nouns.Remove("silly");
                        target.Rules.DeleteAll(ruleID.ToString());
                        GlobalRules.DeleteRule("heartbeat", ruleID.ToString());
                    }
                    return(PerformResult.Continue);
                })
                .ID(ruleID.ToString())
                .Name("Countdown to seriousness rule.");

                return(PerformResult.Continue);
            })
            .Name("Apply sillyness rule.");

            GlobalRules.DeclareCheckRuleBook <MudObject>("can dance?", "[Actor] : Can the actor dance?", "actor");

            GlobalRules.Check <MudObject>("can dance?")
            .When(actor => !GlobalRules.ConsiderValueRule <bool>("silly?", actor))
            .Do(actor =>
            {
                MudObject.SendMessage(actor, "You don't feel silly enough for that.");
                return(CheckResult.Disallow);
            })
            .Name("Your friends don't dance rule.");

            GlobalRules.Check <MudObject>("can dance?")
            .Last
            .Do(actor => CheckResult.Allow)
            .Name("You can dance if you want to rule.");

            GlobalRules.DeclarePerformRuleBook <MudObject>("dance", "[Actor] : Perform a silly dance.", "actor");

            GlobalRules.Perform <MudObject>("dance")
            .Do(actor =>
            {
                MudObject.SendExternalMessage(actor, "^<the0> does a very silly dance.", actor);
                MudObject.SendMessage(actor, "You do a very silly dance.");
                return(PerformResult.Continue);
            })
            .Name("They aren't no friends of mine rule.");
        }