Beispiel #1
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.");
        }
Beispiel #2
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.");
        }
Beispiel #3
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.");
        }