127 lines
4.5 KiB
C#
127 lines
4.5 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
using Terraria.Audio;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
using ForgottenWawiTech.Content.Players;
|
|
|
|
namespace ForgottenWawiTech.Content.Projectiles.Avali
|
|
{
|
|
public class AvaliHuntingDrone : ModProjectile
|
|
{
|
|
private const float OrbitSpeed = 0.045f;
|
|
private const float OrbitRadius = 96f;
|
|
private const int ShootCooldown = 28;
|
|
private const float TargetRange = 920f;
|
|
private const float ShotSpeed = 19.5f;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
ProjectileID.Sets.MinionSacrificable[Type] = false;
|
|
ProjectileID.Sets.MinionTargettingFeature[Type] = true;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.width = 26;
|
|
Projectile.height = 26;
|
|
Projectile.friendly = false;
|
|
Projectile.minion = true;
|
|
Projectile.penetrate = -1;
|
|
Projectile.tileCollide = false;
|
|
Projectile.ignoreWater = true;
|
|
Projectile.DamageType = DamageClass.Summon;
|
|
Projectile.netImportant = true;
|
|
Projectile.timeLeft = 2;
|
|
Projectile.minionSlots = 0f;
|
|
Projectile.damage = 0;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Player owner = Main.player[Projectile.owner];
|
|
AvaliVanguardPlayer modPlayer = owner.GetModPlayer<AvaliVanguardPlayer>();
|
|
if (!owner.active || owner.dead || !modPlayer.HuntingDronesActive)
|
|
{
|
|
Projectile.Kill();
|
|
return;
|
|
}
|
|
|
|
Projectile.timeLeft = 2;
|
|
|
|
float index = Projectile.ai[0];
|
|
float total = Projectile.ai[1];
|
|
if (total <= 0f)
|
|
{
|
|
total = 3f;
|
|
}
|
|
|
|
float rotation = (Main.GameUpdateCount * OrbitSpeed) + index * MathHelper.TwoPi / total;
|
|
Vector2 offset = rotation.ToRotationVector2() * OrbitRadius;
|
|
Projectile.Center = owner.Center + offset;
|
|
Projectile.velocity = owner.velocity;
|
|
Projectile.rotation = (owner.Center - Projectile.Center).ToRotation() + MathHelper.PiOver2;
|
|
|
|
Lighting.AddLight(Projectile.Center, 0.35f, 0.6f, 1f);
|
|
|
|
if (Projectile.owner == Main.myPlayer)
|
|
{
|
|
Projectile.localAI[0]++;
|
|
if (Projectile.localAI[0] >= ShootCooldown)
|
|
{
|
|
Projectile.localAI[0] = 0f;
|
|
NPC target = AcquireTarget(owner, Projectile.Center, TargetRange);
|
|
if (target != null)
|
|
{
|
|
Vector2 velocity = (target.Center - Projectile.Center).SafeNormalize(Vector2.UnitY) * ShotSpeed;
|
|
int damage = AvaliVanguardPlayer.GetDroneBaseDamage(owner);
|
|
var source = Projectile.GetSource_FromAI();
|
|
Projectile.NewProjectile(
|
|
source,
|
|
Projectile.Center,
|
|
velocity,
|
|
ModContent.ProjectileType<AvaliHuntingDroneShot>(),
|
|
damage,
|
|
2f,
|
|
owner.whoAmI);
|
|
SoundEngine.PlaySound(SoundID.Item12 with { Volume = 0.6f }, Projectile.Center);
|
|
Projectile.netUpdate = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static NPC AcquireTarget(Player owner, Vector2 center, float range)
|
|
{
|
|
if (owner.HasMinionAttackTargetNPC)
|
|
{
|
|
NPC target = Main.npc[owner.MinionAttackTargetNPC];
|
|
if (target.CanBeChasedBy())
|
|
{
|
|
return target;
|
|
}
|
|
}
|
|
|
|
NPC closest = null;
|
|
float squaredRange = 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 distance = Vector2.DistanceSquared(npc.Center, center);
|
|
if (distance <= squaredRange && Collision.CanHitLine(center, 0, 0, npc.Center, 0, 0))
|
|
{
|
|
squaredRange = distance;
|
|
closest = npc;
|
|
}
|
|
}
|
|
|
|
return closest;
|
|
}
|
|
}
|
|
}
|