Files
CalamityModPublic/Projectiles/Ranged/TelluricGlareArrow.cs
T

141 lines
5.8 KiB
C#

using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Dusts;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
namespace CalamityMod.Projectiles.Ranged
{
public class TelluricGlareArrow : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Ranged";
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public PrimitiveTrail TrailDrawer = null;
private const int Lifetime = 180;
private static Color ShaderColorOne = new Color(237, 194, 66);
private static Color ShaderColorTwo = new Color(235, 227, 117);
private static Color ShaderEndColor = new Color(199, 153, 26);
public override void SetStaticDefaults()
{
// While this projectile doesn't have afterimages, it keeps track of old positions for its primitive drawcode.
ProjectileID.Sets.TrailingMode[Projectile.type] = 2;
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 21;
}
public override void SetDefaults()
{
Projectile.width = Projectile.height = 24;
Projectile.arrow = true;
Projectile.friendly = true;
Projectile.DamageType = DamageClass.Ranged;
Projectile.tileCollide = false;
Projectile.ignoreWater = true;
Projectile.timeLeft = Lifetime;
Projectile.MaxUpdates = 3;
Projectile.penetrate = 2; // Can hit up to two enemies. Will explode extremely soon after hitting the first, though.
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = -1;
Projectile.Calamity().pointBlankShotDuration = CalamityGlobalProjectile.DefaultPointBlankDuration;
}
public override bool? CanDamage() => Projectile.timeLeft < Lifetime - 4 ? null : false;
public override void AI() => Lighting.AddLight(Projectile.Center, ShaderColorOne.ToVector3());
private void RestrictLifetime()
{
if (Projectile.timeLeft > 8)
Projectile.timeLeft = 8;
}
public override void OnHitPlayer(Player target, Player.HurtInfo info)
{
if (info.Damage <= 0)
return;
RestrictLifetime();
target.AddBuff(ModContent.BuffType<HolyFlames>(), 180);
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
{
RestrictLifetime();
target.AddBuff(ModContent.BuffType<HolyFlames>(), 180);
}
private float PrimitiveWidthFunction(float completionRatio)
{
float arrowheadCutoff = 0.36f;
float width = 39f;
float minHeadWidth = 0.02f;
float maxHeadWidth = width;
if (completionRatio <= arrowheadCutoff)
width = MathHelper.Lerp(minHeadWidth, maxHeadWidth, Utils.GetLerpValue(0f, arrowheadCutoff, completionRatio, true));
return width;
}
private Color PrimitiveColorFunction(float completionRatio)
{
float endFadeRatio = 0.41f;
float completionRatioFactor = 2.7f;
float globalTimeFactor = 5.3f;
float endFadeFactor = 3.2f;
float endFadeTerm = Utils.GetLerpValue(0f, endFadeRatio * 0.5f, completionRatio, true) * endFadeFactor;
float cosArgument = completionRatio * completionRatioFactor - Main.GlobalTimeWrappedHourly * globalTimeFactor + endFadeTerm;
float startingInterpolant = (float)Math.Cos(cosArgument) * 0.5f + 0.5f;
float colorLerpFactor = 0.6f;
Color startingColor = Color.Lerp(ShaderColorOne, ShaderColorTwo, startingInterpolant * colorLerpFactor);
return Color.Lerp(startingColor, ShaderEndColor, MathHelper.SmoothStep(0f, 1f, Utils.GetLerpValue(0f, endFadeRatio, completionRatio, true)));
}
public override bool PreDraw(ref Color lightColor)
{
if (TrailDrawer is null)
TrailDrawer = new PrimitiveTrail(PrimitiveWidthFunction, PrimitiveColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]);
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/Trails/FabstaffStreak"));
Vector2 overallOffset = Projectile.Size * 0.5f - Main.screenPosition;
overallOffset += Projectile.velocity * 1.4f;
TrailDrawer.Draw(Projectile.oldPos, overallOffset, 92); // 58
return false;
}
public override void Kill(int timeLeft)
{
SoundEngine.PlaySound(SoundID.Item14, Projectile.position);
// Explode into a bunch of holy fire on death.
for (int i = 0; i < 10; i++)
{
Dust holyFire = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, (int)CalamityDusts.ProfanedFire, 0f, 0f, 100, default, 2f);
holyFire.velocity *= 3f;
if (Main.rand.NextBool(2))
{
holyFire.scale = 0.5f;
holyFire.fadeIn = Main.rand.NextFloat(1f, 2f);
}
}
for (int i = 0; i < 20; i++)
{
Dust holyFire = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, 246, 0f, 0f, 100, default, 3f);
holyFire.noGravity = true;
holyFire.velocity *= 5f;
holyFire = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, 246, 0f, 0f, 100, default, 2f);
holyFire.velocity *= 2f;
}
}
}
}