Пример #1
0
        private SensoryMessage CreateLeaveMessage(Thing self)
        {
            var message = new ContextualString(self, this.Target)
            {
                ToOriginator = $"You follow {this.Target.Name}.",
                ToOthers     = $"{self.Name} leaves, following {this.Target.Name}."
            };

            return(new SensoryMessage(SensoryType.Sight, 100, message));
        }
Пример #2
0
        private SensoryMessage CreateUnfollowMessage(Thing self, Thing oldTarget)
        {
            var message = new ContextualString(self, oldTarget)
            {
                ToOriginator = "You stop following $Target.Name.",
                ToReceiver   = "$ActiveThing.Name stops following you."
            };

            return(new SensoryMessage(SensoryType.Sight, 100, message));
        }
Пример #3
0
        private SensoryMessage CreateArriveMessage(Thing self)
        {
            var message = new ContextualString(self, this.Target)
            {
                ToReceiver = $"{self.Name} arrives, following you.",
                ToOthers   = $"{self.Name} arrives, following {this.Target.Name}.",
            };

            return(new SensoryMessage(SensoryType.Sight, 100, message));
        }
Пример #4
0
        private SensoryMessage CreateLeaveMessage(Thing self)
        {
            var message = new ContextualString(self, this.Target)
            {
                ToOriginator = "You follow " + this.Target.Name + ".",
                ToOthers     = "$ActiveThing.Name leaves, following " + this.Target.Name + "."
            };

            return(new SensoryMessage(SensoryType.Sight, 100, message));
        }
Пример #5
0
        private SensoryMessage CreateArriveMessage(Thing self)
        {
            var message = new ContextualString(self, this.Target)
            {
                ToReceiver = "$ActiveThing.Name arrives, following you.",
                ToOthers   = "$ActiveThing.Name arrives, following " + this.Target.Name + "."
            };

            return(new SensoryMessage(SensoryType.Sight, 100, message));
        }
Пример #6
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            // Contextual message text to be supplied based on the action below
            var response = new ContextualString(sender.Thing, room.Parent);

            if (command == "add")
            {
                // Add or update the description
                room.Visuals[visualName] = visualDescription;
                response.ToOriginator    = string.Format("Visual '{0}' added/updated on room {1} [{2}].", visualName, roomName, roomId);

                //// TODO: Save change
                //room.Save();
            }
            else if (command == "remove")
            {
                if (room.Visuals.ContainsKey(visualName))
                {
                    room.Visuals.Remove(visualName);

                    response.ToOriginator = string.Format("Visual '{0}' removed from room {1} [{2}]", visualName, roomName, roomId);
                }

                //// TODO: Save change
                //room.Save();
            }
            else if (command == "show")
            {
                var output = new StringBuilder();

                if (room.Visuals.Count > 0)
                {
                    output.AppendLine(string.Format("Visuals for {0} [{1}]:", roomName, roomId)).AppendLine();

                    foreach (var name in room.Visuals.Keys)
                    {
                        output.AppendLine(string.Format("  {0}: {1}", name, room.Visuals[name]));
                    }
                }
                else
                {
                    output.Append(string.Format("No visuals found for {0} [{1}].", roomName, roomId));
                }

                sender.Write(output.ToString());

                // No need to raise event.
                return;
            }

            var message = new SensoryMessage(SensoryType.Sight, 100, response);
            var evt     = new GameEvent(sender.Thing, message);

            sender.Thing.Eventing.OnMiscellaneousEvent(evt, EventScope.SelfDown);
        }
Пример #7
0
        /// <summary>
        /// Executes the command.
        /// TODO: Optionally allow the admin to create a new attribute if the target didn't
        /// already have the attribute available to modify.
        /// </summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            IController sender     = actionInput.Controller;
            var         originator = sender.Thing;

            // Strings to be displayed when the effect is applied/removed.
            var buffString = new ContextualString(sender.Thing, this.target)
            {
                ToOriginator = string.Format("\r\nThe '{0}' stat of {1} has changed by {2}.\r\n", this.stat.Name, this.target.Name, this.modAmount),
                ToReceiver   = string.Format("\r\nYour '{0}' stat has changed by {1}.\r\n", this.stat.Name, this.modAmount)
            };
            var unbuffString = new ContextualString(sender.Thing, this.target)
            {
                ToReceiver = string.Format("\r\nYour '{0}' stat goes back to normal.", this.stat.Abbreviation)
            };

            // Turn the above sets of strings into sensory messages.
            var sensoryMessage    = new SensoryMessage(SensoryType.Sight, 100, buffString);
            var expirationMessage = new SensoryMessage(SensoryType.Sight, 100, unbuffString);

            // Remove all existing effects on stats with the same abbreviation
            // to prevent the effects from being stacked, at least for now.
            foreach (var effect in this.target.Behaviors.OfType <StatEffect>())
            {
                if (effect.Stat.Abbreviation == this.stat.Abbreviation)
                {
                    sender.Thing.Behaviors.Remove(effect);
                }
            }

            // Create the effect, based on the type of modification.
            StatEffect statEffect = null;

            switch (this.modType)
            {
            case "value":
                statEffect = new StatEffect(sender.Thing, this.stat, this.modAmount, 0, 0, this.duration, sensoryMessage, expirationMessage);
                break;

            case "min":
                statEffect = new StatEffect(sender.Thing, this.stat, 0, this.modAmount, 0, this.duration, sensoryMessage, expirationMessage);
                break;

            case "max":
                statEffect = new StatEffect(sender.Thing, this.stat, 0, 0, this.modAmount, this.duration, sensoryMessage, expirationMessage);
                break;
            }

            // Apply the effect.
            if (statEffect != null)
            {
                this.target.Behaviors.Add(statEffect);
            }
        }
Пример #8
0
        private SensoryMessage CreateFollowMessage(Thing self, Thing newTarget)
        {
            var message = new ContextualString(self, newTarget)
            {
                ToOriginator = $"You start following {newTarget.Name}.",
                ToReceiver   = $"{self.Name} starts following you.",
                ToOthers     = $"{self.Name} starts following {newTarget.Name}.",
            };

            return(new SensoryMessage(SensoryType.Sight, 100, message));
        }
Пример #9
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            // If input is a simple number, assume we mean a room
            var targetPlace = int.TryParse(actionInput.Tail, out var roomNum) ? ThingManager.Instance.FindThing("room/" + roomNum) : ThingManager.Instance.FindThingByName(actionInput.Tail, false, true);

            if (targetPlace == null)
            {
                actionInput.Controller.Write(new OutputBuilder().AppendLine("Room or Entity not found."));
                return;
            }

            if (targetPlace.FindBehavior <RoomBehavior>() == null)
            {
                // If the target's parent is a room, go there instead
                if (targetPlace.Parent != null && targetPlace.Parent.FindBehavior <RoomBehavior>() != null)
                {
                    targetPlace = targetPlace.Parent;
                }
                else
                {
                    actionInput.Controller.Write(new OutputBuilder().AppendLine("Target is not a room and is not in a room!"));
                    return;
                }
            }

            var adminName           = actionInput.Controller.Thing.Name;
            var leaveContextMessage = new ContextualString(actionInput.Controller.Thing, actionInput.Controller.Thing.Parent)
            {
                ToOriginator = null,
                ToReceiver   = $"{adminName} disappears into nothingness.",
                ToOthers     = $"{adminName} disappears into nothingness.",
            };
            var arriveContextMessage = new ContextualString(actionInput.Controller.Thing, targetPlace)
            {
                ToOriginator = $"You teleported to {targetPlace.Name}.",
                ToReceiver   = $"{adminName} appears from nothingness.",
                ToOthers     = $"{adminName} appears from nothingness.",
            };
            var leaveMessage  = new SensoryMessage(SensoryType.Sight, 100, leaveContextMessage);
            var arriveMessage = new SensoryMessage(SensoryType.Sight, 100, arriveContextMessage);

            // If we successfully move (IE the move may get cancelled if the user doesn't have permission
            // to enter a particular location, some other behavior cancels it, etc), then perform a 'look'
            // command to get immediate feedback about the new location.
            // TODO: This should not 'enqueue' a command since, should the player have a bunch of
            //     other commands entered, the 'look' feedback will not immediately accompany the 'goto'
            //     command results like it should.
            var movableBehavior = actionInput.Controller.Thing.FindBehavior <MovableBehavior>();

            if (movableBehavior != null && movableBehavior.Move(targetPlace, actionInput.Controller.Thing, leaveMessage, arriveMessage))
            {
                CommandManager.Instance.EnqueueAction(new ActionInput("look", actionInput.Controller));
            }
        }
Пример #10
0
        private void CreateYellEvent(Thing entity)
        {
            var contextMessage = new ContextualString(entity, null)
            {
                ToOriginator = "You yell: " + this.yellSentence,
                ToReceiver   = "You hear $ActiveThing.Name yell: " + this.yellSentence,
                ToOthers     = "You hear $ActiveThing.Name yell: " + this.yellSentence,
            };
            var sm = new SensoryMessage(SensoryType.Hearing, 100, contextMessage);

            this.yellEvent = new VerbalCommunicationEvent(entity, sm, VerbalCommunicationType.Yell);
        }
Пример #11
0
        private void CreateYellEvent(Thing entity)
        {
            var contextMessage = new ContextualString(entity, null)
            {
                ToOriginator = $"You yell: {yellSentence}",
                ToReceiver   = $"You hear {entity.Name} yell: {yellSentence}",
                ToOthers     = $"You hear {entity.Name} yell: {yellSentence}",
            };
            var sm = new SensoryMessage(SensoryType.Hearing, 100, contextMessage);

            yellEvent = new VerbalCommunicationEvent(entity, sm, VerbalCommunicationType.Yell);
        }
Пример #12
0
        /// <summary>Executes the command.</summary>
        /// <remarks>
        /// TODO: Optionally allow the admin to create a new attribute if the target didn't
        /// already have the attribute available to modify.
        /// </remarks>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            // Strings to be displayed when the effect is applied/removed.
            var buffString = new ContextualString(actionInput.Actor, target)
            {
                ToOriginator = $"The '{stat.Name}' stat of {target.Name} has changed by {modAmount}.",
                ToReceiver   = $"Your '{stat.Name}' stat has changed by {modAmount}."
            };
            var unbuffString = new ContextualString(actionInput.Actor, target)
            {
                ToReceiver = $"Your '{stat.Abbreviation}' stat goes back to normal."
            };

            // Turn the above sets of strings into sensory messages.
            var sensoryMessage    = new SensoryMessage(SensoryType.Sight, 100, buffString);
            var expirationMessage = new SensoryMessage(SensoryType.Sight, 100, unbuffString);

            // Remove all existing effects on stats with the same abbreviation
            // to prevent the effects from being stacked, at least for now.
            foreach (var effect in target.Behaviors.OfType <StatEffect>())
            {
                if (effect.Stat.Abbreviation == stat.Abbreviation)
                {
                    actionInput.Actor.Behaviors.Remove(effect);
                }
            }

            // Create the effect, based on the type of modification.
            StatEffect statEffect = null;

            switch (modType)
            {
            case "value":
                statEffect = new StatEffect(actionInput.Actor, stat, modAmount, 0, 0, duration, sensoryMessage, expirationMessage);
                break;

            case "min":
                statEffect = new StatEffect(actionInput.Actor, stat, 0, modAmount, 0, duration, sensoryMessage, expirationMessage);
                break;

            case "max":
                statEffect = new StatEffect(actionInput.Actor, stat, 0, 0, modAmount, duration, sensoryMessage, expirationMessage);
                break;
            }

            // Apply the effect.
            if (statEffect != null)
            {
                target.Behaviors.Add(statEffect);
            }
        }
Пример #13
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <remarks>Verify that the Guards pass first.</remarks>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            IController sender         = actionInput.Controller;
            var         contextMessage = new ContextualString(sender.Thing, sender.Thing)
            {
                ToOriginator = "You have entered the combat state.",
                ToReceiver   = "You see $Aggressor.Name shift into a combat stance.",
                ToOthers     = "You see $Aggressor.Name shift into a combat stance.",
            };

            var sm = new SensoryMessage(SensoryType.Debug, 100, contextMessage);

            var senseEvent = new SensoryEvent(sender.Thing, sm);
        }
Пример #14
0
        /// <summary>Lock or unlock this behavior's parent, via the specified actor.</summary>
        /// <param name="actor">The actor doing the locking or unlocking.</param>
        /// <param name="verb">Whether this is an "lock" or "unlock" action.</param>
        /// <param name="newLockedState">The new IsLocked state to be set, if the request is not cancelled.</param>
        private void LockOrUnlock(Thing actor, string verb, bool newLockedState)
        {
            // If we're already in the desired locked/unlocked state, we're already done with state changes.
            if (newLockedState == IsLocked)
            {
                // TODO: Message to the actor that it is already locked/unlocked.
                return;
            }

            // Use a temporary ref to our own parent to avoid race conditions like sudden parent removal.
            var thisThing = Parent;

            if (thisThing == null)
            {
                return; // Abort if the behavior is unattached (e.g. being destroyed).
            }

            if (newLockedState && thisThing != null)
            {
                // If we are attempting to lock an opened thing, cancel the lock attempt.
                var opensClosesBehavior = thisThing.Behaviors.FindFirst <OpensClosesBehavior>();
                if (opensClosesBehavior != null && opensClosesBehavior.IsOpen)
                {
                    // TODO: Message to the actor that they can't lock an open thing.
                    return;
                }
            }

            // Prepare the Lock/Unlock game event for sending as a request, and if not cancelled, again as an event.
            var contextMessage = new ContextualString(actor, thisThing)
            {
                ToOriginator = $"You {verb} {thisThing.Name}.",
                ToReceiver   = $"{actor.Name} {verb}s you.",
                ToOthers     = $"{actor.Name} {verb}s {thisThing.Name}.",
            };
            var message = new SensoryMessage(SensoryType.Sight, 100, contextMessage);
            var e       = new LockUnlockEvent(thisThing, false, actor, message);

            // Broadcast the Lock or Unlock Request and carry on if nothing cancelled it.
            // Broadcast from the parents of the lockable/unlockable thing (IE a room or inventory where the lockable resides).
            thisThing.Eventing.OnMiscellaneousRequest(e, EventScope.ParentsDown);
            if (!e.IsCancelled)
            {
                // Lock or Unlock the thing.
                IsLocked = newLockedState;

                // Broadcast the Lock or Unlock event.
                thisThing.Eventing.OnMiscellaneousEvent(e, EventScope.ParentsDown);
            }
        }
Пример #15
0
        /// <summary>Executes the command.</summary>
        /// <remarks>Verify that the Guards pass first.</remarks>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            var actor          = actionInput.Actor;
            var contextMessage = new ContextualString(actor, null)
            {
                ToOriginator = "You have entered the combat state.",
                ToReceiver   = $"You see {actor.Name} shift into a combat stance.",
                ToOthers     = $"You see {actor.Name} shift into a combat stance.",
            };

            var sm         = new SensoryMessage(SensoryType.Debug, 100, contextMessage);
            var senseEvent = new SensoryEvent(actor, sm);

            actor.Eventing.OnMiscellaneousEvent(senseEvent, EventScope.ParentsDown);
        }
Пример #16
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            IController sender = actionInput.Controller;

            var myBehaviors = sender.Thing.Behaviors;

            var followingBehavior = myBehaviors.FindFirst <FollowingBehavior>();

            if (followingBehavior != null)
            {
                var target = followingBehavior.Target;
                if (target != null)
                {
                    var targetBehaviors  = target.Behaviors;
                    var followedBehavior = targetBehaviors.FindFirst <FollowedBehavior>();
                    if (followedBehavior != null)
                    {
                        lock (followedBehavior.Followers)
                        {
                            followedBehavior.Followers.Remove(sender.Thing);
                            if (followedBehavior.Followers.Count == 0)
                            {
                                targetBehaviors.Remove(followedBehavior);
                            }
                        }
                    }
                }

                myBehaviors.Remove(followingBehavior);
            }
            else
            {
                var message = new ContextualString(sender.Thing, null)
                {
                    ToOriginator = "You aren't following anybody."
                };

                var senseMessage = new SensoryMessage(SensoryType.All, 100, message);

                var followEvent = new FollowEvent(sender.Thing, senseMessage, sender.Thing, null);

                // Broadcast the event
                sender.Thing.Eventing.OnMiscellaneousEvent(followEvent, EventScope.ParentsDown);
            }
        }
Пример #17
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            var emoteString = $"<*{actionInput.Actor.Name} {actionInput.Tail}>";

            var contextualString = new ContextualString(actionInput.Actor, actionInput.Actor.Parent)
            {
                ToOriginator = emoteString,
                ToOthers     = emoteString
            };

            var msg        = new SensoryMessage(SensoryType.Sight, 100, contextualString);
            var emoteEvent = new VerbalCommunicationEvent(actionInput.Actor, msg, VerbalCommunicationType.Emote);

            actionInput.Actor.Eventing.OnCommunicationRequest(emoteEvent, EventScope.ParentsDown);
            if (!emoteEvent.IsCancelled)
            {
                actionInput.Actor.Eventing.OnCommunicationEvent(emoteEvent, EventScope.ParentsDown);
            }
        }
Пример #18
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            IController sender         = actionInput.Controller;
            var         contextMessage = new ContextualString(sender.Thing, sender.Thing.Parent)
            {
                ToOriginator = $"You say: {this.sayText}",
                ToReceiver   = $"{sender.Thing.Name} says: {this.sayText}",
                ToOthers     = $"{sender.Thing.Name} says: {this.sayText}",
            };
            var sm = new SensoryMessage(SensoryType.Hearing, 100, contextMessage);

            var sayEvent = new VerbalCommunicationEvent(sender.Thing, sm, VerbalCommunicationType.Say);

            sender.Thing.Eventing.OnCommunicationRequest(sayEvent, EventScope.ParentsDown);
            if (!sayEvent.IsCancelled)
            {
                sender.Thing.Eventing.OnCommunicationEvent(sayEvent, EventScope.ParentsDown);
            }
        }
Пример #19
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            var contextMessage = new ContextualString(actionInput.Actor, thingToDrop.Parent)
            {
                ToOriginator = $"You drop up {thingToDrop.Name}.",
                ToReceiver   = $"{actionInput.Actor.Name} drops {thingToDrop.Name} in you.",
                ToOthers     = $"{actionInput.Actor.Name} drops {thingToDrop.Name}."
            };
            var dropMessage = new SensoryMessage(SensoryType.Sight, 100, contextMessage);

            var actor = actionInput.Actor;

            if (movableBehavior.Move(dropLocation, actor, null, dropMessage))
            {
                // TODO: Transactionally save actors if applicable.
                //actor.Save();
                //dropLocation.Save();
            }
        }
Пример #20
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            // Build our knock messages for this room and the next.  Only send message to the door-type thing once.
            IController sender          = actionInput.Controller;
            var         thisRoomMessage = new ContextualString(sender.Thing, this.target)
            {
                ToOriginator = @"You knock on $ActiveThing.Name.",
                ToOthers     = @"$Knocker.Name knocks on $ActiveThing.Name.",
                ToReceiver   = @"$Knocker.Name knocks on you.",
            };
            var nextRoomMessage = new ContextualString(sender.Thing, this.target)
            {
                ToOriginator = null,
                ToOthers     = @"Someone knocks on $ActiveThing.Name.",
                ToReceiver   = null,
            };

            // Create sensory messages.
            var thisRoomSM = new SensoryMessage(SensoryType.Sight | SensoryType.Hearing, 100, thisRoomMessage, new Hashtable {
                { "Knocker", sender.Thing }
            });
            var nextRoomSM = new SensoryMessage(SensoryType.Hearing, 100, nextRoomMessage);

            // Generate our knock events.
            var thisRoomKnockEvent = new KnockEvent(this.target, thisRoomSM);
            var nextRoomKnockEvent = new KnockEvent(this.target, nextRoomSM);

            // Broadcast the requests/events; the events handle sending the sensory messages.
            sender.Thing.Eventing.OnCommunicationRequest(thisRoomKnockEvent, EventScope.ParentsDown);
            if (!thisRoomKnockEvent.IsCancelled)
            {
                // The knocking here happens regardless of whether it's cancelled on the inside.
                sender.Thing.Eventing.OnCommunicationEvent(thisRoomKnockEvent, EventScope.ParentsDown);

                // Next try to send a knock event into the adjacent place too.
                this.nextRoom.Eventing.OnCommunicationRequest(nextRoomKnockEvent, EventScope.SelfDown);
                if (!nextRoomKnockEvent.IsCancelled)
                {
                    this.nextRoom.Eventing.OnCommunicationEvent(nextRoomKnockEvent, EventScope.SelfDown);
                }
            }
        }
Пример #21
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            IController sender      = actionInput.Controller;
            string      emoteString = string.Format("$ActiveThing.Name {0}", emoteText);

            var contextualString = new ContextualString(sender.Thing, sender.Thing.Parent)
            {
                ToOriginator = emoteString,
                ToOthers     = emoteString
            };

            var msg        = new SensoryMessage(SensoryType.Sight, 100, contextualString);
            var emoteEvent = new VerbalCommunicationEvent(sender.Thing, msg, VerbalCommunicationType.Emote);

            sender.Thing.Eventing.OnCommunicationRequest(emoteEvent, EventScope.ParentsDown);
            if (!emoteEvent.IsCancelled)
            {
                sender.Thing.Eventing.OnCommunicationEvent(emoteEvent, EventScope.ParentsDown);
            }
        }
Пример #22
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            // Generate an item changed owner event.
            IController sender = actionInput.Controller;

            var contextMessage = new ContextualString(sender.Thing, this.thingToDrop.Parent)
            {
                ToOriginator = "You drop up $Thing.Name.",
                ToReceiver   = "$ActiveThing.Name drops $Thing.Name in you.",
                ToOthers     = "$ActiveThing.Name drops $Thing.Name.",
            };
            var dropMessage = new SensoryMessage(SensoryType.Sight, 100, contextMessage);

            var actor = actionInput.Controller.Thing;

            if (this.movableBehavior.Move(this.dropLocation, actor, null, dropMessage))
            {
                actor.Save();
                this.dropLocation.Save();
            }
        }
Пример #23
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            // Generate an item changed owner event.
            IController sender = actionInput.Controller;

            var contextMessage = new ContextualString(sender.Thing, thingToDrop.Parent)
            {
                ToOriginator = $"You drop up {thingToDrop.Name}.",
                ToReceiver   = $"{sender.Thing.Name} drops $Thing.Name in you.",
                ToOthers     = $"{sender.Thing.Name} drops $Thing.Name.",
            };
            var dropMessage = new SensoryMessage(SensoryType.Sight, 100, contextMessage);

            var actor = actionInput.Controller.Thing;

            if (movableBehavior.Move(dropLocation, actor, null, dropMessage))
            {
                // TODO: Transactionally save actors if applicable.
                //actor.Save();
                //dropLocation.Save();
            }
        }
Пример #24
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            IController sender = actionInput.Controller;

            if (sourceContainer == null || sourceContainer.Count <= 0 || destinationParent == null)
            {
                return;
            }

            // Dump each child out of the targeted container.
            List <string> movedThingNames = new List <string>();

            foreach (Thing thing in sourceContainer.Children)
            {
                var movableBehavior = thing.Behaviors.FindFirst <MovableBehavior>();
                if (movableBehavior != null)
                {
                    // Try to move the item without any messaging since we'll be sending a bulk message later.
                    if (movableBehavior.Move(destinationParent, sender.Thing, null, null))
                    {
                        movedThingNames.Add(thing.Name);
                    }
                }
            }

            string commaSeparatedList = BuildCommaSeparatedList(movedThingNames);
            var    contextMessage     = new ContextualString(sender.Thing, destinationParent)
            {
                ToOriginator = $"You move {commaSeparatedList} from {sourceContainer.Name} into {destinationParent.Name}",
                ToReceiver   = $"{sender.Thing.Name} moves {commaSeparatedList} from {sourceContainer.Name} into you.",
                ToOthers     = $"{sender.Thing.Name} moves {commaSeparatedList} from {sourceContainer.Name} into {destinationParent.Name}.",
            };
            var message = new SensoryMessage(SensoryType.Sight, 100, contextMessage);

            var bulkMovementEvent = new BulkMovementEvent(sender.Thing, message);

            sender.Thing.Eventing.OnMovementEvent(bulkMovementEvent, EventScope.ParentsDown);
        }
Пример #25
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            // Remove the item from the character's possession.
            // TODO: Test, this may be broken now... esp for numberToGive != max
            if (numberToGive > 0 && thing != null)
            {
                thing.RemoveFromParents();
            }

            var contextMessage = new ContextualString(actionInput.Actor, target)
            {
                ToOriginator = $"You gave {thing.Name} to {target}.",
                ToReceiver   = $"{actionInput.Actor.Name} gave you {thing.Name}.",
                ToOthers     = $"{actionInput.Actor.Name} gave {thing.Name} to {target.Name}.",
            };
            var message = new SensoryMessage(SensoryType.Sight, 100, contextMessage);

            // Try to move the thing from the sender to the target; this handles eventing and whatnot for us.
            if (!movableBehavior.Move(target, actionInput.Actor, null, message))
            {
                actionInput.Session?.WriteLine($"Failed to give {thing.Name} to {target.Name}.");
            }
        }
Пример #26
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        /// <remarks>TODO: ability to block via ear muffs, send tell to NPC? Also remote rtell via @</remarks>
        public override void Execute(ActionInput actionInput)
        {
            var fixedSentence  = $"'<%yellow%> {sentence}<%n%>'";
            var contextMessage = new ContextualString(actionInput.Controller.Thing, target)
            {
                ToOriginator = BuildOriginatorMessage(fixedSentence),
                ToReceiver   = $"{actionInput.Controller.Thing.Name} tells you: {fixedSentence}",
                ToOthers     = null,
            };
            var sm = new SensoryMessage(SensoryType.Hearing, 100, contextMessage);

            var tellEvent = new VerbalCommunicationEvent(actionInput.Controller.Thing, sm, VerbalCommunicationType.Tell);

            // Make sure both the user is allowed to do the tell and the target is allowed to receive it.
            target.Eventing.OnCommunicationRequest(tellEvent, EventScope.SelfDown);
            actionInput.Controller.Thing.Eventing.OnCommunicationRequest(tellEvent, EventScope.SelfDown);
            if (!tellEvent.IsCancelled)
            {
                // Printing the sensory message is all that's left to do, which the event itself will take care of.
                target.Eventing.OnCommunicationEvent(tellEvent, EventScope.SelfDown);
                actionInput.Controller.Thing.Eventing.OnCommunicationEvent(tellEvent, EventScope.SelfDown);
            }
        }
Пример #27
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        /// <remarks>TODO: ability to block via ear muffs, send tell to NPC? Also remote rtell via @</remarks>
        public override void Execute(ActionInput actionInput)
        {
            IController sender         = actionInput.Controller;
            string      fixedSentence  = "\"<%yellow%>" + this.sentence + "<%n%>\"";
            var         contextMessage = new ContextualString(sender.Thing, this.target)
            {
                ToOriginator = this.BuildOriginatorMessage(fixedSentence),
                ToReceiver   = string.Format("{0} tells you: {1}", sender.Thing.Name, fixedSentence),
                ToOthers     = null,
            };
            var sm = new SensoryMessage(SensoryType.Hearing, 100, contextMessage);

            var tellEvent = new VerbalCommunicationEvent(sender.Thing, sm, VerbalCommunicationType.Tell);

            // Make sure both the user is allowed to do the tell and the target is allowed to receive it.
            this.target.Eventing.OnCommunicationRequest(tellEvent, EventScope.SelfDown);
            sender.Thing.Eventing.OnCommunicationRequest(tellEvent, EventScope.SelfDown);
            if (!tellEvent.IsCancelled)
            {
                // Printing the sensory message is all that's left to do, which the event itself will take care of.
                this.target.Eventing.OnCommunicationEvent(tellEvent, EventScope.SelfDown);
                sender.Thing.Eventing.OnCommunicationEvent(tellEvent, EventScope.SelfDown);
            }
        }
Пример #28
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            // Strings to be displayed when the effect is applied/removed.
            var muteString = new ContextualString(actionInput.Actor, playerToMute)
            {
                ToOriginator = $"You mute {playerToMute.Name} for duration {muteDuration}.",
                ToReceiver   = "You are now mute. Please reflect on your recent choices."
            };
            var unmuteString = new ContextualString(actionInput.Actor, playerToMute)
            {
                ToOriginator = $"{playerToMute.Name} is no longer mute.",
                ToReceiver   = "You are no longer mute."
            };

            // Turn the above sets of strings into sensory messages.
            var muteMessage   = new SensoryMessage(SensoryType.Sight, 100, muteString);
            var unmuteMessage = new SensoryMessage(SensoryType.Sight, 100, unmuteString);

            // Create the effect.
            var muteEffect = new MutedEffect(actionInput.Actor, muteDuration, muteMessage, unmuteMessage);

            // Apply the effect.
            playerToMute.Behaviors.Add(muteEffect);
        }
Пример #29
0
 public static MvcHtmlString Format <TModel>(this HtmlHelper <TModel> html, string id, params object[] args)
 {
     return(MvcHtmlString.Create(ContextualString.Merge(id, args)));
 }
Пример #30
0
 public static MvcHtmlString Lookup <TModel>(this HtmlHelper <TModel> html, string id)
 {
     return(MvcHtmlString.Create(ContextualString.Get(id)));
 }
Пример #31
0
        private SensoryMessage CreateArriveMessage(Thing self)
        {
            var message = new ContextualString(self, this.Target)
            {
                ToReceiver = "$ActiveThing.Name arrives, following you.",
                ToOthers = "$ActiveThing.Name arrives, following " + this.Target.Name + "."
            };

            return new SensoryMessage(SensoryType.Sight, 100, message);
        }
Пример #32
0
        private SensoryMessage CreateLeaveMessage(Thing self)
        {
            var message = new ContextualString(self, this.Target)
            {
                ToOriginator = "You follow " + this.Target.Name + ".",
                ToOthers = "$ActiveThing.Name leaves, following " + this.Target.Name + "."
            };

            return new SensoryMessage(SensoryType.Sight, 100, message);
        }
Пример #33
0
        private SensoryMessage CreateUnfollowMessage(Thing self, Thing oldTarget)
        {
            var message = new ContextualString(self, oldTarget)
            {
                ToOriginator = "You stop following $Target.Name.",
                ToReceiver = "$ActiveThing.Name stops following you."
            };

            return new SensoryMessage(SensoryType.Sight, 100, message);
        }