From 36c4405d04e1d7617bf23be6820d6679e20d1591 Mon Sep 17 00:00:00 2001 From: Andrew Marheine Date: Wed, 15 Sep 2021 00:00:18 -0500 Subject: [PATCH 1/2] 1 - Infinite loop fix. --- NPCs/ExoMechs/Apollo/Apollo.cs | 2 +- NPCs/ExoMechs/Artemis/Artemis.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NPCs/ExoMechs/Apollo/Apollo.cs b/NPCs/ExoMechs/Apollo/Apollo.cs index a625ff22f2..4dfe9f5dc0 100644 --- a/NPCs/ExoMechs/Apollo/Apollo.cs +++ b/NPCs/ExoMechs/Apollo/Apollo.cs @@ -786,7 +786,7 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo for (int i = 0; i < Main.maxNPCs; i++) { NPC nPC = Main.npc[i]; - if (nPC.active && nPC.type == ModContent.NPCType()) + if (nPC.active && nPC.type == ModContent.NPCType() && nPC.life > 0) { nPC.life = 0; nPC.HitEffect(0, 10.0); diff --git a/NPCs/ExoMechs/Artemis/Artemis.cs b/NPCs/ExoMechs/Artemis/Artemis.cs index 61d60df768..d0bf69cbcf 100644 --- a/NPCs/ExoMechs/Artemis/Artemis.cs +++ b/NPCs/ExoMechs/Artemis/Artemis.cs @@ -1096,7 +1096,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis for (int i = 0; i < Main.maxNPCs; i++) { NPC nPC = Main.npc[i]; - if (nPC.active && nPC.type == ModContent.NPCType()) + if (nPC.active && nPC.type == ModContent.NPCType() && nPC.life > 0) { nPC.life = 0; nPC.HitEffect(0, 10.0); From 3c7978a21eb9c99e66089bb44cdb1392e7bc9273 Mon Sep 17 00:00:00 2001 From: Andrew Marheine Date: Wed, 15 Sep 2021 03:57:31 -0500 Subject: [PATCH 2/2] 1 - Artemis and Apollo edits and other misc edits to exo mechs. --- NPCs/ExoMechs/Apollo/Apollo.cs | 267 +++++++++++++------ NPCs/ExoMechs/Ares/AresBody.cs | 2 - NPCs/ExoMechs/Ares/AresGaussNuke.cs | 2 - NPCs/ExoMechs/Ares/AresLaserCannon.cs | 2 - NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.cs | 2 - NPCs/ExoMechs/Ares/AresTeslaCannon.cs | 2 - NPCs/ExoMechs/Artemis/Artemis.cs | 115 ++++++-- NPCs/ExoMechs/Thanatos/ThanatosHead.cs | 2 +- 8 files changed, 277 insertions(+), 117 deletions(-) diff --git a/NPCs/ExoMechs/Apollo/Apollo.cs b/NPCs/ExoMechs/Apollo/Apollo.cs index 4dfe9f5dc0..3afaf4f50b 100644 --- a/NPCs/ExoMechs/Apollo/Apollo.cs +++ b/NPCs/ExoMechs/Apollo/Apollo.cs @@ -37,8 +37,9 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo { Normal = 0, RocketBarrage = 1, - ChargeCombo = 2, - PhaseTransition = 3 + LineUpChargeCombo = 2, + ChargeCombo = 3, + PhaseTransition = 4 } public float AIState @@ -83,11 +84,21 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo // Max distance from the target before they are unable to hear sound telegraphs private const float soundDistance = 2800f; - // Total duration of attack telegraphs - public const float attackTelegraphDuration = 100f; + // Normal animation duration + private const float defaultAnimationDuration = 60f; // Total duration of the phase transition - public const float phaseTransitionDuration = 300f; + private const float phaseTransitionDuration = 180f; + + // Where the timer should be when the lens pops off + private const float lensPopTime = 48f; + + // Variable to pick a different location after each attack + private bool pickNewLocation = false; + + // Charge locations during the charge combo + private const int maxCharges = 4; + public Vector2[] chargeLocations = new Vector2[maxCharges] { default, default, default, default }; public override void SetStaticDefaults() { @@ -131,20 +142,36 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo public override void SendExtraAI(BinaryWriter writer) { - writer.Write(npc.chaseable); + writer.Write(frameX); + writer.Write(frameY); + writer.Write(pickNewLocation); writer.Write(npc.dontTakeDamage); writer.Write(npc.localAI[0]); + writer.Write(npc.localAI[1]); + writer.Write(npc.localAI[2]); + writer.Write(npc.localAI[3]); for (int i = 0; i < 4; i++) + { writer.Write(npc.Calamity().newAI[i]); + writer.WriteVector2(chargeLocations[i]); + } } public override void ReceiveExtraAI(BinaryReader reader) { - npc.chaseable = reader.ReadBoolean(); + frameX = reader.ReadInt32(); + frameY = reader.ReadInt32(); + pickNewLocation = reader.ReadBoolean(); npc.dontTakeDamage = reader.ReadBoolean(); npc.localAI[0] = reader.ReadSingle(); + npc.localAI[1] = reader.ReadSingle(); + npc.localAI[2] = reader.ReadSingle(); + npc.localAI[3] = reader.ReadSingle(); for (int i = 0; i < 4; i++) + { npc.Calamity().newAI[i] = reader.ReadSingle(); + chargeLocations[i] = reader.ReadVector2(); + } } public override void AI() @@ -159,6 +186,17 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo bool revenge = CalamityWorld.revenge || malice; bool expertMode = Main.expertMode || malice; + // Get a target + if (npc.target < 0 || npc.target == Main.maxPlayers || Main.player[npc.target].dead || !Main.player[npc.target].active) + npc.TargetClosest(); + + // Despawn safety, make sure to target another player if the current player target is too far away + if (Vector2.Distance(Main.player[npc.target].Center, npc.Center) > CalamityGlobalNPC.CatchUpDistance200Tiles) + npc.TargetClosest(); + + // Target variable + Player player = Main.player[npc.target]; + // Check if the other exo mechs are alive int otherExoMechsAlive = 0; bool exoWormAlive = false; @@ -207,29 +245,30 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo if (exoWormAlive) exoWormPassive = Main.npc[CalamityGlobalNPC.draedonExoMechWorm].Calamity().newAI[1] == (float)ThanatosHead.SecondaryPhase.Passive; if (exoPrimeAlive) - exoPrimePassive = Main.npc[CalamityGlobalNPC.draedonExoMechTwinRed].Calamity().newAI[1] == (float)AresBody.SecondaryPhase.Passive; + exoPrimePassive = Main.npc[CalamityGlobalNPC.draedonExoMechPrime].Calamity().newAI[1] == (float)AresBody.SecondaryPhase.Passive; bool anyOtherExoMechPassive = exoWormPassive || exoPrimePassive; + // Check if any of the other mechs were spawned first + bool exoWormWasFirst = false; + bool exoPrimeWasFirst = false; + if (exoWormAlive) + exoWormWasFirst = Main.npc[CalamityGlobalNPC.draedonExoMechWorm].ai[3] == 1f; + if (exoPrimeAlive) + exoPrimeWasFirst = Main.npc[CalamityGlobalNPC.draedonExoMechPrime].ai[3] == 1f; + bool otherExoMechWasFirst = exoWormWasFirst || exoPrimeWasFirst; + + // Prevent mechs from being respawned + if (otherExoMechWasFirst) + npc.ai[3] = 1f; + // Phases bool phase2 = lifeRatio < 0.6f; - bool spawnOtherExoMechs = lifeRatio > 0.4f && otherExoMechsAlive == 0 && lifeRatio < 0.7f; bool berserk = lifeRatio < 0.4f || (otherExoMechsAlive == 0 && lifeRatio < 0.7f); bool lastMechAlive = berserk && otherExoMechsAlive == 0; // If Artemis and Apollo don't go berserk bool otherMechIsBerserk = exoWormLifeRatio < 0.4f || exoPrimeLifeRatio < 0.4f; - // Get a target - if (npc.target < 0 || npc.target == Main.maxPlayers || Main.player[npc.target].dead || !Main.player[npc.target].active) - npc.TargetClosest(); - - // Despawn safety, make sure to target another player if the current player target is too far away - if (Vector2.Distance(Main.player[npc.target].Center, npc.Center) > CalamityGlobalNPC.CatchUpDistance200Tiles) - npc.TargetClosest(); - - // Target variable - Player player = Main.player[npc.target]; - // Spawn Artemis if it doesn't exist after the first 10 frames have passed if (npc.ai[0] < 10f) { @@ -238,39 +277,6 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); } - // Despawn if target is dead - bool targetDead = false; - if (player.dead) - { - npc.TargetClosest(false); - player = Main.player[npc.target]; - if (player.dead) - { - targetDead = true; - - AIState = (float)Phase.Normal; - calamityGlobalNPC.newAI[2] = 0f; - calamityGlobalNPC.newAI[3] = 0f; - - npc.velocity.Y -= 2f; - if ((double)npc.position.Y < Main.topWorld + 16f) - npc.velocity.Y -= 2f; - - if ((double)npc.position.Y < Main.topWorld + 16f) - { - for (int a = 0; a < Main.maxNPCs; a++) - { - if (Main.npc[a].type == npc.type || Main.npc[a].type == ModContent.NPCType() || Main.npc[a].type == ModContent.NPCType() || - Main.npc[a].type == ModContent.NPCType() || Main.npc[a].type == ModContent.NPCType() || - Main.npc[a].type == ModContent.NPCType() || Main.npc[a].type == ModContent.NPCType() || - Main.npc[a].type == ModContent.NPCType() || Main.npc[a].type == ModContent.NPCType() || - Main.npc[a].type == ModContent.NPCType() || Main.npc[a].type == ModContent.NPCType()) - Main.npc[a].active = false; - } - } - } - } - // General AI pattern // 0 - Fly to the right of the target and fire plasma when ready // 1 - Fly to the right of the target and fire homing rockets, the rockets home in until close to the target and then fly off in the direction they were moving in @@ -302,7 +308,7 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo // Adjust opacity bool invisiblePhase = SecondaryAIState == (float)SecondaryPhase.PassiveAndImmune; - npc.dontTakeDamage = invisiblePhase; + npc.dontTakeDamage = invisiblePhase || AIState == (float)Phase.PhaseTransition; if (!invisiblePhase) { npc.Opacity += 0.2f; @@ -321,45 +327,145 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo if (SecondaryAIState == (int)SecondaryPhase.Passive) predictionAmt *= 0.5f; - Vector2 predictionVector = AIState == (int)Phase.RocketBarrage ? Vector2.Zero : player.velocity * predictionAmt; + // Gate values + float attackPhaseGateValue = lastMechAlive ? 300f : 480f; + float timeToLineUpAttack = lastMechAlive ? 20f : 30f; - // Rotation - if (AIState == (int)Phase.ChargeCombo) - { - npc.rotation = npc.velocity.ToRotation() + MathHelper.PiOver2; - } - else - { - float x = player.Center.X + predictionVector.X - npc.Center.X; - float y = player.Center.Y + predictionVector.Y - npc.Center.Y; - npc.rotation = (float)Math.Atan2(y, x) + MathHelper.PiOver2; - } - - // Light - Lighting.AddLight(npc.Center, 0.05f, 0.25f, 0.15f); - - // Default vector to fly to - Vector2 destination = SecondaryAIState == (float)SecondaryPhase.PassiveAndImmune ? new Vector2(player.Center.X + 1200f, player.Center.Y) : AIState == (float)Phase.ChargeCombo ? new Vector2(player.Center.X, player.Center.Y + 500f) : new Vector2(player.Center.X + 750f, player.Center.Y); + // Distance where Apollo stops moving + float movementDistanceGateValue = 100f; // Velocity and acceleration values float baseVelocityMult = malice ? 1.3f : death ? 1.2f : revenge ? 1.15f : expertMode ? 1.1f : 1f; float baseVelocity = 14f * baseVelocityMult; float baseAcceleration = 1f; - float decelerationVelocityMult = 0.85f; if (berserk) { baseVelocity *= 1.5f; baseAcceleration *= 1.5f; } + + // Charge variables + float chargeVelocity = malice ? 90f : death ? 80f : revenge ? 75f : expertMode ? 70f : 60f; + float chargeDistance = 1500f; + float chargeDuration = chargeDistance / chargeVelocity; + bool lineUpAttack = calamityGlobalNPC.newAI[3] >= attackPhaseGateValue + 2f; + bool doBigAttack = calamityGlobalNPC.newAI[3] >= attackPhaseGateValue + 2f + timeToLineUpAttack; + + // Rocket phase variables + float rocketPhaseDuration = lastMechAlive ? 60f : 90f; + + // Rotation + Vector2 predictionVector = player.velocity * predictionAmt; + Vector2 aimedVector = player.Center + predictionVector - npc.Center; + float rateOfRotation = 0.1f; + Vector2 rotateTowards = player.Center - npc.Center; + bool stopRotatingAndSlowDown = AIState == (float)Phase.LineUpChargeCombo && calamityGlobalNPC.newAI[2] >= timeToLineUpAttack; + if (!stopRotatingAndSlowDown) + { + if (AIState == (int)Phase.ChargeCombo) + { + rateOfRotation = 0f; + npc.rotation = npc.velocity.ToRotation() + MathHelper.PiOver2; + } + else if (AIState == (float)Phase.LineUpChargeCombo && chargeLocations[1] != default) + { + float x = chargeLocations[1].X - npc.Center.X; + float y = chargeLocations[1].Y - npc.Center.Y; + rotateTowards = Vector2.Normalize(new Vector2(x, y)) * baseVelocity; + } + else + { + float x = player.Center.X + predictionVector.X - npc.Center.X; + float y = player.Center.Y + predictionVector.Y - npc.Center.Y; + rotateTowards = Vector2.Normalize(new Vector2(x, y)) * baseVelocity; + } + + // Do not set this during charge or deathray phases + if (rateOfRotation != 0f) + npc.rotation = npc.rotation.AngleTowards((float)Math.Atan2(rotateTowards.Y, rotateTowards.X) + MathHelper.PiOver2, rateOfRotation); + } + + // Light + Lighting.AddLight(npc.Center, 0.05f * npc.Opacity, 0.25f * npc.Opacity, 0.15f * npc.Opacity); + + // Despawn if target is dead + if (player.dead) + { + npc.TargetClosest(false); + player = Main.player[npc.target]; + if (player.dead) + { + AIState = (float)Phase.Normal; + npc.localAI[0] = 0f; + npc.localAI[1] = 0f; + npc.localAI[2] = 0f; + calamityGlobalNPC.newAI[2] = 0f; + calamityGlobalNPC.newAI[3] = 0f; + npc.dontTakeDamage = true; + + npc.velocity.Y -= 2f; + if ((double)npc.position.Y < Main.topWorld + 16f) + npc.velocity.Y -= 2f; + + if ((double)npc.position.Y < Main.topWorld + 16f) + { + for (int a = 0; a < Main.maxNPCs; a++) + { + if (Main.npc[a].type == npc.type || Main.npc[a].type == ModContent.NPCType() || Main.npc[a].type == ModContent.NPCType() || + Main.npc[a].type == ModContent.NPCType() || Main.npc[a].type == ModContent.NPCType() || + Main.npc[a].type == ModContent.NPCType() || Main.npc[a].type == ModContent.NPCType() || + Main.npc[a].type == ModContent.NPCType() || Main.npc[a].type == ModContent.NPCType() || + Main.npc[a].type == ModContent.NPCType() || Main.npc[a].type == ModContent.NPCType()) + Main.npc[a].active = false; + } + } + + return; + } + } + + // Add some random distance to the destination after certain attacks + if (pickNewLocation) + { + pickNewLocation = false; + npc.localAI[0] = Main.rand.Next(-50, 51); + npc.localAI[1] = Main.rand.Next(-250, 251); + npc.netUpdate = true; + } + + // Default vector to fly to + float chargeComboYOffeset = npc.ai[2] == 0f ? 400f : -400f; + Vector2 destination = SecondaryAIState == (float)SecondaryPhase.PassiveAndImmune ? new Vector2(player.Center.X + 1200f, player.Center.Y) : AIState == (float)Phase.LineUpChargeCombo ? new Vector2(player.Center.X + 750f, player.Center.Y + chargeComboYOffeset) : new Vector2(player.Center.X + 750f, player.Center.Y); + + // Add a bit of randomness to the destination, but only in specific phases where it's necessary + if (AIState == (float)Phase.Normal || AIState == (float)Phase.RocketBarrage || AIState == (float)Phase.PhaseTransition) + { + destination.X += npc.localAI[0]; + destination.Y += npc.localAI[1]; + } + + // Destination variables Vector2 distanceFromDestination = destination - npc.Center; Vector2 desiredVelocity = Vector2.Normalize(distanceFromDestination) * baseVelocity; - // Distance where Apollo stops moving - float movementDistanceGateValue = 100f; + // Set to transition to phase 2 if it hasn't happened yet + if (phase2 && npc.localAI[3] == 0f) + { + AIState = (float)Phase.PhaseTransition; + npc.localAI[3] = 1f; + calamityGlobalNPC.newAI[2] = 0f; + calamityGlobalNPC.newAI[3] = 0f; - // Gate values - float chargePhaseGateValue = lastMechAlive ? 300f : 480f; - float deathrayPhaseGateValue = lastMechAlive ? 630f : 900f; + // Set frames to phase transition frames, which begin on frame 30 + // Reset the frame counter + npc.frameCounter = 0D; + + // X = 3 sets to frame 27 + frameX = 3; + + // Y = 3 sets to frame 30 + frameY = 3; + } // Passive and Immune phases switch ((int)SecondaryAIState) @@ -369,15 +475,16 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo // Spawn the other mechs if Artemis and Apollo are first if (otherExoMechsAlive == 0) { - if (spawnOtherExoMechs) + if (npc.ai[3] == 0f) { // Reset everything + npc.ai[3] = 1f; SecondaryAIState = (float)SecondaryPhase.PassiveAndImmune; npc.TargetClosest(); if (Main.netMode != NetmodeID.MultiplayerClient) { - // Spawn code here + // Spawn the fuckers NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); } diff --git a/NPCs/ExoMechs/Ares/AresBody.cs b/NPCs/ExoMechs/Ares/AresBody.cs index 2643bd928f..a472205002 100644 --- a/NPCs/ExoMechs/Ares/AresBody.cs +++ b/NPCs/ExoMechs/Ares/AresBody.cs @@ -110,7 +110,6 @@ namespace CalamityMod.NPCs.ExoMechs.Ares writer.Write(frameX); writer.Write(frameY); writer.Write(armsSpawned); - writer.Write(npc.chaseable); writer.Write(npc.dontTakeDamage); writer.Write(npc.localAI[0]); for (int i = 0; i < 4; i++) @@ -122,7 +121,6 @@ namespace CalamityMod.NPCs.ExoMechs.Ares frameX = reader.ReadInt32(); frameY = reader.ReadInt32(); armsSpawned = reader.ReadBoolean(); - npc.chaseable = reader.ReadBoolean(); npc.dontTakeDamage = reader.ReadBoolean(); npc.localAI[0] = reader.ReadSingle(); for (int i = 0; i < 4; i++) diff --git a/NPCs/ExoMechs/Ares/AresGaussNuke.cs b/NPCs/ExoMechs/Ares/AresGaussNuke.cs index e802e9c995..b9c34def79 100644 --- a/NPCs/ExoMechs/Ares/AresGaussNuke.cs +++ b/NPCs/ExoMechs/Ares/AresGaussNuke.cs @@ -85,7 +85,6 @@ namespace CalamityMod.NPCs.ExoMechs.Ares { writer.Write(frameX); writer.Write(frameY); - writer.Write(npc.chaseable); writer.Write(npc.dontTakeDamage); for (int i = 0; i < 4; i++) writer.Write(npc.Calamity().newAI[i]); @@ -95,7 +94,6 @@ namespace CalamityMod.NPCs.ExoMechs.Ares { frameX = reader.ReadInt32(); frameY = reader.ReadInt32(); - npc.chaseable = reader.ReadBoolean(); npc.dontTakeDamage = reader.ReadBoolean(); for (int i = 0; i < 4; i++) npc.Calamity().newAI[i] = reader.ReadSingle(); diff --git a/NPCs/ExoMechs/Ares/AresLaserCannon.cs b/NPCs/ExoMechs/Ares/AresLaserCannon.cs index 0d7b4bcf13..89aff1c04a 100644 --- a/NPCs/ExoMechs/Ares/AresLaserCannon.cs +++ b/NPCs/ExoMechs/Ares/AresLaserCannon.cs @@ -83,7 +83,6 @@ namespace CalamityMod.NPCs.ExoMechs.Ares { writer.Write(frameX); writer.Write(frameY); - writer.Write(npc.chaseable); writer.Write(npc.dontTakeDamage); for (int i = 0; i < 4; i++) writer.Write(npc.Calamity().newAI[i]); @@ -93,7 +92,6 @@ namespace CalamityMod.NPCs.ExoMechs.Ares { frameX = reader.ReadInt32(); frameY = reader.ReadInt32(); - npc.chaseable = reader.ReadBoolean(); npc.dontTakeDamage = reader.ReadBoolean(); for (int i = 0; i < 4; i++) npc.Calamity().newAI[i] = reader.ReadSingle(); diff --git a/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.cs b/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.cs index 8a5c395286..5eb5958a3b 100644 --- a/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.cs +++ b/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.cs @@ -83,7 +83,6 @@ namespace CalamityMod.NPCs.ExoMechs.Ares { writer.Write(frameX); writer.Write(frameY); - writer.Write(npc.chaseable); writer.Write(npc.dontTakeDamage); for (int i = 0; i < 4; i++) writer.Write(npc.Calamity().newAI[i]); @@ -93,7 +92,6 @@ namespace CalamityMod.NPCs.ExoMechs.Ares { frameX = reader.ReadInt32(); frameY = reader.ReadInt32(); - npc.chaseable = reader.ReadBoolean(); npc.dontTakeDamage = reader.ReadBoolean(); for (int i = 0; i < 4; i++) npc.Calamity().newAI[i] = reader.ReadSingle(); diff --git a/NPCs/ExoMechs/Ares/AresTeslaCannon.cs b/NPCs/ExoMechs/Ares/AresTeslaCannon.cs index 2d27b84446..0212975f6b 100644 --- a/NPCs/ExoMechs/Ares/AresTeslaCannon.cs +++ b/NPCs/ExoMechs/Ares/AresTeslaCannon.cs @@ -83,7 +83,6 @@ namespace CalamityMod.NPCs.ExoMechs.Ares { writer.Write(frameX); writer.Write(frameY); - writer.Write(npc.chaseable); writer.Write(npc.dontTakeDamage); for (int i = 0; i < 4; i++) writer.Write(npc.Calamity().newAI[i]); @@ -93,7 +92,6 @@ namespace CalamityMod.NPCs.ExoMechs.Ares { frameX = reader.ReadInt32(); frameY = reader.ReadInt32(); - npc.chaseable = reader.ReadBoolean(); npc.dontTakeDamage = reader.ReadBoolean(); for (int i = 0; i < 4; i++) npc.Calamity().newAI[i] = reader.ReadSingle(); diff --git a/NPCs/ExoMechs/Artemis/Artemis.cs b/NPCs/ExoMechs/Artemis/Artemis.cs index d0bf69cbcf..45e68697b1 100644 --- a/NPCs/ExoMechs/Artemis/Artemis.cs +++ b/NPCs/ExoMechs/Artemis/Artemis.cs @@ -156,7 +156,6 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis writer.Write(pickNewLocation); writer.Write(rotationDirection); writer.WriteVector2(spinningPoint); - writer.Write(npc.chaseable); writer.Write(npc.dontTakeDamage); writer.Write(npc.localAI[0]); writer.Write(npc.localAI[1]); @@ -174,7 +173,6 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis pickNewLocation = reader.ReadBoolean(); rotationDirection = reader.ReadInt32(); spinningPoint = reader.ReadVector2(); - npc.chaseable = reader.ReadBoolean(); npc.dontTakeDamage = reader.ReadBoolean(); npc.localAI[0] = reader.ReadSingle(); npc.localAI[1] = reader.ReadSingle(); @@ -343,7 +341,6 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis // Gate values float attackPhaseGateValue = lastMechAlive ? 300f : 480f; float timeToLineUpAttack = lastMechAlive ? 20f : 30f; - float deathrayPhaseGateValue = lastMechAlive ? 630f : 900f; // Spin variables float spinRadius = 500f; @@ -504,6 +501,12 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis // Reset everything npc.ai[3] = 1f; SecondaryAIState = (float)SecondaryPhase.PassiveAndImmune; + npc.localAI[0] = 0f; + npc.localAI[1] = 0f; + npc.localAI[2] = 0f; + calamityGlobalNPC.newAI[2] = 0f; + calamityGlobalNPC.newAI[3] = 0f; + rotationDirection = 0; npc.TargetClosest(); } } @@ -516,6 +519,12 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis { // Tells Artemis to return to the battle in passive state and reset everything SecondaryAIState = (float)SecondaryPhase.Passive; + npc.localAI[0] = 0f; + npc.localAI[1] = 0f; + npc.localAI[2] = 0f; + calamityGlobalNPC.newAI[2] = 0f; + calamityGlobalNPC.newAI[3] = 0f; + rotationDirection = 0; npc.TargetClosest(); } @@ -525,6 +534,12 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis { // Reset everything SecondaryAIState = (float)SecondaryPhase.PassiveAndImmune; + npc.localAI[0] = 0f; + npc.localAI[1] = 0f; + npc.localAI[2] = 0f; + calamityGlobalNPC.newAI[2] = 0f; + calamityGlobalNPC.newAI[3] = 0f; + rotationDirection = 0; npc.TargetClosest(); } } @@ -534,11 +549,20 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis // Fire projectiles less often case (int)SecondaryPhase.Passive: + // Fire lasers while passive + AIState = (float)Phase.Normal; + // Enter passive and invincible phase if one of the other exo mechs is berserk if (otherMechIsBerserk) { // Reset everything SecondaryAIState = (float)SecondaryPhase.PassiveAndImmune; + npc.localAI[0] = 0f; + npc.localAI[1] = 0f; + npc.localAI[2] = 0f; + calamityGlobalNPC.newAI[2] = 0f; + calamityGlobalNPC.newAI[3] = 0f; + rotationDirection = 0; npc.TargetClosest(); } @@ -546,6 +570,12 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis if (berserk) { // Reset everything + npc.localAI[0] = 0f; + npc.localAI[1] = 0f; + npc.localAI[2] = 0f; + calamityGlobalNPC.newAI[2] = 0f; + calamityGlobalNPC.newAI[3] = 0f; + rotationDirection = 0; npc.TargetClosest(); // Never be passive if berserk @@ -557,18 +587,33 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis // Fly above target and become immune case (int)SecondaryPhase.PassiveAndImmune: + // Do nothing while immune + AIState = (float)Phase.Normal; + // Enter the fight again if any of the other exo mechs is below 70% and the other mechs aren't berserk if ((exoWormLifeRatio < 0.7f || exoPrimeLifeRatio < 0.7f) && !otherMechIsBerserk) { // Tells Artemis and Apollo to return to the battle in passive state and reset everything // Return to normal phases if one or more mechs have been downed SecondaryAIState = totalOtherExoMechLifeRatio > 5f ? (float)SecondaryPhase.Nothing : (float)SecondaryPhase.Passive; + npc.localAI[0] = 0f; + npc.localAI[1] = 0f; + npc.localAI[2] = 0f; + calamityGlobalNPC.newAI[2] = 0f; + calamityGlobalNPC.newAI[3] = 0f; + rotationDirection = 0; npc.TargetClosest(); } if (berserk) { // Reset everything + npc.localAI[0] = 0f; + npc.localAI[1] = 0f; + npc.localAI[2] = 0f; + calamityGlobalNPC.newAI[2] = 0f; + calamityGlobalNPC.newAI[3] = 0f; + rotationDirection = 0; npc.TargetClosest(); // Never be passive if berserk @@ -617,7 +662,11 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis // newAI[3] tells Artemis what animation state it's currently in bool attacking = calamityGlobalNPC.newAI[3] >= 2f; bool firingLasers = attacking && calamityGlobalNPC.newAI[3] + 2f < attackPhaseGateValue; - calamityGlobalNPC.newAI[2] += 1f; + + // Only increase attack timer if not in immune phase + if (SecondaryAIState != (float)SecondaryPhase.PassiveAndImmune) + calamityGlobalNPC.newAI[2] += 1f; + if (calamityGlobalNPC.newAI[2] >= defaultAnimationDuration || attacking) { if (firingLasers) @@ -650,31 +699,45 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis calamityGlobalNPC.newAI[3] += 1f; if (lineUpAttack) { - // Draw a large laser telegraph for the charge - if (!phase2 && calamityGlobalNPC.newAI[3] == attackPhaseGateValue + 2f) + // Return to normal laser phase if in passive state + if (SecondaryAIState == (float)SecondaryPhase.Passive) { - if (Main.netMode != NetmodeID.MultiplayerClient) - { - int type = ModContent.ProjectileType(); - Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/LaserCannon"), npc.Center); - Vector2 laserVelocity = Vector2.Normalize(aimedVector); - Vector2 offset = laserVelocity * 50f; - Projectile.NewProjectile(npc.Center + offset, laserVelocity, type, 0, 0f, Main.myPlayer, 0f, npc.whoAmI); - } + pickNewLocation = true; + calamityGlobalNPC.newAI[2] = 0f; + calamityGlobalNPC.newAI[3] = 0f; + chargeVelocityNormalized = default; + npc.TargetClosest(); } - - if (doBigAttack) + else { - if (phase2) + // Draw a large laser telegraph for the charge + if (!phase2 && calamityGlobalNPC.newAI[3] == attackPhaseGateValue + 2f) { - AIState = npc.localAI[2] == 1f ? (float)Phase.Deathray : (float)Phase.LaserShotgun; + if (Main.netMode != NetmodeID.MultiplayerClient) + { + int type = ModContent.ProjectileType(); + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/LaserCannon"), npc.Center); + Vector2 laserVelocity = Vector2.Normalize(aimedVector); + Vector2 offset = laserVelocity * 50f; + Projectile.NewProjectile(npc.Center + offset, laserVelocity, type, 0, 0f, Main.myPlayer, 0f, npc.whoAmI); + } } - else + + if (doBigAttack) { - // Charge until a certain distance is reached and then return to normal phase - AIState = (float)Phase.Charge; - npc.velocity = chargeVelocityNormalized * chargeVelocity; - chargeVelocityNormalized = default; + if (phase2) + { + AIState = npc.localAI[2] == 1f ? (float)Phase.Deathray : (float)Phase.LaserShotgun; + calamityGlobalNPC.newAI[3] = 0f; + } + else + { + // Charge until a certain distance is reached and then return to normal phase + AIState = (float)Phase.Charge; + calamityGlobalNPC.newAI[3] = 0f; + npc.velocity = chargeVelocityNormalized * chargeVelocity; + chargeVelocityNormalized = default; + } } } } @@ -698,7 +761,6 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis pickNewLocation = true; AIState = (float)Phase.Normal; calamityGlobalNPC.newAI[2] = 0f; - calamityGlobalNPC.newAI[3] = 0f; npc.TargetClosest(); } } @@ -760,7 +822,6 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis AIState = (float)Phase.Normal; npc.localAI[2] = berserk ? 1f : 0f; calamityGlobalNPC.newAI[2] = 0f; - calamityGlobalNPC.newAI[3] = 0f; npc.TargetClosest(); } @@ -851,7 +912,6 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis AIState = (float)Phase.Normal; npc.localAI[2] = 0f; calamityGlobalNPC.newAI[2] = 0f; - calamityGlobalNPC.newAI[3] = 0f; npc.TargetClosest(); } @@ -892,7 +952,10 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis { pickNewLocation = true; AIState = (float)Phase.Normal; + npc.localAI[0] = 0f; + npc.localAI[1] = 0f; calamityGlobalNPC.newAI[2] = 0f; + calamityGlobalNPC.newAI[3] = 0f; npc.TargetClosest(); } diff --git a/NPCs/ExoMechs/Thanatos/ThanatosHead.cs b/NPCs/ExoMechs/Thanatos/ThanatosHead.cs index eaee2c647c..cdc64402f6 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosHead.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosHead.cs @@ -549,7 +549,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos // Fly underneath target and become immune case (int)SecondaryPhase.PassiveAndImmune: - // Fire lasers while passive + // Do nothing while immune AIState = (float)Phase.UndergroundLaserBarrage; // Enter the fight again if any of the other exo mechs is below 70% and the other mechs aren't berserk