/// <summary>Allows a caller to determine whether this thing can be detected by something's senses.</summary> /// <param name="senses">The sense manager.</param> /// <returns>True if detectable by sense, else false.</returns> public bool IsDetectableBySense(SenseManager senses) { return(senses.Contains(SensoryType.Sight) && senses[SensoryType.Sight].Enabled); }
/// <summary>Sets the default properties of this behavior instance.</summary> protected override void SetDefaultProperties() { Senses = new SenseManager(); LoadDefaultSenses(); }
/// <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; }
/// <summary> /// Sets the default properties of this behavior instance. /// </summary> protected override void SetDefaultProperties() { this.PerceivedThings = new List<Thing>(); this.Senses = new SenseManager(); this.LoadSenses(); }