using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;
using Microsoft.Xna.Framework;
namespace InsaneCrazyThing.Items
{
class TryAgain : ModNPC
{
private int ai;
private int attackTimer = 0;
private bool fastspeed = false;
private Player player;
private float speed;
private bool Eye = false;
private bool Corrupt = false;
private bool Bones = false;
private bool Mech = false;
private bool Golem = false;
private bool EpicAttack = false;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Charc");
}
public override void SetDefaults()
{
npc.width = 96;
npc.height = 96;
Main.npcFrameCount[npc.type] = 4;
npc.lifeMax = 400000;
npc.damage = 100;
npc.defense = 50;
npc.knockBackResist = 0f;
npc.aiStyle = -1;
Main.npcFrameCount[npc.type] = 4;
aiType = 5;
npc.HitSound = SoundID.NPCHit1;
npc.DeathSound = SoundID.NPCDeath2;
npc.noGravity = true;
npc.boss = true;
npc.netAlways = true;
npc.lavaImmune = true;
npc.npcSlots = 1f;
npc.noTileCollide = true;
npc.buffImmune[24] = true;
npc.lavaImmune = true;
npc.value = Item.buyPrice(999, 99, 99, 99);
music = mod.GetSoundSlot(SoundType.Music, "Items/TryAgain");
bossBag = mod.ItemType("TryAgainBag");
}
public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
{
npc.lifeMax = (int)(npc.lifeMax * 0.579f * bossLifeScale); //boss life scale in expertmode
npc.damage = (int)(npc.damage * 0.6f); //boss damage increase in expermode
}
public override void AI()
{
Target();
DespawnHandler();
Move(new Vector2(0, 400));
Move(new Vector2(0, -400));
Move(new Vector2(400, -400));
Move(new Vector2(-400, 400));
if(npc.life < 390000)
{
if (Eye == false)
{
Main.NewText("My Brothers And Sisters, It is time for revenge!");
NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, NPCID.EyeofCthulhu);
Eye = true;
}
}
if (npc.life < 370000)
{
if (Corrupt == false)
{
NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, NPCID.EaterofWorldsHead);
NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, NPCID.BrainofCthulhu);
Corrupt = true;
}
}
if (npc.life < 300000)
{
if (Mech == false)
{
Main.NewText("My Mechanical Buddies, Arise!");
NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, NPCID.TheDestroyer);
NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, NPCID.SkeletronPrime);
NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, NPCID.Spazmatism);
NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, NPCID.Retinazer);
Mech = true;
}
}
if (npc.life < 270000)
{
if (Golem == false)
{
Main.NewText("Golem, Youare freed from the altar");
NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, NPCID.Golem);
Golem = true;
}
}
if (npc.life < 200000)
{
if (Bones == false)
{
Main.NewText("Foolish Child, Here comes three more!");
NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, NPCID.QueenBee);
NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, NPCID.SkeletronHead);
NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, NPCID.SkeletronHand);
NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, NPCID.SkeletronHand);
NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, NPCID.CultistBoss);
Bones = true;
}
}
if (npc.life < 100000)
{
if (EpicAttack == false)
{
Main.NewText("I shall never Die");
NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("Boss2npc"));
NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("Boss1npc"));
Vector2 perturbedSpeed = new Vector2(player.position.X + player.width / 2, player.position.Y + player.height / 2) -
new Vector2(npc.position.X + npc.width / 2, npc.position.Y + npc.height / 2); // 30 degree spread.
// If you want to randomize the speed to stagger the projectiles
// float scale = 1f - (Main.rand.NextFloat() * .3f);
// perturbedSpeed = perturbedSpeed * scale;
Projectile.NewProjectile(npc.position.X + npc.width / 2, npc.position.Y + npc.height / 2, perturbedSpeed.X, perturbedSpeed.Y, ProjectileID.DeathSickle, 2000, 2000, player.whoAmI, player.whoAmI, 0f);
EpicAttack = true;
}
}
}
public override void NPCLoot()
{
if (Main.expertMode)
{
npc.DropBossBags();
}
else
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("Doom"), 1);
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("Steel_Bar"), Main.rand.Next(1, 50));
}
}
public override void BossLoot(ref string name, ref int potionType)
{
Main.NewText("Remach...");
Main.PlaySound(SoundID.Roar, npc.position);
potionType = ItemID.SuperHealingPotion;
}
private void Target()
{
player = Main.player[npc.target]; // This will get the player target.
}
private void DespawnHandler()
{
if (!player.active || player.dead)
{
npc.TargetClosest(false);
player = Main.player[npc.target];
if (!player.active || player.dead)
{
npc.velocity = new Vector2(0f, -10f);
if (npc.timeLeft > 10)
{
npc.timeLeft = 10;
}
return;
}
}
}
private void Move(Vector2 offset)
{
speed = 30f; // Sets the max speed of the npc.
Vector2 moveTo = player.Center - offset; // Gets the point that the npc will be moving to.
Vector2 move = moveTo - npc.Center;
float magnitude = Magnitude(move);
if (magnitude > speed)
{
move *= speed / magnitude;
}
float turnResistance = 10f; // The larget the number the slower the npc will turn.
move = (npc.velocity * turnResistance + move) / (turnResistance + 1f);
magnitude = Magnitude(move);
if (magnitude > speed)
{
move *= speed / magnitude;
}
npc.velocity = move;
Shoot();
}
private float Magnitude(Vector2 mag)
{
return (float)Math.Sqrt(mag.X * mag.X + mag.Y * mag.Y);
}
public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position)
{
scale = 1.5f;
return null;
}
private void Shoot()
{
if (Main.rand.Next(1, 200) == 199)
{
Vector2 perturbedSpeed = new Vector2(player.position.X + player.width / 2, player.position.Y + player.height / 2) -
new Vector2(npc.position.X + npc.width / 2, npc.position.Y + npc.height / 2).RotatedByRandom(MathHelper.ToRadians(1)); // 30 degree spread.
// If you want to randomize the speed to stagger the projectiles
// float scale = 1f - (Main.rand.NextFloat() * .3f);
// perturbedSpeed = perturbedSpeed * scale;
Projectile.NewProjectile(npc.position.X + npc.width / 2, npc.position.Y + npc.height / 2, perturbedSpeed.X, perturbedSpeed.Y, ProjectileID.PinkLaser, 200, 5, player.whoAmI, player.whoAmI, 0f);
}
}
public override float SpawnChance(NPCSpawnInfo spawnInfo)
{
if (NPC.downedMoonlord && player.statDefense >= 70 || NPC.downedMoonlord && player.endurance >= 15)
{
return 0.1f;
}else
{
return 0f;
}
}
}
}