using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using Terraria; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Magic { public class MagneticOrb : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Magic"; private const int Lifetime = 120; private const float FramesPerBeam = 12f; public override void SetStaticDefaults() { Main.projFrames[Projectile.type] = 5; } public override void SetDefaults() { Projectile.width = 38; Projectile.height = 38; Projectile.friendly = true; Projectile.tileCollide = false; Projectile.ignoreWater = true; Projectile.penetrate = 1; Projectile.timeLeft = 120; Projectile.DamageType = DamageClass.Magic; } public override bool? CanDamage() => false; public override void AI() { // Drift to a stop after being launched Projectile.velocity *= 0.972f; // On frame 1, pick a random offset to use for the firing pattern. if (Projectile.timeLeft == Lifetime) Projectile.localAI[1] = Main.rand.NextFloat(0f, FramesPerBeam); // What in the hell does this code do if (Projectile.velocity.X > 0f) { Projectile.rotation += (Math.Abs(Projectile.velocity.Y) + Math.Abs(Projectile.velocity.X)) * 0.001f; } else { Projectile.rotation -= (Math.Abs(Projectile.velocity.Y) + Math.Abs(Projectile.velocity.X)) * 0.001f; } // Update animation Projectile.frameCounter++; if (Projectile.frameCounter > 6) { Projectile.frameCounter = 0; Projectile.frame++; if (Projectile.frame > 4) { Projectile.frame = 0; } } CalamityUtils.MagnetSphereHitscan(Projectile, 300f, 8f, FramesPerBeam, 1, ModContent.ProjectileType(), 1D, true); } public override Color? GetAlpha(Color lightColor) { if (Projectile.timeLeft < 30) { float num7 = (float)Projectile.timeLeft / 30f; Projectile.alpha = (int)(255f - 255f * num7); } return new Color(255 - Projectile.alpha, 255 - Projectile.alpha, 255 - Projectile.alpha, 0); } public override bool PreDraw(ref Color lightColor) { Texture2D texture2D13 = ModContent.Request(Texture).Value; int num214 = ModContent.Request(Texture).Value.Height / Main.projFrames[Projectile.type]; int y6 = num214 * Projectile.frame; Main.spriteBatch.Draw(texture2D13, Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, y6, texture2D13.Width, num214)), Projectile.GetAlpha(lightColor), Projectile.rotation, new Vector2((float)texture2D13.Width / 2f, (float)num214 / 2f), Projectile.scale, SpriteEffects.None, 0); return false; } } }