/// <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); } if (actionInput.Params.Length == 0) { return(null); } // TODO: CommonGuards.RequiresAtLeastOneArgument makes the length check redundant? string targetName = (actionInput.Params.Length > 0) ? actionInput.Params[0] : string.Empty; string targetFullName = actionInput.Tail.Trim().ToLower(); // Try to find the target either by all the parameter text or by just the first parameter. this.target = GetPlayerOrMobile(targetFullName) ?? GetPlayerOrMobile(targetName); // Rule: Is the target an entity? if (this.target == null) { return("You cannot see " + targetName + "."); } // Rule: Is the target the initator? if (sender.Thing.Name.ToLower() == this.target.Name.ToLower()) { return("You can't follow yourself."); } // Rule: Is the target in the same room? if (sender.Thing.Parent.Id != this.target.Parent.Id) { return(targetName + " does not appear to be in the vicinity."); } SenseManager senses = new SenseManager(); senses.AddSense(new Sense { SensoryType = SensoryType.Sight, Enabled = true }); if (!this.target.IsDetectableBySense(senses)) { return(targetName + " does not appear to be in the vicinity."); } return(null); }
/// <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 commonFailure = VerifyCommonGuards(actionInput, ActionGuards); if (commonFailure != null) { return(commonFailure); } if (actionInput.Params.Length == 0) { return(null); } // TODO: CommonGuards.RequiresAtLeastOneArgument makes the length check redundant? var targetName = (actionInput.Params.Length > 0) ? actionInput.Params[0] : string.Empty; var targetFullName = actionInput.Tail.Trim().ToLower(); // Try to find the target either by all the parameter text or by just the first parameter. target = GetPlayerOrMobile(targetFullName) ?? GetPlayerOrMobile(targetName); // Rule: Is the target an entity? if (target == null) { return("You cannot see " + targetName + "."); } // Rule: Is the target the initiator? if (string.Equals(actionInput.Actor.Name, target.Name, StringComparison.CurrentCultureIgnoreCase)) { return("You can't follow yourself."); } // Rule: Is the target in the same room? if (actionInput.Actor.Parent.Id != target.Parent.Id) { return($"{targetName} does not appear to be in the vicinity."); } var senses = new SenseManager(); senses.AddSense(new Sense { SensoryType = SensoryType.Sight, Enabled = true }); if (!target.IsDetectableBySense(senses)) { return($"{targetName} does not appear to be in the vicinity."); } return(null); }