diff --git a/Items/Weapons/Magic/TheDanceofLight.cs b/Items/Weapons/Magic/TheDanceofLight.cs index ebc6569e77..56f1897a08 100644 --- a/Items/Weapons/Magic/TheDanceofLight.cs +++ b/Items/Weapons/Magic/TheDanceofLight.cs @@ -60,8 +60,8 @@ namespace CalamityMod.Items.Weapons.Magic public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { - int numProjs = 2; - for(int i = 0; i < numProjs; ++i) + Projectile[] pair = new Projectile[2]; + for(int i = 0; i < 2; ++i) { // Pick a random direction somewhere behind the player float shootAngle = (float)Math.Atan2(speedY, speedX); @@ -73,8 +73,13 @@ namespace CalamityMod.Items.Weapons.Magic float randSpeed = Main.rand.NextFloat(1f - SpeedRandomness, 1f + SpeedRandomness); float randAngle = Main.rand.NextFloat(-Inaccuracy, Inaccuracy); Vector2 velocity = randSpeed * new Vector2(speedX, speedY).RotatedBy(randAngle); - Projectile.NewProjectileDirect(spawnPos, velocity, type, damage, knockBack, player.whoAmI); + Projectile p = Projectile.NewProjectileDirect(spawnPos, velocity, type, damage, knockBack, player.whoAmI); + pair[i] = p; } + + // Pair the swords up so they home in on each other + pair[0].ai[1] = pair[1].whoAmI + 1f; + pair[1].ai[1] = pair[0].whoAmI + 1f; return false; } diff --git a/Projectiles/Magic/LightBlade.cs b/Projectiles/Magic/LightBlade.cs index 13c78bf28d..0d1611c024 100644 --- a/Projectiles/Magic/LightBlade.cs +++ b/Projectiles/Magic/LightBlade.cs @@ -9,10 +9,13 @@ namespace CalamityMod.Projectiles.Magic { public class LightBlade : ModProjectile { - private const int Lifetime = 180; + private const int Lifetime = 300; private const int NumAfterimages = 8; private const float LightBrightness = 0.7f; private const int DustID = 175; + const float SwordHomingStrength = 30f; + const float EnemyHomingStrength = 70f; + private Color lightColor = Color.White; public override void SetStaticDefaults() @@ -58,8 +61,23 @@ namespace CalamityMod.Projectiles.Magic else Lighting.AddLight(projectile.Center, lightColor.ToVector3() * LightBrightness); - // The projectile never slows down, even as it tries to curve towards enemies - CalamityGlobalProjectile.HomeInOnNPC(projectile, true, 1000f, projectile.ai[0], 80f); + // Home in on the paired sword, if one is defined and it exists + if (projectile.ai[1] > 0f) + { + Projectile paired = Main.projectile[(int)(projectile.ai[1] - 1)]; + if (paired is null || !paired.active || paired.type != ModContent.ProjectileType()) + projectile.ai[1] = 0f; + else + { + Vector2 homingVec = projectile.DirectionTo(paired.Center) * projectile.ai[0]; + projectile.velocity = (projectile.velocity * (SwordHomingStrength - 1f) + homingVec) / SwordHomingStrength; + } + } + + // Also weakly home in on nearby enemies + CalamityGlobalProjectile.HomeInOnNPC(projectile, true, 1000f, projectile.ai[0], EnemyHomingStrength); + + // The projectile never slows down, even as it tries to curve towards enemies and its paired sword. float currentSpeed = projectile.velocity.Length(); projectile.velocity *= projectile.ai[0] / currentSpeed; }