using System; using System.Linq; using CalamityMod.Graphics.Primitives; using CalamityMod.Particles; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.Audio; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Ranged { public class MeowCreature : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Ranged"; public override void SetStaticDefaults() { ProjectileID.Sets.CultistIsResistantTo[Type] = true; ProjectileID.Sets.TrailCacheLength[Projectile.type] = 36; ProjectileID.Sets.TrailingMode[Projectile.type] = 2; } public override void SetDefaults() { Projectile.width = Projectile.height = 24; Projectile.friendly = true; Projectile.penetrate = 1; Projectile.MaxUpdates = 2; Projectile.timeLeft = 90 * Projectile.MaxUpdates; Projectile.DamageType = DamageClass.Ranged; } public override void AI() { CalamityUtils.HomeInOnNPC(Projectile, false, 400f, 15f, 20f); Projectile.rotation = Projectile.velocity.ToRotation(); } public override void OnKill(int timeLeft) { SoundEngine.PlaySound(Main.rand.NextBool() ? SoundID.Item58 : SoundID.Item57, Projectile.Center); // Circular spread of clouds for (int i = 0; i < 12; i++) { Vector2 smokeVel = Main.rand.NextVector2Circular(16f, 16f); Color smokeColor = Main.hslToRgb(Main.rand.NextFloat(), 1f, 0.8f); Particle smoke = new MediumMistParticle(Projectile.Center, smokeVel, smokeColor, Color.Black, Main.rand.NextFloat(0.6f, 1.6f), 220 - Main.rand.Next(60), 0.1f); GeneralParticleHandler.SpawnParticle(smoke); } } internal float WidthFunction(float completionRatio) => (1f - completionRatio) * Projectile.scale * 9f; internal Color ColorFunction(float completionRatio) { float hue = 0.5f + 0.5f * completionRatio * MathF.Sin(Main.GlobalTimeWrappedHourly * 5f); Color trailColor = Main.hslToRgb(hue, 1f, 0.8f); return trailColor * Projectile.Opacity; } // The creature glows public override void PostDraw(Color lightColor) { PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f), 30); Texture2D glow = Terraria.GameContent.TextureAssets.Projectile[Projectile.type].Value; Main.EntitySpriteDraw(glow, Projectile.Center - Main.screenPosition, null, Color.White, Projectile.rotation, glow.Size() * 0.5f, Projectile.scale, SpriteEffects.None); } } }