Beispiel #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)
        {
            // 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);
            }
        }
        /// <summary>Lock or unlock this behavior's parent, via the specified actor.</summary>
        /// <param name="actor">The actor doing the locking or unlocking.</param>
        /// <param name="verb">Whether this is an "lock" or "unlock" action.</param>
        /// <param name="newLockedState">The new IsLocked state to be set, if the request is not cancelled.</param>
        private void LockOrUnlock(Thing actor, string verb, bool newLockedState)
        {
            // If we're already in the desired locked/unlocked state, we're already done with state changes.
            if (newLockedState == this.IsLocked)
            {
                // @@@ TODO: Message to the actor that it is already locked/unlocked.
                return;
            }

            // Use a temporary ref to our own parent to avoid race conditions like sudden parent removal.
            var thisThing = this.Parent;

            if (newLockedState && thisThing != null)
            {
                // If we are attempting to lock an opened thing, cancel the lock attempt.
                var opensClosesBehavior = thisThing.Behaviors.FindFirst <OpensClosesBehavior>();
                if (opensClosesBehavior != null && opensClosesBehavior.IsOpen)
                {
                    // @@@ TODO: Message to the actor that they can't lock an open thing.
                    return;
                }
            }

            // Prepare the Lock/Unlock game event for sending as a request, and if not cancelled, again as an event.
            var csb = new ContextualStringBuilder(actor, this.Parent);

            csb.Append(@"You " + verb + " $TargetThing.Name.", ContextualStringUsage.OnlyWhenBeingPassedToOriginator);
            csb.Append(@"$ActiveThing.Name " + verb + "s you.", ContextualStringUsage.OnlyWhenBeingPassedToReceiver);
            csb.Append(@"$ActiveThing.Name " + verb + "s $TargetThing.Name.", ContextualStringUsage.WhenNotBeingPassedToReceiverOrOriginator);
            var message = new SensoryMessage(SensoryType.Sight, 100, csb);
            var e       = new LockUnlockEvent(this.Parent, false, actor, message);

            // Broadcast the Lock or Unlock Request and carry on if nothing cancelled it.
            if (thisThing != null)
            {
                // Broadcast from the parents of the lockable/unlockable thing (IE a room or inventory where the lockable resides).
                thisThing.Eventing.OnMiscellaneousRequest(e, EventScope.ParentsDown);
                if (!e.IsCancelled)
                {
                    // Lock or Unlock the thing.
                    this.IsLocked = newLockedState;

                    // Broadcast the Lock or Unlock event.
                    thisThing.Eventing.OnMiscellaneousEvent(e, EventScope.ParentsDown);
                }
            }
        }
Beispiel #3
0
        /// <summary>Build the glance command response.</summary>
        /// <param name="sender">The sender of the glance command.</param>
        /// <returns>A fully generated glance of the room.</returns>
        private ContextualStringBuilder BuildGlance(Thing sender)
        {
            // Just basic generation of a general room description until furniture is implemented.
            var glanceString      = new ContextualStringBuilder(sender, sender);
            var perceivedExits    = sensesBehavior.PerceiveExits();
            var perceivedEntities = sensesBehavior.PerceiveEntities();
            var perceivedItems    = sensesBehavior.PerceiveItems();

            glanceString.Append($"You are in <%red%>{sender.Parent.Name}<%n%>.  ", ContextualStringUsage.OnlyWhenBeingPassedToReceiver);

            if (perceivedItems.Count != 0)
            {
                if (perceivedEntities.Count != 0)
                {
                    glanceString.Append(
                        perceivedExits.Count != 0
                            ? "There are various items, figures, and exits here."
                            : "There are various items, and figures here.",
                        ContextualStringUsage.OnlyWhenBeingPassedToReceiver);
                }
                else
                {
                    glanceString.Append(
                        perceivedExits.Count != 0
                            ? "There are various items, and exits here."
                            : "There are various items here.", ContextualStringUsage.OnlyWhenBeingPassedToReceiver);
                }
            }
            else
            {
                if (perceivedEntities.Count != 0)
                {
                    glanceString.Append(
                        perceivedExits.Count != 0
                            ? "There are various figures, and exits here."
                            : "There are various figures here.", ContextualStringUsage.OnlyWhenBeingPassedToReceiver);
                }
                else
                {
                    glanceString.Append(
                        perceivedExits.Count != 0 ? "There are various exits here." : "You don't see anything here.",
                        ContextualStringUsage.OnlyWhenBeingPassedToReceiver);
                }
            }

            return(glanceString);
        }
Beispiel #4
0
        /// <summary>
        /// @@@ DESCRIBE
        /// </summary>
        /// <param name="sender">The sender of the glance command.</param>
        /// <returns>A fully generated glance of the room.</returns>
        private ContextualStringBuilder BuildGlance(Thing sender)
        {
            // Just basic generation of a general room description until furniture is implemented.
            var glanceString      = new ContextualStringBuilder(sender, sender);
            var perceivedExits    = this.sensesBehavior.PerceiveExits();
            var perceivedEntities = this.sensesBehavior.PerceiveEntities();
            var perceivedItems    = this.sensesBehavior.PerceiveItems();

            glanceString.Append("You seem to be in a " + sender.Parent.Name + ".  ", ContextualStringUsage.OnlyWhenBeingPassedToReceiver);

            if (perceivedItems.Count != 0)
            {
                if (perceivedEntities.Count != 0)
                {
                    if (perceivedExits.Count != 0)
                    {
                        glanceString.Append("It appears there are various items, figures, and exits in this room.", ContextualStringUsage.OnlyWhenBeingPassedToReceiver);
                    }
                    else
                    {
                        glanceString.Append("It appears there are various items, and figures in this room.", ContextualStringUsage.OnlyWhenBeingPassedToReceiver);
                    }
                }
                else
                {
                    if (perceivedExits.Count != 0)
                    {
                        glanceString.Append("It appears there are various items, and exits in this room.", ContextualStringUsage.OnlyWhenBeingPassedToReceiver);
                    }
                    else
                    {
                        glanceString.Append("It appears there are various items in this room.", ContextualStringUsage.OnlyWhenBeingPassedToReceiver);
                    }
                }
            }
            else
            {
                if (perceivedEntities.Count != 0)
                {
                    if (perceivedExits.Count != 0)
                    {
                        glanceString.Append("It appears there are various figures, and exits in this room.", ContextualStringUsage.OnlyWhenBeingPassedToReceiver);
                    }
                    else
                    {
                        glanceString.Append("It appears there are various figures in this room.", ContextualStringUsage.OnlyWhenBeingPassedToReceiver);
                    }
                }
                else
                {
                    if (perceivedExits.Count != 0)
                    {
                        glanceString.Append("It appears there are various exits in this room.", ContextualStringUsage.OnlyWhenBeingPassedToReceiver);
                    }
                    else
                    {
                        glanceString.Append("You don't see anything in the room.", ContextualStringUsage.OnlyWhenBeingPassedToReceiver);
                    }
                }
            }

            return(glanceString);
        }