Files
CalamityModPublic/Projectiles/Boss/AresPlasmaBolt.cs
T

92 lines
3.2 KiB
C#

using Microsoft.Xna.Framework;
using System;
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[Projectile.type] = 4;
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 4;
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
}
public override void SetDefaults()
{
Projectile.Calamity().DealsDefenseDamage = true;
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 void OnHitPlayer(Player target, Player.HurtInfo info)
{
if (info.Damage <= 0 || Projectile.Opacity != 1f)
return;
target.AddBuff(BuffID.OnFire, 180);
target.AddBuff(BuffID.CursedInferno, 90);
}
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[Projectile.type], lightColor, 1);
return false;
}
}
}