From bf6fe988623ecd4cccd42562a5485fe06d66978b Mon Sep 17 00:00:00 2001 From: mountaindrew10 Date: Sat, 10 May 2025 07:10:52 -0500 Subject: [PATCH] Just some refactoring. --- NPCs/CalamityAIs/CalamityBossAIs/OldDukeAI.cs | 38 +++++++++---------- NPCs/OldDuke/OldDuke.cs | 38 ++++++++----------- 2 files changed, 32 insertions(+), 44 deletions(-) diff --git a/NPCs/CalamityAIs/CalamityBossAIs/OldDukeAI.cs b/NPCs/CalamityAIs/CalamityBossAIs/OldDukeAI.cs index b63cffdceb..281d6b94ab 100644 --- a/NPCs/CalamityAIs/CalamityBossAIs/OldDukeAI.cs +++ b/NPCs/CalamityAIs/CalamityBossAIs/OldDukeAI.cs @@ -20,7 +20,6 @@ using CalamityMod.NPCs.SunkenSea; using CalamityMod.Particles; using CalamityMod.Projectiles.Boss; using CalamityMod.Projectiles.Enemy; -using CalamityMod.Rarities; using CalamityMod.Sounds; using CalamityMod.Systems; using CalamityMod.World; @@ -29,7 +28,6 @@ using Terraria; using Terraria.Audio; using Terraria.ID; using Terraria.ModLoader; -using static tModPorter.ProgressUpdate; namespace CalamityMod.NPCs.CalamityAIs.CalamityBossAIs { @@ -58,8 +56,8 @@ namespace CalamityMod.NPCs.CalamityAIs.CalamityBossAIs float numberOfAttacksBeforeExhaustion = 12f; float exhaustionIncreasePerAttack = exhaustionGateValue * (1f / numberOfAttacksBeforeExhaustion); bool exhausted = calamityGlobalNPC.newAI[1] == 1f; - bool phase2 = lifeRatio <= (death ? 0.8f : revenge ? 0.7f : 0.5f); - bool phase3 = lifeRatio <= (death ? 0.5f : (revenge ? 0.35f : 0.2f)) && expertMode; + bool phase2 = lifeRatio <= (death ? OldDuke.OldDuke.LifePercentagePhase2_Death : revenge ? OldDuke.OldDuke.LifePercentagePhase2_Revenge : OldDuke.OldDuke.LifePercentagePhase2_Normal); + bool phase3 = lifeRatio <= (death ? OldDuke.OldDuke.LifePercentagePhase3_Death : (revenge ? OldDuke.OldDuke.LifePercentagePhase3_Revenge : OldDuke.OldDuke.LifePercentagePhase3_Expert)) && expertMode; bool phase2AI = npc.ai[0] > 4f; bool phase3AI = npc.ai[0] > 9f; @@ -462,15 +460,14 @@ namespace CalamityMod.NPCs.CalamityAIs.CalamityBossAIs SoundEngine.PlaySound(OldDuke.OldDuke.DashSoundP3, npc.Center); } - if (npc.ai[2] >= 75) + if (npc.ai[2] >= 75f) { - float sd = 1f; - if (player.Center.X > npc.Center.X) sd = -1f; + float sd = player.Center.X > npc.Center.X ? -1f : 1f; (npc.ModNPC as OldDuke.OldDuke).shake = 2f; npc.rotation = MathHelper.Lerp(MathHelper.WrapAngle(npc.rotation), MathHelper.ToRadians(sd == 1f ? 75f : -75f), 0.2f); - if (npc.ai[2] % 5 == 1) + if (npc.ai[2] % 5f == 1f) { Vector2 mouthCenter = npc.Center + new Vector2(-80 * sd, 0).RotatedBy(npc.rotation); @@ -483,7 +480,7 @@ namespace CalamityMod.NPCs.CalamityAIs.CalamityBossAIs } npc.ai[2] += 1f; - if (npc.ai[2] >= 125) + if (npc.ai[2] >= 125f) { npc.ai[0] = 0f; npc.ai[1] = 0f; @@ -653,12 +650,12 @@ namespace CalamityMod.NPCs.CalamityAIs.CalamityBossAIs // Spawn dust Vector2 vel = npc.velocity; vel.Normalize(); - vel *= 55; + vel *= 55f; DoChargeVisual(npc, phase); - GeneralParticleHandler.SpawnParticle(new SparkParticle(npc.Center + vel + vel.RotatedBy(MathHelper.ToRadians(90)), vel / 7, false, 20, 0.75f, new Color(155, 155, 155, 55), true)); - GeneralParticleHandler.SpawnParticle(new SparkParticle(npc.Center + vel + vel.RotatedBy(MathHelper.ToRadians(-90)), vel / 7, false, 20, 0.75f, new Color(155, 155, 155, 55), true)); + GeneralParticleHandler.SpawnParticle(new SparkParticle(npc.Center + vel + vel.RotatedBy(MathHelper.ToRadians(90)), vel / 7f, false, 20, 0.75f, new Color(155, 155, 155, 55), true)); + GeneralParticleHandler.SpawnParticle(new SparkParticle(npc.Center + vel + vel.RotatedBy(MathHelper.ToRadians(-90)), vel / 7f, false, 20, 0.75f, new Color(155, 155, 155, 55), true)); npc.ai[2] += 1f; if (npc.ai[2] >= chargeTime) @@ -1656,9 +1653,7 @@ namespace CalamityMod.NPCs.CalamityAIs.CalamityBossAIs } if (SoundEngine.TryGetActiveSound(modNPC.RoarSoundSlot, out var roarSound) && roarSound.IsPlaying) - { roarSound.Position = npc.Center; - } } static Color FireGreen = new Color(155, 255, 55); @@ -1671,18 +1666,19 @@ namespace CalamityMod.NPCs.CalamityAIs.CalamityBossAIs { for (int i = 0; i < 30; i++) { - float fl = Main.rand.NextFloat(-60, 60); - GeneralParticleHandler.SpawnParticle(new SparkParticle(npc.Center + (Vector2.Zero.DirectionTo(npc.velocity) * 20) + new Vector2(0, fl).RotatedBy(Vector2.Zero.AngleTo(npc.velocity)), (-npc.velocity * Main.rand.NextFloat(2f)).RotatedBy(MathHelper.ToRadians(fl)), false, 25, Main.rand.NextFloat(0.3f, 1.2f), FireGreen)); + float fl = Main.rand.NextFloat(-60f, 60f); + GeneralParticleHandler.SpawnParticle(new SparkParticle(npc.Center + (Vector2.Zero.DirectionTo(npc.velocity) * 20f) + new Vector2(0f, fl).RotatedBy(Vector2.Zero.AngleTo(npc.velocity)), (-npc.velocity * Main.rand.NextFloat(2f)).RotatedBy(MathHelper.ToRadians(fl)), false, 25, Main.rand.NextFloat(0.3f, 1.2f), FireGreen)); } - CalamityUtils.AddScreenshakeAt(npc.Center, 10, 3000); + CalamityUtils.AddScreenshakeAt(npc.Center, 10f, 3000f); SoundEngine.PlaySound(SoundID.DD2_BetsyFireballImpact, npc.Center); SoundEngine.PlaySound(SoundID.DD2_BetsyFireballShot, npc.Center); - GeneralParticleHandler.SpawnParticle(new CustomPulse(npc.Center, -npc.velocity / 3, FireGreen, "CalamityMod/Particles/DustyCircleHardEdge", new Vector2(0.4f, 1.2f), Vector2.Zero.AngleTo(npc.velocity) + (Main.rand.NextBool() ? 0 : -MathHelper.Pi), 0.05f, 0.2f, 20)); - GeneralParticleHandler.SpawnParticle(new CustomPulse(npc.Center, -npc.velocity / 2, FireGreen, "CalamityMod/Particles/FlameExplosion", new Vector2(0.4f, 1.2f), Vector2.Zero.AngleTo(npc.velocity) + (Main.rand.NextBool() ? 0 : -MathHelper.Pi), 0.1f, 0.4f, 20)); + GeneralParticleHandler.SpawnParticle(new CustomPulse(npc.Center, -npc.velocity / 3f, FireGreen, "CalamityMod/Particles/DustyCircleHardEdge", new Vector2(0.4f, 1.2f), Vector2.Zero.AngleTo(npc.velocity) + (Main.rand.NextBool() ? 0 : -MathHelper.Pi), 0.05f, 0.2f, 20)); + GeneralParticleHandler.SpawnParticle(new CustomPulse(npc.Center, -npc.velocity / 2f, FireGreen, "CalamityMod/Particles/FlameExplosion", new Vector2(0.4f, 1.2f), Vector2.Zero.AngleTo(npc.velocity) + (Main.rand.NextBool() ? 0 : -MathHelper.Pi), 0.1f, 0.4f, 20)); } } + static void DoChargeVisual(NPC npc, int phase) { float progress = npc.ai[2]; @@ -1694,13 +1690,13 @@ namespace CalamityMod.NPCs.CalamityAIs.CalamityBossAIs if (phase > 1) { if (Math.Floor(VisualTimerSystem.GlobalVisualTimer % 6f) < 1f) - GeneralParticleHandler.SpawnParticle(new CustomPulse(npc.Center, npc.velocity / 3, col, "CalamityMod/Particles/DustyCircleHardEdge", new Vector2(0.4f, 1f), Vector2.Zero.AngleTo(npc.velocity) + (Main.rand.NextBool() ? 0 : -MathHelper.Pi), 0.04f, 0.1f, 20)); + GeneralParticleHandler.SpawnParticle(new CustomPulse(npc.Center, npc.velocity / 3f, col, "CalamityMod/Particles/DustyCircleHardEdge", new Vector2(0.4f, 1f), Vector2.Zero.AngleTo(npc.velocity) + (Main.rand.NextBool() ? 0 : -MathHelper.Pi), 0.04f, 0.1f, 20)); (npc.ModNPC as OldDuke.OldDuke).NuclearOverlayVisual = 1f; } if (Main.rand.NextBool()) - GeneralParticleHandler.SpawnParticle(new CustomSpark(npc.Center - (npc.velocity * 2), npc.velocity / 2, "CalamityMod/Particles/ForwardSmear", false, 10, Main.rand.NextFloat(0.3f, 0.5f), col, new Vector2(1f, Main.rand.NextFloat(1.45f, 1.6f)), fadeIn: true, extraRotation: MathHelper.ToRadians(180f))); + GeneralParticleHandler.SpawnParticle(new CustomSpark(npc.Center - (npc.velocity * 2f), npc.velocity / 2f, "CalamityMod/Particles/ForwardSmear", false, 10, Main.rand.NextFloat(0.3f, 0.5f), col, new Vector2(1f, Main.rand.NextFloat(1.45f, 1.6f)), fadeIn: true, extraRotation: MathHelper.ToRadians(180f))); } } } diff --git a/NPCs/OldDuke/OldDuke.cs b/NPCs/OldDuke/OldDuke.cs index 17639bf057..88e48e8dbe 100644 --- a/NPCs/OldDuke/OldDuke.cs +++ b/NPCs/OldDuke/OldDuke.cs @@ -42,6 +42,14 @@ namespace CalamityMod.NPCs.OldDuke { public static Color GlowColor = new Color(55, 255, 25, 0); + // Old Duke doesn't have a phase 3 in normal mode + public const float LifePercentagePhase2_Normal = 0.5f; + public const float LifePercentagePhase2_Revenge = 0.7f; + public const float LifePercentagePhase2_Death = 0.8f; + public const float LifePercentagePhase3_Expert = 0.2f; + public const float LifePercentagePhase3_Revenge = 0.35f; + public const float LifePercentagePhase3_Death = 0.5f; + public int Phase = 0; public float NuclearOverlayVisual = 0f; @@ -146,21 +154,11 @@ namespace CalamityMod.NPCs.OldDuke bool revenge = CalamityWorld.revenge || bossRush; bool death = CalamityWorld.death || bossRush; - bool phase2 = lifeRatio <= (death ? 0.8f : revenge ? 0.7f : 0.5f); - bool phase3 = lifeRatio <= (death ? 0.5f : (revenge ? 0.35f : 0.2f)) && expertMode; - - if (phase3) Phase = 2; - else if (phase2) Phase = 1; - else Phase = 0; - - if (Phase == 2 && NPC.Calamity().newAI[1] != 1) - { - NuclearOverlayVisual = MathHelper.Lerp(NuclearOverlayVisual, 0.2f, 0.2f); - } - else - { - NuclearOverlayVisual = MathHelper.Lerp(NuclearOverlayVisual, 0f, 0.1f); - } + bool phase2 = lifeRatio <= (death ? LifePercentagePhase2_Death : revenge ? LifePercentagePhase2_Revenge : LifePercentagePhase2_Normal); + bool phase3 = lifeRatio <= (death ? LifePercentagePhase3_Death : (revenge ? LifePercentagePhase3_Revenge : LifePercentagePhase3_Expert)) && expertMode; + + Phase = phase3 ? 2 : phase2 ? 1 : 0; + NuclearOverlayVisual = (Phase == 2 && NPC.Calamity().newAI[1] != 1) ? MathHelper.Lerp(NuclearOverlayVisual, 0.2f, 0.2f) : MathHelper.Lerp(NuclearOverlayVisual, 0f, 0.1f); OldDukeAI.VanillaOldDukeAI(NPC, Mod); } @@ -248,10 +246,8 @@ namespace CalamityMod.NPCs.OldDuke if (NPC.ai[0] == -1f) { - if (NPC.ai[2] >= 75) - { + if (NPC.ai[2] >= 75f) NPC.frame.Y = frameHeight * 6; - } } } @@ -334,9 +330,7 @@ namespace CalamityMod.NPCs.OldDuke float afterimageScale = 0f; if (NPC.ai[0] == -1f) - { secondAfterimageAmt = 0; - } if (NPC.ai[0] == 3f || NPC.ai[0] == 8f || NPC.ai[0] == 13f) { @@ -387,10 +381,8 @@ namespace CalamityMod.NPCs.OldDuke spriteBatch.Draw(texture2D15, drawLocation, NPC.frame, NPC.GetAlpha(overlayDrawColor), NPC.rotation, halfSizeTexture, NPC.scale, spriteEffects, 0f); float auraOutset = 6f + (float)(Math.Sin(VisualTimerSystem.GlobalVisualTimer / 10f) * 10f); - for (float i = 0; i < 360; i+=90) - { + for (float i = 0f; i < 360f; i += 90f) spriteBatch.Draw(texture2D15, drawLocation + new Vector2(auraOutset, 0).RotatedBy(MathHelper.ToRadians(i)), NPC.frame, NPC.GetAlpha(overlayDrawColor.MultiplyRGBA(new Color(0.4f, 0.4f, 0.4f, 0.4f))), NPC.rotation, halfSizeTexture, NPC.scale, spriteEffects, 0f); - } if (NPC.ai[0] >= 4f && NPC.Calamity().newAI[1] != 1f) {