86 lines
2.7 KiB
C#
86 lines
2.7 KiB
C#
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
using Microsoft.Xna.Framework;
|
|
|
|
namespace ForgottenWawiTech.Content.NPCs.Enemies.AvalianInvasion
|
|
{
|
|
public class AvalianRifleman : ModNPC
|
|
{
|
|
private int shootTimer = 0;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
Main.npcFrameCount[Type] = 6;
|
|
NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers(0)
|
|
{
|
|
Velocity = 1f
|
|
};
|
|
NPCID.Sets.NPCBestiaryDrawOffset.Add(Type, value);
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
NPC.width = 34;
|
|
NPC.height = 42;
|
|
NPC.damage = 55;
|
|
NPC.defense = 20;
|
|
NPC.lifeMax = 400;
|
|
NPC.HitSound = SoundID.NPCHit1;
|
|
NPC.DeathSound = SoundID.NPCDeath6;
|
|
NPC.value = Item.buyPrice(0, 0, 10, 0);
|
|
NPC.knockBackResist = 0.3f;
|
|
NPC.aiStyle = NPCAIStyleID.Bat; // Flying ranged enemy
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
// Ranged attack behavior
|
|
Player target = Main.player[NPC.target];
|
|
if (target.active && !target.dead)
|
|
{
|
|
shootTimer++;
|
|
|
|
// Keep distance from player
|
|
float distanceToPlayer = Vector2.Distance(NPC.Center, target.Center);
|
|
if (distanceToPlayer < 300f)
|
|
{
|
|
// Move away
|
|
Vector2 awayDirection = Vector2.Normalize(NPC.Center - target.Center);
|
|
NPC.velocity = awayDirection * 3f;
|
|
}
|
|
|
|
// Shoot every 90 frames (1.5 seconds)
|
|
if (shootTimer >= 90)
|
|
{
|
|
shootTimer = 0;
|
|
|
|
if (Main.netMode != NetmodeID.MultiplayerClient)
|
|
{
|
|
Vector2 shootDirection = Vector2.Normalize(target.Center - NPC.Center);
|
|
Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center,
|
|
shootDirection * 10f, ProjectileID.BulletHighVelocity,
|
|
NPC.damage / 2, 1f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void HitEffect(NPC.HitInfo hit)
|
|
{
|
|
if (NPC.life <= 0)
|
|
{
|
|
for (int i = 0; i < 12; i++)
|
|
{
|
|
Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Feather);
|
|
}
|
|
}
|
|
}
|
|
|
|
public override float SpawnChance(NPCSpawnInfo spawnInfo)
|
|
{
|
|
return 0f; // Controlled by invasion system
|
|
}
|
|
}
|
|
}
|