/// <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 = VerifyCommonGuards(actionInput, ActionGuards); if (commonFailure != null) { return(commonFailure); } // Rule: A thing must be singly targeted. // @@@ TODO: Try to find a single target according to the specified identifiers. If more than one thing // meets the identifiers then use a disambiguation targeting system to try to narrow to one thing. // @@@ TODO: This sort of find pattern may become common; maybe we need to simplify // to having a Thing method which does this? IE "List<Thing> FindChildren<T>(string id)"? Predicate <Thing> findPredicate = (Thing t) => t.Behaviors.FindFirst <EnterableExitableBehavior>() != null; List <Thing> enterableThings = sender.Thing.Parent.FindAllChildren(findPredicate); if (enterableThings.Count > 1) { return("There is more than one thing by that identity."); } else if (enterableThings.Count == 1) { Thing thing = enterableThings.First(); this.enterableBehavior = thing.Behaviors.FindFirst <EnterableExitableBehavior>(); if (this.enterableBehavior == null) { return("You can not enter " + thing.Name + "."); } } // If we got this far, we couldn't find an appropriate enterable thing in the room. return("You can't see anything like that to enter."); }