84 lines
2.7 KiB
C#
84 lines
2.7 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace ForgottenWawiTech.Content.Projectiles.Transcendent
|
|
{
|
|
public class TranscendentNaniteShard : ModProjectile
|
|
{
|
|
private const float HomingRange = 680f;
|
|
private const float HomingStrength = 0.22f;
|
|
private const float DesiredSpeed = 18f;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
ProjectileID.Sets.MinionShot[Type] = true;
|
|
}
|
|
|
|
public override string Texture => "ForgottenWawiTech/Assets/PlaceholderProj";
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.width = 14;
|
|
Projectile.height = 14;
|
|
Projectile.friendly = true;
|
|
Projectile.penetrate = 1;
|
|
Projectile.timeLeft = 220;
|
|
Projectile.tileCollide = false;
|
|
Projectile.ignoreWater = true;
|
|
Projectile.extraUpdates = 1;
|
|
Projectile.DamageType = DamageClass.Generic;
|
|
Projectile.usesLocalNPCImmunity = true;
|
|
Projectile.localNPCHitCooldown = 12;
|
|
Projectile.alpha = 60;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Projectile.rotation += 0.35f * Projectile.direction;
|
|
Lighting.AddLight(Projectile.Center, 0.45f, 0.8f, 1.15f);
|
|
|
|
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);
|
|
}
|
|
else
|
|
{
|
|
Projectile.velocity *= 0.98f;
|
|
}
|
|
|
|
if (Main.rand.NextBool(5))
|
|
{
|
|
Dust dust = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, DustID.Electric, 0f, 0f, 120, default, 1.05f);
|
|
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;
|
|
}
|
|
}
|
|
}
|