public static TargetSearchResults SearchForTarget(NPC searcher, TargetSearchFlag flags = TargetSearchFlag.All, SearchFilter <Player> playerFilter = null, SearchFilter <NPC> npcFilter = null) { return(SearchForTarget(searcher, searcher.Center, flags, playerFilter, npcFilter)); }
public static TargetSearchResults SearchForTarget(NPC searcher, Vector2 position, TargetSearchFlag flags = TargetSearchFlag.All, SearchFilter <Player> playerFilter = null, SearchFilter <NPC> npcFilter = null) { float num = float.MaxValue; int nearestNPCIndex = -1; float num2 = float.MaxValue; float nearestTankDistance = float.MaxValue; int nearestTankIndex = -1; TargetType tankType = TargetType.Player; if (flags.HasFlag(TargetSearchFlag.NPCs)) { for (int i = 0; i < 200; i++) { NPC nPC = Main.npc[i]; if (nPC.active && nPC.whoAmI != searcher.whoAmI && (npcFilter == null || npcFilter(nPC))) { float num3 = Vector2.DistanceSquared(position, nPC.Center); if (num3 < num) { nearestNPCIndex = i; num = num3; } } } } if (flags.HasFlag(TargetSearchFlag.Players)) { for (int j = 0; j < 255; j++) { Player player = Main.player[j]; if (!player.active || player.dead || player.ghost || (playerFilter != null && !playerFilter(player))) { continue; } float num4 = Vector2.Distance(position, player.Center); float num5 = num4 - (float)player.aggro; bool flag = searcher != null && player.npcTypeNoAggro[searcher.type]; if (searcher != null && flag && searcher.direction == 0) { num5 += 1000f; } if (num5 < num2) { nearestTankIndex = j; num2 = num5; nearestTankDistance = num4; tankType = TargetType.Player; } if (player.tankPet >= 0 && !flag) { Vector2 center = Main.projectile[player.tankPet].Center; num4 = Vector2.Distance(position, center); num5 = num4 - 200f; if (num5 < num2 && num5 < 200f && Collision.CanHit(position, 0, 0, center, 0, 0)) { nearestTankIndex = j; num2 = num5; nearestTankDistance = num4; tankType = TargetType.TankPet; } } } } return(new TargetSearchResults(searcher, nearestNPCIndex, (float)Math.Sqrt(num), nearestTankIndex, nearestTankDistance, num2, tankType)); }
public static TargetSearchResults SearchForTarget(Vector2 position, TargetSearchFlag flags = TargetSearchFlag.All, SearchFilter <Player> playerFilter = null, SearchFilter <NPC> npcFilter = null) { return(SearchForTarget(null, position, flags, playerFilter, npcFilter)); }