Files
CalamityModPublic/Projectiles/Ranged/UltimaSpark.cs
T

94 lines
3.3 KiB
C#

using Microsoft.Xna.Framework;
using System;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Ranged
{
public class UltimaSpark : ModProjectile
{
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public float Time
{
get => projectile.ai[0];
set => projectile.ai[0] = value;
}
public const int DustType = 261;
public const float MaxHomingDistance = 1200f;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Ultima Spark");
}
public override void SetDefaults()
{
projectile.width = projectile.height = 8;
projectile.friendly = true;
projectile.ranged = true;
projectile.arrow = true;
projectile.penetrate = 1;
projectile.timeLeft = 240;
projectile.extraUpdates = 1;
}
public override void AI()
{
if (!Main.dedServ && Time > 5f)
{
for (int i = 0; i < 3; i++)
{
Vector2 spawnPosition = Vector2.Lerp(projectile.oldPosition, projectile.position, i / 3f);
Dust dust = Dust.NewDustPerfect(spawnPosition, DustType);
dust.color = Main.hslToRgb((Main.rand.NextFloat(-0.04f, 0.04f) + Time / 80f) % 1f, 0.8f, 0.6f);
dust.scale = 2.3f;
dust.fadeIn = 1f;
dust.rotation = Main.rand.NextFloat(MathHelper.TwoPi);
dust.velocity = Vector2.Zero;
dust.noGravity = true;
}
}
NPC potentialTarget = projectile.Center.ClosestNPCAt(MaxHomingDistance);
if (potentialTarget != null)
{
projectile.velocity = (projectile.velocity * 8f + projectile.SafeDirectionTo(potentialTarget.Center) * 18f) / 9f;
return;
}
if (Time > 30f)
{
float updatedTime = Time - 30f;
// Make a complete 90 degree turn in 30 frames.
if (updatedTime % 120f > 90f)
{
projectile.velocity = projectile.velocity.RotatedBy(MathHelper.PiOver2 / 20f);
}
// Arc around quickly for 60 frames.
else if (updatedTime % 120f > 30f)
{
projectile.velocity = projectile.velocity.RotatedBy((float)Math.Sin((updatedTime - 30f) % 60f / 60f * MathHelper.TwoPi) * MathHelper.ToRadians(15f));
}
}
Time++;
}
public override void Kill(int timeLeft)
{
CalamityGlobalProjectile.ExpandHitboxBy(projectile, 60, 60);
projectile.Damage();
if (!Main.dedServ)
{
for (int i = 0; i < 20; i++)
{
Dust dust = Dust.NewDustPerfect(projectile.Center, DustType);
dust.color = Main.hslToRgb(Main.rand.NextFloat(), 1f, 0.7f);
dust.scale = Main.rand.NextFloat(0.9f, 1.25f);
dust.velocity = Main.rand.NextVector2Circular(6f, 6f);
dust.noGravity = true;
}
}
}
}
}