public override void Initialize() { Actor(); this.SetProperty("gender", Gender.Female); Long = "The most striking feature of this tree is not it's size - it's the face hacked crudely into the trunk. As you watch, it shifts, as if muttering to itself."; this.Response("who she is", (actor, npc, topic) => { Core.SendLocaleMessage(actor, "The breeze whistles between the trees. It almost sounds like words.... \"...Forest...\", the wind says.", this); GlobalRules.ConsiderPerformRule("introduce self", this); return(PerformResult.Stop); }); Perform <MudObject, MudObject, MudObject>("topic response") .When((actor, npc, topic) => topic == null) .Do((actor, npc, topic) => { Core.SendLocaleMessage(actor, "The wind whistles.", this); return(PerformResult.Stop); }); Short = "Mother Tree"; AddNoun("mother", "tree", "oak", "forest"); Perform <MudObject, MudObject>("describe in locale").Do((actor, item) => { Core.SendMessage(actor, "The wind whistles through the leaves."); return(PerformResult.Continue); }); }
public override void Initialize() { Actor(); this.Response("who he is", (actor, npc, topic) => { Core.SendLocaleMessage(actor, "\"Name's Bjorn,\" <the0> gasps. \"You going to buy something, or..?\"", this); GlobalRules.ConsiderPerformRule("introduce self", this); return(PerformResult.Stop); }); Perform <MudObject, MudObject, MudObject>("topic response") .When((actor, npc, topic) => topic == null) .Do((actor, npc, topic) => { Core.SendLocaleMessage(actor, "\"Eh?\" <the0> asks.", this); return(PerformResult.Stop); }); Short = "Bjorn"; AddNoun("shopkeeper", "shop", "keeper", "keep"); AddNoun("bjorn", "b").When(a => GlobalRules.ConsiderValueRule <bool>("actor knows actor?", a, this)); this.Wear("overalls", ClothingLayer.Outer, ClothingBodyPart.Legs); this.Wear("simple white shirt", ClothingLayer.Outer, ClothingBodyPart.Torso); this.Wear("kufi", ClothingLayer.Outer, ClothingBodyPart.Head); Perform <MudObject, MudObject>("describe in locale").Do((actor, item) => { Core.SendMessage(actor, "The shopkeeper leans on the counter."); return(PerformResult.Continue); }); }
/// <summary> /// Process commands in a single thread, until there are no more queued commands. /// Heartbeat is called between every command. /// </summary> public static void ProcessCommands() { if ((Core.Flags & StartupFlags.SingleThreaded) != StartupFlags.SingleThreaded) { throw new InvalidOperationException("ProcessCommands should only be called in single threaded mode."); } while (PendingCommands.Count > 0 && !ShuttingDown) { GlobalRules.ConsiderPerformRule("heartbeat"); Core.SendPendingMessages(); PendingCommand PendingCommand = null; try { PendingCommand = PendingCommands.FirstOrDefault(); if (PendingCommand != null) { PendingCommands.Remove(PendingCommand); } } catch (Exception e) { LogCommandError(e); PendingCommand = null; } if (PendingCommand != null) { NextCommand = PendingCommand; //Reset flags that the last command may have changed CommandTimeoutEnabled = true; SilentFlag = false; GlobalRules.LogRules(null); try { var handler = NextCommand.Actor.GetProperty <ClientCommandHandler>("command handler"); if (handler != null) { handler.HandleCommand(NextCommand); } } catch (Exception e) { LogCommandError(e); Core.DiscardPendingMessages(); } if (PendingCommand.ProcessingCompleteCallback != null) { PendingCommand.ProcessingCompleteCallback(); } } } }
/// <summary> /// Run update rule on all objects that have been marked. /// </summary> public static void UpdateMarkedObjects() { // Updating an object may mark further objects for update. Avoid an infinite loop. var startCount = MarkedObjects.Count; for (int i = 0; i < startCount; ++i) { GlobalRules.ConsiderPerformRule("update", MarkedObjects[i]); } MarkedObjects.RemoveRange(0, startCount); }
/// <summary> /// Process the Heartbeat. It is assumed that this function is called periodically by the command processing loop. /// When called, this function will invoke the "heartbeat" rulebook if enough time has passed since the last /// invokation. /// </summary> internal static void Heartbeat() { var now = DateTime.Now; var timeSinceLastBeat = now - TimeOfLastHeartbeat; if (timeSinceLastBeat.TotalMilliseconds >= SettingsObject.HeartbeatInterval) { Core.TimeOfDay += Core.SettingsObject.ClockAdvanceRate; TimeOfLastHeartbeat = now; CurrentHeartbeat += 1; var heartbeatObjects = new HashSet <MudObject>(); foreach (var client in Clients.ConnectedClients) { foreach (var visibleObject in Core.EnumerateVisibleTree(Core.FindLocale(client.Player))) { heartbeatObjects.Add(visibleObject); } } foreach (var heartbeatObject in heartbeatObjects) { HeartbeatSet.Add(heartbeatObject); heartbeatObject.CurrentHeartbeat = CurrentHeartbeat; } HeartbeatSet.RemoveWhere(o => o.CurrentHeartbeat < (CurrentHeartbeat - Core.SettingsObject.LiveHeartbeats)); foreach (var heartbeatObject in HeartbeatSet) { GlobalRules.ConsiderPerformRule("heartbeat", heartbeatObject); } //In case heartbeat rules emitted messages. Core.SendPendingMessages(); } for (var i = 0; i < ActiveTimers.Count;) { var timerFireTime = ActiveTimers[i].StartTime + ActiveTimers[i].Interval; if (timerFireTime <= now) { ActiveTimers[i].Action(); SendPendingMessages(); ActiveTimers.RemoveAt(i); } else { ++i; } } }
/// <summary> /// Actually carryout the command, following all of it's rules, including the before and after command rules. /// </summary> /// <param name="Command"></param> /// <param name="Match"></param> /// <param name="Actor"></param> /// <returns>The result of the command's procedural rules.</returns> private static PerformResult ExecuteCommand(CommandEntry Command, PossibleMatch Match, MudObject Actor) { var result = PerformResult.Stop; Match.Upsert("COMMAND", Command); if (GlobalRules.ConsiderMatchBasedPerformRule("before command", Match, Actor) == PerformResult.Continue) { result = Command.ProceduralRules.Consider(Match, Actor); GlobalRules.ConsiderMatchBasedPerformRule("after command", Match, Actor); } GlobalRules.ConsiderPerformRule("after every command", Actor); return(result); }
/// <summary> /// Process the Heartbeat. It is assumed that this function is called periodically by the command processing loop. /// When called, this function will invoke the "heartbeat" rulebook if enough time has passed since the last /// invokation. /// </summary> internal static void Heartbeat() { var now = DateTime.Now; var timeSinceLastBeat = now - TimeOfLastHeartbeat; if (timeSinceLastBeat.TotalMilliseconds >= SettingsObject.HeartbeatInterval) { TimeOfLastHeartbeat = now; GlobalRules.ConsiderPerformRule("heartbeat"); //In case heartbeat rules emitted messages. Core.SendPendingMessages(); } }
public override void Initialize() { Actor(); this.Response("who he is", (actor, npc, topic) => { Core.SendLocaleMessage(actor, "\"Jaygmunder,\" <the0> gasps. \"You can call me Jay though.\"", this); GlobalRules.ConsiderPerformRule("introduce self", this); return(PerformResult.Stop); }); this.Response("his mechanical suit", "\"Huh, my suit? Whhat about it? When you get old, you'll need some help getting around too.\" <the0> sighs. \"Not that it does me much good now. I have't got any plasma for it.\""); this.Response("his plush chair", "\"Yeah it's pretty nice.\" <the0> pauses to stroke the arm of his chair. \"I'd let you sit in it if I could get up. Need plasma for that, though.\""); this.Response("plasma", (actor, nps, topic) => { Core.SendLocaleMessage(actor, "\"The red stuff? In the bags? You know what plasma is, don't you?\""); var quest = Core.GetObject("Homestead.PlasmaQuest"); if (GlobalRules.ConsiderValueRule <bool>("quest available?", actor, quest)) { Core.SendMessage(actor, "\"Think you can grab some for me?\" <the0> asks.", this); this.OfferQuest(actor, quest); } return(PerformResult.Stop); }); Perform <MudObject, MudObject, MudObject>("topic response") .When((actor, npc, topic) => topic == null) .Do((actor, npc, topic) => { Core.SendLocaleMessage(actor, "\"Wut?\" <the0> asks.", this); return(PerformResult.Stop); }); Short = "Jaygmundre"; AddNoun("jaygmundre", "jay", "j").When(a => GlobalRules.ConsiderValueRule <bool>("actor knows actor?", a, this)); this.Wear("mechanical suit", ClothingLayer.Outer, ClothingBodyPart.Torso); }
public override void Initialize() { Actor(); this.Response("who he is", (actor, npc, topic) => { SendLocaleMessage(actor, "\"I am Soranus,\" <the0> says.", this); GlobalRules.ConsiderPerformRule("introduce self", this); return(PerformResult.Stop); }); this.Response("the entrails", "\"These things?\" <the0> asks. \"Nothing special. They're for the wolves.\""); this.Response("wolves", (actor, npc, topic) => { SendLocaleMessage(actor, "^<the0> grins, expossing a pair of wicked yellow canines. \"Oh don't worry, they aren't here now.\"", this); var quest = GetObject("palantine/entrail_quest"); if (GlobalRules.ConsiderValueRule <bool>("quest available?", actor, quest)) { SendMessage(actor, "\"Would you mind feeding them for me?\" <the0> asks.", this); this.OfferQuest(actor, quest); } return(PerformResult.Stop); }); Perform <MudObject, MudObject, MudObject>("topic response") .When((actor, npc, topic) => topic == null) .Do((actor, npc, topic) => { SendLocaleMessage(actor, "\"This is my default response,\" <the0> says, showing his sharp little teeth.", this); return(PerformResult.Stop); }); Short = "Soranus"; AddNoun("soranus").When(a => GlobalRules.ConsiderValueRule <bool>("actor knows actor?", a, this)); this.Wear("toga", ClothingLayer.Outer, ClothingBodyPart.Torso); this.Wear(GetObject("palantine/entrails")); }