Exemple #1
0
 bool Use(Item item, MudObject target)
 {
     if (item.Usable == target) {
         return true;
     }
     return false;
 }
Exemple #2
0
 public MudObject(string name, string description, Room room, MudObject usable, Action action)
     : base(name, description)
 {
     this.room = room;
     Usable = usable;
     this.action = action;
 }
Exemple #3
0
 public static void Act(Action action, MudObject target)
 {
     switch (action){
         case Action.OpenDoor:
             OpenDoor(action, target);
             break;
         case Action.Shoot:
             Shoot(action, target);
             break;
     }
 }
Exemple #4
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("you drop", "You drop <the0>.");
            Core.StandardMessage("they drop", "^<the0> drops <a1>.");

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

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

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

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

            GlobalRules.Perform <MudObject, MudObject>("drop").Do((actor, target) =>
            {
                MudObject.SendMessage(actor, "@you drop", target);
                MudObject.SendExternalMessage(actor, "@they drop", actor, target);
                MudObject.Move(target, actor.Location);
                return(PerformResult.Continue);
            }).Name("Default drop handler rule.");
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        public override void Create(CommandParser Parser)
        {
            Parser.AddCommand(
                KeyWord("BANS"))
            .Manual("Lists all active bans.")
            .ProceduralRule((match, actor) =>
            {
                MudObject.SendMessage(actor, "~~~ ALL SET BANS ~~~");
                foreach (var proscription in Clients.ProscriptionList.Proscriptions)
                {
                    MudObject.SendMessage(actor, proscription.Glob + " : " + proscription.Reason);
                }
                return(PerformResult.Continue);
            });

            Parser.AddCommand(
                Sequence(
                    RequiredRank(500),
                    KeyWord("BAN"),
                    MustMatch("You must supply an ip mask.", SingleWord("GLOB")),
                    MustMatch("You must supply a reason.", Rest("REASON"))))
            .Manual("Ban every player who's ip matches the mask.")
            .ProceduralRule((match, actor) =>
            {
                Clients.ProscriptionList.Ban(match["GLOB"].ToString(), match["REASON"].ToString());
                Clients.SendGlobalMessage("^<the0> has banned " + match["GLOB"].ToString(), actor);
                return(PerformResult.Continue);
            });

            Parser.AddCommand(
                Sequence(
                    RequiredRank(500),
                    KeyWord("UNBAN"),
                    MustMatch("You must supply an ip mask.", SingleWord("GLOB"))))
            .Manual("Remove an existing ban.")
            .ProceduralRule((match, actor) =>
            {
                Clients.ProscriptionList.RemoveBan(match["GLOB"].ToString());
                Clients.SendGlobalMessage("^<the0> removes the ban on " + match["GLOB"].ToString(), actor);
                return(PerformResult.Continue);
            });
        }
Exemple #7
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("not lockable", "I don't think the concept of 'locked' applies to that.");
            Core.StandardMessage("you lock", "You lock <the0>.");
            Core.StandardMessage("they lock", "^<the0> locks <the1> with <the2>.");

            GlobalRules.DeclareValueRuleBook <MudObject, bool>("lockable?", "[Item] : Can this item be locked?", "item");

            GlobalRules.Value <MudObject, bool>("lockable?").Do(item => false).Name("Things not lockable by default rule.");

            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject, MudObject>("can lock?", "[Actor, Item, Key] : Can the item be locked by the actor with the key?", "actor", "item", "key");

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

            GlobalRules.Check <MudObject, MudObject, MudObject>("can lock?")
            .Do((actor, item, key) => MudObject.CheckIsHolding(actor, key))
            .Name("Key must be held rule.");

            GlobalRules.Check <MudObject, MudObject, MudObject>("can lock?")
            .When((actor, item, key) => !GlobalRules.ConsiderValueRule <bool>("lockable?", item))
            .Do((a, b, c) =>
            {
                MudObject.SendMessage(a, "@not lockable");
                return(CheckResult.Disallow);
            })
            .Name("Can't lock the unlockable rule.");

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

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

            GlobalRules.Perform <MudObject, MudObject, MudObject>("locked").Do((actor, target, key) =>
            {
                MudObject.SendMessage(actor, "@you lock", target);
                MudObject.SendExternalMessage(actor, "@they lock", actor, target, key);
                return(PerformResult.Continue);
            });
        }
Exemple #8
0
        public void Authenticate(Actor Actor, String UserName, String Password)
        {
            var existingAccount = Accounts.LoadAccount(UserName);

            if (existingAccount != null)
            {
                MudObject.SendMessage(Actor, "Account already exists.");
                return;
            }

            var newAccount = Accounts.CreateAccount(UserName, Password);

            if (newAccount == null)
            {
                MudObject.SendMessage(Actor, "Could not create account.");
                return;
            }

            LoginCommandHandler.LogPlayerIn(Actor.ConnectedClient as NetworkClient, newAccount);
        }
Exemple #9
0
 public void HandleCommand(PendingCommand Command)
 {
     try
     {
         var matchedCommand = Parser.ParseCommand(Command);
         if (matchedCommand != null)
         {
             Core.ProcessPlayerCommand(matchedCommand.Command, matchedCommand.Matches[0], Command.Actor);
         }
         else
         {
             MudObject.SendMessage(Command.Actor, "I do not understand.");
         }
     }
     catch (Exception e)
     {
         Core.ClearPendingMessages();
         MudObject.SendMessage(Command.Actor, e.Message);
     }
 }
Exemple #10
0
 public override void Create(CommandParser Parser)
 {
     Parser.AddCommand(
         KeyWord("WHO"))
     .Manual("Displays a list of current logged in players.")
     .ProceduralRule((match, actor) =>
     {
         var clients = Clients.ConnectedClients.Where(c => c is NetworkClient && (c as NetworkClient).IsLoggedOn);
         MudObject.SendMessage(actor, "~~ THESE PLAYERS ARE ONLINE NOW ~~");
         foreach (NetworkClient client in clients)
         {
             MudObject.SendMessage(actor,
                                   "[" + Core.SettingsObject.GetNameForRank(client.Player.Rank) + "] <a0> ["
                                   + client.ConnectionDescription + "]"
                                   + (client.IsAfk ? (" afk: " + client.Player.GetProperty <Account>("account").AFKMessage) : "")
                                   + (client.Player.Location != null ? (" -- " + client.Player.Location.Path) : ""),
                                   client.Player);
         }
         return(PerformResult.Continue);
     });
 }
Exemple #11
0
        public override void Create(CommandParser Parser)
        {
            Parser.AddCommand(
                Sequence(
                    RequiredRank(500),
                    KeyWord("!SAVE")))
            .Manual("Saves all persistent objects to disc.")
            .ProceduralRule((match, actor) =>
            {
                Core.CommandTimeoutEnabled = false;

                //TODO MudObject.SendGlobalMessage("The database is being saved. There may be a brief delay.");
                Core.SendPendingMessages();

                var saved = Core.Database.Save();

                //TODO MudObject.SendGlobalMessage("The database has been saved.");
                MudObject.SendMessage(actor, String.Format("I saved {0} persistent objects.", saved));
                return(PerformResult.Continue);
            });
        }
Exemple #12
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject>("can wear?", "[Actor, Item] : Can the actor wear the item?", "actor", "item");
            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("worn", "[Actor, Item] : Handle the actor wearing the item.", "actor", "item");

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

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

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

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

            GlobalRules.Perform <MudObject, MudObject>("worn").Do((actor, target) =>
            {
                MudObject.SendMessage(actor, "@clothing you wear", target);
                MudObject.SendExternalMessage(actor, "@clothing they wear", actor, target);
                MudObject.Move(target, actor, RelativeLocations.Worn);
                return(PerformResult.Continue);
            });
        }
Exemple #13
0
 public override void Create(CommandParser Parser)
 {
     Parser.AddCommand(
         Sequence(
             RequiredRank(500),
             KeyWord("!STATS"),
             Optional(SingleWord("TYPE"))))
     .Manual("Displays various stats about the server. Type the command with no argument to get a list of available options.")
     .ProceduralRule((match, actor) =>
     {
         if (!match.ContainsKey("TYPE"))
         {
             MudObject.SendMessage(actor, "Try one of these stats options");
             Core.GlobalRules.ConsiderPerformRule("enumerate-stats", actor);
         }
         else
         {
             Core.GlobalRules.ConsiderPerformRule("stats", actor, match["TYPE"].ToString().ToUpper());
         }
         return(PerformResult.Continue);
     });
 }
Exemple #14
0
        public override void Create(CommandParser Parser)
        {
            Parser.AddCommand(
                Sequence(
                    KeyWord("REGISTER"),
                    MustMatch("You must supply a username.",
                              SingleWord("USERNAME"))))
            .Manual("If you got this far, you know how to register.")
            .ProceduralRule((match, actor) =>
            {
                if (actor.ConnectedClient is NetworkClient && (actor.ConnectedClient as NetworkClient).IsLoggedOn)
                {
                    MudObject.SendMessage(actor, "You are already logged in.");
                    return(PerformResult.Stop);
                }

                var userName = match["USERNAME"].ToString();

                actor.CommandHandler = new PasswordCommandHandler(actor, Authenticate, userName);
                return(PerformResult.Continue);
            });
        }
Exemple #15
0
        public override void Initialize()
        {
            Short = "you";
            Move(GetObject("Suit"), this, RelativeLocations.Worn);

            Perform <Actor>("inventory")
            .Do(a =>
            {
                var suit         = GetObject("Suit") as Container;
                var tapedObjects = suit.GetContents(RelativeLocations.On);
                if (tapedObjects.Count != 0)
                {
                    MudObject.SendMessage(a, "Taped on my space suit is..");
                    foreach (var item in tapedObjects)
                    {
                        MudObject.SendMessage(a, "  <a0>", item);
                    }
                }
                return(PerformResult.Continue);
            })
            .Name("List taped items in inventory rule.");
        }
Exemple #16
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject>("can remove?", "[Actor, Item] : Can the actor remove the item?", "actor", "item");
            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("removed", "[Actor, Item] : Handle the actor removing the item.", "actor", "item");

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

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

            GlobalRules.Perform <MudObject, MudObject>("removed").Do((actor, target) =>
            {
                MudObject.SendMessage(actor, "@clothing you remove", target);
                MudObject.SendExternalMessage(actor, "@clothing they remove", actor, target);
                MudObject.Move(target, actor, RelativeLocations.Held);
                return(PerformResult.Continue);
            });
        }
Exemple #17
0
 public override void Create(CommandParser Parser)
 {
     Parser.AddCommand(
         Sequence(
             RequiredRank(500),
             KeyWord("!DUMP"),
             MustMatch("It helps if you supply a path.",
                       Path("TARGET"))))
     .Manual("Display the source of a database object.")
     .ProceduralRule((match, actor) =>
     {
         var target = match["TARGET"].ToString();
         var source = Core.Database.LoadSourceFile(target);
         if (!source.Item1)
         {
             MudObject.SendMessage(actor, "Could not display source: " + source.Item2);
         }
         else
         {
             MudObject.SendMessage(actor, "Source of " + target + "\n" + source.Item2);
         }
         return(PerformResult.Continue);
     });
 }
Exemple #18
0
        public static void AtStartup(RMUD.RuleEngine GlobalRules)
        {
            // Heavy things can be picked up, but not carried around.

            Core.StandardMessage("cant carry heavy thing", "^<the0> is too heavy to carry around.");

            GlobalRules.Check <MudObject, MudObject>("can go?")
            .When((actor, link) => HasHeavyThing(actor))
            .Do((actor, link) =>
            {
                MudObject.SendMessage(actor, "@cant carry heavy thing", FirstHeavyThing(actor));
                return(CheckResult.Disallow);
            })
            .Name("Can't carry around heavy things rule.");

            GlobalRules.Check <MudObject, MudObject, MudObject>("can push direction?")
            .When((actor, subject, link) => HasHeavyThing(actor))
            .Do((actor, subject, link) =>
            {
                MudObject.SendMessage(actor, "@cant carry heavy thing", FirstHeavyThing(actor));
                return(CheckResult.Disallow);
            })
            .Name("Can't carry around heavy things while pushing rule.");
        }
Exemple #19
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject, MudObject>("can hit with?", "[Actor, Subject, Object] : Can the SUBJECT be hit by the ACTOR with the OBJECT?");

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

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

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

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

            GlobalRules.Perform <MudObject, MudObject, MudObject>("hit with").Do((actor, subject, @object) =>
            {
                MudObject.SendMessage(actor, "I smacked <the0> with <the1>. I don't think it did anything.", subject, @object);
                return(PerformResult.Stop);
            });
        }
Exemple #20
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("is open", "^<the0> is open.");
            Core.StandardMessage("is closed", "^<the0> is closed.");
            Core.StandardMessage("describe on", "On <the0> is <l1>.");
            Core.StandardMessage("describe in", "In <the0> is <l1>.");
            Core.StandardMessage("empty handed", "^<the0> is empty handed.");
            Core.StandardMessage("holding", "^<the0> is holding <l1>.");

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

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

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

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

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


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

                return(PerformResult.Continue);
            })
            .Name("List held items when describing an actor rule.");
        }
Exemple #21
0
 static void OpenDoor(Action action, MudObject target)
 {
     Door door = target as Door;
     door.Open();
 }
Exemple #22
0
        public override void Create(CommandParser Parser)
        {
            Parser.AddCommand(
                Sequence(
                    KeyWord("SUBSCRIBE"),
                    MustMatch("I don't recognize that channel.",
                              Object("CHANNEL", new ChatChannelObjectSource()))))
            .Manual("Subscribes you to the specified chat channel, if you are able to access it.")
            .Check("can access channel?", "ACTOR", "CHANNEL")
            .ProceduralRule((match, actor) =>
            {
                var channel = match.ValueOrDefault("CHANNEL") as ChatChannel;
                if (!channel.Subscribers.Contains(actor))
                {
                    channel.Subscribers.Add(actor);
                }
                MudObject.SendMessage(actor, "You are now subscribed to <a0>.", channel);
                return(PerformResult.Continue);
            });

            Parser.AddCommand(
                Sequence(
                    KeyWord("UNSUBSCRIBE"),
                    MustMatch("I don't recognize that channel.",
                              Object("CHANNEL", new ChatChannelObjectSource()))))
            .Manual("Unsubscribe from the specified chat channel.")
            .ProceduralRule((match, actor) =>
            {
                var channel = match.ValueOrDefault("CHANNEL") as ChatChannel;
                channel.Subscribers.RemoveAll(c => System.Object.ReferenceEquals(c, actor.ConnectedClient));
                MudObject.SendMessage(actor, "You are now unsubscribed from <a0>.", channel);
                return(PerformResult.Continue);
            });

            Parser.AddCommand(
                KeyWord("CHANNELS"))
            .Manual("Lists all existing chat channels.")
            .ProceduralRule((match, actor) =>
            {
                MudObject.SendMessage(actor, "~~ CHANNELS ~~");
                foreach (var channel in ChatChannel.ChatChannels)
                {
                    MudObject.SendMessage(actor, (channel.Subscribers.Contains(actor) ? "*" : "") + channel.Short);
                }
                return(PerformResult.Continue);
            });

            Parser.AddCommand(
                Sequence(
                    Object("CHANNEL", new ChatChannelObjectSource()),
                    Rest("TEXT")))
            .Name("CHAT")
            .Manual("Chat on a chat channel.")
            .ProceduralRule((match, actor) =>
            {
                if (actor.ConnectedClient == null)
                {
                    return(PerformResult.Stop);
                }
                var channel = match.ValueOrDefault("CHANNEL") as ChatChannel;
                if (!channel.Subscribers.Contains(actor))
                {
                    if (Core.GlobalRules.ConsiderCheckRule("can access channel?", actor, channel) != CheckResult.Allow)
                    {
                        return(PerformResult.Stop);
                    }

                    channel.Subscribers.Add(actor);
                    MudObject.SendMessage(actor, "You are now subscribed to <a0>.", channel);
                }
                return(PerformResult.Continue);
            }, "Subscribe to channels before chatting rule.")
            .ProceduralRule((match, actor) =>
            {
                var message = match["TEXT"].ToString();
                var channel = match.ValueOrDefault("CHANNEL") as ChatChannel;
                ChatChannel.SendChatMessage(channel, "[" + channel.Short + "] " + actor.Short +
                                            (message.StartsWith("\"") ?
                                             (" " + message.Substring(1).Trim())
                            : (": \"" + message + "\"")));
                return(PerformResult.Continue);
            });


            Parser.AddCommand(
                Sequence(
                    KeyWord("RECALL"),
                    MustMatch("I don't recognize that channel.",
                              Object("CHANNEL", new ChatChannelObjectSource())),
                    Optional(Number("COUNT"))))
            .Manual("Recalls past conversation on a chat channel. An optional line count parameter allows you to peek further into the past.")
            .Check("can access channel?", "ACTOR", "CHANNEL")
            .ProceduralRule((match, actor) =>
            {
                if (actor.ConnectedClient == null)
                {
                    return(PerformResult.Stop);
                }
                var channel = match.ValueOrDefault("CHANNEL") as ChatChannel;

                int count = 20;
                if (match.ContainsKey("COUNT"))
                {
                    count = (match["COUNT"] as int?).Value;
                }

                var logFilename = ChatChannel.ChatLogsPath + channel.Short + ".txt";
                if (System.IO.File.Exists(logFilename))
                {
                    foreach (var line in (new RMUD.ReverseLineReader(logFilename)).Take(count).Reverse())
                    {
                        MudObject.SendMessage(actor, line);
                    }
                }
                return(PerformResult.Continue);
            });
        }
Exemple #23
0
 public Item(string name, string description, Room room, MudObject usable, Action action, Entity owner)
     : base(name, description, room, usable, action)
 {
     Owner = owner;
 }
Exemple #24
0
Fichier : Go.cs Projet : SinaC/RMUD
 public static RuleBuilder <MudObject, MudObject, PerformResult> PerformGo(this MudObject Object)
 {
     return(Object.Perform <MudObject, MudObject>("go"));
 }
Exemple #25
0
        public Locker() : base(RelativeLocations.In, RelativeLocations.In)
        {
            Nouns.Add("LOCKER");
            Short = "locker";
            var seen = false;

            SetProperty("open?", false);

            Check <MudObject, Locker>("can take?")
            .Do((actor, locker) =>
            {
                SendMessage(actor, "I think it's attached to the wall.");
                return(CheckResult.Disallow);
            });

            Perform <Player, Locker>("describe in locale")
            .When((player, locker) => seen == false)
            .Do((player, locker) =>
            {
                seen = true;
                SendMessage(player, "There is a locker against the wall.");
                return(PerformResult.Stop);
            });

            SetProperty("openable?", true);

            Check <MudObject, MudObject>("can open?")
            .Last
            .Do((a, b) =>
            {
                if (GetBooleanProperty("open?"))
                {
                    MudObject.SendMessage(a, "It's already open.");
                    return(CheckResult.Disallow);
                }
                return(CheckResult.Allow);
            })
            .Name("Can open doors rule.");

            Check <MudObject, MudObject>("can close?")
            .Last
            .Do((a, b) =>
            {
                if (!GetBooleanProperty("open?"))
                {
                    MudObject.SendMessage(a, "It's already closed.");
                    return(CheckResult.Disallow);
                }
                return(CheckResult.Allow);
            });

            Perform <MudObject, MudObject>("opened").Do((a, b) =>
            {
                SetProperty("open?", true);
                return(PerformResult.Continue);
            });

            Perform <MudObject, MudObject>("close").Do((a, b) =>
            {
                SetProperty("open?", false);
                return(PerformResult.Continue);
            });
        }
Exemple #26
0
 private static void DisplayBookHeader(Actor Actor, RuleBook Book)
 {
     MudObject.SendMessage(Actor, Book.Name + " -> " + Book.ResultType.Name + " : " + Book.Description);
 }
Exemple #27
0
 /// <summary>
 /// Factory that creates a Describe rule that applies only to the object it is called on.
 /// </summary>
 /// <param name="Object"></param>
 /// <returns></returns>
 public static RuleBuilder <MudObject, MudObject, PerformResult> PerformDescribe(this MudObject Object)
 {
     return(Object.Perform <MudObject, MudObject>("describe").ThisOnly(1));
 }
Exemple #28
0
 public Player(string name, string description, Room room, NetworkPlayer networkPlayer, MudObject usable, Action action)
     : base(name, description, room, usable, action)
 {
     this.networkPlayer = networkPlayer;
     room.Enter(this);
 }
Exemple #29
0
 public void Use(MudObject target)
 {
     ObjectAction.Act(action, target);
 }
Exemple #30
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("nowhere", "You aren't anywhere.");
            Core.StandardMessage("dark", "It's too dark to see.");
            Core.StandardMessage("also here", "Also here: <l0>.");
            Core.StandardMessage("on which", "(on which is <l0>)");
            Core.StandardMessage("obvious exits", "Obvious exits:");
            Core.StandardMessage("through", "through <the0>");
            Core.StandardMessage("to", "to <the0>");

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("describe in locale", "[Actor, Item] : Generate a locale description for the item.", "actor", "item");

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

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

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

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

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

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

            var describingLocale = false;

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

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

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

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

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

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

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

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

                var normalContents = new List <MudObject>();

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

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

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

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

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

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

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

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

                return(PerformResult.Continue);
            })
            .Name("List exits in locale description rule.");
        }
Exemple #31
0
 public static void Wear(this NPC NPC, MudObject Item)
 {
     MudObject.Move(Item, NPC, RelativeLocations.Worn);
 }
Exemple #32
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            GlobalRules.DeclareCheckRuleBook <MudObject, MudObject>("can introduce?", "[Actor A, Actor B] : Can A introduce B?", "actor", "itroductee");

            GlobalRules.Check <MudObject, MudObject>("can introduce?")
            .When((a, b) => !(b is Actor))
            .Do((a, b) =>
            {
                MudObject.SendMessage(a, "That just sounds silly.");
                return(CheckResult.Disallow);
            })
            .Name("Can only introduce actors rule.");

            GlobalRules.Check <MudObject, MudObject>("can introduce?")
            .Do((a, b) => MudObject.CheckIsVisibleTo(a, b))
            .Name("Introducee must be visible rule.");

            GlobalRules.Check <MudObject, MudObject>("can introduce?")
            .When((a, b) => !GlobalRules.ConsiderValueRule <bool>("actor knows actor?", a, b))
            .Do((a, b) =>
            {
                MudObject.SendMessage(a, "How can you introduce <the0> when you don't know them yourself?", b);
                return(CheckResult.Disallow);
            })
            .Name("Can't introduce who you don't know rule.");

            GlobalRules.Perform <MudObject, Actor>("describe")
            .First
            .When((viewer, actor) => GlobalRules.ConsiderValueRule <bool>("actor knows actor?", viewer, actor))
            .Do((viewer, actor) =>
            {
                MudObject.SendMessage(viewer, "^<the0>, a " + (actor.Gender == Gender.Male ? "man." : "woman."), actor);
                return(PerformResult.Continue);
            })
            .Name("Report gender of known actors rule.");

            #region Perform and report rules

            GlobalRules.DeclarePerformRuleBook <MudObject, MudObject>("introduce", "[Actor A, Actor B] : Handle A introducing B.", "actor", "introductee");

            GlobalRules.Perform <MudObject, MudObject>("introduce")
            .Do((actor, introductee) =>
            {
                var locale = MudObject.FindLocale(introductee);
                if (locale != null)
                {
                    foreach (var player in MudObject.EnumerateObjectTree(locale).Where(o => o is Player).Select(o => o as Player))
                    {
                        GlobalRules.ConsiderPerformRule("introduce to", introductee, player);
                    }
                }

                MudObject.SendExternalMessage(actor, "^<the0> introduces <the1>.", actor, introductee);
                MudObject.SendMessage(actor, "You introduce <the0>.", introductee);
                return(PerformResult.Continue);
            })
            .Name("Report introduction rule.");

            GlobalRules.DeclarePerformRuleBook <Actor>("introduce self", "[Introductee] : Introduce the introductee");

            GlobalRules.Perform <Actor>("introduce self")
            .Do((introductee) =>
            {
                var locale = MudObject.FindLocale(introductee);
                if (locale != null)
                {
                    foreach (var player in MudObject.EnumerateObjectTree(locale).Where(o => o is Player).Select(o => o as Player))
                    {
                        GlobalRules.ConsiderPerformRule("introduce to", introductee, player);
                    }
                }

                MudObject.SendExternalMessage(introductee, "^<the0> introduces themselves.", introductee);
                MudObject.SendMessage(introductee, "You introduce yourself.");

                return(PerformResult.Continue);
            })
            .Name("Introduce an actor to everyone present rule.");

            #endregion

            #region Printed name rules

            GlobalRules.Value <Player, Actor, String, String>("printed name")
            .When((viewer, thing, article) => GlobalRules.ConsiderValueRule <bool>("actor knows actor?", viewer, thing))
            .Do((viewer, actor, article) => actor.Short)
            .Name("Name of introduced actor.");

            GlobalRules.Value <MudObject, MudObject, String, String>("printed name")
            .When((viewer, thing, article) => thing is Actor && (thing as Actor).Gender == Gender.Male)
            .Do((viewer, actor, article) => article + " man")
            .Name("Default name for unintroduced male actor.");

            GlobalRules.Value <MudObject, MudObject, String, String>("printed name")
            .When((viewer, thing, article) => thing is Actor && (thing as Actor).Gender == Gender.Female)
            .Do((viewer, actor, article) => article + " woman")
            .Name("Default name for unintroduced female actor.");

            #endregion

            #region Knowledge management rules

            GlobalRules.DeclareValueRuleBook <Actor, Actor, bool>("actor knows actor?", "[Player, Whom] : Does the player know the actor?");

            GlobalRules.Value <Player, Actor, bool>("actor knows actor?")
            .Do((player, whom) => player.Recall <bool>(whom, "knows"))
            .Name("Use player memory to recall actors rule.");

            GlobalRules.Value <Actor, Actor, bool>("actor knows actor?")
            .Do((player, whom) => false)
            .Name("Actors that aren't players don't know anybody rule.");

            GlobalRules.DeclarePerformRuleBook <Actor, Actor>("introduce to", "[Introductee, ToWhom] : Introduce the introductee to someone");

            GlobalRules.Perform <Actor, Player>("introduce to")
            .Do((introductee, player) =>
            {
                player.Remember(introductee, "knows", true);
                return(PerformResult.Continue);
            })
            .Name("Players remember actors rule.");

            #endregion
        }
Exemple #33
0
 public void AddObject(MudObject obj)
 {
     mudObjectList.Add(obj);
 }
Exemple #34
0
Fichier : Go.cs Projet : SinaC/RMUD
 public static RuleBuilder <MudObject, MudObject, CheckResult> CheckCanGo(this MudObject Object)
 {
     return(Object.Check <MudObject, MudObject>("can go?").ThisOnly());
 }
Exemple #35
0
 public void RemoveObject(MudObject obj)
 {
     mudObjectList.Remove(obj);
 }
Exemple #36
0
Fichier : Go.cs Projet : SinaC/RMUD
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("unmatched cardinal", "What way was that?");
            Core.StandardMessage("go to null link", "You can't go that way.");
            Core.StandardMessage("go to closed door", "The door is closed.");
            Core.StandardMessage("you went", "You went <s0>.");
            Core.StandardMessage("they went", "^<the0> went <s1>.");
            Core.StandardMessage("bad link", "Error - Link does not lead to a room.");
            Core.StandardMessage("they arrive", "^<the0> arrives <s1>.");
            Core.StandardMessage("first opening", "[first opening <the0>]");

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

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

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

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

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

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

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

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

            GlobalRules.Perform <MudObject, MudObject>("go")
            .When((actor, link) => actor is Player && (actor as Player).ConnectedClient != null)
            .Do((actor, link) =>
            {
                Core.EnqueuActorCommand(actor as Actor, "look", HelperExtensions.MakeDictionary("AUTO", true));
                return(PerformResult.Continue);
            })
            .Name("Players look after going rule.");
        }
Exemple #37
0
 public Door(string name, string description, Room room, Room room2, MudObject usable, Entity owner, Action action)
     : base(name, description, room, usable, action)
 {
 }
Exemple #38
0
        public override void Create(CommandParser Parser)
        {
            Parser.AddCommand(
                Sequence(
                    RequiredRank(500),
                    KeyWord("!FORCE"),
                    MustMatch("Whom do you wish to command?",
                              FirstOf(
                                  Object("OBJECT", InScope),
                                  Path("PATH"))),
                    Rest("RAW-COMMAND")))
            .Manual("An administrative command that allows you to execute a command as if you were another actor or player. The other entity will see all output from the command, and rules restricting their access to the command are considered.")
            .ProceduralRule((match, actor) =>
            {
                if (match.ContainsKey("PATH"))
                {
                    var target = MudObject.GetObject(match["PATH"].ToString());
                    if (target == null)
                    {
                        MudObject.SendMessage(actor, "I can't find whomever it is you want to submit to your foolish whims.");
                        return(PerformResult.Stop);
                    }
                    match.Upsert("OBJECT", target);
                }
                return(PerformResult.Continue);
            }, "Convert path to object rule.")
            .ProceduralRule((match, actor) =>
            {
                MudObject target = match["OBJECT"] as MudObject;

                var targetActor = target as Actor;
                if (targetActor == null)
                {
                    MudObject.SendMessage(actor, "You can order inanimate objects about as much as you like, they aren't going to listen.");
                    return(PerformResult.Stop);
                }

                var command        = match["RAW-COMMAND"].ToString();
                var matchedCommand = Core.DefaultParser.ParseCommand(new PendingCommand {
                    RawCommand = command, Actor = targetActor
                });

                if (matchedCommand != null)
                {
                    if (matchedCommand.Matches.Count > 1)
                    {
                        MudObject.SendMessage(actor, "The command was ambigious.");
                    }
                    else
                    {
                        MudObject.SendMessage(actor, "Enacting your will.");
                        Core.ProcessPlayerCommand(matchedCommand.Command, matchedCommand.Matches[0], targetActor);
                    }
                }
                else
                {
                    MudObject.SendMessage(actor, "The command did not match.");
                }

                return(PerformResult.Continue);
            });
        }
Exemple #39
0
        public override void Initialize()
        {
            /*
             * The Bar is south of the Foyer. The printed name of the bar is "Foyer Bar".
             * The Bar is dark.  "The bar, much rougher than you'd have guessed
             * after the opulence of the foyer to the north, is completely empty.
             * There seems to be some sort of message scrawled in the sawdust on the floor."
             */
            Locale(RMUD.Locale.Interior);

            SetProperty("short", "Foyer Bar");
            SetProperty("long", "The bar, much rougher than you'd have guessed after the opulence of the foyer to the north, is completely empty. There seems to be some sort of message scrawled in the sawdust on the floor.");
            SetProperty("ambient light", LightingLevel.Dark);


            OpenLink(Direction.NORTH, "Foyer");

            // The scrawled message is scenery in the Bar. Understand "floor" or "sawdust" as the message.

            var message = new MudObject();

            message.SimpleName("message", "floor", "sawdust", "scrawled");
            AddScenery(message);

            //Neatness is a kind of value. The neatnesses are neat, scuffed, and trampled. The message has a neatness. The message is neat.

            bool messageScuffed = false;

            /*
             * Instead of examining the message:
             * increase score by 1;
             * say "The message, neatly marked in the sawdust, reads...";
             * end the game in victory.
             *
             * Instead of examining the trampled message:
             * say "The message has been carelessly trampled, making it difficult to read.
             * You can just distinguish the words...";
             * end the game saying "You have lost".
             */
            message.Perform <MudObject, MudObject>("describe")
            .Do((actor, item) =>
            {
                if (messageScuffed)
                {
                    Core.SendMessage(actor, "The message has been carelessly trampled, making it difficult to read. You can just distinguish the words...");
                    Core.SendMessage(actor, "YOU HAVE LOST.");
                    Core.Shutdown();
                }
                else
                {
                    Core.SendMessage(actor, "The message, neatly marked in the sawdust, reads...");
                    Core.SendMessage(actor, "YOU HAVE WON!");
                    Core.Shutdown();
                }
                return(PerformResult.Stop);
            });

            /*
             * Instead of doing something other than going in the bar when in darkness:
             * if the message is not trampled, change the neatness of the message
             * to the neatness after the neatness of the message;
             * say "In the dark? You could easily disturb something."
             */
            Perform <PossibleMatch, MudObject>("before acting")
            .When((match, actor) => GetProperty <LightingLevel>("ambient light") == LightingLevel.Dark)
            .Do((match, actor) =>
            {
                if (match.TypedValue <CommandEntry>("COMMAND").IsNamed("GO"))
                {
                    return(PerformResult.Continue);
                }
                messageScuffed = true;
                Core.SendMessage(actor, "In the dark? You could easily disturb something.");
                return(PerformResult.Stop);
            });

            /*
             * Instead of going nowhere from the bar when in darkness:
             * now the message is trampled;
             * say "Blundering around in the dark isn't a good idea!"
             */
            Perform <PossibleMatch, MudObject>("before command")
            .When((match, actor) => GetProperty <LightingLevel>("ambient light") == LightingLevel.Dark &&
                  match.TypedValue <CommandEntry>("COMMAND").IsNamed("GO") &&
                  (match.ValueOrDefault("DIRECTION") as Direction?).Value != Direction.NORTH)
            .Do((match, actor) =>
            {
                messageScuffed = true;
                Core.SendMessage(actor, "Blundering around in the dark isn't a good idea!");
                return(PerformResult.Stop);
            });
        }
Exemple #40
0
        public static void AtStartup(RuleEngine GlobalRules)
        {
            Core.StandardMessage("convo topic prompt", "Suggested topics: <l0>");
            Core.StandardMessage("convo cant converse", "You can't converse with that.");
            Core.StandardMessage("convo greet whom", "Whom did you want to greet?");
            Core.StandardMessage("convo nobody", "You aren't talking to anybody.");
            Core.StandardMessage("convo no response", "There doesn't seem to be a response defined for that topic.");
            Core.StandardMessage("convo no topics", "There is nothing obvious to discuss.");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            GlobalRules.Check <MudObject, MudObject, MudObject>("topic available?")
            .Last
            .Do((actor, npc, topic) => CheckResult.Allow)
            .Name("Topics available by default rule.");
        }
Exemple #41
0
 static void Shoot(Action action, MudObject target)
 {
 }