示例#1
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject>("is matching key?", "Check if [KEY] matches [PORTAL]", "PORTAL", "KEY");

            GlobalRules.Check <MudObject, MudObject, MudObject>("can lock?")
            .When((actor, item, key) => item.GetProperty <bool>("lockable?"))
            .Do((actor, item, key) =>
            {
                if (item.GetProperty <bool>("openable?") && item.GetProperty <bool>("open?"))
                {
                    Core.SendMessage(actor, "@close it first");
                    return(CheckResult.Disallow);
                }

                if (Core.GlobalRules.ConsiderCheckRuleSilently("is matching key?", item, key) == CheckResult.Disallow)
                {
                    Core.SendMessage(actor, "@wrong key");
                    return(CheckResult.Disallow);
                }

                return(CheckResult.Allow);
            });

            GlobalRules.Perform <MudObject, MudObject, MudObject>("locked")
            .When((a, b, c) => b.GetProperty <bool>("lockable?"))
            .Do((a, b, c) =>
            {
                b.SetProperty("locked?", true);
                return(PerformResult.Continue);
            });

            GlobalRules.Perform <MudObject, MudObject, MudObject>("unlocked")
            .When((a, b, c) => b.GetProperty <bool>("lockable?"))
            .Do((a, b, c) =>
            {
                b.SetProperty("locked?", false);
                return(PerformResult.Continue);
            });

            GlobalRules.Check <MudObject, MudObject>("can open?")
            .First
            .When((a, b) => b.GetProperty <bool>("openable?") && b.GetProperty <bool>("lockable?") && b.GetProperty <bool>("locked?"))
            .Do((a, b) =>
            {
                Core.SendMessage(a, "@error locked");
                return(CheckResult.Disallow);
            })
            .Name("Can't open locked door rule.");

            GlobalRules.Perform <MudObject, MudObject>("close")
            .When((a, b) => b.GetProperty <bool>("openable?") && b.GetProperty <bool>("lockable?"))
            .Do((a, b) =>
            {
                b.SetProperty("locked?", false);
                return(PerformResult.Continue);
            });
        }
示例#2
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) => Core.CheckIsVisibleTo(actor, item))
            .Name("Item must be visible to pull rule.");

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

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

            GlobalRules.Check <MudObject, MudObject>("can pull?")
            .First
            .When((actor, target) => target.GetProperty <bool>("actor?"))
            .Do((actor, thing) =>
            {
                Core.SendMessage(actor, "@unappreciated", thing);
                return(CheckResult.Disallow);
            })
            .Name("Can't pull people rule.");
        }
示例#3
0
        public static void AtStartup(RMUD.RuleEngine GlobalRules)
        {
            GlobalRules.DeclareValueRuleBook <MudObject, bool>("silly?", "[Thing -> bool] : Determine if an object is silly.", "item");
            GlobalRules.Value <MudObject, bool>("silly?").Last.Do((thing) => false).Name("Things are serious by default rule.");

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

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

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

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

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

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

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

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

                target.AddNoun("silly");

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

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

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

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

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

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

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

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

            GlobalRules.Perform <MudObject>("dance")
            .Do(actor =>
            {
                Core.SendExternalMessage(actor, "^<the0> does a very silly dance.", actor);
                Core.SendMessage(actor, "You do a very silly dance.");
                return(PerformResult.Continue);
            })
            .Name("They aren't no friends of mine rule.");
        }
示例#4
0
        public static void AtStartup(RMUD.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.GetProperty <bool>("container?")))
                {
                    Core.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) =>
            {
                Core.SendMessage(actor, "@you put", item, Relloc.GetRelativeLocationName(relloc), container);
                Core.SendExternalMessage(actor, "@they put", actor, item, Relloc.GetRelativeLocationName(relloc), container);
                Core.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) =>
            {
                if ((container.ContentLocationsAllowed & relloc) != relloc)
                {
                    Core.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.GetProperty <bool>("open?"))
                {
                    Core.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) => Core.CheckIsVisibleTo(actor, container))
            .Name("Container must be visible rule.");

            GlobalRules.Check <MudObject, MudObject, MudObject, RelativeLocations>("can put?")
            .First
            .Do((actor, item, container, relloc) => Core.CheckIsHolding(actor, item))
            .Name("Must be holding item rule.");
        }
示例#5
0
文件: Go.cs 项目: Blecki/RMUDReboot
        public static void AtStartup(RMUD.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) =>
            {
                Core.SendMessage(actor, "@go to null link");
                return(CheckResult.Disallow);
            })
            .Name("No link found 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.GetProperty <Direction>("link direction");
                Core.SendMessage(actor, "@you went", direction.ToString().ToLower());
                Core.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 = Core.GetObject(link.GetProperty <String>("link destination"));
                if (destination == null)
                {
                    Core.SendMessage(actor, "@bad link");
                    return(PerformResult.Stop);
                }
                Core.Move(actor, destination);
                return(PerformResult.Continue);
            })
            .Name("Move through the link rule.");

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

            GlobalRules.Perform <MudObject, MudObject>("go")
            .When((actor, link) => actor.GetProperty <Client>("client") != null)
            .Do((actor, link) =>
            {
                Core.EnqueuActorCommand(actor, "look", HelperExtensions.MakeDictionary("AUTO", true));
                return(PerformResult.Continue);
            })
            .Name("Players look after going rule.");
        }