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

◆ FindTargetWithLineOfSight()

int Terraria.Projectile.FindTargetWithLineOfSight ( float maxRange = 800f)
inline

Finds the closest NPC to this projectile which can be targeted and which it has line of sight to.

Parameters
maxRangeThe maximum range at which this projectile should search out a target, measured in pixels.
Defaults to 800 (50 tiles). Each tile, for reference, measures out to be 16x16 pixels.
Returns
The index, in F:Terraria.Main.npc, of the closest targetable NPC.

Definition at line 48144 of file Projectile.cs.

48145 {
48146 //IL_0033: Unknown result type (might be due to invalid IL or missing references)
48147 //IL_0045: Unknown result type (might be due to invalid IL or missing references)
48148 //IL_0057: Unknown result type (might be due to invalid IL or missing references)
48149 float num = maxRange;
48150 int result = -1;
48151 for (int i = 0; i < 200; i++)
48152 {
48153 NPC nPC = Main.npc[i];
48154 bool flag = nPC.CanBeChasedBy(this);
48155 if (localNPCImmunity[i] != 0)
48156 {
48157 flag = false;
48158 }
48159 if (flag)
48160 {
48161 float num2 = Distance(Main.npc[i].Center);
48162 if (num2 < num && Collision.CanHit(position, width, height, nPC.position, nPC.width, nPC.height))
48163 {
48164 num = num2;
48165 result = i;
48166 }
48167 }
48168 }
48169 return result;
48170 }
float Distance(Vector2 Other)
Definition Entity.cs:275
Vector2 position
The position of this Entity in world coordinates.
Definition Entity.cs:28
int width
The width of this Entity's hitbox, in pixels.
Definition Entity.cs:46
int height
The height of this Entity's hitbox, in pixels.
Definition Entity.cs:51

References Terraria.Collision.CanHit(), and Terraria.Main.npc.

Referenced by Terraria.Projectile.Damage(), and Terraria.Projectile.HandleMovement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: