Files
CalamityModPublic/Projectiles/Ranged/ElementalFire.cs
T
Altixal c159e202a4 elemental eruption
+ some asset management
2023-10-17 03:57:23 +07:00

68 lines
3.1 KiB
C#

using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Particles;
using Microsoft.Xna.Framework;
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Ranged
{
public class ElementalFire : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Ranged";
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public static int Lifetime => 96;
public ref float ColorType => ref Projectile.ai[0];
public ref float Time => ref Projectile.ai[1];
public override void SetDefaults()
{
Projectile.width = Projectile.height = 12;
Projectile.friendly = true;
Projectile.ignoreWater = true;
Projectile.DamageType = DamageClass.Ranged;
Projectile.penetrate = -1;
Projectile.MaxUpdates = 4;
Projectile.timeLeft = Lifetime; // 24 effectively
Projectile.usesIDStaticNPCImmunity = true;
Projectile.idStaticNPCHitCooldown = 8;
}
public override void AI()
{
Time++;
ColorType += 0.02f;
// Determines particle size as well as hitbox
if (Time >= 5f)
Projectile.scale = 1.8f * Utils.GetLerpValue(5f, 30f, Time, true);
else
return; // Helps position it at the tip
// Rainbow smokes of increasing opacity
float smokeRot = MathHelper.ToRadians(3f); // *Rate of rotation per frame, not a constant rotation
float hue = 0.5f * (ColorType % 1f) + 0.5f * Utils.GetLerpValue(30f, Lifetime, Time, true) * MathF.Sin(Main.GlobalTimeWrappedHourly * 5f);
Color smokeColor = Main.hslToRgb(hue, 1f, 0.8f);
Particle smoke = new HeavySmokeParticle(Projectile.Center, Projectile.velocity * 0.5f, smokeColor, 12, Projectile.scale * Main.rand.NextFloat(0.6f, 1.2f), 0.3f, smokeRot, true, required: true);
GeneralParticleHandler.SpawnParticle(smoke);
// Overlay the glow on top, which is on the brighter side
if (Main.rand.NextBool(5))
{
Color glowColor = Color.Lerp(smokeColor, Color.White, 0.3f);
Particle smokeGlow = new HeavySmokeParticle(Projectile.Center, Projectile.velocity * 0.5f, glowColor, 9, Projectile.scale * Main.rand.NextFloat(0.4f, 0.7f), 0.2f, smokeRot, true, 0.005f);
GeneralParticleHandler.SpawnParticle(smokeGlow);
}
Lighting.AddLight(Projectile.Center, smokeColor.ToVector3() * Projectile.scale * 0.3f);
}
// Circular hitbox adjusted for the size of the smoke particles (which is 52 here)
public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => CalamityUtils.CircularHitboxCollision(Projectile.Center, 52 * Projectile.scale * 0.5f, targetHitbox);
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.AddBuff(ModContent.BuffType<ElementalMix>(), 540);
}
}