using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; using ForgottenWawiTech.Content.Buffs.Debuffs; using ForgottenWawiTech.Content.Players; namespace ForgottenWawiTech.Content.Projectiles.Avali { public class AvaliThermalDrone : ModProjectile { private const float OrbitSpeed = 0.06f; private const float OrbitRadius = 72f; private const int MarkCooldown = 45; private const float MarkRange = 700f; public override string Texture => "ForgottenWawiTech/Assets/PlaceholderProj"; public override void SetStaticDefaults() { ProjectileID.Sets.MinionSacrificable[Type] = false; ProjectileID.Sets.MinionShot[Type] = true; } public override void SetDefaults() { Projectile.width = 26; Projectile.height = 26; Projectile.friendly = true; Projectile.DamageType = DamageClass.Summon; Projectile.penetrate = -1; Projectile.tileCollide = false; Projectile.ignoreWater = true; Projectile.timeLeft = 2; Projectile.netImportant = true; Projectile.minion = true; Projectile.minionSlots = 0f; } public override void AI() { Player owner = Main.player[Projectile.owner]; AvaliSkirmisherPlayer modPlayer = owner.GetModPlayer(); if (!owner.active || owner.dead || !modPlayer.ThermalDronesActive) { Projectile.Kill(); return; } Projectile.timeLeft = 2; float index = Projectile.ai[0]; float total = Projectile.ai[1]; if (total <= 0f) { total = 2f; } float rotation = (Main.GameUpdateCount * OrbitSpeed) + index * MathHelper.TwoPi / total; Vector2 offset = rotation.ToRotationVector2() * OrbitRadius; Projectile.Center = owner.Center + offset; Projectile.velocity = owner.velocity; Lighting.AddLight(Projectile.Center, 0.55f, 0.2f, 0.15f); if (Projectile.localAI[0]++ >= MarkCooldown) { Projectile.localAI[0] = 0f; if (Projectile.owner == Main.myPlayer) { NPC target = FindTarget(Projectile.Center, MarkRange); if (target != null) { target.AddBuff(ModContent.BuffType(), 300); Vector2 burstDirection = (target.Center - Projectile.Center).SafeNormalize(Vector2.UnitY); for (int i = 0; i < 6; i++) { Dust dust = Dust.NewDustDirect(Projectile.Center, 0, 0, DustID.Torch, burstDirection.X * 4f, burstDirection.Y * 4f, 120, default, 1.1f); dust.noGravity = true; } } } } } private static NPC FindTarget(Vector2 center, float range) { NPC selected = 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(center, npc.Center); if (dist < sqrRange && Collision.CanHitLine(center, 0, 0, npc.Center, 0, 0)) { sqrRange = dist; selected = npc; } } return selected; } } }