/// <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); } }
/// <summary>Called when a parent has just been assigned to this behavior.</summary> /// <remarks> /// 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. /// </remarks> protected override void OnAddBehavior() { // While this effect is attached to its parent, it denies all verbal communications from it. Interceptor = new CancellableGameEventHandler(DenyCommunicationRequest); Parent.Eventing.CommunicationRequest += Interceptor; // Create event and broadcast it to let the affected parties know the effect was applied. var muteEvent = new EffectEvent(ActiveThing, Parent, SensoryMessage); ActiveThing.Eventing.OnCommunicationRequest(muteEvent, EventScope.ParentsDown); if (!muteEvent.IsCancelled) { ActiveThing.Eventing.OnCommunicationEvent(muteEvent, EventScope.ParentsDown); } // Create an event to be broadcast when the mute effect expires, // and schedule it with the TimeSystem. UnmuteEvent = new TimeEvent(ActiveThing, Unmute, EndTime, ExpirationMessage); TimeSystem.Instance.ScheduleEvent(UnmuteEvent); base.OnAddBehavior(); }