using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System.IO;
namespace BlastsMod.NPCs
{
[AutoloadBossHead]
public class DestroyerAnt : ModNPC
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Destroyer Ant");
Main.npcFrameCount[npc.type] = 6;
}
public override void SetDefaults()
{
npc.width = 144;
npc.height = 88;
npc.damage = 200;
npc.defense = 70;
npc.lifeMax = 50000;
npc.HitSound = SoundID.NPCHit4;
npc.DeathSound = SoundID.NPCDeath14;
npc.value = 100000f;
npc.knockBackResist = 0.0f;
npc.aiStyle = 3;
npc.boss = true;
npc.buffImmune[24] = true;
npc.buffImmune[69] = true;
npc.buffImmune[39] = true;
npc.buffImmune[31] = true;
npc.lavaImmune = true;
aiType = NPCID.SwampThing;
animationType = NPCID.Zombie;
music = MusicID.Boss3;
}
public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
{
npc.lifeMax = (int)(npc.lifeMax / Main.expertLife * 1.5f * bossLifeScale);
npc.defense = 90;
}
internal const int dpsCap = 3000;
public override float SpawnChance(NPCSpawnInfo spawnInfo)
{
if(NPC.downedMoonlord)
return SpawnCondition.SolarEclipse.Chance * 0.001f;
else
{
return SpawnCondition.SolarEclipse.Chance * 0.00f;
}
}
int attackCounter = 0;
int attackCounter2 = 0;
int attackCounter3 = 0;
int attackCounter4 = 0;
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(attackCounter);
writer.Write(attackCounter2);
writer.Write(attackCounter3);
writer.Write(attackCounter4);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
attackCounter = reader.ReadInt32();
attackCounter2 = reader.ReadInt32();
attackCounter3 = reader.ReadInt32();
attackCounter4 = reader.ReadInt32();
}
public override void AI() //this is where you program your AI
{
if(Main.netMode != 1)
{
if (npc.life >= npc.lifeMax/2)
{
if (attackCounter > 0)
attackCounter--;
Player target = Main.player[npc.target];
if (attackCounter <= 0 && Vector2.Distance(npc.Center, target.Center) < 1200 && Collision.CanHit(npc.Center, 1, 1, target.Center, 1, 1))
{
Vector2 direction = (target.Center - npc.Center).SafeNormalize(Vector2.UnitX);
direction = direction.RotatedByRandom(MathHelper.ToRadians(10));
int projectile = Projectile.NewProjectile(npc.Center, direction * 12, mod.ProjectileType("DestroyerLaser"), 40, 0, Main.myPlayer);
Main.projectile[projectile].timeLeft = 600;
attackCounter = 50;
npc.netUpdate = true;
}
}
else
{
npc.aiStyle = 2;
animationType = NPCID.Corruptor;
aiType = NPCID.DemonEye;
npc.noTileCollide = true;
if (attackCounter > 0)
attackCounter--;
Player target = Main.player[npc.target];
if (attackCounter <= 0 && Vector2.Distance(npc.Center, target.Center) < 1200 && Collision.CanHit(npc.Center, 1, 1, target.Center, 1, 1))
{
Vector2 direction = (target.Center - npc.Center).SafeNormalize(Vector2.UnitX);
direction = direction.RotatedByRandom(MathHelper.ToRadians(10));
int projectile = Projectile.NewProjectile(npc.Center, direction * 12, mod.ProjectileType("DestroyerLaser"), 40, 0, Main.myPlayer);
Main.projectile[projectile].timeLeft = 600;
attackCounter = 30;
npc.netUpdate = true;
}
}
}
if(Main.netMode != 1)
{
if (attackCounter2 > 0)
attackCounter2--;
if (attackCounter2 <= 0)
{
NPC.NewNPC((int)npc.position.X + npc.width, (int)npc.position.Y + npc.height, mod.NPCType("DestroyerDrone"));
attackCounter2 = 360;
}
}
if(Main.netMode != 1)
{
if (attackCounter3 > 0)
attackCounter3--;
Player target = Main.player[npc.target];
if (attackCounter3 <= 0 && Vector2.Distance(npc.Center, target.Center) > 1200 && Collision.CanHit(npc.Center, 1, 1, target.Center, 1, 1))
{
Vector2 direction = (target.Center - npc.Center).SafeNormalize(Vector2.UnitX);
direction = direction.RotatedByRandom(MathHelper.ToRadians(10));
int projectile = Projectile.NewProjectile(npc.Center, direction * 20, ProjectileID.RocketSkeleton, 50, 0, Main.myPlayer);
Main.projectile[projectile].timeLeft = 1200;
attackCounter3 = 15;
npc.netUpdate = true;
}
}
if(Main.netMode != 1)
{
if (npc.life <= npc.lifeMax/2)
{
if (attackCounter4 > 0)
attackCounter4--;
Player target = Main.player[npc.target];
if (attackCounter4 <= 0 && Vector2.Distance(npc.Center, target.Center) < 1200 && Collision.CanHit(npc.Center, 1, 1, target.Center, 1, 1))
{
Vector2 direction = (target.Center - npc.Center).SafeNormalize(Vector2.UnitX);
direction = direction.RotatedByRandom(MathHelper.ToRadians(10));
int projectile = Projectile.NewProjectile(npc.Center, direction * 12, ProjectileID.RocketSkeleton, 40, 0, Main.myPlayer);
Main.projectile[projectile].timeLeft = 600;
attackCounter4 = 120;
npc.netUpdate = true;
}
}
}
}
public override void NPCLoot()
{
Item.NewItem(npc.getRect(), mod.ItemType("InspiraniteIngot"), 20 + Main.rand.Next(5));
}
}
}