From 2170f4f3e90aa0b95ee30c4861f4e073ba40ecc1 Mon Sep 17 00:00:00 2001 From: Andrew Marheine Date: Mon, 15 Nov 2021 16:21:02 -0600 Subject: [PATCH] 1 - Artemis, Apollo and Ares increase their velocities over time if they're not in their proper positions. --- NPCs/ExoMechs/Apollo/Apollo.cs | 68 +++++++++++++------- NPCs/ExoMechs/Ares/AresBody.cs | 30 +++++++-- NPCs/ExoMechs/Ares/AresGaussNuke.cs | 1 + NPCs/ExoMechs/Ares/AresLaserCannon.cs | 1 + NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.cs | 1 + NPCs/ExoMechs/Ares/AresTeslaCannon.cs | 1 + NPCs/ExoMechs/Artemis/Artemis.cs | 64 +++++++++++------- 7 files changed, 113 insertions(+), 53 deletions(-) diff --git a/NPCs/ExoMechs/Apollo/Apollo.cs b/NPCs/ExoMechs/Apollo/Apollo.cs index e0a2c29692..74f11d774b 100644 --- a/NPCs/ExoMechs/Apollo/Apollo.cs +++ b/NPCs/ExoMechs/Apollo/Apollo.cs @@ -63,6 +63,9 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo set => npc.Calamity().newAI[1] = value; } + // Variable used to scale up velocity if too far from destination + private float velocityBoostMult = 0f; + // Number of frames on the X and Y axis private const int maxFramesX = 10; private const int maxFramesY = 9; @@ -158,6 +161,7 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo public override void SendExtraAI(BinaryWriter writer) { + writer.Write(velocityBoostMult); writer.Write(frameX); writer.Write(frameY); writer.Write(pickNewLocation); @@ -175,6 +179,7 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo public override void ReceiveExtraAI(BinaryReader reader) { + velocityBoostMult = reader.ReadSingle(); frameX = reader.ReadInt32(); frameY = reader.ReadInt32(); pickNewLocation = reader.ReadBoolean(); @@ -431,6 +436,43 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo float chargeComboYOffset = npc.ai[2] % 2f == 0f ? 400f : -400f; Vector2 destination = SecondaryAIState == (float)SecondaryPhase.PassiveAndImmune ? new Vector2(player.Center.X + destinationX * 1.6f, destinationY) : AIState == (float)Phase.LineUpChargeCombo ? new Vector2(player.Center.X + destinationX, destinationY + chargeComboYOffset) : new Vector2(player.Center.X + destinationX, destinationY); + // 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); + if (AIState == (float)Phase.RocketBarrage) + { + npc.localAI[0] *= 0.5f; + npc.localAI[1] *= 0.5f; + } + + npc.netUpdate = true; + } + + // 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]; + } + + // Scale up velocity over time if too far from destination + Vector2 distanceFromDestination = destination - npc.Center; + if (distanceFromDestination.Length() > movementDistanceGateValue && AIState != (float)Phase.ChargeCombo) + { + if (velocityBoostMult < 1f) + velocityBoostMult += 0.004f; + } + else + { + if (velocityBoostMult > 0f) + velocityBoostMult -= 0.004f; + } + baseVelocity += 20f * velocityBoostMult; + // If Apollo can fire projectiles, cannot fire if too close to the target bool canFire = Vector2.Distance(npc.Center, player.Center) > 320f; @@ -504,29 +546,6 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo } } - // 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); - if (AIState == (float)Phase.RocketBarrage) - { - npc.localAI[0] *= 0.5f; - npc.localAI[1] *= 0.5f; - } - - npc.netUpdate = true; - } - - // 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]; - } - // Cause the charge visual effects to begin while performing or preparing for a combo if (AIState == (float)Phase.LineUpChargeCombo || AIState == (float)Phase.ChargeCombo) ChargeComboFlash = MathHelper.Clamp(ChargeComboFlash + 0.08f, 0f, 1f); @@ -535,8 +554,7 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo else ChargeComboFlash = MathHelper.Clamp(ChargeComboFlash - 0.1f, 0f, 1f); - // Destination variables - Vector2 distanceFromDestination = destination - npc.Center; + // Velocity Vector2 desiredVelocity = Vector2.Normalize(distanceFromDestination) * baseVelocity; // Set to transition to phase 2 if it hasn't happened yet diff --git a/NPCs/ExoMechs/Ares/AresBody.cs b/NPCs/ExoMechs/Ares/AresBody.cs index 6ea1ed7573..fc1358b27f 100644 --- a/NPCs/ExoMechs/Ares/AresBody.cs +++ b/NPCs/ExoMechs/Ares/AresBody.cs @@ -73,6 +73,12 @@ namespace CalamityMod.NPCs.ExoMechs.Ares set => npc.localAI[1] = value; } + public float VelocityBoostMult + { + get => npc.localAI[2]; + set => npc.localAI[2] = value; + } + public ThanatosSmokeParticleSet SmokeDrawer = new ThanatosSmokeParticleSet(-1, 3, 0f, 16f, 1.5f); // Spawn rate for enrage steam @@ -162,6 +168,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares writer.Write(npc.dontTakeDamage); writer.Write(npc.localAI[0]); writer.Write(npc.localAI[1]); + writer.Write(npc.localAI[2]); for (int i = 0; i < 4; i++) writer.Write(npc.Calamity().newAI[i]); } @@ -174,6 +181,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares npc.dontTakeDamage = reader.ReadBoolean(); npc.localAI[0] = reader.ReadSingle(); npc.localAI[1] = reader.ReadSingle(); + npc.localAI[2] = reader.ReadSingle(); for (int i = 0; i < 4; i++) npc.Calamity().newAI[i] = reader.ReadSingle(); } @@ -425,15 +433,27 @@ namespace CalamityMod.NPCs.ExoMechs.Ares float baseVelocity = (EnragedState == (float)Enraged.Yes ? 28f : 20f) * baseVelocityMult; float baseAcceleration = berserk ? 1.25f : 1f; float decelerationVelocityMult = 0.85f; - Vector2 distanceFromDestination = destination - npc.Center; - Vector2 desiredVelocity = Vector2.Normalize(distanceFromDestination) * baseVelocity; - - // Distance from target - float distanceFromTarget = Vector2.Distance(npc.Center, player.Center); // Distance where Ares stops moving float movementDistanceGateValue = 50f; + // Scale up velocity over time if too far from destination + Vector2 distanceFromDestination = destination - npc.Center; + if (distanceFromDestination.Length() > movementDistanceGateValue && AIState != (float)Phase.Deathrays) + { + if (VelocityBoostMult < 1f) + VelocityBoostMult += 0.004f; + } + else + { + if (VelocityBoostMult > 0f) + VelocityBoostMult -= 0.004f; + } + baseVelocity += 20f * VelocityBoostMult; + + // Distance from target + float distanceFromTarget = Vector2.Distance(npc.Center, player.Center); + // Gate values float deathrayPhaseGateValue = lastMechAlive ? 420f : 600f; float deathrayDistanceGateValue = 480f; diff --git a/NPCs/ExoMechs/Ares/AresGaussNuke.cs b/NPCs/ExoMechs/Ares/AresGaussNuke.cs index 316d98e152..1620658187 100644 --- a/NPCs/ExoMechs/Ares/AresGaussNuke.cs +++ b/NPCs/ExoMechs/Ares/AresGaussNuke.cs @@ -292,6 +292,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares // Velocity and acceleration values float baseVelocityMult = (berserk ? 0.25f : 0f) + (malice ? 1.15f : death ? 1.1f : revenge ? 1.075f : expertMode ? 1.05f : 1f); float baseVelocity = (enraged ? 38f : 30f) * baseVelocityMult; + baseVelocity += 20f * Main.npc[(int)npc.ai[2]].localAI[2]; Vector2 distanceFromDestination = destination - npc.Center; diff --git a/NPCs/ExoMechs/Ares/AresLaserCannon.cs b/NPCs/ExoMechs/Ares/AresLaserCannon.cs index 94b6b94033..18a20cc78e 100644 --- a/NPCs/ExoMechs/Ares/AresLaserCannon.cs +++ b/NPCs/ExoMechs/Ares/AresLaserCannon.cs @@ -284,6 +284,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares // Velocity and acceleration values float baseVelocityMult = (berserk ? 0.25f : 0f) + (malice ? 1.15f : death ? 1.1f : revenge ? 1.075f : expertMode ? 1.05f : 1f); float baseVelocity = (enraged ? 38f : 30f) * baseVelocityMult; + baseVelocity += 20f * Main.npc[(int)npc.ai[2]].localAI[2]; float baseAcceleration = berserk ? 1.25f : 1f; Vector2 distanceFromDestination = destination - npc.Center; diff --git a/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.cs b/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.cs index f73b8758b4..003147e921 100644 --- a/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.cs +++ b/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.cs @@ -292,6 +292,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares // Velocity and acceleration values float baseVelocityMult = (berserk ? 0.25f : 0f) + (malice ? 1.15f : death ? 1.1f : revenge ? 1.075f : expertMode ? 1.05f : 1f); float baseVelocity = (enraged ? 38f : 30f) * baseVelocityMult; + baseVelocity += 20f * Main.npc[(int)npc.ai[2]].localAI[2]; Vector2 distanceFromDestination = destination - npc.Center; diff --git a/NPCs/ExoMechs/Ares/AresTeslaCannon.cs b/NPCs/ExoMechs/Ares/AresTeslaCannon.cs index 113b611958..92c415aa45 100644 --- a/NPCs/ExoMechs/Ares/AresTeslaCannon.cs +++ b/NPCs/ExoMechs/Ares/AresTeslaCannon.cs @@ -293,6 +293,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares // Velocity and acceleration values float baseVelocityMult = (berserk ? 0.25f : 0f) + (malice ? 1.15f : death ? 1.1f : revenge ? 1.075f : expertMode ? 1.05f : 1f); float baseVelocity = (enraged ? 38f : 30f) * baseVelocityMult; + baseVelocity += 20f * Main.npc[(int)npc.ai[2]].localAI[2]; Vector2 distanceFromDestination = destination - npc.Center; diff --git a/NPCs/ExoMechs/Artemis/Artemis.cs b/NPCs/ExoMechs/Artemis/Artemis.cs index 0c45e62f75..5ef01138f6 100644 --- a/NPCs/ExoMechs/Artemis/Artemis.cs +++ b/NPCs/ExoMechs/Artemis/Artemis.cs @@ -61,6 +61,9 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis set => npc.Calamity().newAI[1] = value; } + // Variable used to scale up velocity if too far from destination + private float velocityBoostMult = 0f; + // The vector used for charging private Vector2 chargeVelocityNormalized = default; @@ -168,6 +171,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis public override void SendExtraAI(BinaryWriter writer) { + writer.Write(velocityBoostMult); writer.WriteVector2(spinVelocity); writer.WriteVector2(chargeVelocityNormalized); writer.Write(frameX); @@ -186,6 +190,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis public override void ReceiveExtraAI(BinaryReader reader) { + velocityBoostMult = reader.ReadSingle(); spinVelocity = reader.ReadVector2(); chargeVelocityNormalized = reader.ReadVector2(); frameX = reader.ReadInt32(); @@ -467,6 +472,42 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis // If Artemis can fire projectiles, cannot fire if too close to the target bool canFire = Vector2.Distance(npc.Center, player.Center) > 320f && canFireLasers; + // 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 + bool flyLeft = npc.ai[0] % 2f == 0f || npc.ai[0] < 10f || !revenge; + float destinationX = flyLeft ? -750f : 750f; + float destinationY = player.Center.Y; + Vector2 destination = SecondaryAIState == (float)SecondaryPhase.PassiveAndImmune ? new Vector2(player.Center.X + destinationX * 1.6f, destinationY) : AIState == (float)Phase.Deathray ? spinLocation : new Vector2(player.Center.X + destinationX, destinationY); + + // 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.LaserShotgun || AIState == (float)Phase.PhaseTransition) + { + destination.X += npc.localAI[0]; + destination.Y += npc.localAI[1]; + } + + // Scale up velocity over time if too far from destination + Vector2 distanceFromDestination = destination - npc.Center; + if (distanceFromDestination.Length() > movementDistanceGateValue && AIState != (float)Phase.Charge) + { + if (velocityBoostMult < 1f) + velocityBoostMult += 0.004f; + } + else + { + if (velocityBoostMult > 0f) + velocityBoostMult -= 0.004f; + } + baseVelocity += 20f * velocityBoostMult; + // Rotation Vector2 predictionVector = AIState == (float)Phase.Deathray ? Vector2.Zero : player.velocity * predictionAmt; Vector2 aimedVector = player.Center + predictionVector - npc.Center; @@ -544,30 +585,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis } } - // 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 - bool flyLeft = npc.ai[0] % 2f == 0f || npc.ai[0] < 10f || !revenge; - float destinationX = flyLeft ? -750f : 750f; - float destinationY = player.Center.Y; - Vector2 destination = SecondaryAIState == (float)SecondaryPhase.PassiveAndImmune ? new Vector2(player.Center.X + destinationX * 1.6f, destinationY) : AIState == (float)Phase.Deathray ? spinLocation : new Vector2(player.Center.X + destinationX, destinationY); - - // 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.LaserShotgun || 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; // Duration of deathray spin to do a full circle