Skip to content

Commit

Permalink
Fix #258: Fix the exceptions that are occuring
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeeeeeeeeen committed Oct 15, 2021
1 parent 358e5c2 commit fbcf066
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion GradiusHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions Projectiles/Melee/AlliedZalk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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;
}
}

0 comments on commit fbcf066

Please sign in to comment.