using Microsoft.Xna.Framework; using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; using Terraria.Audio; namespace CalamityMod.Projectiles.Rogue { public class SphereBladed : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Rogue"; public override void SetStaticDefaults() { ProjectileID.Sets.TrailCacheLength[Projectile.type] = 10; ProjectileID.Sets.TrailingMode[Projectile.type] = 0; } public override void SetDefaults() { Projectile.width = 20; Projectile.height = 20; Projectile.friendly = true; Projectile.tileCollide = true; Projectile.ignoreWater = true; Projectile.penetrate = -1; Projectile.extraUpdates = 1; Projectile.DamageType = RogueDamageClass.Instance; Projectile.usesIDStaticNPCImmunity = true; Projectile.idStaticNPCHitCooldown = 10; Projectile.timeLeft = 300; Projectile.tileCollide = false; } public override void AI() { Lighting.AddLight(Projectile.Center, 1f, 0f, 0f); if (Main.rand.NextBool(5)) { Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, 229, Projectile.velocity.X * 0.5f, Projectile.velocity.Y * 0.5f, 100); } if (Projectile.soundDelay == 0) { Projectile.soundDelay = 8; SoundEngine.PlaySound(SoundID.Item7, Projectile.position); } if (Projectile.ai[0] == 0f) { Projectile.ai[1] += 1f; if (Projectile.ai[1] >= 25f) { Projectile.ai[0] = 1f; Projectile.ai[1] = 0f; Projectile.netUpdate = true; } } else { float num42 = 16f; float num43 = 3.2f; Vector2 vector2 = new Vector2(Projectile.position.X + (float)Projectile.width * 0.5f, Projectile.position.Y + (float)Projectile.height * 0.5f); float num44 = Main.player[Projectile.owner].position.X + (float)(Main.player[Projectile.owner].width / 2) - vector2.X; float num45 = Main.player[Projectile.owner].position.Y + (float)(Main.player[Projectile.owner].height / 2) - vector2.Y; float num46 = (float)Math.Sqrt((double)(num44 * num44 + num45 * num45)); if (num46 > 3000f) { Projectile.Kill(); } num46 = num42 / num46; num44 *= num46; num45 *= num46; if (Projectile.velocity.X < num44) { Projectile.velocity.X = Projectile.velocity.X + num43; if (Projectile.velocity.X < 0f && num44 > 0f) { Projectile.velocity.X = Projectile.velocity.X + num43; } } else if (Projectile.velocity.X > num44) { Projectile.velocity.X = Projectile.velocity.X - num43; if (Projectile.velocity.X > 0f && num44 < 0f) { Projectile.velocity.X = Projectile.velocity.X - num43; } } if (Projectile.velocity.Y < num45) { Projectile.velocity.Y = Projectile.velocity.Y + num43; if (Projectile.velocity.Y < 0f && num45 > 0f) { Projectile.velocity.Y = Projectile.velocity.Y + num43; } } else if (Projectile.velocity.Y > num45) { Projectile.velocity.Y = Projectile.velocity.Y - num43; if (Projectile.velocity.Y > 0f && num45 < 0f) { Projectile.velocity.Y = Projectile.velocity.Y - num43; } } if (Main.myPlayer == Projectile.owner) { Rectangle rectangle = new Rectangle((int)Projectile.position.X, (int)Projectile.position.Y, Projectile.width, Projectile.height); Rectangle value2 = new Rectangle((int)Main.player[Projectile.owner].position.X, (int)Main.player[Projectile.owner].position.Y, Main.player[Projectile.owner].width, Main.player[Projectile.owner].height); if (rectangle.Intersects(value2)) { Projectile.Kill(); } } } Projectile.rotation += 0.5f; } public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { SoundEngine.PlaySound(SoundID.NPCHit34, Projectile.position); } public override bool PreDraw(ref Color lightColor) { CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 1); return false; } } }