Esempio n. 1
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.GetProperty <String>("short")) : (article + " " + thing.GetProperty <String>("short"))))
            .Name("Default name of a thing.");
        }
Esempio n. 2
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.");
        }
Esempio n. 3
0
        public static void AtStartup(RMUD.RuleEngine GlobalRules)
        {
            PropertyManifest.RegisterProperty("active-quest", typeof(MudObject), null, new DefaultSerializer());
            PropertyManifest.RegisterProperty("offered-quest", typeof(MudObject), null, new DefaultSerializer());

            GlobalRules.Perform <PossibleMatch, MudObject>("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.SetProperty("active-quest", null);
                        GlobalRules.ConsiderPerformRule("quest completed", actor, quest);
                    }
                    else if (GlobalRules.ConsiderValueRule <bool>("quest failed?", actor, quest))
                    {
                        actor.SetProperty("active-quest", null);
                        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.");
        }
Esempio n. 4
0
        public static void AtStartup(RMUD.RuleEngine GlobalRules)
        {
            PropertyManifest.RegisterProperty("introduction memory", typeof(Dictionary <String, bool>), null, new DefaultSerializer());

            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.GetProperty <bool>("actor?"))
            .Do((a, b) =>
            {
                Core.SendMessage(a, "That just sounds silly.");
                return(CheckResult.Disallow);
            })
            .Name("Can only introduce actors rule.");

            GlobalRules.Check <MudObject, MudObject>("can introduce?")
            .Do((a, b) => Core.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) =>
            {
                Core.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, MudObject>("describe")
            .First
            .When((viewer, actor) => GlobalRules.ConsiderValueRule <bool>("actor knows actor?", viewer, actor))
            .Do((viewer, actor) =>
            {
                Core.SendMessage(viewer, "^<the0>, a " + (actor.GetProperty <Gender>("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 = Core.FindLocale(introductee);
                if (locale != null)
                {
                    foreach (var player in Core.EnumerateObjectTree(locale).Where(o => o.GetProperty <bool>("actor?")))
                    {
                        GlobalRules.ConsiderPerformRule("introduce to", introductee, player);
                    }
                }

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

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

            GlobalRules.Perform <MudObject>("introduce self")
            .Do((introductee) =>
            {
                var locale = Core.FindLocale(introductee);
                if (locale != null)
                {
                    foreach (var player in Core.EnumerateObjectTree(locale).Where(o => o.GetProperty <bool>("actor?")))
                    {
                        GlobalRules.ConsiderPerformRule("introduce to", introductee, player);
                    }
                }

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

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

            #endregion

            #region Printed name rules

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

            GlobalRules.Value <MudObject, MudObject, String, String>("printed name")
            .When((viewer, thing, article) => thing.GetProperty <bool>("actor?"))
            .When((viewer, thing, article) => thing.GetProperty <Gender>("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.GetProperty <bool>("actor?"))
            .When((viewer, thing, article) => thing.GetProperty <Gender>("gender") == Gender.Female)
            .Do((viewer, actor, article) => article + " woman")
            .Name("Default name for unintroduced female actor.");

            #endregion

            #region Knowledge management rules

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

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

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

            GlobalRules.Perform <MudObject, MudObject>("introduce to")
            .Do((introductee, player) =>
            {
                RememberActor(player, introductee);
                return(PerformResult.Continue);
            })
            .Name("Players remember actors rule.");

            #endregion
        }
Esempio n. 5
0
        public static void AtStartup(RMUD.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.GetProperty <bool>("actor?")))
            .Do((actor, target) =>
            {
                Core.SendMessage(actor, "That just sounds silly.");
                return(CheckResult.Disallow);
            })
            .Name("Can only silly actors rule.");

            GlobalRules.Check <MudObject, MudObject>("can silly?")
            .Do((actor, target) => Core.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) =>
            {
                Core.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) =>
            {
                Core.SendExternalMessage(actor, "^<the0> applies extra silly to <the1>.", actor, target);
                Core.SendMessage(actor, "You apply extra silly to <the0>.", target);

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

                target.AddNoun("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.GetProperty <String>("short"));
                })
                .Name("Silly things have silly names rule.")
                .ID(ruleID.ToString());

                GlobalRules.Perform("heartbeat")
                .Do(() =>
                {
                    counter -= 1;
                    if (counter <= 0)
                    {
                        Core.SendExternalMessage(target, "^<the0> is serious now.", target);
                        target.GetProperty <NounList>("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 =>
            {
                Core.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 =>
            {
                Core.SendExternalMessage(actor, "^<the0> does a very silly dance.", actor);
                Core.SendMessage(actor, "You do a very silly dance.");
                return(PerformResult.Continue);
            })
            .Name("They aren't no friends of mine rule.");
        }