74 lines
2.6 KiB
C#
74 lines
2.6 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace ForgottenWawiTech.Content.Projectiles.Transcendent
|
|
{
|
|
public class TranscendentAscendantBolt : ModProjectile
|
|
{
|
|
private const float HomingRange = 720f;
|
|
private const float HomingStrength = 0.2f;
|
|
private const float DesiredSpeed = 20f;
|
|
|
|
public override string Texture => "ForgottenWawiTech/Assets/PlaceholderProj";
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.width = 18;
|
|
Projectile.height = 18;
|
|
Projectile.friendly = true;
|
|
Projectile.timeLeft = 180;
|
|
Projectile.penetrate = 2;
|
|
Projectile.tileCollide = false;
|
|
Projectile.ignoreWater = true;
|
|
Projectile.DamageType = DamageClass.Summon;
|
|
Projectile.extraUpdates = 1;
|
|
Projectile.usesLocalNPCImmunity = true;
|
|
Projectile.localNPCHitCooldown = 10;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Projectile.rotation = Projectile.velocity.ToRotation();
|
|
Lighting.AddLight(Projectile.Center, 0.6f, 0.55f, 1.2f);
|
|
|
|
NPC target = AcquireTarget(Projectile.Center, HomingRange);
|
|
if (target != null)
|
|
{
|
|
Vector2 desiredVelocity = (target.Center - Projectile.Center).SafeNormalize(Vector2.Zero) * DesiredSpeed;
|
|
Projectile.velocity = Vector2.Lerp(Projectile.velocity, desiredVelocity, HomingStrength);
|
|
}
|
|
|
|
if (Main.rand.NextBool(4))
|
|
{
|
|
Dust dust = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, DustID.Enchanted_Pink, Projectile.velocity.X * 0.2f, Projectile.velocity.Y * 0.2f, 150, default, 1.15f);
|
|
dust.noGravity = true;
|
|
}
|
|
}
|
|
|
|
private static NPC AcquireTarget(Vector2 center, float range)
|
|
{
|
|
NPC closest = null;
|
|
float sqrRange = range * range;
|
|
for (int i = 0; i < Main.maxNPCs; i++)
|
|
{
|
|
NPC npc = Main.npc[i];
|
|
if (!npc.active || npc.friendly || npc.dontTakeDamage || npc.life <= 0)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
float dist = Vector2.DistanceSquared(npc.Center, center);
|
|
if (dist <= sqrRange && Collision.CanHitLine(center, 0, 0, npc.Center, 0, 0))
|
|
{
|
|
sqrRange = dist;
|
|
closest = npc;
|
|
}
|
|
}
|
|
|
|
return closest;
|
|
}
|
|
}
|
|
}
|