using CalamityMod.Particles; using Terraria.Graphics.Shaders; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; using static Terraria.ModLoader.ModContent; namespace CalamityMod.Projectiles.Melee { public class EonBolt : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Melee"; internal PrimitiveTrail TrailDrawer; public override string Texture => "CalamityMod/Projectiles/Melee/GalaxiaBolt"; public NPC target; public Player Owner => Main.player[Projectile.owner]; public ref float Hue => ref Projectile.ai[0]; public ref float HomingStrenght => ref Projectile.ai[1]; Particle Head; public override void SetStaticDefaults() { ProjectileID.Sets.TrailCacheLength[Projectile.type] = 20; ProjectileID.Sets.TrailingMode[Projectile.type] = 2; } public override void SetDefaults() { Projectile.width = Projectile.height = 30; Projectile.friendly = true; Projectile.penetrate = 1; Projectile.timeLeft = 80; Projectile.DamageType = DamageClass.Melee; Projectile.tileCollide = false; } public override void AI() { Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2; if (Head == null) { Head = new GenericSparkle(Projectile.Center, Vector2.Zero, Color.White, Main.hslToRgb(Hue, 100, 50), 1.2f, 2, 0.06f, 3, true); GeneralParticleHandler.SpawnParticle(Head); } else { Head.Position = Projectile.Center + Projectile.velocity * 0.5f; Head.Time = 0; Head.Scale += (float)Math.Sin(Main.GlobalTimeWrappedHourly * 6) * 0.02f * Projectile.scale; } if (target == null) target = Projectile.Center.ClosestNPCAt(812f, true); else if (CalamityUtils.AngleBetween(Projectile.velocity, target.Center - Projectile.Center) < MathHelper.Pi) //Home in { float idealDirection = Projectile.AngleTo(target.Center); float updatedDirection = Projectile.velocity.ToRotation().AngleTowards(idealDirection, HomingStrenght); Projectile.velocity = updatedDirection.ToRotationVector2() * Projectile.velocity.Length() * 0.995f; } Lighting.AddLight(Projectile.Center, 0.75f, 1f, 0.24f); if (Main.rand.Next(2) == 0) { Particle smoke = new HeavySmokeParticle(Projectile.Center, Projectile.velocity * 0.5f, Color.Lerp(Color.DodgerBlue, Color.MediumVioletRed, (float)Math.Sin(Main.GlobalTimeWrappedHourly * 6f)), 20, Main.rand.NextFloat(0.6f, 1.2f) * Projectile.scale, 0.28f, 0, false, 0, true); GeneralParticleHandler.SpawnParticle(smoke); if (Main.rand.Next(3) == 0) { Particle smokeGlow = new HeavySmokeParticle(Projectile.Center, Projectile.velocity * 0.5f, Main.hslToRgb(Hue, 1, 0.7f), 15, Main.rand.NextFloat(0.4f, 0.7f) * Projectile.scale, 0.8f, 0, true, 0.05f, true); GeneralParticleHandler.SpawnParticle(smokeGlow); } } } internal Color ColorFunction(float completionRatio) { float fadeToEnd = MathHelper.Lerp(0.65f, 1f, (float)Math.Cos(-Main.GlobalTimeWrappedHourly * 3f) * 0.5f + 0.5f); float fadeOpacity = Utils.GetLerpValue(1f, 0.64f, completionRatio, true) * Projectile.Opacity; Color colorHue = Main.hslToRgb(Hue, 1, 0.8f); Color endColor = Color.Lerp(colorHue, Color.PaleTurquoise, (float)Math.Sin(completionRatio * MathHelper.Pi * 1.6f - Main.GlobalTimeWrappedHourly * 4f) * 0.5f + 0.5f); return Color.Lerp(Color.White, endColor, fadeToEnd) * fadeOpacity; } internal float WidthFunction(float completionRatio) { float expansionCompletion = (float)Math.Pow(1 - completionRatio, 3); return MathHelper.Lerp(0f, 22 * Projectile.scale * Projectile.Opacity, expansionCompletion); } public override bool PreDraw(ref Color lightColor) { if (TrailDrawer is null) TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]); GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak")); TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 30); Texture2D texture = Request("CalamityMod/Projectiles/Melee/GalaxiaBolt").Value; Main.EntitySpriteDraw(texture, Projectile.Center - Main.screenPosition, null, Color.Lerp(lightColor, Color.White, 0.5f), Projectile.rotation, texture.Size() / 2f, Projectile.scale, SpriteEffects.None, 0); return false; } } }