From 91fae83f1acaf5ce260ea50ee4ab6a2d7291fbe5 Mon Sep 17 00:00:00 2001 From: SheerExpanse Date: Sat, 13 Jul 2019 22:46:07 -0400 Subject: [PATCH] Polterghast only enrages on surface --- NPCs/Polterghast/PolterPhantom.cs | 620 +++++----- NPCs/Polterghast/Polterghast.cs | 1624 +++++++++++++-------------- NPCs/Polterghast/PolterghastHook.cs | 969 ++++++++-------- 3 files changed, 1607 insertions(+), 1606 deletions(-) diff --git a/NPCs/Polterghast/PolterPhantom.cs b/NPCs/Polterghast/PolterPhantom.cs index e4a03b1fd9..f50bf2f894 100644 --- a/NPCs/Polterghast/PolterPhantom.cs +++ b/NPCs/Polterghast/PolterPhantom.cs @@ -1,310 +1,310 @@ -using System; -using System.Collections.Generic; -using System.IO; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.Localization; -using Terraria.ID; -using Terraria.ModLoader; -using CalamityMod.Projectiles; -using CalamityMod.World; - -namespace CalamityMod.NPCs.Polterghast -{ - public class PolterPhantom : ModNPC - { - private int despawnTimer = 600; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Polterghast"); - Main.npcFrameCount[npc.type] = 4; - } - - public override void SetDefaults() - { - npc.damage = 210; - npc.width = 90; - npc.height = 120; - npc.defense = 0; - npc.lifeMax = CalamityWorld.revenge ? 150000 : 130000; - if (CalamityWorld.death) - { - npc.lifeMax = 225000; - } - if (CalamityWorld.bossRushActive) - { - npc.lifeMax = CalamityWorld.death ? 1100000 : 900000; - } - double HPBoost = (double)Config.BossHealthPercentageBoost * 0.01; - npc.lifeMax += (int)((double)npc.lifeMax * HPBoost); - npc.knockBackResist = 0f; - npc.aiStyle = -1; //new - aiType = -1; //new - npc.alpha = 255; - for (int k = 0; k < npc.buffImmune.Length; k++) - { - npc.buffImmune[k] = true; - } - npc.buffImmune[BuffID.Ichor] = false; - npc.buffImmune[BuffID.CursedInferno] = false; - npc.buffImmune[mod.BuffType("AbyssalFlames")] = false; - npc.buffImmune[mod.BuffType("DemonFlames")] = false; - npc.buffImmune[mod.BuffType("GodSlayerInferno")] = false; - npc.buffImmune[mod.BuffType("Nightwither")] = false; - npc.buffImmune[mod.BuffType("Shred")] = false; - npc.noGravity = true; - npc.noTileCollide = true; - npc.netAlways = true; - npc.canGhostHeal = false; - npc.HitSound = SoundID.NPCHit36; - npc.DeathSound = SoundID.NPCDeath39; - } - - public override void SendExtraAI(BinaryWriter writer) - { - writer.Write(despawnTimer); - } - - public override void ReceiveExtraAI(BinaryReader reader) - { - despawnTimer = reader.ReadInt32(); - } - - public override void AI() - { - CalamityGlobalNPC.ghostBossClone = npc.whoAmI; - npc.alpha -= 5; - if (npc.alpha < 50) - { - npc.alpha = 50; - } - if (CalamityGlobalNPC.ghostBoss < 0 || !Main.npc[CalamityGlobalNPC.ghostBoss].active) - { - npc.active = false; - npc.netUpdate = true; - return; - } - Lighting.AddLight((int)((npc.position.X + (float)(npc.width / 2)) / 16f), (int)((npc.position.Y + (float)(npc.height / 2)) / 16f), 0.5f, 0.25f, 0.75f); - npc.TargetClosest(true); - Vector2 vector = npc.Center; - if (Vector2.Distance(Main.player[npc.target].Center, vector) > 6000f) - { - npc.active = false; - } - bool speedBoost1 = false; - bool despawnBoost = false; - if (npc.timeLeft < 1500) - { - npc.timeLeft = 1500; - } - bool revenge = (CalamityWorld.revenge || CalamityWorld.bossRushActive); - bool expertMode = (Main.expertMode || CalamityWorld.bossRushActive); - int[] array2 = new int[4]; - float num730 = 0f; - float num731 = 0f; - int num732 = 0; - int num; - for (int num733 = 0; num733 < 200; num733 = num + 1) - { - if (Main.npc[num733].active && Main.npc[num733].type == mod.NPCType("PolterghastHook")) - { - num730 += Main.npc[num733].Center.X; - num731 += Main.npc[num733].Center.Y; - array2[num732] = num733; - num732++; - if (num732 > 3) - break; - } - num = num733; - } - num730 /= (float)num732; - num731 /= (float)num732; - float num734 = 3f; - float num735 = 0.03f; - if (!Main.player[npc.target].ZoneDungeon) - { - despawnTimer--; - if (despawnTimer <= 0) - despawnBoost = true; - speedBoost1 = true; - num734 += 8f; - num735 = 0.15f; - } - else - { - despawnTimer = 600; - } - if (Main.npc[CalamityGlobalNPC.ghostBoss].ai[2] < 300f) - { - num734 = 18f; - num735 = 0.12f; - } - if (expertMode) - { - num734 += revenge ? 1.5f : 1f; - num734 *= revenge ? 1.25f : 1.1f; - num735 += revenge ? 0.015f : 0.01f; - num735 *= revenge ? 1.2f : 1.1f; - } - Vector2 vector91 = new Vector2(num730, num731); - float num736 = Main.player[npc.target].Center.X - vector91.X; - float num737 = Main.player[npc.target].Center.Y - vector91.Y; - if (despawnBoost) - { - num737 *= -1f; - num736 *= -1f; - num734 += 8f; - } - float num738 = (float)Math.Sqrt((double)(num736 * num736 + num737 * num737)); - int num739 = 500; - if (speedBoost1) - { - num739 += 500; - } - if (expertMode) - { - num739 += 150; - } - if (num738 >= (float)num739) - { - num738 = (float)num739 / num738; - num736 *= num738; - num737 *= num738; - } - num730 += num736; - num731 += num737; - vector91 = new Vector2(vector.X, vector.Y); - num736 = num730 - vector91.X; - num737 = num731 - vector91.Y; - num738 = (float)Math.Sqrt((double)(num736 * num736 + num737 * num737)); - if (num738 < num734) - { - num736 = npc.velocity.X; - num737 = npc.velocity.Y; - } - else - { - num738 = num734 / num738; - num736 *= num738; - num737 *= num738; - } - if (npc.velocity.X < num736) - { - npc.velocity.X = npc.velocity.X + num735; - if (npc.velocity.X < 0f && num736 > 0f) - { - npc.velocity.X = npc.velocity.X + num735 * 2f; - } - } - else if (npc.velocity.X > num736) - { - npc.velocity.X = npc.velocity.X - num735; - if (npc.velocity.X > 0f && num736 < 0f) - { - npc.velocity.X = npc.velocity.X - num735 * 2f; - } - } - if (npc.velocity.Y < num737) - { - npc.velocity.Y = npc.velocity.Y + num735; - if (npc.velocity.Y < 0f && num737 > 0f) - { - npc.velocity.Y = npc.velocity.Y + num735 * 2f; - } - } - else if (npc.velocity.Y > num737) - { - npc.velocity.Y = npc.velocity.Y - num735; - if (npc.velocity.Y > 0f && num737 < 0f) - { - npc.velocity.Y = npc.velocity.Y - num735 * 2f; - } - } - Vector2 vector92 = new Vector2(vector.X, vector.Y); - float num740 = Main.player[npc.target].Center.X - vector92.X; - float num741 = Main.player[npc.target].Center.Y - vector92.Y; - npc.rotation = (float)Math.Atan2((double)num741, (double)num740) + 1.57f; - if (speedBoost1) - { - npc.defense = 400; - npc.damage = 1200; - } - else - { - npc.damage = expertMode ? 336 : 210; - npc.defense = 0; - } - } - - public override Color? GetAlpha(Color drawColor) - { - return new Color(200, 150, 255, npc.alpha); - } - - public override void FindFrame(int frameHeight) - { - npc.frameCounter += 1.0; - if (npc.frameCounter > 6.0) - { - npc.frameCounter = 0.0; - npc.frame.Y = npc.frame.Y + frameHeight; - } - if (npc.frame.Y > frameHeight * 3) - { - npc.frame.Y = 0; - } - } - - public override void OnHitPlayer(Player player, int damage, bool crit) - { - if (CalamityWorld.revenge) - player.AddBuff(mod.BuffType("Horror"), 180, true); - } - - public override bool CanHitPlayer(Player target, ref int cooldownSlot) - { - cooldownSlot = 1; - return true; - } - - public override void ScaleExpertStats(int numPlayers, float bossLifeScale) - { - npc.lifeMax = (int)(npc.lifeMax * 0.8f * bossLifeScale); - npc.damage = (int)(npc.damage * 0.8f); - } - - public override void HitEffect(int hitDirection, double damage) - { - Dust.NewDust(npc.position, npc.width, npc.height, 180, hitDirection, -1f, 0, default(Color), 1f); - if (npc.life <= 0) - { - npc.position.X = npc.position.X + (float)(npc.width / 2); - npc.position.Y = npc.position.Y + (float)(npc.height / 2); - npc.width = 90; - npc.height = 90; - npc.position.X = npc.position.X - (float)(npc.width / 2); - npc.position.Y = npc.position.Y - (float)(npc.height / 2); - for (int num621 = 0; num621 < 10; num621++) - { - int num622 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 60, 0f, 0f, 100, default(Color), 2f); - Main.dust[num622].velocity *= 3f; - if (Main.rand.Next(2) == 0) - { - Main.dust[num622].scale = 0.5f; - Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; - } - } - for (int num623 = 0; num623 < 60; num623++) - { - int num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 3f); - Main.dust[num624].noGravity = true; - Main.dust[num624].velocity *= 5f; - num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 2f); - Main.dust[num624].velocity *= 2f; - } - } - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Localization; +using Terraria.ID; +using Terraria.ModLoader; +using CalamityMod.Projectiles; +using CalamityMod.World; + +namespace CalamityMod.NPCs.Polterghast +{ + public class PolterPhantom : ModNPC + { + private int despawnTimer = 600; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Polterghast"); + Main.npcFrameCount[npc.type] = 4; + } + + public override void SetDefaults() + { + npc.damage = 210; + npc.width = 90; + npc.height = 120; + npc.defense = 0; + npc.lifeMax = CalamityWorld.revenge ? 150000 : 130000; + if (CalamityWorld.death) + { + npc.lifeMax = 225000; + } + if (CalamityWorld.bossRushActive) + { + npc.lifeMax = CalamityWorld.death ? 1100000 : 900000; + } + double HPBoost = (double)Config.BossHealthPercentageBoost * 0.01; + npc.lifeMax += (int)((double)npc.lifeMax * HPBoost); + npc.knockBackResist = 0f; + npc.aiStyle = -1; //new + aiType = -1; //new + npc.alpha = 255; + for (int k = 0; k < npc.buffImmune.Length; k++) + { + npc.buffImmune[k] = true; + } + npc.buffImmune[BuffID.Ichor] = false; + npc.buffImmune[BuffID.CursedInferno] = false; + npc.buffImmune[mod.BuffType("AbyssalFlames")] = false; + npc.buffImmune[mod.BuffType("DemonFlames")] = false; + npc.buffImmune[mod.BuffType("GodSlayerInferno")] = false; + npc.buffImmune[mod.BuffType("Nightwither")] = false; + npc.buffImmune[mod.BuffType("Shred")] = false; + npc.noGravity = true; + npc.noTileCollide = true; + npc.netAlways = true; + npc.canGhostHeal = false; + npc.HitSound = SoundID.NPCHit36; + npc.DeathSound = SoundID.NPCDeath39; + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(despawnTimer); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + despawnTimer = reader.ReadInt32(); + } + + public override void AI() + { + CalamityGlobalNPC.ghostBossClone = npc.whoAmI; + npc.alpha -= 5; + if (npc.alpha < 50) + { + npc.alpha = 50; + } + if (CalamityGlobalNPC.ghostBoss < 0 || !Main.npc[CalamityGlobalNPC.ghostBoss].active) + { + npc.active = false; + npc.netUpdate = true; + return; + } + Lighting.AddLight((int)((npc.position.X + (float)(npc.width / 2)) / 16f), (int)((npc.position.Y + (float)(npc.height / 2)) / 16f), 0.5f, 0.25f, 0.75f); + npc.TargetClosest(true); + Vector2 vector = npc.Center; + if (Vector2.Distance(Main.player[npc.target].Center, vector) > 6000f) + { + npc.active = false; + } + bool speedBoost1 = false; + bool despawnBoost = false; + if (npc.timeLeft < 1500) + { + npc.timeLeft = 1500; + } + bool revenge = (CalamityWorld.revenge || CalamityWorld.bossRushActive); + bool expertMode = (Main.expertMode || CalamityWorld.bossRushActive); + int[] array2 = new int[4]; + float num730 = 0f; + float num731 = 0f; + int num732 = 0; + int num; + for (int num733 = 0; num733 < 200; num733 = num + 1) + { + if (Main.npc[num733].active && Main.npc[num733].type == mod.NPCType("PolterghastHook")) + { + num730 += Main.npc[num733].Center.X; + num731 += Main.npc[num733].Center.Y; + array2[num732] = num733; + num732++; + if (num732 > 3) + break; + } + num = num733; + } + num730 /= (float)num732; + num731 /= (float)num732; + float num734 = 3f; + float num735 = 0.03f; + if (!Main.player[npc.target].ZoneDungeon && !CalamityWorld.bossRushActive && (double)Main.player[npc.target].position.Y < Main.worldSurface * 16.0) + { + despawnTimer--; + if (despawnTimer <= 0) + despawnBoost = true; + speedBoost1 = true; + num734 += 8f; + num735 = 0.15f; + } + else + { + despawnTimer = 600; + } + if (Main.npc[CalamityGlobalNPC.ghostBoss].ai[2] < 300f) + { + num734 = 18f; + num735 = 0.12f; + } + if (expertMode) + { + num734 += revenge ? 1.5f : 1f; + num734 *= revenge ? 1.25f : 1.1f; + num735 += revenge ? 0.015f : 0.01f; + num735 *= revenge ? 1.2f : 1.1f; + } + Vector2 vector91 = new Vector2(num730, num731); + float num736 = Main.player[npc.target].Center.X - vector91.X; + float num737 = Main.player[npc.target].Center.Y - vector91.Y; + if (despawnBoost) + { + num737 *= -1f; + num736 *= -1f; + num734 += 8f; + } + float num738 = (float)Math.Sqrt((double)(num736 * num736 + num737 * num737)); + int num739 = 500; + if (speedBoost1) + { + num739 += 500; + } + if (expertMode) + { + num739 += 150; + } + if (num738 >= (float)num739) + { + num738 = (float)num739 / num738; + num736 *= num738; + num737 *= num738; + } + num730 += num736; + num731 += num737; + vector91 = new Vector2(vector.X, vector.Y); + num736 = num730 - vector91.X; + num737 = num731 - vector91.Y; + num738 = (float)Math.Sqrt((double)(num736 * num736 + num737 * num737)); + if (num738 < num734) + { + num736 = npc.velocity.X; + num737 = npc.velocity.Y; + } + else + { + num738 = num734 / num738; + num736 *= num738; + num737 *= num738; + } + if (npc.velocity.X < num736) + { + npc.velocity.X = npc.velocity.X + num735; + if (npc.velocity.X < 0f && num736 > 0f) + { + npc.velocity.X = npc.velocity.X + num735 * 2f; + } + } + else if (npc.velocity.X > num736) + { + npc.velocity.X = npc.velocity.X - num735; + if (npc.velocity.X > 0f && num736 < 0f) + { + npc.velocity.X = npc.velocity.X - num735 * 2f; + } + } + if (npc.velocity.Y < num737) + { + npc.velocity.Y = npc.velocity.Y + num735; + if (npc.velocity.Y < 0f && num737 > 0f) + { + npc.velocity.Y = npc.velocity.Y + num735 * 2f; + } + } + else if (npc.velocity.Y > num737) + { + npc.velocity.Y = npc.velocity.Y - num735; + if (npc.velocity.Y > 0f && num737 < 0f) + { + npc.velocity.Y = npc.velocity.Y - num735 * 2f; + } + } + Vector2 vector92 = new Vector2(vector.X, vector.Y); + float num740 = Main.player[npc.target].Center.X - vector92.X; + float num741 = Main.player[npc.target].Center.Y - vector92.Y; + npc.rotation = (float)Math.Atan2((double)num741, (double)num740) + 1.57f; + if (speedBoost1) + { + npc.defense = 400; + npc.damage = 1200; + } + else + { + npc.damage = expertMode ? 336 : 210; + npc.defense = 0; + } + } + + public override Color? GetAlpha(Color drawColor) + { + return new Color(200, 150, 255, npc.alpha); + } + + public override void FindFrame(int frameHeight) + { + npc.frameCounter += 1.0; + if (npc.frameCounter > 6.0) + { + npc.frameCounter = 0.0; + npc.frame.Y = npc.frame.Y + frameHeight; + } + if (npc.frame.Y > frameHeight * 3) + { + npc.frame.Y = 0; + } + } + + public override void OnHitPlayer(Player player, int damage, bool crit) + { + if (CalamityWorld.revenge) + player.AddBuff(mod.BuffType("Horror"), 180, true); + } + + public override bool CanHitPlayer(Player target, ref int cooldownSlot) + { + cooldownSlot = 1; + return true; + } + + public override void ScaleExpertStats(int numPlayers, float bossLifeScale) + { + npc.lifeMax = (int)(npc.lifeMax * 0.8f * bossLifeScale); + npc.damage = (int)(npc.damage * 0.8f); + } + + public override void HitEffect(int hitDirection, double damage) + { + Dust.NewDust(npc.position, npc.width, npc.height, 180, hitDirection, -1f, 0, default(Color), 1f); + if (npc.life <= 0) + { + npc.position.X = npc.position.X + (float)(npc.width / 2); + npc.position.Y = npc.position.Y + (float)(npc.height / 2); + npc.width = 90; + npc.height = 90; + npc.position.X = npc.position.X - (float)(npc.width / 2); + npc.position.Y = npc.position.Y - (float)(npc.height / 2); + for (int num621 = 0; num621 < 10; num621++) + { + int num622 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 60, 0f, 0f, 100, default(Color), 2f); + Main.dust[num622].velocity *= 3f; + if (Main.rand.Next(2) == 0) + { + Main.dust[num622].scale = 0.5f; + Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; + } + } + for (int num623 = 0; num623 < 60; num623++) + { + int num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 3f); + Main.dust[num624].noGravity = true; + Main.dust[num624].velocity *= 5f; + num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 2f); + Main.dust[num624].velocity *= 2f; + } + } + } + } +} \ No newline at end of file diff --git a/NPCs/Polterghast/Polterghast.cs b/NPCs/Polterghast/Polterghast.cs index 6a92500883..418c6dd784 100644 --- a/NPCs/Polterghast/Polterghast.cs +++ b/NPCs/Polterghast/Polterghast.cs @@ -1,812 +1,812 @@ -using System; -using System.Collections.Generic; -using System.IO; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.Localization; -using Terraria.ID; -using Terraria.ModLoader; -using CalamityMod.Projectiles; -using CalamityMod.World; - -namespace CalamityMod.NPCs.Polterghast -{ - [AutoloadBossHead] - public class Polterghast : ModNPC - { - private int despawnTimer = 600; - private bool spawnGhost = false; - private bool boostDR = false; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Polterghast"); - Main.npcFrameCount[npc.type] = 12; - } - - public override void SetDefaults() - { - npc.npcSlots = 50f; - npc.damage = 150; - npc.width = 90; - npc.height = 120; - npc.defense = 150; - npc.lifeMax = CalamityWorld.revenge ? 495000 : 412500; - if (CalamityWorld.death) - { - npc.lifeMax = 660000; - } - if (CalamityWorld.bossRushActive) - { - npc.lifeMax = CalamityWorld.death ? 2800000 : 2500000; - } - double HPBoost = (double)Config.BossHealthPercentageBoost * 0.01; - npc.lifeMax += (int)((double)npc.lifeMax * HPBoost); - npc.knockBackResist = 0f; - npc.aiStyle = -1; //new - aiType = -1; //new - npc.value = Item.buyPrice(0, 60, 0, 0); - npc.boss = true; - for (int k = 0; k < npc.buffImmune.Length; k++) - { - npc.buffImmune[k] = true; - } - npc.buffImmune[BuffID.Ichor] = false; - npc.buffImmune[BuffID.CursedInferno] = false; - npc.buffImmune[mod.BuffType("AbyssalFlames")] = false; - npc.buffImmune[mod.BuffType("DemonFlames")] = false; - npc.buffImmune[mod.BuffType("GodSlayerInferno")] = false; - npc.buffImmune[mod.BuffType("Nightwither")] = false; - npc.buffImmune[mod.BuffType("Shred")] = false; - npc.noGravity = true; - npc.noTileCollide = true; - npc.netAlways = true; - Mod calamityModMusic = ModLoader.GetMod("CalamityModMusic"); - if (calamityModMusic != null) - music = calamityModMusic.GetSoundSlot(SoundType.Music, "Sounds/Music/RUIN"); - else - music = MusicID.Plantera; - npc.HitSound = SoundID.NPCHit7; - npc.DeathSound = SoundID.NPCDeath39; - bossBag = mod.ItemType("PolterghastBag"); - } - - public override void SendExtraAI(BinaryWriter writer) - { - writer.Write(spawnGhost); - writer.Write(boostDR); - writer.Write(despawnTimer); - } - - public override void ReceiveExtraAI(BinaryReader reader) - { - spawnGhost = reader.ReadBoolean(); - boostDR = reader.ReadBoolean(); - despawnTimer = reader.ReadInt32(); - } - - public override void AI() - { - Lighting.AddLight((int)((npc.position.X + (float)(npc.width / 2)) / 16f), (int)((npc.position.Y + (float)(npc.height / 2)) / 16f), 0.5f, 1.25f, 1.25f); - CalamityGlobalNPC.ghostBoss = npc.whoAmI; - - bool cloneAlive = false; - if (CalamityGlobalNPC.ghostBossClone != -1) - { - cloneAlive = Main.npc[CalamityGlobalNPC.ghostBossClone].active; - } - - Vector2 vector = npc.Center; - bool speedBoost1 = false; - bool despawnBoost = false; - bool revenge = (CalamityWorld.revenge || CalamityWorld.bossRushActive); - bool expertMode = (Main.expertMode || CalamityWorld.bossRushActive); - bool phase2 = (double)npc.life <= (double)npc.lifeMax * 0.75; //hooks detach and fire beams - bool phase3 = (double)npc.life <= (double)npc.lifeMax * (revenge ? 0.5 : 0.33); //hooks die and begins charging with ghosts spinning around player - bool phase4 = (double)npc.life <= (double)npc.lifeMax * (revenge ? 0.33 : 0.2); //starts spitting ghost dudes - bool phase5 = (double)npc.life <= (double)npc.lifeMax * (revenge ? 0.1 : 0.05); //starts moving incredibly fast - npc.TargetClosest(true); - - if (Main.raining) - CalamityGlobalNPC.StopRain(); - if (npc.timeLeft < 1500) - npc.timeLeft = 1500; - if (Vector2.Distance(Main.player[npc.target].Center, vector) > 6000f) - npc.active = false; - - if (npc.localAI[0] == 0f && Main.netMode != 1) - { - npc.localAI[0] = 1f; - int num729 = NPC.NewNPC((int)vector.X, (int)vector.Y, mod.NPCType("PolterghastHook"), npc.whoAmI, 0f, 0f, 0f, 0f, 255); - num729 = NPC.NewNPC((int)vector.X, (int)vector.Y, mod.NPCType("PolterghastHook"), npc.whoAmI, 0f, 0f, 0f, 0f, 255); - num729 = NPC.NewNPC((int)vector.X, (int)vector.Y, mod.NPCType("PolterghastHook"), npc.whoAmI, 0f, 0f, 0f, 0f, 255); - num729 = NPC.NewNPC((int)vector.X, (int)vector.Y, mod.NPCType("PolterghastHook"), npc.whoAmI, 0f, 0f, 0f, 0f, 255); - } - int[] array2 = new int[4]; - float num730 = 0f; - float num731 = 0f; - int num732 = 0; - int num; - for (int num733 = 0; num733 < 200; num733 = num + 1) - { - if (Main.npc[num733].active && Main.npc[num733].type == mod.NPCType("PolterghastHook")) - { - num730 += Main.npc[num733].Center.X; - num731 += Main.npc[num733].Center.Y; - array2[num732] = num733; - num732++; - if (num732 > 3) - break; - } - num = num733; - } - num730 /= (float)num732; - num731 /= (float)num732; - - float num734 = 2.5f; - float num735 = 0.025f; - if (!Main.player[npc.target].ZoneDungeon && !CalamityWorld.bossRushActive) - { - despawnTimer--; - if (despawnTimer <= 0) - despawnBoost = true; - speedBoost1 = true; - num734 += 2f; - num735 += 0.025f; - } - else - { - despawnTimer = 600; - } - - if (phase2) - { - num734 += 1.5f; - num735 += 0.01f; - } - - if (phase3) - { - if (cloneAlive) - { - boostDR = true; - if (npc.ai[2] >= 300f) - { - num734 += phase5 ? 14.5f : 8.5f; - num735 += phase5 ? 0.085f : 0.045f; - } - else - { - if (phase5) - { - num734 += 1.5f; - num735 += 0.015f; - } - else if (phase4) - { - num734 += 1f; - num735 += 0.01f; - } - else - { - num734 += 0.5f; - num735 += 0.005f; - } - } - npc.ai[2] += 1f; - if (npc.ai[2] >= 600f) - { - npc.ai[2] = 0f; - npc.netUpdate = true; - } - } - else - { - boostDR = false; - num734 += phase5 ? 18.5f : 14.5f; - num735 += phase5 ? 0.115f : 0.085f; - npc.localAI[2] += 1f; - if (npc.localAI[2] >= 600f) - { - npc.localAI[2] = 0f; - if (Main.netMode != 1) - { - NPC.NewNPC((int)vector.X, (int)vector.Y, mod.NPCType("PolterPhantom"), 0, 0f, 0f, 0f, 0f, 255); - } - Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 122); - for (int num621 = 0; num621 < 10; num621++) - { - int num622 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 173, 0f, 0f, 100, default(Color), 2f); - Main.dust[num622].velocity *= 3f; - Main.dust[num622].noGravity = true; - if (Main.rand.Next(2) == 0) - { - Main.dust[num622].scale = 0.5f; - Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; - } - } - for (int num623 = 0; num623 < 30; num623++) - { - int num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 173, 0f, 0f, 100, default(Color), 3f); - Main.dust[num624].noGravity = true; - Main.dust[num624].velocity *= 5f; - num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 2f); - Main.dust[num624].velocity *= 2f; - } - } - } - } - - if (expertMode) - { - num734 += revenge ? 1.5f : 1f; - num734 *= revenge ? 1.25f : 1.1f; - num735 += revenge ? 0.015f : 0.01f; - num735 *= revenge ? 1.2f : 1.1f; - } - - Vector2 vector91 = new Vector2(num730, num731); - float num736 = Main.player[npc.target].Center.X - vector91.X; - float num737 = Main.player[npc.target].Center.Y - vector91.Y; - if (despawnBoost) - { - num737 *= -1f; - num736 *= -1f; - num734 += 10f; - } - float num738 = (float)Math.Sqrt((double)(num736 * num736 + num737 * num737)); - - int num739 = 500; - if (speedBoost1) - num739 += 250; - if (expertMode) - num739 += 150; - - if (num738 >= (float)num739) - { - num738 = (float)num739 / num738; - num736 *= num738; - num737 *= num738; - } - num730 += num736; - num731 += num737; - vector91 = new Vector2(vector.X, vector.Y); - num736 = num730 - vector91.X; - num737 = num731 - vector91.Y; - num738 = (float)Math.Sqrt((double)(num736 * num736 + num737 * num737)); - if (num738 < num734) - { - num736 = npc.velocity.X; - num737 = npc.velocity.Y; - } - else - { - num738 = num734 / num738; - num736 *= num738; - num737 *= num738; - } - - Vector2 vector92 = new Vector2(vector.X, vector.Y); - float num740 = Main.player[npc.target].Center.X - vector92.X; - float num741 = Main.player[npc.target].Center.Y - vector92.Y; - npc.rotation = (float)Math.Atan2((double)num741, (double)num740) + 1.57f; - - if (npc.velocity.X < num736) - { - npc.velocity.X = npc.velocity.X + num735; - if (npc.velocity.X < 0f && num736 > 0f) - npc.velocity.X = npc.velocity.X + num735 * 2f; - } - else if (npc.velocity.X > num736) - { - npc.velocity.X = npc.velocity.X - num735; - if (npc.velocity.X > 0f && num736 < 0f) - npc.velocity.X = npc.velocity.X - num735 * 2f; - } - if (npc.velocity.Y < num737) - { - npc.velocity.Y = npc.velocity.Y + num735; - if (npc.velocity.Y < 0f && num737 > 0f) - npc.velocity.Y = npc.velocity.Y + num735 * 2f; - } - else if (npc.velocity.Y > num737) - { - npc.velocity.Y = npc.velocity.Y - num735; - if (npc.velocity.Y > 0f && num737 < 0f) - npc.velocity.Y = npc.velocity.Y - num735 * 2f; - } - - if (!phase2 && !phase3) - { - if (speedBoost1) - { - npc.defense = 300; - npc.damage = (int)(200f * Main.damageMultiplier); - } - else - { - npc.damage = expertMode ? 240 : 150; - npc.defense = 150; - } - if (Main.netMode != 1) - { - npc.localAI[1] += (expertMode ? 2f : 1.5f); - if (speedBoost1 || CalamityWorld.bossRushActive) - npc.localAI[1] += 6f; - - if (npc.localAI[1] >= 60f) - { - npc.localAI[1] = 0f; - bool flag47 = Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height); - if (npc.localAI[3] > 0f) - { - flag47 = true; - npc.localAI[3] = 0f; - } - if (flag47) - { - Vector2 vector93 = new Vector2(vector.X, vector.Y); - float num742 = 6f; - if (expertMode) - { - num742 = (CalamityWorld.bossRushActive ? 13f : 7f); - } - if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) - { - num742 *= 2f; - } - float num743 = Main.player[npc.target].position.X + (float)Main.player[npc.target].width * 0.5f - vector93.X; - float num744 = Main.player[npc.target].position.Y + (float)Main.player[npc.target].height * 0.5f - vector93.Y; - float num745 = (float)Math.Sqrt((double)(num743 * num743 + num744 * num744)); - num745 = num742 / num745; - num743 *= num745; - num744 *= num745; - int num746 = expertMode ? 46 : 55; - int num747 = mod.ProjectileType("PhantomShot"); - int maxValue2 = 2; - if (expertMode) - { - maxValue2 = 4; - } - if ((double)npc.life < (double)npc.lifeMax * 0.8 && Main.rand.Next(maxValue2) == 0) - { - num746 = expertMode ? 51 : 60; - npc.localAI[1] = -30f; - num747 = mod.ProjectileType("PhantomBlast"); - } - if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) - { - num746 *= 2; - } - vector93.X += num743 * 3f; - vector93.Y += num744 * 3f; - int num748 = Projectile.NewProjectile(vector93.X, vector93.Y, num743, num744, num747, num746, 0f, Main.myPlayer, 0f, 0f); - Main.projectile[num748].timeLeft = (num747 == mod.ProjectileType("PhantomBlast") ? 300 : 1200); - } - else - { - Vector2 vector93 = new Vector2(vector.X, vector.Y); - float num742 = 11f; - if (expertMode) - { - num742 = (CalamityWorld.bossRushActive ? 18f : 12f); - } - if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) - { - num742 *= 2f; - } - float num743 = Main.player[npc.target].position.X + (float)Main.player[npc.target].width * 0.5f - vector93.X; - float num744 = Main.player[npc.target].position.Y + (float)Main.player[npc.target].height * 0.5f - vector93.Y; - float num745 = (float)Math.Sqrt((double)(num743 * num743 + num744 * num744)); - num745 = num742 / num745; - num743 *= num745; - num744 *= num745; - int num746 = expertMode ? 51 : 60; - int num747 = mod.ProjectileType("PhantomBlast"); - if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) - { - num746 *= 2; - } - vector93.X += num743 * 3f; - vector93.Y += num744 * 3f; - int num748 = Projectile.NewProjectile(vector93.X, vector93.Y, num743, num744, num747, num746, 0f, Main.myPlayer, 0f, 0f); - Main.projectile[num748].timeLeft = 180; - } - } - } - } - else if (!phase3) - { - if (npc.ai[0] == 0f) - { - npc.ai[0] += 1f; - Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 122); - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt"), 1f); - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt2"), 1f); - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt3"), 1f); - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt4"), 1f); - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt5"), 1f); - for (int num621 = 0; num621 < 10; num621++) - { - int num622 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 60, 0f, 0f, 100, default(Color), 2f); - Main.dust[num622].velocity *= 3f; - Main.dust[num622].noGravity = true; - if (Main.rand.Next(2) == 0) - { - Main.dust[num622].scale = 0.5f; - Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; - } - } - for (int num623 = 0; num623 < 30; num623++) - { - int num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 3f); - Main.dust[num624].noGravity = true; - Main.dust[num624].velocity *= 5f; - num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 2f); - Main.dust[num624].velocity *= 2f; - } - } - npc.GivenName = "Necroghast"; - if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) - { - npc.defense = 200; - npc.damage = (int)(300f * Main.damageMultiplier); - } - else - { - npc.damage = expertMode ? 288 : 180; - npc.defense = 100; - } - if (Main.netMode != 1) - { - npc.localAI[1] += (expertMode ? 2f : 1.5f); - if (speedBoost1 || CalamityWorld.bossRushActive) - npc.localAI[1] += 8f; - - if (npc.localAI[1] > 50f) - { - npc.localAI[1] = 0f; - bool flag47 = Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height); - if (npc.localAI[3] > 0f) - { - flag47 = true; - npc.localAI[3] = 0f; - } - if (flag47) - { - Vector2 vector93 = new Vector2(vector.X, vector.Y); - float num742 = 6f; - if (expertMode) - { - num742 = (CalamityWorld.bossRushActive ? 13f : 7f); - } - if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) - { - num742 *= 2f; - } - float num743 = Main.player[npc.target].position.X + (float)Main.player[npc.target].width * 0.5f - vector93.X; - float num744 = Main.player[npc.target].position.Y + (float)Main.player[npc.target].height * 0.5f - vector93.Y; - float num745 = (float)Math.Sqrt((double)(num743 * num743 + num744 * num744)); - num745 = num742 / num745; - num743 *= num745; - num744 *= num745; - int num746 = expertMode ? 49 : 60; - int num747 = mod.ProjectileType("PhantomShot2"); - int maxValue2 = 2; - if (expertMode) - { - maxValue2 = 4; - } - if (Main.rand.Next(maxValue2) == 0) - { - num746 = expertMode ? 54 : 65; - npc.localAI[1] = -30f; - num747 = mod.ProjectileType("PhantomBlast2"); - } - if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) - { - num746 *= 2; - } - vector93.X += num743 * 3f; - vector93.Y += num744 * 3f; - int num748 = Projectile.NewProjectile(vector93.X, vector93.Y, num743, num744, num747, num746, 0f, Main.myPlayer, 0f, 0f); - Main.projectile[num748].timeLeft = (num747 == mod.ProjectileType("PhantomBlast2") ? 300 : 1200); - } - else - { - Vector2 vector93 = new Vector2(vector.X, vector.Y); - float num742 = 11f; - if (expertMode) - { - num742 = (CalamityWorld.bossRushActive ? 18f : 12f); - } - if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) - { - num742 *= 2f; - } - float num743 = Main.player[npc.target].position.X + (float)Main.player[npc.target].width * 0.5f - vector93.X; - float num744 = Main.player[npc.target].position.Y + (float)Main.player[npc.target].height * 0.5f - vector93.Y; - float num745 = (float)Math.Sqrt((double)(num743 * num743 + num744 * num744)); - num745 = num742 / num745; - num743 *= num745; - num744 *= num745; - int num746 = expertMode ? 54 : 65; - int num747 = mod.ProjectileType("PhantomBlast2"); - if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) - { - num746 *= 2; - } - vector93.X += num743 * 3f; - vector93.Y += num744 * 3f; - int num748 = Projectile.NewProjectile(vector93.X, vector93.Y, num743, num744, num747, num746, 0f, Main.myPlayer, 0f, 0f); - Main.projectile[num748].timeLeft = 240; - } - } - } - } - else - { - npc.HitSound = SoundID.NPCHit36; - if (!spawnGhost) - { - spawnGhost = true; - if (Main.netMode != 1) - { - NPC.NewNPC((int)vector.X, (int)vector.Y, mod.NPCType("PolterPhantom"), 0, 0f, 0f, 0f, 0f, 255); - for (int I = 0; I < 3; I++) - { - int Phantom = NPC.NewNPC((int)(Main.player[npc.target].Center.X + (Math.Sin(I * 120) * 500)), - (int)(Main.player[npc.target].Center.Y + (Math.Cos(I * 120) * 500)), mod.NPCType("PhantomFuckYou"), 0, 0, 0, 0, -1); - NPC Eye = Main.npc[Phantom]; - Eye.ai[0] = I * 120; - Eye.ai[3] = I * 120; - } - } - Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 122); - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt"), 1f); - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt2"), 1f); - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt3"), 1f); - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt4"), 1f); - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt5"), 1f); - for (int num621 = 0; num621 < 10; num621++) - { - int num622 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 60, 0f, 0f, 100, default(Color), 2f); - Main.dust[num622].velocity *= 3f; - Main.dust[num622].noGravity = true; - if (Main.rand.Next(2) == 0) - { - Main.dust[num622].scale = 0.5f; - Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; - } - } - for (int num623 = 0; num623 < 30; num623++) - { - int num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 3f); - Main.dust[num624].noGravity = true; - Main.dust[num624].velocity *= 5f; - num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 2f); - Main.dust[num624].velocity *= 2f; - } - } - npc.GivenName = "Necroplasm"; - if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) - { - npc.defense = 200; - npc.damage = (int)(400f * Main.damageMultiplier); - } - else - { - npc.damage = expertMode ? 336 : 210; - npc.defense = 0; - } - if (phase4) - { - npc.localAI[1] += 1f; - if (npc.localAI[1] >= 150f) - { - float num757 = 8f; - Vector2 vector94 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f); - float num758 = Main.player[npc.target].position.X + (float)Main.player[npc.target].width * 0.5f - vector94.X + (float)Main.rand.Next(-10, 11); - float num759 = Math.Abs(num758 * 0.2f); - float num760 = Main.player[npc.target].position.Y + (float)Main.player[npc.target].height * 0.5f - vector94.Y + (float)Main.rand.Next(-10, 11); - if (num760 > 0f) - { - num759 = 0f; - } - num760 -= num759; - float num761 = (float)Math.Sqrt((double)(num758 * num758 + num760 * num760)); - num761 = num757 / num761; - num758 *= num761; - num760 *= num761; - if (NPC.CountNPCS(mod.NPCType("PhantomSpiritL")) < (revenge ? 3 : 2) && Main.netMode != 1) - { - int num762 = NPC.NewNPC((int)vector.X, (int)vector.Y, mod.NPCType("PhantomSpiritL"), 0, 0f, 0f, 0f, 0f, 255); - Main.npc[num762].velocity.X = num758; - Main.npc[num762].velocity.Y = num760; - Main.npc[num762].netUpdate = true; - } - npc.localAI[1] = 0f; - } - } - } - } - - public override void NPCLoot() - { - if (CalamityWorld.armageddon) - { - for (int i = 0; i < 5; i++) - { - npc.DropBossBags(); - } - } - if (Main.rand.Next(10) == 0) - { - Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("PolterghastTrophy")); - } - if (Main.expertMode) - { - npc.DropBossBags(); - } - else - { - Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("RuinousSoul"), Main.rand.Next(5, 9)); - if (Main.rand.Next(4) == 0) - { - Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("BansheeHook")); - } - if (Main.rand.Next(4) == 0) - { - Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("DaemonsFlame")); - } - if (Main.rand.Next(4) == 0) - { - Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("EtherealSubjugator")); - } - if (Main.rand.Next(4) == 0) - { - Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("FatesReveal")); - } - if (Main.rand.Next(4) == 0) - { - Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("GhastlyVisage")); - } - if (Main.rand.Next(4) == 0) - { - Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("GhoulishGouger")); - } - if (Main.rand.Next(4) == 0) - { - Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("TerrorBlade")); - } - } - } - - public override void BossLoot(ref string name, ref int potionType) - { - potionType = ItemID.SuperHealingPotion; - } - - public override bool StrikeNPC(ref double damage, int defense, ref float knockback, int hitDirection, ref bool crit) - { - double newDamage = (damage + (int)((double)defense * 0.25)); - float protection = 0.1f + //.1 - ((double)npc.life <= (double)npc.lifeMax * 0.75 ? 0.05f : 0f) + //.15 - ((double)npc.life <= (double)npc.lifeMax * (CalamityWorld.revenge ? 0.5 : 0.33) ? 0.05f : 0f) + //.2 - (boostDR ? 0.6f : 0f); //.8 - if (npc.ichor) - { - protection *= 0.88f; - } - else if (npc.onFire2) - { - protection *= 0.9f; - } - if (newDamage < 1.0) - { - newDamage = 1.0; - } - if (newDamage >= 1.0) - { - newDamage = (double)((int)((double)(1f - protection) * newDamage)); - if (newDamage < 1.0) - { - newDamage = 1.0; - } - } - damage = newDamage; - return true; - } - - public override void FindFrame(int frameHeight) - { - bool phase2 = (double)npc.life > (double)npc.lifeMax * (CalamityWorld.revenge ? 0.5 : 0.33); - npc.frameCounter += 1.0; - if (npc.frameCounter > 6.0) - { - npc.frameCounter = 0.0; - npc.frame.Y = npc.frame.Y + frameHeight; - } - if ((double)npc.life > (double)npc.lifeMax * 0.75) - { - if (npc.frame.Y > frameHeight * 3) - { - npc.frame.Y = 0; - } - } - else if (phase2) - { - if (npc.frame.Y < frameHeight * 4) - { - npc.frame.Y = frameHeight * 4; - } - if (npc.frame.Y > frameHeight * 7) - { - npc.frame.Y = frameHeight * 4; - } - } - else - { - if (npc.frame.Y < frameHeight * 8) - { - npc.frame.Y = frameHeight * 8; - } - if (npc.frame.Y > frameHeight * 11) - { - npc.frame.Y = frameHeight * 8; - } - } - } - - public override void OnHitPlayer(Player player, int damage, bool crit) - { - if (CalamityWorld.revenge) - player.AddBuff(mod.BuffType("Horror"), 300, true); - } - - public override bool CanHitPlayer(Player target, ref int cooldownSlot) - { - cooldownSlot = 1; - return true; - } - - public override void ScaleExpertStats(int numPlayers, float bossLifeScale) - { - npc.lifeMax = (int)(npc.lifeMax * 0.8f * bossLifeScale); - npc.damage = (int)(npc.damage * 0.8f); - } - - public override void HitEffect(int hitDirection, double damage) - { - Dust.NewDust(npc.position, npc.width, npc.height, 180, hitDirection, -1f, 0, default(Color), 1f); - if (npc.life <= 0) - { - npc.position.X = npc.position.X + (float)(npc.width / 2); - npc.position.Y = npc.position.Y + (float)(npc.height / 2); - npc.width = 90; - npc.height = 90; - npc.position.X = npc.position.X - (float)(npc.width / 2); - npc.position.Y = npc.position.Y - (float)(npc.height / 2); - for (int num621 = 0; num621 < 10; num621++) - { - int num622 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 60, 0f, 0f, 100, default(Color), 2f); - Main.dust[num622].velocity *= 3f; - if (Main.rand.Next(2) == 0) - { - Main.dust[num622].scale = 0.5f; - Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; - } - } - for (int num623 = 0; num623 < 60; num623++) - { - int num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 3f); - Main.dust[num624].noGravity = true; - Main.dust[num624].velocity *= 5f; - num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 2f); - Main.dust[num624].velocity *= 2f; - } - } - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Localization; +using Terraria.ID; +using Terraria.ModLoader; +using CalamityMod.Projectiles; +using CalamityMod.World; + +namespace CalamityMod.NPCs.Polterghast +{ + [AutoloadBossHead] + public class Polterghast : ModNPC + { + private int despawnTimer = 600; + private bool spawnGhost = false; + private bool boostDR = false; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Polterghast"); + Main.npcFrameCount[npc.type] = 12; + } + + public override void SetDefaults() + { + npc.npcSlots = 50f; + npc.damage = 150; + npc.width = 90; + npc.height = 120; + npc.defense = 150; + npc.lifeMax = CalamityWorld.revenge ? 495000 : 412500; + if (CalamityWorld.death) + { + npc.lifeMax = 660000; + } + if (CalamityWorld.bossRushActive) + { + npc.lifeMax = CalamityWorld.death ? 2800000 : 2500000; + } + double HPBoost = (double)Config.BossHealthPercentageBoost * 0.01; + npc.lifeMax += (int)((double)npc.lifeMax * HPBoost); + npc.knockBackResist = 0f; + npc.aiStyle = -1; //new + aiType = -1; //new + npc.value = Item.buyPrice(0, 60, 0, 0); + npc.boss = true; + for (int k = 0; k < npc.buffImmune.Length; k++) + { + npc.buffImmune[k] = true; + } + npc.buffImmune[BuffID.Ichor] = false; + npc.buffImmune[BuffID.CursedInferno] = false; + npc.buffImmune[mod.BuffType("AbyssalFlames")] = false; + npc.buffImmune[mod.BuffType("DemonFlames")] = false; + npc.buffImmune[mod.BuffType("GodSlayerInferno")] = false; + npc.buffImmune[mod.BuffType("Nightwither")] = false; + npc.buffImmune[mod.BuffType("Shred")] = false; + npc.noGravity = true; + npc.noTileCollide = true; + npc.netAlways = true; + Mod calamityModMusic = ModLoader.GetMod("CalamityModMusic"); + if (calamityModMusic != null) + music = calamityModMusic.GetSoundSlot(SoundType.Music, "Sounds/Music/RUIN"); + else + music = MusicID.Plantera; + npc.HitSound = SoundID.NPCHit7; + npc.DeathSound = SoundID.NPCDeath39; + bossBag = mod.ItemType("PolterghastBag"); + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(spawnGhost); + writer.Write(boostDR); + writer.Write(despawnTimer); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + spawnGhost = reader.ReadBoolean(); + boostDR = reader.ReadBoolean(); + despawnTimer = reader.ReadInt32(); + } + + public override void AI() + { + Lighting.AddLight((int)((npc.position.X + (float)(npc.width / 2)) / 16f), (int)((npc.position.Y + (float)(npc.height / 2)) / 16f), 0.5f, 1.25f, 1.25f); + CalamityGlobalNPC.ghostBoss = npc.whoAmI; + + bool cloneAlive = false; + if (CalamityGlobalNPC.ghostBossClone != -1) + { + cloneAlive = Main.npc[CalamityGlobalNPC.ghostBossClone].active; + } + + Vector2 vector = npc.Center; + bool speedBoost1 = false; + bool despawnBoost = false; + bool revenge = (CalamityWorld.revenge || CalamityWorld.bossRushActive); + bool expertMode = (Main.expertMode || CalamityWorld.bossRushActive); + bool phase2 = (double)npc.life <= (double)npc.lifeMax * 0.75; //hooks detach and fire beams + bool phase3 = (double)npc.life <= (double)npc.lifeMax * (revenge ? 0.5 : 0.33); //hooks die and begins charging with ghosts spinning around player + bool phase4 = (double)npc.life <= (double)npc.lifeMax * (revenge ? 0.33 : 0.2); //starts spitting ghost dudes + bool phase5 = (double)npc.life <= (double)npc.lifeMax * (revenge ? 0.1 : 0.05); //starts moving incredibly fast + npc.TargetClosest(true); + + if (Main.raining) + CalamityGlobalNPC.StopRain(); + if (npc.timeLeft < 1500) + npc.timeLeft = 1500; + if (Vector2.Distance(Main.player[npc.target].Center, vector) > 6000f) + npc.active = false; + + if (npc.localAI[0] == 0f && Main.netMode != 1) + { + npc.localAI[0] = 1f; + int num729 = NPC.NewNPC((int)vector.X, (int)vector.Y, mod.NPCType("PolterghastHook"), npc.whoAmI, 0f, 0f, 0f, 0f, 255); + num729 = NPC.NewNPC((int)vector.X, (int)vector.Y, mod.NPCType("PolterghastHook"), npc.whoAmI, 0f, 0f, 0f, 0f, 255); + num729 = NPC.NewNPC((int)vector.X, (int)vector.Y, mod.NPCType("PolterghastHook"), npc.whoAmI, 0f, 0f, 0f, 0f, 255); + num729 = NPC.NewNPC((int)vector.X, (int)vector.Y, mod.NPCType("PolterghastHook"), npc.whoAmI, 0f, 0f, 0f, 0f, 255); + } + int[] array2 = new int[4]; + float num730 = 0f; + float num731 = 0f; + int num732 = 0; + int num; + for (int num733 = 0; num733 < 200; num733 = num + 1) + { + if (Main.npc[num733].active && Main.npc[num733].type == mod.NPCType("PolterghastHook")) + { + num730 += Main.npc[num733].Center.X; + num731 += Main.npc[num733].Center.Y; + array2[num732] = num733; + num732++; + if (num732 > 3) + break; + } + num = num733; + } + num730 /= (float)num732; + num731 /= (float)num732; + + float num734 = 2.5f; + float num735 = 0.025f; + if (!Main.player[npc.target].ZoneDungeon && !CalamityWorld.bossRushActive && (double)Main.player[npc.target].position.Y < Main.worldSurface * 16.0) + { + despawnTimer--; + if (despawnTimer <= 0) + despawnBoost = true; + speedBoost1 = true; + num734 += 2f; + num735 += 0.025f; + } + else + { + despawnTimer = 600; + } + + if (phase2) + { + num734 += 1.5f; + num735 += 0.01f; + } + + if (phase3) + { + if (cloneAlive) + { + boostDR = true; + if (npc.ai[2] >= 300f) + { + num734 += phase5 ? 14.5f : 8.5f; + num735 += phase5 ? 0.085f : 0.045f; + } + else + { + if (phase5) + { + num734 += 1.5f; + num735 += 0.015f; + } + else if (phase4) + { + num734 += 1f; + num735 += 0.01f; + } + else + { + num734 += 0.5f; + num735 += 0.005f; + } + } + npc.ai[2] += 1f; + if (npc.ai[2] >= 600f) + { + npc.ai[2] = 0f; + npc.netUpdate = true; + } + } + else + { + boostDR = false; + num734 += phase5 ? 18.5f : 14.5f; + num735 += phase5 ? 0.115f : 0.085f; + npc.localAI[2] += 1f; + if (npc.localAI[2] >= 600f) + { + npc.localAI[2] = 0f; + if (Main.netMode != 1) + { + NPC.NewNPC((int)vector.X, (int)vector.Y, mod.NPCType("PolterPhantom"), 0, 0f, 0f, 0f, 0f, 255); + } + Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 122); + for (int num621 = 0; num621 < 10; num621++) + { + int num622 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 173, 0f, 0f, 100, default(Color), 2f); + Main.dust[num622].velocity *= 3f; + Main.dust[num622].noGravity = true; + if (Main.rand.Next(2) == 0) + { + Main.dust[num622].scale = 0.5f; + Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; + } + } + for (int num623 = 0; num623 < 30; num623++) + { + int num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 173, 0f, 0f, 100, default(Color), 3f); + Main.dust[num624].noGravity = true; + Main.dust[num624].velocity *= 5f; + num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 2f); + Main.dust[num624].velocity *= 2f; + } + } + } + } + + if (expertMode) + { + num734 += revenge ? 1.5f : 1f; + num734 *= revenge ? 1.25f : 1.1f; + num735 += revenge ? 0.015f : 0.01f; + num735 *= revenge ? 1.2f : 1.1f; + } + + Vector2 vector91 = new Vector2(num730, num731); + float num736 = Main.player[npc.target].Center.X - vector91.X; + float num737 = Main.player[npc.target].Center.Y - vector91.Y; + if (despawnBoost) + { + num737 *= -1f; + num736 *= -1f; + num734 += 10f; + } + float num738 = (float)Math.Sqrt((double)(num736 * num736 + num737 * num737)); + + int num739 = 500; + if (speedBoost1) + num739 += 250; + if (expertMode) + num739 += 150; + + if (num738 >= (float)num739) + { + num738 = (float)num739 / num738; + num736 *= num738; + num737 *= num738; + } + num730 += num736; + num731 += num737; + vector91 = new Vector2(vector.X, vector.Y); + num736 = num730 - vector91.X; + num737 = num731 - vector91.Y; + num738 = (float)Math.Sqrt((double)(num736 * num736 + num737 * num737)); + if (num738 < num734) + { + num736 = npc.velocity.X; + num737 = npc.velocity.Y; + } + else + { + num738 = num734 / num738; + num736 *= num738; + num737 *= num738; + } + + Vector2 vector92 = new Vector2(vector.X, vector.Y); + float num740 = Main.player[npc.target].Center.X - vector92.X; + float num741 = Main.player[npc.target].Center.Y - vector92.Y; + npc.rotation = (float)Math.Atan2((double)num741, (double)num740) + 1.57f; + + if (npc.velocity.X < num736) + { + npc.velocity.X = npc.velocity.X + num735; + if (npc.velocity.X < 0f && num736 > 0f) + npc.velocity.X = npc.velocity.X + num735 * 2f; + } + else if (npc.velocity.X > num736) + { + npc.velocity.X = npc.velocity.X - num735; + if (npc.velocity.X > 0f && num736 < 0f) + npc.velocity.X = npc.velocity.X - num735 * 2f; + } + if (npc.velocity.Y < num737) + { + npc.velocity.Y = npc.velocity.Y + num735; + if (npc.velocity.Y < 0f && num737 > 0f) + npc.velocity.Y = npc.velocity.Y + num735 * 2f; + } + else if (npc.velocity.Y > num737) + { + npc.velocity.Y = npc.velocity.Y - num735; + if (npc.velocity.Y > 0f && num737 < 0f) + npc.velocity.Y = npc.velocity.Y - num735 * 2f; + } + + if (!phase2 && !phase3) + { + if (speedBoost1) + { + npc.defense = 300; + npc.damage = (int)(200f * Main.damageMultiplier); + } + else + { + npc.damage = expertMode ? 240 : 150; + npc.defense = 150; + } + if (Main.netMode != 1) + { + npc.localAI[1] += (expertMode ? 2f : 1.5f); + if (speedBoost1 || CalamityWorld.bossRushActive) + npc.localAI[1] += 6f; + + if (npc.localAI[1] >= 60f) + { + npc.localAI[1] = 0f; + bool flag47 = Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height); + if (npc.localAI[3] > 0f) + { + flag47 = true; + npc.localAI[3] = 0f; + } + if (flag47) + { + Vector2 vector93 = new Vector2(vector.X, vector.Y); + float num742 = 6f; + if (expertMode) + { + num742 = (CalamityWorld.bossRushActive ? 13f : 7f); + } + if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) + { + num742 *= 2f; + } + float num743 = Main.player[npc.target].position.X + (float)Main.player[npc.target].width * 0.5f - vector93.X; + float num744 = Main.player[npc.target].position.Y + (float)Main.player[npc.target].height * 0.5f - vector93.Y; + float num745 = (float)Math.Sqrt((double)(num743 * num743 + num744 * num744)); + num745 = num742 / num745; + num743 *= num745; + num744 *= num745; + int num746 = expertMode ? 46 : 55; + int num747 = mod.ProjectileType("PhantomShot"); + int maxValue2 = 2; + if (expertMode) + { + maxValue2 = 4; + } + if ((double)npc.life < (double)npc.lifeMax * 0.8 && Main.rand.Next(maxValue2) == 0) + { + num746 = expertMode ? 51 : 60; + npc.localAI[1] = -30f; + num747 = mod.ProjectileType("PhantomBlast"); + } + if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) + { + num746 *= 2; + } + vector93.X += num743 * 3f; + vector93.Y += num744 * 3f; + int num748 = Projectile.NewProjectile(vector93.X, vector93.Y, num743, num744, num747, num746, 0f, Main.myPlayer, 0f, 0f); + Main.projectile[num748].timeLeft = (num747 == mod.ProjectileType("PhantomBlast") ? 300 : 1200); + } + else + { + Vector2 vector93 = new Vector2(vector.X, vector.Y); + float num742 = 11f; + if (expertMode) + { + num742 = (CalamityWorld.bossRushActive ? 18f : 12f); + } + if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) + { + num742 *= 2f; + } + float num743 = Main.player[npc.target].position.X + (float)Main.player[npc.target].width * 0.5f - vector93.X; + float num744 = Main.player[npc.target].position.Y + (float)Main.player[npc.target].height * 0.5f - vector93.Y; + float num745 = (float)Math.Sqrt((double)(num743 * num743 + num744 * num744)); + num745 = num742 / num745; + num743 *= num745; + num744 *= num745; + int num746 = expertMode ? 51 : 60; + int num747 = mod.ProjectileType("PhantomBlast"); + if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) + { + num746 *= 2; + } + vector93.X += num743 * 3f; + vector93.Y += num744 * 3f; + int num748 = Projectile.NewProjectile(vector93.X, vector93.Y, num743, num744, num747, num746, 0f, Main.myPlayer, 0f, 0f); + Main.projectile[num748].timeLeft = 180; + } + } + } + } + else if (!phase3) + { + if (npc.ai[0] == 0f) + { + npc.ai[0] += 1f; + Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 122); + Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt"), 1f); + Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt2"), 1f); + Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt3"), 1f); + Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt4"), 1f); + Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt5"), 1f); + for (int num621 = 0; num621 < 10; num621++) + { + int num622 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 60, 0f, 0f, 100, default(Color), 2f); + Main.dust[num622].velocity *= 3f; + Main.dust[num622].noGravity = true; + if (Main.rand.Next(2) == 0) + { + Main.dust[num622].scale = 0.5f; + Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; + } + } + for (int num623 = 0; num623 < 30; num623++) + { + int num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 3f); + Main.dust[num624].noGravity = true; + Main.dust[num624].velocity *= 5f; + num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 2f); + Main.dust[num624].velocity *= 2f; + } + } + npc.GivenName = "Necroghast"; + if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) + { + npc.defense = 200; + npc.damage = (int)(300f * Main.damageMultiplier); + } + else + { + npc.damage = expertMode ? 288 : 180; + npc.defense = 100; + } + if (Main.netMode != 1) + { + npc.localAI[1] += (expertMode ? 2f : 1.5f); + if (speedBoost1 || CalamityWorld.bossRushActive) + npc.localAI[1] += 8f; + + if (npc.localAI[1] > 50f) + { + npc.localAI[1] = 0f; + bool flag47 = Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height); + if (npc.localAI[3] > 0f) + { + flag47 = true; + npc.localAI[3] = 0f; + } + if (flag47) + { + Vector2 vector93 = new Vector2(vector.X, vector.Y); + float num742 = 6f; + if (expertMode) + { + num742 = (CalamityWorld.bossRushActive ? 13f : 7f); + } + if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) + { + num742 *= 2f; + } + float num743 = Main.player[npc.target].position.X + (float)Main.player[npc.target].width * 0.5f - vector93.X; + float num744 = Main.player[npc.target].position.Y + (float)Main.player[npc.target].height * 0.5f - vector93.Y; + float num745 = (float)Math.Sqrt((double)(num743 * num743 + num744 * num744)); + num745 = num742 / num745; + num743 *= num745; + num744 *= num745; + int num746 = expertMode ? 49 : 60; + int num747 = mod.ProjectileType("PhantomShot2"); + int maxValue2 = 2; + if (expertMode) + { + maxValue2 = 4; + } + if (Main.rand.Next(maxValue2) == 0) + { + num746 = expertMode ? 54 : 65; + npc.localAI[1] = -30f; + num747 = mod.ProjectileType("PhantomBlast2"); + } + if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) + { + num746 *= 2; + } + vector93.X += num743 * 3f; + vector93.Y += num744 * 3f; + int num748 = Projectile.NewProjectile(vector93.X, vector93.Y, num743, num744, num747, num746, 0f, Main.myPlayer, 0f, 0f); + Main.projectile[num748].timeLeft = (num747 == mod.ProjectileType("PhantomBlast2") ? 300 : 1200); + } + else + { + Vector2 vector93 = new Vector2(vector.X, vector.Y); + float num742 = 11f; + if (expertMode) + { + num742 = (CalamityWorld.bossRushActive ? 18f : 12f); + } + if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) + { + num742 *= 2f; + } + float num743 = Main.player[npc.target].position.X + (float)Main.player[npc.target].width * 0.5f - vector93.X; + float num744 = Main.player[npc.target].position.Y + (float)Main.player[npc.target].height * 0.5f - vector93.Y; + float num745 = (float)Math.Sqrt((double)(num743 * num743 + num744 * num744)); + num745 = num742 / num745; + num743 *= num745; + num744 *= num745; + int num746 = expertMode ? 54 : 65; + int num747 = mod.ProjectileType("PhantomBlast2"); + if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) + { + num746 *= 2; + } + vector93.X += num743 * 3f; + vector93.Y += num744 * 3f; + int num748 = Projectile.NewProjectile(vector93.X, vector93.Y, num743, num744, num747, num746, 0f, Main.myPlayer, 0f, 0f); + Main.projectile[num748].timeLeft = 240; + } + } + } + } + else + { + npc.HitSound = SoundID.NPCHit36; + if (!spawnGhost) + { + spawnGhost = true; + if (Main.netMode != 1) + { + NPC.NewNPC((int)vector.X, (int)vector.Y, mod.NPCType("PolterPhantom"), 0, 0f, 0f, 0f, 0f, 255); + for (int I = 0; I < 3; I++) + { + int Phantom = NPC.NewNPC((int)(Main.player[npc.target].Center.X + (Math.Sin(I * 120) * 500)), + (int)(Main.player[npc.target].Center.Y + (Math.Cos(I * 120) * 500)), mod.NPCType("PhantomFuckYou"), 0, 0, 0, 0, -1); + NPC Eye = Main.npc[Phantom]; + Eye.ai[0] = I * 120; + Eye.ai[3] = I * 120; + } + } + Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 122); + Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt"), 1f); + Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt2"), 1f); + Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt3"), 1f); + Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt4"), 1f); + Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Polt5"), 1f); + for (int num621 = 0; num621 < 10; num621++) + { + int num622 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 60, 0f, 0f, 100, default(Color), 2f); + Main.dust[num622].velocity *= 3f; + Main.dust[num622].noGravity = true; + if (Main.rand.Next(2) == 0) + { + Main.dust[num622].scale = 0.5f; + Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; + } + } + for (int num623 = 0; num623 < 30; num623++) + { + int num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 3f); + Main.dust[num624].noGravity = true; + Main.dust[num624].velocity *= 5f; + num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 2f); + Main.dust[num624].velocity *= 2f; + } + } + npc.GivenName = "Necroplasm"; + if (speedBoost1 || npc.GetGlobalNPC(mod).enraged || (Config.BossRushXerocCurse && CalamityWorld.bossRushActive)) + { + npc.defense = 200; + npc.damage = (int)(400f * Main.damageMultiplier); + } + else + { + npc.damage = expertMode ? 336 : 210; + npc.defense = 0; + } + if (phase4) + { + npc.localAI[1] += 1f; + if (npc.localAI[1] >= 150f) + { + float num757 = 8f; + Vector2 vector94 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f); + float num758 = Main.player[npc.target].position.X + (float)Main.player[npc.target].width * 0.5f - vector94.X + (float)Main.rand.Next(-10, 11); + float num759 = Math.Abs(num758 * 0.2f); + float num760 = Main.player[npc.target].position.Y + (float)Main.player[npc.target].height * 0.5f - vector94.Y + (float)Main.rand.Next(-10, 11); + if (num760 > 0f) + { + num759 = 0f; + } + num760 -= num759; + float num761 = (float)Math.Sqrt((double)(num758 * num758 + num760 * num760)); + num761 = num757 / num761; + num758 *= num761; + num760 *= num761; + if (NPC.CountNPCS(mod.NPCType("PhantomSpiritL")) < (revenge ? 3 : 2) && Main.netMode != 1) + { + int num762 = NPC.NewNPC((int)vector.X, (int)vector.Y, mod.NPCType("PhantomSpiritL"), 0, 0f, 0f, 0f, 0f, 255); + Main.npc[num762].velocity.X = num758; + Main.npc[num762].velocity.Y = num760; + Main.npc[num762].netUpdate = true; + } + npc.localAI[1] = 0f; + } + } + } + } + + public override void NPCLoot() + { + if (CalamityWorld.armageddon) + { + for (int i = 0; i < 5; i++) + { + npc.DropBossBags(); + } + } + if (Main.rand.Next(10) == 0) + { + Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("PolterghastTrophy")); + } + if (Main.expertMode) + { + npc.DropBossBags(); + } + else + { + Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("RuinousSoul"), Main.rand.Next(5, 9)); + if (Main.rand.Next(4) == 0) + { + Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("BansheeHook")); + } + if (Main.rand.Next(4) == 0) + { + Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("DaemonsFlame")); + } + if (Main.rand.Next(4) == 0) + { + Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("EtherealSubjugator")); + } + if (Main.rand.Next(4) == 0) + { + Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("FatesReveal")); + } + if (Main.rand.Next(4) == 0) + { + Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("GhastlyVisage")); + } + if (Main.rand.Next(4) == 0) + { + Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("GhoulishGouger")); + } + if (Main.rand.Next(4) == 0) + { + Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("TerrorBlade")); + } + } + } + + public override void BossLoot(ref string name, ref int potionType) + { + potionType = ItemID.SuperHealingPotion; + } + + public override bool StrikeNPC(ref double damage, int defense, ref float knockback, int hitDirection, ref bool crit) + { + double newDamage = (damage + (int)((double)defense * 0.25)); + float protection = 0.1f + //.1 + ((double)npc.life <= (double)npc.lifeMax * 0.75 ? 0.05f : 0f) + //.15 + ((double)npc.life <= (double)npc.lifeMax * (CalamityWorld.revenge ? 0.5 : 0.33) ? 0.05f : 0f) + //.2 + (boostDR ? 0.6f : 0f); //.8 + if (npc.ichor) + { + protection *= 0.88f; + } + else if (npc.onFire2) + { + protection *= 0.9f; + } + if (newDamage < 1.0) + { + newDamage = 1.0; + } + if (newDamage >= 1.0) + { + newDamage = (double)((int)((double)(1f - protection) * newDamage)); + if (newDamage < 1.0) + { + newDamage = 1.0; + } + } + damage = newDamage; + return true; + } + + public override void FindFrame(int frameHeight) + { + bool phase2 = (double)npc.life > (double)npc.lifeMax * (CalamityWorld.revenge ? 0.5 : 0.33); + npc.frameCounter += 1.0; + if (npc.frameCounter > 6.0) + { + npc.frameCounter = 0.0; + npc.frame.Y = npc.frame.Y + frameHeight; + } + if ((double)npc.life > (double)npc.lifeMax * 0.75) + { + if (npc.frame.Y > frameHeight * 3) + { + npc.frame.Y = 0; + } + } + else if (phase2) + { + if (npc.frame.Y < frameHeight * 4) + { + npc.frame.Y = frameHeight * 4; + } + if (npc.frame.Y > frameHeight * 7) + { + npc.frame.Y = frameHeight * 4; + } + } + else + { + if (npc.frame.Y < frameHeight * 8) + { + npc.frame.Y = frameHeight * 8; + } + if (npc.frame.Y > frameHeight * 11) + { + npc.frame.Y = frameHeight * 8; + } + } + } + + public override void OnHitPlayer(Player player, int damage, bool crit) + { + if (CalamityWorld.revenge) + player.AddBuff(mod.BuffType("Horror"), 300, true); + } + + public override bool CanHitPlayer(Player target, ref int cooldownSlot) + { + cooldownSlot = 1; + return true; + } + + public override void ScaleExpertStats(int numPlayers, float bossLifeScale) + { + npc.lifeMax = (int)(npc.lifeMax * 0.8f * bossLifeScale); + npc.damage = (int)(npc.damage * 0.8f); + } + + public override void HitEffect(int hitDirection, double damage) + { + Dust.NewDust(npc.position, npc.width, npc.height, 180, hitDirection, -1f, 0, default(Color), 1f); + if (npc.life <= 0) + { + npc.position.X = npc.position.X + (float)(npc.width / 2); + npc.position.Y = npc.position.Y + (float)(npc.height / 2); + npc.width = 90; + npc.height = 90; + npc.position.X = npc.position.X - (float)(npc.width / 2); + npc.position.Y = npc.position.Y - (float)(npc.height / 2); + for (int num621 = 0; num621 < 10; num621++) + { + int num622 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 60, 0f, 0f, 100, default(Color), 2f); + Main.dust[num622].velocity *= 3f; + if (Main.rand.Next(2) == 0) + { + Main.dust[num622].scale = 0.5f; + Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; + } + } + for (int num623 = 0; num623 < 60; num623++) + { + int num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 3f); + Main.dust[num624].noGravity = true; + Main.dust[num624].velocity *= 5f; + num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 180, 0f, 0f, 100, default(Color), 2f); + Main.dust[num624].velocity *= 2f; + } + } + } + } +} \ No newline at end of file diff --git a/NPCs/Polterghast/PolterghastHook.cs b/NPCs/Polterghast/PolterghastHook.cs index 0c45cc42b7..e1ba39b945 100644 --- a/NPCs/Polterghast/PolterghastHook.cs +++ b/NPCs/Polterghast/PolterghastHook.cs @@ -1,484 +1,485 @@ -using System; -using System.Collections.Generic; -using System.IO; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; -using CalamityMod.Projectiles; -using CalamityMod.World; - -namespace CalamityMod.NPCs.Polterghast -{ - public class PolterghastHook : ModNPC - { - private int despawnTimer = 300; - private bool phase2 = false; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Polterghast Hook"); - Main.npcFrameCount[npc.type] = 2; - } - - public override void SetDefaults() - { - npc.aiStyle = -1; - aiType = -1; - npc.damage = 120; - npc.width = 40; //324 - npc.height = 40; //216 - npc.defense = 50; - npc.lifeMax = CalamityWorld.revenge ? 60000 : 50000; - if (CalamityWorld.death) - { - npc.lifeMax = 100000; - } - npc.dontTakeDamage = true; - npc.noGravity = true; - npc.noTileCollide = true; - for (int k = 0; k < npc.buffImmune.Length; k++) - { - npc.buffImmune[k] = true; - } - npc.HitSound = SoundID.NPCHit34; - npc.DeathSound = SoundID.NPCDeath39; - } - - public override void SendExtraAI(BinaryWriter writer) - { - writer.Write(phase2); - writer.Write(despawnTimer); - } - - public override void ReceiveExtraAI(BinaryReader reader) - { - phase2 = reader.ReadBoolean(); - despawnTimer = reader.ReadInt32(); - } - - public override void AI() - { - Lighting.AddLight((int)((npc.position.X + (float)(npc.width / 2)) / 16f), (int)((npc.position.Y + (float)(npc.height / 2)) / 16f), 0.3f, 1f, 1f); - bool expertMode = Main.expertMode; - bool revenge = CalamityWorld.revenge; - bool speedBoost1 = false; - bool despawnBoost = false; - if (CalamityGlobalNPC.ghostBoss < 0 || !Main.npc[CalamityGlobalNPC.ghostBoss].active) - { - npc.active = false; - npc.netUpdate = true; - return; - } - if (CalamityGlobalNPC.ghostBoss != -1 && !Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].ZoneDungeon && !CalamityWorld.bossRushActive) - { - despawnTimer--; - if (despawnTimer <= 0) { despawnBoost = true; } - npc.localAI[0] -= 6f; - speedBoost1 = true; - } - else { despawnTimer = 300; } - if ((double)Main.npc[CalamityGlobalNPC.ghostBoss].life <= (double)Main.npc[CalamityGlobalNPC.ghostBoss].lifeMax * 0.75) - { - if (!phase2) - { - npc.damage = 0; - phase2 = true; - } - npc.TargetClosest(true); - if (Main.netMode == 1) - { - if (npc.ai[0] == 0f) - { - npc.ai[0] = (float)((int)(npc.Center.X / 16f)); - } - if (npc.ai[1] == 0f) - { - npc.ai[1] = (float)((int)(npc.Center.X / 16f)); - } - } - if (Main.netMode != 1) - { - if (npc.ai[0] == 0f || npc.ai[1] == 0f) - { - npc.localAI[0] = 0f; - } - npc.localAI[0] -= 5f; - if (speedBoost1) - { - npc.localAI[0] -= 10f; - } - if (!despawnBoost && npc.localAI[0] <= 0f && npc.ai[0] != 0f) - { - int num; - for (int num763 = 0; num763 < 200; num763 = num + 1) - { - if (num763 != npc.whoAmI && Main.npc[num763].active && Main.npc[num763].type == npc.type && (Main.npc[num763].velocity.X != 0f || Main.npc[num763].velocity.Y != 0f)) - { - npc.localAI[0] = (float)Main.rand.Next(60, 300); - } - num = num763; - } - } - if (npc.localAI[0] <= 0f) - { - npc.localAI[0] = (float)Main.rand.Next(300, 600); - bool flag50 = false; - int num764 = 0; - while (!flag50 && num764 <= 1000) - { - num764++; - int num765 = (int)(Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].Center.X / 16f); - int num766 = (int)(Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].Center.Y / 16f); - if (npc.ai[0] == 0f) - { - num765 = (int)((Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].Center.X + Main.npc[CalamityGlobalNPC.ghostBoss].Center.X) / 32f); - num766 = (int)((Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].Center.Y + Main.npc[CalamityGlobalNPC.ghostBoss].Center.Y) / 32f); - } - if (despawnBoost) - { - num765 = (int)Main.npc[CalamityGlobalNPC.ghostBoss].position.X / 16; - num766 = (int)(Main.npc[CalamityGlobalNPC.ghostBoss].position.Y + 400f) / 16; - } - int num767 = 20; - num767 += (int)(100f * ((float)num764 / 1000f)); - int num768 = num765 + Main.rand.Next(-num767, num767 + 1); - int num769 = num766 + Main.rand.Next(-num767, num767 + 1); - try - { - if (WorldGen.SolidTile(num768, num769) || (Main.tile[num768, num769].wall > 0 && (num764 > 500 || Main.npc[CalamityGlobalNPC.ghostBoss].life < Main.npc[CalamityGlobalNPC.ghostBoss].lifeMax / 2))) - { - flag50 = true; - npc.ai[0] = (float)num768; - npc.ai[1] = (float)num769; - npc.netUpdate = true; - } - } - catch - { - } - } - } - } - if (npc.ai[0] > 0f && npc.ai[1] > 0f) - { - float num772 = 8f; - if (expertMode) - { - num772 += 1f; - } - if (speedBoost1) - { - num772 *= 2f; - } - if (despawnBoost) - { - num772 *= 2f; - } - Vector2 vector95 = new Vector2(npc.Center.X, npc.Center.Y); - float num773 = npc.ai[0] * 16f - 8f - vector95.X; - float num774 = npc.ai[1] * 16f - 8f - vector95.Y; - float num775 = (float)Math.Sqrt((double)(num773 * num773 + num774 * num774)); - if (num775 < 12f + num772) - { - npc.velocity.X = num773; - npc.velocity.Y = num774; - } - else - { - num775 = num772 / num775; - npc.velocity.X = num773 * num775; - npc.velocity.Y = num774 * num775; - } - } - Vector2 vector102 = new Vector2(npc.Center.X, npc.Center.Y); - float num818 = Main.player[npc.target].Center.X - vector102.X; - float num819 = Main.player[npc.target].Center.Y - vector102.Y; - float num820 = (float)Math.Sqrt((double)(num818 * num818 + num819 * num819)); - float num821 = 10f; - num820 = num821 / num820; - num818 *= num820; - num819 *= num820; - npc.rotation = (float)Math.Atan2((double)num819, (double)num818) + 1.57f; - Vector2 vector17 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f); - float num147 = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2) - vector17.X; - float num148 = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2) - vector17.Y; - float num149 = (float)Math.Sqrt((double)(num147 * num147 + num148 * num148)); - num149 = 4f / num149; - num147 *= num149; - num148 *= num149; - vector17 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f); - num147 = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2) - vector17.X; - num148 = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2) - vector17.Y; - num149 = (float)Math.Sqrt((double)(num147 * num147 + num148 * num148)); - if (num149 > 1200f) - { - npc.ai[2] = 0f; - npc.ai[3] = 0f; - return; - } - npc.ai[2] += 1f; - if (npc.ai[3] == 0f) - { - if (npc.ai[2] > 120f) - { - npc.ai[2] = 0f; - npc.ai[3] = 1f; - npc.netUpdate = true; - } - } - else - { - if (npc.ai[2] > 40f) - { - npc.ai[3] = 0f; - } - if (Main.netMode != 1 && npc.ai[2] == 20f) - { - float num151 = 5f; - int num152 = 60; - int num153 = mod.ProjectileType("PhantomHookShot"); - num149 = num151 / num149; - num147 *= num149; - num148 *= num149; - int num154 = Projectile.NewProjectile(vector17.X, vector17.Y, num147, num148, num153, num152, 0f, Main.myPlayer, 0f, 0f); - } - } - return; - } - if (Main.netMode == 1) - { - if (npc.ai[0] == 0f) - { - npc.ai[0] = (float)((int)(npc.Center.X / 16f)); - } - if (npc.ai[1] == 0f) - { - npc.ai[1] = (float)((int)(npc.Center.X / 16f)); - } - } - if (Main.netMode != 1) - { - if (npc.ai[0] == 0f || npc.ai[1] == 0f) - { - npc.localAI[0] = 0f; - } - npc.localAI[0] -= 5f; - if (speedBoost1) - { - npc.localAI[0] -= 10f; - } - if (!despawnBoost && npc.localAI[0] <= 0f && npc.ai[0] != 0f) - { - int num; - for (int num763 = 0; num763 < 200; num763 = num + 1) - { - if (num763 != npc.whoAmI && Main.npc[num763].active && Main.npc[num763].type == npc.type && (Main.npc[num763].velocity.X != 0f || Main.npc[num763].velocity.Y != 0f)) - { - npc.localAI[0] = (float)Main.rand.Next(60, 300); - } - num = num763; - } - } - if (npc.localAI[0] <= 0f) - { - npc.localAI[0] = (float)Main.rand.Next(300, 600); - bool flag50 = false; - int num764 = 0; - while (!flag50 && num764 <= 1000) - { - num764++; - int num765 = (int)(Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].Center.X / 16f); - int num766 = (int)(Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].Center.Y / 16f); - if (npc.ai[0] == 0f) - { - num765 = (int)((Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].Center.X + Main.npc[CalamityGlobalNPC.ghostBoss].Center.X) / 32f); - num766 = (int)((Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].Center.Y + Main.npc[CalamityGlobalNPC.ghostBoss].Center.Y) / 32f); - } - if (despawnBoost) - { - num765 = (int)Main.npc[CalamityGlobalNPC.ghostBoss].position.X / 16; - num766 = (int)(Main.npc[CalamityGlobalNPC.ghostBoss].position.Y + 400f) / 16; - } - int num767 = 20; - num767 += (int)(100f * ((float)num764 / 1000f)); - int num768 = num765 + Main.rand.Next(-num767, num767 + 1); - int num769 = num766 + Main.rand.Next(-num767, num767 + 1); - try - { - if (WorldGen.SolidTile(num768, num769) || (Main.tile[num768, num769].wall > 0 && (num764 > 500 || Main.npc[CalamityGlobalNPC.ghostBoss].life < Main.npc[CalamityGlobalNPC.ghostBoss].lifeMax / 2))) - { - flag50 = true; - npc.ai[0] = (float)num768; - npc.ai[1] = (float)num769; - npc.netUpdate = true; - } - } - catch - { - } - } - } - } - if (npc.ai[0] > 0f && npc.ai[1] > 0f) - { - float num772 = 11f; - if (expertMode) - { - num772 += 1f; - } - if (speedBoost1) - { - num772 *= 2f; - } - if (despawnBoost) - { - num772 *= 2f; - } - Vector2 vector95 = new Vector2(npc.Center.X, npc.Center.Y); - float num773 = npc.ai[0] * 16f - 8f - vector95.X; - float num774 = npc.ai[1] * 16f - 8f - vector95.Y; - float num775 = (float)Math.Sqrt((double)(num773 * num773 + num774 * num774)); - if (num775 < 12f + num772) - { - npc.velocity.X = num773; - npc.velocity.Y = num774; - } - else - { - num775 = num772 / num775; - npc.velocity.X = num773 * num775; - npc.velocity.Y = num774 * num775; - } - Vector2 vector96 = new Vector2(npc.Center.X, npc.Center.Y); - float num776 = Main.npc[CalamityGlobalNPC.ghostBoss].Center.X - vector96.X; - float num777 = Main.npc[CalamityGlobalNPC.ghostBoss].Center.Y - vector96.Y; - npc.rotation = (float)Math.Atan2((double)num777, (double)num776) - 1.57f; - } - } - - public override void FindFrame(int frameHeight) - { - if (phase2) - { - if (npc.ai[3] == 0f) - { - if (npc.frame.Y < 1) - { - npc.frameCounter += 1.0; - if (npc.frameCounter > 4.0) - { - npc.frameCounter = 0.0; - npc.frame.Y = npc.frame.Y + frameHeight; - } - } - } - else if (npc.frame.Y > 0) - { - npc.frameCounter += 1.0; - if (npc.frameCounter > 4.0) - { - npc.frameCounter = 0.0; - npc.frame.Y = npc.frame.Y - frameHeight; - } - } - return; - } - if (npc.velocity.X == 0f && npc.velocity.Y == 0f) - { - if (npc.frame.Y < 1) - { - npc.frameCounter += 1.0; - if (npc.frameCounter > 4.0) - { - npc.frameCounter = 0.0; - npc.frame.Y = npc.frame.Y + frameHeight; - } - } - } - else if (npc.frame.Y > 0) - { - npc.frameCounter += 1.0; - if (npc.frameCounter > 4.0) - { - npc.frameCounter = 0.0; - npc.frame.Y = npc.frame.Y - frameHeight; - } - } - } - - public override bool PreDraw(SpriteBatch spriteBatch, Color drawColor) - { - if (Main.npc[CalamityGlobalNPC.ghostBoss].active && !phase2) - { - Vector2 center = new Vector2(npc.Center.X, npc.Center.Y); - float bossCenterX = Main.npc[CalamityGlobalNPC.ghostBoss].Center.X - center.X; - float bossCenterY = Main.npc[CalamityGlobalNPC.ghostBoss].Center.Y - center.Y; - float rotation2 = (float)Math.Atan2((double)bossCenterY, (double)bossCenterX) - 1.57f; - bool draw = true; - while (draw) - { - int chainWidth = 20; //16 24 - int chainHeight = 52; //32 16 - float num10 = (float)Math.Sqrt((double)(bossCenterX * bossCenterX + bossCenterY * bossCenterY)); - if (num10 < (float)chainHeight) - { - chainWidth = (int)num10 - chainHeight + chainWidth; - draw = false; - } - num10 = (float)chainWidth / num10; - bossCenterX *= num10; - bossCenterY *= num10; - center.X += bossCenterX; - center.Y += bossCenterY; - bossCenterX = Main.npc[CalamityGlobalNPC.ghostBoss].Center.X - center.X; - bossCenterY = Main.npc[CalamityGlobalNPC.ghostBoss].Center.Y - center.Y; - Microsoft.Xna.Framework.Color color2 = Lighting.GetColor((int)center.X / 16, (int)(center.Y / 16f)); - Main.spriteBatch.Draw(mod.GetTexture("NPCs/Polterghast/PolterghastChain"), new Vector2(center.X - Main.screenPosition.X, center.Y - Main.screenPosition.Y), - new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(0, 0, mod.GetTexture("NPCs/Polterghast/PolterghastChain").Width, chainWidth)), color2, rotation2, - new Vector2((float)mod.GetTexture("NPCs/Polterghast/PolterghastChain").Width * 0.5f, (float)mod.GetTexture("NPCs/Polterghast/PolterghastChain").Height * 0.5f), 1f, SpriteEffects.None, 0f); - } - } - return true; - } - - public override bool CheckActive() - { - return false; - } - - public override bool CanHitPlayer(Player target, ref int cooldownSlot) - { - cooldownSlot = 1; - return true; - } - - public override void OnHitPlayer(Player player, int damage, bool crit) - { - if (CalamityWorld.revenge) - player.AddBuff(mod.BuffType("Horror"), 180, true); - } - - public override void ScaleExpertStats(int numPlayers, float bossLifeScale) - { - npc.lifeMax = (int)(npc.lifeMax * 0.5f * bossLifeScale); - npc.damage = (int)(npc.damage * 0.7f); - } - - public override void HitEffect(int hitDirection, double damage) - { - for (int k = 0; k < 5; k++) - { - Dust.NewDust(npc.position, npc.width, npc.height, 180, hitDirection, -1f, 0, default(Color), 1f); - } - if (npc.life <= 0) - { - for (int k = 0; k < 20; k++) - { - Dust.NewDust(npc.position, npc.width, npc.height, 180, hitDirection, -1f, 0, default(Color), 1f); - } - } - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using CalamityMod.Projectiles; +using CalamityMod.World; + +namespace CalamityMod.NPCs.Polterghast +{ + public class PolterghastHook : ModNPC + { + private int despawnTimer = 300; + private bool phase2 = false; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Polterghast Hook"); + Main.npcFrameCount[npc.type] = 2; + } + + public override void SetDefaults() + { + npc.aiStyle = -1; + aiType = -1; + npc.damage = 120; + npc.width = 40; //324 + npc.height = 40; //216 + npc.defense = 50; + npc.lifeMax = CalamityWorld.revenge ? 60000 : 50000; + if (CalamityWorld.death) + { + npc.lifeMax = 100000; + } + npc.dontTakeDamage = true; + npc.noGravity = true; + npc.noTileCollide = true; + for (int k = 0; k < npc.buffImmune.Length; k++) + { + npc.buffImmune[k] = true; + } + npc.HitSound = SoundID.NPCHit34; + npc.DeathSound = SoundID.NPCDeath39; + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(phase2); + writer.Write(despawnTimer); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + phase2 = reader.ReadBoolean(); + despawnTimer = reader.ReadInt32(); + } + + public override void AI() + { + Lighting.AddLight((int)((npc.position.X + (float)(npc.width / 2)) / 16f), (int)((npc.position.Y + (float)(npc.height / 2)) / 16f), 0.3f, 1f, 1f); + bool expertMode = Main.expertMode; + bool revenge = CalamityWorld.revenge; + bool speedBoost1 = false; + bool despawnBoost = false; + if (CalamityGlobalNPC.ghostBoss < 0 || !Main.npc[CalamityGlobalNPC.ghostBoss].active) + { + npc.active = false; + npc.netUpdate = true; + return; + } + if (CalamityGlobalNPC.ghostBoss != -1 && !Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].ZoneDungeon && + (double)Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].position.Y < Main.worldSurface * 16.0 && !CalamityWorld.bossRushActive) + { + despawnTimer--; + if (despawnTimer <= 0) { despawnBoost = true; } + npc.localAI[0] -= 6f; + speedBoost1 = true; + } + else { despawnTimer = 300; } + if ((double)Main.npc[CalamityGlobalNPC.ghostBoss].life <= (double)Main.npc[CalamityGlobalNPC.ghostBoss].lifeMax * 0.75) + { + if (!phase2) + { + npc.damage = 0; + phase2 = true; + } + npc.TargetClosest(true); + if (Main.netMode == 1) + { + if (npc.ai[0] == 0f) + { + npc.ai[0] = (float)((int)(npc.Center.X / 16f)); + } + if (npc.ai[1] == 0f) + { + npc.ai[1] = (float)((int)(npc.Center.X / 16f)); + } + } + if (Main.netMode != 1) + { + if (npc.ai[0] == 0f || npc.ai[1] == 0f) + { + npc.localAI[0] = 0f; + } + npc.localAI[0] -= 5f; + if (speedBoost1) + { + npc.localAI[0] -= 10f; + } + if (!despawnBoost && npc.localAI[0] <= 0f && npc.ai[0] != 0f) + { + int num; + for (int num763 = 0; num763 < 200; num763 = num + 1) + { + if (num763 != npc.whoAmI && Main.npc[num763].active && Main.npc[num763].type == npc.type && (Main.npc[num763].velocity.X != 0f || Main.npc[num763].velocity.Y != 0f)) + { + npc.localAI[0] = (float)Main.rand.Next(60, 300); + } + num = num763; + } + } + if (npc.localAI[0] <= 0f) + { + npc.localAI[0] = (float)Main.rand.Next(300, 600); + bool flag50 = false; + int num764 = 0; + while (!flag50 && num764 <= 1000) + { + num764++; + int num765 = (int)(Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].Center.X / 16f); + int num766 = (int)(Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].Center.Y / 16f); + if (npc.ai[0] == 0f) + { + num765 = (int)((Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].Center.X + Main.npc[CalamityGlobalNPC.ghostBoss].Center.X) / 32f); + num766 = (int)((Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].Center.Y + Main.npc[CalamityGlobalNPC.ghostBoss].Center.Y) / 32f); + } + if (despawnBoost) + { + num765 = (int)Main.npc[CalamityGlobalNPC.ghostBoss].position.X / 16; + num766 = (int)(Main.npc[CalamityGlobalNPC.ghostBoss].position.Y + 400f) / 16; + } + int num767 = 20; + num767 += (int)(100f * ((float)num764 / 1000f)); + int num768 = num765 + Main.rand.Next(-num767, num767 + 1); + int num769 = num766 + Main.rand.Next(-num767, num767 + 1); + try + { + if (WorldGen.SolidTile(num768, num769) || (Main.tile[num768, num769].wall > 0 && (num764 > 500 || Main.npc[CalamityGlobalNPC.ghostBoss].life < Main.npc[CalamityGlobalNPC.ghostBoss].lifeMax / 2))) + { + flag50 = true; + npc.ai[0] = (float)num768; + npc.ai[1] = (float)num769; + npc.netUpdate = true; + } + } + catch + { + } + } + } + } + if (npc.ai[0] > 0f && npc.ai[1] > 0f) + { + float num772 = 8f; + if (expertMode) + { + num772 += 1f; + } + if (speedBoost1) + { + num772 *= 2f; + } + if (despawnBoost) + { + num772 *= 2f; + } + Vector2 vector95 = new Vector2(npc.Center.X, npc.Center.Y); + float num773 = npc.ai[0] * 16f - 8f - vector95.X; + float num774 = npc.ai[1] * 16f - 8f - vector95.Y; + float num775 = (float)Math.Sqrt((double)(num773 * num773 + num774 * num774)); + if (num775 < 12f + num772) + { + npc.velocity.X = num773; + npc.velocity.Y = num774; + } + else + { + num775 = num772 / num775; + npc.velocity.X = num773 * num775; + npc.velocity.Y = num774 * num775; + } + } + Vector2 vector102 = new Vector2(npc.Center.X, npc.Center.Y); + float num818 = Main.player[npc.target].Center.X - vector102.X; + float num819 = Main.player[npc.target].Center.Y - vector102.Y; + float num820 = (float)Math.Sqrt((double)(num818 * num818 + num819 * num819)); + float num821 = 10f; + num820 = num821 / num820; + num818 *= num820; + num819 *= num820; + npc.rotation = (float)Math.Atan2((double)num819, (double)num818) + 1.57f; + Vector2 vector17 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f); + float num147 = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2) - vector17.X; + float num148 = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2) - vector17.Y; + float num149 = (float)Math.Sqrt((double)(num147 * num147 + num148 * num148)); + num149 = 4f / num149; + num147 *= num149; + num148 *= num149; + vector17 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f); + num147 = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2) - vector17.X; + num148 = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2) - vector17.Y; + num149 = (float)Math.Sqrt((double)(num147 * num147 + num148 * num148)); + if (num149 > 1200f) + { + npc.ai[2] = 0f; + npc.ai[3] = 0f; + return; + } + npc.ai[2] += 1f; + if (npc.ai[3] == 0f) + { + if (npc.ai[2] > 120f) + { + npc.ai[2] = 0f; + npc.ai[3] = 1f; + npc.netUpdate = true; + } + } + else + { + if (npc.ai[2] > 40f) + { + npc.ai[3] = 0f; + } + if (Main.netMode != 1 && npc.ai[2] == 20f) + { + float num151 = 5f; + int num152 = 60; + int num153 = mod.ProjectileType("PhantomHookShot"); + num149 = num151 / num149; + num147 *= num149; + num148 *= num149; + int num154 = Projectile.NewProjectile(vector17.X, vector17.Y, num147, num148, num153, num152, 0f, Main.myPlayer, 0f, 0f); + } + } + return; + } + if (Main.netMode == 1) + { + if (npc.ai[0] == 0f) + { + npc.ai[0] = (float)((int)(npc.Center.X / 16f)); + } + if (npc.ai[1] == 0f) + { + npc.ai[1] = (float)((int)(npc.Center.X / 16f)); + } + } + if (Main.netMode != 1) + { + if (npc.ai[0] == 0f || npc.ai[1] == 0f) + { + npc.localAI[0] = 0f; + } + npc.localAI[0] -= 5f; + if (speedBoost1) + { + npc.localAI[0] -= 10f; + } + if (!despawnBoost && npc.localAI[0] <= 0f && npc.ai[0] != 0f) + { + int num; + for (int num763 = 0; num763 < 200; num763 = num + 1) + { + if (num763 != npc.whoAmI && Main.npc[num763].active && Main.npc[num763].type == npc.type && (Main.npc[num763].velocity.X != 0f || Main.npc[num763].velocity.Y != 0f)) + { + npc.localAI[0] = (float)Main.rand.Next(60, 300); + } + num = num763; + } + } + if (npc.localAI[0] <= 0f) + { + npc.localAI[0] = (float)Main.rand.Next(300, 600); + bool flag50 = false; + int num764 = 0; + while (!flag50 && num764 <= 1000) + { + num764++; + int num765 = (int)(Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].Center.X / 16f); + int num766 = (int)(Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].Center.Y / 16f); + if (npc.ai[0] == 0f) + { + num765 = (int)((Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].Center.X + Main.npc[CalamityGlobalNPC.ghostBoss].Center.X) / 32f); + num766 = (int)((Main.player[Main.npc[CalamityGlobalNPC.ghostBoss].target].Center.Y + Main.npc[CalamityGlobalNPC.ghostBoss].Center.Y) / 32f); + } + if (despawnBoost) + { + num765 = (int)Main.npc[CalamityGlobalNPC.ghostBoss].position.X / 16; + num766 = (int)(Main.npc[CalamityGlobalNPC.ghostBoss].position.Y + 400f) / 16; + } + int num767 = 20; + num767 += (int)(100f * ((float)num764 / 1000f)); + int num768 = num765 + Main.rand.Next(-num767, num767 + 1); + int num769 = num766 + Main.rand.Next(-num767, num767 + 1); + try + { + if (WorldGen.SolidTile(num768, num769) || (Main.tile[num768, num769].wall > 0 && (num764 > 500 || Main.npc[CalamityGlobalNPC.ghostBoss].life < Main.npc[CalamityGlobalNPC.ghostBoss].lifeMax / 2))) + { + flag50 = true; + npc.ai[0] = (float)num768; + npc.ai[1] = (float)num769; + npc.netUpdate = true; + } + } + catch + { + } + } + } + } + if (npc.ai[0] > 0f && npc.ai[1] > 0f) + { + float num772 = 11f; + if (expertMode) + { + num772 += 1f; + } + if (speedBoost1) + { + num772 *= 2f; + } + if (despawnBoost) + { + num772 *= 2f; + } + Vector2 vector95 = new Vector2(npc.Center.X, npc.Center.Y); + float num773 = npc.ai[0] * 16f - 8f - vector95.X; + float num774 = npc.ai[1] * 16f - 8f - vector95.Y; + float num775 = (float)Math.Sqrt((double)(num773 * num773 + num774 * num774)); + if (num775 < 12f + num772) + { + npc.velocity.X = num773; + npc.velocity.Y = num774; + } + else + { + num775 = num772 / num775; + npc.velocity.X = num773 * num775; + npc.velocity.Y = num774 * num775; + } + Vector2 vector96 = new Vector2(npc.Center.X, npc.Center.Y); + float num776 = Main.npc[CalamityGlobalNPC.ghostBoss].Center.X - vector96.X; + float num777 = Main.npc[CalamityGlobalNPC.ghostBoss].Center.Y - vector96.Y; + npc.rotation = (float)Math.Atan2((double)num777, (double)num776) - 1.57f; + } + } + + public override void FindFrame(int frameHeight) + { + if (phase2) + { + if (npc.ai[3] == 0f) + { + if (npc.frame.Y < 1) + { + npc.frameCounter += 1.0; + if (npc.frameCounter > 4.0) + { + npc.frameCounter = 0.0; + npc.frame.Y = npc.frame.Y + frameHeight; + } + } + } + else if (npc.frame.Y > 0) + { + npc.frameCounter += 1.0; + if (npc.frameCounter > 4.0) + { + npc.frameCounter = 0.0; + npc.frame.Y = npc.frame.Y - frameHeight; + } + } + return; + } + if (npc.velocity.X == 0f && npc.velocity.Y == 0f) + { + if (npc.frame.Y < 1) + { + npc.frameCounter += 1.0; + if (npc.frameCounter > 4.0) + { + npc.frameCounter = 0.0; + npc.frame.Y = npc.frame.Y + frameHeight; + } + } + } + else if (npc.frame.Y > 0) + { + npc.frameCounter += 1.0; + if (npc.frameCounter > 4.0) + { + npc.frameCounter = 0.0; + npc.frame.Y = npc.frame.Y - frameHeight; + } + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color drawColor) + { + if (Main.npc[CalamityGlobalNPC.ghostBoss].active && !phase2) + { + Vector2 center = new Vector2(npc.Center.X, npc.Center.Y); + float bossCenterX = Main.npc[CalamityGlobalNPC.ghostBoss].Center.X - center.X; + float bossCenterY = Main.npc[CalamityGlobalNPC.ghostBoss].Center.Y - center.Y; + float rotation2 = (float)Math.Atan2((double)bossCenterY, (double)bossCenterX) - 1.57f; + bool draw = true; + while (draw) + { + int chainWidth = 20; //16 24 + int chainHeight = 52; //32 16 + float num10 = (float)Math.Sqrt((double)(bossCenterX * bossCenterX + bossCenterY * bossCenterY)); + if (num10 < (float)chainHeight) + { + chainWidth = (int)num10 - chainHeight + chainWidth; + draw = false; + } + num10 = (float)chainWidth / num10; + bossCenterX *= num10; + bossCenterY *= num10; + center.X += bossCenterX; + center.Y += bossCenterY; + bossCenterX = Main.npc[CalamityGlobalNPC.ghostBoss].Center.X - center.X; + bossCenterY = Main.npc[CalamityGlobalNPC.ghostBoss].Center.Y - center.Y; + Microsoft.Xna.Framework.Color color2 = Lighting.GetColor((int)center.X / 16, (int)(center.Y / 16f)); + Main.spriteBatch.Draw(mod.GetTexture("NPCs/Polterghast/PolterghastChain"), new Vector2(center.X - Main.screenPosition.X, center.Y - Main.screenPosition.Y), + new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(0, 0, mod.GetTexture("NPCs/Polterghast/PolterghastChain").Width, chainWidth)), color2, rotation2, + new Vector2((float)mod.GetTexture("NPCs/Polterghast/PolterghastChain").Width * 0.5f, (float)mod.GetTexture("NPCs/Polterghast/PolterghastChain").Height * 0.5f), 1f, SpriteEffects.None, 0f); + } + } + return true; + } + + public override bool CheckActive() + { + return false; + } + + public override bool CanHitPlayer(Player target, ref int cooldownSlot) + { + cooldownSlot = 1; + return true; + } + + public override void OnHitPlayer(Player player, int damage, bool crit) + { + if (CalamityWorld.revenge) + player.AddBuff(mod.BuffType("Horror"), 180, true); + } + + public override void ScaleExpertStats(int numPlayers, float bossLifeScale) + { + npc.lifeMax = (int)(npc.lifeMax * 0.5f * bossLifeScale); + npc.damage = (int)(npc.damage * 0.7f); + } + + public override void HitEffect(int hitDirection, double damage) + { + for (int k = 0; k < 5; k++) + { + Dust.NewDust(npc.position, npc.width, npc.height, 180, hitDirection, -1f, 0, default(Color), 1f); + } + if (npc.life <= 0) + { + for (int k = 0; k < 20; k++) + { + Dust.NewDust(npc.position, npc.width, npc.height, 180, hitDirection, -1f, 0, default(Color), 1f); + } + } + } + } +} \ No newline at end of file