/// <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); } }
/// <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); } }