using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace FutureNowMod.NPCs
{
public class UPOSpy : ModNPC
{
public override void SetDefaults()
{
npc.name = "UPOSpy";
npc.displayName = "UPO Spy";
npc.width = 40;
npc.height = 20;
npc.damage = 500;
npc.defense = 30;
npc.lifeMax = 500;
npc.HitSound = SoundID.NPCHit4;
npc.DeathSound = SoundID.NPCDeath14;
npc.value = 60f;
npc.noGravity = true;
npc.knockBackResist = 0.3f;
npc.aiStyle = 2;
Main.npcFrameCount[npc.type] = Main.npcFrameCount[NPCID.DemonEye];
aiType = NPCID.EyeofCthulhu;
animationType = NPCID.DemonEye;
}
public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 0f : 3f;
}
public override void AI()
{
npc.ai[0]++;
Player P = Main.player[npc.target];
if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
{
npc.TargetClosest(true);
}
npc.netUpdate = true;
npc.ai[1]++;
if (npc.ai[1] >= 230) // 230 is projectile fire rate
{
float Speed = 20f; //Projecile speed
Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
int damage = 100; //projectile damage
int type = mod.ProjectileType("ShadowArm"); //put your projectile
Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
npc.ai[1] = 0;
}
public override void HitEffect(int hitDirection, double damage)
{
for (int i = 0; i < 10; i++)
{
int dustType = Main.rand.Next(259, 259);
int dustIndex = Dust.NewDust(npc.position, npc.width, npc.height, dustType);
Dust dust = Main.dust[dustIndex];
dust.velocity.X = dust.velocity.X + Main.rand.Next(-50, 51) * 0.01f;
dust.velocity.Y = dust.velocity.Y + Main.rand.Next(-50, 51) * 0.01f;
dust.scale *= 1f + Main.rand.Next(-30, 31) * 0.01f;
}
}
}
}