Example #1
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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("nowhere", "You aren't anywhere.");
            Core.StandardMessage("dark", "It's too dark to see.");
            Core.StandardMessage("also here", "Also here: <l0>.");
            Core.StandardMessage("on which", "(on which is <l0>)");
            Core.StandardMessage("obvious exits", "Obvious exits:");
            Core.StandardMessage("through", "through <the0>");
            Core.StandardMessage("to", "to <the0>");

            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 || !(room is Room))
                .Do((viewer, room) =>
                {
                    MudObject.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 lighting before generating description rule.");

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

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

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

            var describingLocale = false;

            GlobalRules.Value<Actor, Container, String, String>("printed name")
                .When((viewer, container, article) =>
                    {
                        return describingLocale && (container.LocationsSupported & 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.Short + " " + Core.FormatMessage(viewer, Core.GetMessage("on which"), subObjects);
                        else
                            return container.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.GetBooleanProperty("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.GetBooleanProperty("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 as 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;
                        MudObject.SendMessage(viewer, "@also here", normalContents);
                        describingLocale = false;
                    }

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

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

                        foreach (var link in (room as Room).EnumerateObjects<MudObject>().Where(l => l.GetBooleanProperty("portal?")))
                        {
                            var builder = new StringBuilder();
                            builder.Append("  ^");
                            builder.Append(link.GetPropertyOrDefault<Direction>("link direction", Direction.NOWHERE).ToString());

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

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

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

                    return PerformResult.Continue;
                })
                .Name("List exits in locale description rule.");
        }