From 57f5e7ae68ce2c087f522faeb42e6d7033b010c8 Mon Sep 17 00:00:00 2001 From: CongratsIsTrash <1q2w3e4dasd@gmail.com> Date: Thu, 26 Oct 2023 21:57:33 -0400 Subject: [PATCH] Queen Slime, Skeletron, Skeletron Prime --- .../Bosses/QueenSlimeAI.cs | 162 +++---- .../VanillaNPCOverrides/Bosses/SkeletronAI.cs | 425 +++++++++--------- .../Bosses/SkeletronPrimeAI.cs | 378 ++++++++-------- 3 files changed, 480 insertions(+), 485 deletions(-) diff --git a/NPCs/VanillaNPCOverrides/Bosses/QueenSlimeAI.cs b/NPCs/VanillaNPCOverrides/Bosses/QueenSlimeAI.cs index c6ab749eeb..8dbf151dbc 100644 --- a/NPCs/VanillaNPCOverrides/Bosses/QueenSlimeAI.cs +++ b/NPCs/VanillaNPCOverrides/Bosses/QueenSlimeAI.cs @@ -21,8 +21,8 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses // Percent life remaining float lifeRatio = npc.life / (float)npc.lifeMax; - float num3 = 1f; - bool flag = false; + float slimeScale = 1f; + bool teleported = false; bool phase2 = lifeRatio <= 0.5f; bool phase3 = lifeRatio <= 0.4f; bool phase4 = lifeRatio <= 0.2f; @@ -71,34 +71,34 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.netUpdate = true; npc.TargetClosest(faceTarget: false); Vector2 vectorAimedAheadOfTarget = Main.player[npc.target].Center + new Vector2((float)Math.Round(Main.player[npc.target].velocity.X), 0f).SafeNormalize(Vector2.Zero) * 800f; - Point point2 = vectorAimedAheadOfTarget.ToTileCoordinates(); - int num5 = 5; - int num8 = 0; - while (num8 < 100) + Point predictiveTeleportPoint = vectorAimedAheadOfTarget.ToTileCoordinates(); + int randomTeleportOffset = 5; + int teleportTries = 0; + while (teleportTries < 100) { - num8++; - int num9 = Main.rand.Next(point2.X - num5, point2.X + num5 + 1); - int num10 = Main.rand.Next(point2.Y - num5, point2.Y); - if (Main.tile[num9, num10].HasUnactuatedTile) + teleportTries++; + int teleportTileX = Main.rand.Next(predictiveTeleportPoint.X - randomTeleportOffset, predictiveTeleportPoint.X + randomTeleportOffset + 1); + int teleportTileY = Main.rand.Next(predictiveTeleportPoint.Y - randomTeleportOffset, predictiveTeleportPoint.Y); + if (Main.tile[teleportTileX, teleportTileY].HasUnactuatedTile) continue; - bool flag4 = true; - if (flag4 && Main.tile[num9, num10].LiquidType == LiquidID.Lava) - flag4 = false; - if (flag4 && !Collision.CanHitLine(npc.Center, 0, 0, vectorAimedAheadOfTarget, 0, 0)) - flag4 = false; + bool canTeleportToTile = true; + if (canTeleportToTile && Main.tile[teleportTileX, teleportTileY].LiquidType == LiquidID.Lava) + canTeleportToTile = false; + if (canTeleportToTile && !Collision.CanHitLine(npc.Center, 0, 0, vectorAimedAheadOfTarget, 0, 0)) + canTeleportToTile = false; - if (flag4) + if (canTeleportToTile) { - npc.localAI[1] = num9 * 16 + 8; - npc.localAI[2] = num10 * 16 + 16; + npc.localAI[1] = teleportTileX * 16 + 8; + npc.localAI[2] = teleportTileY * 16 + 16; npc.ai[3] = 0f; break; } } // Default teleport if the above conditions aren't met in 100 iterations - if (num8 >= 100) + if (teleportTries >= 100) { Vector2 bottom = Main.player[Player.FindClosest(npc.position, npc.width, npc.height)].Bottom; npc.localAI[1] = bottom.X; @@ -121,11 +121,11 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses } else { - float num13 = npc.ai[3]; + float teleportNetUpdate = npc.ai[3]; npc.ai[3] -= 1f; if (npc.ai[3] < 0f) { - if (Main.netMode != NetmodeID.MultiplayerClient && num13 > 0f) + if (Main.netMode != NetmodeID.MultiplayerClient && teleportNetUpdate > 0f) npc.netUpdate = true; npc.ai[3] = 0f; @@ -254,8 +254,8 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.rotation = 0f; npc.ai[1] += 1f; float teleportEndTime = bossRush ? 10f : death ? 15f : 20f; - num3 = MathHelper.Clamp(npc.ai[1] / teleportEndTime, 0f, 1f); - num3 = 0.5f + num3 * 0.5f; + slimeScale = MathHelper.Clamp(npc.ai[1] / teleportEndTime, 0f, 1f); + slimeScale = 0.5f + slimeScale * 0.5f; if (npc.ai[1] >= teleportEndTime && Main.netMode != NetmodeID.MultiplayerClient) { npc.ai[0] = 0f; @@ -274,11 +274,11 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses // Emit teleport dust Color newColor2 = NPC.AI_121_QueenSlime_GetDustColor(); newColor2.A = 150; - for (int num26 = 0; num26 < 10; num26++) + for (int i = 0; i < 10; i++) { - int num27 = Dust.NewDust(npc.position + Vector2.UnitX * -20f, npc.width + 40, npc.height, 4, npc.velocity.X, npc.velocity.Y, 50, newColor2, 1.5f); - Main.dust[num27].noGravity = true; - Main.dust[num27].velocity *= 2f; + int queenSlimeDust = Dust.NewDust(npc.position + Vector2.UnitX * -20f, npc.width + 40, npc.height, 4, npc.velocity.X, npc.velocity.Y, 50, newColor2, 1.5f); + Main.dust[queenSlimeDust].noGravity = true; + Main.dust[queenSlimeDust].velocity *= 2f; } break; @@ -292,11 +292,11 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.rotation = 0f; npc.ai[1] += 1f; float teleportTime = bossRush ? 20f : death ? 30f : 40f; - num3 = MathHelper.Clamp((teleportTime - npc.ai[1]) / teleportTime, 0f, 1f); - num3 = 0.5f + num3 * 0.5f; + slimeScale = MathHelper.Clamp((teleportTime - npc.ai[1]) / teleportTime, 0f, 1f); + slimeScale = 0.5f + slimeScale * 0.5f; if (npc.ai[1] >= teleportTime) - flag = true; + teleported = true; // Spawn crown gore if (npc.ai[1] == teleportTime) @@ -317,15 +317,15 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses } // Emit teleport dust - if (!flag) + if (!teleported) { Color newColor = NPC.AI_121_QueenSlime_GetDustColor(); newColor.A = 150; for (int n = 0; n < 10; n++) { - int num25 = Dust.NewDust(npc.position + Vector2.UnitX * -20f, npc.width + 40, npc.height, 4, npc.velocity.X, npc.velocity.Y, 50, newColor, 1.5f); - Main.dust[num25].noGravity = true; - Main.dust[num25].velocity *= 0.5f; + int queenSlimeDust2 = Dust.NewDust(npc.position + Vector2.UnitX * -20f, npc.width + 40, npc.height, 4, npc.velocity.X, npc.velocity.Y, 50, newColor, 1.5f); + Main.dust[queenSlimeDust2].noGravity = true; + Main.dust[queenSlimeDust2].velocity *= 0.5f; } } @@ -402,11 +402,11 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses if (npc.target >= Main.maxPlayers) break; - float num19 = bossRush ? 6.5f : death ? 5.5f : 4.5f; + float jumpVelocity = bossRush ? 6.5f : death ? 5.5f : 4.5f; if (Main.getGoodWorld) - num19 = 7f; + jumpVelocity = 7f; - if ((npc.direction == 1 && npc.velocity.X < num19) || (npc.direction == -1 && npc.velocity.X > 0f - num19)) + if ((npc.direction == 1 && npc.velocity.X < jumpVelocity) || (npc.direction == -1 && npc.velocity.X > 0f - jumpVelocity)) { if ((npc.direction == -1 && npc.velocity.X < 0.1) || (npc.direction == 1 && npc.velocity.X > -0.1)) npc.velocity.X += (bossRush ? 0.5f : death ? 0.35f : 0.3f) * npc.direction; @@ -442,12 +442,12 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.noTileCollide = false; npc.noGravity = false; - int num20 = 30; + int slamDelay = 30; if (phase2) - num20 = 10; + slamDelay = 10; if (Main.getGoodWorld) - num20 = 0; + slamDelay = 0; if (npc.velocity.Y == 0f) { @@ -479,10 +479,10 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses for (int l = 0; l < 20; l++) { - int num21 = Dust.NewDust(npc.Bottom - new Vector2(npc.width / 2, 30f), npc.width, 30, 31, npc.velocity.X, npc.velocity.Y, 40, NPC.AI_121_QueenSlime_GetDustColor()); - Main.dust[num21].noGravity = true; - Main.dust[num21].velocity.Y = -5f + Main.rand.NextFloat() * -3f; - Main.dust[num21].velocity.X *= 7f; + int slamDust = Dust.NewDust(npc.Bottom - new Vector2(npc.width / 2, 30f), npc.width, 30, 31, npc.velocity.X, npc.velocity.Y, 40, NPC.AI_121_QueenSlime_GetDustColor()); + Main.dust[slamDust].noGravity = true; + Main.dust[slamDust].velocity.Y = -5f + Main.rand.NextFloat() * -3f; + Main.dust[slamDust].velocity.X *= 7f; } npc.Calamity().newAI[0] = npc.ai[0]; @@ -492,28 +492,28 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.ai[2] = 0f; npc.netUpdate = true; } - else if (npc.ai[1] >= num20) + else if (npc.ai[1] >= slamDelay) { for (int m = 0; m < 4; m++) { Vector2 position = npc.Bottom - new Vector2(Main.rand.NextFloatDirection() * 16f, Main.rand.Next(8)); - int num22 = Dust.NewDust(position, 2, 2, 31, npc.velocity.X, npc.velocity.Y, 40, NPC.AI_121_QueenSlime_GetDustColor(), 1.4f); - Main.dust[num22].position = position; - Main.dust[num22].noGravity = true; - Main.dust[num22].velocity.Y = npc.velocity.Y * 0.9f; - Main.dust[num22].velocity.X = (Main.rand.NextBool() ? (-10f) : 10f) + Main.rand.NextFloatDirection() * 3f; + int slamDust2 = Dust.NewDust(position, 2, 2, 31, npc.velocity.X, npc.velocity.Y, 40, NPC.AI_121_QueenSlime_GetDustColor(), 1.4f); + Main.dust[slamDust2].position = position; + Main.dust[slamDust2].noGravity = true; + Main.dust[slamDust2].velocity.Y = npc.velocity.Y * 0.9f; + Main.dust[slamDust2].velocity.X = (Main.rand.NextBool() ? (-10f) : 10f) + Main.rand.NextFloatDirection() * 3f; } } npc.velocity.X *= 0.8f; - float num23 = npc.ai[1]; + float slamNetUpdate = npc.ai[1]; npc.ai[1] += 1f; - if (npc.ai[1] >= num20) + if (npc.ai[1] >= slamDelay) { - if (num23 < num20) + if (slamNetUpdate < slamDelay) npc.netUpdate = true; - if (phase2 && npc.ai[1] > (num20 + 120)) + if (phase2 && npc.ai[1] > (slamDelay + 120)) { npc.Calamity().newAI[0] = npc.ai[0]; npc.SyncExtraAI(); @@ -526,18 +526,18 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses } npc.velocity.Y += bossRush ? 2f : death ? 1.75f : 1.5f; - float num24 = bossRush ? 15.99f : death ? 15.5f : 15f; + float slamVelocity = bossRush ? 15.99f : death ? 15.5f : 15f; if (Main.getGoodWorld) { npc.velocity.Y += 1f; - num24 = 15.99f; + slamVelocity = 15.99f; } if (npc.velocity.Y == 0f) npc.velocity.Y = 0.01f; - if (npc.velocity.Y >= num24) - npc.velocity.Y = num24; + if (npc.velocity.Y >= slamVelocity) + npc.velocity.Y = slamVelocity; // Cascade of crystals in phase 3 or 4 while falling down if (((npc.ai[0] == 4f && phase3) || phase4) && npc.ai[1] % 12f == 0f) @@ -709,21 +709,21 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses } } - float num16 = 100f; + float slamDustRadius = 100f; for (int k = 0; k < 4; k++) { - Vector2 vector2 = npc.Center + Main.rand.NextVector2CircularEdge(num16, num16); + Vector2 slamDustArea = npc.Center + Main.rand.NextVector2CircularEdge(slamDustRadius, slamDustRadius); if (!phase2) - vector2 += new Vector2(0f, 20f); + slamDustArea += new Vector2(0f, 20f); - Vector2 v = vector2 - npc.Center; + Vector2 v = slamDustArea - npc.Center; v = v.SafeNormalize(Vector2.Zero) * -8f; - int num17 = Dust.NewDust(vector2, 2, 2, 31, v.X, v.Y, 40, NPC.AI_121_QueenSlime_GetDustColor(), 1.8f); - Main.dust[num17].position = vector2; - Main.dust[num17].noGravity = true; - Main.dust[num17].alpha = 250; - Main.dust[num17].velocity = v; - Main.dust[num17].customData = npc; + int superSlamDust = Dust.NewDust(slamDustArea, 2, 2, 31, v.X, v.Y, 40, NPC.AI_121_QueenSlime_GetDustColor(), 1.8f); + Main.dust[superSlamDust].position = slamDustArea; + Main.dust[superSlamDust].noGravity = true; + Main.dust[superSlamDust].alpha = 250; + Main.dust[superSlamDust].velocity = v; + Main.dust[superSlamDust].customData = npc; } if (phase2) @@ -733,14 +733,14 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses } // Don't take damage while teleporting - npc.dontTakeDamage = npc.hide = flag; + npc.dontTakeDamage = npc.hide = teleported; // Adjust size with HP - if (num3 != npc.scale) + if (slimeScale != npc.scale) { npc.position.X += npc.width / 2; npc.position.Y += npc.height; - npc.scale = num3; + npc.scale = slimeScale; npc.width = (int)(114f * npc.scale); npc.height = (int)(100f * npc.scale); npc.position.X -= npc.width / 2; @@ -765,8 +765,8 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.netUpdate = true; } - int num28 = (int)(npc.lifeMax * (CalamityWorld.LegendaryMode ? 0.01f : phase3 ? 0.04f : phase2 ? 0.03f : 0.025f)); - if (!((npc.life + num28) < npc.localAI[0])) + int slimeSpawnThreshold = (int)(npc.lifeMax * (CalamityWorld.LegendaryMode ? 0.01f : phase3 ? 0.04f : phase2 ? 0.03f : 0.025f)); + if (!((npc.life + slimeSpawnThreshold) < npc.localAI[0])) return false; npc.localAI[0] = npc.life; @@ -793,14 +793,14 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses break; } - int num32 = NPC.NewNPC(npc.GetSource_FromAI(), x, y, typeToSpawn); - Main.npc[num32].SetDefaults(typeToSpawn); - Main.npc[num32].velocity.X = Main.rand.Next(-15, 16) * 0.1f; - Main.npc[num32].velocity.Y = Main.rand.Next(-30, 1) * 0.1f; - Main.npc[num32].ai[0] = -500 * Main.rand.Next(3); - Main.npc[num32].ai[1] = 0f; - if (Main.netMode == NetmodeID.Server && num32 < Main.maxNPCs) - NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, num32); + int slimeScale2 = NPC.NewNPC(npc.GetSource_FromAI(), x, y, typeToSpawn); + Main.npc[slimeScale2].SetDefaults(typeToSpawn); + Main.npc[slimeScale2].velocity.X = Main.rand.Next(-15, 16) * 0.1f; + Main.npc[slimeScale2].velocity.Y = Main.rand.Next(-30, 1) * 0.1f; + Main.npc[slimeScale2].ai[0] = -500 * Main.rand.Next(3); + Main.npc[slimeScale2].ai[1] = 0f; + if (Main.netMode == NetmodeID.Server && slimeScale2 < Main.maxNPCs) + NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, slimeScale2); return false; } diff --git a/NPCs/VanillaNPCOverrides/Bosses/SkeletronAI.cs b/NPCs/VanillaNPCOverrides/Bosses/SkeletronAI.cs index 271967206e..8cfb3b2349 100644 --- a/NPCs/VanillaNPCOverrides/Bosses/SkeletronAI.cs +++ b/NPCs/VanillaNPCOverrides/Bosses/SkeletronAI.cs @@ -61,37 +61,37 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses void SpawnHands() { - int num155 = NPC.NewNPC(npc.GetSource_FromAI(), (int)(npc.position.X + (npc.width / 2)), (int)npc.position.Y + npc.height / 2, NPCID.SkeletronHand, npc.whoAmI); - Main.npc[num155].ai[0] = -1f; - Main.npc[num155].ai[1] = npc.whoAmI; - Main.npc[num155].target = npc.target; - Main.npc[num155].netUpdate = true; + int skeletronHand = NPC.NewNPC(npc.GetSource_FromAI(), (int)(npc.position.X + (npc.width / 2)), (int)npc.position.Y + npc.height / 2, NPCID.SkeletronHand, npc.whoAmI); + Main.npc[skeletronHand].ai[0] = -1f; + Main.npc[skeletronHand].ai[1] = npc.whoAmI; + Main.npc[skeletronHand].target = npc.target; + Main.npc[skeletronHand].netUpdate = true; - num155 = NPC.NewNPC(npc.GetSource_FromAI(), (int)(npc.position.X + (npc.width / 2)), (int)npc.position.Y + npc.height / 2, NPCID.SkeletronHand, npc.whoAmI); - Main.npc[num155].ai[0] = 1f; - Main.npc[num155].ai[1] = npc.whoAmI; - Main.npc[num155].ai[3] = 150f; - Main.npc[num155].target = npc.target; - Main.npc[num155].netUpdate = true; + skeletronHand = NPC.NewNPC(npc.GetSource_FromAI(), (int)(npc.position.X + (npc.width / 2)), (int)npc.position.Y + npc.height / 2, NPCID.SkeletronHand, npc.whoAmI); + Main.npc[skeletronHand].ai[0] = 1f; + Main.npc[skeletronHand].ai[1] = npc.whoAmI; + Main.npc[skeletronHand].ai[3] = 150f; + Main.npc[skeletronHand].target = npc.target; + Main.npc[skeletronHand].netUpdate = true; // Spawn two additional hands with different attack timings if (death) { - num155 = NPC.NewNPC(npc.GetSource_FromAI(), (int)(npc.position.X + (npc.width / 2)), (int)npc.position.Y + npc.height / 2, NPCID.SkeletronHand, npc.whoAmI); - Main.npc[num155].ai[0] = -1f; - Main.npc[num155].Calamity().newAI[0] = -1f; - Main.npc[num155].ai[1] = npc.whoAmI; - Main.npc[num155].ai[3] = respawnHands ? -75f : 0f; - Main.npc[num155].target = npc.target; - Main.npc[num155].netUpdate = true; + skeletronHand = NPC.NewNPC(npc.GetSource_FromAI(), (int)(npc.position.X + (npc.width / 2)), (int)npc.position.Y + npc.height / 2, NPCID.SkeletronHand, npc.whoAmI); + Main.npc[skeletronHand].ai[0] = -1f; + Main.npc[skeletronHand].Calamity().newAI[0] = -1f; + Main.npc[skeletronHand].ai[1] = npc.whoAmI; + Main.npc[skeletronHand].ai[3] = respawnHands ? -75f : 0f; + Main.npc[skeletronHand].target = npc.target; + Main.npc[skeletronHand].netUpdate = true; - num155 = NPC.NewNPC(npc.GetSource_FromAI(), (int)(npc.position.X + (npc.width / 2)), (int)npc.position.Y + npc.height / 2, NPCID.SkeletronHand, npc.whoAmI); - Main.npc[num155].ai[0] = 1f; - Main.npc[num155].Calamity().newAI[0] = -1f; - Main.npc[num155].ai[1] = npc.whoAmI; - Main.npc[num155].ai[3] = respawnHands ? 75f : 150f; - Main.npc[num155].target = npc.target; - Main.npc[num155].netUpdate = true; + skeletronHand = NPC.NewNPC(npc.GetSource_FromAI(), (int)(npc.position.X + (npc.width / 2)), (int)npc.position.Y + npc.height / 2, NPCID.SkeletronHand, npc.whoAmI); + Main.npc[skeletronHand].ai[0] = 1f; + Main.npc[skeletronHand].Calamity().newAI[0] = -1f; + Main.npc[skeletronHand].ai[1] = npc.whoAmI; + Main.npc[skeletronHand].ai[3] = respawnHands ? 75f : 150f; + Main.npc[skeletronHand].target = npc.target; + Main.npc[skeletronHand].netUpdate = true; } } } @@ -115,17 +115,17 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses } // Hand immunity - int num156 = 0; - for (int num157 = 0; num157 < Main.maxNPCs; num157++) + int numHandsAlive = 0; + for (int i = 0; i < Main.maxNPCs; i++) { - if (Main.npc[num157].active && Main.npc[num157].type == NPCID.SkeletronHand) - num156++; + if (Main.npc[i].active && Main.npc[i].type == NPCID.SkeletronHand) + numHandsAlive++; } - bool handsDead = num156 == 0; + bool handsDead = numHandsAlive == 0; npc.chaseable = handsDead; - calamityGlobalNPC.DR = num156 > 0 ? 0.9999f : 0.05f; - calamityGlobalNPC.unbreakableDR = num156 > 0; - calamityGlobalNPC.CurrentlyIncreasingDefenseOrDR = num156 > 0; + calamityGlobalNPC.DR = numHandsAlive > 0 ? 0.9999f : 0.05f; + calamityGlobalNPC.unbreakableDR = numHandsAlive > 0; + calamityGlobalNPC.CurrentlyIncreasingDefenseOrDR = numHandsAlive > 0; // Teleport if (handsDead || phase2) @@ -140,28 +140,28 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses // Fire magic bolt after teleport if (Main.netMode != NetmodeID.MultiplayerClient) { - float num151 = 2f + (distance * 0.005f); - if (num151 > 6f) - num151 = 6f; + float magicBoltSpeed = 2f + (distance * 0.005f); + if (magicBoltSpeed > 6f) + magicBoltSpeed = 6f; int type = ProjectileID.Skull; int damage = npc.GetProjectileDamage(type); int numProj = Main.getGoodWorld ? 22 : death ? 5 : 3; - float num743 = Main.player[npc.target].Center.X - npc.Center.X; - float num744 = Main.player[npc.target].Center.Y - npc.Center.Y; - float num745 = (float)Math.Sqrt(num743 * num743 + num744 * num744); + float boltTargetXDist = Main.player[npc.target].Center.X - npc.Center.X; + float boltTargetYDist = Main.player[npc.target].Center.Y - npc.Center.Y; + float boltTargetDistance = (float)Math.Sqrt(boltTargetXDist * boltTargetXDist + boltTargetYDist * boltTargetYDist); - num745 = num151 / num745; - num743 *= num745; - num744 *= num745; + boltTargetDistance = magicBoltSpeed / boltTargetDistance; + boltTargetXDist *= boltTargetDistance; + boltTargetYDist *= boltTargetDistance; Vector2 center = npc.Center; - center.X += num743 * 5f; - center.Y += num744 * 5f; + center.X += boltTargetXDist * 5f; + center.Y += boltTargetYDist * 5f; float rotation = MathHelper.ToRadians(Main.getGoodWorld ? 180 : 60); - float baseSpeed = (float)Math.Sqrt(num743 * num743 + num744 * num744); - double startAngle = Math.Atan2(num743, num744) - rotation / 2; + float baseSpeed = (float)Math.Sqrt(boltTargetXDist * boltTargetXDist + boltTargetYDist * boltTargetYDist); + double startAngle = Math.Atan2(boltTargetXDist, boltTargetYDist) - rotation / 2; double deltaAngle = rotation / numProj; double offsetAngle; @@ -178,9 +178,9 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses // Teleport dust for (int m = 0; m < 30; m++) { - int num39 = Dust.NewDust(npc.position, npc.width, npc.height, 27, 0f, 0f, 200, default, 3f); - Main.dust[num39].noGravity = true; - Main.dust[num39].velocity.X = Main.dust[num39].velocity.X * 2f; + int teleportDust = Dust.NewDust(npc.position, npc.width, npc.height, 27, 0f, 0f, 200, default, 3f); + Main.dust[teleportDust].noGravity = true; + Main.dust[teleportDust].velocity.X = Main.dust[teleportDust].velocity.X * 2f; } } @@ -198,29 +198,29 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses { if (Main.netMode != NetmodeID.MultiplayerClient) { - Vector2 value53 = npc.Center + new Vector2(npc.direction * 20, 6f); - Vector2 vector251 = Main.player[npc.target].Center - value53; - Point point12 = npc.Center.ToTileCoordinates(); - Point point13 = Main.player[npc.target].Center.ToTileCoordinates(); - int num1453 = 26; - int num1454 = 4; - int num1455 = 22; - int num1457 = 0; + Vector2 skullFaceDirection = npc.Center + new Vector2(npc.direction * 20, 6f); + Vector2 skullTargetDirection = Main.player[npc.target].Center - skullFaceDirection; + Point skullTileCoords = npc.Center.ToTileCoordinates(); + Point targetTileCoords = Main.player[npc.target].Center.ToTileCoordinates(); + int randomTeleportOffset = 26; + int skullPositionOffset = 4; + int targetPositionOffset = 22; + int teleportTries = 0; - bool flag106 = false; - if (vector251.Length() > 2000f) - flag106 = true; + bool targetTooFar = false; + if (skullTargetDirection.Length() > 2000f) + targetTooFar = true; - while (!flag106 && num1457 < 100) + while (!targetTooFar && teleportTries < 100) { - num1457++; - int num1458 = Main.rand.Next(point13.X - num1453, point13.X + num1453 + 1); - int num1459 = Main.rand.Next(point13.Y - num1453, point13.Y + num1453 + 1); - if ((num1459 < point13.Y - num1455 || num1459 > point13.Y + num1455 || num1458 < point13.X - num1455 || num1458 > point13.X + num1455) && (num1459 < point12.Y - num1454 || num1459 > point12.Y + num1454 || num1458 < point12.X - num1454 || num1458 > point12.X + num1454) && !Main.tile[num1458, num1459].HasUnactuatedTile) + teleportTries++; + int teleportTileX = Main.rand.Next(targetTileCoords.X - randomTeleportOffset, targetTileCoords.X + randomTeleportOffset + 1); + int teleportTileY = Main.rand.Next(targetTileCoords.Y - randomTeleportOffset, targetTileCoords.Y + randomTeleportOffset + 1); + if ((teleportTileY < targetTileCoords.Y - targetPositionOffset || teleportTileY > targetTileCoords.Y + targetPositionOffset || teleportTileX < targetTileCoords.X - targetPositionOffset || teleportTileX > targetTileCoords.X + targetPositionOffset) && (teleportTileY < skullTileCoords.Y - skullPositionOffset || teleportTileY > skullTileCoords.Y + skullPositionOffset || teleportTileX < skullTileCoords.X - skullPositionOffset || teleportTileX > skullTileCoords.X + skullPositionOffset) && !Main.tile[teleportTileX, teleportTileY].HasUnactuatedTile) { // New location params - calamityGlobalNPC.newAI[2] = num1458 * 16 - npc.width / 2; - calamityGlobalNPC.newAI[3] = num1459 * 16 - npc.height; + calamityGlobalNPC.newAI[2] = teleportTileX * 16 - npc.width / 2; + calamityGlobalNPC.newAI[3] = teleportTileY * 16 - npc.height; npc.SyncExtraAI(); break; } @@ -233,8 +233,8 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses for (int m = 0; m < 5; m++) { Vector2 position = new Vector2(calamityGlobalNPC.newAI[2], calamityGlobalNPC.newAI[3]); - int num39 = Dust.NewDust(position, npc.width, npc.height, 27, 0f, 0f, 200, default, 2f); - Main.dust[num39].noGravity = true; + int teleportDust = Dust.NewDust(position, npc.width, npc.height, 27, 0f, 0f, 200, default, 2f); + Main.dust[teleportDust].noGravity = true; } } @@ -257,9 +257,9 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses // Teleport dust for (int m = 0; m < 30; m++) { - int num39 = Dust.NewDust(npc.position, npc.width, npc.height, 27, 0f, 0f, 200, default, 3f); - Main.dust[num39].noGravity = true; - Main.dust[num39].velocity.X = Main.dust[num39].velocity.X * 2f; + int teleportDust = Dust.NewDust(npc.position, npc.width, npc.height, 27, 0f, 0f, 200, default, 3f); + Main.dust[teleportDust].noGravity = true; + Main.dust[teleportDust].velocity.X = Main.dust[teleportDust].velocity.X * 2f; } // New location @@ -278,38 +278,38 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses // Skull shooting if (handsDead && npc.ai[1] == 0f) { - float num158 = bossRush ? 10f : phase2 ? (60f - (death ? 30f * (1f - lifeRatio) : 0f)) : 75f; + float skullProjFrequency = bossRush ? 10f : phase2 ? (60f - (death ? 30f * (1f - lifeRatio) : 0f)) : 75f; if (Main.getGoodWorld) - num158 *= 0.8f; - num158 = (float)Math.Ceiling(num158); + skullProjFrequency *= 0.8f; + skullProjFrequency = (float)Math.Ceiling(skullProjFrequency); - if (Main.netMode != NetmodeID.MultiplayerClient && calamityGlobalNPC.newAI[1] % num158 == 0f && calamityGlobalNPC.newAI[1] > 45f) + if (Main.netMode != NetmodeID.MultiplayerClient && calamityGlobalNPC.newAI[1] % skullProjFrequency == 0f && calamityGlobalNPC.newAI[1] > 45f) { - Vector2 vector18 = npc.Center; - float num159 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - vector18.X; - float num160 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - vector18.Y; - float num161 = (float)Math.Sqrt(num159 * num159 + num160 * num160); - if (Collision.CanHit(vector18, 1, 1, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) + Vector2 skullFiringPos = npc.Center; + float skullProjTargetX = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - skullFiringPos.X; + float skullProjTargetY = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - skullFiringPos.Y; + float skullProjTargetDist = (float)Math.Sqrt(skullProjTargetX * skullProjTargetX + skullProjTargetY * skullProjTargetY); + if (Collision.CanHit(skullFiringPos, 1, 1, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) { - float num162 = phase2 ? (5f + (death ? 3f * (1f - lifeRatio) : 0f)) : 4f; - float num163 = Main.player[npc.target].position.X + Main.player[npc.target].width * 0.5f - vector18.X; - float num164 = Main.player[npc.target].position.Y + Main.player[npc.target].height * 0.5f - vector18.Y; - float num165 = (float)Math.Sqrt(num163 * num163 + num164 * num164); - num165 = num162 / num165; - num163 *= num165; - num164 *= num165; + float skullProjSpeed = phase2 ? (5f + (death ? 3f * (1f - lifeRatio) : 0f)) : 4f; + float skullProjTargetX = Main.player[npc.target].position.X + Main.player[npc.target].width * 0.5f - skullFiringPos.X; + float skullProjTargetY = Main.player[npc.target].position.Y + Main.player[npc.target].height * 0.5f - skullFiringPos.Y; + float skullProjTargetDist = (float)Math.Sqrt(skullProjTargetX * skullProjTargetX + skullProjTargetY * skullProjTargetY); + skullProjTargetDist = skullProjSpeed / skullProjTargetDist; + skullProjTargetX *= skullProjTargetDist; + skullProjTargetY *= skullProjTargetDist; int spread = bossRush ? 100 : 50; - Vector2 vector19 = new Vector2(num163 + Main.rand.Next(-spread, spread + 1) * 0.01f, num164 + Main.rand.Next(-spread, spread + 1) * 0.01f); - vector19.Normalize(); - vector19 *= num162; - vector19 += npc.velocity; - num163 = vector19.X; - num164 = vector19.Y; + Vector2 skullProjDirection = new Vector2(skullProjTargetX + Main.rand.Next(-spread, spread + 1) * 0.01f, skullProjTargetY + Main.rand.Next(-spread, spread + 1) * 0.01f); + skullProjDirection.Normalize(); + skullProjDirection *= skullProjSpeed; + skullProjDirection += npc.velocity; + skullProjTargetX = skullProjDirection.X; + skullProjTargetY = skullProjDirection.Y; int type = ProjectileID.Skull; int damage = npc.GetProjectileDamage(type); - vector18 += vector19 * 5f; - int num168 = Projectile.NewProjectile(npc.GetSource_FromAI(), vector18.X, vector18.Y, num163, num164, type, damage, 0f, Main.myPlayer, -1f, 0f); - Main.projectile[num168].timeLeft = 300; + skullFiringPos += skullProjDirection * 5f; + int skullProjectile = Projectile.NewProjectile(npc.GetSource_FromAI(), skullFiringPos.X, skullFiringPos.Y, skullProjTargetX, skullProjTargetY, type, damage, 0f, Main.myPlayer, -1f, 0f); + Main.projectile[skullProjectile].timeLeft = 300; npc.netUpdate = true; } @@ -337,58 +337,58 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.rotation = npc.velocity.X / 15f; - float num169 = 0.04f + (death ? 0.04f * (1f - lifeRatio) : 0f); - float num170 = 3.5f - (death ? 1f - lifeRatio : 0f); - float num171 = 0.08f + (death ? 0.04f * (1f - lifeRatio) : 0f); - float num172 = 8.5f - (death ? 2f * (1f - lifeRatio) : 0f); + float headYAcceleration = 0.04f + (death ? 0.04f * (1f - lifeRatio) : 0f); + float headYTopSpeed = 3.5f - (death ? 1f - lifeRatio : 0f); + float headXAcceleration = 0.08f + (death ? 0.04f * (1f - lifeRatio) : 0f); + float headXTopSpeed = 8.5f - (death ? 2f * (1f - lifeRatio) : 0f); if (Main.getGoodWorld) { - num169 += 0.01f; - num170 += 1f; - num171 += 0.05f; - num172 += 2f; + headYAcceleration += 0.01f; + headYTopSpeed += 1f; + headXAcceleration += 0.05f; + headXTopSpeed += 2f; } if (bossRush) { - num169 *= 1.25f; - num170 *= 0.75f; - num171 *= 1.25f; - num172 *= 0.75f; + headYAcceleration *= 1.25f; + headYTopSpeed *= 0.75f; + headXAcceleration *= 1.25f; + headXTopSpeed *= 0.75f; } if (npc.position.Y > Main.player[npc.target].position.Y - 250f) { if (npc.velocity.Y > 0f) npc.velocity.Y *= 0.98f; - npc.velocity.Y -= num169; - if (npc.velocity.Y > num170) - npc.velocity.Y = num170; + npc.velocity.Y -= headYAcceleration; + if (npc.velocity.Y > headYTopSpeed) + npc.velocity.Y = headYTopSpeed; } else if (npc.position.Y < Main.player[npc.target].position.Y - 250f) { if (npc.velocity.Y < 0f) npc.velocity.Y *= 0.98f; - npc.velocity.Y += num169; - if (npc.velocity.Y < -num170) - npc.velocity.Y = -num170; + npc.velocity.Y += headYAcceleration; + if (npc.velocity.Y < -headYTopSpeed) + npc.velocity.Y = -headYTopSpeed; } if (npc.position.X + (npc.width / 2) > Main.player[npc.target].position.X + (Main.player[npc.target].width / 2)) { if (npc.velocity.X > 0f) npc.velocity.X *= 0.98f; - npc.velocity.X -= num171; - if (npc.velocity.X > num172) - npc.velocity.X = num172; + npc.velocity.X -= headXAcceleration; + if (npc.velocity.X > headXTopSpeed) + npc.velocity.X = headXTopSpeed; } if (npc.position.X + (npc.width / 2) < Main.player[npc.target].position.X + (Main.player[npc.target].width / 2)) { if (npc.velocity.X < 0f) npc.velocity.X *= 0.98f; - npc.velocity.X += num171; - if (npc.velocity.X < -num172) - npc.velocity.X = -num172; + npc.velocity.X += headXAcceleration; + if (npc.velocity.X < -headXTopSpeed) + npc.velocity.X = -headXTopSpeed; } } @@ -402,21 +402,20 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses { if (NPC.CountNPCS(NPCID.DarkCaster) < 6) { - int num167 = 1000; - for (int num168 = 0; num168 < num167; num168++) + for (int i = 0; i < 1000; i++) { - int num169 = (int)(npc.Center.X / 16f) + Main.rand.Next(-50, 51); - int num170; - for (num170 = (int)(npc.Center.Y / 16f) + Main.rand.Next(-50, 51); num170 < Main.maxTilesY - 10 && !WorldGen.SolidTile(num169, num170); num170++) + int headYAcceleration = (int)(npc.Center.X / 16f) + Main.rand.Next(-50, 51); + int headYTopSpeed; + for (headYTopSpeed = (int)(npc.Center.Y / 16f) + Main.rand.Next(-50, 51); headYTopSpeed < Main.maxTilesY - 10 && !WorldGen.SolidTile(headYAcceleration, headYTopSpeed); headYTopSpeed++) { } - num170--; - if (!WorldGen.SolidTile(num169, num170)) + headYTopSpeed--; + if (!WorldGen.SolidTile(headYAcceleration, headYTopSpeed)) { - int num171 = NPC.NewNPC(npc.GetSource_FromAI(), num169 * 16 + 8, num170 * 16, NPCID.DarkCaster); - if (Main.netMode == NetmodeID.Server && num171 < Main.maxNPCs) - NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, num171); + int headXAcceleration = NPC.NewNPC(npc.GetSource_FromAI(), headYAcceleration * 16 + 8, headYTopSpeed * 16, NPCID.DarkCaster); + if (Main.netMode == NetmodeID.Server && headXAcceleration < Main.maxNPCs) + NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, headXAcceleration); break; } @@ -427,21 +426,20 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses { if (!NPC.AnyNPCs(NPCID.DiabolistWhite)) { - int num167 = 1000; - for (int num168 = 0; num168 < num167; num168++) + for (int i = 0; i < 1000; i++) { - int num169 = (int)(npc.Center.X / 16f) + Main.rand.Next(-50, 51); - int num170; - for (num170 = (int)(npc.Center.Y / 16f) + Main.rand.Next(-50, 51); num170 < Main.maxTilesY - 10 && !WorldGen.SolidTile(num169, num170); num170++) + int headYAcceleration = (int)(npc.Center.X / 16f) + Main.rand.Next(-50, 51); + int headYTopSpeed; + for (headYTopSpeed = (int)(npc.Center.Y / 16f) + Main.rand.Next(-50, 51); headYTopSpeed < Main.maxTilesY - 10 && !WorldGen.SolidTile(headYAcceleration, headYTopSpeed); headYTopSpeed++) { } - num170--; - if (!WorldGen.SolidTile(num169, num170)) + headYTopSpeed--; + if (!WorldGen.SolidTile(headYAcceleration, headYTopSpeed)) { - int num171 = NPC.NewNPC(npc.GetSource_FromAI(), num169 * 16 + 8, num170 * 16, NPCID.DiabolistWhite); - if (Main.netMode == NetmodeID.Server && num171 < Main.maxNPCs) - NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, num171); + int headXAcceleration = NPC.NewNPC(npc.GetSource_FromAI(), headYAcceleration * 16 + 8, headYTopSpeed * 16, NPCID.DiabolistWhite); + if (Main.netMode == NetmodeID.Server && headXAcceleration < Main.maxNPCs) + NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, headXAcceleration); break; } @@ -466,21 +464,20 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses { if (Main.netMode != NetmodeID.MultiplayerClient && NPC.CountNPCS(NPCID.DarkCaster) < 6) { - int num167 = 1000; - for (int num168 = 0; num168 < num167; num168++) + for (int j = 0; j < 1000; j++) { - int num169 = (int)(npc.Center.X / 16f) + Main.rand.Next(-50, 51); - int num170; - for (num170 = (int)(npc.Center.Y / 16f) + Main.rand.Next(-50, 51); num170 < Main.maxTilesY - 10 && !WorldGen.SolidTile(num169, num170); num170++) + int headYAcceleration = (int)(npc.Center.X / 16f) + Main.rand.Next(-50, 51); + int headYTopSpeed; + for (headYTopSpeed = (int)(npc.Center.Y / 16f) + Main.rand.Next(-50, 51); headYTopSpeed < Main.maxTilesY - 10 && !WorldGen.SolidTile(headYAcceleration, headYTopSpeed); headYTopSpeed++) { } - num170--; - if (!WorldGen.SolidTile(num169, num170)) + headYTopSpeed--; + if (!WorldGen.SolidTile(headYAcceleration, headYTopSpeed)) { - int num171 = NPC.NewNPC(npc.GetSource_FromAI(), num169 * 16 + 8, num170 * 16, NPCID.DarkCaster); - if (Main.netMode == NetmodeID.Server && num171 < Main.maxNPCs) - NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, num171); + int headXAcceleration = NPC.NewNPC(npc.GetSource_FromAI(), headYAcceleration * 16 + 8, headYTopSpeed * 16, NPCID.DarkCaster); + if (Main.netMode == NetmodeID.Server && headXAcceleration < Main.maxNPCs) + NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, headXAcceleration); break; } @@ -498,30 +495,30 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses } npc.rotation += npc.direction * 0.3f; - Vector2 vector20 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num173 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - vector20.X; - float num174 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - vector20.Y; - float num175 = (float)Math.Sqrt(num173 * num173 + num174 * num174); + Vector2 headSpinPos = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float headSpinTargetX = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - headSpinPos.X; + float headSpinTargetY = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - headSpinPos.Y; + float headSpinTargetDist = (float)Math.Sqrt(headSpinTargetX * headSpinTargetX + headSpinTargetY * headSpinTargetY); // Increase speed while charging npc.damage = (int)(npc.defDamage * 1.3); - float num176 = bossRush ? 9f : 4.5f; + float headSpinVelocityMult = bossRush ? 9f : 4.5f; float velocityBoost = death ? 1f : 1f - lifeRatio; if (handsDead || bossRush) - num176 += velocityBoost; + headSpinVelocityMult += velocityBoost; - if (num175 > 150f) + if (headSpinTargetDist > 150f) { - float baseDistanceVelocityMult = 1f + MathHelper.Clamp((num175 - 150f) * 0.0015f, 0.05f, 1.5f); - num176 *= baseDistanceVelocityMult; + float baseDistanceVelocityMult = 1f + MathHelper.Clamp((headSpinTargetDist - 150f) * 0.0015f, 0.05f, 1.5f); + headSpinVelocityMult *= baseDistanceVelocityMult; } if (Main.getGoodWorld) - num176 *= 1.3f; + headSpinVelocityMult *= 1.3f; - num175 = num176 / num175; - npc.velocity.X = num173 * num175; - npc.velocity.Y = num174 * num175; + headSpinTargetDist = headSpinVelocityMult / headSpinTargetDist; + npc.velocity.X = headSpinTargetX * headSpinTargetDist; + npc.velocity.Y = headSpinTargetY * headSpinTargetDist; } // Daytime enrage @@ -531,13 +528,13 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses calamityGlobalNPC.DR = 0.9999f; calamityGlobalNPC.unbreakableDR = true; npc.rotation += npc.direction * 0.3f; - Vector2 vector21 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num177 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - vector21.X; - float num178 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - vector21.Y; - float num179 = (float)Math.Sqrt(num177 * num177 + num178 * num178); - num179 = 8f / num179; - npc.velocity.X = num177 * num179; - npc.velocity.Y = num178 * num179; + Vector2 enrageSpinPos = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float enrageSpinTargetX = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - enrageSpinPos.X; + float enrageSpinTargetY = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - enrageSpinPos.Y; + float enrageSpinTargetDist = (float)Math.Sqrt(enrageSpinTargetX * enrageSpinTargetX + enrageSpinTargetY * enrageSpinTargetY); + enrageSpinTargetDist = 8f / enrageSpinTargetDist; + npc.velocity.X = enrageSpinTargetX * enrageSpinTargetDist; + npc.velocity.Y = enrageSpinTargetY * enrageSpinTargetDist; } // Despawn @@ -552,19 +549,19 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses } // Emit dust - if (npc.ai[1] != 2f && npc.ai[1] != 3f && num156 != 0) + if (npc.ai[1] != 2f && npc.ai[1] != 3f && numHandsAlive != 0) { - int num180 = Dust.NewDust(new Vector2(npc.position.X + (npc.width / 2) - 15f - npc.velocity.X * 5f, npc.position.Y + npc.height - 2f), 30, 10, 5, -npc.velocity.X * 0.2f, 3f, 0, default, 2f); - Main.dust[num180].noGravity = true; - Main.dust[num180].velocity.X = Main.dust[num180].velocity.X * 1.3f; - Main.dust[num180].velocity.X = Main.dust[num180].velocity.X + npc.velocity.X * 0.4f; - Main.dust[num180].velocity.Y = Main.dust[num180].velocity.Y + (2f + npc.velocity.Y); - for (int num181 = 0; num181 < 2; num181++) + int idleDust = Dust.NewDust(new Vector2(npc.position.X + (npc.width / 2) - 15f - npc.velocity.X * 5f, npc.position.Y + npc.height - 2f), 30, 10, 5, -npc.velocity.X * 0.2f, 3f, 0, default, 2f); + Main.dust[idleDust].noGravity = true; + Main.dust[idleDust].velocity.X = Main.dust[idleDust].velocity.X * 1.3f; + Main.dust[idleDust].velocity.X = Main.dust[idleDust].velocity.X + npc.velocity.X * 0.4f; + Main.dust[idleDust].velocity.Y = Main.dust[idleDust].velocity.Y + (2f + npc.velocity.Y); + for (int j = 0; j < 2; j++) { - num180 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y + 120f), npc.width, 60, 5, npc.velocity.X, npc.velocity.Y, 0, default, 2f); - Main.dust[num180].noGravity = true; - Main.dust[num180].velocity -= npc.velocity; - Main.dust[num180].velocity.Y = Main.dust[num180].velocity.Y + 5f; + idleDust = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y + 120f), npc.width, 60, 5, npc.velocity.X, npc.velocity.Y, 0, default, 2f); + Main.dust[idleDust].noGravity = true; + Main.dust[idleDust].velocity -= npc.velocity; + Main.dust[idleDust].velocity.Y = Main.dust[idleDust].velocity.Y + 5f; } } @@ -610,9 +607,9 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses // Teleport dust for (int m = 0; m < 10; m++) { - int num39 = Dust.NewDust(npc.position, npc.width, npc.height, 27, 0f, 0f, 200, default, 3f); - Main.dust[num39].noGravity = true; - Main.dust[num39].velocity.X = Main.dust[num39].velocity.X * 2f; + int teleportDust = Dust.NewDust(npc.position, npc.width, npc.height, 27, 0f, 0f, 200, default, 3f); + Main.dust[teleportDust].noGravity = true; + Main.dust[teleportDust].velocity.X = Main.dust[teleportDust].velocity.X * 2f; } // New location @@ -726,20 +723,20 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses } } - Vector2 vector22 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num182 = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - vector22.X; - float num183 = Main.npc[(int)npc.ai[1]].position.Y + 230f - vector22.Y; - float num184 = (float)Math.Sqrt(num182 * num182 + num183 * num183); - npc.rotation = (float)Math.Atan2(num183, num182) + MathHelper.PiOver2; + Vector2 handCurrentPos = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float handIdleXPos = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - handCurrentPos.X; + float handIdleYPos = Main.npc[(int)npc.ai[1]].position.Y + 230f - handCurrentPos.Y; + float handIdleDist = (float)Math.Sqrt(handIdleXPos * handIdleXPos + handIdleYPos * handIdleYPos); + npc.rotation = (float)Math.Atan2(handIdleYPos, handIdleXPos) + MathHelper.PiOver2; return false; } if (npc.ai[2] == 1f) { - Vector2 vector23 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num185 = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - vector23.X; - float num186 = Main.npc[(int)npc.ai[1]].position.Y + 230f - vector23.Y; - float num187 = (float)Math.Sqrt(num185 * num185 + num186 * num186); - npc.rotation = (float)Math.Atan2(num186, num185) + MathHelper.PiOver2; + Vector2 handCurrentPosition = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float handDrawbackXPos = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - handCurrentPosition.X; + float handDrawbackYPos = Main.npc[(int)npc.ai[1]].position.Y + 230f - handCurrentPosition.Y; + float handDrawbackDist = (float)Math.Sqrt(handDrawbackXPos * handDrawbackXPos + handDrawbackYPos * handDrawbackYPos); + npc.rotation = (float)Math.Atan2(handDrawbackYPos, handDrawbackXPos) + MathHelper.PiOver2; npc.velocity.X *= 0.95f; npc.velocity.Y -= 0.2f; @@ -750,13 +747,13 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses { npc.TargetClosest(); npc.ai[2] = 2f; - vector23 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - num185 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - vector23.X; - num186 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - vector23.Y; - num187 = (float)Math.Sqrt(num185 * num185 + num186 * num186); - num187 = 22f / num187; - npc.velocity.X = num185 * num187; - npc.velocity.Y = num186 * num187; + handCurrentPosition = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + handDrawbackXPos = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - handCurrentPosition.X; + handDrawbackYPos = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - handCurrentPosition.Y; + handDrawbackDist = (float)Math.Sqrt(handDrawbackXPos * handDrawbackXPos + handDrawbackYPos * handDrawbackYPos); + handDrawbackDist = 22f / handDrawbackDist; + npc.velocity.X = handDrawbackXPos * handDrawbackDist; + npc.velocity.Y = handDrawbackYPos * handDrawbackDist; npc.netUpdate = true; } } @@ -770,11 +767,11 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses } else if (npc.ai[2] == 4f) { - Vector2 vector24 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num188 = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - vector24.X; - float num189 = Main.npc[(int)npc.ai[1]].position.Y + 230f - vector24.Y; - float num190 = (float)Math.Sqrt(num188 * num188 + num189 * num189); - npc.rotation = (float)Math.Atan2(num189, num188) + MathHelper.PiOver2; + Vector2 handStrikeCurrentPos = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float handStrikeXPos = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - handStrikeCurrentPos.X; + float handStrikeYPos = Main.npc[(int)npc.ai[1]].position.Y + 230f - handStrikeCurrentPos.Y; + float handStrikeDist = (float)Math.Sqrt(handStrikeXPos * handStrikeXPos + handStrikeYPos * handStrikeYPos); + npc.rotation = (float)Math.Atan2(handStrikeYPos, handStrikeXPos) + MathHelper.PiOver2; npc.velocity.Y *= 0.95f; npc.velocity.X += 0.2f * -npc.ai[0]; @@ -787,13 +784,13 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses { npc.TargetClosest(); npc.ai[2] = 5f; - vector24 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - num188 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - vector24.X; - num189 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - vector24.Y; - num190 = (float)Math.Sqrt(num188 * num188 + num189 * num189); - num190 = 23f / num190; - npc.velocity.X = num188 * num190; - npc.velocity.Y = num189 * num190; + handStrikeCurrentPos = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + handStrikeXPos = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - handStrikeCurrentPos.X; + handStrikeYPos = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - handStrikeCurrentPos.Y; + handStrikeDist = (float)Math.Sqrt(handStrikeXPos * handStrikeXPos + handStrikeYPos * handStrikeYPos); + handStrikeDist = 23f / handStrikeDist; + npc.velocity.X = handStrikeXPos * handStrikeDist; + npc.velocity.Y = handStrikeYPos * handStrikeDist; npc.netUpdate = true; } } diff --git a/NPCs/VanillaNPCOverrides/Bosses/SkeletronPrimeAI.cs b/NPCs/VanillaNPCOverrides/Bosses/SkeletronPrimeAI.cs index 159a652c59..fab85f1c45 100644 --- a/NPCs/VanillaNPCOverrides/Bosses/SkeletronPrimeAI.cs +++ b/NPCs/VanillaNPCOverrides/Bosses/SkeletronPrimeAI.cs @@ -209,15 +209,15 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses float velocityX = 7f - (death ? 3.5f * (1f - lifeRatio) : 0f); float acceleration = 0.1f + (death ? 0.05f * (1f - lifeRatio) : 0f); - float num500 = 0f; - float num501 = 0f; - float num502 = 0f; - int num503 = ((!(Main.player[npc.target].Center.X < npc.Center.X)) ? 1 : (-1)); + float headDecelerationUpDist = 0f; + float headDecelerationDownDist = 0f; + float headDecelerationHorizontalDist = 0f; + int headHorizontalDirection = ((!(Main.player[npc.target].Center.X < npc.Center.X)) ? 1 : (-1)); if (NPC.IsMechQueenUp) { - num502 = -150f * (float)num503; - num500 = -100f; - num501 = -100f; + headDecelerationHorizontalDist = -150f * (float)headHorizontalDirection; + headDecelerationUpDist = -100f; + headDecelerationDownDist = -100f; } if (!cannonAlive) @@ -252,7 +252,7 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses if (Main.player[npc.target].HoldingTrueMeleeWeapon()) acceleration *= 0.5f; - if (npc.position.Y > Main.player[npc.target].position.Y - (400f + num500)) + if (npc.position.Y > Main.player[npc.target].position.Y - (400f + headDecelerationUpDist)) { if (npc.velocity.Y > 0f) npc.velocity.Y *= 0.9f; @@ -262,7 +262,7 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses if (npc.velocity.Y > velocityY) npc.velocity.Y = velocityY; } - else if (npc.position.Y < Main.player[npc.target].position.Y - (450f + num501)) + else if (npc.position.Y < Main.player[npc.target].position.Y - (450f + headDecelerationDownDist)) { if (npc.velocity.Y < 0f) npc.velocity.Y *= 0.9f; @@ -273,7 +273,7 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.velocity.Y = -velocityY; } - if (npc.position.X + (npc.width / 2) > Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) + (400f + num502)) + if (npc.position.X + (npc.width / 2) > Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) + (400f + headDecelerationHorizontalDist)) { if (npc.velocity.X > 0f) npc.velocity.X *= 0.9f; @@ -283,7 +283,7 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses if (npc.velocity.X > velocityX) npc.velocity.X = velocityX; } - if (npc.position.X + (npc.width / 2) < Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - (400f + num502)) + if (npc.position.X + (npc.width / 2) < Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - (400f + headDecelerationHorizontalDist)) { if (npc.velocity.X < 0f) npc.velocity.X *= 0.9f; @@ -321,8 +321,8 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses Vector2 spinningPoint = normalLaserRotation ? new Vector2(0f, -velocity) : new Vector2(-velocityX, -velocity); for (int k = 0; k < totalProjectiles; k++) { - Vector2 vector255 = spinningPoint.RotatedBy(radians * k); - int proj = Projectile.NewProjectile(npc.GetSource_FromAI(), npc.Center + Vector2.Normalize(vector255) * 30f, vector255, type, damage, 0f, Main.myPlayer, 1f, 0f); + Vector2 laserFireDirection = spinningPoint.RotatedBy(radians * k); + int proj = Projectile.NewProjectile(npc.GetSource_FromAI(), npc.Center + Vector2.Normalize(laserFireDirection) * 30f, laserFireDirection, type, damage, 0f, Main.myPlayer, 1f, 0f); Main.projectile[proj].timeLeft = 900; } calamityGlobalNPC.newAI[3] += 1f; @@ -351,10 +351,10 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses else npc.rotation += npc.direction * 0.3f; - Vector2 vector48 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num455 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - vector48.X; - float num456 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - vector48.Y; - float num457 = (float)Math.Sqrt(num455 * num455 + num456 * num456); + Vector2 headPosition = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float headTargetX = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - headPosition.X; + float headTargetY = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - headPosition.Y; + float headTargetDistance = (float)Math.Sqrt(headTargetX * headTargetX + headTargetY * headTargetY); float speed = bossRush ? 9f : 6f; if (phase2) @@ -362,30 +362,30 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses if (phase3) speed += 0.5f; - if (num457 > 150f) + if (headTargetDistance > 150f) { - float baseDistanceVelocityMult = 1f + MathHelper.Clamp((num457 - 150f) * 0.0015f, 0.05f, 1.5f); + float baseDistanceVelocityMult = 1f + MathHelper.Clamp((headTargetDistance - 150f) * 0.0015f, 0.05f, 1.5f); speed *= baseDistanceVelocityMult; } if (NPC.IsMechQueenUp) { - float num508 = (NPC.npcsFoundForCheckActive[NPCID.TheDestroyerBody] ? 0.6f : 0.75f); - speed *= num508; + float mechdusaSpeedMult = (NPC.npcsFoundForCheckActive[NPCID.TheDestroyerBody] ? 0.6f : 0.75f); + speed *= mechdusaSpeedMult; } - num457 = speed / num457; - npc.velocity.X = num455 * num457; - npc.velocity.Y = num456 * num457; + headTargetDistance = speed / headTargetDistance; + npc.velocity.X = headTargetX * headTargetDistance; + npc.velocity.Y = headTargetY * headTargetDistance; if (NPC.IsMechQueenUp) { - float num509 = Vector2.Distance(npc.Center, Main.player[npc.target].Center); - if (num509 < 0.1f) - num509 = 0f; + float mechdusaAccelMult = Vector2.Distance(npc.Center, Main.player[npc.target].Center); + if (mechdusaAccelMult < 0.1f) + mechdusaAccelMult = 0f; - if (num509 < speed) - npc.velocity = npc.velocity.SafeNormalize(Vector2.Zero) * num509; + if (mechdusaAccelMult < speed) + npc.velocity = npc.velocity.SafeNormalize(Vector2.Zero) * mechdusaAccelMult; } } @@ -401,21 +401,21 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses else npc.rotation += npc.direction * 0.3f; - Vector2 vector49 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num458 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - vector49.X; - float num459 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - vector49.Y; - float num460 = (float)Math.Sqrt(num458 * num458 + num459 * num459); + Vector2 enragedHeadPosition = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float enragedHeadTargetX = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - enragedHeadPosition.X; + float enragedHeadTargetY = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - enragedHeadPosition.Y; + float enragedHeadTargetDist = (float)Math.Sqrt(enragedHeadTargetX * enragedHeadTargetX + enragedHeadTargetY * enragedHeadTargetY); - float num461 = 10f; - num461 += num460 / 100f; - if (num461 < 8f) - num461 = 8f; - if (num461 > 32f) - num461 = 32f; + float enragedHeadSpeed = 10f; + enragedHeadSpeed += enragedHeadTargetDist / 100f; + if (enragedHeadSpeed < 8f) + enragedHeadSpeed = 8f; + if (enragedHeadSpeed > 32f) + enragedHeadSpeed = 32f; - num460 = num461 / num460; - npc.velocity.X = num458 * num460; - npc.velocity.Y = num459 * num460; + enragedHeadTargetDist = enragedHeadSpeed / enragedHeadTargetDist; + npc.velocity.X = enragedHeadTargetX * enragedHeadTargetDist; + npc.velocity.Y = enragedHeadTargetY * enragedHeadTargetDist; if (Main.netMode != NetmodeID.MultiplayerClient) { @@ -423,28 +423,28 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses if (npc.localAI[0] >= 60f) { npc.localAI[0] = 0f; - Vector2 vector16 = npc.Center; - if (Collision.CanHit(vector16, 1, 1, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) + Vector2 headCenter = npc.Center; + if (Collision.CanHit(headCenter, 1, 1, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) { - float num159 = 7f; - float num160 = Main.player[npc.target].position.X + Main.player[npc.target].width * 0.5f - vector16.X + Main.rand.Next(-20, 21); - float num161 = Main.player[npc.target].position.Y + Main.player[npc.target].height * 0.5f - vector16.Y + Main.rand.Next(-20, 21); - float num162 = (float)Math.Sqrt(num160 * num160 + num161 * num161); - num162 = num159 / num162; - num160 *= num162; - num161 *= num162; + float enragedHeadSpeed = 7f; + float enragedHeadSkullTargetX = Main.player[npc.target].position.X + Main.player[npc.target].width * 0.5f - headCenter.X + Main.rand.Next(-20, 21); + float enragedHeadSkullTargetY = Main.player[npc.target].position.Y + Main.player[npc.target].height * 0.5f - headCenter.Y + Main.rand.Next(-20, 21); + float enragedHeadSkullTargetDist = (float)Math.Sqrt(enragedHeadSkullTargetX * enragedHeadSkullTargetX + enragedHeadSkullTargetY * enragedHeadSkullTargetY); + enragedHeadSkullTargetDist = enragedHeadSpeed / enragedHeadSkullTargetDist; + enragedHeadSkullTargetX *= enragedHeadSkullTargetDist; + enragedHeadSkullTargetY *= enragedHeadSkullTargetDist; - Vector2 value = new Vector2(num160 * 1f + Main.rand.Next(-50, 51) * 0.01f, num161 * 1f + Main.rand.Next(-50, 51) * 0.01f); + Vector2 value = new Vector2(enragedHeadSkullTargetX * 1f + Main.rand.Next(-50, 51) * 0.01f, enragedHeadSkullTargetY * 1f + Main.rand.Next(-50, 51) * 0.01f); value.Normalize(); - value *= num159; + value *= enragedHeadSpeed; value += npc.velocity; - num160 = value.X; - num161 = value.Y; + enragedHeadSkullTargetX = value.X; + enragedHeadSkullTargetY = value.Y; int type = ProjectileID.Skull; - vector16 += value * 5f; - int num165 = Projectile.NewProjectile(npc.GetSource_FromAI(), vector16.X, vector16.Y, num160, num161, type, 250, 0f, Main.myPlayer, -1f, 0f); - Main.projectile[num165].timeLeft = 300; + headCenter += value * 5f; + int enragedSkulls = Projectile.NewProjectile(npc.GetSource_FromAI(), headCenter.X, headCenter.Y, enragedHeadSkullTargetX, enragedHeadSkullTargetY, type, 250, 0f, Main.myPlayer, -1f, 0f); + Main.projectile[enragedSkulls].timeLeft = 300; } } } @@ -455,19 +455,19 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses { if (NPC.IsMechQueenUp) { - int num514 = NPC.FindFirstNPC(NPCID.Retinazer); - if (num514 >= 0) - Main.npc[num514].EncourageDespawn(5); + int mechdusaBossDespawning = NPC.FindFirstNPC(NPCID.Retinazer); + if (mechdusaBossDespawning >= 0) + Main.npc[mechdusaBossDespawning].EncourageDespawn(5); - num514 = NPC.FindFirstNPC(NPCID.Spazmatism); - if (num514 >= 0) - Main.npc[num514].EncourageDespawn(5); + mechdusaBossDespawning = NPC.FindFirstNPC(NPCID.Spazmatism); + if (mechdusaBossDespawning >= 0) + Main.npc[mechdusaBossDespawning].EncourageDespawn(5); if (!NPC.AnyNPCs(NPCID.Retinazer) && !NPC.AnyNPCs(NPCID.Spazmatism)) { - num514 = NPC.FindFirstNPC(NPCID.TheDestroyer); - if (num514 >= 0) - Main.npc[num514].Transform(NPCID.TheDestroyerTail); + mechdusaBossDespawning = NPC.FindFirstNPC(NPCID.TheDestroyer); + if (mechdusaBossDespawning >= 0) + Main.npc[mechdusaBossDespawning].Transform(NPCID.TheDestroyerTail); npc.EncourageDespawn(5); } @@ -540,27 +540,27 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses { if (Main.netMode != NetmodeID.MultiplayerClient) { - Vector2 vector16 = npc.Center; - float num159 = 4f + (death ? 2f * (1f - lifeRatio) : 0f); - float num160 = Main.player[npc.target].position.X + Main.player[npc.target].width * 0.5f - vector16.X + Main.rand.Next(-20, 21); - float num161 = Main.player[npc.target].position.Y + Main.player[npc.target].height * 0.5f - vector16.Y + Main.rand.Next(-20, 21); - float num162 = (float)Math.Sqrt(num160 * num160 + num161 * num161); - num162 = num159 / num162; - num160 *= num162; - num161 *= num162; + Vector2 headCenter = npc.Center; + float enragedHeadSpeed = 4f + (death ? 2f * (1f - lifeRatio) : 0f); + float enragedHeadSkullTargetX = Main.player[npc.target].position.X + Main.player[npc.target].width * 0.5f - headCenter.X + Main.rand.Next(-20, 21); + float enragedHeadSkullTargetY = Main.player[npc.target].position.Y + Main.player[npc.target].height * 0.5f - headCenter.Y + Main.rand.Next(-20, 21); + float enragedHeadSkullTargetDist = (float)Math.Sqrt(enragedHeadSkullTargetX * enragedHeadSkullTargetX + enragedHeadSkullTargetY * enragedHeadSkullTargetY); + enragedHeadSkullTargetDist = enragedHeadSpeed / enragedHeadSkullTargetDist; + enragedHeadSkullTargetX *= enragedHeadSkullTargetDist; + enragedHeadSkullTargetY *= enragedHeadSkullTargetDist; - Vector2 value = new Vector2(num160 + Main.rand.Next(-skullSpread, skullSpread + 1) * 0.01f, num161 + Main.rand.Next(-skullSpread, skullSpread + 1) * 0.01f); + Vector2 value = new Vector2(enragedHeadSkullTargetX + Main.rand.Next(-skullSpread, skullSpread + 1) * 0.01f, enragedHeadSkullTargetY + Main.rand.Next(-skullSpread, skullSpread + 1) * 0.01f); value.Normalize(); - value *= num159; - num160 = value.X; - num161 = value.Y; + value *= enragedHeadSpeed; + enragedHeadSkullTargetX = value.X; + enragedHeadSkullTargetY = value.Y; int type = ProjectileID.Skull; int damage = npc.GetProjectileDamage(type); - vector16 += value * 5f; - int num165 = Projectile.NewProjectile(npc.GetSource_FromAI(), vector16.X, vector16.Y, num160, num161, type, damage, 0f, Main.myPlayer, -1f, 0f); - Main.projectile[num165].timeLeft = 480; - Main.projectile[num165].tileCollide = false; + headCenter += value * 5f; + int enragedSkulls = Projectile.NewProjectile(npc.GetSource_FromAI(), headCenter.X, headCenter.Y, enragedHeadSkullTargetX, enragedHeadSkullTargetY, type, damage, 0f, Main.myPlayer, -1f, 0f); + Main.projectile[enragedSkulls].timeLeft = 480; + Main.projectile[enragedSkulls].tileCollide = false; } } @@ -772,11 +772,11 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.netUpdate = true; } - Vector2 vector62 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num506 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - vector62.X; - float num507 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - vector62.Y; - float num508 = (float)Math.Sqrt(num506 * num506 + num507 * num507); - npc.rotation = (float)Math.Atan2(num507, num506) - MathHelper.PiOver2; + Vector2 laserArmPosition = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float laserArmTargetX = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - laserArmPosition.X; + float laserArmTargetY = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - laserArmPosition.Y; + float laserArmTargetDist = (float)Math.Sqrt(laserArmTargetX * laserArmTargetX + laserArmTargetY * laserArmTargetY); + npc.rotation = (float)Math.Atan2(laserArmTargetY, laserArmTargetX) - MathHelper.PiOver2; if (Main.netMode != NetmodeID.MultiplayerClient && !dontAttack) { @@ -793,15 +793,15 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses { npc.localAI[0] = 0f; npc.TargetClosest(); - float num509 = bossRush ? 5f : 4f; + float laserSpeed = bossRush ? 5f : 4f; int type = ProjectileID.DeathLaser; int damage = npc.GetProjectileDamage(type); - num508 = num509 / num508; - num506 *= num508; - num507 *= num508; - vector62.X += num506 * 30f; - vector62.Y += num507 * 30f; - Projectile.NewProjectile(npc.GetSource_FromAI(), vector62.X, vector62.Y, num506, num507, type, damage, 0f, Main.myPlayer, 1f, 0f); + laserArmTargetDist = laserSpeed / laserArmTargetDist; + laserArmTargetX *= laserArmTargetDist; + laserArmTargetY *= laserArmTargetDist; + laserArmPosition.X += laserArmTargetX * 30f; + laserArmPosition.Y += laserArmTargetY * 30f; + Projectile.NewProjectile(npc.GetSource_FromAI(), laserArmPosition.X, laserArmPosition.Y, laserArmTargetX, laserArmTargetY, type, damage, 0f, Main.myPlayer, 1f, 0f); } } } @@ -830,10 +830,10 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.netUpdate = true; } - Vector2 vector63 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num513 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - vector63.X; - float num514 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - vector63.Y; - npc.rotation = (float)Math.Atan2(num514, num513) - MathHelper.PiOver2; + Vector2 laserRingArmPosition = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float laserRingTargetX = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - laserRingArmPosition.X; + float laserRingTargetY = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - laserRingArmPosition.Y; + npc.rotation = (float)Math.Atan2(laserRingTargetY, laserRingTargetX) - MathHelper.PiOver2; if (Main.netMode != NetmodeID.MultiplayerClient && !dontAttack) { @@ -861,8 +861,8 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses Vector2 spinningPoint = normalLaserRotation ? new Vector2(0f, -velocity) : new Vector2(-laserVelocityX, -velocity); for (int k = 0; k < totalProjectiles; k++) { - Vector2 vector255 = spinningPoint.RotatedBy(radians * k); - int proj = Projectile.NewProjectile(npc.GetSource_FromAI(), npc.Center + Vector2.Normalize(vector255) * 30f, vector255, type, damage, 0f, Main.myPlayer, 1f, 0f); + Vector2 laserFireDirection = spinningPoint.RotatedBy(radians * k); + int proj = Projectile.NewProjectile(npc.GetSource_FromAI(), npc.Center + Vector2.Normalize(laserFireDirection) * 30f, laserFireDirection, type, damage, 0f, Main.myPlayer, 1f, 0f); Main.projectile[proj].timeLeft = 900; } npc.localAI[1] += 1f; @@ -1041,11 +1041,11 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses if (Main.npc[(int)npc.ai[1]].ai[1] == 3f && npc.timeLeft > 10) npc.timeLeft = 10; - Vector2 vector60 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num492 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - vector60.X; - float num493 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - vector60.Y; - float num494 = (float)Math.Sqrt(num492 * num492 + num493 * num493); - npc.rotation = (float)Math.Atan2(num493, num492) - MathHelper.PiOver2; + Vector2 cannonArmPosition = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float cannonArmTargetX = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - cannonArmPosition.X; + float cannonArmTargetY = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - cannonArmPosition.Y; + float cannonArmTargetDist = (float)Math.Sqrt(cannonArmTargetX * cannonArmTargetX + cannonArmTargetY * cannonArmTargetY); + npc.rotation = (float)Math.Atan2(cannonArmTargetY, cannonArmTargetX) - MathHelper.PiOver2; if (Main.netMode != NetmodeID.MultiplayerClient && !dontAttack) { @@ -1063,25 +1063,24 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses SoundEngine.PlaySound(SoundID.Item62, npc.Center); npc.localAI[0] = 0f; npc.TargetClosest(); - float num495 = 0.5f; int type = ProjectileID.RocketSkeleton; int damage = npc.GetProjectileDamage(type); - num494 = num495 / num494; - num492 *= num494; - num493 *= num494; - vector60.X += num492 * 30f; - vector60.Y += num493 * 30f; - int proj = Projectile.NewProjectile(npc.GetSource_FromAI(), vector60.X, vector60.Y, num492, num493, type, damage, 0f, Main.myPlayer, npc.target, 1f); + cannonArmTargetDist = 0.5f / cannonArmTargetDist; + cannonArmTargetX *= cannonArmTargetDist; + cannonArmTargetY *= cannonArmTargetDist; + cannonArmPosition.X += cannonArmTargetX * 30f; + cannonArmPosition.Y += cannonArmTargetY * 30f; + int proj = Projectile.NewProjectile(npc.GetSource_FromAI(), cannonArmPosition.X, cannonArmPosition.Y, cannonArmTargetX, cannonArmTargetY, type, damage, 0f, Main.myPlayer, npc.target, 1f); Main.projectile[proj].timeLeft = 600; } } } else { - Vector2 vector61 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num499 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - vector61.X; - float num500 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - vector61.Y; - npc.rotation = (float)Math.Atan2(num500, num499) - MathHelper.PiOver2; + Vector2 cannonSpreadArmPosition = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float cannonSpreadArmTargetX = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - cannonSpreadArmPosition.X; + float cannonSpreadArmTargetY = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - cannonSpreadArmPosition.Y; + npc.rotation = (float)Math.Atan2(cannonSpreadArmTargetY, cannonSpreadArmTargetX) - MathHelper.PiOver2; if (Main.netMode != NetmodeID.MultiplayerClient && !dontAttack) { @@ -1099,17 +1098,16 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses SoundEngine.PlaySound(SoundID.Item62, npc.Center); npc.localAI[0] = 0f; npc.TargetClosest(); - float num502 = 0.5f; int type = ProjectileID.RocketSkeleton; int damage = npc.GetProjectileDamage(type); - Vector2 value19 = Main.player[npc.target].Center - npc.Center; - value19.Normalize(); - value19 *= num502; + Vector2 cannonSpreadTargetDist = Main.player[npc.target].Center - npc.Center; + cannonSpreadTargetDist.Normalize(); + cannonSpreadTargetDist *= 0.5f; int numProj = bossRush ? 5 : 3; float rotation = MathHelper.ToRadians(bossRush ? 8 : 5); for (int i = 0; i < numProj; i++) { - Vector2 perturbedSpeed = value19.RotatedBy(MathHelper.Lerp(-rotation, rotation, i / (float)(numProj - 1))); + Vector2 perturbedSpeed = cannonSpreadTargetDist.RotatedBy(MathHelper.Lerp(-rotation, rotation, i / (float)(numProj - 1))); int proj = Projectile.NewProjectile(npc.GetSource_FromAI(), npc.Center + Vector2.Normalize(perturbedSpeed) * 30f, perturbedSpeed, type, damage, 0f, Main.myPlayer, npc.target, 1f); Main.projectile[proj].timeLeft = 600; } @@ -1137,18 +1135,18 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.spriteDirection = -(int)npc.ai[0]; // Where the vice should be in relation to the head - Vector2 vector55 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num477 = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - vector55.X; - float num478 = Main.npc[(int)npc.ai[1]].position.Y + 230f - vector55.Y; - float num479 = (float)Math.Sqrt(num477 * num477 + num478 * num478); + Vector2 viceArmPosition = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float viceArmIdleXPos = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - viceArmPosition.X; + float viceArmIdleYPos = Main.npc[(int)npc.ai[1]].position.Y + 230f - viceArmPosition.Y; + float viceArmIdleDistance = (float)Math.Sqrt(viceArmIdleXPos * viceArmIdleXPos + viceArmIdleYPos * viceArmIdleYPos); // Return the vice to its proper location in relation to the head if it's too far away if (npc.ai[2] != 99f) { - if (num479 > 800f) + if (viceArmIdleDistance > 800f) npc.ai[2] = 99f; } - else if (num479 < 400f) + else if (viceArmIdleDistance < 400f) npc.ai[2] = 0f; // Despawn if head is gone @@ -1318,10 +1316,10 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.velocity.X = -velocityX2; } - Vector2 vector57 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num483 = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - vector57.X; - float num484 = Main.npc[(int)npc.ai[1]].position.Y + 230f - vector57.Y; - npc.rotation = (float)Math.Atan2(num484, num483) + MathHelper.PiOver2; + Vector2 viceArmReelbackCurrentPos = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float viceArmReelbackXDest = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - viceArmReelbackCurrentPos.X; + float viceArmReelbackYDest = Main.npc[(int)npc.ai[1]].position.Y + 230f - viceArmReelbackCurrentPos.Y; + npc.rotation = (float)Math.Atan2(viceArmReelbackYDest, viceArmReelbackXDest) + MathHelper.PiOver2; return false; } @@ -1331,10 +1329,10 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses if (npc.velocity.Y > 0f) npc.velocity.Y *= 0.9f; - Vector2 vector58 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num486 = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 280f * npc.ai[0] - vector58.X; - float num487 = Main.npc[(int)npc.ai[1]].position.Y + 230f - vector58.Y; - npc.rotation = (float)Math.Atan2(num487, num486) + MathHelper.PiOver2; + Vector2 viceArmChargePosition = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float viceArmChargeTargetX = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 280f * npc.ai[0] - viceArmChargePosition.X; + float viceArmChargeTargetY = Main.npc[(int)npc.ai[1]].position.Y + 230f - viceArmChargePosition.Y; + npc.rotation = (float)Math.Atan2(viceArmChargeTargetY, viceArmChargeTargetX) + MathHelper.PiOver2; npc.velocity.X = (npc.velocity.X * 5f + Main.npc[(int)npc.ai[1]].velocity.X) / 6f; npc.velocity.X += 0.5f; @@ -1355,13 +1353,13 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.ai[2] = 2f; npc.TargetClosest(); - vector58 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - num486 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - vector58.X; - num487 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - vector58.Y; - float num488 = (float)Math.Sqrt(num486 * num486 + num487 * num487); - num488 = chargeVelocity / num488; - npc.velocity.X = num486 * num488; - npc.velocity.Y = num487 * num488; + viceArmChargePosition = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + viceArmChargeTargetX = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - viceArmChargePosition.X; + viceArmChargeTargetY = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - viceArmChargePosition.Y; + float viceArmChargeTargetDist = (float)Math.Sqrt(viceArmChargeTargetX * viceArmChargeTargetX + viceArmChargeTargetY * viceArmChargeTargetY); + viceArmChargeTargetDist = chargeVelocity / viceArmChargeTargetDist; + npc.velocity.X = viceArmChargeTargetX * viceArmChargeTargetDist; + npc.velocity.Y = viceArmChargeTargetY * viceArmChargeTargetDist; npc.netUpdate = true; } } @@ -1396,10 +1394,10 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses // Different type of charge else if (npc.ai[2] == 4f) { - Vector2 vector59 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num489 = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - vector59.X; - float num490 = Main.npc[(int)npc.ai[1]].position.Y + 230f - vector59.Y; - npc.rotation = (float)Math.Atan2(num490, num489) + MathHelper.PiOver2; + Vector2 viceArmOtherChargePosition = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float viceArmOtherChargeTargetX = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - viceArmOtherChargePosition.X; + float viceArmOtherChargeTargetY = Main.npc[(int)npc.ai[1]].position.Y + 230f - viceArmOtherChargePosition.Y; + npc.rotation = (float)Math.Atan2(viceArmOtherChargeTargetY, viceArmOtherChargeTargetX) + MathHelper.PiOver2; npc.velocity.Y = (npc.velocity.Y * 5f + Main.npc[(int)npc.ai[1]].velocity.Y) / 6f; @@ -1419,13 +1417,13 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.ai[2] = 5f; npc.TargetClosest(); - vector59 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - num489 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - vector59.X; - num490 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - vector59.Y; - float num491 = (float)Math.Sqrt(num489 * num489 + num490 * num490); - num491 = chargeVelocity / num491; - npc.velocity.X = num489 * num491; - npc.velocity.Y = num490 * num491; + viceArmOtherChargePosition = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + viceArmOtherChargeTargetX = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - viceArmOtherChargePosition.X; + viceArmOtherChargeTargetY = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - viceArmOtherChargePosition.Y; + float viceArmOtherChargeTargetDist = (float)Math.Sqrt(viceArmOtherChargeTargetX * viceArmOtherChargeTargetX + viceArmOtherChargeTargetY * viceArmOtherChargeTargetY); + viceArmOtherChargeTargetDist = chargeVelocity / viceArmOtherChargeTargetDist; + npc.velocity.X = viceArmOtherChargeTargetX * viceArmOtherChargeTargetDist; + npc.velocity.Y = viceArmOtherChargeTargetY * viceArmOtherChargeTargetDist; npc.netUpdate = true; } } @@ -1471,17 +1469,17 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses if (Vector2.Distance(Main.player[npc.target].Center, npc.Center) > CalamityGlobalNPC.CatchUpDistance200Tiles) npc.TargetClosest(); - Vector2 vector50 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num462 = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - vector50.X; - float num463 = Main.npc[(int)npc.ai[1]].position.Y + 230f - vector50.Y; - float num464 = (float)Math.Sqrt(num462 * num462 + num463 * num463); + Vector2 sawArmLocation = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float sawArmIdleXPos = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - sawArmLocation.X; + float sawArmIdleYPos = Main.npc[(int)npc.ai[1]].position.Y + 230f - sawArmLocation.Y; + float sawArmIdleDistance = (float)Math.Sqrt(sawArmIdleXPos * sawArmIdleXPos + sawArmIdleYPos * sawArmIdleYPos); if (npc.ai[2] != 99f) { - if (num464 > 800f) + if (sawArmIdleDistance > 800f) npc.ai[2] = 99f; } - else if (num464 < 400f) + else if (sawArmIdleDistance < 400f) npc.ai[2] = 0f; npc.spriteDirection = -(int)npc.ai[0]; @@ -1646,19 +1644,19 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.velocity.X = -velocityX; } - Vector2 vector52 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num468 = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - vector52.X; - float num469 = Main.npc[(int)npc.ai[1]].position.Y + 230f - vector52.Y; - npc.rotation = (float)Math.Atan2(num469, num468) + MathHelper.PiOver2; + Vector2 sawArmReelbackCurrentPos = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float sawArmReelbackXDest = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - sawArmReelbackCurrentPos.X; + float sawArmReelbackYDest = Main.npc[(int)npc.ai[1]].position.Y + 230f - sawArmReelbackCurrentPos.Y; + npc.rotation = (float)Math.Atan2(sawArmReelbackYDest, sawArmReelbackXDest) + MathHelper.PiOver2; return false; } if (npc.ai[2] == 1f) { - Vector2 vector53 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num471 = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - vector53.X; - float num472 = Main.npc[(int)npc.ai[1]].position.Y + 230f - vector53.Y; - npc.rotation = (float)Math.Atan2(num472, num471) + MathHelper.PiOver2; + Vector2 sawArmChargePos = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float sawArmChargeTargetX = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - sawArmChargePos.X; + float sawArmChargeTargetY = Main.npc[(int)npc.ai[1]].position.Y + 230f - sawArmChargePos.Y; + npc.rotation = (float)Math.Atan2(sawArmChargeTargetY, sawArmChargeTargetX) + MathHelper.PiOver2; npc.velocity.X *= 0.95f; npc.velocity.Y -= 0.5f; @@ -1677,13 +1675,13 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.ai[2] = 2f; npc.TargetClosest(); - vector53 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - num471 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - vector53.X; - num472 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - vector53.Y; - float num473 = (float)Math.Sqrt(num471 * num471 + num472 * num472); - num473 = chargeVelocity / num473; - npc.velocity.X = num471 * num473; - npc.velocity.Y = num472 * num473; + sawArmChargePos = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + sawArmChargeTargetX = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - sawArmChargePos.X; + sawArmChargeTargetY = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - sawArmChargePos.Y; + float sawArmChargeTargetDist = (float)Math.Sqrt(sawArmChargeTargetX * sawArmChargeTargetX + sawArmChargeTargetY * sawArmChargeTargetY); + sawArmChargeTargetDist = chargeVelocity / sawArmChargeTargetDist; + npc.velocity.X = sawArmChargeTargetX * sawArmChargeTargetDist; + npc.velocity.Y = sawArmChargeTargetY * sawArmChargeTargetDist; npc.netUpdate = true; } } @@ -1706,37 +1704,37 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses if (!viceAlive) chargeVelocity += 1.5f; - Vector2 vector54 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - float num474 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - vector54.X; - float num475 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - vector54.Y; - float num476 = (float)Math.Sqrt(num474 * num474 + num475 * num475); - num476 = chargeVelocity / num476; - num474 *= num476; - num475 *= num476; + Vector2 sawArmOtherChargePos = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + float sawArmOtherChargeTargetX = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - sawArmOtherChargePos.X; + float sawArmOtherChargeTargetY = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - sawArmOtherChargePos.Y; + float sawArmOtherChargeTargetDist = (float)Math.Sqrt(sawArmOtherChargeTargetX * sawArmOtherChargeTargetX + sawArmOtherChargeTargetY * sawArmOtherChargeTargetY); + sawArmOtherChargeTargetDist = chargeVelocity / sawArmOtherChargeTargetDist; + sawArmOtherChargeTargetX *= sawArmOtherChargeTargetDist; + sawArmOtherChargeTargetY *= sawArmOtherChargeTargetDist; float acceleration = bossRush ? 0.3f : death ? 0.1f : 0.08f; - if (npc.velocity.X > num474) + if (npc.velocity.X > sawArmOtherChargeTargetX) { if (npc.velocity.X > 0f) npc.velocity.X *= 0.9f; npc.velocity.X -= acceleration; } - if (npc.velocity.X < num474) + if (npc.velocity.X < sawArmOtherChargeTargetX) { if (npc.velocity.X < 0f) npc.velocity.X *= 0.9f; npc.velocity.X += acceleration; } - if (npc.velocity.Y > num475) + if (npc.velocity.Y > sawArmOtherChargeTargetY) { if (npc.velocity.Y > 0f) npc.velocity.Y *= 0.9f; npc.velocity.Y -= acceleration; } - if (npc.velocity.Y < num475) + if (npc.velocity.Y < sawArmOtherChargeTargetY) { if (npc.velocity.Y < 0f) npc.velocity.Y *= 0.9f; @@ -1756,10 +1754,10 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.netUpdate = true; } - vector54 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); - num474 = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - vector54.X; - num475 = Main.npc[(int)npc.ai[1]].position.Y + 230f - vector54.Y; - npc.rotation = (float)Math.Atan2(num475, num474) + MathHelper.PiOver2; + sawArmOtherChargePos = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); + sawArmOtherChargeTargetX = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - 200f * npc.ai[0] - sawArmOtherChargePos.X; + sawArmOtherChargeTargetY = Main.npc[(int)npc.ai[1]].position.Y + 230f - sawArmOtherChargePos.Y; + npc.rotation = (float)Math.Atan2(sawArmOtherChargeTargetY, sawArmOtherChargeTargetX) + MathHelper.PiOver2; return false; }