示例#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;
            string      commonFailure = this.VerifyCommonGuards(actionInput, ActionGuards);

            if (commonFailure != null)
            {
                return(commonFailure);
            }

            // Rule: Do we have an item matching in our inventory?
            // TODO: Support drinking from, for instance, a fountain sitting in the room.
            string itemIdentifier = actionInput.Tail.Trim();

            this.thingToDrink = sender.Thing.FindChild(itemIdentifier.ToLower());
            if (this.thingToDrink == null)
            {
                return("You do not hold " + actionInput.Tail.Trim() + ".");
            }

            // Rule: Is the item drinkable?
            this.drinkableBehavior = this.thingToDrink.Behaviors.FindFirst <DrinkableBehavior>();
            if (this.drinkableBehavior == null)
            {
                return(itemIdentifier + " is not drinkable");
            }

            return(null);
        }
示例#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)
        {
            var actor         = actionInput.Actor;
            var commonFailure = VerifyCommonGuards(actionInput, ActionGuards);

            if (commonFailure != null)
            {
                return(commonFailure);
            }

            // Rule: Do we have an item matching in our inventory?
            // TODO: Support drinking from, for instance, a fountain sitting in the room.
            var itemIdentifier = actionInput.Tail.Trim();
            var thingToDrink   = actor.FindChild(itemIdentifier.ToLower());

            if (thingToDrink == null)
            {
                return($"You do not hold {actionInput.Tail.Trim()}.");
            }

            // Rule: Is the item drinkable?
            drinkableBehavior = thingToDrink.FindBehavior <DrinkableBehavior>();
            return(drinkableBehavior == null ? $"{itemIdentifier} is not drinkable" : null);
        }