using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Rogue { public class WrathwingFireball : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Rogue"; public override void SetStaticDefaults() { Main.projFrames[Projectile.type] = 5; ProjectileID.Sets.TrailCacheLength[Projectile.type] = 20; ProjectileID.Sets.TrailingMode[Projectile.type] = 2; } public override void SetDefaults() { Projectile.width = 34; Projectile.height = 34; Projectile.friendly = true; Projectile.ignoreWater = true; Projectile.alpha = 255; Projectile.penetrate = 1; Projectile.timeLeft = 180; Projectile.aiStyle = ProjAIStyleID.Arrow; AIType = ProjectileID.DD2BetsyFireball; Projectile.DamageType = RogueDamageClass.Instance; } public override void AI() { // Cancel out the first ten frames of Betsy fireball gravity, and half of all gravity thereafter Projectile.velocity.Y -= 0.1f; // Animation Projectile.frameCounter++; if (Projectile.frameCounter > 4) { Projectile.frame++; Projectile.frameCounter = 0; } if (Projectile.frame >= Main.projFrames[Projectile.type]) Projectile.frame = 0; // Keep the fireball rotated the correct way because the sheet faces down, not up Projectile.rotation += MathHelper.Pi; } public override Color? GetAlpha(Color lightColor) => new Color(200, 200, 200, Projectile.alpha); public override bool PreDraw(ref Color lightColor) { Texture2D texture = ModContent.Request(Texture).Value; int frameHeight = texture.Height / Main.projFrames[Projectile.type]; int frameY = frameHeight * Projectile.frame; Rectangle rectangle = new Rectangle(0, frameY, texture.Width, frameHeight); if (CalamityConfig.Instance.Afterimages) { for (int i = 0; i < Projectile.oldPos.Length; i++) { Vector2 drawPos = Projectile.oldPos[i] + Projectile.Size / 2f - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); Color color2 = Projectile.GetAlpha(lightColor) * ((float)(Projectile.oldPos.Length - i) / (float)Projectile.oldPos.Length); Main.spriteBatch.Draw(texture, drawPos, new Microsoft.Xna.Framework.Rectangle?(rectangle), color2, Projectile.rotation, rectangle.Size() / 2f, Projectile.scale, SpriteEffects.None, 0); } } Main.spriteBatch.Draw(texture, Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, frameY, texture.Width, frameHeight)), Projectile.GetAlpha(lightColor), Projectile.rotation, new Vector2((float)texture.Width / 2f, (float)frameHeight / 2f), Projectile.scale, SpriteEffects.None, 0); return false; } // Expand hitbox and explode on hit. public override void Kill(int timeLeft) { Projectile.ExpandHitboxBy(144); // Allow infinite piercing and ignoring iframes for this one extra AoE hit Projectile.maxPenetrate = -1; Projectile.penetrate = -1; Projectile.usesLocalNPCImmunity = true; Projectile.localNPCHitCooldown = -1; Projectile.Damage(); for (int i = 0; i < 2; i++) Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, 55, 0f, 0f, 50, default, 1.5f); for (int i = 0; i < 20; i++) { int d = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, 55, 0f, 0f, 0, default, 2.5f); Main.dust[d].noGravity = true; Main.dust[d].velocity *= 3f; d = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, 55, 0f, 0f, 50, default, 1.5f); Main.dust[d].velocity *= 2f; Main.dust[d].noGravity = true; } } } }