From 4a191d0d4e08a175f4cb300682dfdcc929430819 Mon Sep 17 00:00:00 2001 From: mountaindrew10 Date: Tue, 20 Feb 2024 05:11:54 -0600 Subject: [PATCH] Master Mode Twins and contact damage fairness (plus some vanilla Expert Mode changes because they didn't have many). THIS MADE ME GO INSANE --- NPCs/CalamityGlobalNPC.cs | 6 +- NPCs/VanillaNPCOverrides/Bosses/TwinsAI.cs | 1207 +++++++++++++++++++- 2 files changed, 1205 insertions(+), 8 deletions(-) diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index c030f3a204..816e3a9a13 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -3097,16 +3097,14 @@ namespace CalamityMod.NPCs /*case NPCID.TheDestroyer: case NPCID.TheDestroyerBody: case NPCID.TheDestroyerTail: - return DestroyerAI.VanillaDestroyerAI(npc, Mod); - case NPCID.Probe: - return DestroyerAI.VanillaProbeAI(npc, Mod); + return DestroyerAI.VanillaDestroyerAI(npc, Mod);*/ case NPCID.Retinazer: return TwinsAI.VanillaRetinazerAI(npc, Mod); case NPCID.Spazmatism: return TwinsAI.VanillaSpazmatismAI(npc, Mod); - case NPCID.SkeletronPrime: + /*case NPCID.SkeletronPrime: return SkeletronPrimeAI.VanillaSkeletronPrimeAI(npc, Mod); case NPCID.PrimeLaser: return SkeletronPrimeAI.VanillaPrimeLaserAI(npc, Mod); diff --git a/NPCs/VanillaNPCOverrides/Bosses/TwinsAI.cs b/NPCs/VanillaNPCOverrides/Bosses/TwinsAI.cs index 5278dd5d20..4346e2e41d 100644 --- a/NPCs/VanillaNPCOverrides/Bosses/TwinsAI.cs +++ b/NPCs/VanillaNPCOverrides/Bosses/TwinsAI.cs @@ -12,7 +12,6 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses { public static class TwinsAI { - #region Twins AI public static bool BuffedRetinazerAI(NPC npc, Mod mod) { CalamityGlobalNPC calamityGlobalNPC = npc.Calamity(); @@ -1430,8 +1429,8 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses if (NPC.IsMechQueenUp) { spazmatismFlamethrowerMaxSpeed = 14f; - spazmatismFlamethrowerTargetX = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2) - spazmatismFlamethrowerPos.X; - spazmatismFlamethrowerTargetY = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2) - 300f - spazmatismFlamethrowerPos.Y; + spazmatismFlamethrowerTargetX = Main.player[npc.target].Center.X - spazmatismFlamethrowerPos.X; + spazmatismFlamethrowerTargetY = Main.player[npc.target].Center.Y - 300f - spazmatismFlamethrowerPos.Y; spazmatismFlamethrowerTargetX = mechQueenSpacing.X; spazmatismFlamethrowerTargetY = mechQueenSpacing.Y; spazmatismFlamethrowerTargetX -= spazmatismFlamethrowerPos.X; @@ -1723,6 +1722,1206 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses return false; } - #endregion + + public static bool VanillaRetinazerAI(NPC npc, Mod mod) + { + if (npc.target < 0 || npc.target == Main.maxPlayers || Main.player[npc.target].dead || !Main.player[npc.target].active) + npc.TargetClosest(); + + float phase2LifeRatio = Main.masterMode ? 0.6f : 0.4f; + + bool dead2 = Main.player[npc.target].dead; + float num412 = npc.Center.X - Main.player[npc.target].position.X - (float)(Main.player[npc.target].width / 2); + float num413 = npc.position.Y + (float)npc.height - 59f - Main.player[npc.target].position.Y - (float)(Main.player[npc.target].height / 2); + float num414 = (float)Math.Atan2(num413, num412) + MathHelper.PiOver2; + if (num414 < 0f) + num414 += MathHelper.TwoPi; + else if ((double)num414 > MathHelper.TwoPi) + num414 -= MathHelper.TwoPi; + + float num415 = 0.1f; + if (npc.rotation < num414) + { + if ((double)(num414 - npc.rotation) > MathHelper.Pi) + npc.rotation -= num415; + else + npc.rotation += num415; + } + else if (npc.rotation > num414) + { + if ((double)(npc.rotation - num414) > MathHelper.Pi) + npc.rotation += num415; + else + npc.rotation -= num415; + } + + if (npc.rotation > num414 - num415 && npc.rotation < num414 + num415) + npc.rotation = num414; + + if (npc.rotation < 0f) + npc.rotation += MathHelper.TwoPi; + else if ((double)npc.rotation > MathHelper.TwoPi) + npc.rotation -= MathHelper.TwoPi; + + if (npc.rotation > num414 - num415 && npc.rotation < num414 + num415) + npc.rotation = num414; + + if (Main.rand.NextBool(5)) + { + int num416 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y + (float)npc.height * 0.25f), npc.width, (int)((float)npc.height * 0.5f), 5, npc.velocity.X, 2f); + Main.dust[num416].velocity.X *= 0.5f; + Main.dust[num416].velocity.Y *= 0.1f; + } + + if (Main.netMode != NetmodeID.MultiplayerClient && !Main.IsItDay() && !dead2 && npc.timeLeft < 10) + { + for (int num417 = 0; num417 < Main.maxNPCs; num417++) + { + if (num417 != npc.whoAmI && Main.npc[num417].active && (Main.npc[num417].type == NPCID.Retinazer || Main.npc[num417].type == NPCID.Spazmatism)) + npc.DiscourageDespawn(Main.npc[num417].timeLeft - 1); + } + } + + Vector2 vector41 = Vector2.Zero; + if (NPC.IsMechQueenUp) + { + NPC nPC = Main.npc[NPC.mechQueen]; + Vector2 mechQueenCenter = nPC.GetMechQueenCenter(); + Vector2 vector42 = new Vector2(-150f, -250f); + vector42 *= 0.75f; + float num418 = nPC.velocity.X * 0.025f; + vector41 = mechQueenCenter + vector42; + vector41 = vector41.RotatedBy(num418, mechQueenCenter); + } + + npc.reflectsProjectiles = false; + if (Main.IsItDay() || dead2) + { + npc.velocity.Y -= 0.04f; + npc.EncourageDespawn(10); + return false; + } + + if (npc.ai[0] == 0f) + { + if (npc.ai[1] == 0f) + { + // Avoid cheap bullshit + npc.damage = 0; + + float num419 = 7f; + float num420 = 0.1f; + if (Main.expertMode) + { + num419 = Main.masterMode ? 9.5f : 8.25f; + num420 = Main.masterMode ? 0.13f : 0.115f; + } + + if (Main.getGoodWorld) + { + num419 *= 1.15f; + num420 *= 1.15f; + } + + int num421 = 1; + if (npc.Center.X < Main.player[npc.target].position.X + (float)Main.player[npc.target].width) + num421 = -1; + + Vector2 vector43 = npc.Center; + float num422 = Main.player[npc.target].Center.X + (float)(num421 * 300) - vector43.X; + float num423 = Main.player[npc.target].Center.Y - 300f - vector43.Y; + if (NPC.IsMechQueenUp) + { + num419 = 14f; + num422 = vector41.X; + num423 = vector41.Y; + num422 -= vector43.X; + num423 -= vector43.Y; + } + + float num424 = (float)Math.Sqrt(num422 * num422 + num423 * num423); + float num425 = num424; + if (NPC.IsMechQueenUp) + { + if (num424 > num419) + { + num424 = num419 / num424; + num422 *= num424; + num423 *= num424; + } + + float num426 = 60f; + npc.velocity.X = (npc.velocity.X * (num426 - 1f) + num422) / num426; + npc.velocity.Y = (npc.velocity.Y * (num426 - 1f) + num423) / num426; + } + else + { + num424 = num419 / num424; + num422 *= num424; + num423 *= num424; + if (npc.velocity.X < num422) + { + npc.velocity.X += num420; + if (npc.velocity.X < 0f && num422 > 0f) + npc.velocity.X += num420; + } + else if (npc.velocity.X > num422) + { + npc.velocity.X -= num420; + if (npc.velocity.X > 0f && num422 < 0f) + npc.velocity.X -= num420; + } + + if (npc.velocity.Y < num423) + { + npc.velocity.Y += num420; + if (npc.velocity.Y < 0f && num423 > 0f) + npc.velocity.Y += num420; + } + else if (npc.velocity.Y > num423) + { + npc.velocity.Y -= num420; + if (npc.velocity.Y > 0f && num423 < 0f) + npc.velocity.Y -= num420; + } + } + + int num427 = 600; + int num428 = 60; + if (NPC.IsMechQueenUp) + { + num427 = 1200; + num428 = ((!NPC.npcsFoundForCheckActive[NPCID.TheDestroyerBody]) ? 90 : 120); + } + + if (Main.expertMode) + num428 = (int)(num428 * 0.8f); + + if (Main.masterMode) + num427 /= 2; + + npc.ai[2] += 1f; + if (npc.ai[2] >= (float)num427) + { + npc.ai[1] = 1f; + npc.ai[2] = 0f; + npc.ai[3] = 0f; + npc.target = Main.maxPlayers; + npc.netUpdate = true; + } + else if (npc.position.Y + (float)npc.height < Main.player[npc.target].position.Y && num425 < (Main.masterMode ? 720f : Main.expertMode ? 560f : 400f)) + { + if (!Main.player[npc.target].dead) + { + npc.ai[3] += 1f; + + if (Main.expertMode) + npc.ai[3] += MathHelper.Lerp(0f, Main.masterMode ? 2.5f : 1.5f, 1f - (npc.life / (float)npc.lifeMax - phase2LifeRatio) / (1f - phase2LifeRatio)); + + if (Main.getGoodWorld) + npc.ai[3] += 0.5f; + } + + if (npc.ai[3] >= (float)num428) + { + npc.ai[3] = 0f; + vector43 = npc.Center; + num422 = Main.player[npc.target].Center.X - vector43.X; + num423 = Main.player[npc.target].Center.Y - vector43.Y; + if (Main.netMode != NetmodeID.MultiplayerClient) + { + float num429 = 9f; + int attackDamage_ForProjectiles3 = npc.GetAttackDamage_ForProjectiles(20f, 19f); + int num430 = ProjectileID.EyeLaser; + if (Main.expertMode) + num429 = 10.5f; + + num424 = (float)Math.Sqrt(num422 * num422 + num423 * num423); + num424 = num429 / num424; + num422 *= num424; + num423 *= num424; + int inaccuracy = Main.masterMode ? 20 : Main.expertMode ? 30 : 40; + num422 += (float)Main.rand.Next(-inaccuracy, inaccuracy + 1) * 0.08f; + num423 += (float)Main.rand.Next(-inaccuracy, inaccuracy + 1) * 0.08f; + vector43.X += num422 * 15f; + vector43.Y += num423 * 15f; + Projectile.NewProjectile(npc.GetSource_FromAI(), vector43.X, vector43.Y, num422, num423, num430, attackDamage_ForProjectiles3, 0f, Main.myPlayer); + } + } + } + } + else if (npc.ai[1] == 1f) + { + // Set damage + npc.damage = npc.defDamage; + + npc.rotation = num414; + float num432 = 12f; + if (Main.expertMode) + num432 = Main.masterMode ? 18f : 15f; + + if (Main.getGoodWorld) + num432 += 2f; + + Vector2 vector44 = npc.Center; + float num433 = Main.player[npc.target].Center.X - vector44.X; + float num434 = Main.player[npc.target].Center.Y - vector44.Y; + float num435 = (float)Math.Sqrt(num433 * num433 + num434 * num434); + num435 = num432 / num435; + npc.velocity.X = num433 * num435; + npc.velocity.Y = num434 * num435; + npc.ai[1] = 2f; + } + else if (npc.ai[1] == 2f) + { + // Set damage + npc.damage = npc.defDamage; + + npc.ai[2] += 1f; + float decelerateGateValue = Main.masterMode ? 38f : Main.expertMode ? 32f : 25f; + if (npc.ai[2] >= decelerateGateValue) + { + // Avoid cheap bullshit + npc.damage = 0; + + float decelerationMultiplier = Main.masterMode ? 0.78f : Main.expertMode ? 0.92f : 0.96f; + npc.velocity *= decelerationMultiplier; + if ((double)npc.velocity.X > -0.1 && (double)npc.velocity.X < 0.1) + npc.velocity.X = 0f; + + if ((double)npc.velocity.Y > -0.1 && (double)npc.velocity.Y < 0.1) + npc.velocity.Y = 0f; + } + else + npc.rotation = (float)Math.Atan2(npc.velocity.Y, npc.velocity.X) - MathHelper.PiOver2; + + float delayBeforeChargingAgain = Main.masterMode ? 47f : Main.expertMode ? 56f : 70f; + if (npc.ai[2] >= delayBeforeChargingAgain) + { + npc.ai[3] += 1f; + npc.ai[2] = 0f; + npc.target = Main.maxPlayers; + npc.rotation = num414; + float numCharges = Main.masterMode ? 6f : Main.expertMode ? 5f : 4f; + if (npc.ai[3] >= numCharges) + { + npc.ai[1] = 0f; + npc.ai[3] = 0f; + } + else + npc.ai[1] = 1f; + } + } + + if (npc.life < npc.lifeMax * phase2LifeRatio) + { + npc.ai[0] = 1f; + npc.ai[1] = 0f; + npc.ai[2] = 0f; + npc.ai[3] = 0f; + npc.netUpdate = true; + } + + return false; + } + + if (npc.ai[0] == 1f || npc.ai[0] == 2f) + { + // Avoid cheap bullshit + npc.damage = 0; + + if (NPC.IsMechQueenUp) + npc.reflectsProjectiles = true; + + if (npc.ai[0] == 1f) + { + npc.ai[2] += 0.005f; + if ((double)npc.ai[2] > 0.5) + npc.ai[2] = 0.5f; + } + else + { + npc.ai[2] -= 0.005f; + if (npc.ai[2] < 0f) + npc.ai[2] = 0f; + } + + npc.rotation += npc.ai[2]; + + npc.ai[1] += 1f; + if (Main.masterMode) + { + if (npc.ai[1] % 10f == 0f) + { + if (Main.netMode != NetmodeID.MultiplayerClient) + { + int type = ProjectileID.EyeLaser; + int attackDamage_ForProjectiles = npc.GetAttackDamage_ForProjectiles(20f, 19f); + Vector2 projectileVelocity = Main.rand.NextVector2CircularEdge(10f, 10f); + int numProj = 3; + int spread = 8; + float rotation = MathHelper.ToRadians(spread); + for (int i = 0; i < numProj; i++) + { + Vector2 perturbedSpeed = projectileVelocity.RotatedBy(MathHelper.Lerp(-rotation, rotation, i / (float)(numProj - 1))); + Projectile.NewProjectile(npc.GetSource_FromAI(), npc.Center + Vector2.Normalize(perturbedSpeed) * 50f, perturbedSpeed, type, attackDamage_ForProjectiles, 0f, Main.myPlayer); + } + } + } + } + + if (npc.ai[1] >= 100f) + { + npc.ai[0] += 1f; + npc.ai[1] = 0f; + if (npc.ai[0] == 3f) + { + npc.ai[2] = 0f; + } + else + { + SoundEngine.PlaySound(SoundID.NPCHit1, npc.Center); + for (int num436 = 0; num436 < 2; num436++) + { + Gore.NewGore(npc.GetSource_FromAI(), npc.position, new Vector2((float)Main.rand.Next(-30, 31) * 0.2f, (float)Main.rand.Next(-30, 31) * 0.2f), 143); + Gore.NewGore(npc.GetSource_FromAI(), npc.position, new Vector2((float)Main.rand.Next(-30, 31) * 0.2f, (float)Main.rand.Next(-30, 31) * 0.2f), 7); + Gore.NewGore(npc.GetSource_FromAI(), npc.position, new Vector2((float)Main.rand.Next(-30, 31) * 0.2f, (float)Main.rand.Next(-30, 31) * 0.2f), 6); + } + + for (int num437 = 0; num437 < 20; num437++) + Dust.NewDust(npc.position, npc.width, npc.height, 5, (float)Main.rand.Next(-30, 31) * 0.2f, (float)Main.rand.Next(-30, 31) * 0.2f); + + SoundEngine.PlaySound(SoundID.ForceRoar, npc.Center); + } + } + + Dust.NewDust(npc.position, npc.width, npc.height, 5, (float)Main.rand.Next(-30, 31) * 0.2f, (float)Main.rand.Next(-30, 31) * 0.2f); + + npc.velocity *= 0.98f; + if ((double)npc.velocity.X > -0.1 && (double)npc.velocity.X < 0.1) + npc.velocity.X = 0f; + + if ((double)npc.velocity.Y > -0.1 && (double)npc.velocity.Y < 0.1) + npc.velocity.Y = 0f; + + return false; + } + + // Avoid cheap bullshit + npc.damage = 0; + + npc.defense = npc.defDefense + 10; + npc.HitSound = SoundID.NPCHit4; + + if (npc.ai[1] == 0f) + { + float num438 = 8f; + float num439 = 0.15f; + if (Main.expertMode) + { + num438 = Main.masterMode ? 11f : 9.5f; + num439 = Main.masterMode ? 0.2f : 0.175f; + } + + if (Main.getGoodWorld) + { + num438 *= 1.15f; + num439 *= 1.15f; + } + + Vector2 vector45 = npc.Center; + float num440 = Main.player[npc.target].Center.X - vector45.X; + float num441 = Main.player[npc.target].Center.Y - 300f - vector45.Y; + if (NPC.IsMechQueenUp) + { + num438 = 14f; + num440 = vector41.X; + num441 = vector41.Y; + num440 -= vector45.X; + num441 -= vector45.Y; + } + + float num442 = (float)Math.Sqrt(num440 * num440 + num441 * num441); + if (NPC.IsMechQueenUp) + { + if (num442 > num438) + { + num442 = num438 / num442; + num440 *= num442; + num441 *= num442; + } + + npc.velocity.X = (npc.velocity.X * 4f + num440) / 5f; + npc.velocity.Y = (npc.velocity.Y * 4f + num441) / 5f; + } + else + { + num442 = num438 / num442; + num440 *= num442; + num441 *= num442; + if (npc.velocity.X < num440) + { + npc.velocity.X += num439; + if (npc.velocity.X < 0f && num440 > 0f) + npc.velocity.X += num439; + } + else if (npc.velocity.X > num440) + { + npc.velocity.X -= num439; + if (npc.velocity.X > 0f && num440 < 0f) + npc.velocity.X -= num439; + } + + if (npc.velocity.Y < num441) + { + npc.velocity.Y += num439; + if (npc.velocity.Y < 0f && num441 > 0f) + npc.velocity.Y += num439; + } + else if (npc.velocity.Y > num441) + { + npc.velocity.Y -= num439; + if (npc.velocity.Y > 0f && num441 < 0f) + npc.velocity.Y -= num439; + } + } + + int num443 = 300; + if (NPC.IsMechQueenUp) + num443 = 1200; + + if (Main.masterMode) + num443 = (int)(num443 * 0.8f); + + npc.ai[2] += 1f; + if (npc.ai[2] >= (float)num443) + { + npc.ai[1] = 1f; + npc.ai[2] = 0f; + npc.ai[3] = 0f; + npc.TargetClosest(); + npc.netUpdate = true; + } + + vector45 = npc.Center; + num440 = Main.player[npc.target].Center.X - vector45.X; + num441 = Main.player[npc.target].Center.Y - vector45.Y; + npc.rotation = (float)Math.Atan2(num441, num440) - MathHelper.PiOver2; + if (Main.netMode == NetmodeID.MultiplayerClient) + return false; + + npc.localAI[1] += 1f; + + npc.localAI[1] += MathHelper.Lerp(0f, Main.masterMode ? 7f : Main.expertMode ? 6f : 5f, 1f - (npc.life / (float)npc.lifeMax) / phase2LifeRatio); + + if (npc.localAI[1] > 180f && Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) + { + npc.localAI[1] = 0f; + float num444 = 8.5f; + int attackDamage_ForProjectiles4 = npc.GetAttackDamage_ForProjectiles(25f, 23f); + int num445 = ProjectileID.DeathLaser; + if (Main.expertMode) + num444 = 10f; + + num442 = (float)Math.Sqrt(num440 * num440 + num441 * num441); + num442 = num444 / num442; + num440 *= num442; + num441 *= num442; + vector45.X += num440 * 15f; + vector45.Y += num441 * 15f; + int num446 = Projectile.NewProjectile(npc.GetSource_FromAI(), vector45.X, vector45.Y, num440, num441, num445, attackDamage_ForProjectiles4, 0f, Main.myPlayer); + } + + return false; + } + + int num447 = 1; + if (npc.Center.X < Main.player[npc.target].position.X + (float)Main.player[npc.target].width) + num447 = -1; + + float num448 = 8f; + float num449 = 0.2f; + if (Main.expertMode) + { + num448 = Main.masterMode ? 11f : 9.5f; + num449 = Main.masterMode ? 0.3f : 0.25f; + } + + if (Main.getGoodWorld) + { + num448 *= 1.15f; + num449 *= 1.15f; + } + + Vector2 vector46 = npc.Center; + float num450 = Main.player[npc.target].Center.X + (float)(num447 * 340) - vector46.X; + float num451 = Main.player[npc.target].Center.Y - vector46.Y; + float num452 = (float)Math.Sqrt(num450 * num450 + num451 * num451); + num452 = num448 / num452; + num450 *= num452; + num451 *= num452; + if (npc.velocity.X < num450) + { + npc.velocity.X += num449; + if (npc.velocity.X < 0f && num450 > 0f) + npc.velocity.X += num449; + } + else if (npc.velocity.X > num450) + { + npc.velocity.X -= num449; + if (npc.velocity.X > 0f && num450 < 0f) + npc.velocity.X -= num449; + } + + if (npc.velocity.Y < num451) + { + npc.velocity.Y += num449; + if (npc.velocity.Y < 0f && num451 > 0f) + npc.velocity.Y += num449; + } + else if (npc.velocity.Y > num451) + { + npc.velocity.Y -= num449; + if (npc.velocity.Y > 0f && num451 < 0f) + npc.velocity.Y -= num449; + } + + vector46 = npc.Center; + num450 = Main.player[npc.target].Center.X - vector46.X; + num451 = Main.player[npc.target].Center.Y - vector46.Y; + npc.rotation = (float)Math.Atan2(num451, num450) - MathHelper.PiOver2; + if (Main.netMode != NetmodeID.MultiplayerClient) + { + npc.localAI[1] += 1f; + + npc.localAI[1] += MathHelper.Lerp(0f, Main.masterMode ? 6f : Main.expertMode ? 5.25f : 3.75f, 1f - (npc.life / (float)npc.lifeMax) / phase2LifeRatio); + + if (npc.localAI[1] > 60f && Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) + { + npc.localAI[1] = 0f; + float num453 = 9f; + int attackDamage_ForProjectiles5 = npc.GetAttackDamage_ForProjectiles(18f, 17f); + int num454 = ProjectileID.DeathLaser; + num452 = (float)Math.Sqrt(num450 * num450 + num451 * num451); + num452 = num453 / num452; + num450 *= num452; + num451 *= num452; + vector46.X += num450 * 15f; + vector46.Y += num451 * 15f; + int num455 = Projectile.NewProjectile(npc.GetSource_FromAI(), vector46.X, vector46.Y, num450, num451, num454, attackDamage_ForProjectiles5, 0f, Main.myPlayer); + } + } + + npc.ai[2] += 1f; + float rapidLaserPhaseGateValue = Main.masterMode ? 120f : Main.expertMode ? 150f : 180f; + if (npc.ai[2] >= rapidLaserPhaseGateValue) + { + npc.ai[1] = 0f; + npc.ai[2] = 0f; + npc.ai[3] = 0f; + npc.TargetClosest(); + npc.netUpdate = true; + } + + return false; + } + + public static bool VanillaSpazmatismAI(NPC npc, Mod mod) + { + if (npc.target < 0 || npc.target == Main.maxPlayers || Main.player[npc.target].dead || !Main.player[npc.target].active) + npc.TargetClosest(); + + float phase2LifeRatio = Main.masterMode ? 0.6f : 0.4f; + + bool dead3 = Main.player[npc.target].dead; + float num456 = npc.Center.X - Main.player[npc.target].position.X - (float)(Main.player[npc.target].width / 2); + float num457 = npc.position.Y + (float)npc.height - 59f - Main.player[npc.target].position.Y - (float)(Main.player[npc.target].height / 2); + float num458 = (float)Math.Atan2(num457, num456) + MathHelper.PiOver2; + if (num458 < 0f) + num458 += MathHelper.TwoPi; + else if ((double)num458 > MathHelper.TwoPi) + num458 -= MathHelper.TwoPi; + + float num459 = 0.15f; + if (NPC.IsMechQueenUp && npc.ai[0] == 3f && npc.ai[1] == 0f) + num459 *= 0.25f; + + if (npc.rotation < num458) + { + if ((double)(num458 - npc.rotation) > MathHelper.Pi) + npc.rotation -= num459; + else + npc.rotation += num459; + } + else if (npc.rotation > num458) + { + if ((double)(npc.rotation - num458) > MathHelper.Pi) + npc.rotation += num459; + else + npc.rotation -= num459; + } + + if (npc.rotation > num458 - num459 && npc.rotation < num458 + num459) + npc.rotation = num458; + + if (npc.rotation < 0f) + npc.rotation += MathHelper.TwoPi; + else if ((double)npc.rotation > MathHelper.TwoPi) + npc.rotation -= MathHelper.TwoPi; + + if (npc.rotation > num458 - num459 && npc.rotation < num458 + num459) + npc.rotation = num458; + + if (Main.rand.NextBool(5)) + { + int num460 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y + (float)npc.height * 0.25f), npc.width, (int)((float)npc.height * 0.5f), 5, npc.velocity.X, 2f); + Main.dust[num460].velocity.X *= 0.5f; + Main.dust[num460].velocity.Y *= 0.1f; + } + + if (Main.netMode != NetmodeID.MultiplayerClient && !Main.IsItDay() && !dead3 && npc.timeLeft < 10) + { + for (int num461 = 0; num461 < Main.maxNPCs; num461++) + { + if (num461 != npc.whoAmI && Main.npc[num461].active && (Main.npc[num461].type == NPCID.Retinazer || Main.npc[num461].type == NPCID.Spazmatism)) + npc.DiscourageDespawn(Main.npc[num461].timeLeft - 1); + } + } + + Vector2 vector47 = Vector2.Zero; + if (NPC.IsMechQueenUp) + { + NPC nPC2 = Main.npc[NPC.mechQueen]; + Vector2 mechQueenCenter2 = nPC2.GetMechQueenCenter(); + Vector2 vector48 = new Vector2(150f, -250f); + vector48 *= 0.75f; + float num462 = nPC2.velocity.X * 0.025f; + vector47 = mechQueenCenter2 + vector48; + vector47 = vector47.RotatedBy(num462, mechQueenCenter2); + } + + npc.reflectsProjectiles = false; + if (Main.IsItDay() || dead3) + { + npc.velocity.Y -= 0.04f; + npc.EncourageDespawn(10); + return false; + } + + if (npc.ai[0] == 0f) + { + if (npc.ai[1] == 0f) + { + // Avoid cheap bullshit + npc.damage = 0; + + npc.TargetClosest(); + float num463 = 12f; + float num464 = 0.4f; + if (Main.expertMode) + { + num463 = Main.masterMode ? 13.2f : 12.6f; + num464 = Main.masterMode ? 0.48f : 0.44f; + } + + if (Main.getGoodWorld) + { + num463 *= 1.15f; + num464 *= 1.15f; + } + + int num465 = 1; + if (npc.Center.X < Main.player[npc.target].position.X + (float)Main.player[npc.target].width) + num465 = -1; + + Vector2 vector49 = npc.Center; + float num466 = Main.player[npc.target].Center.X + (float)(num465 * 400) - vector49.X; + float num467 = Main.player[npc.target].Center.Y - vector49.Y; + if (NPC.IsMechQueenUp) + { + num463 = 14f; + num466 = vector47.X; + num467 = vector47.Y; + num466 -= vector49.X; + num467 -= vector49.Y; + } + + float num468 = (float)Math.Sqrt(num466 * num466 + num467 * num467); + float num469 = num468; + if (NPC.IsMechQueenUp) + { + if (num468 > num463) + { + num468 = num463 / num468; + num466 *= num468; + num467 *= num468; + } + + npc.velocity.X = (npc.velocity.X * 4f + num466) / 5f; + npc.velocity.Y = (npc.velocity.Y * 4f + num467) / 5f; + } + else + { + num468 = num463 / num468; + num466 *= num468; + num467 *= num468; + if (npc.velocity.X < num466) + { + npc.velocity.X += num464; + if (npc.velocity.X < 0f && num466 > 0f) + npc.velocity.X += num464; + } + else if (npc.velocity.X > num466) + { + npc.velocity.X -= num464; + if (npc.velocity.X > 0f && num466 < 0f) + npc.velocity.X -= num464; + } + + if (npc.velocity.Y < num467) + { + npc.velocity.Y += num464; + if (npc.velocity.Y < 0f && num467 > 0f) + npc.velocity.Y += num464; + } + else if (npc.velocity.Y > num467) + { + npc.velocity.Y -= num464; + if (npc.velocity.Y > 0f && num467 < 0f) + npc.velocity.Y -= num464; + } + } + + int num470 = 600; + if (NPC.IsMechQueenUp) + num470 = 1200; + + if (Main.masterMode) + num470 = (int)(num470 * 0.75f); + + npc.ai[2] += 1f; + if (npc.ai[2] >= (float)num470) + { + npc.ai[1] = 1f; + npc.ai[2] = 0f; + npc.ai[3] = 0f; + npc.target = Main.maxPlayers; + npc.netUpdate = true; + } + else + { + if (!Main.player[npc.target].dead) + { + npc.ai[3] += 1f; + + if (Main.expertMode) + npc.ai[3] += MathHelper.Lerp(0f, Main.masterMode ? 1.8f : 1.2f, 1f - (npc.life / (float)npc.lifeMax - phase2LifeRatio) / (1f - phase2LifeRatio)); + + if (Main.getGoodWorld) + npc.ai[3] += 0.4f; + } + + if (npc.ai[3] >= 60f) + { + npc.ai[3] = 0f; + vector49 = npc.Center; + num466 = Main.player[npc.target].Center.X - vector49.X; + num467 = Main.player[npc.target].Center.Y - vector49.Y; + if (Main.netMode != NetmodeID.MultiplayerClient) + { + float num471 = 12f; + int attackDamage_ForProjectiles6 = npc.GetAttackDamage_ForProjectiles(25f, 22f); + int num472 = ProjectileID.CursedFlameHostile; + if (Main.expertMode) + num471 = 14f; + + num468 = (float)Math.Sqrt(num466 * num466 + num467 * num467); + num468 = num471 / num468; + num466 *= num468; + num467 *= num468; + int inaccuracy = Main.masterMode ? 20 : Main.expertMode ? 30 : 40; + num466 += (float)Main.rand.Next(-inaccuracy, inaccuracy + 1) * 0.05f; + num467 += (float)Main.rand.Next(-inaccuracy, inaccuracy + 1) * 0.05f; + vector49.X += num466 * 4f; + vector49.Y += num467 * 4f; + int num473 = Projectile.NewProjectile(npc.GetSource_FromAI(), vector49.X, vector49.Y, num466, num467, num472, attackDamage_ForProjectiles6, 0f, Main.myPlayer); + } + } + } + } + else if (npc.ai[1] == 1f) + { + // Set damage + npc.damage = npc.defDamage; + + npc.rotation = num458; + float num474 = 13f; + + if (Main.expertMode) + num474 += MathHelper.Lerp(0f, Main.masterMode ? 5.6f : 2.8f, 1f - (npc.life / (float)npc.lifeMax - phase2LifeRatio) / (1f - phase2LifeRatio)); + + if (Main.getGoodWorld) + num474 *= 1.2f; + + Vector2 vector50 = npc.Center; + float num475 = Main.player[npc.target].Center.X - vector50.X; + float num476 = Main.player[npc.target].Center.Y - vector50.Y; + float num477 = (float)Math.Sqrt(num475 * num475 + num476 * num476); + num477 = num474 / num477; + npc.velocity.X = num475 * num477; + npc.velocity.Y = num476 * num477; + npc.ai[1] = 2f; + } + else if (npc.ai[1] == 2f) + { + // Set damage + npc.damage = npc.defDamage; + + npc.ai[2] += 1f; + float decelerateGateValue = Main.masterMode ? 12f : Main.expertMode ? 10f : 8f; + if (npc.ai[2] >= decelerateGateValue) + { + // Avoid cheap bullshit + npc.damage = 0; + + float decelerationMultiplier = Main.masterMode ? 0.78f : Main.expertMode ? 0.85f : 0.9f; + npc.velocity *= decelerationMultiplier; + if ((double)npc.velocity.X > -0.1 && (double)npc.velocity.X < 0.1) + npc.velocity.X = 0f; + + if ((double)npc.velocity.Y > -0.1 && (double)npc.velocity.Y < 0.1) + npc.velocity.Y = 0f; + } + else + npc.rotation = (float)Math.Atan2(npc.velocity.Y, npc.velocity.X) - MathHelper.PiOver2; + + float delayBeforeChargingAgain = Main.masterMode ? 28f : Main.expertMode ? 34f : 42f; + if (npc.ai[2] >= delayBeforeChargingAgain) + { + npc.ai[3] += 1f; + npc.ai[2] = 0f; + npc.target = Main.maxPlayers; + npc.rotation = num458; + float numCharges = Main.masterMode ? 6f : Main.expertMode ? 8f : 10f; + if (npc.ai[3] >= numCharges) + { + npc.ai[1] = 0f; + npc.ai[3] = 0f; + } + else + npc.ai[1] = 1f; + } + } + + if (npc.life < npc.lifeMax * phase2LifeRatio) + { + npc.ai[0] = 1f; + npc.ai[1] = 0f; + npc.ai[2] = 0f; + npc.ai[3] = 0f; + npc.netUpdate = true; + } + + return false; + } + + if (npc.ai[0] == 1f || npc.ai[0] == 2f) + { + // Avoid cheap bullshit + npc.damage = 0; + + if (NPC.IsMechQueenUp) + npc.reflectsProjectiles = true; + + if (npc.ai[0] == 1f) + { + npc.ai[2] += 0.005f; + if ((double)npc.ai[2] > 0.5) + npc.ai[2] = 0.5f; + } + else + { + npc.ai[2] -= 0.005f; + if (npc.ai[2] < 0f) + npc.ai[2] = 0f; + } + + npc.rotation += npc.ai[2]; + + npc.ai[1] += 1f; + if (Main.masterMode) + { + if (npc.ai[1] % 10f == 0f) + { + if (Main.netMode != NetmodeID.MultiplayerClient) + { + int type = ProjectileID.CursedFlameHostile; + int attackDamage_ForProjectiles = npc.GetAttackDamage_ForProjectiles(25f, 22f); + Vector2 projectileVelocity = Main.rand.NextVector2CircularEdge(15f, 15f); + Projectile.NewProjectile(npc.GetSource_FromAI(), npc.Center + Vector2.Normalize(projectileVelocity) * 50f, projectileVelocity, type, attackDamage_ForProjectiles, 0f, Main.myPlayer); + } + } + } + + if (npc.ai[1] >= 100f) + { + npc.ai[0] += 1f; + npc.ai[1] = 0f; + if (npc.ai[0] == 3f) + { + npc.ai[2] = 0f; + } + else + { + SoundEngine.PlaySound(SoundID.NPCHit1, npc.Center); + for (int num478 = 0; num478 < 2; num478++) + { + Gore.NewGore(npc.GetSource_FromAI(), npc.position, new Vector2((float)Main.rand.Next(-30, 31) * 0.2f, (float)Main.rand.Next(-30, 31) * 0.2f), 144); + Gore.NewGore(npc.GetSource_FromAI(), npc.position, new Vector2((float)Main.rand.Next(-30, 31) * 0.2f, (float)Main.rand.Next(-30, 31) * 0.2f), 7); + Gore.NewGore(npc.GetSource_FromAI(), npc.position, new Vector2((float)Main.rand.Next(-30, 31) * 0.2f, (float)Main.rand.Next(-30, 31) * 0.2f), 6); + } + + for (int num479 = 0; num479 < 20; num479++) + Dust.NewDust(npc.position, npc.width, npc.height, 5, (float)Main.rand.Next(-30, 31) * 0.2f, (float)Main.rand.Next(-30, 31) * 0.2f); + + SoundEngine.PlaySound(SoundID.ForceRoar, npc.Center); + } + } + + Dust.NewDust(npc.position, npc.width, npc.height, 5, (float)Main.rand.Next(-30, 31) * 0.2f, (float)Main.rand.Next(-30, 31) * 0.2f); + + npc.velocity *= 0.98f; + if ((double)npc.velocity.X > -0.1 && (double)npc.velocity.X < 0.1) + npc.velocity.X = 0f; + + if ((double)npc.velocity.Y > -0.1 && (double)npc.velocity.Y < 0.1) + npc.velocity.Y = 0f; + + return false; + } + + npc.HitSound = SoundID.NPCHit4; + int setDamage = (int)(npc.defDamage * 1.5); + int reducedSetDamage = (int)(setDamage * 0.5f); + npc.defense = npc.defDefense + 18; + + if (npc.ai[1] == 0f) + { + // Bites your fucking ass + npc.damage = reducedSetDamage; + + float num480 = 4f; + float num481 = Main.masterMode ? 0.12f : 0.1f; + int num482 = 1; + if (npc.Center.X < Main.player[npc.target].position.X + (float)Main.player[npc.target].width) + num482 = -1; + + Vector2 vector51 = npc.Center; + int flamethrowerDistance = 180; + float num483 = Main.player[npc.target].Center.X + (float)(num482 * flamethrowerDistance) - vector51.X; + float num484 = Main.player[npc.target].Center.Y - vector51.Y; + float num485 = (float)Math.Sqrt(num483 * num483 + num484 * num484); + if (!NPC.IsMechQueenUp) + { + if (num485 > flamethrowerDistance) + num480 += MathHelper.Lerp(0f, Main.masterMode ? 5f : 3.3f, MathHelper.Clamp((num485 - flamethrowerDistance) / 800f, 0f, 1f)); + + if (Main.getGoodWorld) + { + num480 *= 1.15f; + num481 *= 1.15f; + } + + num485 = num480 / num485; + num483 *= num485; + num484 *= num485; + if (npc.velocity.X < num483) + { + npc.velocity.X += num481; + if (npc.velocity.X < 0f && num483 > 0f) + npc.velocity.X += num481; + } + else if (npc.velocity.X > num483) + { + npc.velocity.X -= num481; + if (npc.velocity.X > 0f && num483 < 0f) + npc.velocity.X -= num481; + } + + if (npc.velocity.Y < num484) + { + npc.velocity.Y += num481; + if (npc.velocity.Y < 0f && num484 > 0f) + npc.velocity.Y += num481; + } + else if (npc.velocity.Y > num484) + { + npc.velocity.Y -= num481; + if (npc.velocity.Y > 0f && num484 < 0f) + npc.velocity.Y -= num481; + } + } + + int num486 = 400; + if (NPC.IsMechQueenUp) + num486 = 1200; + + if (Main.masterMode) + num486 = (int)(num486 * 0.8f); + + npc.ai[2] += 1f; + if (npc.ai[2] >= (float)num486) + { + npc.ai[1] = 1f; + npc.ai[2] = 0f; + npc.ai[3] = 0f; + npc.target = Main.maxPlayers; + npc.netUpdate = true; + } + + if (Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) + { + npc.localAI[2] += 1f; + if (npc.localAI[2] > 22f) + { + npc.localAI[2] = 0f; + SoundEngine.PlaySound(SoundID.Item34, npc.Center); + } + + if (Main.netMode != NetmodeID.MultiplayerClient) + { + npc.localAI[1] += 1f; + + npc.localAI[1] += MathHelper.Lerp(0f, 5f, 1f - (npc.life / (float)npc.lifeMax) / phase2LifeRatio); + + if (npc.localAI[1] > 8f) + { + npc.localAI[1] = 0f; + float num487 = 6f + (Main.expertMode ? MathHelper.Lerp(0f, Main.masterMode ? 3f : 1.5f, 1f - (npc.life / (float)npc.lifeMax) / phase2LifeRatio) : 0f); + int attackDamage_ForProjectiles7 = npc.GetAttackDamage_ForProjectiles(30f, 27f); + int num488 = ProjectileID.EyeFire; + vector51 = npc.Center; + num483 = Main.player[npc.target].Center.X - vector51.X; + num484 = Main.player[npc.target].Center.Y - vector51.Y; + num485 = (float)Math.Sqrt(num483 * num483 + num484 * num484); + num485 = num487 / num485; + num483 *= num485; + num484 *= num485; + int inaccuracy = Main.masterMode ? 5 : Main.expertMode ? 20 : 40; + num484 += (float)Main.rand.Next(-inaccuracy, inaccuracy + 1) * 0.01f; + num483 += (float)Main.rand.Next(-inaccuracy, inaccuracy + 1) * 0.01f; + num484 += npc.velocity.Y * 0.5f; + num483 += npc.velocity.X * 0.5f; + vector51.X -= num483 * 1f; + vector51.Y -= num484 * 1f; + if (NPC.IsMechQueenUp) + { + Vector2 vector52 = (npc.rotation + (float)Math.PI / 2f).ToRotationVector2() * num487 + npc.velocity * 0.5f; + num483 = vector52.X; + num484 = vector52.Y; + vector51 = npc.Center - vector52 * 3f; + } + + int num489 = Projectile.NewProjectile(npc.GetSource_FromAI(), vector51.X, vector51.Y, num483, num484, num488, attackDamage_ForProjectiles7, 0f, Main.myPlayer); + } + } + } + + if (NPC.IsMechQueenUp) + { + num480 = 14f; + num483 = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2) - vector51.X; + num484 = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2) - 300f - vector51.Y; + num483 = vector47.X; + num484 = vector47.Y; + num483 -= vector51.X; + num484 -= vector51.Y; + num485 = (float)Math.Sqrt(num483 * num483 + num484 * num484); + if (num485 > num480) + { + num485 = num480 / num485; + num483 *= num485; + num484 *= num485; + } + + int num490 = 60; + npc.velocity.X = (npc.velocity.X * (float)(num490 - 1) + num483) / (float)num490; + npc.velocity.Y = (npc.velocity.Y * (float)(num490 - 1) + num484) / (float)num490; + } + } + else if (npc.ai[1] == 1f) + { + // Set damage + npc.damage = setDamage; + + SoundEngine.PlaySound(SoundID.ForceRoar, npc.Center); + npc.rotation = num458; + float num491 = 14f; + if (Main.expertMode) + num491 += 2.5f; + if (Main.masterMode) + num491 += 3.5f; + + Vector2 vector53 = npc.Center; + float num492 = Main.player[npc.target].Center.X - vector53.X; + float num493 = Main.player[npc.target].Center.Y - vector53.Y; + float num494 = (float)Math.Sqrt(num492 * num492 + num493 * num493); + num494 = num491 / num494; + npc.velocity.X = num492 * num494; + npc.velocity.Y = num493 * num494; + npc.ai[1] = 2f; + } + else + { + if (npc.ai[1] != 2f) + return false; + + // Set damage + npc.damage = setDamage; + + npc.ai[2] += 1f; + if (Main.expertMode) + npc.ai[2] += 0.5f; + if (Main.masterMode) + npc.ai[2] += 0.5f; + + if (npc.ai[2] >= 50f) + { + // Bites your fucking ass + npc.damage = reducedSetDamage; + + npc.velocity *= 0.93f; + if ((double)npc.velocity.X > -0.1 && (double)npc.velocity.X < 0.1) + npc.velocity.X = 0f; + + if ((double)npc.velocity.Y > -0.1 && (double)npc.velocity.Y < 0.1) + npc.velocity.Y = 0f; + } + else + npc.rotation = (float)Math.Atan2(npc.velocity.Y, npc.velocity.X) - MathHelper.PiOver2; + + if (npc.ai[2] >= 80f) + { + npc.ai[3] += 1f; + npc.ai[2] = 0f; + npc.target = Main.maxPlayers; + npc.rotation = num458; + float numCharges = Main.masterMode ? Main.rand.Next(4, 7) : 6f; + if (npc.ai[3] >= numCharges) + { + npc.ai[1] = 0f; + npc.ai[3] = 0f; + } + else + npc.ai[1] = 1f; + + // Due to the random number of charges in Master Mode + if (Main.masterMode) + npc.netUpdate = true; + } + } + + return false; + } } }