using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Dusts; using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; using Terraria.Audio; namespace CalamityMod.Projectiles.Ranged { public class AstralRound : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Ranged"; private float speed = 0f; public override void SetStaticDefaults() { ProjectileID.Sets.TrailCacheLength[Projectile.type] = 6; ProjectileID.Sets.TrailingMode[Projectile.type] = 0; } public override void SetDefaults() { Projectile.width = 4; Projectile.height = 4; Projectile.aiStyle = ProjAIStyleID.Arrow; Projectile.friendly = true; Projectile.DamageType = DamageClass.Ranged; Projectile.penetrate = 1; Projectile.timeLeft = 600; Projectile.light = 0.25f; Projectile.extraUpdates = 2; AIType = ProjectileID.Bullet; Projectile.Calamity().pointBlankShotDuration = CalamityGlobalProjectile.DefaultPointBlankDuration; } public override bool OnTileCollide(Vector2 oldVelocity) { Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height); SoundEngine.PlaySound(SoundID.Dig, Projectile.position); return true; } public override bool PreDraw(ref Color lightColor) { CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 1); return false; } public override bool PreAI() { Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.ToRadians(90f); Projectile.spriteDirection = Projectile.direction; Projectile.localAI[0] += 1f; if (Projectile.localAI[0] > 4f) { if (Main.rand.NextBool(2)) { int randomDust = Utils.SelectRandom(Main.rand, new int[] { ModContent.DustType(), ModContent.DustType() }); int astral = Dust.NewDust(Projectile.position, 1, 1, randomDust, 0f, 0f, 0, default, 0.5f); Main.dust[astral].alpha = Projectile.alpha; Main.dust[astral].velocity *= 0f; Main.dust[astral].noGravity = true; } } if (speed == 0f) speed = Projectile.velocity.Length(); CalamityUtils.HomeInOnNPC(Projectile, !Projectile.tileCollide, 200f, speed, 12f); return false; } public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { target.AddBuff(ModContent.BuffType(), 120); } } }