public bool HasTarget() { return(Data.UseCustomTargeting && Target.ActiveEntity()); }
public bool EvaluateTarget(ITarget target, TargetProfile data, bool skipExpensiveChecks = false) { if (target == null) { Logger.MsgDebug("Target Is Null, Cannot Evaluate", DebugTypeEnum.TargetEvaluation); return(false); } if (!target.ActiveEntity()) { Logger.MsgDebug("Target Invalid, Cannot Evaluate", DebugTypeEnum.TargetEvaluation); return(false); } Logger.MsgDebug(string.Format(" - Evaluating Target: {0} using profile {1}", target.Name(), data.ProfileSubtypeId), DebugTypeEnum.TargetEvaluation); if (!data.BuiltUniqueFilterList) { foreach (var filter in data.MatchAllFilters) { if (!data.AllUniqueFilters.Contains(filter)) { data.AllUniqueFilters.Add(filter); } } foreach (var filter in data.MatchAnyFilters) { if (!data.AllUniqueFilters.Contains(filter)) { data.AllUniqueFilters.Add(filter); } } foreach (var filter in data.MatchNoneFilters) { if (!data.AllUniqueFilters.Contains(filter)) { data.AllUniqueFilters.Add(filter); } } data.BuiltUniqueFilterList = true; } List <TargetFilterEnum> FilterHits = new List <TargetFilterEnum>(); //Distance var distance = target.Distance(RemoteControl.GetPosition()); if (distance > data.MaxDistance) { return(false); } //Altitude if (data.AllUniqueFilters.Contains(TargetFilterEnum.Altitude)) { var altitude = target.CurrentAltitude(); if (altitude == -1000000 || (altitude >= data.MinAltitude && altitude <= data.MaxAltitude)) { FilterHits.Add(TargetFilterEnum.Altitude); } Logger.MsgDebug(string.Format(" - Evaluated Altitude: {0}", altitude), DebugTypeEnum.TargetEvaluation); } //Broadcasting if (data.AllUniqueFilters.Contains(TargetFilterEnum.Broadcasting)) { var range = target.BroadcastRange(data.BroadcastOnlyAntenna); if (range > distance || distance < data.NonBroadcastVisualRange) { FilterHits.Add(TargetFilterEnum.Broadcasting); } Logger.MsgDebug(string.Format(" - Evaluated Broadcast Range vs Distance: {0} / {1}", range, distance), DebugTypeEnum.TargetEvaluation); } //Faction if (data.AllUniqueFilters.Contains(TargetFilterEnum.Faction)) { var faction = target.FactionOwner() ?? ""; if (data.PrioritizeSpecifiedFactions || data.FactionTargets.Contains(faction)) { FilterHits.Add(TargetFilterEnum.Faction); } Logger.MsgDebug(string.Format(" - Evaluated Faction: {0}", faction), DebugTypeEnum.TargetEvaluation); } //Gravity if (data.AllUniqueFilters.Contains(TargetFilterEnum.Gravity)) { var gravity = target.CurrentGravity(); if (gravity >= data.MinGravity && gravity <= data.MaxGravity) { FilterHits.Add(TargetFilterEnum.Gravity); } Logger.MsgDebug(string.Format(" - Evaluated Gravity: {0}", gravity), DebugTypeEnum.TargetEvaluation); } //LineOfSight if (!skipExpensiveChecks && data.AllUniqueFilters.Contains(TargetFilterEnum.LineOfSight) && _behavior.AutoPilot.Collision.TargetResult.HasTarget()) { bool targetMatch = (target.GetParentEntity().EntityId == _behavior.AutoPilot.Collision.TargetResult.GetCollisionEntity().EntityId); if (targetMatch) { FilterHits.Add(TargetFilterEnum.MovementScore); } } //MovementScore if (data.AllUniqueFilters.Contains(TargetFilterEnum.MovementScore)) { if (distance < data.MaxMovementDetectableDistance || data.MaxMovementDetectableDistance < 0) { var score = target.MovementScore(); if ((data.MinMovementScore == -1 || score >= data.MinMovementScore) && (data.MaxMovementScore == -1 || score <= data.MaxMovementScore)) { FilterHits.Add(TargetFilterEnum.MovementScore); } } } //Name if (data.AllUniqueFilters.Contains(TargetFilterEnum.Name)) { var name = target.Name(); string successName = "N/A"; foreach (var allowedName in data.Names) { if (string.IsNullOrWhiteSpace(allowedName)) { continue; } if (data.UsePartialNameMatching) { if (name.Contains(allowedName)) { successName = allowedName; break; } } else { if (name == allowedName) { successName = allowedName; break; } } } if (successName != "N/A") { FilterHits.Add(TargetFilterEnum.Name); } Logger.MsgDebug(string.Format(" - Evaluated Name: {0} // {1}", name, successName), DebugTypeEnum.TargetEvaluation); } //OutsideOfSafezone if (data.AllUniqueFilters.Contains(TargetFilterEnum.OutsideOfSafezone)) { bool inZone = target.InSafeZone(); if (!inZone) { FilterHits.Add(TargetFilterEnum.OutsideOfSafezone); } Logger.MsgDebug(string.Format(" - Evaluated Outside Safezone: {0}", !inZone), DebugTypeEnum.TargetEvaluation); } //Owner if (data.AllUniqueFilters.Contains(TargetFilterEnum.Owner)) { var owners = target.OwnerTypes(data.OnlyGetFromEntityOwner, data.GetFromMinorityGridOwners); bool gotRelation = false; var values = Enum.GetValues(typeof(OwnerTypeEnum)).Cast <OwnerTypeEnum>(); foreach (var ownerType in values) { if (ownerType == OwnerTypeEnum.None) { continue; } if (owners.HasFlag(ownerType) && data.Owners.HasFlag(ownerType)) { gotRelation = true; break; } } if (gotRelation) { FilterHits.Add(TargetFilterEnum.Owner); } Logger.MsgDebug(string.Format(" - Evaluated Owners: Required: {0}", data.Owners.ToString()), DebugTypeEnum.TargetEvaluation); Logger.MsgDebug(string.Format(" - Evaluated Owners: Found: {0}", owners.ToString()), DebugTypeEnum.TargetEvaluation); Logger.MsgDebug(string.Format(" - Evaluated Target Owners: {0} / Passed: {1}", owners.ToString(), gotRelation), DebugTypeEnum.TargetEvaluation); } //PlayerControlled if (data.AllUniqueFilters.Contains(TargetFilterEnum.PlayerControlled)) { var controlled = target.PlayerControlled(); if (data.PrioritizePlayerControlled || controlled) { FilterHits.Add(TargetFilterEnum.PlayerControlled); } Logger.MsgDebug(string.Format(" - Evaluated Player Controlled: {0}", controlled), DebugTypeEnum.TargetEvaluation); } //PlayerKnownLocation if (data.AllUniqueFilters.Contains(TargetFilterEnum.PlayerKnownLocation)) { bool inKnownLocation = false; if (MESApi.MESApiReady) { if (MESApi.IsPositionInKnownPlayerLocation(target.GetPosition(), true, string.IsNullOrWhiteSpace(data.PlayerKnownLocationFactionOverride) ? _behavior.Owner.Faction?.Tag : data.PlayerKnownLocationFactionOverride)) { ; } FilterHits.Add(TargetFilterEnum.PlayerKnownLocation); } Logger.MsgDebug(string.Format(" - Evaluated Player Known Location: {0}", inKnownLocation), DebugTypeEnum.TargetEvaluation); } //Powered if (data.AllUniqueFilters.Contains(TargetFilterEnum.Powered)) { bool powered = target.IsPowered(); if (powered) { FilterHits.Add(TargetFilterEnum.Powered); } Logger.MsgDebug(string.Format(" - Evaluated Power: {0}", powered), DebugTypeEnum.TargetEvaluation); } //Relation if (data.AllUniqueFilters.Contains(TargetFilterEnum.Relation)) { var relations = target.RelationTypes(RemoteControl.OwnerId, data.OnlyGetFromEntityOwner, data.GetFromMinorityGridOwners); bool gotRelation = false; var values = Enum.GetValues(typeof(RelationTypeEnum)).Cast <RelationTypeEnum>(); foreach (var relationType in values) { if (relationType == RelationTypeEnum.None) { continue; } if (relations.HasFlag(relationType) && data.Relations.HasFlag(relationType)) { gotRelation = true; break; } } if (gotRelation) { FilterHits.Add(TargetFilterEnum.Relation); } Logger.MsgDebug(string.Format(" - Evaluated Relations: Required: {0}", data.Relations.ToString()), DebugTypeEnum.TargetEvaluation); Logger.MsgDebug(string.Format(" - Evaluated Relations: Found: {0}", relations.ToString()), DebugTypeEnum.TargetEvaluation); Logger.MsgDebug(string.Format(" - Evaluated Relations: {0} / Passed: {1}", relations.ToString(), gotRelation), DebugTypeEnum.TargetEvaluation); } //Shielded if (data.AllUniqueFilters.Contains(TargetFilterEnum.Shielded)) { bool shielded = target.ProtectedByShields(); if (shielded) { FilterHits.Add(TargetFilterEnum.Shielded); } Logger.MsgDebug(string.Format(" - Evaluated Shields: {0}", shielded), DebugTypeEnum.TargetEvaluation); } //Speed if (data.AllUniqueFilters.Contains(TargetFilterEnum.Speed)) { var speed = target.CurrentSpeed(); if ((data.MinSpeed < 0 || speed >= data.MinSpeed) && (data.MaxSpeed < 0 || speed <= data.MaxSpeed)) { FilterHits.Add(TargetFilterEnum.Speed); } Logger.MsgDebug(string.Format(" - Evaluated Speed: {0}", speed), DebugTypeEnum.TargetEvaluation); } //Static if (data.IsStatic != CheckEnum.Ignore && data.AllUniqueFilters.Contains(TargetFilterEnum.Static)) { var staticGrid = target.IsStatic(); if ((staticGrid && data.IsStatic == CheckEnum.Yes) || (!staticGrid && data.IsStatic == CheckEnum.No)) { FilterHits.Add(TargetFilterEnum.Static); } Logger.MsgDebug(string.Format(" - Evaluated Static Grid: {0}", staticGrid), DebugTypeEnum.TargetEvaluation); } //TargetValue if (data.AllUniqueFilters.Contains(TargetFilterEnum.TargetValue)) { var targetValue = target.TargetValue(); if (targetValue >= data.MinTargetValue && targetValue <= data.MaxTargetValue) { FilterHits.Add(TargetFilterEnum.TargetValue); } Logger.MsgDebug(string.Format(" - Evaluated Target Value: {0}", targetValue), DebugTypeEnum.TargetEvaluation); } //Underwater if (data.AllUniqueFilters.Contains(TargetFilterEnum.Underwater)) { bool result = false; if (WaterHelper.Enabled) { result = WaterHelper.UnderwaterAndDepthCheck(target.GetPosition(), _behavior.AutoPilot.CurrentWater, true, Data.MinUnderWaterDepth, Data.MaxUnderWaterDepth); } if (result) { FilterHits.Add(TargetFilterEnum.Underwater); } Logger.MsgDebug(string.Format(" - Evaluated Underwater: {0}", result), DebugTypeEnum.TargetEvaluation); } //Any Conditions Check bool anyConditionPassed = false; if (data.MatchAnyFilters.Count > 0) { foreach (var filter in data.MatchAnyFilters) { if (FilterHits.Contains(filter)) { anyConditionPassed = true; break; } } } else { anyConditionPassed = true; } if (!anyConditionPassed) { Logger.MsgDebug(" - Evaluation Condition -Any- Failed", DebugTypeEnum.TargetEvaluation); return(false); } //All Condition Checks foreach (var filter in data.MatchAllFilters) { if (!FilterHits.Contains(filter)) { Logger.MsgDebug(" - Evaluation Condition -All- Failed", DebugTypeEnum.TargetEvaluation); return(false); } } //None Condition Checks foreach (var filter in data.MatchNoneFilters) { if (FilterHits.Contains(filter)) { Logger.MsgDebug(" - Evaluation Condition -None- Failed", DebugTypeEnum.TargetEvaluation); return(false); } } Logger.MsgDebug(" - Evaluation Passed", DebugTypeEnum.TargetEvaluation); TargetLastKnownCoords = target.GetPosition(); return(true); }
public bool EvaluateTarget(ITarget target) { if (target == null) { Logger.MsgDebug("Target Is Null, Cannot Evaluate", DebugTypeEnum.TargetEvaluation); return(false); } if (!target.ActiveEntity()) { Logger.MsgDebug("Target Invalid, Cannot Evaluate", DebugTypeEnum.TargetEvaluation); return(false); } Logger.MsgDebug(string.Format(" - Evaluating Target: {0}", target.Name()), DebugTypeEnum.TargetEvaluation); if (!Data.BuiltUniqueFilterList) { foreach (var filter in Data.MatchAllFilters) { if (!Data.AllUniqueFilters.Contains(filter)) { Data.AllUniqueFilters.Add(filter); } } foreach (var filter in Data.MatchAnyFilters) { if (!Data.AllUniqueFilters.Contains(filter)) { Data.AllUniqueFilters.Add(filter); } } foreach (var filter in Data.MatchNoneFilters) { if (!Data.AllUniqueFilters.Contains(filter)) { Data.AllUniqueFilters.Add(filter); } } Data.BuiltUniqueFilterList = true; } List <TargetFilterEnum> FilterHits = new List <TargetFilterEnum>(); //Altitude if (Data.AllUniqueFilters.Contains(TargetFilterEnum.Altitude)) { var altitude = target.CurrentAltitude(); if (altitude == -1000000 || (altitude >= Data.MinAltitude && altitude <= Data.MaxAltitude)) { FilterHits.Add(TargetFilterEnum.Altitude); } Logger.MsgDebug(string.Format(" - Evaluated Altitude: {0}", altitude), DebugTypeEnum.TargetEvaluation); } //Broadcasting if (Data.AllUniqueFilters.Contains(TargetFilterEnum.Broadcasting)) { var range = target.BroadcastRange(); var distance = target.Distance(RemoteControl.GetPosition()); if (range > distance || distance < Data.NonBroadcastVisualRange) { FilterHits.Add(TargetFilterEnum.Broadcasting); } Logger.MsgDebug(string.Format(" - Evaluated Broadcast Range vs Distance: {0} / {1}", range, distance), DebugTypeEnum.TargetEvaluation); } //Faction if (Data.AllUniqueFilters.Contains(TargetFilterEnum.Faction)) { var faction = target.FactionOwner() ?? ""; if (Data.PrioritizeSpecifiedFactions || Data.FactionTargets.Contains(faction)) { FilterHits.Add(TargetFilterEnum.Faction); } Logger.MsgDebug(string.Format(" - Evaluated Faction: {0}", faction), DebugTypeEnum.TargetEvaluation); } //Gravity if (Data.AllUniqueFilters.Contains(TargetFilterEnum.Gravity)) { var gravity = target.CurrentGravity(); if (gravity >= Data.MinGravity && gravity <= Data.MaxGravity) { FilterHits.Add(TargetFilterEnum.Gravity); } Logger.MsgDebug(string.Format(" - Evaluated Gravity: {0}", gravity), DebugTypeEnum.TargetEvaluation); } //OutsideOfSafezone if (Data.AllUniqueFilters.Contains(TargetFilterEnum.OutsideOfSafezone)) { bool inZone = target.InSafeZone(); if (!inZone) { FilterHits.Add(TargetFilterEnum.OutsideOfSafezone); } Logger.MsgDebug(string.Format(" - Evaluated Outside Safezone: {0}", inZone), DebugTypeEnum.TargetEvaluation); } //Owner if (Data.AllUniqueFilters.Contains(TargetFilterEnum.Owner)) { var owners = target.OwnerTypes(Data.OnlyGetFromEntityOwner, Data.GetFromMinorityGridOwners); bool gotRelation = false; var values = Enum.GetValues(typeof(OwnerTypeEnum)).Cast <OwnerTypeEnum>(); foreach (var ownerType in values) { if (ownerType == OwnerTypeEnum.None) { continue; } if (owners.HasFlag(ownerType) && Data.Owners.HasFlag(ownerType)) { gotRelation = true; break; } } if (gotRelation) { FilterHits.Add(TargetFilterEnum.Owner); } Logger.MsgDebug(string.Format(" - Evaluated Owners: Required: {0}", Data.Owners.ToString()), DebugTypeEnum.TargetEvaluation); Logger.MsgDebug(string.Format(" - Evaluated Owners: Found: {0}", owners.ToString()), DebugTypeEnum.TargetEvaluation); Logger.MsgDebug(string.Format(" - Evaluated Target Owners: {0} / Passed: {1}", owners.ToString(), gotRelation), DebugTypeEnum.TargetEvaluation); } //Powered if (Data.AllUniqueFilters.Contains(TargetFilterEnum.Powered)) { bool powered = target.IsPowered(); if (powered) { FilterHits.Add(TargetFilterEnum.Powered); } Logger.MsgDebug(string.Format(" - Evaluated Power: {0}", powered), DebugTypeEnum.TargetEvaluation); } //Relation if (Data.AllUniqueFilters.Contains(TargetFilterEnum.Relation)) { var relations = target.RelationTypes(RemoteControl.OwnerId, Data.OnlyGetFromEntityOwner, Data.GetFromMinorityGridOwners); bool gotRelation = false; var values = Enum.GetValues(typeof(RelationTypeEnum)).Cast <RelationTypeEnum>(); foreach (var relationType in values) { if (relationType == RelationTypeEnum.None) { continue; } if (relations.HasFlag(relationType) && Data.Relations.HasFlag(relationType)) { gotRelation = true; break; } } if (gotRelation) { FilterHits.Add(TargetFilterEnum.Relation); } Logger.MsgDebug(string.Format(" - Evaluated Relations: Required: {0}", Data.Relations.ToString()), DebugTypeEnum.TargetEvaluation); Logger.MsgDebug(string.Format(" - Evaluated Relations: Found: {0}", relations.ToString()), DebugTypeEnum.TargetEvaluation); Logger.MsgDebug(string.Format(" - Evaluated Relations: {0} / Passed: {1}", relations.ToString(), gotRelation), DebugTypeEnum.TargetEvaluation); } //Shielded if (Data.AllUniqueFilters.Contains(TargetFilterEnum.Shielded)) { bool shielded = target.ProtectedByShields(); if (shielded) { FilterHits.Add(TargetFilterEnum.Shielded); } Logger.MsgDebug(string.Format(" - Evaluated Shields: {0}", shielded), DebugTypeEnum.TargetEvaluation); } //Speed if (Data.AllUniqueFilters.Contains(TargetFilterEnum.Speed)) { var speed = target.CurrentSpeed(); if ((Data.MinSpeed < 0 || speed >= Data.MinSpeed) && (Data.MaxSpeed < 0 || speed <= Data.MaxSpeed)) { FilterHits.Add(TargetFilterEnum.Speed); } Logger.MsgDebug(string.Format(" - Evaluated Speed: {0}", speed), DebugTypeEnum.TargetEvaluation); } //Static if (Data.IsStatic != CheckEnum.Ignore && Data.AllUniqueFilters.Contains(TargetFilterEnum.Static)) { var staticGrid = target.IsStatic(); if ((staticGrid && Data.IsStatic == CheckEnum.Yes) || (!staticGrid && Data.IsStatic == CheckEnum.No)) { FilterHits.Add(TargetFilterEnum.Static); } Logger.MsgDebug(string.Format(" - Evaluated Static Grid: {0}", staticGrid), DebugTypeEnum.TargetEvaluation); } //TargetValue if (Data.AllUniqueFilters.Contains(TargetFilterEnum.TargetValue)) { var targetValue = target.TargetValue(); if (targetValue >= Data.MinTargetValue && targetValue <= Data.MaxTargetValue) { FilterHits.Add(TargetFilterEnum.TargetValue); } Logger.MsgDebug(string.Format(" - Evaluated Target Value: {0}", targetValue), DebugTypeEnum.TargetEvaluation); } //Any Conditions Check bool anyConditionPassed = false; if (Data.MatchAnyFilters.Count > 0) { foreach (var filter in Data.MatchAnyFilters) { if (FilterHits.Contains(filter)) { anyConditionPassed = true; break; } } } else { anyConditionPassed = true; } if (!anyConditionPassed) { Logger.MsgDebug(" - Evaluation Condition -Any- Failed", DebugTypeEnum.TargetEvaluation); return(false); } //All Condition Checks foreach (var filter in Data.MatchAllFilters) { if (!FilterHits.Contains(filter)) { Logger.MsgDebug(" - Evaluation Condition -All- Failed", DebugTypeEnum.TargetEvaluation); return(false); } } //None Condition Checks foreach (var filter in Data.MatchNoneFilters) { if (FilterHits.Contains(filter)) { Logger.MsgDebug(" - Evaluation Condition -None- Failed", DebugTypeEnum.TargetEvaluation); return(false); } } Logger.MsgDebug(" - Evaluation Passed", DebugTypeEnum.TargetEvaluation); return(true); }