Exemplo n.º 1
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, this.target)
            {
                ToOriginator = "You cast ThunderClap at $ActiveThing.Name!",
                ToReceiver = "$Aggressor.Name casts ThunderClap at you, you only hear a ringing in your ears now.",
                ToOthers = "You hear $Aggressor.Name cast ThunderClap at $ActiveThing.Name!  It was very loud.",
            };
            var sm = new SensoryMessage(SensoryType.Hearing, 100, contextMessage);

            var attackEvent = new AttackEvent(this.target, sm, sender.Thing);
            sender.Thing.Eventing.OnCombatRequest(attackEvent, EventScope.ParentsDown);
            if (!attackEvent.IsCancelled)
            {
                var deafenEffect = new AlterSenseEffect()
                {
                    SensoryType = SensoryType.Hearing,
                    AlterAmount = -1000,
                    Duration = new TimeSpan(0, 0, 45),
                };

                this.target.Behaviors.Add(deafenEffect);
                sender.Thing.Eventing.OnCombatEvent(attackEvent, EventScope.ParentsDown);
            }
        }
Exemplo n.º 2
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;

            // Strings to be displayed when the effect is applied/removed.
            var muteString = new ContextualString(sender.Thing, this.playerToMute)
            {
                ToOriginator = "You mute $Target.",
                ToReceiver = "You are muted by $ActiveThing.",
                ToOthers = "$ActiveThing mutes $Target."
            };
            var unmuteString = new ContextualString(sender.Thing, this.playerToMute)
            {
                ToOriginator = "$Target 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(sender.Thing, this.muteDuration, muteMessage, unmuteMessage);

            // Apply the effect.
            this.playerToMute.Behaviors.Add(muteEffect);
        }
Exemplo n.º 3
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;

            this.itemToUnwieldBehavior.Wielder = null;

            // Remove the event handler that prevents dropping the item while wielded.
            var interceptor = this.itemToUnwieldBehavior.MovementInterceptor;
            this.itemToUnwield.Eventing.MovementRequest -= interceptor;

            var contextMessage = new ContextualString(sender.Thing, this.itemToUnwield.Parent)
            {
                ToOriginator = "You unwield the $WieldedItem.Name.",
                ToOthers = "$ActiveThing.Name unwields a $WieldedItem.Name.",
            };

            var sensoryMessage = new SensoryMessage(SensoryType.Sight, 100, contextMessage);

            var unwieldEvent = new WieldUnwieldEvent(this.itemToUnwield, true, sender.Thing, sensoryMessage);

            sender.Thing.Eventing.OnCombatRequest(unwieldEvent, EventScope.ParentsDown);

            if (!unwieldEvent.IsCancelled)
            {
                sender.Thing.Eventing.OnCombatEvent(unwieldEvent, EventScope.ParentsDown);
            }
        }
Exemplo n.º 4
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            // Send just one message to the command sender since they know what's going on.
            IController sender = actionInput.Controller;

            // Attempt exact ID match
            var targetPlace = ThingManager.Instance.FindThing(actionInput.Tail);

            // If input is a simple number, assume we mean a room
            int roomNum;
            targetPlace = int.TryParse(actionInput.Tail, out roomNum) ? ThingManager.Instance.FindThing("room/" + roomNum) : ThingManager.Instance.FindThingByName(actionInput.Tail, false, true);

            if (targetPlace == null)
            {
                sender.Write("Room or Entity not found.\n");
                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
                {
                    sender.Write("Target is not a room and is not in a room!\n");
                    return;
                }
            }

            var leaveContextMessage = new ContextualString(sender.Thing, sender.Thing.Parent)
            {
                ToOriginator = null,
                ToReceiver = @"$ActiveThing.Name disappears into nothingness.",
                ToOthers = @"$ActiveThing.Name disappears into nothingness.",
            };
            var arriveContextMessage = new ContextualString(sender.Thing, targetPlace)
            {
                ToOriginator = "You teleport to " + targetPlace.Name + ".",
                ToReceiver = @"$ActiveThing.Name appears from nothingness.",
                ToOthers = @"$ActiveThing.Name 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 = sender.Thing.FindBehavior<MovableBehavior>();

            if (movableBehavior != null && movableBehavior.Move(targetPlace, sender.Thing, leaveMessage, arriveMessage))
            {
                CommandManager.Instance.EnqueueAction(new ActionInput("look", sender));
            }
        }
Exemplo n.º 5
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;

            this.itemToWieldBehavior.Wielder = sender.Thing;

            // Create an event handler that intercepts the ChangeOwnerEvent and
            // prevents dropping/trading the item around while it is wielded.
            // A reference is stored in the WieldableBehavior instance so it
            // can be easily removed by the unwield command.
            var interceptor = new CancellableGameEventHandler(this.Eventing_MovementRequest);
            this.itemToWieldBehavior.MovementInterceptor = interceptor;
            this.itemToWield.Eventing.MovementRequest += interceptor;

            var contextMessage = new ContextualString(sender.Thing, this.itemToWield.Parent)
            {
                ToOriginator = "You wield the $WieldedItem.Name.",
                ToOthers = "$ActiveThing.Name wields a $WieldedItem.Name.",
            };

            var sensoryMessage = new SensoryMessage(SensoryType.Sight, 100, contextMessage);

            var wieldEvent = new WieldUnwieldEvent(this.itemToWield, true, sender.Thing, sensoryMessage);

            sender.Thing.Eventing.OnCombatRequest(wieldEvent, EventScope.ParentsDown);

            if (!wieldEvent.IsCancelled)
            {
                sender.Thing.Eventing.OnCombatEvent(wieldEvent, EventScope.ParentsDown);
            }
        }
Exemplo n.º 6
0
        private SensoryMessage CreateUnfollowMessage(Thing self, Thing oldTarget)
        {
            var message = new ContextualString(self, oldTarget)
            {
                ToOriginator = $"You stop following {oldTarget.Name}.",
                ToReceiver   = $"{self.Name} stops following you.",
            };

            return(new SensoryMessage(SensoryType.Sight, 100, message));
        }
Exemplo n.º 7
0
        private SensoryMessage CreateLeaveMessage(Thing self)
        {
            var message = new ContextualString(self, Target)
            {
                ToOriginator = $"You follow {Target.Name}.",
                ToOthers     = $"{self.Name} leaves, following {Target.Name}."
            };

            return(new SensoryMessage(SensoryType.Sight, 100, message));
        }
Exemplo n.º 8
0
        private SensoryMessage CreateArriveMessage(Thing self)
        {
            var message = new ContextualString(self, Target)
            {
                ToReceiver = $"{self.Name} arrives, following you.",
                ToOthers   = $"{self.Name} arrives, following {Target.Name}.",
            };

            return(new SensoryMessage(SensoryType.Sight, 100, message));
        }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
0
        /// <summary>Moves the Thing through.</summary>
        /// <param name="thingToMove">The thing to move.</param>
        /// <returns>Returns true if the move was successful, false if not.</returns>
        public bool MoveThrough(Thing thingToMove)
        {
            // If the thing isn't currently mobile, bail.
            var movableBehavior = thingToMove.Behaviors.FindFirst <MovableBehavior>();

            if (movableBehavior == null)
            {
                // TODO: Add messaging to thingToMove?
                return(false);
            }

            // Find the target location to be reached from here.
            DestinationInfo destinationInfo = GetDestinationFrom(thingToMove.Parent.Id);

            if (destinationInfo == null)
            {
                // There was no destination reachable from the thing's starting location.
                return(false);
            }

            // If the target location hasn't been cached already, try to do so now.
            if (destinationInfo.CachedTarget == null || destinationInfo.CachedTarget.Target == null)
            {
                Thing newTarget = ThingManager.Instance.FindThing(destinationInfo.TargetID);
                destinationInfo.CachedTarget = new SimpleWeakReference <Thing>(newTarget);
            }

            // If the destination can't be found, abort.
            Thing destination = destinationInfo.CachedTarget.Target;

            if (destination == null)
            {
                // TODO: Add messaging to thingToMove?
                return(false);
            }

            string dir = destinationInfo.ExitCommand;
            var    leaveContextMessage = new ContextualString(thingToMove, thingToMove.Parent)
            {
                ToOriginator = null,
                ToReceiver   = $"{thingToMove.Name} moves {dir}.",
                ToOthers     = $"{thingToMove.Name} moves {dir}.",
            };
            var arriveContextMessage = new ContextualString(thingToMove, destination)
            {
                ToOriginator = $"You move {dir} to {destination.Name}.",
                ToReceiver   = $"{thingToMove.Name} arrives, heading {dir}.",
                ToOthers     = $"{thingToMove.Name} arrives, heading {dir}.",
            };
            var leaveMessage  = new SensoryMessage(SensoryType.Sight, 100, leaveContextMessage);
            var arriveMessage = new SensoryMessage(SensoryType.Sight, 100, arriveContextMessage);

            return(movableBehavior.Move(destination, Parent, leaveMessage, arriveMessage));
        }
Exemplo n.º 11
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);
            }
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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 = @"$ActiveThing.Name says: " + this.sayText,
                ToOthers = @"$ActiveThing.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);
            }
        }
Exemplo n.º 14
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);
            }
        }
Exemplo n.º 15
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}>", actionInput.Tail);

            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);
            }
        }
Exemplo n.º 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)
        {
            // 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);
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>Open or close this behavior's parent, via the specified actor.</summary>
        /// <param name="actor">The actor doing the opening or closing.</param>
        /// <param name="verb">Whether this is an "open" or "close" action.</param>
        /// <param name="newOpenedState">The new IsOpen state to be set, if the request is not cancelled.</param>
        private void OpenOrClose(Thing actor, string verb, bool newOpenedState)
        {
            // If we're already in the desired opened/closed state, we're already done with state changes.
            if (newOpenedState == IsOpen)
            {
                // TODO: Message to the actor that it is already open/closed.
                return;
            }

            var thisThing = Parent;

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

            // Prepare the Close/Open 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 OpenCloseEvent(thisThing, newOpenedState, actor, message);

            // Broadcast the Open or Close Request and carry on if nothing cancelled it.
            // Broadcast from the parents of the openable/closable thing (IE the rooms an openable exit is attached to).
            thisThing.Eventing.OnMiscellaneousRequest(e, EventScope.ParentsDown);
            if (!e.IsCancelled)
            {
                // Open or Close the thing.
                IsOpen = newOpenedState;

                // Broadcast the Open or Close event.
                thisThing.Eventing.OnMiscellaneousEvent(e, EventScope.ParentsDown);
            }
        }
Exemplo n.º 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)
        {
            // Remove the item from the character's posession.
            // @@@ TODO: Test, this may be broken now... esp for numberToGive != max
            IController sender = actionInput.Controller;
            if (this.numberToGive > 0 && this.thing != null)
            {
                this.thing.RemoveFromParents();
            }

            var contextMessage = new ContextualString(sender.Thing, this.target)
            {
                ToOriginator = string.Format("You gave $Item.Name to {0}.", this.target),
                ToReceiver = "$ActiveThing.Name gave you $Item.Name.",
                ToOthers = string.Format("$ActiveThing.Name gave $Item.Name to {0}.", this.target),
            };
            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 (!this.movableBehavior.Move(this.target, sender.Thing, null, message))
            {
                sender.Write(string.Format("Failed to give {0} to {1}.", this.thing.Name, this.target.Name));
            }
        }
Exemplo n.º 19
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);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Choose sensory messaging based on whether or not the hit landed.
        /// </summary>
        /// <param name="attacker">The Thing performing the attack.</param>
        /// <param name="target">The Thing being attacked.</param>
        /// <param name="attackRoll">Die roll for the attack.</param>
        /// <param name="defendRoll">Die roll for the defense.</param>
        /// <param name="damage">Amount of damage to be inflicted if the attack is successful.</param>
        /// <returns>A SensoryMessage describing the successful or failed attack.</returns>
        private SensoryMessage CreateResultMessage(Thing attacker, Thing target, int attackRoll, int defendRoll, int damage)
        {
            ContextualString message;

            if (attackRoll > defendRoll)
            {
                message = new ContextualString(attacker, target)
                {
                    ToOriginator = @"You punch $ActiveThing.Name for $Damage health.",
                    ToReceiver = @"$Aggressor.Name punches you for $Damage health.",
                    ToOthers = @"$Aggressor.Name punches $ActiveThing.Name for $Damage health.",
                };
            }
            else
            {
                message = new ContextualString(attacker, target)
                {
                    ToOriginator = @"You attempt to punch $ActiveThing.Name, but miss.",
                    ToReceiver = @"$Aggressor.Name attempts to punch you, but misses.",
                    ToOthers = @"$Aggressor.Name attempts to punch $ActiveThing.Name, but misses.",
                };
            }

            var sm = new SensoryMessage(SensoryType.Sight, 100, message, new Hashtable { { "Damage", damage } });

            return sm;
        }
Exemplo n.º 21
0
        /// <summary>
        /// Moves the Thing through.
        /// </summary>
        /// <param name="thingToMove">The thing to move.</param>
        /// <returns>Returns true if the move was successful, false if not.</returns>
        public bool MoveThrough(Thing thingToMove)
        {
            // If the thing isn't currently mobile, bail.
            var movableBehavior = thingToMove.Behaviors.FindFirst<MovableBehavior>();
            if (movableBehavior == null)
            {
                // @@@ TODO: Add messaging to thingToMove?
                return false;
            }

            // Find the target location to be reached from here.
            DestinationInfo destinationInfo = this.GetDestinationFrom(thingToMove.Parent.ID);
            if (destinationInfo == null)
            {
                // There was no destination reachable from the thing's starting location.
                return false;
            }

            // If the target location hasn't been cached already, try to do so now.
            if (destinationInfo.CachedTarget == null || destinationInfo.CachedTarget.Target == null)
            {
                Thing newTarget = ThingManager.Instance.FindThing(destinationInfo.TargetID);
                destinationInfo.CachedTarget = new WeakReference<Thing>(newTarget);
            }

            // If the destination can't be found, abort.
            Thing destination = destinationInfo.CachedTarget.Target;
            if (destination == null)
            {
                // @@@ TODO: Add messaging to thingToMove?
                return false;
            }

            string dir = destinationInfo.ExitCommand;
            var leaveContextMessage = new ContextualString(thingToMove, thingToMove.Parent)
            {
                ToOriginator = null,
                ToReceiver = @"$ActiveThing.Name moves " + dir + ".",
                ToOthers = @"$ActiveThing.Name moves " + dir + ".",
            };
            var arriveContextMessage = new ContextualString(thingToMove, destination)
            {
                ToOriginator = @"You move " + dir + " to $GoingTo.Name.",
                ToReceiver = @"$ActiveThing.Name arrives, heading " + dir + ".",
                ToOthers = @"$ActiveThing.Name arrives, heading " + dir + ".",
            };
            var leaveMessage = new SensoryMessage(SensoryType.Sight, 100, leaveContextMessage);
            var arriveMessage = new SensoryMessage(SensoryType.Sight, 100, arriveContextMessage);

            return movableBehavior.Move(destination, this.Parent, leaveMessage, arriveMessage);
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 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)
        {
            // Contextual message text to be supplied based on the action below
            var response = new ContextualString(this.sender.Thing, this.room.Parent);

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

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

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

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

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

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

                //// HACK: Using sender.Write() for now to avoid the ViewEngine stripping newlines.
                this.sender.Write(output.ToString());

                // No need to raise event.
                return;
            }

            var message = new SensoryMessage(SensoryType.Sight, 100, response);
            var evt = new GameEvent(this.sender.Thing, message);
            this.sender.Thing.Eventing.OnMiscellaneousEvent(evt, EventScope.SelfDown);
        }