Exemplo n.º 1
0
        /// <summary>
        /// <para>Applies the effect to its host.</para>
        /// <para>
        /// Preconditions: this.Parent.Attributes must not be null if this.Parent is not null.
        /// </para>
        /// </summary>
        public override void OnAddBehavior()
        {
            // Create and broadcast the event notifying players that the effect was applied.
            var addEvent = new EffectEvent(this.ActiveThing, this.Parent, this.SensoryMessage);
            this.ActiveThing.Eventing.OnCommunicationRequest(addEvent, EventScope.ParentsDown);
            if (!addEvent.IsCancelled)
            {
                this.ActiveThing.Eventing.OnCommunicationEvent(addEvent, EventScope.ParentsDown);
            }

            // Create and schedule an event that tells TimeSystem to call Expire()
            // after EndTime is reached.
            this.RemoveStatEvent = new TimeEvent(this.ActiveThing, this.Expire, this.EndTime, this.ExpirationMessage);
            TimeSystem.Instance.ScheduleEvent(this.RemoveStatEvent);

            base.OnAddBehavior();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called when a parent has just been assigned to this behavior.
        /// This method first creates and broadcasts an event notifying users that
        /// the mute effect was applied. Then it creates another event that holds
        /// the Unmute method, and adds it to the TimeSystem scheduler to call
        /// after the duration time has passed.
        /// </summary>
        public override void OnAddBehavior()
        {
            // While this effect is attached to its parent, it denies all verbal communications from it.
            this.Interceptor = new CancellableGameEventHandler(this.DenyCommunicationRequest);
            this.Parent.Eventing.CommunicationRequest += this.Interceptor;

            // Create event and broadcast it to let the affected parties know the effect was applied.
            var muteEvent = new EffectEvent(this.ActiveThing, this.Parent, this.SensoryMessage);
            this.ActiveThing.Eventing.OnCommunicationRequest(muteEvent, EventScope.ParentsDown);
            if (!muteEvent.IsCancelled)
            {
                this.ActiveThing.Eventing.OnCommunicationEvent(muteEvent, EventScope.ParentsDown);
            }

            // Create an event to be broadcast when the mute effect expires,
            // and schedule it with the TimeSystem.
            this.UnmuteEvent = new TimeEvent(this.ActiveThing, this.Unmute, this.EndTime, this.ExpirationMessage);
            TimeSystem.Instance.ScheduleEvent(this.UnmuteEvent);

            base.OnAddBehavior();
        }