using Microsoft.Xna.Framework; using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; using Terraria.Audio; namespace CalamityMod.Projectiles.Magic { public class SerpentineHead : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Magic"; public override void SetStaticDefaults() { ProjectileID.Sets.NeedsUUID[Projectile.type] = true; } public override void SetDefaults() { Projectile.width = 14; Projectile.height = 16; Projectile.friendly = true; Projectile.ignoreWater = true; Projectile.netImportant = true; Projectile.penetrate = 5; Projectile.timeLeft = 600; Projectile.DamageType = DamageClass.Magic; Projectile.usesLocalNPCImmunity = true; Projectile.localNPCHitCooldown = 20; } public override void AI() { Lighting.AddLight(Projectile.Center, (255 - Projectile.alpha) * 0f / 255f, (255 - Projectile.alpha) * 0.55f / 255f, (255 - Projectile.alpha) * 0.55f / 255f); if (Projectile.alpha > 0) { Projectile.alpha -= 40; } if (Projectile.alpha < 0) { Projectile.alpha = 0; } int num114 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, 68, 0f, 0f, 100, default, 1.25f); Dust dust = Main.dust[num114]; dust.velocity *= 0.3f; Main.dust[num114].position.X = Projectile.position.X + (float)(Projectile.width / 2) + 4f + (float)Main.rand.Next(-4, 5); Main.dust[num114].position.Y = Projectile.position.Y + (float)(Projectile.height / 2) + (float)Main.rand.Next(-4, 5); Main.dust[num114].noGravity = true; Projectile.rotation = Projectile.velocity.ToRotation() + 1.57079637f; int direction = Projectile.direction; Projectile.direction = Projectile.spriteDirection = (Projectile.velocity.X > 0f) ? 1 : -1; if (direction != Projectile.direction) { Projectile.netUpdate = true; } float num1061 = MathHelper.Clamp(Projectile.localAI[0], 0f, 50f); Projectile.position = Projectile.Center; Projectile.scale = 1f + num1061 * 0.01f; Projectile.width = Projectile.height = (int)(10 * Projectile.scale); Projectile.Center = Projectile.position; Projectile.ai[0] += 1f; if (Projectile.ai[0] >= 20f && Projectile.ai[0] < 40f) { Projectile.velocity.Y = Projectile.velocity.Y + 0.3f; } else if (Projectile.ai[0] >= 40f && Projectile.ai[0] < 60f) { Projectile.velocity.Y = Projectile.velocity.Y - 0.3f; } else if (Projectile.ai[0] >= 60f) { Projectile.ai[0] = 0f; } if (Main.myPlayer == Projectile.owner && Projectile.ai[0] <= 0f) { if (Main.player[Projectile.owner].channel) { float num115 = 18f; 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 if (Projectile.ai[0] <= 0f) { Projectile.netUpdate = true; float num127 = 12f; 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.velocity.X == 0f && Projectile.velocity.Y == 0f) { Projectile.Kill(); } Projectile.ai[0] = 1f; } } if (Projectile.velocity.X != 0f || Projectile.velocity.Y != 0f) { Projectile.rotation = (float)Math.Atan2((double)Projectile.velocity.Y, (double)Projectile.velocity.X) + 1.57f; } if (Projectile.velocity.Y > 16f) { Projectile.velocity.Y = 16f; } } public override void Kill(int timeLeft) { SoundEngine.PlaySound(SoundID.Item10, Projectile.position); for (int k = 0; k < 8; k++) { int num114 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, 68, 0f, 0f, 100, default, 1.25f); Dust dust = Main.dust[num114]; dust.velocity *= 0.3f; Main.dust[num114].position.X = Projectile.position.X + (float)(Projectile.width / 2) + 4f + (float)Main.rand.Next(-4, 5); Main.dust[num114].position.Y = Projectile.position.Y + (float)(Projectile.height / 2) + (float)Main.rand.Next(-4, 5); Main.dust[num114].noGravity = true; } } } }