Files
CalamityModPublic/Projectiles/Boss/WaterSpear.cs
T

91 lines
3.2 KiB
C#

using Microsoft.Xna.Framework;
using System;
using System.IO;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Boss
{
public class WaterSpear : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Boss";
public override void SetStaticDefaults()
{
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 4;
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
}
public override void SetDefaults()
{
Projectile.width = 14;
Projectile.height = 14;
Projectile.hostile = true;
Projectile.ignoreWater = true;
Projectile.tileCollide = false;
Projectile.penetrate = -1;
Projectile.timeLeft = 300;
Projectile.Opacity = 0f;
}
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(Projectile.localAI[0]);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
Projectile.localAI[0] = reader.ReadSingle();
}
public override void AI()
{
if (Projectile.velocity.Length() < 10f)
Projectile.velocity *= 1.01f;
if (Projectile.ai[1] == 0f)
{
for (int num621 = 0; num621 < 10; num621++)
{
int num622 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, 33, 0f, 0f, 100, default, 2f);
Main.dust[num622].velocity *= 3f;
if (Main.rand.NextBool(2))
{
Main.dust[num622].scale = 0.5f;
Main.dust[num622].fadeIn = 1f + Main.rand.Next(10) * 0.1f;
}
}
Projectile.ai[1] = 1f;
}
if (Projectile.timeLeft < 30)
Projectile.Opacity = MathHelper.Clamp(Projectile.timeLeft / 30f, 0f, 1f);
else
Projectile.Opacity = MathHelper.Clamp(1f - ((Projectile.timeLeft - 270) / 30f), 0f, 1f);
Projectile.rotation = (float)Math.Atan2(Projectile.velocity.Y, Projectile.velocity.X) + MathHelper.PiOver2;
Lighting.AddLight(Projectile.Center, 0f, 0f, 0.5f * Projectile.Opacity);
}
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[Projectile.type], lightColor, 1);
return false;
}
public override void Kill(int timeLeft)
{
for (int k = 0; k < 5; k++)
{
Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, 33, Projectile.oldVelocity.X * 0.5f, Projectile.oldVelocity.Y * 0.5f);
}
}
}
}