using System; using CalamityMod.Buffs.StatDebuffs; using CalamityMod.DataStructures; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Magic { public class Ancient2 : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Magic"; public override string Texture => "CalamityMod/Projectiles/Magic/Ancient"; public override void SetStaticDefaults() { Main.projFrames[Projectile.type] = 6; } public override void SetDefaults() { Projectile.width = 50; Projectile.height = 50; Projectile.friendly = true; Projectile.ignoreWater = true; Projectile.DamageType = DamageClass.Magic; Projectile.penetrate = 4; Projectile.extraUpdates = 12; Projectile.timeLeft = 30; Projectile.usesLocalNPCImmunity = true; Projectile.localNPCHitCooldown = 6; Projectile.scale = 0.5f; } public override void AI() { Lighting.AddLight(Projectile.Center, 0.3f, 0.25f, 0f); Projectile.frameCounter++; if (Projectile.frameCounter > 3) { Projectile.frame++; Projectile.frameCounter = 0; } if (Projectile.frame >= Main.projFrames[Projectile.type]) { Projectile.frame = 0; } Projectile.rotation += (Math.Abs(Projectile.velocity.X) + Math.Abs(Projectile.velocity.Y)) * 0.01f * (float)Projectile.direction; if (Projectile.ai[0] > 7f && Projectile.numUpdates % 2 == 0) { int dustType = 22; int idx = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, dustType, Projectile.velocity.X * 0.2f, Projectile.velocity.Y * 0.2f, 100, default, 1f); Dust dust = Main.dust[idx]; if (Main.rand.NextBool()) { dust.noGravity = true; dust.scale *= 2f; dust.velocity.X *= 2f; dust.velocity.Y *= 2f; } else { dust.scale *= 1.25f; } dust.velocity.X *= 3f; dust.velocity.Y *= 3f; idx = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, dustType, Projectile.velocity.X * 0.2f, Projectile.velocity.Y * 0.2f, 100, default, 1f); if (Main.rand.NextBool(3)) { dust.noGravity = true; dust.scale *= 2.5f; dust.velocity.X *= 1.5f; dust.velocity.Y *= 1.5f; } else { dust.scale *= 1.5f; } dust.velocity.X *= 1.1f; dust.velocity.Y *= 1.1f; } Projectile.ai[0] += 1f; Projectile.rotation += 0.3f * (float)Projectile.direction; } public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.AddBuff(ModContent.BuffType(), 180); public override void OnHitPlayer(Player target, Player.HurtInfo info) => target.AddBuff(ModContent.BuffType(), 180); public override bool PreDraw(ref Color lightColor) { Texture2D texture = ModContent.Request(Texture).Value; Vector2 drawPos = Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); int height = texture.Height / Main.projFrames[Projectile.type]; int frameHeight = height * Projectile.frame; Rectangle rectangle = new Rectangle(0, frameHeight, texture.Width, height); Vector2 origin = new Vector2(texture.Width / 2f, height / 2f); Main.EntitySpriteDraw(texture, drawPos, new Microsoft.Xna.Framework.Rectangle?(rectangle), lightColor, Projectile.rotation, origin, Projectile.scale, SpriteEffects.None, 0); // Dust effects Circle dustCircle = new Circle(Projectile.Center, Projectile.width / 2); for (int i = 0; i < 20; i++) { // Dust Vector2 dustPos = dustCircle.RandomPointInCircle(); if ((dustPos - Projectile.Center).Length() > 48) { int dustIndex = Dust.NewDust(dustPos, 1, 1, DustID.Pot); Main.dust[dustIndex].noGravity = true; Main.dust[dustIndex].fadeIn = 1f; Vector2 dustVelocity = Projectile.Center - Main.dust[dustIndex].position; float distToCenter = dustVelocity.Length(); dustVelocity.Normalize(); dustVelocity = dustVelocity.RotatedBy(MathHelper.ToRadians(-90f)); dustVelocity *= distToCenter * 0.04f; Main.dust[dustIndex].velocity = dustVelocity; } } return false; } } }