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 void ProcessTriggerWatchers() { var timeDifference = MyAPIGateway.Session.GameDateTime - LastTriggerRun; if (timeDifference.TotalMilliseconds < 500) { //Logger.MsgDebug("Triggers Not Ready (total ms elapsed: "+ timeDifference.TotalMilliseconds.ToString() + "), Handing Off to Next Action", DebugTypeEnum.Dev); //OnComplete?.Invoke(); return; } //Logger.MsgDebug("Checking Triggers", DebugTypeEnum.Dev); LastTriggerRun = MyAPIGateway.Session.GameDateTime; for (int i = 0; i < Triggers.Count; i++) { var trigger = Triggers[i]; if (!trigger.UseTrigger) { continue; } //Timer if (trigger.Type == "Timer") { //Logger.MsgDebug("Checking Timer Trigger: " + trigger.ProfileSubtypeId, DebugTypeEnum.Trigger); if (trigger.UseTrigger == true) { trigger.ActivateTrigger(); } continue; } //PlayerNear if (trigger.Type == "PlayerNear") { //Logger.MsgDebug("Checking PlayerNear Trigger: " + trigger.ProfileSubtypeId, DebugTypeEnum.Trigger); if (trigger.UseTrigger == true) { if (IsPlayerNearby(trigger)) { trigger.ActivateTrigger(); } } continue; } //PlayerFar if (trigger.Type == "PlayerFar") { //Logger.MsgDebug("Checking PlayerNear Trigger: " + trigger.ProfileSubtypeId, DebugTypeEnum.Trigger); if (trigger.UseTrigger == true) { if (IsPlayerNearby(trigger, true)) { trigger.ActivateTrigger(); } } continue; } //TargetNear if (trigger.Type == "TargetNear") { //Logger.MsgDebug("Checking PlayerNear Trigger: " + trigger.ProfileSubtypeId, DebugTypeEnum.Trigger); if (trigger.UseTrigger == true) { if (_behavior.AutoPilot.Targeting.HasTarget() && Vector3D.Distance(RemoteControl.GetPosition(), _behavior.AutoPilot.Targeting.TargetLastKnownCoords) < trigger.TargetDistance) { trigger.ActivateTrigger(); } } continue; } //TargetFar if (trigger.Type == "TargetFar") { //Logger.MsgDebug("Checking PlayerNear Trigger: " + trigger.ProfileSubtypeId, DebugTypeEnum.Trigger); if (trigger.UseTrigger == true) { if (_behavior.AutoPilot.Targeting.HasTarget() && Vector3D.Distance(RemoteControl.GetPosition(), _behavior.AutoPilot.Targeting.TargetLastKnownCoords) > trigger.TargetDistance) { trigger.ActivateTrigger(); } } continue; } //DespawnNear if (trigger.Type == "DespawnNear") { //Logger.MsgDebug("Checking DespawnNear Trigger: " + trigger.ProfileSubtypeId, DebugTypeEnum.Trigger); if (trigger.UseTrigger == true) { if (_behavior.Settings.DespawnCoords != Vector3D.Zero && Vector3D.Distance(RemoteControl.GetPosition(), _behavior.Settings.DespawnCoords) < trigger.TargetDistance) { trigger.ActivateTrigger(); } } continue; } //DespawnFar if (trigger.Type == "DespawnFar") { //Logger.MsgDebug("Checking DespawnFar Trigger: " + trigger.ProfileSubtypeId, DebugTypeEnum.Trigger); if (trigger.UseTrigger == true) { if (_behavior.Settings.DespawnCoords != Vector3D.Zero && Vector3D.Distance(RemoteControl.GetPosition(), _behavior.Settings.DespawnCoords) > trigger.TargetDistance) { trigger.ActivateTrigger(); } } continue; } //TurretTarget if (trigger.Type == "TurretTarget") { //Logger.MsgDebug("Checking TurretTarget Trigger: " + trigger.ProfileSubtypeId, DebugTypeEnum.Trigger); if (trigger.UseTrigger == true) { var turretTarget = _autopilot.Weapons.GetTurretTarget(); if (turretTarget != 0) { trigger.ActivateTrigger(); if (trigger.Triggered == true) { trigger.DetectedEntityId = turretTarget; } } } continue; } //NoWeapon if (trigger.Type == "NoWeapon") { //Logger.MsgDebug("Checking NoWeapon Trigger: " + trigger.ProfileSubtypeId, DebugTypeEnum.Trigger); if (trigger.UseTrigger && !_autopilot.Weapons.HasWorkingWeapons()) { trigger.ActivateTrigger(); } continue; } //NoTarget if (trigger.Type == "NoTarget") { //Logger.MsgDebug("Checking NoTarget Trigger: " + trigger.ProfileSubtypeId, DebugTypeEnum.Trigger); if (trigger.UseTrigger) { if (!_autopilot.Targeting.HasTarget()) { trigger.ActivateTrigger(); } } continue; } //HasTarget if (trigger.Type == "HasTarget") { //Logger.MsgDebug("Checking HasTarget Trigger: " + trigger.ProfileSubtypeId, DebugTypeEnum.Trigger); if (trigger.UseTrigger) { if (_autopilot.Targeting.HasTarget()) { trigger.ActivateTrigger(); } } continue; } //AcquiredTarget if (trigger.Type == "AcquiredTarget") { //Logger.MsgDebug("Checking NoTarget Trigger: " + trigger.ProfileSubtypeId, DebugTypeEnum.Trigger); if (trigger.UseTrigger) { if (_autopilot.Targeting.TargetAcquired) { _autopilot.Targeting.TargetAcquired = false; trigger.ActivateTrigger(); } } continue; } //LostTarget if (trigger.Type == "LostTarget") { //Logger.MsgDebug("Checking HasTarget Trigger: " + trigger.ProfileSubtypeId, DebugTypeEnum.Trigger); if (trigger.UseTrigger) { if (_autopilot.Targeting.TargetLost) { _autopilot.Targeting.TargetLost = false; trigger.ActivateTrigger(); } } continue; } //TargetInSafezone if (trigger.Type == "TargetInSafezone") { //Logger.MsgDebug("Checking TargetInSafezone Trigger: " + trigger.ProfileSubtypeId, DebugTypeEnum.Trigger); if (trigger.UseTrigger == true) { if (_autopilot.Targeting.HasTarget() && _autopilot.Targeting.Target.InSafeZone()) { trigger.ActivateTrigger(); } } continue; } //Grounded if (trigger.Type == "Grounded") { if (trigger.UseTrigger == true) { //Check if Grounded trigger.ActivateTrigger(); } continue; } //BehaviorTriggerA if (trigger.Type == "BehaviorTriggerA") { if (trigger.UseTrigger == true && _behavior.BehaviorTriggerA) { trigger.ActivateTrigger(); } continue; } //BehaviorTriggerB if (trigger.Type == "BehaviorTriggerB") { if (trigger.UseTrigger == true && _behavior.BehaviorTriggerB) { trigger.ActivateTrigger(); } continue; } //BehaviorTriggerC if (trigger.Type == "BehaviorTriggerC") { if (trigger.UseTrigger == true && _behavior.BehaviorTriggerC) { trigger.ActivateTrigger(); } continue; } //BehaviorTriggerD if (trigger.Type == "BehaviorTriggerD") { if (trigger.UseTrigger == true && _behavior.BehaviorTriggerD) { trigger.ActivateTrigger(); } continue; } //BehaviorTriggerE if (trigger.Type == "BehaviorTriggerE") { if (trigger.UseTrigger == true && _behavior.BehaviorTriggerE) { trigger.ActivateTrigger(); } continue; } //BehaviorTriggerF if (trigger.Type == "BehaviorTriggerF") { if (trigger.UseTrigger == true && _behavior.BehaviorTriggerF) { trigger.ActivateTrigger(); } continue; } //BehaviorTriggerG if (trigger.Type == "BehaviorTriggerG") { if (trigger.UseTrigger == true && _behavior.BehaviorTriggerG) { trigger.ActivateTrigger(); } continue; } //PaymentSuccess if (trigger.Type == "PaymentSuccess") { if (trigger.UseTrigger == true && PaymentSuccessTriggered) { trigger.ActivateTrigger(); } continue; } //PaymentFailure if (trigger.Type == "PaymentFailure") { if (trigger.UseTrigger == true && PaymentFailureTriggered) { trigger.ActivateTrigger(); } continue; } //PlayerKnownLocation if (trigger.Type == "PlayerKnownLocation") { if (MESApi.MESApiReady) { if (trigger.UseTrigger == true && MESApi.IsPositionInKnownPlayerLocation(RemoteControl.GetPosition(), true, _behavior.Owner.Faction?.Tag)) { trigger.ActivateTrigger(); } } continue; } //SensorActive if (trigger.Type == "SensorActive") { if (_behavior.Grid.SensorCheck(trigger.SensorName)) { trigger.ActivateTrigger(); } continue; } //SensorActive if (trigger.Type == "SensorIdle") { if (_behavior.Grid.SensorCheck(trigger.SensorName, false)) { trigger.ActivateTrigger(); } continue; } } _behavior.BehaviorTriggerA = false; _behavior.BehaviorTriggerB = false; _behavior.BehaviorTriggerC = false; _behavior.BehaviorTriggerD = false; _behavior.BehaviorTriggerE = false; _behavior.BehaviorTriggerF = false; _behavior.BehaviorTriggerG = false; PaymentSuccessTriggered = false; PaymentFailureTriggered = false; TimedTriggersProcessed = true; }