Exemple #1
0
        /// <summary>Checks against the guards for the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        /// <returns>A string with the error message for the user upon guard failure, else null.</returns>
        public override string Guards(ActionInput actionInput)
        {
            IController sender = actionInput.Controller;
            Thing wielder = sender.Thing;
            Thing room = wielder.Parent;

            string commonFailure = VerifyCommonGuards(actionInput, ActionGuards);
            if (commonFailure != null)
            {
                return commonFailure;
            }

            string itemName = actionInput.Tail.Trim().ToLower();

            // First look for a matching item in inventory and make sure it can
            // be wielded. If nothing was found in inventory, look for a matching
            // wieldable item in the surrounding environment.
            this.itemToUnwield = wielder.FindChild(item => item.Name.ToLower() == itemName && item.HasBehavior<WieldableBehavior>() && item.Behaviors.FindFirst<WieldableBehavior>().Wielder == sender.Thing);

            if (this.itemToUnwield == null)
            {
                this.itemToUnwield = wielder.Parent.FindChild(item => item.Name.ToLower() == itemName && item.HasBehavior<WieldableBehavior>() && item.Behaviors.FindFirst<WieldableBehavior>().Wielder == sender.Thing);
            }

            if (this.itemToUnwield == null)
            {
                return "You are not wielding the " + itemName + ".";
            }

            this.itemToUnwieldBehavior = this.itemToUnwield.Behaviors.FindFirst<WieldableBehavior>();

            return null;
        }
Exemple #2
0
        /// <summary>Checks against the guards for the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        /// <returns>A string with the error message for the user upon guard failure, else null.</returns>
        public override string Guards(ActionInput actionInput)
        {
            string commonFailure = VerifyCommonGuards(actionInput, ActionGuards);
            if (commonFailure != null)
            {
                return commonFailure;
            }

            IController sender = actionInput.Controller;
            Thing wielder = sender.Thing;
            Thing room = wielder.Parent;

            string itemName = actionInput.Tail.Trim().ToLower();

            // First look for a matching item in inventory and make sure it can
            // be wielded. If nothing was found in inventory, look for a matching
            // wieldable item in the surrounding environment.
            Thing itemInInventory = wielder.FindChild(itemName);

            if (itemInInventory != null)
            {
                this.itemToWieldBehavior = itemInInventory.Behaviors.FindFirst<WieldableBehavior>();

                // Item was found in inventory, but it cannot be wielded.
                if (this.itemToWieldBehavior == null)
                {
                    return "This item cannot be wielded!";
                }

                this.itemToWield = itemInInventory;
            }
            else
            {
                Thing itemInRoom = room.FindChild(itemName);

                // Item was not found in inventory or the room.
                if (itemInRoom == null)
                {
                    return "Unable to find: " + itemName;
                }

                this.itemToWieldBehavior = itemInRoom.Behaviors.FindFirst<WieldableBehavior>();

                // Item was found in the room, but it cannot be wielded.
                if (this.itemToWieldBehavior == null)
                {
                    return "This item cannot be wielded!";
                }

                // Item was found in the room, but it must be picked up first.
                if (this.itemToWieldBehavior.MustBeHeld)
                {
                    return "You are not holding the " + itemInRoom.FullName + ".";
                }

                this.itemToWield = itemInRoom;
            }

            // Make sure the item is not already wielded by someone else.
            // This shouldn't happen (famous last words) if the item is in
            // inventory, but it could happen with stationary wieldable items
            // in the room.
            if (this.itemToWieldBehavior.Wielder != null)
            {
                return string.Format("The {0} is already wielded by {1}.", this.itemToWield.Name, this.itemToWieldBehavior.Wielder.FullName);
            }

            return null;
        }