Example #1
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("say what", "Say what?");
            Core.StandardMessage("emote what", "You exist. Actually this is an error message, but that's what you just told me to say.");
            Core.StandardMessage("speak", "^<the0> : \"<s1>\"");
            Core.StandardMessage("emote", "^<the0> <s1>");

            GlobalRules.DeclarePerformRuleBook<MudObject, String>("speak", "[Actor, Text] : Handle the actor speaking the text.", "actor", "text");

            GlobalRules.Perform<MudObject, String>("speak")
                .Do((actor, text) =>
                {
                    MudObject.SendLocaleMessage(actor, "@speak", actor, text);
                    return PerformResult.Continue;
                })
                .Name("Default motormouth rule.");

            GlobalRules.DeclarePerformRuleBook<MudObject, String>("emote", "[Actor, Text] : Handle the actor emoting the text.", "actor", "text");

            GlobalRules.Perform<MudObject, String>("emote")
                .Do((actor, text) =>
                {
                    MudObject.SendLocaleMessage(actor, "@emote", actor, text);
                    return PerformResult.Continue;
                })
                .Name("Default exhibitionist rule.");
        }
Example #2
0
File: Say.cs Project: SinaC/RMUD
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("say what", "Say what?");
            Core.StandardMessage("emote what", "You exist. Actually this is an error message, but that's what you just told me to say.");
            Core.StandardMessage("speak", "^<the0> : \"<s1>\"");
            Core.StandardMessage("emote", "^<the0> <s1>");

            GlobalRules.DeclarePerformRuleBook <MudObject, String>("speak", "[Actor, Text] : Handle the actor speaking the text.", "actor", "text");

            GlobalRules.Perform <MudObject, String>("speak")
            .Do((actor, text) =>
            {
                MudObject.SendLocaleMessage(actor, "@speak", actor, text);
                return(PerformResult.Continue);
            })
            .Name("Default motormouth rule.");

            GlobalRules.DeclarePerformRuleBook <MudObject, String>("emote", "[Actor, Text] : Handle the actor emoting the text.", "actor", "text");

            GlobalRules.Perform <MudObject, String>("emote")
            .Do((actor, text) =>
            {
                MudObject.SendLocaleMessage(actor, "@emote", actor, text);
                return(PerformResult.Continue);
            })
            .Name("Default exhibitionist rule.");
        }
Example #3
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclarePerformRuleBook<PossibleMatch, Actor>("before command", "[Match, Actor] : Considered before every command's procedural rules are run.", "match", "actor");

            GlobalRules.DeclarePerformRuleBook<PossibleMatch, Actor>("after command", "[Match, Actor] : Considered after every command's procedural rules are run, unless the before command rules stopped the command.", "match", "actor");

            GlobalRules.DeclarePerformRuleBook<Actor>("after every command", "[Actor] : Considered after every command, even if earlier rules stopped the command.", "actor");
        }
Example #4
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 #5
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 #6
0
        /// <summary>
        /// Start the mud engine.
        /// </summary>
        /// <param name="Flags">Flags control engine functions</param>
        /// <param name="Database"></param>
        /// <param name="Assemblies">Modules to integrate</param>
        /// <returns></returns>
        public static bool Start(StartupFlags Flags, WorldDataService Database, params ModuleAssembly[] Assemblies)
        {
            ShuttingDown = false;
            Core.Flags = Flags;

            try
            {
                // Setup the rule engine and some basic rules.
                GlobalRules = new RuleEngine(NewRuleQueueingMode.QueueNewRules);
                GlobalRules.DeclarePerformRuleBook("at startup", "[] : Considered when the engine is started.");
                GlobalRules.DeclarePerformRuleBook<MudObject>("singleplayer game started", "Considered when a single player game is begun");

                // Integrate modules. The Core assembly is always integrated.
                IntegratedModules.Add(new ModuleAssembly(Assembly.GetExecutingAssembly(), new ModuleInfo { Author = "Blecki", Description = "RMUD Core", BaseNameSpace = "RMUD" }, "Core.dll"));
                IntegratedModules.AddRange(Assemblies);

                if ((Flags & StartupFlags.SearchDirectory) == StartupFlags.SearchDirectory)
                {
                    foreach (var file in System.IO.Directory.EnumerateFiles(System.IO.Directory.GetCurrentDirectory()).Where(p => System.IO.Path.GetExtension(p) == ".dll"))
                    {
                        var assembly = System.Reflection.Assembly.LoadFrom(file);

                        var infoType = assembly.GetTypes().FirstOrDefault(t => t.IsSubclassOf(typeof(ModuleInfo)));
                        if (infoType != null)
                        {
                            IntegratedModules.Add(new ModuleAssembly(assembly, file));
                            if ((Flags & StartupFlags.Silent) == 0)
                                Console.WriteLine("Discovered module: " + file);
                        }
                    }
                }

                foreach (var startupAssembly in IntegratedModules)
                    IntegrateModule(startupAssembly);

                PersistentValueSerializer.AddGlobalSerializer(new BitArraySerializer());

                InitializeCommandProcessor();

                GlobalRules.FinalizeNewRules();

                Core.Database = Database;
                Database.Initialize();

                GlobalRules.ConsiderPerformRule("at startup");

                if ((Flags & StartupFlags.SingleThreaded) == 0)
                    StartThreadedCommandProcesor();
            }
            catch (Exception e)
            {
                LogError("Failed to start mud engine.");
                LogError(e.Message);
                LogError(e.StackTrace);
                throw;
            }
            return true;
        }
Example #7
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclarePerformRuleBook<Actor>("player joined", "[Player] : Considered when a player enters the game.", "actor");

            GlobalRules.DeclarePerformRuleBook<Actor>("player left", "[Player] : Considered when a player leaves the game.", "actor");

            GlobalRules.Perform<Actor>("player joined")
                .First
                .Do((actor) =>
                {
                    MudObject.Move(actor, MudObject.GetObject(Core.SettingsObject.NewPlayerStartRoom));
                    return PerformResult.Continue;
                })
                .Name("Move to start room rule.");
        }
Example #8
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("you close", "You close <the0>.");
            Core.StandardMessage("they close", "^<the0> closes <the1>.");

            GlobalRules.DeclareCheckRuleBook<MudObject, MudObject>("can close?", "[Actor, Item] : Determine if the item can be closed.", "actor", "item");

            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("close", "[Actor, Item] : Handle the item being closed.", "actor", "item");

            GlobalRules.Check<MudObject, MudObject>("can close?")
                .When((actor, item) => !item.GetBooleanProperty("openable?"))
                .Do((a, b) =>
                {
                    MudObject.SendMessage(a, "@not openable");
                    return CheckResult.Disallow;
                })
                .Name("Default can't close unopenable things rule.");

            GlobalRules.Check<MudObject, MudObject>("can close?")
                .Do((actor, item) => CheckResult.Allow)
                .Name("Default close things rule.");

            GlobalRules.Perform<MudObject, MudObject>("close").Do((actor, target) =>
            {
                MudObject.SendMessage(actor, "@you close", target);
                MudObject.SendExternalMessage(actor, "@they close", actor, target);
                return PerformResult.Continue;
            }).Name("Default close reporting rule.");

            GlobalRules.Check<MudObject, MudObject>("can close?").First.Do((actor, item) => MudObject.CheckIsVisibleTo(actor, item)).Name("Item must be visible rule.");
        }
Example #9
0
File: Pull.cs Project: SinaC/RMUD
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject>("can pull?", "[Actor, Item] : Can the actor pull the item?", "actor", "item");
            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("pull", "[Actor, Item] : Handle the actor pulling the item.", "actor", "item");

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

            GlobalRules.Check <MudObject, MudObject>("can pull?")
            .Last
            .Do((a, t) =>
            {
                MudObject.SendMessage(a, "@does nothing");
                return(CheckResult.Disallow);
            })
            .Name("Default disallow pulling rule.");

            GlobalRules.Perform <MudObject, MudObject>("pull")
            .Do((actor, target) =>
            {
                MudObject.SendMessage(actor, "@nothing happens");
                return(PerformResult.Continue);
            })
            .Name("Default handle pulling rule.");

            GlobalRules.Check <MudObject, Actor>("can pull?")
            .First
            .Do((actor, thing) =>
            {
                MudObject.SendMessage(actor, "@unappreciated", thing);
                return(CheckResult.Disallow);
            })
            .Name("Can't pull people rule.");
        }
Example #10
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("empty handed", "You have nothing.");
            Core.StandardMessage("carrying", "You are carrying..");

            GlobalRules.DeclarePerformRuleBook <MudObject>("inventory", "[Actor] : Describes a player's inventory to themselves.", "actor");

            GlobalRules.Perform <Actor>("inventory")
            .Do(a =>
            {
                var heldObjects = (a as Actor).GetContents(RelativeLocations.Held);
                if (heldObjects.Count == 0)
                {
                    MudObject.SendMessage(a, "@empty handed");
                }
                else
                {
                    MudObject.SendMessage(a, "@carrying");
                    foreach (var item in heldObjects)
                    {
                        MudObject.SendMessage(a, "  <a0>", item);
                    }
                }
                return(PerformResult.Continue);
            })
            .Name("List held items in inventory rule.");
        }
Example #11
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("you close", "You close <the0>.");
            Core.StandardMessage("they close", "^<the0> closes <the1>.");

            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject>("can close?", "[Actor, Item] : Determine if the item can be closed.", "actor", "item");

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("close", "[Actor, Item] : Handle the item being closed.", "actor", "item");

            GlobalRules.Check <MudObject, MudObject>("can close?")
            .When((actor, item) => !item.GetBooleanProperty("openable?"))
            .Do((a, b) =>
            {
                MudObject.SendMessage(a, "@not openable");
                return(CheckResult.Disallow);
            })
            .Name("Default can't close unopenable things rule.");

            GlobalRules.Check <MudObject, MudObject>("can close?")
            .Do((actor, item) => CheckResult.Allow)
            .Name("Default close things rule.");

            GlobalRules.Perform <MudObject, MudObject>("close").Do((actor, target) =>
            {
                MudObject.SendMessage(actor, "@you close", target);
                MudObject.SendExternalMessage(actor, "@they close", actor, target);
                return(PerformResult.Continue);
            }).Name("Default close reporting rule.");

            GlobalRules.Check <MudObject, MudObject>("can close?").First.Do((actor, item) => MudObject.CheckIsVisibleTo(actor, item)).Name("Item must be visible rule.");
        }
Example #12
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("not openable", "I don't think the concept of 'open' applies to that.");
            Core.StandardMessage("you open", "You open <the0>.");
            Core.StandardMessage("they open", "^<the0> opens <the1>.");

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

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("opened", "[Actor, Item] : Handle the actor opening the item.", "actor", "item");

            GlobalRules.Check <MudObject, MudObject>("can open?")
            .When((actor, item) => !item.GetBooleanProperty("openable?"))
            .Do((a, b) =>
            {
                MudObject.SendMessage(a, "@not openable");
                return(CheckResult.Disallow);
            })
            .Name("Can't open the unopenable rule.");

            GlobalRules.Check <MudObject, MudObject>("can open?")
            .Do((a, b) => CheckResult.Allow)
            .Name("Default go ahead and open it rule.");

            GlobalRules.Perform <MudObject, MudObject>("opened").Do((actor, target) =>
            {
                MudObject.SendMessage(actor, "@you open", target);
                MudObject.SendExternalMessage(actor, "@they open", actor, target);
                return(PerformResult.Continue);
            }).Name("Default report opening rule.");

            GlobalRules.Check <MudObject, MudObject>("can open?").First.Do((actor, item) => MudObject.CheckIsVisibleTo(actor, item)).Name("Item must be visible rule.");
        }
Example #13
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("dont see that", "I don't see that here.");

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

            GlobalRules.Check <MudObject, MudObject>("can examine?")
            .First
            .Do((viewer, item) => MudObject.CheckIsVisibleTo(viewer, item))
            .Name("Can't examine what isn't here rule.");

            GlobalRules.Check <MudObject, MudObject>("can examine?")
            .Last
            .Do((viewer, item) => CheckResult.Allow)
            .Name("Default can examine everything rule.");

            GlobalRules.DeclarePerformRuleBook <MudObject>("examine", "[Actor] -> Take a close look at the actor's surroundings.");

            GlobalRules.Perform <MudObject>("examine")
            .Do((actor) =>
            {
                MudObject.SendMessage(actor, "A detailed account of all objects present.");
                if (actor.Location != null && actor.Location is Container)
                {
                    foreach (var item in (actor.Location as Container).EnumerateObjects().Where(i => !System.Object.ReferenceEquals(i, actor)))
                    {
                        MudObject.SendMessage(actor, "<a0>", item);
                    }
                }
                return(PerformResult.Continue);
            });
        }
Example #14
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("not openable", "I don't think the concept of 'open' applies to that.");
            Core.StandardMessage("you open", "You open <the0>.");
            Core.StandardMessage("they open", "^<the0> opens <the1>.");

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

            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("opened", "[Actor, Item] : Handle the actor opening the item.", "actor", "item");

            GlobalRules.Check<MudObject, MudObject>("can open?")
                .When((actor, item) => !item.GetBooleanProperty("openable?"))
                .Do((a, b) =>
                {
                    MudObject.SendMessage(a, "@not openable");
                    return CheckResult.Disallow;
                })
                .Name("Can't open the unopenable rule.");

            GlobalRules.Check<MudObject, MudObject>("can open?")
                .Do((a, b) => CheckResult.Allow)
                .Name("Default go ahead and open it rule.");

            GlobalRules.Perform<MudObject, MudObject>("opened").Do((actor, target) =>
            {
                MudObject.SendMessage(actor, "@you open", target);
                MudObject.SendExternalMessage(actor, "@they open", actor, target);
                return PerformResult.Continue;
            }).Name("Default report opening rule.");

            GlobalRules.Check<MudObject, MudObject>("can open?").First.Do((actor, item) => MudObject.CheckIsVisibleTo(actor, item)).Name("Item must be visible rule.");
        }
Example #15
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook<MudObject, MudObject>("can pull?", "[Actor, Item] : Can the actor pull the item?", "actor", "item");
            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("pull", "[Actor, Item] : Handle the actor pulling the item.", "actor", "item");

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

            GlobalRules.Check<MudObject, MudObject>("can pull?")
                .Last
                .Do((a, t) =>
                    {
                        MudObject.SendMessage(a, "@does nothing");
                        return CheckResult.Disallow;
                    })
                .Name("Default disallow pulling rule.");

            GlobalRules.Perform<MudObject, MudObject>("pull")
                .Do((actor, target) =>
                {
                    MudObject.SendMessage(actor, "@nothing happens");
                    return PerformResult.Continue;
                })
                .Name("Default handle pulling rule.");

            GlobalRules.Check<MudObject, Actor>("can pull?")
                .First
                .Do((actor, thing) =>
                {
                    MudObject.SendMessage(actor, "@unappreciated", thing);
                    return CheckResult.Disallow;
                })
                .Name("Can't pull people rule.");
        }
Example #16
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("dont see that", "I don't see that here.");

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

            GlobalRules.Check<MudObject, MudObject>("can examine?")
                .First
                .Do((viewer, item) => MudObject.CheckIsVisibleTo(viewer, item))
                .Name("Can't examine what isn't here rule.");

            GlobalRules.Check<MudObject, MudObject>("can examine?")
                .Last
                .Do((viewer, item) => CheckResult.Allow)
                .Name("Default can examine everything rule.");

            GlobalRules.DeclarePerformRuleBook<MudObject>("examine", "[Actor] -> Take a close look at the actor's surroundings.");

            GlobalRules.Perform<MudObject>("examine")
                .Do((actor) =>
                {
                    MudObject.SendMessage(actor, "A detailed account of all objects present.");
                    if (actor.Location != null && actor.Location is Container)
                        foreach (var item in (actor.Location as Container).EnumerateObjects().Where(i => !System.Object.ReferenceEquals(i, actor)))
                        {
                            MudObject.SendMessage(actor, "<a0>", item);
                        }
                    return PerformResult.Continue;
                });
        }
Example #17
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("cant look relloc", "You can't look <s0> that.");
            Core.StandardMessage("is closed error", "^<the0> is closed.");
            Core.StandardMessage("relloc it is", "^<s0> <the1> is..");
            Core.StandardMessage("nothing relloc it", "There is nothing <s0> <the1>.");

            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject, RelativeLocations>("can look relloc?", "[Actor, Item, Relative Location] : Can the actor look in/on/under/behind the item?", "actor", "item", "relloc");

            GlobalRules.Check <MudObject, MudObject, RelativeLocations>("can look relloc?")
            .Do((actor, item, relloc) => MudObject.CheckIsVisibleTo(actor, item))
            .Name("Container must be visible rule.");

            GlobalRules.Check <MudObject, MudObject, RelativeLocations>("can look relloc?")
            .When((actor, item, relloc) => !(item is Container) || (((item as Container).LocationsSupported & relloc) != relloc))
            .Do((actor, item, relloc) =>
            {
                MudObject.SendMessage(actor, "@cant look relloc", Relloc.GetRelativeLocationName(relloc));
                return(CheckResult.Disallow);
            })
            .Name("Container must support relloc rule.");

            GlobalRules.Check <MudObject, MudObject, RelativeLocations>("can look relloc?")
            .When((actor, item, relloc) => (relloc == RelativeLocations.In) && !item.GetBooleanProperty("open?"))
            .Do((actor, item, relloc) =>
            {
                MudObject.SendMessage(actor, "@is closed error", item);
                return(CheckResult.Disallow);
            })
            .Name("Container must be open to look in rule.");

            GlobalRules.Check <MudObject, MudObject, RelativeLocations>("can look relloc?")
            .Do((actor, item, relloc) => CheckResult.Allow)
            .Name("Default allow looking relloc rule.");

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject, RelativeLocations>("look relloc", "[Actor, Item, Relative Location] : Handle the actor looking on/under/in/behind the item.", "actor", "item", "relloc");

            GlobalRules.Perform <MudObject, MudObject, RelativeLocations>("look relloc")
            .Do((actor, item, relloc) =>
            {
                var contents = new List <MudObject>((item as Container).EnumerateObjects(relloc));

                if (contents.Count > 0)
                {
                    MudObject.SendMessage(actor, "@relloc it is", Relloc.GetRelativeLocationName(relloc), item);
                    foreach (var thing in contents)
                    {
                        MudObject.SendMessage(actor, "  <a0>", thing);
                    }
                }
                else
                {
                    MudObject.SendMessage(actor, "@nothing relloc it", Relloc.GetRelativeLocationName(relloc), item);
                }

                return(PerformResult.Continue);
            })
            .Name("List contents in relative location rule.");
        }
Example #18
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclarePerformRuleBook("heartbeat", "[] : Considered every tick.");

            GlobalRules.Perform("heartbeat").Do(() =>
                {
                    MudObject.TimeOfDay += Core.SettingsObject.ClockAdvanceRate;
                    return PerformResult.Continue;
                }).Name("Advance clock on heartbeat rule");
        }
Example #19
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("cant look relloc", "You can't look <s0> that.");
            Core.StandardMessage("is closed error", "^<the0> is closed.");
            Core.StandardMessage("relloc it is", "^<s0> <the1> is..");
            Core.StandardMessage("nothing relloc it", "There is nothing <s0> <the1>.");

            GlobalRules.DeclareCheckRuleBook<MudObject, MudObject, RelativeLocations>("can look relloc?", "[Actor, Item, Relative Location] : Can the actor look in/on/under/behind the item?", "actor", "item", "relloc");

            GlobalRules.Check<MudObject, MudObject, RelativeLocations>("can look relloc?")
                .Do((actor, item, relloc) => MudObject.CheckIsVisibleTo(actor, item))
                .Name("Container must be visible rule.");

            GlobalRules.Check<MudObject, MudObject, RelativeLocations>("can look relloc?")
                .When((actor, item, relloc) => !(item is Container) || (((item as Container).LocationsSupported & relloc) != relloc))
                .Do((actor, item, relloc) =>
                {
                    MudObject.SendMessage(actor, "@cant look relloc", Relloc.GetRelativeLocationName(relloc));
                    return CheckResult.Disallow;
                })
                .Name("Container must support relloc rule.");

            GlobalRules.Check<MudObject, MudObject, RelativeLocations>("can look relloc?")
                .When((actor, item, relloc) => (relloc == RelativeLocations.In) && !item.GetBooleanProperty("open?"))
                .Do((actor, item, relloc) =>
                {
                        MudObject.SendMessage(actor, "@is closed error", item);
                        return CheckResult.Disallow;
                })
                .Name("Container must be open to look in rule.");

            GlobalRules.Check<MudObject, MudObject, RelativeLocations>("can look relloc?")
                .Do((actor, item, relloc) => CheckResult.Allow)
                .Name("Default allow looking relloc rule.");

            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject, RelativeLocations>("look relloc", "[Actor, Item, Relative Location] : Handle the actor looking on/under/in/behind the item.", "actor", "item", "relloc");

            GlobalRules.Perform<MudObject, MudObject, RelativeLocations>("look relloc")
                .Do((actor, item, relloc) =>
                {
                    var contents = new List<MudObject>((item as Container).EnumerateObjects(relloc));

                    if (contents.Count > 0)
                    {
                        MudObject.SendMessage(actor, "@relloc it is", Relloc.GetRelativeLocationName(relloc), item);
                        foreach (var thing in contents)
                            MudObject.SendMessage(actor, "  <a0>", thing);
                    }
                    else
                        MudObject.SendMessage(actor, "@nothing relloc it", Relloc.GetRelativeLocationName(relloc), item);

                    return PerformResult.Continue;
                })
                .Name("List contents in relative location rule.");
        }
Example #20
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject, RelativeLocations>("can look relloc?", "[Actor, Item, Relative Location] : Can the actor look in/on/under/behind the item?", "actor", "item", "relloc");

            GlobalRules.Check <MudObject, MudObject, RelativeLocations>("can look relloc?")
            .Do((actor, item, relloc) => Core.CheckIsVisibleTo(actor, item))
            .Name("Container must be visible rule.");

            GlobalRules.Check <MudObject, MudObject, RelativeLocations>("can look relloc?")
            .When((actor, item, relloc) => (item.ContentLocationsAllowed & relloc) != relloc)
            .Do((actor, item, relloc) =>
            {
                Core.SendMessage(actor, "@cant look relloc", Relloc.GetRelativeLocationName(relloc));
                return(CheckResult.Disallow);
            })
            .Name("Container must support relloc rule.");

            GlobalRules.Check <MudObject, MudObject, RelativeLocations>("can look relloc?")
            .When((actor, item, relloc) => (relloc == RelativeLocations.IN) && !item.GetProperty <bool>("open?"))
            .Do((actor, item, relloc) =>
            {
                Core.SendMessage(actor, "@is closed error", item);
                return(CheckResult.Disallow);
            })
            .Name("Container must be open to look in rule.");

            GlobalRules.Check <MudObject, MudObject, RelativeLocations>("can look relloc?")
            .Do((actor, item, relloc) => CheckResult.Allow)
            .Name("Default allow looking relloc rule.");

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject, RelativeLocations>("look relloc", "[Actor, Item, Relative Location] : Handle the actor looking on/under/in/behind the item.", "actor", "item", "relloc");

            GlobalRules.Perform <MudObject, MudObject, RelativeLocations>("look relloc")
            .Do((actor, item, relloc) =>
            {
                var contents = new List <MudObject>(item.EnumerateObjects(relloc));

                if (contents.Count > 0)
                {
                    Core.SendMessage(actor, "@relloc it is", Relloc.GetRelativeLocationName(relloc), item);
                    foreach (var thing in contents)
                    {
                        Core.SendMessage(actor, "  <a0>", thing);
                    }
                }
                else
                {
                    Core.SendMessage(actor, "@nothing relloc it", Relloc.GetRelativeLocationName(relloc), item);
                }

                return(PerformResult.Continue);
            })
            .Name("List contents in relative location rule.");
        }
Example #21
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook<MudObject, MudObject, MudObject>("can tape to?", "[Actor, Subject, Object] : Can the subject be taped to the object?");

            GlobalRules.Check<MudObject, MudObject, MudObject>("can tape to?")
                .Do((actor, subject, @object) => MudObject.CheckIsVisibleTo(actor, @object))
                .Name("Object must be visible to tape something to it rule.");

            GlobalRules.Check<MudObject, MudObject, MudObject>("can tape to?")
                .Do((actor, subject, @object) => MudObject.CheckIsHolding(actor, subject))
                .Name("Subject must be held to tape it to something rule.");

            GlobalRules.Check<MudObject, MudObject, MudObject>("can tape to?")
                .When((actor, subject, @object) => !MudObject.ObjectContainsObject(actor, MudObject.GetObject("DuctTape")))
                .Do((actor, subject, @object) =>
                {
                    MudObject.SendMessage(actor, "You don't have any tape.");
                    return CheckResult.Disallow;
                })
                .Name("Need tape to tape rule.");

            GlobalRules.Check<MudObject, MudObject, MudObject>("can tape to?")
                .When((actor, subject, @object) => subject.GetPropertyOrDefault<Weight>("weight", Weight.Normal) != Weight.Light)
                .Do((actor, subject, @object) =>
                {
                    MudObject.SendMessage(actor, "^<the0> is too heavy to tape to things.", subject);
                    return CheckResult.Disallow;
                })
                .Name("Can only tape light things rule.");

            GlobalRules.Check<MudObject, MudObject, MudObject>("can tape to?")
               .When((actor, subject, @object) => !(@object is Container) || ((@object as Container).Supported & RelativeLocations.On) != RelativeLocations.On)
               .Do((actor, subject, @object) =>
               {
                   MudObject.SendMessage(actor, "I can't tape things to <the0>.", @object);
                   return CheckResult.Disallow;
               })
               .Name("Can only tape things to containers that support 'on' rule");

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

            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject, MudObject>("taped to", "[Actor, Subject, Object] : Handle the actor taping the subject to the object.");

            GlobalRules.Perform<MudObject, MudObject, MudObject>("taped to").Do((actor, subject, @object) =>
            {
                MudObject.SendMessage(actor, "Okay, I taped <the0> onto <the1>.", subject, @object);
                MudObject.Move(subject, @object, RelativeLocations.On);
                return PerformResult.Continue;
            });
        }
Example #22
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject, MudObject>("can tape to?", "[Actor, Subject, Object] : Can the subject be taped to the object?");

            GlobalRules.Check <MudObject, MudObject, MudObject>("can tape to?")
            .Do((actor, subject, @object) => MudObject.CheckIsVisibleTo(actor, @object))
            .Name("Object must be visible to tape something to it rule.");

            GlobalRules.Check <MudObject, MudObject, MudObject>("can tape to?")
            .Do((actor, subject, @object) => MudObject.CheckIsHolding(actor, subject))
            .Name("Subject must be held to tape it to something rule.");

            GlobalRules.Check <MudObject, MudObject, MudObject>("can tape to?")
            .When((actor, subject, @object) => !MudObject.ObjectContainsObject(actor, MudObject.GetObject("DuctTape")))
            .Do((actor, subject, @object) =>
            {
                MudObject.SendMessage(actor, "You don't have any tape.");
                return(CheckResult.Disallow);
            })
            .Name("Need tape to tape rule.");

            GlobalRules.Check <MudObject, MudObject, MudObject>("can tape to?")
            .When((actor, subject, @object) => subject.GetPropertyOrDefault <Weight>("weight", Weight.Normal) != Weight.Light)
            .Do((actor, subject, @object) =>
            {
                MudObject.SendMessage(actor, "^<the0> is too heavy to tape to things.", subject);
                return(CheckResult.Disallow);
            })
            .Name("Can only tape light things rule.");

            GlobalRules.Check <MudObject, MudObject, MudObject>("can tape to?")
            .When((actor, subject, @object) => !(@object is Container) || ((@object as Container).Supported & RelativeLocations.On) != RelativeLocations.On)
            .Do((actor, subject, @object) =>
            {
                MudObject.SendMessage(actor, "I can't tape things to <the0>.", @object);
                return(CheckResult.Disallow);
            })
            .Name("Can only tape things to containers that support 'on' rule");

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

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject, MudObject>("taped to", "[Actor, Subject, Object] : Handle the actor taping the subject to the object.");

            GlobalRules.Perform <MudObject, MudObject, MudObject>("taped to").Do((actor, subject, @object) =>
            {
                MudObject.SendMessage(actor, "Okay, I taped <the0> onto <the1>.", subject, @object);
                MudObject.Move(subject, @object, RelativeLocations.On);
                return(PerformResult.Continue);
            });
        }
Example #23
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("you unlock", "You unlock <the0>.");
            Core.StandardMessage("they unlock", "^<the0> unlocks <the1> with <a2>.");

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

            GlobalRules.Perform<MudObject, MudObject, MudObject>("unlocked").Do((actor, target, key) =>
            {
                MudObject.SendMessage(actor, "@you unlock", target);
                MudObject.SendExternalMessage(actor, "@they unlock", actor, target, key);
                return PerformResult.Continue;
            });
        }
Example #24
0
File: Unlock.cs Project: SinaC/RMUD
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("you unlock", "You unlock <the0>.");
            Core.StandardMessage("they unlock", "^<the0> unlocks <the1> with <a2>.");

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

            GlobalRules.Perform <MudObject, MudObject, MudObject>("unlocked").Do((actor, target, key) =>
            {
                MudObject.SendMessage(actor, "@you unlock", target);
                MudObject.SendExternalMessage(actor, "@they unlock", actor, target, key);
                return(PerformResult.Continue);
            });
        }
Example #25
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("jump", "^<the0> jumps around.");

            GlobalRules.DeclarePerformRuleBook <MudObject, String>("jump", "[Actor] : Handle the actor jumping.");

            GlobalRules.Perform <MudObject>("jump")
            .Do((actor) =>
            {
                Core.SendExternalMessage(actor, "@jump", actor);
                Core.SendMessage(actor, "You jump about.");
                return(PerformResult.Continue);
            })
            .Name("Default jump rule.");
        }
Example #26
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("you drop", "You drop <the0>.");
            Core.StandardMessage("they drop", "^<the0> drops <a1>.");

            GlobalRules.DeclareCheckRuleBook<MudObject, MudObject>("can drop?", "[Actor, Item] : Determine if the item can be dropped.", "actor", "item");
            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("drop", "[Actor, Item] : Handle an item being dropped.", "actor", "item");

            GlobalRules.Check<MudObject, MudObject>("can drop?")
                .First
                .When((actor, item) => !MudObject.ObjectContainsObject(actor, item))
                .Do((actor, item) =>
                {
                    MudObject.SendMessage(actor, "@dont have that");
                    return CheckResult.Disallow;
                })
                .Name("Must be holding it to drop it rule.");

            GlobalRules.Check<MudObject, MudObject>("can drop?")
                .First
                .When((actor, item) => actor is Actor && (actor as Actor).Contains(item, RelativeLocations.Worn))
                .Do((actor, item) =>
                {
                    if (GlobalRules.ConsiderCheckRule("can remove?", actor, item) == CheckResult.Allow)
                    {
                        GlobalRules.ConsiderPerformRule("remove", actor, item);
                        return CheckResult.Continue;
                    }
                    return CheckResult.Disallow;
                })
                .Name("Dropping worn items follows remove rules rule.");

            GlobalRules.Check<MudObject, MudObject>("can drop?").Do((a, b) => CheckResult.Allow).Name("Default can drop anything rule.");

            GlobalRules.Perform<MudObject, MudObject>("drop").Do((actor, target) =>
            {
                MudObject.SendMessage(actor, "@you drop", target);
                MudObject.SendExternalMessage(actor, "@they drop", actor, target);
                MudObject.Move(target, actor.Location);
                return PerformResult.Continue;
            }).Name("Default drop handler rule.");
        }
Example #27
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 #28
0
File: Drop.cs Project: SinaC/RMUD
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("you drop", "You drop <the0>.");
            Core.StandardMessage("they drop", "^<the0> drops <a1>.");

            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject>("can drop?", "[Actor, Item] : Determine if the item can be dropped.", "actor", "item");
            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("drop", "[Actor, Item] : Handle an item being dropped.", "actor", "item");

            GlobalRules.Check <MudObject, MudObject>("can drop?")
            .First
            .When((actor, item) => !MudObject.ObjectContainsObject(actor, item))
            .Do((actor, item) =>
            {
                MudObject.SendMessage(actor, "@dont have that");
                return(CheckResult.Disallow);
            })
            .Name("Must be holding it to drop it rule.");

            GlobalRules.Check <MudObject, MudObject>("can drop?")
            .First
            .When((actor, item) => actor is Actor && (actor as Actor).Contains(item, RelativeLocations.Worn))
            .Do((actor, item) =>
            {
                if (GlobalRules.ConsiderCheckRule("can remove?", actor, item) == CheckResult.Allow)
                {
                    GlobalRules.ConsiderPerformRule("remove", actor, item);
                    return(CheckResult.Continue);
                }
                return(CheckResult.Disallow);
            })
            .Name("Dropping worn items follows remove rules rule.");

            GlobalRules.Check <MudObject, MudObject>("can drop?").Do((a, b) => CheckResult.Allow).Name("Default can drop anything rule.");

            GlobalRules.Perform <MudObject, MudObject>("drop").Do((actor, target) =>
            {
                MudObject.SendMessage(actor, "@you drop", target);
                MudObject.SendExternalMessage(actor, "@they drop", actor, target);
                MudObject.Move(target, actor.Location);
                return(PerformResult.Continue);
            }).Name("Default drop handler rule.");
        }
Example #29
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 #30
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook<MudObject, MudObject>("can wear?", "[Actor, Item] : Can the actor wear the item?", "actor", "item");
            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("worn", "[Actor, Item] : Handle the actor wearing the item.", "actor", "item");

            GlobalRules.Check<MudObject, MudObject>("can wear?")
                .When((a, b) => !MudObject.ObjectContainsObject(a, b))
                .Do((actor, item) =>
                {
                    MudObject.SendMessage(actor, "@dont have that");
                    return CheckResult.Disallow;
                });

            GlobalRules.Check<MudObject, MudObject>("can wear?")
                .When((a, b) => a is Actor && (a as Actor).RelativeLocationOf(b) == RelativeLocations.Worn)
                .Do((a, b) =>
                {
                    MudObject.SendMessage(a, "@clothing already wearing");
                    return CheckResult.Disallow;
                });

            GlobalRules.Check<MudObject, MudObject>("can wear?")
                .When((actor, item) => !item.GetPropertyOrDefault<bool>("wearable?", false))
                .Do((actor, item) =>
                {
                    MudObject.SendMessage(actor, "@clothing cant wear");
                    return CheckResult.Disallow;
                })
                .Name("Can't wear unwearable things rule.");

            GlobalRules.Check<MudObject, MudObject>("can wear?").Do((a, b) => CheckResult.Allow);

            GlobalRules.Perform<MudObject, MudObject>("worn").Do((actor, target) =>
                {
                    MudObject.SendMessage(actor, "@clothing you wear", target);
                    MudObject.SendExternalMessage(actor, "@clothing they wear", actor, target);
                    MudObject.Move(target, actor, RelativeLocations.Worn);
                    return PerformResult.Continue;
                });
        }
Example #31
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject>("can wear?", "[Actor, Item] : Can the actor wear the item?", "actor", "item");
            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("worn", "[Actor, Item] : Handle the actor wearing the item.", "actor", "item");

            GlobalRules.Check <MudObject, MudObject>("can wear?")
            .When((a, b) => !MudObject.ObjectContainsObject(a, b))
            .Do((actor, item) =>
            {
                MudObject.SendMessage(actor, "@dont have that");
                return(CheckResult.Disallow);
            });

            GlobalRules.Check <MudObject, MudObject>("can wear?")
            .When((a, b) => a is Actor && (a as Actor).RelativeLocationOf(b) == RelativeLocations.Worn)
            .Do((a, b) =>
            {
                MudObject.SendMessage(a, "@clothing already wearing");
                return(CheckResult.Disallow);
            });

            GlobalRules.Check <MudObject, MudObject>("can wear?")
            .When((actor, item) => !item.GetPropertyOrDefault <bool>("wearable?", false))
            .Do((actor, item) =>
            {
                MudObject.SendMessage(actor, "@clothing cant wear");
                return(CheckResult.Disallow);
            })
            .Name("Can't wear unwearable things rule.");

            GlobalRules.Check <MudObject, MudObject>("can wear?").Do((a, b) => CheckResult.Allow);

            GlobalRules.Perform <MudObject, MudObject>("worn").Do((actor, target) =>
            {
                MudObject.SendMessage(actor, "@clothing you wear", target);
                MudObject.SendExternalMessage(actor, "@clothing they wear", actor, target);
                MudObject.Move(target, actor, RelativeLocations.Worn);
                return(PerformResult.Continue);
            });
        }
Example #32
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclarePerformRuleBook<MudObject>("update", "[Thing] : Considered for all things that have been marked for update.", "item");

            GlobalRules.Perform<Actor>("after every command")
                .First
                .Do((actor) =>
                    {
                        Core.UpdateMarkedObjects();
                        return PerformResult.Continue;
                    })
                .Name("Update marked objects at end of turn rule.");

            GlobalRules.Perform<Actor>("after every command")
                .Last
                .Do((actor) =>
                    {
                        Core.SendPendingMessages();
                        return PerformResult.Continue;
                    })
               .Name("Send pending messages at end of turn rule.");
        }
Example #33
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("empty handed", "You have nothing.");
            Core.StandardMessage("carrying", "You are carrying..");

            GlobalRules.DeclarePerformRuleBook<MudObject>("inventory", "[Actor] : Describes a player's inventory to themselves.", "actor");

            GlobalRules.Perform<Actor>("inventory")
                .Do(a =>
                {
                    var heldObjects = (a as Actor).GetContents(RelativeLocations.Held);
                    if (heldObjects.Count == 0) MudObject.SendMessage(a, "@empty handed");
                    else
                    {
                        MudObject.SendMessage(a, "@carrying");
                        foreach (var item in heldObjects)
                            MudObject.SendMessage(a, "  <a0>", item);
                    }
                    return PerformResult.Continue;
                })
                .Name("List held items in inventory rule.");
        }
Example #34
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook<MudObject, MudObject>("can remove?", "[Actor, Item] : Can the actor remove the item?", "actor", "item");
            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("removed", "[Actor, Item] : Handle the actor removing the item.", "actor", "item");

            GlobalRules.Check<MudObject, MudObject>("can remove?")
                .When((a, b) => !(a is Actor) || !(a as Actor).Contains(b, RelativeLocations.Worn))
                .Do((actor, item) =>
                {
                    MudObject.SendMessage(actor, "@clothing not wearing");
                    return CheckResult.Disallow;
                });

            GlobalRules.Check<MudObject, MudObject>("can remove?").Do((a, b) => CheckResult.Allow);

            GlobalRules.Perform<MudObject, MudObject>("removed").Do((actor, target) =>
                {
                    MudObject.SendMessage(actor, "@clothing you remove", target);
                    MudObject.SendExternalMessage(actor, "@clothing they remove", actor, target);
                    MudObject.Move(target, actor, RelativeLocations.Held);
                    return PerformResult.Continue;
                });
        }
Example #35
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject>("can remove?", "[Actor, Item] : Can the actor remove the item?", "actor", "item");
            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("removed", "[Actor, Item] : Handle the actor removing the item.", "actor", "item");

            GlobalRules.Check <MudObject, MudObject>("can remove?")
            .When((a, b) => !(a is Actor) || !(a as Actor).Contains(b, RelativeLocations.Worn))
            .Do((actor, item) =>
            {
                MudObject.SendMessage(actor, "@clothing not wearing");
                return(CheckResult.Disallow);
            });

            GlobalRules.Check <MudObject, MudObject>("can remove?").Do((a, b) => CheckResult.Allow);

            GlobalRules.Perform <MudObject, MudObject>("removed").Do((actor, target) =>
            {
                MudObject.SendMessage(actor, "@clothing you remove", target);
                MudObject.SendExternalMessage(actor, "@clothing they remove", actor, target);
                MudObject.Move(target, actor, RelativeLocations.Held);
                return(PerformResult.Continue);
            });
        }
Example #36
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject, MudObject>("can hit with?", "[Actor, Subject, Object] : Can the SUBJECT be hit by the ACTOR with the OBJECT?");

            GlobalRules.Check <MudObject, MudObject, MudObject>("can hit with?")
            .Do((actor, subject, @object) => MudObject.CheckIsVisibleTo(actor, subject))
            .Name("Item must be visible to hit it.");

            GlobalRules.Check <MudObject, MudObject, MudObject>("can hit with?")
            .Do((actor, subject, @object) => MudObject.CheckIsHolding(actor, @object))
            .Name("Object must be held rule.");

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

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject, MudObject>("hit with", "[Actor, Subject, Object] : Handle the actor hitting the subject with the object.");

            GlobalRules.Perform <MudObject, MudObject, MudObject>("hit with").Do((actor, subject, @object) =>
            {
                MudObject.SendMessage(actor, "I smacked <the0> with <the1>. I don't think it did anything.", subject, @object);
                return(PerformResult.Stop);
            });
        }
Example #37
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook<MudObject, MudObject, MudObject>("can hit with?", "[Actor, Subject, Object] : Can the SUBJECT be hit by the ACTOR with the OBJECT?");

            GlobalRules.Check<MudObject, MudObject, MudObject>("can hit with?")
                .Do((actor, subject, @object) => MudObject.CheckIsVisibleTo(actor, subject))
                .Name("Item must be visible to hit it.");

            GlobalRules.Check<MudObject, MudObject, MudObject>("can hit with?")
                .Do((actor, subject, @object) => MudObject.CheckIsHolding(actor, @object))
                .Name("Object must be held rule.");

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

            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject, MudObject>("hit with", "[Actor, Subject, Object] : Handle the actor hitting the subject with the object.");

            GlobalRules.Perform<MudObject, MudObject, MudObject>("hit with").Do((actor, subject, @object) =>
            {
                MudObject.SendMessage(actor, "I smacked <the0> with <the1>. I don't think it did anything.", subject, @object);
                return PerformResult.Stop;
            });
        }
Example #38
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 #39
0
File: Go.cs Project: SinaC/RMUD
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("unmatched cardinal", "What way was that?");
            Core.StandardMessage("go to null link", "You can't go that way.");
            Core.StandardMessage("go to closed door", "The door is closed.");
            Core.StandardMessage("you went", "You went <s0>.");
            Core.StandardMessage("they went", "^<the0> went <s1>.");
            Core.StandardMessage("bad link", "Error - Link does not lead to a room.");
            Core.StandardMessage("they arrive", "^<the0> arrives <s1>.");
            Core.StandardMessage("first opening", "[first opening <the0>]");

            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject>("can go?", "[Actor, Link] : Can the actor go through that link?", "actor", "link");

            GlobalRules.Check <MudObject, MudObject>("can go?")
            .When((actor, link) => link == null)
            .Do((actor, link) =>
            {
                MudObject.SendMessage(actor, "@go to null link");
                return(CheckResult.Disallow);
            })
            .Name("No link found rule.");

            GlobalRules.Check <Actor, MudObject>("can go?")
            .When((actor, link) => link != null && link.GetBooleanProperty("openable?") && !link.GetBooleanProperty("open?"))
            .Do((actor, link) =>
            {
                MudObject.SendMessage(actor, "@first opening", link);
                var tryOpen = Core.Try("StandardActions:Open", Core.ExecutingCommand.With("SUBJECT", link), actor);
                if (tryOpen == PerformResult.Stop)
                {
                    return(CheckResult.Disallow);
                }
                return(CheckResult.Continue);
            })
            .Name("Try opening a closed door first rule.");

            GlobalRules.Check <MudObject, MudObject>("can go?")
            .Do((actor, link) => CheckResult.Allow)
            .Name("Default can go rule.");

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("go", "[Actor, Link] : Handle the actor going through the link.", "actor", "link");

            GlobalRules.Perform <MudObject, MudObject>("go")
            .Do((actor, link) =>
            {
                var direction = link.GetPropertyOrDefault <Direction>("link direction", Direction.NOWHERE);
                MudObject.SendMessage(actor, "@you went", direction.ToString().ToLower());
                MudObject.SendExternalMessage(actor, "@they went", actor, direction.ToString().ToLower());
                return(PerformResult.Continue);
            })
            .Name("Report leaving rule.");

            GlobalRules.Perform <MudObject, MudObject>("go")
            .Do((actor, link) =>
            {
                var destination = MudObject.GetObject(link.GetProperty <String>("link destination")) as Room;
                if (destination == null)
                {
                    MudObject.SendMessage(actor, "@bad link");
                    return(PerformResult.Stop);
                }
                MudObject.Move(actor, destination);
                return(PerformResult.Continue);
            })
            .Name("Move through the link rule.");

            GlobalRules.Perform <MudObject, MudObject>("go")
            .Do((actor, link) =>
            {
                var direction     = link.GetPropertyOrDefault <Direction>("link direction", Direction.NOWHERE);
                var arriveMessage = Link.FromMessage(Link.Opposite(direction));
                MudObject.SendExternalMessage(actor, "@they arrive", actor, arriveMessage);
                return(PerformResult.Continue);
            })
            .Name("Report arrival rule.");

            GlobalRules.Perform <MudObject, MudObject>("go")
            .When((actor, link) => actor is Player && (actor as Player).ConnectedClient != null)
            .Do((actor, link) =>
            {
                Core.EnqueuActorCommand(actor as Actor, "look", HelperExtensions.MakeDictionary("AUTO", true));
                return(PerformResult.Continue);
            })
            .Name("Players look after going rule.");
        }
Example #40
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("is open", "^<the0> is open.");
            Core.StandardMessage("is closed", "^<the0> is closed.");
            Core.StandardMessage("describe on", "On <the0> is <l1>.");
            Core.StandardMessage("describe in", "In <the0> is <l1>.");
            Core.StandardMessage("empty handed", "^<the0> is empty handed.");
            Core.StandardMessage("holding", "^<the0> is holding <l1>.");

            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("describe", "[Actor, Item] : Generates descriptions of the item.", "actor", "item");

            GlobalRules.Perform<MudObject, MudObject>("describe")
                .When((viewer, item) => !String.IsNullOrEmpty(item.Long))
                .Do((viewer, item) =>
                {
                    MudObject.SendMessage(viewer, item.Long);
                    return PerformResult.Continue;
                })
                .Name("Basic description rule.");

            GlobalRules.Perform<MudObject, MudObject>("describe")
                .When((viewer, item) => GlobalRules.ConsiderValueRule<bool>("openable", item))
                .Do((viewer, item) =>
                {
                    if (item.GetBooleanProperty("open?"))
                        MudObject.SendMessage(viewer, "@is open", item);
                    else
                        MudObject.SendMessage(viewer, "@is closed", item);
                    return PerformResult.Continue;
                })
                .Name("Describe open or closed state rule.");

            GlobalRules.Perform<MudObject, MudObject>("describe")
                .When((viewer, item) => (item is Container) && ((item as Container).LocationsSupported & RelativeLocations.On) == RelativeLocations.On)
                .Do((viewer, item) =>
                {
                    var contents = (item as Container).GetContents(RelativeLocations.On);
                    if (contents.Count() > 0)
                        MudObject.SendMessage(viewer, "@describe on", item, contents);
                    return PerformResult.Continue;
                })
                .Name("List things on container in description rule.");

            GlobalRules.Perform<MudObject, MudObject>("describe")
                .When((viewer, item) =>
                    {
                        if (!(item is Container)) return false;
                        if (!item.GetBooleanProperty("open?")) return false;
                        if ((item as Container).EnumerateObjects(RelativeLocations.In).Count() == 0) return false;
                        return true;
                    })
                .Do((viewer, item) =>
                {
                    var contents = (item as Container).GetContents(RelativeLocations.In);
                    if (contents.Count() > 0)
                        MudObject.SendMessage(viewer, "@describe in", item, contents);
                    return PerformResult.Continue;
                })
                .Name("List things in open container in description rule.");

            GlobalRules.Perform<MudObject, Actor>("describe")
                .First
                .Do((viewer, actor) =>
                {
                    var heldItems = new List<MudObject>(actor.EnumerateObjects(RelativeLocations.Held));
                    if (heldItems.Count == 0)
                        MudObject.SendMessage(viewer, "@empty handed", actor);
                    else
                        MudObject.SendMessage(viewer, "@holding", actor, heldItems);

                    return PerformResult.Continue;
                })
                .Name("List held items when describing an actor rule.");
        }
Example #41
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 #42
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclarePerformRuleBook<PossibleMatch, Actor>("before acting", "[Match, Actor] : Considered before performing in world actions.");

            GlobalRules.DeclarePerformRuleBook<PossibleMatch, Actor>("after acting", "[Match, Actor] : Considered after performing in world actions.");
        }
Example #43
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 #44
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("is open", "^<the0> is open.");
            Core.StandardMessage("is closed", "^<the0> is closed.");
            Core.StandardMessage("describe on", "On <the0> is <l1>.");
            Core.StandardMessage("describe in", "In <the0> is <l1>.");
            Core.StandardMessage("empty handed", "^<the0> is empty handed.");
            Core.StandardMessage("holding", "^<the0> is holding <l1>.");

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("describe", "[Actor, Item] : Generates descriptions of the item.", "actor", "item");

            GlobalRules.Perform <MudObject, MudObject>("describe")
            .When((viewer, item) => !String.IsNullOrEmpty(item.Long))
            .Do((viewer, item) =>
            {
                MudObject.SendMessage(viewer, item.Long);
                return(PerformResult.Continue);
            })
            .Name("Basic description rule.");

            GlobalRules.Perform <MudObject, MudObject>("describe")
            .When((viewer, item) => GlobalRules.ConsiderValueRule <bool>("openable", item))
            .Do((viewer, item) =>
            {
                if (item.GetBooleanProperty("open?"))
                {
                    MudObject.SendMessage(viewer, "@is open", item);
                }
                else
                {
                    MudObject.SendMessage(viewer, "@is closed", item);
                }
                return(PerformResult.Continue);
            })
            .Name("Describe open or closed state rule.");

            GlobalRules.Perform <MudObject, MudObject>("describe")
            .When((viewer, item) => (item is Container) && ((item as Container).LocationsSupported & RelativeLocations.On) == RelativeLocations.On)
            .Do((viewer, item) =>
            {
                var contents = (item as Container).GetContents(RelativeLocations.On);
                if (contents.Count() > 0)
                {
                    MudObject.SendMessage(viewer, "@describe on", item, contents);
                }
                return(PerformResult.Continue);
            })
            .Name("List things on container in description rule.");

            GlobalRules.Perform <MudObject, MudObject>("describe")
            .When((viewer, item) =>
            {
                if (!(item is Container))
                {
                    return(false);
                }
                if (!item.GetBooleanProperty("open?"))
                {
                    return(false);
                }
                if ((item as Container).EnumerateObjects(RelativeLocations.In).Count() == 0)
                {
                    return(false);
                }
                return(true);
            })
            .Do((viewer, item) =>
            {
                var contents = (item as Container).GetContents(RelativeLocations.In);
                if (contents.Count() > 0)
                {
                    MudObject.SendMessage(viewer, "@describe in", item, contents);
                }
                return(PerformResult.Continue);
            })
            .Name("List things in open container in description rule.");


            GlobalRules.Perform <MudObject, Actor>("describe")
            .First
            .Do((viewer, actor) =>
            {
                var heldItems = new List <MudObject>(actor.EnumerateObjects(RelativeLocations.Held));
                if (heldItems.Count == 0)
                {
                    MudObject.SendMessage(viewer, "@empty handed", actor);
                }
                else
                {
                    MudObject.SendMessage(viewer, "@holding", actor, heldItems);
                }

                return(PerformResult.Continue);
            })
            .Name("List held items when describing an actor rule.");
        }
Example #45
0
File: Rules.cs Project: SinaC/RMUD
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("convo topic prompt", "Suggested topics: <l0>");
            Core.StandardMessage("convo cant converse", "You can't converse with that.");
            Core.StandardMessage("convo greet whom", "Whom did you want to greet?");
            Core.StandardMessage("convo nobody", "You aren't talking to anybody.");
            Core.StandardMessage("convo no response", "There doesn't seem to be a response defined for that topic.");
            Core.StandardMessage("convo no topics", "There is nothing obvious to discuss.");

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

            GlobalRules.Check <MudObject, MudObject>("can converse?")
            .When((actor, item) => !(item is NPC))
            .Do((actor, item) =>
            {
                MudObject.SendMessage(actor, "@convo cant converse");
                return(CheckResult.Disallow);
            })
            .Name("Can only converse with NPCs rule.");

            GlobalRules.Check <MudObject, MudObject>("can converse?")
            .Do((actor, item) => MudObject.CheckIsVisibleTo(actor, item))
            .Name("Locutor must be visible rule.");

            GlobalRules.Check <MudObject, MudObject>("can converse?")
            .Last
            .Do((actor, item) => CheckResult.Allow)
            .Name("Let them chat rule.");

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("greet", "[Actor, NPC] : Handle an actor greeting an NPC.", "actor", "npc");

            GlobalRules.DeclarePerformRuleBook <MudObject>("list topics", "[Actor] : List conversation topics available to the actor.", "actor");

            GlobalRules.Perform <MudObject>("list topics")
            .When(actor => !(actor is Player) || actor.GetProperty <NPC>("interlocutor") == null)
            .Do(actor =>
            {
                MudObject.SendMessage(actor, "@convo nobody");
                return(PerformResult.Stop);
            })
            .Name("Need interlocutor to list topics rule.");

            GlobalRules.Perform <MudObject>("list topics")
            .Do(actor =>
            {
                if (!(actor is Player))
                {
                    return(PerformResult.Stop);
                }
                var npc             = actor.GetProperty <NPC>("interlocutor");
                var suggestedTopics = npc.GetPropertyOrDefault <List <MudObject> >("conversation-topics", new List <MudObject>()).AsEnumerable();

                if (!Settings.ListDiscussedTopics)
                {
                    suggestedTopics = suggestedTopics.Where(obj => !obj.GetBooleanProperty("topic-discussed"));
                }

                suggestedTopics = suggestedTopics.Where(topic => GlobalRules.ConsiderCheckRule("topic available?", actor, npc, topic) == CheckResult.Allow);

                var enumeratedSuggestedTopics = new List <MudObject>(suggestedTopics);

                if (enumeratedSuggestedTopics.Count != 0)
                {
                    MudObject.SendMessage(actor, "@convo topic prompt", enumeratedSuggestedTopics);
                }
                else
                {
                    MudObject.SendMessage(actor, "@convo no topics");
                }

                return(PerformResult.Continue);
            })
            .Name("List un-discussed available topics rule.");

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject, MudObject>("discuss topic", "[Actor, NPC, Topic] : Handle the actor discussing the topic with the npc.");

            GlobalRules.Perform <MudObject, MudObject, MudObject>("discuss topic")
            .Do((actor, npc, topic) =>
            {
                GlobalRules.ConsiderPerformRule("topic response", actor, npc, topic);
                if (topic != null)
                {
                    topic.SetProperty("topic-discussed", true);
                }
                return(PerformResult.Continue);
            })
            .Name("Show topic response when discussing topic rule.");

            GlobalRules.Perform <MudObject, MudObject, MudObject>("topic response")
            .Do((actor, npc, topic) =>
            {
                MudObject.SendMessage(actor, "@convo no response");
                return(PerformResult.Stop);
            })
            .Name("No response rule for the topic rule.");

            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject, MudObject>("topic available?", "[Actor, NPC, Topic -> bool] : Is the topic available for discussion with the NPC to the actor?", "actor", "npc", "topic");

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject, MudObject>("topic response", "[Actor, NPC, Topic] : Display the response of the topic.", "actor", "npc", "topic");

            GlobalRules.Check <MudObject, MudObject, MudObject>("topic available?")
            .First
            .When((actor, npc, topic) => (topic != null) && (Settings.AllowRepeats == false) && topic.GetBooleanProperty("topic-discussed"))
            .Do((actor, npc, topic) => CheckResult.Disallow)
            .Name("Already discussed topics unavailable when repeats disabled rule.");

            GlobalRules.Check <MudObject, MudObject, MudObject>("topic available?")
            .Last
            .Do((actor, npc, topic) => CheckResult.Allow)
            .Name("Topics available by default rule.");
        }
Example #46
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclarePerformRuleBook <MudObject, String>("stats", "[Actor, Type] : Display engine stats.");

            GlobalRules.DeclarePerformRuleBook <MudObject>("enumerate-stats", "[Actor] : Display stats options.");
        }
Example #47
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("describe in locale", "[Actor, Item] : Generate a locale description for the item.", "actor", "item");

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("describe locale", "[Actor, Room] : Generates a description of the locale.", "actor", "room");

            GlobalRules.Perform <MudObject, MudObject>("describe locale")
            .First
            .When((viewer, room) => room == null)
            .Do((viewer, room) =>
            {
                Core.SendMessage(viewer, "@nowhere");
                return(PerformResult.Stop);
            })
            .Name("Can't describe the locale if there isn't one rule.");

            GlobalRules.Perform <MudObject, MudObject>("describe locale")
            .First
            .Do((viewer, room) =>
            {
                GlobalRules.ConsiderPerformRule("update", room);
                return(PerformResult.Continue);
            })
            .Name("Update room before generating description rule.");

            GlobalRules.Perform <MudObject, MudObject>("describe locale")
            .First
            .Do((viewer, locale) =>
            {
                if (!String.IsNullOrEmpty(locale.GetProperty <String>("short")))
                {
                    Core.SendMessage(viewer, locale.GetProperty <String>("short"));
                }
                return(PerformResult.Continue);
            })
            .Name("Display locale name rule.");

            GlobalRules.Perform <MudObject, MudObject>("describe locale")
            .First
            .When((viewer, room) => room.GetProperty <LightingLevel>("locale light") == LightingLevel.Dark)
            .Do((viewer, room) =>
            {
                Core.SendMessage(viewer, "@dark");
                return(PerformResult.Stop);
            })
            .Name("Can't see in darkness rule.");

            GlobalRules.Perform <MudObject, MudObject>("describe locale")
            .Do((viewer, locale) =>
            {
                GlobalRules.ConsiderPerformRule("describe", viewer, locale);
                return(PerformResult.Continue);
            })
            .Name("Include describe rules in locale description rule.");

            var describingLocale = false;

            GlobalRules.Value <MudObject, MudObject, String, String>("printed name")
            .When((viewer, container, article) => describingLocale && (container.ContentLocationsAllowed & RelativeLocations.ON) == RelativeLocations.ON)
            .Do((viewer, container, article) =>
            {
                var subObjects = new List <MudObject>(container.EnumerateObjects(RelativeLocations.ON)
                                                      .Where(t => GlobalRules.ConsiderCheckRule("should be listed?", viewer, t) == CheckResult.Allow));

                if (subObjects.Count > 0)
                {
                    return(container.GetProperty <String>("short") + " " + Core.FormatMessage(viewer, Core.GetMessage("on which"), subObjects));
                }
                else
                {
                    return(container.GetProperty <String>("short"));
                }
            })
            .Name("List contents of container after name when describing locale rule");

            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject>("should be listed in locale?", "[Viewer, Item] : When describing a room, or the contents of a container, should this item be listed?");

            GlobalRules.Check <MudObject, MudObject>("should be listed in locale?")
            .When((viewer, item) => System.Object.ReferenceEquals(viewer, item))
            .Do((viewer, item) => CheckResult.Disallow)
            .Name("Don't list yourself rule.");

            GlobalRules.Check <MudObject, MudObject>("should be listed in locale?")
            .When((viewer, item) => item.GetProperty <bool>("scenery?"))
            .Do((viewer, item) => CheckResult.Disallow)
            .Name("Don't list scenery objects rule.");

            GlobalRules.Check <MudObject, MudObject>("should be listed in locale?")
            .When((viewer, item) => item.GetProperty <bool>("portal?"))
            .Do((viewer, item) => CheckResult.Disallow)
            .Name("Don't list portals rule.");

            GlobalRules.Check <MudObject, MudObject>("should be listed in locale?")
            .Do((viewer, item) => CheckResult.Allow)
            .Name("List objects by default rule.");

            GlobalRules.Perform <MudObject, MudObject>("describe locale")
            .Do((viewer, room) =>
            {
                var visibleThings = room.EnumerateObjects(RelativeLocations.CONTENTS)
                                    .Where(t => GlobalRules.ConsiderCheckRule("should be listed in locale?", viewer, t) == CheckResult.Allow);

                var normalContents = new List <MudObject>();

                foreach (var thing in visibleThings)
                {
                    Core.BeginOutputQuery();
                    GlobalRules.ConsiderPerformRule("describe in locale", viewer, thing);
                    if (!Core.CheckOutputQuery())
                    {
                        normalContents.Add(thing);
                    }
                }

                if (normalContents.Count > 0)
                {
                    describingLocale = true;
                    Core.SendMessage(viewer, "@also here", normalContents);
                    describingLocale = false;
                }

                return(PerformResult.Continue);
            })
            .Name("List contents of room rule.");

            GlobalRules.Perform <MudObject, MudObject>("describe locale")
            .Last
            .Do((viewer, room) =>
            {
                if (room.EnumerateObjects().Where(l => l.GetProperty <bool>("portal?")).Count() > 0)
                {
                    Core.SendMessage(viewer, "@obvious exits");

                    foreach (var link in room.EnumerateObjects <MudObject>().Where(l => l.GetProperty <bool>("portal?")))
                    {
                        var builder = new StringBuilder();
                        builder.Append("  ^");
                        builder.Append(link.GetProperty <Direction>("link direction").ToString());

                        if (!link.GetProperty <bool>("link anonymous?"))
                        {
                            builder.Append(" " + Core.FormatMessage(viewer, Core.GetMessage("through"), link));
                        }

                        var destinationRoom = Core.GetObject(link.GetProperty <String>("link destination"));
                        if (destinationRoom != null)
                        {
                            builder.Append(" " + Core.FormatMessage(viewer, Core.GetMessage("to"), destinationRoom));
                        }

                        Core.SendMessage(viewer, builder.ToString());
                    }
                }

                return(PerformResult.Continue);
            })
            .Name("List exits in locale description rule.");
        }
Example #48
0
        // Any function with this signature will be called when the module is loaded. This is our chance to
        // do anything we want, but usually all we'll do is define some rules. We used some rulebooks above,
        // now we have to actually define them.
        public static void AtStartup(RuleEngine GlobalRules)
        {
            // Lets start by defining some messages we'll use later. This commentary isn't about the message
            // formatting system, but lets still do this 'right'.
            Core.StandardMessage("can't push direction", "That isn't going to work.");
            Core.StandardMessage("you push", "You push <the0> <s1>.");
            Core.StandardMessage("they push", "^<the0> pushed <the1> <s2>.");
            Core.StandardMessage("they arrive pushing", "^<the0> arrives <s2> pushing <the1>.");

            // We'll declare the 'can push direction?' rulebook first. Notice that we were passed the global rules,
            // and that is what we want to declare it on. DeclareCheckRuleBook takes the types the rulebook
            // expects as generic arguments, then the name of the rulebook. The documentation is helpful but
            // not required. This rulebook takes three mud objects. Their usage is documented in the rulebook
            // description.
            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject, MudObject>("can push direction?", "[Actor, Subject, Link] : Can the actor push the subject through that link?", "actor", "subject", "link");

            // Now we want to define a global rule in the 'can push direction?' rulebook. Rulebooks do not have
            // to be declared before rules are defined, but it's good style. The Check function returns a
            // rulebuilder, which provides a fluent interface for declaring rules.
            GlobalRules.Check <MudObject, MudObject, MudObject>("can push direction?")
            // Do expects a lambda, and lets us specify what the rule should actually do.
            .Do((actor, subject, link) =>
            {
                MudObject.SendMessage(actor, "@can't push direction"); // We defined this message above.
                return(CheckResult.Disallow);                          // Disallow the action.
            }).Name("Can't push between rooms by default rule.");
            // So by default, nothing can be pushed between rooms. What a useful command!

            // That's the only check rule we need. Now lets define the perform rules. We need to duplicate
            // large portions of the functionality of the go command. I'll comment in a little less detail
            // now - I think you've got the idea of how this works. These rules will be invoked by the command
            // in the order they are declared. We could smush them all into one rule, but that would be
            // poor style maybe.
            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject, MudObject>("push direction", "[Actor, Subject, Link] : Handle the actor pushing the subject through the link.", "actor", "subject", "link");

            // First we want to report the action to the player and any other players that happen to be around.
            GlobalRules.Perform <MudObject, MudObject, MudObject>("push direction")
            .Do((actor, subject, link) =>
            {
                var direction = link.GetPropertyOrDefault <Direction>("link direction", Direction.NOWHERE);
                MudObject.SendMessage(actor, "@you push", subject, direction.ToString().ToLower());

                // SendExternalMessage sends the message to everyone in the same place as the actor,
                // except the actor themself.
                MudObject.SendExternalMessage(actor, "@they push", actor, subject, direction.ToString().ToLower());
                return(PerformResult.Continue);
            })
            .Name("Report pushing between rooms rule.");

            // Now we want to actually move the player, and the object they are pushing.
            GlobalRules.Perform <MudObject, MudObject, MudObject>("push direction")
            .Do((actor, subject, link) =>
            {
                var destination = MudObject.GetObject(link.GetProperty <String>("link destination")) as Room;
                if (destination == null)
                {
                    MudObject.SendMessage(actor, "@bad link");
                    return(PerformResult.Stop);
                }

                MudObject.Move(actor, destination);
                MudObject.Move(subject, destination);
                return(PerformResult.Continue);
            })
            .Name("Push through the link rule.");

            // For most actions that's enough. But in this case, we want to let players in the room the
            // actor went to know they have arrived.
            GlobalRules.Perform <MudObject, MudObject, MudObject>("push direction")
            .Do((actor, subject, link) =>
            {
                var direction     = link.GetPropertyOrDefault <Direction>("link direction", Direction.NOWHERE);
                var arriveMessage = Link.FromMessage(Link.Opposite(direction));
                MudObject.SendExternalMessage(actor, "@they arrive pushing", actor, subject, arriveMessage);
                return(PerformResult.Continue);
            })
            .Name("Report arrival while pushing rule.");

            // And finally, lets make sure the player gets a description of the room they have arrived in.
            GlobalRules.Perform <MudObject, MudObject, MudObject>("push direction")
            .When((actor, subject, link) => actor is Player && (actor as Player).ConnectedClient != null)
            .Do((actor, subject, link) =>
            {
                // We set the 'auto' flag to let the look command know it's been generated, and not
                // typed by the player. This is handy for deciding wether to show a brief description
                // or the full description of a room.
                Core.EnqueuActorCommand(actor as Actor, "look", HelperExtensions.MakeDictionary("AUTO", true));
                return(PerformResult.Continue);
            })
            .Name("Players look after pushing between rooms rule.");
        }
Example #49
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("convo topic prompt", "Suggested topics: <l0>");
            Core.StandardMessage("convo cant converse", "You can't converse with that.");
            Core.StandardMessage("convo greet whom", "Whom did you want to greet?");
            Core.StandardMessage("convo nobody", "You aren't talking to anybody.");
            Core.StandardMessage("convo no response", "There doesn't seem to be a response defined for that topic.");
            Core.StandardMessage("convo no topics", "There is nothing obvious to discuss.");

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

            GlobalRules.Check<MudObject, MudObject>("can converse?")
                .When((actor, item) => !(item is NPC))
                .Do((actor, item) =>
                {
                    MudObject.SendMessage(actor, "@convo cant converse");
                    return CheckResult.Disallow;
                })
                .Name("Can only converse with NPCs rule.");

            GlobalRules.Check<MudObject, MudObject>("can converse?")
                .Do((actor, item) => MudObject.CheckIsVisibleTo(actor, item))
                .Name("Locutor must be visible rule.");

            GlobalRules.Check<MudObject, MudObject>("can converse?")
                .Last
                .Do((actor, item) => CheckResult.Allow)
                .Name("Let them chat rule.");

            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("greet", "[Actor, NPC] : Handle an actor greeting an NPC.", "actor", "npc");

            GlobalRules.DeclarePerformRuleBook<MudObject>("list topics", "[Actor] : List conversation topics available to the actor.", "actor");

            GlobalRules.Perform<MudObject>("list topics")
                .When(actor => !(actor is Player) || actor.GetProperty<NPC>("interlocutor") == null)
                .Do(actor =>
                {
                    MudObject.SendMessage(actor, "@convo nobody");
                    return PerformResult.Stop;
                })
                .Name("Need interlocutor to list topics rule.");

            GlobalRules.Perform<MudObject>("list topics")
                .Do(actor =>
                {
                    if (!(actor is Player)) return PerformResult.Stop;
                    var npc = actor.GetProperty<NPC>("interlocutor");
                    var suggestedTopics = npc.GetPropertyOrDefault<List<MudObject>>("conversation-topics", new List<MudObject>()).AsEnumerable();

                    if (!Settings.ListDiscussedTopics)
                        suggestedTopics = suggestedTopics.Where(obj => !obj.GetBooleanProperty("topic-discussed"));

                    suggestedTopics = suggestedTopics.Where(topic => GlobalRules.ConsiderCheckRule("topic available?", actor, npc, topic) == CheckResult.Allow);

                    var enumeratedSuggestedTopics = new List<MudObject>(suggestedTopics);

                    if (enumeratedSuggestedTopics.Count != 0)
                        MudObject.SendMessage(actor, "@convo topic prompt", enumeratedSuggestedTopics);
                    else
                        MudObject.SendMessage(actor, "@convo no topics");

                    return PerformResult.Continue;
                })
                .Name("List un-discussed available topics rule.");

            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject, MudObject>("discuss topic", "[Actor, NPC, Topic] : Handle the actor discussing the topic with the npc.");

            GlobalRules.Perform<MudObject, MudObject, MudObject>("discuss topic")
                .Do((actor, npc, topic) =>
                {
                    GlobalRules.ConsiderPerformRule("topic response", actor, npc, topic);
                    if (topic != null) topic.SetProperty("topic-discussed", true);
                    return PerformResult.Continue;
                })
                .Name("Show topic response when discussing topic rule.");

            GlobalRules.Perform<MudObject, MudObject, MudObject>("topic response")
                .Do((actor, npc, topic) =>
                {
                    MudObject.SendMessage(actor, "@convo no response");
                    return PerformResult.Stop;
                })
                .Name("No response rule for the topic rule.");

            GlobalRules.DeclareCheckRuleBook<MudObject, MudObject, MudObject>("topic available?", "[Actor, NPC, Topic -> bool] : Is the topic available for discussion with the NPC to the actor?", "actor", "npc", "topic");

            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject, MudObject>("topic response", "[Actor, NPC, Topic] : Display the response of the topic.", "actor", "npc", "topic");

            GlobalRules.Check<MudObject, MudObject, MudObject>("topic available?")
                .First
                .When((actor, npc, topic) => (topic != null) && (Settings.AllowRepeats == false) && topic.GetBooleanProperty("topic-discussed"))
                .Do((actor, npc, topic) => CheckResult.Disallow)
                .Name("Already discussed topics unavailable when repeats disabled rule.");

            GlobalRules.Check<MudObject, MudObject, MudObject>("topic available?")
                .Last
                .Do((actor, npc, topic) => CheckResult.Allow)
                .Name("Topics available by default rule.");
        }
Example #50
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("cant put relloc", "You can't put things <s0> that.");
            Core.StandardMessage("you put", "You put <the0> <s1> <the2>.");
            Core.StandardMessage("they put", "^<the0> puts <the1> <s2> <the3>.");

            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject, MudObject, RelativeLocations>("can put?", "[Actor, Item, Container, Location] : Determine if the actor can put the item in or on or under the container.", "actor", "item", "container", "relloc");
            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject, MudObject, RelativeLocations>("put", "[Actor, Item, Container, Location] : Handle an actor putting the item in or on or under the container.", "actor", "item", "container", "relloc");

            GlobalRules.Check <MudObject, MudObject, MudObject, RelativeLocations>("can put?")
            .Last
            .Do((a, b, c, d) => CheckResult.Allow)
            .Name("Allow putting as default rule.");

            GlobalRules.Check <MudObject, MudObject, MudObject, RelativeLocations>("can put?")
            .Do((actor, item, container, relloc) =>
            {
                if (!(container is Container))
                {
                    MudObject.SendMessage(actor, "@cant put relloc", Relloc.GetRelativeLocationName(relloc));
                    return(CheckResult.Disallow);
                }
                return(CheckResult.Continue);
            })
            .Name("Can't put things in things that aren't containers rule.");

            GlobalRules.Check <MudObject, MudObject, MudObject, RelativeLocations>("can put?")
            .Do((actor, item, container, relloc) =>
            {
                if (GlobalRules.ConsiderCheckRule("can drop?", actor, item) != CheckResult.Allow)
                {
                    return(CheckResult.Disallow);
                }
                return(CheckResult.Continue);
            })
            .Name("Putting is dropping rule.");

            GlobalRules.Perform <MudObject, MudObject, MudObject, RelativeLocations>("put")
            .Do((actor, item, container, relloc) =>
            {
                MudObject.SendMessage(actor, "@you put", item, Relloc.GetRelativeLocationName(relloc), container);
                MudObject.SendExternalMessage(actor, "@they put", actor, item, Relloc.GetRelativeLocationName(relloc), container);
                MudObject.Move(item, container, relloc);
                return(PerformResult.Continue);
            })
            .Name("Default putting things in things handler.");

            GlobalRules.Check <MudObject, MudObject, MudObject, RelativeLocations>("can put?")
            .Do((actor, item, container, relloc) =>
            {
                var c = container as Container;
                if (c == null || (c.LocationsSupported & relloc) != relloc)
                {
                    MudObject.SendMessage(actor, "@cant put relloc", Relloc.GetRelativeLocationName(relloc));
                    return(CheckResult.Disallow);
                }
                return(CheckResult.Continue);
            })
            .Name("Check supported locations before putting rule.");

            GlobalRules.Check <MudObject, MudObject, MudObject, RelativeLocations>("can put?")
            .Do((actor, item, container, relloc) =>
            {
                if (relloc == RelativeLocations.In && !container.GetBooleanProperty("open?"))
                {
                    MudObject.SendMessage(actor, "@is closed error", container);
                    return(CheckResult.Disallow);
                }

                return(CheckResult.Continue);
            })
            .Name("Can't put things in closed container rule.");

            GlobalRules.Check <MudObject, MudObject, MudObject, RelativeLocations>("can put?")
            .First
            .Do((actor, item, container, relloc) => MudObject.CheckIsVisibleTo(actor, container))
            .Name("Container must be visible rule.");

            GlobalRules.Check <MudObject, MudObject, MudObject, RelativeLocations>("can put?")
            .First
            .Do((actor, item, container, relloc) => MudObject.CheckIsHolding(actor, item))
            .Name("Must be holding item rule.");
        }
Example #51
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("cant put relloc", "You can't put things <s0> that.");
            Core.StandardMessage("you put", "You put <the0> <s1> <the2>.");
            Core.StandardMessage("they put", "^<the0> puts <the1> <s2> <the3>.");

            GlobalRules.DeclareCheckRuleBook<MudObject, MudObject, MudObject, RelativeLocations>("can put?", "[Actor, Item, Container, Location] : Determine if the actor can put the item in or on or under the container.", "actor", "item", "container", "relloc");
            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject, MudObject, RelativeLocations>("put", "[Actor, Item, Container, Location] : Handle an actor putting the item in or on or under the container.", "actor", "item", "container", "relloc");

            GlobalRules.Check<MudObject, MudObject, MudObject, RelativeLocations>("can put?")
                .Last
                .Do((a, b, c, d) => CheckResult.Allow)
                .Name("Allow putting as default rule.");

            GlobalRules.Check<MudObject, MudObject, MudObject, RelativeLocations>("can put?")
                .Do((actor, item, container, relloc) =>
                {
                    if (!(container is Container))
                    {
                        MudObject.SendMessage(actor, "@cant put relloc", Relloc.GetRelativeLocationName(relloc));
                        return CheckResult.Disallow;
                    }
                    return CheckResult.Continue;
                })
                .Name("Can't put things in things that aren't containers rule.");

            GlobalRules.Check<MudObject, MudObject, MudObject, RelativeLocations>("can put?")
                .Do((actor, item, container, relloc) =>
                {
                    if (GlobalRules.ConsiderCheckRule("can drop?", actor, item) != CheckResult.Allow)
                        return CheckResult.Disallow;
                    return CheckResult.Continue;
                })
                .Name("Putting is dropping rule.");

            GlobalRules.Perform<MudObject, MudObject, MudObject, RelativeLocations>("put")
                .Do((actor, item, container, relloc) =>
                {
                    MudObject.SendMessage(actor, "@you put", item, Relloc.GetRelativeLocationName(relloc), container);
                    MudObject.SendExternalMessage(actor, "@they put", actor, item, Relloc.GetRelativeLocationName(relloc), container);
                    MudObject.Move(item, container, relloc);
                    return PerformResult.Continue;
                })
                .Name("Default putting things in things handler.");

            GlobalRules.Check<MudObject, MudObject, MudObject, RelativeLocations>("can put?")
                .Do((actor, item, container, relloc) =>
                {
                    var c = container as Container;
                    if (c == null || (c.LocationsSupported & relloc) != relloc)
                    {
                        MudObject.SendMessage(actor, "@cant put relloc", Relloc.GetRelativeLocationName(relloc));
                        return CheckResult.Disallow;
                    }
                    return CheckResult.Continue;
                })
                .Name("Check supported locations before putting rule.");

            GlobalRules.Check<MudObject, MudObject, MudObject, RelativeLocations>("can put?")
                .Do((actor, item, container, relloc) =>
                {
                    if (relloc == RelativeLocations.In && !container.GetBooleanProperty("open?"))
                    {
                        MudObject.SendMessage(actor, "@is closed error", container);
                        return CheckResult.Disallow;
                    }

                    return CheckResult.Continue;
                })
                .Name("Can't put things in closed container rule.");

            GlobalRules.Check<MudObject, MudObject, MudObject, RelativeLocations>("can put?")
                .First
                .Do((actor, item, container, relloc) => MudObject.CheckIsVisibleTo(actor, container))
                .Name("Container must be visible rule.");

            GlobalRules.Check<MudObject, MudObject, MudObject, RelativeLocations>("can put?")
                .First
                .Do((actor, item, container, relloc) => MudObject.CheckIsHolding(actor, item))
                .Name("Must be holding item rule.");
        }
Example #52
0
        // Any function with this signature will be called when the module is loaded. This is our chance to
        // do anything we want, but usually all we'll do is define some rules. We used some rulebooks above,
        // now we have to actually define them.
        public static void AtStartup(RuleEngine GlobalRules)
        {
            // Lets start by defining some messages we'll use later. This commentary isn't about the message
            // formatting system, but lets still do this 'right'.
            Core.StandardMessage("can't push direction", "That isn't going to work.");
            Core.StandardMessage("you push", "You push <the0> <s1>.");
            Core.StandardMessage("they push", "^<the0> pushed <the1> <s2>.");
            Core.StandardMessage("they arrive pushing", "^<the0> arrives <s2> pushing <the1>.");

            // We'll declare the 'can push direction?' rulebook first. Notice that we were passed the global rules,
            // and that is what we want to declare it on. DeclareCheckRuleBook takes the types the rulebook
            // expects as generic arguments, then the name of the rulebook. The documentation is helpful but
            // not required. This rulebook takes three mud objects. Their usage is documented in the rulebook
            // description.
            GlobalRules.DeclareCheckRuleBook<MudObject, MudObject, MudObject>("can push direction?", "[Actor, Subject, Link] : Can the actor push the subject through that link?", "actor", "subject", "link");

            // Now we want to define a global rule in the 'can push direction?' rulebook. Rulebooks do not have
            // to be declared before rules are defined, but it's good style. The Check function returns a
            // rulebuilder, which provides a fluent interface for declaring rules.
            GlobalRules.Check<MudObject, MudObject, MudObject>("can push direction?")
                // Do expects a lambda, and lets us specify what the rule should actually do.
                .Do((actor, subject, link) =>
                {
                    MudObject.SendMessage(actor, "@can't push direction"); // We defined this message above.
                    return CheckResult.Disallow; // Disallow the action.
                }).Name("Can't push between rooms by default rule.");
            // So by default, nothing can be pushed between rooms. What a useful command!

            // That's the only check rule we need. Now lets define the perform rules. We need to duplicate
            // large portions of the functionality of the go command. I'll comment in a little less detail
            // now - I think you've got the idea of how this works. These rules will be invoked by the command
            // in the order they are declared. We could smush them all into one rule, but that would be
            // poor style maybe.
            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject, MudObject>("push direction", "[Actor, Subject, Link] : Handle the actor pushing the subject through the link.", "actor", "subject", "link");

            // First we want to report the action to the player and any other players that happen to be around.
            GlobalRules.Perform<MudObject, MudObject, MudObject>("push direction")
                .Do((actor, subject, link) =>
                {
                    var direction = link.GetPropertyOrDefault<Direction>("link direction", Direction.NOWHERE);
                    MudObject.SendMessage(actor, "@you push", subject, direction.ToString().ToLower());

                    // SendExternalMessage sends the message to everyone in the same place as the actor,
                    // except the actor themself.
                    MudObject.SendExternalMessage(actor, "@they push", actor, subject, direction.ToString().ToLower());
                    return PerformResult.Continue;
                })
                .Name("Report pushing between rooms rule.");

            // Now we want to actually move the player, and the object they are pushing.
            GlobalRules.Perform<MudObject, MudObject, MudObject>("push direction")
                .Do((actor, subject, link) =>
                {
                    var destination = MudObject.GetObject(link.GetProperty<String>("link destination")) as Room;
                    if (destination == null)
                    {
                        MudObject.SendMessage(actor, "@bad link");
                        return PerformResult.Stop;
                    }

                    MudObject.Move(actor, destination);
                    MudObject.Move(subject, destination);
                    return PerformResult.Continue;
                })
                .Name("Push through the link rule.");

            // For most actions that's enough. But in this case, we want to let players in the room the
            // actor went to know they have arrived.
            GlobalRules.Perform<MudObject, MudObject, MudObject>("push direction")
                .Do((actor, subject, link) =>
                {
                    var direction = link.GetPropertyOrDefault<Direction>("link direction", Direction.NOWHERE);
                    var arriveMessage = Link.FromMessage(Link.Opposite(direction));
                    MudObject.SendExternalMessage(actor, "@they arrive pushing", actor, subject, arriveMessage);
                    return PerformResult.Continue;
                })
                .Name("Report arrival while pushing rule.");

            // And finally, lets make sure the player gets a description of the room they have arrived in.
            GlobalRules.Perform<MudObject, MudObject, MudObject>("push direction")
                .When((actor, subject, link) => actor is Player && (actor as Player).ConnectedClient != null)
                .Do((actor, subject, link) =>
                {
                    // We set the 'auto' flag to let the look command know it's been generated, and not
                    // typed by the player. This is handy for deciding wether to show a brief description
                    // or the full description of a room.
                    Core.EnqueuActorCommand(actor as Actor, "look", HelperExtensions.MakeDictionary("AUTO", true));
                    return PerformResult.Continue;
                })
                .Name("Players look after pushing between rooms rule.");
        }
Example #53
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("unmatched cardinal", "What way was that?");
            Core.StandardMessage("go to null link", "You can't go that way.");
            Core.StandardMessage("go to closed door", "The door is closed.");
            Core.StandardMessage("you went", "You went <s0>.");
            Core.StandardMessage("they went", "^<the0> went <s1>.");
            Core.StandardMessage("bad link", "Error - Link does not lead to a room.");
            Core.StandardMessage("they arrive", "^<the0> arrives <s1>.");
            Core.StandardMessage("first opening", "[first opening <the0>]");

            GlobalRules.DeclareCheckRuleBook<MudObject, MudObject>("can go?", "[Actor, Link] : Can the actor go through that link?", "actor", "link");

            GlobalRules.Check<MudObject, MudObject>("can go?")
                .When((actor, link) => link == null)
                .Do((actor, link) =>
                {
                    MudObject.SendMessage(actor, "@go to null link");
                    return CheckResult.Disallow;
                })
                .Name("No link found rule.");

            GlobalRules.Check<Actor, MudObject>("can go?")
                .When((actor, link) => link != null && link.GetBooleanProperty("openable?") && !link.GetBooleanProperty("open?"))
                .Do((actor, link) =>
                {
                    MudObject.SendMessage(actor, "@first opening", link);
                    var tryOpen = Core.Try("StandardActions:Open", Core.ExecutingCommand.With("SUBJECT", link), actor);
                    if (tryOpen == PerformResult.Stop)
                        return CheckResult.Disallow;
                    return CheckResult.Continue;
                })
                .Name("Try opening a closed door first rule.");

            GlobalRules.Check<MudObject, MudObject>("can go?")
                .Do((actor, link) => CheckResult.Allow)
                .Name("Default can go rule.");

            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("go", "[Actor, Link] : Handle the actor going through the link.", "actor", "link");

            GlobalRules.Perform<MudObject, MudObject>("go")
                .Do((actor, link) =>
                {
                    var direction = link.GetPropertyOrDefault<Direction>("link direction", Direction.NOWHERE);
                    MudObject.SendMessage(actor, "@you went", direction.ToString().ToLower());
                    MudObject.SendExternalMessage(actor, "@they went", actor, direction.ToString().ToLower());
                    return PerformResult.Continue;
                })
                .Name("Report leaving rule.");

            GlobalRules.Perform<MudObject, MudObject>("go")
                .Do((actor, link) =>
                {
                    var destination = MudObject.GetObject(link.GetProperty<String>("link destination")) as Room;
                    if (destination == null)
                    {
                        MudObject.SendMessage(actor, "@bad link");
                        return PerformResult.Stop;
                    }
                    MudObject.Move(actor, destination);
                    return PerformResult.Continue;
                })
                .Name("Move through the link rule.");

            GlobalRules.Perform<MudObject, MudObject>("go")
                .Do((actor, link) =>
                {
                    var direction = link.GetPropertyOrDefault<Direction>("link direction", Direction.NOWHERE);
                    var arriveMessage = Link.FromMessage(Link.Opposite(direction));
                    MudObject.SendExternalMessage(actor, "@they arrive", actor, arriveMessage);
                    return PerformResult.Continue;
                })
                .Name("Report arrival rule.");

            GlobalRules.Perform<MudObject, MudObject>("go")
                .When((actor, link) => actor is Player && (actor as Player).ConnectedClient != null)
                .Do((actor, link) =>
                {
                    Core.EnqueuActorCommand(actor as Actor, "look", HelperExtensions.MakeDictionary("AUTO", true));
                    return PerformResult.Continue;
                })
                .Name("Players look after going rule.");
        }
Example #54
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclarePerformRuleBook<MudObject, String>("stats", "[Actor, Type] : Display engine stats.");

            GlobalRules.DeclarePerformRuleBook<MudObject>("enumerate-stats", "[Actor] : Display stats options.");
        }
Example #55
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 #56
0
File: Take.cs Project: SinaC/RMUD
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("you take", "You take <the0>.");
            Core.StandardMessage("they take", "^<the0> takes <the1>.");
            Core.StandardMessage("cant take people", "You can't take people.");
            Core.StandardMessage("cant take portals", "You can't take portals.");
            Core.StandardMessage("cant take scenery", "That's a terrible idea.");

            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject>("can take?", "[Actor, Item] : Can the actor take the item?", "actor", "item");
            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("take", "[Actor, Item] : Handle the actor taking the item.", "actor", "item");

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

            GlobalRules.Check <MudObject, MudObject>("can take?")
            .When((actor, item) => actor is Container && (actor as Container).Contains(item, RelativeLocations.Held))
            .Do((actor, item) =>
            {
                MudObject.SendMessage(actor, "@already have that");
                return(CheckResult.Disallow);
            })
            .Name("Can't take what you're already holding rule.");

            GlobalRules.Check <MudObject, MudObject>("can take?")
            .Last
            .Do((a, t) => CheckResult.Allow)
            .Name("Default allow taking rule.");

            GlobalRules.Perform <MudObject, MudObject>("take")
            .Do((actor, target) =>
            {
                MudObject.SendMessage(actor, "@you take", target);
                MudObject.SendExternalMessage(actor, "@they take", actor, target);
                MudObject.Move(target, actor);
                return(PerformResult.Continue);
            })
            .Name("Default handle taken rule.");

            GlobalRules.Check <MudObject, MudObject>("can take?")
            .First
            .When((actor, thing) => thing is Actor)
            .Do((actor, thing) =>
            {
                MudObject.SendMessage(actor, "@cant take people");
                return(CheckResult.Disallow);
            })
            .Name("Can't take people rule.");

            GlobalRules.Check <MudObject, MudObject>("can take?")
            .First
            .When((actor, thing) => thing.GetPropertyOrDefault <bool>("portal?", false))
            .Do((actor, thing) =>
            {
                MudObject.SendMessage(actor, "@cant take portal");
                return(CheckResult.Disallow);
            });

            GlobalRules.Check <MudObject, MudObject>("can take?")
            .First
            .When((actor, thing) => thing.GetBooleanProperty("scenery?"))
            .Do((actor, thing) =>
            {
                MudObject.SendMessage(actor, "@cant take scenery");
                return(CheckResult.Disallow);
            })
            .Name("Can't take scenery rule.");
        }
Example #57
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("you take", "You take <the0>.");
            Core.StandardMessage("they take", "^<the0> takes <the1>.");
            Core.StandardMessage("cant take people", "You can't take people.");
            Core.StandardMessage("cant take portals", "You can't take portals.");
            Core.StandardMessage("cant take scenery", "That's a terrible idea.");

            GlobalRules.DeclareCheckRuleBook<MudObject, MudObject>("can take?", "[Actor, Item] : Can the actor take the item?", "actor", "item");
            GlobalRules.DeclarePerformRuleBook<MudObject, MudObject>("take", "[Actor, Item] : Handle the actor taking the item.", "actor", "item");

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

            GlobalRules.Check<MudObject, MudObject>("can take?")
                .When((actor, item) => actor is Container && (actor as Container).Contains(item, RelativeLocations.Held))
                .Do((actor, item) =>
                {
                    MudObject.SendMessage(actor, "@already have that");
                    return CheckResult.Disallow;
                })
                .Name("Can't take what you're already holding rule.");

            GlobalRules.Check<MudObject, MudObject>("can take?")
                .Last
                .Do((a, t) => CheckResult.Allow)
                .Name("Default allow taking rule.");

            GlobalRules.Perform<MudObject, MudObject>("take")
                .Do((actor, target) =>
                {
                    MudObject.SendMessage(actor, "@you take", target);
                    MudObject.SendExternalMessage(actor, "@they take", actor, target);
                    MudObject.Move(target, actor);
                    return PerformResult.Continue;
                })
                .Name("Default handle taken rule.");

            GlobalRules.Check<MudObject, MudObject>("can take?")
                .First
                .When((actor, thing) => thing is Actor)
                .Do((actor, thing) =>
                {
                    MudObject.SendMessage(actor, "@cant take people");
                    return CheckResult.Disallow;
                })
                .Name("Can't take people rule.");

            GlobalRules.Check<MudObject, MudObject>("can take?")
                .First
                .When((actor, thing) => thing.GetPropertyOrDefault<bool>("portal?", false))
                .Do((actor, thing) =>
                {
                    MudObject.SendMessage(actor, "@cant take portal");
                    return CheckResult.Disallow;
                });

            GlobalRules.Check<MudObject, MudObject>("can take?")
                .First
                .When((actor, thing) => thing.GetBooleanProperty("scenery?"))
                .Do((actor, thing) =>
                {
                    MudObject.SendMessage(actor, "@cant take scenery");
                    return CheckResult.Disallow;
                })
                .Name("Can't take scenery rule.");
        }