using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Dusts; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; using Terraria.Audio; namespace CalamityMod.Projectiles.Typeless { public class AstralStar : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Typeless"; private int noTileHitCounter = 90; public override void SetStaticDefaults() { ProjectileID.Sets.TrailCacheLength[Projectile.type] = 10; ProjectileID.Sets.TrailingMode[Projectile.type] = 1; } public override void SetDefaults() { Projectile.width = 24; Projectile.height = 24; Projectile.friendly = true; Projectile.alpha = 50; Projectile.penetrate = 1; Projectile.tileCollide = false; Projectile.timeLeft = 300; } public override void AI() { if (Projectile.ai[0] == 3f) CalamityUtils.HomeInOnNPC(Projectile, true, 300f, 12f, 20); if (Projectile.ai[0] == 2f) Projectile.DamageType = RogueDamageClass.Instance; noTileHitCounter -= 1; if (noTileHitCounter == 0) Projectile.tileCollide = true; if (Projectile.soundDelay == 0) { Projectile.soundDelay = 20 + Main.rand.Next(40); if (Main.rand.NextBool(5)) SoundEngine.PlaySound(SoundID.Item9, Projectile.position); } Projectile.alpha -= 15; int num58 = 150; if (Projectile.Center.Y >= Projectile.ai[1]) num58 = 0; if (Projectile.alpha < num58) Projectile.alpha = num58; Projectile.localAI[0] += (Math.Abs(Projectile.velocity.X) + Math.Abs(Projectile.velocity.Y)) * 0.01f * (float)Projectile.direction; Projectile.rotation += (Math.Abs(Projectile.velocity.X) + Math.Abs(Projectile.velocity.Y)) * 0.01f * (float)Projectile.direction; if (Main.rand.NextBool(16)) { Vector2 value3 = Vector2.UnitX.RotatedByRandom(1.5707963705062866).RotatedBy((double)Projectile.velocity.ToRotation(), default); int num59 = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, ModContent.DustType(), Projectile.velocity.X * 0.5f, Projectile.velocity.Y * 0.5f, 150, default, 1f); Main.dust[num59].velocity = value3 * 0.66f; Main.dust[num59].position = Projectile.Center + value3 * 12f; } if (Main.rand.NextBool(48) && Main.netMode != NetmodeID.Server) { int num60 = Gore.NewGore(Projectile.GetSource_FromAI(), Projectile.Center, new Vector2(Projectile.velocity.X * 0.2f, Projectile.velocity.Y * 0.2f), 16, 1f); Main.gore[num60].velocity *= 0.66f; Main.gore[num60].velocity += Projectile.velocity * 0.3f; } if (Projectile.ai[1] == 1f) { Projectile.light = 0.9f; if (Main.rand.NextBool(10)) Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, ModContent.DustType(), Projectile.velocity.X * 0.5f, Projectile.velocity.Y * 0.5f, 150, default, 1f); if (Main.rand.NextBool(20) && Main.netMode != NetmodeID.Server) Gore.NewGore(Projectile.GetSource_FromAI(), Projectile.position, new Vector2(Projectile.velocity.X * 0.2f, Projectile.velocity.Y * 0.2f), Main.rand.Next(16, 18), 1f); } } public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { if (Projectile.DamageType != DamageClass.Ranged) target.AddBuff(ModContent.BuffType(), 120); } public override void OnHitPlayer(Player target, Player.HurtInfo info) { if (Projectile.DamageType != DamageClass.Ranged) target.AddBuff(ModContent.BuffType(), 120); } public override Color? GetAlpha(Color lightColor) => new Color(200, 100, 250, Projectile.alpha); public override void Kill(int timeLeft) { if (Projectile.ai[0] == 1f) return; Projectile.position.X = Projectile.position.X + (float)(Projectile.width / 2); Projectile.position.Y = Projectile.position.Y + (float)(Projectile.height / 2); Projectile.width = 36; Projectile.height = 36; Projectile.position.X = Projectile.position.X - (float)(Projectile.width / 2); Projectile.position.Y = Projectile.position.Y - (float)(Projectile.height / 2); for (int num621 = 0; num621 < 5; num621++) { int num622 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, ModContent.DustType(), 0f, 0f, 100, default, 1.2f); Main.dust[num622].velocity *= 3f; if (Main.rand.NextBool(2)) { Main.dust[num622].scale = 0.5f; Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; } } for (int num623 = 0; num623 < 5; num623++) { int num624 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, ModContent.DustType(), 0f, 0f, 100, default, 1.7f); Main.dust[num624].noGravity = true; Main.dust[num624].velocity *= 5f; num624 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, ModContent.DustType(), 0f, 0f, 100, default, 1f); Main.dust[num624].velocity *= 2f; } if (Main.netMode != NetmodeID.Server) { for (int num480 = 0; num480 < 3; num480++) Gore.NewGore(Projectile.GetSource_Death(), Projectile.position, new Vector2(Projectile.velocity.X * 0.05f, Projectile.velocity.Y * 0.05f), Main.rand.Next(16, 18), 1f); } } public override bool PreDraw(ref Color lightColor) { Projectile.DrawStarTrail(Color.Coral, Color.White); CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 2); return false; } } }