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

◆ FindClosestPlayer() [2/2]

int Terraria.NPC.FindClosestPlayer ( out float distanceToPlayer)
inline

Definition at line 82899 of file NPC.cs.

82900 {
82901 //IL_0001: Unknown result type (might be due to invalid IL or missing references)
82902 //IL_0006: Unknown result type (might be due to invalid IL or missing references)
82903 //IL_0037: Unknown result type (might be due to invalid IL or missing references)
82904 //IL_003a: Unknown result type (might be due to invalid IL or missing references)
82905 //IL_0078: Unknown result type (might be due to invalid IL or missing references)
82906 //IL_007b: Unknown result type (might be due to invalid IL or missing references)
82907 Vector2 center = base.Center;
82908 float num = float.MaxValue;
82909 int num2 = -1;
82910 for (int i = 0; i < 255; i++)
82911 {
82912 Player player2 = Main.player[i];
82913 if (player2.active && !player2.dead && !player2.ghost)
82914 {
82915 float num3 = Vector2.DistanceSquared(center, player2.Center);
82916 if (num3 < num)
82917 {
82918 num = num3;
82919 num2 = i;
82920 }
82921 }
82922 }
82923 if (num2 < 0)
82924 {
82925 for (int j = 0; j < 255; j++)
82926 {
82927 Player player = Main.player[j];
82928 if (player.active)
82929 {
82930 float num4 = Vector2.DistanceSquared(center, player.Center);
82931 if (num4 < num)
82932 {
82933 num = num4;
82934 num2 = j;
82935 }
82936 }
82937 }
82938 }
82939 distanceToPlayer = (float)Math.Sqrt(num);
82940 return num2;
82941 }

References Terraria.Entity.active, Terraria.Entity.Center, and Terraria.Main.player.