Example #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;

            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);
            }
        }
Example #2
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);
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the StatChangeEvent class.
 /// </summary>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="senseMessage">The sensory message.</param>
 /// <param name="stat">The applicable stat.</param>
 /// <param name="modifier">The stat modifier.</param>
 /// <param name="oldValue">The old stat value.</param>
 public StatChangeEvent(Thing activeThing, SensoryMessage senseMessage, BaseStat stat, int modifier, int oldValue)
     : base(activeThing, senseMessage)
 {
     this.Stat = stat;
     this.OldValue = oldValue;
     this.Modifier = modifier;
 }
Example #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)
        {
            var actor = actionInput.Actor;

            itemToUnwieldBehavior.Wielder = null;

            // Remove the event handler that prevents dropping the item while wielded.
            var interceptor = itemToUnwieldBehavior.MovementInterceptor;

            itemToUnwield.Eventing.MovementRequest -= interceptor;

            var contextMessage = new ContextualString(actor, itemToUnwield.Parent)
            {
                ToOriginator = $"You unwield {itemToUnwield.Name}.",
                ToOthers     = $"{actor.Name} unwields {itemToUnwield.Name}.",
            };
            var sensoryMessage = new SensoryMessage(SensoryType.Sight, 100, contextMessage);

            var unwieldEvent = new WieldUnwieldEvent(itemToUnwield, true, actor, sensoryMessage);

            actor.Eventing.OnCombatRequest(unwieldEvent, EventScope.ParentsDown);

            if (!unwieldEvent.IsCancelled)
            {
                actor.Eventing.OnCombatEvent(unwieldEvent, EventScope.ParentsDown);
            }
        }
Example #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)
        {
            var contextMessage = new ContextualString(actionInput.Actor, target)
            {
                ToOriginator = $"You cast ThunderClap at {target.Name}!",
                ToReceiver = $"{actionInput.Actor.Name} casts ThunderClap at you. You only hear a ringing in your ears now.",
                ToOthers = $"You hear {actionInput.Actor.Name} cast ThunderClap at {target.Name}! It was very loud.",
            };
            var sm = new SensoryMessage(SensoryType.Hearing, 100, contextMessage);

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

                target.Behaviors.Add(deafenEffect);
                actionInput.Actor.Eventing.OnCombatEvent(attackEvent, EventScope.ParentsDown);
            }
        }
Example #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)
        {
            // Generate an item changed owner event.
            IController             sender = actionInput.Controller;
            ContextualStringBuilder csb    = new ContextualStringBuilder(sender.Thing, this.parent);

            csb.Append(@"$ActiveThing.Name drops $Thing.Name.", ContextualStringUsage.WhenNotBeingPassedToOriginator);
            csb.Append(@"You drop $Thing.Name.", ContextualStringUsage.OnlyWhenBeingPassedToOriginator);
            SensoryMessage message          = new SensoryMessage(SensoryType.Sight, 100, csb);
            var            changeOwnerEvent = new ChangeOwnerEvent(sender.Thing, message, sender.Thing, this.parent, this.thing);

            // Broadcast as a request and see if anything wants to prevent the event.
            this.parent.Eventing.OnMovementRequest(changeOwnerEvent, EventScope.ParentsDown);
            if (!changeOwnerEvent.IsCancelled)
            {
                // Always have to remove an item before adding it because of the event observer system.
                // @@@ TODO: Test, this may be broken now...
                this.thing.Parent.Remove(this.thing);
                this.parent.Add(this.thing);

                //// @@@ BUG: Saving currently throws a NotImplementedException. Disabled for now...
                this.thing.Save();
                this.parent.Save();

                // Broadcast the event.
                this.parent.Eventing.OnMovementEvent(changeOwnerEvent, EventScope.ParentsDown);
            }
        }
Example #7
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 session = actionInput.Session;

            if (session == null)
            {
                return;                  // This action only makes sense for player sessions.
            }
            // 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)
            {
                session.WriteLine("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
                {
                    session.WriteLine("Target is not a room and is not in a room!");
                    return;
                }
            }

            var adminName           = actionInput.Actor.Name;
            var leaveContextMessage = new ContextualString(actionInput.Actor, actionInput.Actor.Parent)
            {
                ToOriginator = null,
                ToReceiver   = $"{adminName} disappears into nothingness.",
                ToOthers     = $"{adminName} disappears into nothingness.",
            };
            var arriveContextMessage = new ContextualString(actionInput.Actor, 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.Actor.FindBehavior <MovableBehavior>();

            if (movableBehavior != null && movableBehavior.Move(targetPlace, actionInput.Actor, leaveMessage, arriveMessage))
            {
                CommandManager.Instance.EnqueueAction(new ActionInput("look", actionInput.Session, actionInput.Actor));
            }
        }
Example #8
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 (!(actionInput.Controller is Session session))
            {
                return;
            }

            // Strings to be displayed when the effect is applied/removed.
            var muteString = new ContextualString(actionInput.Controller.Thing, playerToMute)
            {
                ToOriginator = $"You mute {playerToMute.Name} for duration {muteDuration}.",
                ToReceiver   = "You are now mute. Please reflect on recent choices."
            };
            var unmuteString = new ContextualString(actionInput.Controller.Thing, 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.Controller.Thing, muteDuration, muteMessage, unmuteMessage);

            // Apply the effect.
            playerToMute.Behaviors.Add(muteEffect);
        }
Example #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)
        {
            // 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 = $"You gave {this.thing.Name} to {this.target}.",
                ToReceiver   = $"{sender.Thing.Name} gave you {this.thing.Name}.",
                ToOthers     = $"{sender.Thing.Name} gave {this.thing.Name} to {this.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 (!this.movableBehavior.Move(this.target, sender.Thing, null, message))
            {
                sender.Write($"Failed to give {this.thing.Name} to {this.target.Name}.");
            }
        }
Example #10
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);
        }
Example #11
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 (sourceContainer == null || sourceContainer.Count <= 0 || destinationParent == null)
            {
                return;
            }

            // Dump each child out of the targeted container.
            var movedThingNames = (from thing in sourceContainer.Children
                                   let movableBehavior = thing.FindBehavior <MovableBehavior>()
                                                         where movableBehavior != null
                                                         where movableBehavior.Move(destinationParent, actionInput.Actor, null, null)
                                                         select thing.Name).ToList();

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

            var bulkMovementEvent = new BulkMovementEvent(actionInput.Actor, message);

            actionInput.Actor.Eventing.OnMovementEvent(bulkMovementEvent, EventScope.ParentsDown);
        }
Example #12
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);
            }
        }
Example #13
0
 /// <summary>Initializes a new instance of the <see cref="EnterEvent"/> class.</summary>
 /// <param name="thingEntered">The thing entered.</param>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="sensoryMessage">The sensory message.</param>
 /// <param name="startLocation">The start location.</param>
 /// <param name="endLocation">The end location.</param>
 public EnterEvent(Thing thingEntered, Thing activeThing, SensoryMessage sensoryMessage, Thing startLocation, Thing endLocation)
     : base(activeThing, sensoryMessage)
 {
     ThingEntered  = thingEntered;
     StartLocation = startLocation;
     EndLocation   = endLocation;
 }
Example #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)
        {
            // Remove the item from its current container.
            // We have to do this before we attempt to add it because of the event subscriptions.
            // TODO: Test, this may be broken now...
            var actor = actionInput.Controller.Thing;

            if (numberToGet <= 0)
            {
                numberToGet = 1;
            }

            // TODO: Prevent item duplication from specifying large numbers, or races for same item, etc.
            // TODO: Fix Implementation of numberToGet.
            var contextMessage = new ContextualString(actor, thingToGet.Parent)
            {
                ToOriginator = $"You pick up {thingToGet}.",
                ToReceiver   = $"{actor.Name} takes {thingToGet} from you.",
                ToOthers     = $"{actor.Name} picks up {thingToGet.Name}.",
            };
            var getMessage = new SensoryMessage(SensoryType.Sight, 100, contextMessage);

            if (movableBehavior.Move(actor, actor, getMessage, null))
            {
                // TODO: Transactionally move owners if applicable.
                //actor.Save();
                //actor.Parent.Save();
            }
        }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WieldUnwieldEvent"/> class.
 /// </summary>
 /// <param name="wieldedItem">The thing being affected by this event.</param>
 /// <param name="isBeingWielded">Whether the thing is being wielded (true) or unwielded (false).</param>
 /// <param name="activeThing">The actor causing the event (if applicable).</param>
 /// <param name="sensoryMessage">The message to display to those who can perceive the change.</param>
 public WieldUnwieldEvent(Thing wieldedItem, bool isBeingWielded, Thing activeThing, SensoryMessage sensoryMessage)
     : base(activeThing, sensoryMessage)
 {
     this.WieldedItem = wieldedItem;
     this.IsBeingWielded = isBeingWielded;
     sensoryMessage.Context.Add("WieldedItem", this.WieldedItem);
 }
Example #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EnterEvent"/> class.
 /// </summary>
 /// <param name="thingEntered">The thing entered.</param>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="sensoryMessage">The sensory message.</param>
 /// <param name="startLocation">The start location.</param>
 /// <param name="endLocation">The end location.</param>
 public EnterEvent(Thing thingEntered, Thing activeThing, SensoryMessage sensoryMessage, Thing startLocation, Thing endLocation)
     : base(activeThing, sensoryMessage)
 {
     this.ThingEntered = thingEntered;
     this.StartLocation = startLocation;
     this.EndLocation = endLocation;
 }
Example #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)
        {
            // Remove the item from its current container.
            // We have to do this before we attempt to add it because of the event subscriptions.
            // @@@ TODO: Test, this may be broken now...
            IController sender = actionInput.Controller;

            if (this.numberToGet <= 0)
            {
                this.numberToGet = 1;
            }

            // @@@ TODO: Prevent item duplication from specifying large numbers, or races for same item, etc.
            // @@@ TODO: Fix Implementation of numberToGet
            var contextMessage = new ContextualString(sender.Thing, this.thingToGet.Parent)
            {
                ToOriginator = "You pick up $Thing.Name.",
                ToReceiver   = "$ActiveThing.Name takes $Thing.Name from you.",
                ToOthers     = "$ActiveThing.Name picks up $Thing.Name.",
            };
            var getMessage = new SensoryMessage(SensoryType.Sight, 100, contextMessage);

            var getEvent = new ChangeOwnerEvent(
                sender.Thing,
                getMessage,
                this.thingToGet.Parent,
                sender.Thing,
                this.thingToGet);

            this.movableBehavior.Move(sender.Thing, sender.Thing, getMessage, null);
        }
Example #18
0
 /// <summary>Initializes a new instance of the StatChangeEvent class.</summary>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="senseMessage">The sensory message.</param>
 /// <param name="stat">The applicable stat.</param>
 /// <param name="modifier">The stat modifier.</param>
 /// <param name="oldValue">The old stat value.</param>
 public StatChangeEvent(Thing activeThing, SensoryMessage senseMessage, BaseStat stat, int modifier, int oldValue)
     : base(activeThing, senseMessage)
 {
     Stat     = stat;
     OldValue = oldValue;
     Modifier = modifier;
 }
Example #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)
        {
            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);
            }
        }
Example #20
0
 /// <summary>Initializes a new instance of the <see cref="FollowEvent"/> class.</summary>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="senseMessage">The sense message.</param>
 /// <param name="follower">The follower.</param>
 /// <param name="target">The target.</param>
 public FollowEvent(Thing activeThing, SensoryMessage senseMessage, Thing follower, Thing target)
     : base(activeThing, senseMessage)
 {
     this.Follower = follower;
     this.Target   = target;
     senseMessage.Context.Add("Follower", this.Follower);
     senseMessage.Context.Add("Target", this.Target);
 }
Example #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnfollowEvent"/> class.
 /// </summary>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="senseMessage">The sense message.</param>
 /// <param name="follower">The follower.</param>
 /// <param name="target">The target.</param>
 public UnfollowEvent(Thing activeThing, SensoryMessage senseMessage, Thing follower, Thing target)
     : base(activeThing, senseMessage)
 {
     this.Follower = follower;
     this.Target = target;
     senseMessage.Context.Add("Follower", this.Follower);
     senseMessage.Context.Add("Target", this.Target);
 }
Example #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VerbalCommunicationEvent"/> class.
 /// </summary>
 /// <param name="activeThing">The thing that is communicating.</param>
 /// <param name="sensoryMessage">The sensory message describing the communication to those who can perceive it.</param>
 /// <param name="communicationType">Type of the communication.</param>
 public VerbalCommunicationEvent(
     Thing activeThing,
     SensoryMessage sensoryMessage,
     VerbalCommunicationType communicationType)
     : base(activeThing, sensoryMessage)
 {
     this.CommunicationType = communicationType;
 }
Example #23
0
 /// <summary>Initializes a new instance of the <see cref="VerbalCommunicationEvent"/> class.</summary>
 /// <param name="activeThing">The thing that is communicating.</param>
 /// <param name="sensoryMessage">The sensory message describing the communication to those who can perceive it.</param>
 /// <param name="communicationType">Type of the communication.</param>
 public VerbalCommunicationEvent(
     Thing activeThing,
     SensoryMessage sensoryMessage,
     VerbalCommunicationType communicationType)
     : base(activeThing, sensoryMessage)
 {
     this.CommunicationType = communicationType;
 }
Example #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)
        {
            // Simply send a sensory event to the glancer; If they can see it, they'll get the output.
            var actor        = actionInput.Actor;
            var message      = new SensoryMessage(SensoryType.Sight, 100, BuildGlance(actor));
            var sensoryEvent = new SensoryEvent(actor, message);

            actor.Eventing.OnMiscellaneousEvent(sensoryEvent, EventScope.SelfOnly);
        }
Example #25
0
 /// <summary>Initializes a new instance of the <see cref="MutedEffect" /> class.</summary>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="duration">The duration.</param>
 /// <param name="sensoryMessage">The sensory message.</param>
 /// <param name="expirationMessage">The expiration message.</param>
 public MutedEffect(Thing activeThing, TimeSpan duration, SensoryMessage sensoryMessage, SensoryMessage expirationMessage)
     : base(duration)
 {
     this.Name              = "Mute";
     this.ActiveThing       = activeThing;
     this.SensoryMessage    = sensoryMessage;
     this.ExpirationMessage = expirationMessage;
     this.Duration          = duration;
 }
Example #26
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            // Simply send a sensory event to the glancer; If they can see it, they'll get the output.
            var sender       = actionInput.Controller;
            var message      = new SensoryMessage(SensoryType.Sight, 100, this.BuildGlance(sender.Thing));
            var sensoryEvent = new SensoryEvent(sender.Thing, message);

            sender.Thing.Eventing.OnMiscellaneousEvent(sensoryEvent, EventScope.SelfOnly);
        }
Example #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EffectEvent"/> class.
 /// </summary>
 /// <param name="activeThing">The thing that initiated the event.</param>
 /// <param name="target">The the target of the event.</param>
 /// <param name="sensoryMessage">The sensory message.</param>
 public EffectEvent(Thing activeThing, Thing target, SensoryMessage sensoryMessage)
     : base(activeThing, sensoryMessage)
 {
     this.Target = target;
     if (sensoryMessage != null)
     {
         sensoryMessage.Context.Add("Target", this.Target);
     }
 }
Example #28
0
 /// <summary>Initializes a new instance of the <see cref="MutedEffect" /> class.</summary>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="duration">The duration.</param>
 /// <param name="sensoryMessage">The sensory message.</param>
 /// <param name="expirationMessage">The expiration message.</param>
 public MutedEffect(Thing activeThing, TimeSpan duration, SensoryMessage sensoryMessage, SensoryMessage expirationMessage)
     : base(duration)
 {
     Name              = "Mute";
     ActiveThing       = activeThing;
     SensoryMessage    = sensoryMessage;
     ExpirationMessage = expirationMessage;
     Duration          = duration;
 }
Example #29
0
 /// <summary>Initializes a new instance of the <see cref="EffectEvent"/> class.</summary>
 /// <param name="activeThing">The thing that initiated the event.</param>
 /// <param name="target">The the target of the event.</param>
 /// <param name="sensoryMessage">The sensory message.</param>
 public EffectEvent(Thing activeThing, Thing target, SensoryMessage sensoryMessage)
     : base(activeThing, sensoryMessage)
 {
     this.Target = target;
     if (sensoryMessage != null)
     {
         sensoryMessage.Context.Add("Target", this.Target);
     }
 }
Example #30
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);
        }
Example #31
0
 /// <summary>
 /// Initializes a new instance of the ChangeOwnerEvent class.
 /// </summary>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="senseMessage">The sensory message.</param>
 /// <param name="oldOwner">The old owner of the item.</param>
 /// <param name="newOwner">The new owner of the item.</param>
 /// <param name="thing">The item which changed owners.</param>
 public ChangeOwnerEvent(Thing activeThing, SensoryMessage senseMessage, Thing oldOwner, Thing newOwner, Thing thing)
     : base(activeThing, senseMessage)
 {
     this.OldOwner = oldOwner;
     this.NewOwner = newOwner;
     this.Thing    = thing;
     senseMessage.Context.Add("Thing", this.Thing);
     senseMessage.Context.Add("OldOwner", this.OldOwner);
     senseMessage.Context.Add("NewOwner", this.NewOwner);
 }
Example #32
0
 /// <summary>
 /// Initializes a new instance of the ChangeOwnerEvent class.
 /// </summary>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="senseMessage">The sensory message.</param>
 /// <param name="oldOwner">The old owner of the item.</param>
 /// <param name="newOwner">The new owner of the item.</param>
 /// <param name="thing">The item which changed owners.</param>
 public ChangeOwnerEvent(Thing activeThing, SensoryMessage senseMessage, Thing oldOwner, Thing newOwner, Thing thing)
     : base(activeThing, senseMessage)
 {
     this.OldOwner = oldOwner;
     this.NewOwner = newOwner;
     this.Thing = thing;
     senseMessage.Context.Add("Thing", this.Thing);
     senseMessage.Context.Add("OldOwner", this.OldOwner);
     senseMessage.Context.Add("NewOwner", this.NewOwner);
 }
Example #33
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(actionInput.Controller.Thing, room.Parent);

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

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

                    response.ToOriginator = $"Visual '{visualName}' removed from room {roomName} [{roomId}]";
                }

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

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

                    foreach (var name in room.Visuals.Keys)
                    {
                        output.AppendLine($"  {name}: {room.Visuals[name]}");
                    }
                }
                else
                {
                    output.AppendLine($"No visuals found for {roomName} [{roomId}].");
                }

                actionInput.Controller.Write(output);

                // No need to raise event.
                return;
            }

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

            actionInput.Controller.Thing.Eventing.OnMiscellaneousEvent(evt, EventScope.SelfDown);
        }
Example #34
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);
            }
        }
Example #35
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);
        }
Example #36
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);
        }
Example #37
0
 /// <summary>Initializes a new instance of the <see cref="StatEffect" /> class.</summary>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="stat">The stat.</param>
 /// <param name="valueMod">The modification to the stat's value.</param>
 /// <param name="minimumMod">The modification to the stat's minimum.</param>
 /// <param name="maximumMod">The modification to the stat's maximum.</param>
 /// <param name="duration">The duration of the effect.</param>
 /// <param name="sensoryMessage">The sensory message.</param>
 /// <param name="expirationMessage">The expiration message.</param>
 public StatEffect(Thing activeThing, GameStat stat, int valueMod, int minimumMod, int maximumMod, TimeSpan duration, SensoryMessage sensoryMessage, SensoryMessage expirationMessage)
     : base(duration)
 {
     Name              = stat.Name;
     Stat              = stat;
     ValueMod          = valueMod;
     MinimumMod        = minimumMod;
     MaximumMod        = maximumMod;
     ActiveThing       = activeThing;
     SensoryMessage    = sensoryMessage;
     ExpirationMessage = expirationMessage;
     Duration          = duration;
 }
Example #38
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MovementEvent"/> class.
 /// </summary>
 /// <param name="thingMoving">The thing moving.</param>
 /// <param name="goingFrom">The original location of the moving thing.</param>
 /// <param name="goingTo">The location where the thing is going.</param>
 /// <param name="goingVia">The thing (typically an exit) through which the movement occurs.</param>
 /// <param name="sensoryMessage">The sensory message describing the movement.</param>
 public MovementEvent(Thing thingMoving, Thing goingFrom, Thing goingTo, Thing goingVia, SensoryMessage sensoryMessage)
     : base(thingMoving, sensoryMessage)
 {
     this.GoingFrom = goingFrom;
     this.GoingTo = goingTo;
     this.GoingVia = goingVia;
     if (sensoryMessage != null)
     {
         sensoryMessage.Context.Add("GoingFrom", this.GoingFrom);
         sensoryMessage.Context.Add("GoingTo", this.GoingTo);
         sensoryMessage.Context.Add("GoingVia", this.GoingVia);
     }
 }
Example #39
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LeaveEvent"/> class.
 /// </summary>
 /// <param name="thingMoving">The thing moving.</param>
 /// <param name="goingFrom">The original location of the moving thing.</param>
 /// <param name="goingTo">The location where the thing is going.</param>
 /// <param name="goingVia">The thing (typically an exit) through which the movement occurs.</param>
 /// <param name="sensoryMessage">The sensory message describing the movement.</param>
 public LeaveEvent(Thing thingMoving, Thing goingFrom, Thing goingTo, Thing goingVia, SensoryMessage sensoryMessage)
     : base(thingMoving, goingFrom, goingTo, goingVia, sensoryMessage)
 {
 }
Example #40
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BulkMovementEvent"/> class.
 /// </summary>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="sensoryMessage">The sensory message.</param>
 public BulkMovementEvent(Thing activeThing, SensoryMessage sensoryMessage)
     : base(activeThing, sensoryMessage)
 {
 }
Example #41
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TimeEvent" /> class.
 /// </summary>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="callback">The callback.</param>
 /// <param name="endTime">The end time.</param>
 /// <param name="sensoryMessage">The sensory message.</param>
 public TimeEvent(Thing activeThing, Action callback, DateTime endTime, SensoryMessage sensoryMessage)
     : base(activeThing, sensoryMessage)
 {
     this.Callback = callback;
     this.EndTime = endTime;
 }
Example #42
0
 /// <summary>
 /// Initializes a new instance of the AttackEvent class.
 /// </summary>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="senseMessage">The sensory message.</param>
 /// <param name="aggressor">The aggressor of the attack.</param>
 public AttackEvent(Thing activeThing, SensoryMessage senseMessage, Thing aggressor)
     : base(activeThing, senseMessage)
 {
     this.Aggressor = aggressor;
     senseMessage.Context.Add("Aggressor", aggressor);
 }
Example #43
0
 /// <summary>
 /// Initializes a new instance of the SensoryEvent class.
 /// </summary>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="senseMessage">The sensory message.</param>
 public SensoryEvent(Thing activeThing, SensoryMessage senseMessage)
     : base(activeThing, senseMessage)
 {
 }
Example #44
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CancellableGameEvent"/> class.
 /// </summary>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="sensoryMessage">The sensory message.</param>
 public CancellableGameEvent(Thing activeThing, SensoryMessage sensoryMessage)
     : base(activeThing, sensoryMessage)
 {
 }
Example #45
0
        /// <summary>
        /// Initializes a new instance of the GameEvent class.
        /// </summary>
        /// <param name="activeThing">The active thing.</param>
        /// <param name="sensoryMessage">The sensory message.</param>
        public GameEvent(Thing activeThing, SensoryMessage sensoryMessage)
        {
            this.ActiveThing = activeThing;
            if (sensoryMessage != null)
            {
                this.SensoryMessage = sensoryMessage;

                // TODO: This if-condition was added to deal with some cases where
                // two ActiveThings are attempted for one action, e.g. "get".
                // Should multiple ActiveThings be supported instead, or maybe
                // there's a way to prevent this scenario?
                if (!this.SensoryMessage.Context.ContainsKey("ActiveThing"))
                {
                    this.SensoryMessage.Context.Add("ActiveThing", this.ActiveThing);
                }

                this.SensoryMessage.Context.Add(this.GetType().Name, this);
            }
        }
 /// <summary>
 /// Initializes a new instance of the PlayerLogOutEvent class.
 /// </summary>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="senseMessage">The sensory message.</param>
 public PlayerLogOutEvent(Thing activeThing, SensoryMessage senseMessage)
     : base(activeThing, senseMessage)
 {
 }
Example #47
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LockUnlockEvent"/> class.
 /// </summary>
 /// <param name="target">The thing being affected by this event.</param>
 /// <param name="isBeingLocked">Whether the thing is being locked (true) or unlocked (false).</param>
 /// <param name="activeThing">The actor causing the event (if applicable).</param>
 /// <param name="sensoryMessage">The message to display to those who can perceive the change.</param>
 public LockUnlockEvent(Thing target, bool isBeingLocked, Thing activeThing, SensoryMessage sensoryMessage)
     : base(activeThing, sensoryMessage)
 {
     this.Target = target;
     this.IsBeingLocked = isBeingLocked;
 }
Example #48
0
 /// <summary>
 /// Initializes a new instance of the DeathEvent class.
 /// </summary>
 /// <param name="activeThing">The active thing.</param>
 /// <param name="senseMessage">The sensory message.</param>
 /// <param name="killer">The thing that caused the death.</param>
 public DeathEvent(Thing activeThing, SensoryMessage senseMessage, Thing killer)
     : base(activeThing, senseMessage)
 {
     this.Killer = killer;
 }
Example #49
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EffectEvent"/> class.
 /// </summary>
 /// <param name="activeThing">The thing that initiated the event.</param>
 /// <param name="sensoryMessage">The sensory message.</param>
 public EffectEvent(Thing activeThing, SensoryMessage sensoryMessage)
     : base(activeThing, sensoryMessage)
 {
 }