applied hitbox fix and ignoretiles parameter to ClosestNPCAt
This commit is contained in:
1 parent
f24dbb05a5
commit
464cd8ec17
8 files changed
+28
-14
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -371,8 +371,9 @@ namespace CalamityMod
|
||||
/// </summary>
|
||||
/// <param name="origin">The position where we wish to check for nearby NPCs</param>
|
||||
/// <param name="maxDistanceToCheck">Maximum amount of pixels to check around the origin</param>
|
||||
/// <param name="ignoreTiles">Whether to ignore tiles when finding a target or not</param>
|
||||
/// <param name="bossPriority">Whether bosses should be prioritized in targetting or not</param>
|
||||
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
|
||||
/// <param name="origin">The position where we wish to check for nearby NPCs</param>
|
||||
/// <param name="maxDistanceToCheck">Maximum amount of pixels to check around the origin</param>
|
||||
/// <param name="owner">Owner of the minion</param>
|
||||
public static NPC MinionHoming(this Vector2 origin, float maxDistanceToCheck, Player owner)
|
||||
/// <param name="ignoreTiles">Whether to ignore tiles when finding a target or not</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user