Example #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 = 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 = GameAction.GetPlayerOrMobile(targetFullName) ?? GameAction.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;
        }