Files
CalamityModPublic/Projectiles/Melee/BotanicSpear.cs
T

99 lines
3.6 KiB
C#

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Audio;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Melee
{
public class BotanicSpear : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Melee";
private const int TimeLeft = 180;
public override void SetStaticDefaults()
{
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 10;
ProjectileID.Sets.TrailingMode[Projectile.type] = 1;
}
public override void SetDefaults()
{
Projectile.width = 16;
Projectile.height = 16;
Projectile.friendly = true;
Projectile.DamageType = DamageClass.Melee;
Projectile.penetrate = -1;
Projectile.tileCollide = false;
Projectile.timeLeft = TimeLeft;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = 10;
}
public override void AI()
{
Lighting.AddLight(Projectile.Center, 0f, 1f, 0f);
Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver4;
if (Projectile.localAI[1] == 0f)
{
Projectile.scale -= 0.01f;
Projectile.alpha += 15;
if (Projectile.alpha >= 125)
{
Projectile.alpha = 130;
Projectile.localAI[1] = 1f;
}
}
else if (Projectile.localAI[1] == 1f)
{
Projectile.scale += 0.01f;
Projectile.alpha -= 15;
if (Projectile.alpha <= 0)
{
Projectile.alpha = 0;
Projectile.localAI[1] = 0f;
}
}
int dust = Dust.NewDust(Projectile.oldPosition + Projectile.oldVelocity, Projectile.width, Projectile.height, DustID.TerraBlade, 0f, 0f, 100, default, 1.25f);
Main.dust[dust].noGravity = true;
Main.dust[dust].velocity *= 0f;
Main.dust[dust].noLightEmittence = true;
}
public override void OnKill(int timeLeft)
{
SoundEngine.PlaySound(SoundID.Item10, Projectile.Center);
for (int i = 4; i < 31; i++)
{
float projOldX = Projectile.oldVelocity.X * (30f / i);
float projOldY = Projectile.oldVelocity.Y * (30f / i);
int dust = Dust.NewDust(new Vector2(Projectile.oldPosition.X - projOldX, Projectile.oldPosition.Y - projOldY), 8, 8, DustID.TerraBlade, Projectile.oldVelocity.X, Projectile.oldVelocity.Y, 100, default, 1.8f);
Main.dust[dust].noGravity = true;
Main.dust[dust].noLightEmittence = true;
dust = Dust.NewDust(new Vector2(Projectile.oldPosition.X - projOldX, Projectile.oldPosition.Y - projOldY), 8, 8, DustID.TerraBlade, Projectile.oldVelocity.X, Projectile.oldVelocity.Y, 100, default, 1.4f);
Main.dust[dust].noGravity = true;
Main.dust[dust].velocity *= 0.1f;
Main.dust[dust].noLightEmittence = true;
}
}
public override Color? GetAlpha(Color lightColor) => new Color(128, byte.MaxValue, 128);
public override bool PreDraw(ref Color lightColor)
{
if (Projectile.timeLeft > TimeLeft - 5)
return false;
CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 2);
return false;
}
}
}