TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ SearchForTarget() [2/3]

static TargetSearchResults Terraria.Utilities.NPCUtils.SearchForTarget ( NPC searcher,
Vector2 position,
TargetSearchFlag flags = TargetSearchFlag::All,
SearchFilter< Player > playerFilter = null,
SearchFilter< NPC > npcFilter = null )
inlinestatic

Definition at line 204 of file NPCUtils.cs.

205 {
206 //IL_0063: Unknown result type (might be due to invalid IL or missing references)
207 //IL_0066: Unknown result type (might be due to invalid IL or missing references)
208 //IL_00e8: Unknown result type (might be due to invalid IL or missing references)
209 //IL_00eb: Unknown result type (might be due to invalid IL or missing references)
210 //IL_0162: Unknown result type (might be due to invalid IL or missing references)
211 //IL_0167: Unknown result type (might be due to invalid IL or missing references)
212 //IL_0169: Unknown result type (might be due to invalid IL or missing references)
213 //IL_016a: Unknown result type (might be due to invalid IL or missing references)
214 //IL_018b: Unknown result type (might be due to invalid IL or missing references)
215 //IL_018e: Unknown result type (might be due to invalid IL or missing references)
216 float num = float.MaxValue;
217 int nearestNPCIndex = -1;
218 float num2 = float.MaxValue;
219 float nearestTankDistance = float.MaxValue;
220 int nearestTankIndex = -1;
221 TargetType tankType = TargetType.Player;
222 if (flags.HasFlag(TargetSearchFlag.NPCs))
223 {
224 for (int i = 0; i < 200; i++)
225 {
226 NPC nPC = Main.npc[i];
227 if (nPC.active && nPC.whoAmI != searcher.whoAmI && (npcFilter == null || npcFilter(nPC)))
228 {
229 float num3 = Vector2.DistanceSquared(position, nPC.Center);
230 if (num3 < num)
231 {
232 nearestNPCIndex = i;
233 num = num3;
234 }
235 }
236 }
237 }
238 if (flags.HasFlag(TargetSearchFlag.Players))
239 {
240 for (int j = 0; j < 255; j++)
241 {
242 Player player = Main.player[j];
243 if (!player.active || player.dead || player.ghost || (playerFilter != null && !playerFilter(player)))
244 {
245 continue;
246 }
247 float num4 = Vector2.Distance(position, player.Center);
248 float num5 = num4 - (float)player.aggro;
249 bool flag = searcher != null && player.npcTypeNoAggro[searcher.type];
250 if (searcher != null && flag && searcher.direction == 0)
251 {
252 num5 += 1000f;
253 }
254 if (num5 < num2)
255 {
257 num2 = num5;
259 tankType = TargetType.Player;
260 }
261 if (player.tankPet >= 0 && !flag)
262 {
263 Vector2 center = Main.projectile[player.tankPet].Center;
264 num4 = Vector2.Distance(position, center);
265 num5 = num4 - 200f;
266 if (num5 < num2 && num5 < 200f && Collision.CanHit(position, 0, 0, center, 0, 0))
267 {
269 num2 = num5;
271 tankType = TargetType.TankPet;
272 }
273 }
274 }
275 }
276 return new TargetSearchResults(searcher, nearestNPCIndex, (float)Math.Sqrt(num), nearestTankIndex, nearestTankDistance, num2, tankType);
277 }

References Terraria.Entity.active, Terraria.Player.aggro, Terraria.Collision.CanHit(), Terraria.Entity.Center, Terraria.Player.dead, Terraria.Player.ghost, Terraria.Main.npc, Terraria.Player.npcTypeNoAggro, Terraria.Main.player, Terraria.Main.projectile, and Terraria.Player.tankPet.

+ Here is the call graph for this function: