Files
CalamityModPublic/Projectiles/Boss/AresPlasmaBolt.cs
T
2025-08-01 04:49:20 +07:00

82 lines
2.8 KiB
C#

using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Boss
{
public class AresPlasmaBolt : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Boss";
private const int timeLeft = 360;
private const float maxVelocity = 10f;
public override void SetStaticDefaults()
{
Main.projFrames[Type] = 4;
ProjectileID.Sets.TrailCacheLength[Type] = 4;
ProjectileID.Sets.TrailingMode[Type] = 0;
}
public override void SetDefaults()
{
Projectile.width = 18;
Projectile.height = 18;
Projectile.hostile = true;
Projectile.ignoreWater = true;
Projectile.tileCollide = false;
Projectile.Opacity = 0f;
CooldownSlot = ImmunityCooldownID.Bosses;
Projectile.penetrate = -1;
Projectile.extraUpdates = 1;
Projectile.timeLeft = timeLeft;
}
public override void AI()
{
if (Projectile.velocity.Length() < maxVelocity)
{
Projectile.velocity *= 1.025f;
if (Projectile.velocity.Length() > maxVelocity)
{
Projectile.velocity.Normalize();
Projectile.velocity *= maxVelocity;
}
}
int fadeOutTime = 15;
int fadeInTime = 3;
if (Projectile.timeLeft < fadeOutTime)
Projectile.Opacity = MathHelper.Clamp(Projectile.timeLeft / (float)fadeOutTime, 0f, 1f);
else
Projectile.Opacity = MathHelper.Clamp(1f - ((Projectile.timeLeft - (timeLeft - fadeInTime)) / (float)fadeInTime), 0f, 1f);
Lighting.AddLight(Projectile.Center, 0f, 0.4f * Projectile.Opacity, 0f);
Projectile.frameCounter++;
if (Projectile.frameCounter > 8)
{
Projectile.frame++;
Projectile.frameCounter = 0;
}
if (Projectile.frame > 3)
Projectile.frame = 0;
Projectile.rotation = (float)Math.Atan2(Projectile.velocity.Y, Projectile.velocity.X) - MathHelper.PiOver2;
}
public override bool CanHitPlayer(Player target) => Projectile.Opacity == 1f;
public override bool PreDraw(ref Color lightColor)
{
lightColor.R = (byte)(255 * Projectile.Opacity);
lightColor.G = (byte)(255 * Projectile.Opacity);
lightColor.B = (byte)(255 * Projectile.Opacity);
CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Type], lightColor, 1);
return false;
}
}
}