public bool SelectTarget(out IEnumerable <WowUnit> possibleTargets) { //if ((PriorityTargets == null || !PriorityTargets.Any()) && WowInterface.ObjectManager.MapId == MapId.UtgardeKeep) //{ // PriorityTargets = new List<string>() { "Frost Tomb" }; //} if (WowInterface.ObjectManager.TargetGuid != 0 && WowInterface.ObjectManager.Target != null && (WowInterface.ObjectManager.Target.IsDead || WowInterface.ObjectManager.Target.IsNotAttackable || !BotUtils.IsValidUnit(WowInterface.ObjectManager.Target) || WowInterface.HookManager.GetUnitReaction(WowInterface.ObjectManager.Player, WowInterface.ObjectManager.Target) == WowUnitReaction.Friendly)) { WowInterface.HookManager.ClearTarget(); possibleTargets = null; return(false); } if (PriorityTargets != null && PriorityTargets.Any()) { IEnumerable <WowUnit> nearPriorityEnemies = WowInterface.ObjectManager.GetNearEnemies <WowUnit>(WowInterface.ObjectManager.Player.Position, 64.0) .Where(e => BotUtils.IsValidUnit(e) && !e.IsDead && e.Health > 0 && PriorityTargets.Any(x => e.Name.Equals(x, StringComparison.OrdinalIgnoreCase))) .OrderBy(e => e.Position.GetDistance(WowInterface.ObjectManager.Player.Position)); if (nearPriorityEnemies.Any()) { possibleTargets = nearPriorityEnemies; return(true); } } IEnumerable <WowUnit> nearEnemies = WowInterface.ObjectManager .GetEnemiesInCombatWithUs <WowUnit>(WowInterface.ObjectManager.Player.Position, 64.0) .Where(e => !(WowInterface.ObjectManager.MapId == MapId.HallsOfReflection && e.Name == "The Lich King") && !(WowInterface.ObjectManager.MapId == MapId.DrakTharonKeep && WowInterface.ObjectManager.WowObjects.OfType <WowDynobject>().Any(e => e.SpellId == 47346))) // Novos fix .OrderByDescending(e => e.Type) // make sure players are at the top (pvp) .ThenByDescending(e => e.IsFleeing) // catch fleeing enemies .ThenByDescending(e => e.MaxHealth) .ThenBy(e => e.Health); // TODO: need to handle duels, our target will // be friendly there but is attackable if (nearEnemies.Any()) { possibleTargets = nearEnemies; return(true); } nearEnemies = WowInterface.ObjectManager.GetNearEnemies <WowUnit>(WowInterface.ObjectManager.Player.Position, 100.0); if (nearEnemies.Any()) { possibleTargets = nearEnemies; return(true); } possibleTargets = null; return(false); }
public bool SelectTarget(out IEnumerable <WowUnit> possibleTargets) { if (WowInterface.ObjectManager.TargetGuid != 0 && WowInterface.ObjectManager.Target != null && (WowInterface.ObjectManager.Target.IsDead || WowInterface.ObjectManager.Target.IsNotAttackable || !BotUtils.IsValidUnit(WowInterface.ObjectManager.Target) || WowInterface.HookManager.WowGetUnitReaction(WowInterface.ObjectManager.Player, WowInterface.ObjectManager.Target) == WowUnitReaction.Friendly)) { WowInterface.HookManager.WowClearTarget(); possibleTargets = null; return(false); } Vector3 position = Config.StayCloseToGroupInCombat ? WowInterface.ObjectManager.MeanGroupPosition : WowInterface.ObjectManager.Player.Position; if (PriorityTargets != null && PriorityTargets.Any()) { IEnumerable <WowUnit> nearPriorityEnemies = WowInterface.ObjectManager.GetNearEnemies <WowUnit>(position, 64.0) .Where(e => BotUtils.IsValidUnit(e) && !e.IsDead && e.Health > 0 && e.IsInCombat && PriorityTargets.Any(x => e.DisplayId == x) && e.Position.GetDistance(WowInterface.ObjectManager.Player.Position) < 80.0) .OrderBy(e => e.Position.GetDistance(WowInterface.ObjectManager.Player.Position)); if (nearPriorityEnemies.Any()) { possibleTargets = nearPriorityEnemies; return(true); } } IEnumerable <WowUnit> nearEnemies = WowInterface.ObjectManager .GetEnemiesInCombatWithGroup <WowUnit>(position, 64.0) .Where(e => !(WowInterface.ObjectManager.MapId == MapId.HallsOfReflection && e.Name == "The Lich King") && !(WowInterface.ObjectManager.MapId == MapId.DrakTharonKeep && WowInterface.ObjectManager.WowObjects.OfType <WowDynobject>().Any(e => e.SpellId == 47346))) // Novos fix .OrderByDescending(e => e.Type) // make sure players are at the top (pvp) .ThenByDescending(e => e.IsFleeing) // catch fleeing enemies .ThenByDescending(e => e.MaxHealth) .ThenBy(e => e.Health); // TODO: need to handle duels, our target will // be friendly there but is attackable if (nearEnemies.Any()) { possibleTargets = nearEnemies; return(true); } nearEnemies = WowInterface.ObjectManager.GetNearEnemies <WowUnit>(position, 100.0).Where(e => e.IsInCombat); if (nearEnemies.Any()) { possibleTargets = nearEnemies; return(true); } possibleTargets = null; return(false); }
/// <summary> /// Return the best possible target (based on current target, distance and low value first) /// </summary> /// <param name="currentTarget"></param> /// <param name="distance"></param> /// <param name="lowValueFirst"></param> /// <returns></returns> public EntityCache GetBestTarget(EntityCache currentTarget, double distance, bool lowValueFirst) { // Is our current target a warp scrambling priority target? if (currentTarget != null && PriorityTargets.Any(pt => pt.Id == currentTarget.Id && pt.IsWarpScramblingMe)) { return(currentTarget); } // Get the closest warp scrambling priority target var target = PriorityTargets.OrderBy(OrderByLowestHealth()).ThenBy(t => t.Distance).FirstOrDefault(pt => pt.Distance < distance && pt.IsWarpScramblingMe && Targets.Any(t => t.Id == pt.Id)); if (target != null) { return(target); } // Is our current target any other priority target? if (currentTarget != null && PriorityTargets.Any(pt => pt.Id == currentTarget.Id)) { return(currentTarget); } // Get the closest priority target target = PriorityTargets.OrderBy(OrderByLowestHealth()).ThenBy(t => t.Distance).FirstOrDefault(pt => pt.Distance < distance && Targets.Any(t => t.Id == pt.Id)); if (target != null) { return(target); } // Do we have a target? if (currentTarget != null) { return(currentTarget); } // Get all entity targets var targets = Targets.Where(e => e.CategoryId == (int)CategoryID.Entity && e.IsNpc && !e.IsContainer && e.GroupId != (int)Group.LargeCollidableStructure); // Get the closest high value target var highValueTarget = targets.Where(t => t.TargetValue.HasValue && t.Distance < distance).OrderByDescending(t => t.TargetValue.Value).ThenBy(OrderByLowestHealth()).ThenBy(t => t.Distance).FirstOrDefault(); // Get the closest low value target var lowValueTarget = targets.Where(t => !t.TargetValue.HasValue && t.Distance < distance).OrderBy(OrderByLowestHealth()).ThenBy(t => t.Distance).FirstOrDefault(); if (lowValueFirst && lowValueTarget != null) { return(lowValueTarget); } if (!lowValueFirst && highValueTarget != null) { return(highValueTarget); } // Return either one or the other return(lowValueTarget ?? highValueTarget); }
/// <summary> /// Return the best possible target (based on current target, distance and low value first) /// </summary> /// <param name="currentTarget"></param> /// <param name="distance"></param> /// <param name="lowValueFirst"></param> /// <returns></returns> public EntityCache GetBestTarget(EntityCache currentTarget, double distance, bool lowValueFirst) { // Do we have a 'current target' and if so, is it an actual target? // If not, clear current target if (currentTarget != null && !currentTarget.IsTarget) { currentTarget = null; } // Is our current target a warp scrambling priority target? if (currentTarget != null && PriorityTargets.Any(pt => pt.Id == currentTarget.Id && pt.IsWarpScramblingMe && pt.IsTarget)) { return(currentTarget); } // Get the closest warp scrambling priority target var target = PriorityTargets.OrderBy(OrderByLowestHealth()).ThenBy(t => t.Distance).FirstOrDefault(pt => pt.Distance < distance && pt.IsWarpScramblingMe && pt.IsTarget); if (target != null) { return(target); } // Is our current target any other priority target? if (currentTarget != null && PriorityTargets.Any(pt => pt.Id == currentTarget.Id)) { return(currentTarget); } // Get the closest priority target target = PriorityTargets.OrderBy(OrderByLowestHealth()).ThenBy(t => t.Distance).FirstOrDefault(pt => pt.Distance < distance && pt.IsTarget); if (target != null) { return(target); } // Do we have a target? if (currentTarget != null) { return(currentTarget); } // Get all entity targets var targets = Targets.Where(e => e.CategoryId == (int)CategoryID.Entity && e.IsNpc && !e.IsContainer && e.GroupId != (int)Group.LargeCollidableStructure); // Get the closest high value target var highValueTarget = targets.Where(t => t.TargetValue.HasValue && t.Distance < distance).OrderByDescending(t => t.TargetValue.Value).ThenBy(OrderByLowestHealth()).ThenBy(t => t.Distance).FirstOrDefault(); // Get the closest low value target var lowValueTarget = targets.Where(t => !t.TargetValue.HasValue && t.Distance < distance).OrderBy(OrderByLowestHealth()).ThenBy(t => t.Distance).FirstOrDefault(); if (Settings.Instance.DontShootFrigatesWithSiegeorAutoCannons) { if (Cache.Instance.MissionWeaponGroupId == 55 || Cache.Instance.MissionWeaponGroupId == 508) { if (lowValueTarget != null && !lowValueFirst && lowValueTarget.Distance > (int)Distance.InsideThisRangeIsLIkelyToBeMostlyFrigates) { return(targets.Where(t => !t.TargetValue.HasValue && t.Distance > (int)Distance.InsideThisRangeIsLIkelyToBeMostlyFrigates && t.Distance < distance).OrderByDescending(t => t.Distance).FirstOrDefault()); } if (lowValueTarget != null && !lowValueFirst && lowValueTarget.Distance < (int)Distance.InsideThisRangeIsLIkelyToBeMostlyFrigates) { lowValueTarget = null; } } } if (lowValueFirst && lowValueTarget != null) { return(lowValueTarget); } if (!lowValueFirst && highValueTarget != null) { return(highValueTarget); } // Return either one or the other return(lowValueTarget ?? highValueTarget); }
public bool GetUnitToTarget(out List <WowUnit> possibleTargets) { if (TargetSwitchEvent.Run() && TargetSelectionLogic.SelectTarget(out List <WowUnit> possibleTargetsFromLogic)) { // move the priority unit to the start of the list if (PriorityTargets != null && PriorityTargets.Count > 0) { WowUnit priorityUnit = possibleTargetsFromLogic.FirstOrDefault(e => PriorityTargets.Any(x => x.Equals(e.Name, StringComparison.OrdinalIgnoreCase))); if (priorityUnit != null) { int index = possibleTargetsFromLogic.IndexOf(priorityUnit); possibleTargetsFromLogic.RemoveAt(index); possibleTargetsFromLogic.Insert(0, priorityUnit); } } possibleTargets = possibleTargetsFromLogic; return(true); } possibleTargets = null; return(false); }