diff --git a/Projectiles/Magic/EnormousConsumingVortex.cs b/Projectiles/Magic/EnormousConsumingVortex.cs
index 9daf7066d8..6abcb381e3 100644
--- a/Projectiles/Magic/EnormousConsumingVortex.cs
+++ b/Projectiles/Magic/EnormousConsumingVortex.cs
@@ -110,7 +110,7 @@ namespace CalamityMod.Projectiles.Magic
public void TargetingMovement()
{
- NPC potentialTarget = projectile.Center.ClosestNPCAt(1500f, true);
+ NPC potentialTarget = projectile.Center.ClosestNPCAt(1500f, true, true);
if (potentialTarget != null)
{
projectile.velocity = (projectile.velocity * 5f + projectile.DirectionTo(potentialTarget.Center) * 7f) / 6f;
@@ -153,7 +153,7 @@ namespace CalamityMod.Projectiles.Magic
}
if (Main.myPlayer == projectile.owner)
{
- NPC closestTarget = projectile.Center.ClosestNPCAt(1600f, true);
+ NPC closestTarget = projectile.Center.ClosestNPCAt(1600f, true, true);
for (int i = 0; i < 12; i++)
{
float rotation = Main.rand.NextFloat(MathHelper.TwoPi);
diff --git a/Projectiles/Magic/EternityBook.cs b/Projectiles/Magic/EternityBook.cs
index d1ded915c0..66419f62ed 100644
--- a/Projectiles/Magic/EternityBook.cs
+++ b/Projectiles/Magic/EternityBook.cs
@@ -34,7 +34,7 @@ namespace CalamityMod.Projectiles.Magic
projectile.ai[0]++;
if (projectile.ai[0] == 1f)
{
- NPC target = projectile.Center.ClosestNPCAt(4400f, true);
+ NPC target = projectile.Center.ClosestNPCAt(4400f, true, true);
if (target != null)
{
diff --git a/Projectiles/Magic/EternityHex.cs b/Projectiles/Magic/EternityHex.cs
index 63e7f91b3d..fc60339ed0 100644
--- a/Projectiles/Magic/EternityHex.cs
+++ b/Projectiles/Magic/EternityHex.cs
@@ -40,7 +40,7 @@ namespace CalamityMod.Projectiles.Magic
if (!target.active)
{
- NPC potentialNPC = projectile.Center.ClosestNPCAt(4400f, true);
+ NPC potentialNPC = projectile.Center.ClosestNPCAt(4400f, true, true);
if (potentialNPC != null)
{
projectile.ai[0] = potentialNPC.whoAmI;
diff --git a/Projectiles/Magic/SubsumingTentacle.cs b/Projectiles/Magic/SubsumingTentacle.cs
index bf66907557..e6ab77c645 100644
--- a/Projectiles/Magic/SubsumingTentacle.cs
+++ b/Projectiles/Magic/SubsumingTentacle.cs
@@ -70,7 +70,7 @@ namespace CalamityMod.Projectiles.Magic
projectile.tileCollide = false;
}
- NPC closestTarget = projectile.Center.ClosestNPCAt(MaxEnemyDistance, true);
+ NPC closestTarget = projectile.Center.ClosestNPCAt(MaxEnemyDistance, true, true);
if (closestTarget != null)
{
HomingMovement(closestTarget);
diff --git a/Projectiles/Magic/Vortex.cs b/Projectiles/Magic/Vortex.cs
index 8c8831843c..390bd05184 100644
--- a/Projectiles/Magic/Vortex.cs
+++ b/Projectiles/Magic/Vortex.cs
@@ -80,7 +80,7 @@ namespace CalamityMod.Projectiles.Magic
// Attempt to find a target if the projectile has none.
if (TargetIndex == -1 && TargetCheckCooldown <= 0f)
{
- NPC potentialTarget = projectile.Center.ClosestNPCAt(targetCheckDistance, true);
+ NPC potentialTarget = projectile.Center.ClosestNPCAt(targetCheckDistance, true, true);
if (potentialTarget != null)
TargetIndex = potentialTarget.whoAmI;
projectile.netUpdate = true;
diff --git a/Projectiles/Ranged/ExoLightBurst.cs b/Projectiles/Ranged/ExoLightBurst.cs
index f6545889c5..dc68a71e89 100644
--- a/Projectiles/Ranged/ExoLightBurst.cs
+++ b/Projectiles/Ranged/ExoLightBurst.cs
@@ -50,7 +50,7 @@ namespace CalamityMod.Projectiles.Ranged
}
if (projectile.ai[0] == 0f)
{
- NPC potentialTarget = projectile.Center.ClosestNPCAt(MaxDistanceFromTarget, true);
+ NPC potentialTarget = projectile.Center.ClosestNPCAt(MaxDistanceFromTarget, true, true);
if (potentialTarget != null)
{
if (projectile.Distance(potentialTarget.Center) > MinDistanceFromTarget)
diff --git a/Projectiles/Rogue/CelestialReaperProjectile.cs b/Projectiles/Rogue/CelestialReaperProjectile.cs
index a005b94e1b..df056ca2c8 100644
--- a/Projectiles/Rogue/CelestialReaperProjectile.cs
+++ b/Projectiles/Rogue/CelestialReaperProjectile.cs
@@ -53,7 +53,7 @@ namespace CalamityMod.Projectiles.Rogue
public override bool? CanHitNPC(NPC target)
{
- if (HomingCooldown != 0)
+ if (HomingCooldown > 0)
{
return false;
}
@@ -62,7 +62,7 @@ namespace CalamityMod.Projectiles.Rogue
public override bool CanHitPvp(Player target)
{
- return HomingCooldown == 0;
+ return HomingCooldown <= 0;
}
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
diff --git a/Utilities/CalamityUtils.cs b/Utilities/CalamityUtils.cs
index 203d628e24..ecbf80b629 100644
--- a/Utilities/CalamityUtils.cs
+++ b/Utilities/CalamityUtils.cs
@@ -371,8 +371,9 @@ namespace CalamityMod
///
/// The position where we wish to check for nearby NPCs
/// Maximum amount of pixels to check around the origin
+ /// Whether to ignore tiles when finding a target or not
/// Whether bosses should be prioritized in targetting or not
- public static NPC ClosestNPCAt(this Vector2 origin, float maxDistanceToCheck, bool bossPriority = false)
+ public static NPC ClosestNPCAt(this Vector2 origin, float maxDistanceToCheck, bool ignoreTiles = true, bool bossPriority = false)
{
NPC closestTarget = null;
float distance = maxDistanceToCheck;
@@ -386,7 +387,13 @@ namespace CalamityMod
continue;
if (Main.npc[index].CanBeChasedBy(null, false))
{
- if (Vector2.Distance(origin, Main.npc[index].Center) < distance)
+ float extraDistance = (Main.npc[index].width / 2) + (Main.npc[index].height / 2);
+
+ bool canHit = true;
+ if (extraDistance < maxDistance && !ignoreTiles)
+ canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[index].Center, 1, 1);
+
+ if (Vector2.Distance(origin, Main.npc[index].Center) < (distance + extraDistance) && canHit)
{
if (Main.npc[index].boss)
bossFound = true;
@@ -402,7 +409,13 @@ namespace CalamityMod
{
if (Main.npc[index].CanBeChasedBy(null, false))
{
- if (Vector2.Distance(origin, Main.npc[index].Center) < distance)
+ float extraDistance = (Main.npc[index].width / 2) + (Main.npc[index].height / 2);
+
+ bool canHit = true;
+ if (extraDistance < maxDistance && !ignoreTiles)
+ canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[index].Center, 1, 1);
+
+ if (Vector2.Distance(origin, Main.npc[index].Center) < (distance + extraDistance) && canHit)
{
distance = Vector2.Distance(origin, Main.npc[index].Center);
closestTarget = Main.npc[index];
@@ -418,13 +431,14 @@ namespace CalamityMod
/// The position where we wish to check for nearby NPCs
/// Maximum amount of pixels to check around the origin
/// Owner of the minion
- public static NPC MinionHoming(this Vector2 origin, float maxDistanceToCheck, Player owner)
+ /// Whether to ignore tiles when finding a target or not
+ public static NPC MinionHoming(this Vector2 origin, float maxDistanceToCheck, Player owner, bool ignoreTiles = true)
{
if (owner.HasMinionAttackTargetNPC)
{
return Main.npc[owner.MinionAttackTargetNPC];
}
- return ClosestNPCAt(origin, maxDistanceToCheck);
+ return ClosestNPCAt(origin, maxDistanceToCheck, ignoreTiles);
}
///