using CalamityMod.Buffs.DamageOverTime; using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; using Terraria.Audio; namespace CalamityMod.Projectiles.Rogue { public class NightsGazeStar : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Rogue"; public static int lifetime = 150; public override void SetStaticDefaults() { ProjectileID.Sets.TrailCacheLength[Projectile.type] = 8; ProjectileID.Sets.TrailingMode[Projectile.type] = 1; } public override void SetDefaults() { Projectile.width = 10; Projectile.height = 10; Projectile.friendly = true; Projectile.ignoreWater = true; Projectile.penetrate = 5; Projectile.timeLeft = lifetime; Projectile.DamageType = RogueDamageClass.Instance; Projectile.localAI[0] = 10f; } public override void AI() { Projectile.rotation += Projectile.direction * 0.05f; if (Projectile.ai[0] == 0f) { if (Projectile.timeLeft < (lifetime - Projectile.ai[1]) && Projectile.localAI[0] >= 0) { Projectile.velocity.Normalize(); Projectile.velocity *= Projectile.localAI[0]; Projectile.localAI[0]--; } else if (Projectile.timeLeft >= (lifetime - Projectile.ai[1])) { for (int i = 0; i < 3; i++) { float dustVelocity = Main.rand.NextFloat(0f, 0.5f); int dustType = Utils.SelectRandom(Main.rand, new int[] { 109, 111, 132 }); int dust = Dust.NewDust(Projectile.Center, 1, 1, dustType, Projectile.velocity.X, Projectile.velocity.Y, 0, default, 1.5f); Main.dust[dust].noGravity = true; Main.dust[dust].velocity *= dustVelocity; } } } else if (Projectile.ai[0] == 1f) { float minDist = 999f; int index = 0; for (int i = 0; i < Main.npc.Length; i++) { NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float dist = (Projectile.Center - npc.Center).Length(); if (dist < minDist) { minDist = dist; index = i; } } } if (minDist < 999f) { Vector2 velocityNew = Main.npc[index].Center - Projectile.Center; float speed = 10f; velocityNew.Normalize(); Projectile.velocity = velocityNew * speed; } } if (Projectile.soundDelay == 0) { Projectile.soundDelay = 20 + Main.rand.Next(40); if (Main.rand.NextBool(5)) { SoundEngine.PlaySound(SoundID.Item9, Projectile.position); } } } public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.AddBuff(ModContent.BuffType(), 120); public override void OnHitPlayer(Player target, Player.HurtInfo info) => target.AddBuff(ModContent.BuffType(), 120); public override bool OnTileCollide(Vector2 oldVelocity) { Collision.HitTiles(Projectile.position + Projectile.velocity, Projectile.velocity, Projectile.width, Projectile.height); Projectile.Kill(); return false; } public override bool PreDraw(ref Color lightColor) { CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], Color.White, 1); return false; } public override void Kill(int timeLeft) { for (int i = 0; i < 5; i++) { int dustType = Utils.SelectRandom(Main.rand, new int[] { 109, 111, 132 }); int dust = Dust.NewDust(Projectile.Center, 1, 1, dustType, Projectile.velocity.X, Projectile.velocity.Y, 0, default, 1.5f); Main.dust[dust].noGravity = true; } } } }