using System; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Dusts; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.Audio; using Terraria.ID; using Terraria.ModLoader; 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 = 22; 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 alphaControl = 150; if (Projectile.Center.Y >= Projectile.ai[1]) alphaControl = 0; if (Projectile.alpha < alphaControl) Projectile.alpha = alphaControl; 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 rotational = Vector2.UnitX.RotatedByRandom(1.5707963705062866).RotatedBy((double)Projectile.velocity.ToRotation(), default); int astralDust = 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[astralDust].velocity = rotational * 0.66f; Main.dust[astralDust].position = Projectile.Center + rotational * 12f; } if (Main.rand.NextBool(48) && Main.netMode != NetmodeID.Server) { int starry = Gore.NewGore(Projectile.GetSource_FromAI(), Projectile.Center, new Vector2(Projectile.velocity.X * 0.2f, Projectile.velocity.Y * 0.2f), 16, 1f); Main.gore[starry].velocity *= 0.66f; Main.gore[starry].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 OnKill(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 i = 0; i < 5; i++) { int starryDust = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, ModContent.DustType(), 0f, 0f, 100, default, 1.2f); Main.dust[starryDust].velocity *= 3f; if (Main.rand.NextBool()) { Main.dust[starryDust].scale = 0.5f; Main.dust[starryDust].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; } } for (int j = 0; j < 5; j++) { int starryDust2 = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, ModContent.DustType(), 0f, 0f, 100, default, 1.7f); Main.dust[starryDust2].noGravity = true; Main.dust[starryDust2].velocity *= 5f; starryDust2 = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, ModContent.DustType(), 0f, 0f, 100, default, 1f); Main.dust[starryDust2].velocity *= 2f; } if (Main.netMode != NetmodeID.Server) { for (int k = 0; k < 3; k++) 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; } } }