Files
CalamityModPublic/Projectiles/Ranged/AstrealArrow.cs
T

116 lines
4.1 KiB
C#

using Microsoft.Xna.Framework;
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Ranged
{
public class AstrealArrow : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Ranged";
public override void SetStaticDefaults()
{
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 10;
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
}
public override void SetDefaults()
{
Projectile.width = 18;
Projectile.height = 18;
Projectile.alpha = 255;
Projectile.ignoreWater = true;
Projectile.friendly = true;
Projectile.DamageType = DamageClass.Ranged;
Projectile.arrow = true;
Projectile.extraUpdates = 1;
Projectile.penetrate = 1;
Projectile.timeLeft = 600;
Projectile.Calamity().pointBlankShotDuration = CalamityGlobalProjectile.DefaultPointBlankDuration;
}
public override void AI()
{
Projectile.rotation = (float)Math.Atan2((double)Projectile.velocity.Y, (double)Projectile.velocity.X) + 1.57f;
if (Projectile.localAI[0] == 0f)
{
Projectile.scale -= 0.02f;
Projectile.alpha += 30;
if (Projectile.alpha >= 250)
{
Projectile.alpha = 255;
Projectile.localAI[0] = 1f;
}
}
else if (Projectile.localAI[0] == 1f)
{
Projectile.scale += 0.02f;
Projectile.alpha -= 30;
if (Projectile.alpha <= 0)
{
Projectile.alpha = 0;
Projectile.localAI[0] = 0f;
}
}
if (Projectile.velocity.Length() < 16f)
{
switch ((int)Projectile.ai[0])
{
case 0:
Projectile.velocity.X *= 1.02f;
break;
case 1:
Projectile.velocity.Y *= 1.02f;
break;
case 2:
Projectile.velocity.X += 0.1f;
Projectile.velocity.Y *= 1.01f;
break;
case 3:
Projectile.velocity.Y += 0.1f;
Projectile.velocity.X *= 1.01f;
break;
default:
break;
}
}
if (Main.rand.NextBool(5))
Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, 173, Projectile.velocity.X * 0.5f, Projectile.velocity.Y * 0.5f);
Projectile.ai[1] += Main.rand.Next(2) + 1;
if (Projectile.ai[1] >= 135f)
{
Projectile.ai[1] = 0f;
Projectile.netUpdate = true;
if (Projectile.owner == Main.myPlayer)
{
Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Projectile.velocity, ModContent.ProjectileType<AstrealFlame>(), (int)(Projectile.damage * 0.5), Projectile.knockBack, Projectile.owner, 0f, 0f);
}
}
}
public override bool PreDraw(ref Color lightColor)
{
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, 173, Projectile.oldVelocity.X * 0.5f, Projectile.oldVelocity.Y * 0.5f);
}
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
{
target.AddBuff(BuffID.ShadowFlame, 180);
}
}
}