private static void EngageTarget()
{
if (Settings.Instance.DebugDrones) Logging.Log("Drones.EngageTarget", "Entering EngageTarget()", Logging.Debug);
// Find the first active weapon's target
//TargetingCache.CurrentDronesTarget = Cache.Instance.EntityById(_lastTarget);
if (Settings.Instance.DebugDrones) Logging.Log("Drones.EngageTarget", "GetBestDroneTarget: MaxDroneRange [" + Cache.Instance.MaxDroneRange + "]);", Logging.Debug);
// Return best possible low value target
if (Cache.Instance.PreferredDroneTarget == null || !Cache.Instance.PreferredDroneTarget.IsFrigate)
{
Cache.Instance.GetBestDroneTarget(Cache.Instance.MaxDroneRange, !Cache.Instance.DronesKillHighValueTargets, "Drones");
}
EntityCache DroneToShoot = Cache.Instance.PreferredDroneTarget;
if (DroneToShoot == null)
{
if (Settings.Instance.DebugDrones) Logging.Log("Drones.EngageTarget", "GetBestDroneTarget: PreferredDroneTarget is null, picking a target using a simple rule set...", Logging.Debug);
if (Cache.Instance.Targets.Any(i => !i.IsContainer && !i.IsBadIdea))
{
DroneToShoot = Cache.Instance.Targets.Where(i => !i.IsContainer && !i.IsBadIdea && i.Distance < Cache.Instance.MaxDroneRange).OrderByDescending(i => i.IsWarpScramblingMe).ThenByDescending(i => i.IsFrigate).ThenBy(i => i.Distance).FirstOrDefault();
}
}
if (DroneToShoot != null)
{
if (DroneToShoot.IsReadyToShoot && DroneToShoot.Distance < Cache.Instance.MaxDroneRange)
{
if (Settings.Instance.DebugDrones) Logging.Log("Drones.EngageTarget", "if (DroneToShoot != null && DroneToShoot.IsReadyToShoot && DroneToShoot.Distance < Cache.Instance.MaxDroneRange)", Logging.Debug);
// Nothing to engage yet, probably re-targeting
if (!DroneToShoot.IsTarget)
{
if (Settings.Instance.DebugDrones) Logging.Log("Drones.EngageTarget", "if (!DroneToShoot.IsTarget)", Logging.Debug);
return;
}
if (DroneToShoot.IsBadIdea) //&& !DroneToShoot.IsAttacking)
{
if (Settings.Instance.DebugDrones) Logging.Log("Drones.EngageTarget", "if (DroneToShoot.IsBadIdea && !DroneToShoot.IsAttacking) return;", Logging.Debug);
return;
}
// Is our current target still the same and are all the drones shooting the PreferredDroneTarget?
if (Cache.Instance.LastDroneTargetID != null)
{
if (Cache.Instance.LastDroneTargetID == DroneToShoot.Id && Cache.Instance.ActiveDrones.Any(i => i.FollowId != Cache.Instance.PreferredDroneTargetID))
{
if (Settings.Instance.DebugDrones) Logging.Log("Drones.EngageTarget", "if (LastDroneTargetID [" + Cache.Instance.LastDroneTargetID + "] == DroneToShoot.Id [" + DroneToShoot.Id + "] && Cache.Instance.ActiveDrones.Any(i => i.FollowId != Cache.Instance.PreferredDroneTargetID) [" + Cache.Instance.ActiveDrones.Any(i => i.FollowId != Cache.Instance.PreferredDroneTargetID) + "])", Logging.Debug);
return;
}
}
//
// If we got this far we need to tell the drones to do something
// Is the last target our current active target?
//
if (DroneToShoot.IsActiveTarget)
{
// Save target id (so we do not constantly switch)
Cache.Instance.LastDroneTargetID = DroneToShoot.Id;
// Engage target
Logging.Log("Drones", "Engaging [ " + Cache.Instance.ActiveDrones.Count() + " ] drones on [" + DroneToShoot.Name + "][ID: " + Cache.Instance.MaskedID(DroneToShoot.Id) + "]" + Math.Round(DroneToShoot.Distance / 1000, 0) + "k away]", Logging.Magenta);
Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdDronesEngage);
_lastEngageCommand = DateTime.UtcNow;
}
else // Make the target active
{
if (DateTime.UtcNow > Cache.Instance.NextMakeActiveTargetAction)
{
DroneToShoot.MakeActiveTarget();
Logging.Log("Drones", "[" + DroneToShoot.Name + "][ID: " + Cache.Instance.MaskedID(DroneToShoot.Id) + "]IsActiveTarget[" + DroneToShoot.IsActiveTarget + "][" + Math.Round(DroneToShoot.Distance / 1000, 0) + "k away] has been made the ActiveTarget (needed for drones)", Logging.Magenta);
Cache.Instance.NextMakeActiveTargetAction = DateTime.UtcNow.AddSeconds(5 + Cache.Instance.RandomNumber(0, 3));
}
}
}
if (Settings.Instance.DebugDrones) Logging.Log("Drones.EngageTarget", "if (DroneToShoot != null && DroneToShoot.IsReadyToShoot && DroneToShoot.Distance < Cache.Instance.MaxDroneRange)", Logging.Debug);
return;
}
if (Settings.Instance.DebugDrones) Logging.Log("Drones.EngageTarget", "if (Cache.Instance.PreferredDroneTargetID != null)", Logging.Debug);
return;
}