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."); }
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."); }
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); }); }
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."); }
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."); }
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; }); }
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."); }
public static void AtStartup(RuleEngine GlobalRules) { GlobalRules.Perform<Actor>("inventory") .Do(a => { var wornObjects = (a as Actor).GetContents(RelativeLocations.Worn); if (wornObjects.Count == 0) MudObject.SendMessage(a, "@nude"); else { MudObject.SendMessage(a, "@clothing wearing"); foreach (var item in wornObjects) MudObject.SendMessage(a, " <a0>", item); } return PerformResult.Continue; }) .Name("List worn items in inventory rule."); GlobalRules.Check<Actor, MudObject>("can wear?") .Do((actor, item) => { var layer = item.GetPropertyOrDefault<ClothingLayer>("clothing layer", ClothingLayer.Assecories); var part = item.GetPropertyOrDefault<ClothingBodyPart>("clothing part", ClothingBodyPart.Cloak); foreach (var wornItem in actor.EnumerateObjects(RelativeLocations.Worn)) if (wornItem.GetPropertyOrDefault<ClothingLayer>("clothing layer", ClothingLayer.Assecories) == layer && wornItem.GetPropertyOrDefault<ClothingBodyPart>("clothing part", ClothingBodyPart.Cloak) == part) { MudObject.SendMessage(actor, "@clothing remove first", wornItem); return CheckResult.Disallow; } return CheckResult.Continue; }) .Name("Check clothing layering before wearing rule."); GlobalRules.Check<Actor, MudObject>("can remove?") .Do((actor, item) => { var layer = item.GetPropertyOrDefault<ClothingLayer>("clothing layer", ClothingLayer.Assecories); var part = item.GetPropertyOrDefault<ClothingBodyPart>("clothing part", ClothingBodyPart.Cloak); foreach (var wornItem in actor.EnumerateObjects(RelativeLocations.Worn)) if (wornItem.GetPropertyOrDefault<ClothingLayer>("clothing layer", ClothingLayer.Assecories) < layer && wornItem.GetPropertyOrDefault<ClothingBodyPart>("clothing part", ClothingBodyPart.Cloak) == part) { MudObject.SendMessage(actor, "@clothing remove first", wornItem); return CheckResult.Disallow; } return CheckResult.Allow; }) .Name("Can't remove items under other items rule."); GlobalRules.Perform<MudObject, Actor>("describe") .First .Do((viewer, actor) => { var wornItems = new List<MudObject>(actor.EnumerateObjects(RelativeLocations.Worn)); if (wornItems.Count == 0) MudObject.SendMessage(viewer, "@clothing they are naked", actor); else MudObject.SendMessage(viewer, "@clothing they are wearing", actor, wornItems); return PerformResult.Continue; }) .Name("List worn items when describing an actor rule."); }
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."); }
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."); }
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."); }
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."); }
public static void AtStartup(RuleEngine GlobalRules) { 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) => Core.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."); }
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); }); }
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."); }
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."); }
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; }); }
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); }); }
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; }); }
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; }); }
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); }); }
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); }); }
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; }); }
public static void AtStartup(RuleEngine GlobalRules) { GlobalRules.Check <Actor, ControlPanel>("can take?") .Do((actor, panel) => { SendMessage(actor, "I can't take it. It's firmly attached."); return(CheckResult.Disallow); }); GlobalRules.Perform <Actor, ControlPanel>("describe") .When((actor, panel) => !panel.Broken) .Do((actor, panel) => { if (panel.Location is Hatch) { var thisSide = FindLocale(panel) as Room; var otherSide = Portal.FindOppositeSide(panel.Location).Location as Room; if (thisSide != null && otherSide != null && thisSide.AirLevel == otherSide.AirLevel) { panel.Indicator = IndicatorState.green; } else { panel.Indicator = IndicatorState.red; } } SendMessage(actor, "It's a little square panel covered in buttons. There is a <s0> light on it.", panel.Indicator.ToString()); return(PerformResult.Continue); }); GlobalRules.Perform <Actor, ControlPanel>("describe") .When((actor, panel) => panel.Broken) .Do((actor, panel) => { SendMessage(actor, "It's been smashed up real good."); return(PerformResult.Continue); }); GlobalRules.Perform <Player, Space.ControlPanel, MudObject>("hit with") .When((player, panel, wrench) => wrench.GetPropertyOrDefault <Weight>("weight", Weight.Normal) == Weight.Heavy) .Do((player, panel, wrench) => { SendMessage(player, "The panel smashed up good."); panel.Broken = true; return(PerformResult.Stop); }); }
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); }); }
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; }); }
public static void AtStartup(RuleEngine GlobalRules) { GlobalRules.Check<Actor, ControlPanel>("can take?") .Do((actor, panel) => { SendMessage(actor, "I can't take it. It's firmly attached."); return CheckResult.Disallow; }); GlobalRules.Perform<Actor, ControlPanel>("describe") .When((actor, panel) => !panel.Broken) .Do((actor, panel) => { if (panel.Location is Hatch) { var thisSide = FindLocale(panel) as Room; var otherSide = Portal.FindOppositeSide(panel.Location).Location as Room; if (thisSide != null && otherSide != null && thisSide.AirLevel == otherSide.AirLevel) panel.Indicator = IndicatorState.green; else panel.Indicator = IndicatorState.red; } SendMessage(actor, "It's a little square panel covered in buttons. There is a <s0> light on it.", panel.Indicator.ToString()); return PerformResult.Continue; }); GlobalRules.Perform<Actor, ControlPanel>("describe") .When((actor, panel) => panel.Broken) .Do((actor, panel) => { SendMessage(actor, "It's been smashed up real good."); return PerformResult.Continue; }); GlobalRules.Perform<Player, Space.ControlPanel, MudObject>("hit with") .When((player, panel, wrench) => wrench.GetPropertyOrDefault<Weight>("weight", Weight.Normal) == Weight.Heavy) .Do((player, panel, wrench) => { SendMessage(player, "The panel smashed up good."); panel.Broken = true; return PerformResult.Stop; }); }
public static void AtStartup(RuleEngine GlobalRules) { GlobalRules.DeclareCheckRuleBook <MudObject, MudObject>("can access channel?", "[Client, Channel] : Can the client access the chat channel?", "actor", "channel"); GlobalRules.Check <MudObject, MudObject>("can access channel?") .Do((client, channel) => CheckResult.Allow) .Name("Default allow channel access rule."); GlobalRules.Perform <Actor>("player joined") .Do(player => { foreach (var c in ChatChannel.ChatChannels.Where(c => c.Short == "OOC")) { c.Subscribers.Add(player); } return(PerformResult.Continue); }) .Name("Subscribe new players to OOC rule."); GlobalRules.Perform <Actor>("player left") .Do(player => { ChatChannel.RemoveFromAllChannels(player); return(PerformResult.Continue); }) .Name("Unsubscribe players from all channels when they leave rule."); ChatChannel.ChatChannels.Clear(); ChatChannel.ChatChannels.Add(new ChatChannel("OOC")); var senate = new ChatChannel("SENATE"); senate.Check <MudObject, MudObject>("can access channel?") .When((actor, channel) => !(actor is Actor) || (actor as Actor).Rank < 100) .Do((actor, channel) => { MudObject.SendMessage(actor, "You must have a rank of 100 or greater to access this channel."); return(CheckResult.Disallow); }); ChatChannel.ChatChannels.Add(senate); }
public static void AtStartup(RuleEngine GlobalRules) { GlobalRules.DeclareCheckRuleBook<MudObject, MudObject>("can access channel?", "[Client, Channel] : Can the client access the chat channel?", "actor", "channel"); GlobalRules.Check<MudObject, MudObject>("can access channel?") .Do((client, channel) => CheckResult.Allow) .Name("Default allow channel access rule."); GlobalRules.Perform<Actor>("player joined") .Do(player => { foreach (var c in ChatChannel.ChatChannels.Where(c => c.Short == "OOC")) c.Subscribers.Add(player); return PerformResult.Continue; }) .Name("Subscribe new players to OOC rule."); GlobalRules.Perform<Actor>("player left") .Do(player => { ChatChannel.RemoveFromAllChannels(player); return PerformResult.Continue; }) .Name("Unsubscribe players from all channels when they leave rule."); ChatChannel.ChatChannels.Clear(); ChatChannel.ChatChannels.Add(new ChatChannel("OOC")); var senate = new ChatChannel("SENATE"); senate.Check<MudObject, MudObject>("can access channel?") .When((actor, channel) => !(actor is Actor) || (actor as Actor).Rank < 100) .Do((actor, channel) => { MudObject.SendMessage(actor, "You must have a rank of 100 or greater to access this channel."); return CheckResult.Disallow; }); ChatChannel.ChatChannels.Add(senate); }
public static void AtStartup(RuleEngine GlobalRules) { GlobalRules.Check<Actor, ControlPanel>("can take?") .Do((actor, panel) => { SendMessage(actor, "I can't take it. It's firmly attached."); return SharpRuleEngine.CheckResult.Disallow; }); GlobalRules.Perform<Actor, ControlPanel>("describe") .Do((actor, panel) => { panel.UpdateHatchIndicatorState(); SendMessage(actor, "It's a little square panel covered in buttons. There is a <s0> light on it.", panel.Indicator.ToString()); return SharpRuleEngine.PerformResult.Continue; }); GlobalRules.Value<MudObject, ControlPanel, String, String>("printed name") .Do((viewer, panel, article) => { panel.UpdateHatchIndicatorState(); return String.Format("{0} control panel ({1})", article, panel.Indicator); }); }
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."); }
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 }
public static void AtStartup(RuleEngine GlobalRules) { GlobalRules.Perform <Actor>("inventory") .Do(a => { var wornObjects = (a as Actor).GetContents(RelativeLocations.Worn); if (wornObjects.Count == 0) { MudObject.SendMessage(a, "@nude"); } else { MudObject.SendMessage(a, "@clothing wearing"); foreach (var item in wornObjects) { MudObject.SendMessage(a, " <a0>", item); } } return(PerformResult.Continue); }) .Name("List worn items in inventory rule."); GlobalRules.Check <Actor, MudObject>("can wear?") .Do((actor, item) => { var layer = item.GetPropertyOrDefault <ClothingLayer>("clothing layer", ClothingLayer.Assecories); var part = item.GetPropertyOrDefault <ClothingBodyPart>("clothing part", ClothingBodyPart.Cloak); foreach (var wornItem in actor.EnumerateObjects(RelativeLocations.Worn)) { if (wornItem.GetPropertyOrDefault <ClothingLayer>("clothing layer", ClothingLayer.Assecories) == layer && wornItem.GetPropertyOrDefault <ClothingBodyPart>("clothing part", ClothingBodyPart.Cloak) == part) { MudObject.SendMessage(actor, "@clothing remove first", wornItem); return(CheckResult.Disallow); } } return(CheckResult.Continue); }) .Name("Check clothing layering before wearing rule."); GlobalRules.Check <Actor, MudObject>("can remove?") .Do((actor, item) => { var layer = item.GetPropertyOrDefault <ClothingLayer>("clothing layer", ClothingLayer.Assecories); var part = item.GetPropertyOrDefault <ClothingBodyPart>("clothing part", ClothingBodyPart.Cloak); foreach (var wornItem in actor.EnumerateObjects(RelativeLocations.Worn)) { if (wornItem.GetPropertyOrDefault <ClothingLayer>("clothing layer", ClothingLayer.Assecories) < layer && wornItem.GetPropertyOrDefault <ClothingBodyPart>("clothing part", ClothingBodyPart.Cloak) == part) { MudObject.SendMessage(actor, "@clothing remove first", wornItem); return(CheckResult.Disallow); } } return(CheckResult.Allow); }) .Name("Can't remove items under other items rule."); GlobalRules.Perform <MudObject, Actor>("describe") .First .Do((viewer, actor) => { var wornItems = new List <MudObject>(actor.EnumerateObjects(RelativeLocations.Worn)); if (wornItems.Count == 0) { MudObject.SendMessage(viewer, "@clothing they are naked", actor); } else { MudObject.SendMessage(viewer, "@clothing they are wearing", actor, wornItems); } return(PerformResult.Continue); }) .Name("List worn items when describing an actor rule."); }
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."); }
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 }
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."); }
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."); }
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."); }
// 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."); }
// 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."); }
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."); }
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."); }
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."); }
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."); }
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."); }
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."); }
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."); }