diff --git a/GradiusHelper.cs b/GradiusHelper.cs index 36280e2..d8b7afb 100644 --- a/GradiusHelper.cs +++ b/GradiusHelper.cs @@ -323,7 +323,7 @@ public static int FindTarget(Projectile projectile, Vector2 ownPosition, float r float enemyDistance = Vector2.Distance(ownPosition, selectNpc.Center); if (enemyDistance <= range && distance < shortestDistance && selectNpc.CanBeChasedBy() && - (selectNpc.modNPC.CanBeHitByProjectile(projectile) ?? true) && + (NPCLoader.CanBeHitByProjectile(selectNpc, projectile) ?? true) && (!needLineOfSight || Collision.CanHit(projectile.Center, 1, 1, selectNpc.Center, 1, 1))) { shortestDistance = distance; diff --git a/Projectiles/Melee/AlliedZalk.cs b/Projectiles/Melee/AlliedZalk.cs index 9d5a8a7..d9831fa 100644 --- a/Projectiles/Melee/AlliedZalk.cs +++ b/Projectiles/Melee/AlliedZalk.cs @@ -39,8 +39,12 @@ public override void SetDefaults() public override void AI() { - AnimateSprite(); - Movement(); + if (IsMotherValid) + { + AnimateSprite(); + Movement(); + } + else projectile.Kill(); } public override void Kill(int timeLeft) @@ -49,7 +53,7 @@ public override void Kill(int timeLeft) mod.GetGoreSlot("Gores/GradiusExplode"), .5f); Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Enemies/Gradius2Death"), projectile.Center); - ActualMotherProjectile.alliedZalks.Remove(projectile); + if (IsMotherValid) ActualMotherProjectile.alliedZalks.Remove(projectile); } private void AnimateSprite() @@ -81,5 +85,7 @@ private void Movement() private ZalkYoyoProjectile ActualMotherProjectile => MotherProjectile.modProjectile as ZalkYoyoProjectile; private int Numbering => ActualMotherProjectile.alliedZalks.IndexOf(projectile); + + private bool IsMotherValid => MotherProjectile.active && ActualMotherProjectile != null; } } \ No newline at end of file