using CalamityMod.Buffs.DamageOverTime; using Microsoft.Xna.Framework; using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; using Terraria.Audio; namespace CalamityMod.Projectiles.Magic { public class BeastScythe : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Magic"; public override void SetStaticDefaults() { ProjectileID.Sets.TrailCacheLength[Projectile.type] = 8; ProjectileID.Sets.TrailingMode[Projectile.type] = 1; } public override void SetDefaults() { Projectile.width = 50; Projectile.height = 54; Projectile.alpha = 255; Projectile.friendly = true; Projectile.ignoreWater = true; Projectile.netImportant = true; Projectile.penetrate = 1; Projectile.timeLeft = 600; Projectile.DamageType = DamageClass.Magic; Projectile.extraUpdates = 1; Projectile.tileCollide = false; } public override void AI() { if (Projectile.alpha > 0) { Projectile.alpha -= 20; } if (Projectile.alpha < 0) { Projectile.alpha = 0; } Projectile.rotation += 0.5f; Lighting.AddLight(Projectile.Center, 0.35f, 0f, 0.35f); if (Main.rand.NextBool(3)) { Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, 173, Projectile.velocity.X * 0.25f, Projectile.velocity.Y * 0.25f); } Projectile.ai[0] += 1f; if (Projectile.ai[0] <= 30f) { Projectile.velocity *= 0.999f; } if (Main.myPlayer == Projectile.owner && Projectile.ai[0] == 30f) { if (Main.player[Projectile.owner].channel) { float num115 = 20f; Vector2 vector10 = new Vector2(Projectile.position.X + (float)Projectile.width * 0.5f, Projectile.position.Y + (float)Projectile.height * 0.5f); float num116 = (float)Main.mouseX + Main.screenPosition.X - vector10.X; float num117 = (float)Main.mouseY + Main.screenPosition.Y - vector10.Y; if (Main.player[Projectile.owner].gravDir == -1f) { num117 = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY - vector10.Y; } float num118 = (float)Math.Sqrt((double)(num116 * num116 + num117 * num117)); num118 = (float)Math.Sqrt((double)(num116 * num116 + num117 * num117)); if (num118 > num115) { num118 = num115 / num118; num116 *= num118; num117 *= num118; int num119 = (int)(num116 * 1000f); int num120 = (int)(Projectile.velocity.X * 1000f); int num121 = (int)(num117 * 1000f); int num122 = (int)(Projectile.velocity.Y * 1000f); if (num119 != num120 || num121 != num122) { Projectile.netUpdate = true; } Projectile.velocity.X = num116; Projectile.velocity.Y = num117; } else { int num123 = (int)(num116 * 1000f); int num124 = (int)(Projectile.velocity.X * 1000f); int num125 = (int)(num117 * 1000f); int num126 = (int)(Projectile.velocity.Y * 1000f); if (num123 != num124 || num125 != num126) { Projectile.netUpdate = true; } Projectile.velocity.X = num116; Projectile.velocity.Y = num117; } } else { Projectile.netUpdate = true; float num127 = 20f; Vector2 vector11 = new Vector2(Projectile.position.X + (float)Projectile.width * 0.5f, Projectile.position.Y + (float)Projectile.height * 0.5f); float num128 = (float)Main.mouseX + Main.screenPosition.X - vector11.X; float num129 = (float)Main.mouseY + Main.screenPosition.Y - vector11.Y; if (Main.player[Projectile.owner].gravDir == -1f) { num129 = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY - vector11.Y; } float num130 = (float)Math.Sqrt((double)(num128 * num128 + num129 * num129)); if (num130 == 0f || Projectile.ai[0] < 0f) { vector11 = new Vector2(Main.player[Projectile.owner].position.X + (float)(Main.player[Projectile.owner].width / 2), Main.player[Projectile.owner].position.Y + (float)(Main.player[Projectile.owner].height / 2)); num128 = Projectile.position.X + (float)Projectile.width * 0.5f - vector11.X; num129 = Projectile.position.Y + (float)Projectile.height * 0.5f - vector11.Y; num130 = (float)Math.Sqrt((double)(num128 * num128 + num129 * num129)); } num130 = num127 / num130; num128 *= num130; num129 *= num130; Projectile.velocity.X = num128; Projectile.velocity.Y = num129; } } if (Projectile.ai[0] >= 30f) { Projectile.velocity *= 1.001f; CalamityUtils.HomeInOnNPC(Projectile, true, 200f, 12f, 20f); } } public override void Kill(int timeLeft) { SoundEngine.PlaySound(SoundID.Item14, Projectile.position); Projectile.position = Projectile.Center; Projectile.width = Projectile.height = 100; Projectile.position.X = Projectile.position.X - (float)(Projectile.width / 2); Projectile.position.Y = Projectile.position.Y - (float)(Projectile.height / 2); Projectile.maxPenetrate = -1; Projectile.penetrate = -1; Projectile.usesLocalNPCImmunity = true; Projectile.localNPCHitCooldown = 10; Projectile.damage /= 2; Projectile.Damage(); bool flag = WorldGen.SolidTile(Framing.GetTileSafely((int)Projectile.position.X / 16, (int)Projectile.position.Y / 16)); for (int m = 0; m < 4; m++) { Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, 173, 0f, 0f, 100, default, 1.5f); } for (int n = 0; n < 4; n++) { int num10 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, 173, 0f, 0f, 0, default, 2.5f); Main.dust[num10].noGravity = true; Main.dust[num10].velocity *= 3f; if (flag) { Main.dust[num10].noLight = true; } num10 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, 173, 0f, 0f, 100, default, 1.5f); Main.dust[num10].velocity *= 2f; Main.dust[num10].noGravity = true; if (flag) { Main.dust[num10].noLight = true; } } } public override bool PreDraw(ref Color lightColor) { CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 2); return false; } } }