Files
CalamityModPublic/Projectiles/Ranged/BlightFlames.cs
T
doze-zoze 3a3520696c flamethrower debuff duration consistency
Almost all flamethrowers now have 20 seconds of their debuff to match vanilla. Exceptions made to Pristine Fury primary, Dragoon Drizzlefish, Spark Spreader, and Halley's Inferno due to reasons laid out in comments on their debuff inflictions.
2026-01-10 19:31:24 -06:00

185 lines
8.9 KiB
C#

using System;
using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Items.Weapons.Ranged;
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 BlightFlames : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Ranged";
public override string Texture => "CalamityMod/Projectiles/Ranged/BlightFlames";
public ref float ScaleFactor => ref Projectile.ai[0];
public ref float LightPower => ref Projectile.ai[1];
public int Time = 0;
public bool postTileHit = false;
public bool postEnemyHit = false;
public NPC targeted;
public Vector2 savedDist;
public Color FogColor = new Color(30, 255, 30);
public override void SetStaticDefaults() => ProjectileID.Sets.CultistIsResistantTo[Type] = true;
public override void SetDefaults()
{
Projectile.width = 14;
Projectile.height = 14;
Projectile.friendly = true;
Projectile.ignoreWater = true;
Projectile.DamageType = DamageClass.Ranged;
Projectile.penetrate = -1;
Projectile.extraUpdates = 5;
Projectile.timeLeft = 400;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = 55;
}
public override void AI()
{
Time++;
Projectile.rotation += Main.rand.NextFloat(0.2f, 0.9f);
if (Time > 6 && Time < 540 && Main.rand.NextBool(2 + Time / 7))
{
DirectionalPulseRing pulse = new DirectionalPulseRing(Projectile.Center + Main.rand.NextVector2Circular(10 + Time * 0.5f, 10 + Time * 0.5f), Vector2.Zero, Main.rand.NextBool(3) ? Color.LimeGreen : Color.Green, new Vector2(1, 1), 0, Main.rand.NextFloat(0.03f, 0.09f) + Time * 0.00055f, 0f, 25);
GeneralParticleHandler.SpawnParticle(pulse);
}
if (Time > 6 && Time < 150 && !postTileHit && !postEnemyHit && Main.rand.NextBool(3 + Time / 7))
{
MediumMistParticle smoke = new MediumMistParticle(Projectile.Center + Main.rand.NextVector2Circular(5 + Time * 0.2f, 5 + Time * 0.2f), -Projectile.velocity * 0.05f, Main.rand.NextBool(3) ? Color.LimeGreen : Color.Lime, Color.Black, Main.rand.NextFloat(0.3f, 0.8f) + Time * 0.013f, 160);
GeneralParticleHandler.SpawnParticle(smoke);
}
if (Time == 8)
{
for (int i = 0; i <= 8; i++)
{
Dust dust = Dust.NewDustPerfect(Projectile.Center, DustID.GemDiamond, Projectile.velocity * 0.6f);
dust.scale = Main.rand.NextFloat(1.1f, 1.9f);
dust.velocity = Projectile.velocity.RotatedByRandom(0.3f) * Main.rand.NextFloat(0.3f, 2.1f);
dust.noGravity = true;
dust.color = Main.rand.NextBool() ? Color.Chartreuse : Color.LimeGreen;
dust.noLight = true;
dust.alpha = 90;
}
}
if (Time == 10)
{
for (int i = 0; i <= 3; i++)
{
Dust dust = Dust.NewDustPerfect(Projectile.Center, DustID.FireworkFountain_Green, Projectile.velocity * 0.6f);
dust.scale = Main.rand.NextFloat(0.4f, 1.2f);
dust.velocity = Projectile.velocity.RotatedByRandom(0.3f) * Main.rand.NextFloat(0.3f, 2.1f);
dust.noGravity = false;
}
}
if (Main.rand.NextBool(4) && Time > 135 && !postTileHit && !postEnemyHit)
{
Dust dust = Dust.NewDustPerfect(Projectile.Center + Main.rand.NextVector2Circular(145, 145), DustID.FireworkFountain_Green, Vector2.Zero);
dust.scale = Main.rand.NextFloat(0.2f, 0.4f);
dust.noGravity = true;
}
if (Main.rand.NextBool(20) && (postTileHit || postEnemyHit))
{
Dust dust = Dust.NewDustPerfect(Projectile.Center + Main.rand.NextVector2Circular(145, 145), DustID.FireworkFountain_Green, Vector2.Zero);
dust.scale = Main.rand.NextFloat(0.4f, 1.2f);
dust.noGravity = true;
}
// Add some degree of variation to the fog with rotation/color
ScaleFactor += 0.0061f;
ScaleFactor = MathHelper.Clamp(ScaleFactor, 0f, Projectile.scale * 0.8f);
Lighting.AddLight(Projectile.Center, new Vector3(1f, 1f, 0.25f) * ScaleFactor);
Projectile.velocity *= 0.99f;
Projectile.Opacity = Utils.GetLerpValue(30f, 50f, Projectile.timeLeft, true) * Utils.GetLerpValue(0f, 130f, Projectile.timeLeft, true);
if (postEnemyHit && !postTileHit && targeted != null && targeted.life > 0 && targeted.active)
{
Projectile.Center = targeted.Center + savedDist;
savedDist *= 0.99f;
}
// 08DEC2023: Ozzatron: All below code does not run on dedicated servers as it requires clientside lighting information.
if (Main.dedServ)
return;
// Calculate light power. This checks below the position of the fog to check if this fog is underground.
// Without this, it may render over the fullblack that the game renders for obscured tiles.
float lightPowerBelow = Lighting.GetColor((int)Projectile.Center.X / 16, (int)Projectile.Center.Y / 16 + 6).ToVector3().Length() / (float)Math.Sqrt(3D);
LightPower = MathHelper.Lerp(LightPower, lightPowerBelow, 0.15f);
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
{
//if (!postTileHit)
//Projectile.Center = Projectile.Center + Main.rand.NextVector2Circular(20, 20);
//Doze - Flamethrowers in vanilla are long debuff infliction tools (20 seconds of their debuff).
//I am applying this as the base for Cal flamethrowers, with shorter times being the exception instead of the rule
target.AddBuff(ModContent.BuffType<Plague>(), 1200);
for (int i = 0; i <= 3; i++)
{
MediumMistParticle smoke = new MediumMistParticle(Projectile.Center + Main.rand.NextVector2Circular(5 + Time * 0.2f, 5 + Time * 0.2f), new Vector2(Main.rand.NextFloat(2, 6), Main.rand.NextFloat(2, 6)).RotatedByRandom(60), Main.rand.NextBool(3) ? Color.LimeGreen : Color.Lime, Color.Black, Main.rand.NextFloat(1.2f, 2.3f), 140);
GeneralParticleHandler.SpawnParticle(smoke);
}
if (!postTileHit && !postEnemyHit)
{
SoundEngine.PlaySound(BlightSpewer.Nanomachines, Projectile.Center);
Projectile.velocity = Vector2.Zero;
Projectile.timeLeft = 300;
postEnemyHit = true;
targeted = target;
savedDist = Projectile.Center - target.Center;
}
}
public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers)
{
if (Projectile.numHits > 0)
Projectile.damage = (int)(Projectile.damage * 0.95f);
if (Projectile.damage < 1)
Projectile.damage = 1;
}
public override bool OnTileCollide(Vector2 oldVelocity)
{
if (!postEnemyHit)
{
Projectile.velocity = oldVelocity * 0.95f;
Projectile.Center -= Projectile.velocity;
if (!postTileHit)
{
Projectile.timeLeft = 800;
postTileHit = true;
}
}
return false;
}
// Expanding hitbox
public override void ModifyDamageHitbox(ref Rectangle hitbox)
{
int size = (int)Utils.Remap(Time, 0f, 90, 10f, 95f);
hitbox.Inflate(size, size);
}
public override bool PreDraw(ref Color lightColor)
{
Texture2D splatTex = ModContent.Request<Texture2D>("CalamityMod/Particles/WaterFoam").Value;
Texture2D texture = Terraria.GameContent.TextureAssets.Projectile[Type].Value;
Vector2 drawPosition = Projectile.Center - Main.screenPosition;
float opacity = Projectile.Opacity * 0.3f;
Color drawColor = (FogColor with { A = 0 }) * opacity;
Main.EntitySpriteDraw(texture, drawPosition + Main.rand.NextVector2Circular(19, 19), null, drawColor * 0.55f, Projectile.rotation, texture.Size() * 0.5f, ScaleFactor * 1.2f, SpriteEffects.None);
Main.EntitySpriteDraw(texture, drawPosition, null, drawColor, -Projectile.rotation * 0.9f, texture.Size() * 0.5f, ScaleFactor, SpriteEffects.None);
return false;
}
}
}