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