Fixed possible Timekeeper crash if the sibling projectile doesn't exists anymore.

This commit is contained in:
FyloZ 2020-07-19 22:51:57 -04:00
parent f188eb2757
commit 923c05a70a

View File

@ -23,7 +23,24 @@ namespace Decimation.Content.Projectiles.Boss.DuneWyrm
set => projectile.localAI[1] = value; set => projectile.localAI[1] = value;
} }
private Projectile SiblingProjectile => !IsChild && Sibling >= 0 && Sibling < Main.projectile.Length ? Main.projectile[Sibling] : null; private Projectile SiblingProjectile
{
get
{
if (Sibling >= 0 && Sibling < Main.projectile.Length)
{
Projectile sibling = Main.projectile[Sibling];
if (sibling.active)
{
Main.NewText("test");
return sibling;
}
}
return null;
}
}
private int Counter private int Counter
{ {
@ -45,14 +62,12 @@ namespace Decimation.Content.Projectiles.Boss.DuneWyrm
projectile.penetrate = -1; projectile.penetrate = -1;
projectile.aiStyle = -1; projectile.aiStyle = -1;
projectile.timeLeft = 600; projectile.timeLeft = 600;
Sibling = -1; Sibling = -1;
} }
public override bool PreKill(int timeLeft) public override bool PreKill(int timeLeft)
{ {
SiblingProjectile?.Kill(); SiblingProjectile?.Kill();
return true; return true;
} }
@ -89,7 +104,6 @@ namespace Decimation.Content.Projectiles.Boss.DuneWyrm
Vector2 siblingVelocity = parentVelocity * new Vector2(1, -1); Vector2 siblingVelocity = parentVelocity * new Vector2(1, -1);
SiblingProjectile.velocity = siblingVelocity.RotatedBy(Rotation); SiblingProjectile.velocity = siblingVelocity.RotatedBy(Rotation);
if (Initialization) if (Initialization)
{ {
Vector2 offset = new Vector2(projectile.position.X - SiblingProjectile.position.X, -16); Vector2 offset = new Vector2(projectile.position.X - SiblingProjectile.position.X, -16);
@ -107,8 +121,11 @@ namespace Decimation.Content.Projectiles.Boss.DuneWyrm
} }
Lighting.AddLight(projectile.Center, _dustColor); Lighting.AddLight(projectile.Center, _dustColor);
Dust dust = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height, 229, projectile.velocity.X * 0.2f,
Dust dust = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height, 229,
projectile.velocity.X * 0.2f,
projectile.velocity.Y * 0.2f, 100, default, 1f * projectile.scale); projectile.velocity.Y * 0.2f, 100, default, 1f * projectile.scale);
dust.noGravity = true; dust.noGravity = true;
} }
} }