diff --git a/NPCs/ExoMechs/Apollo/Apollo.cs b/NPCs/ExoMechs/Apollo/Apollo.cs index b21243039f..eba4711d38 100644 --- a/NPCs/ExoMechs/Apollo/Apollo.cs +++ b/NPCs/ExoMechs/Apollo/Apollo.cs @@ -250,7 +250,7 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo NPC.TargetClosest(); // Target variable - Player player = Main.player[NPC.target]; + int targetIndex = NPC.target; // Check if the other exo mechs are alive int otherExoMechsAlive = 0; @@ -275,7 +275,7 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo if (Main.npc[CalamityGlobalNPC.draedonExoMechWorm].active) { // Set target to Thanatos' target if Thanatos is alive - player = Main.player[Main.npc[CalamityGlobalNPC.draedonExoMechWorm].target]; + targetIndex = Main.npc[CalamityGlobalNPC.draedonExoMechWorm].target; otherExoMechsAlive++; exoWormAlive = true; @@ -286,7 +286,7 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo if (Main.npc[CalamityGlobalNPC.draedonExoMechPrime].active) { // Set target to Ares' target if Ares is alive - player = Main.player[Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target]; + targetIndex = Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target; otherExoMechsAlive++; exoPrimeAlive = true; @@ -366,7 +366,7 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo { NPC.ai[0] += 1f; if (NPC.ai[0] == 10f && !NPC.AnyNPCs(ModContent.NPCType())) - NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); + NPC.SpawnOnPlayer(Main.player[targetIndex].whoAmI, ModContent.NPCType()); } else { @@ -465,13 +465,13 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo // Default vector to fly to bool flyRight = NPC.ai[0] % 2f == 0f || NPC.ai[0] < 10f || !revenge; float destinationX = flyRight ? 750f : -750f; - float destinationY = player.Center.Y; + float destinationY = Main.player[targetIndex].Center.Y; float chargeComboXOffset = flyRight ? -600f : 600f; float chargeComboYOffset = NPC.ai[2] % 2f == 0f ? 480f : -480f; - Vector2 destination = SecondaryAIState == (float)SecondaryPhase.PassiveAndImmune ? new Vector2(player.Center.X + destinationX * 1.6f, destinationY) : - SecondaryAIState == (float)SecondaryPhase.Passive ? new Vector2(player.Center.X + destinationX, destinationY + 360f) : - AIState == (float)Phase.LineUpChargeCombo ? new Vector2(player.Center.X + destinationX * 1.2f, destinationY + chargeComboYOffset) : - new Vector2(player.Center.X + destinationX, destinationY); + Vector2 destination = SecondaryAIState == (float)SecondaryPhase.PassiveAndImmune ? new Vector2(Main.player[targetIndex].Center.X + destinationX * 1.6f, destinationY) : + SecondaryAIState == (float)SecondaryPhase.Passive ? new Vector2(Main.player[targetIndex].Center.X + destinationX, destinationY + 360f) : + AIState == (float)Phase.LineUpChargeCombo ? new Vector2(Main.player[targetIndex].Center.X + destinationX * 1.2f, destinationY + chargeComboYOffset) : + new Vector2(Main.player[targetIndex].Center.X + destinationX, destinationY); // Add some random distance to the destination after certain attacks if (pickNewLocation) @@ -523,9 +523,9 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo bool canFire = distanceFromDestination.Length() <= 320f; // Rotation - Vector2 aimedVector = player.Center - NPC.Center; + Vector2 aimedVector = Main.player[targetIndex].Center - NPC.Center; float rateOfRotation = 0.1f; - Vector2 rotateTowards = player.Center - NPC.Center; + Vector2 rotateTowards = Main.player[targetIndex].Center - NPC.Center; bool readyToCharge = AIState == (float)Phase.LineUpChargeCombo && (Vector2.Distance(NPC.Center, destination) <= chargeLocationDistanceGateValue || calamityGlobalNPC.newAI[2] > 0f); if (AIState == (int)Phase.ChargeCombo) { @@ -540,8 +540,8 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo } else { - float x = player.Center.X - NPC.Center.X; - float y = player.Center.Y - NPC.Center.Y; + float x = Main.player[targetIndex].Center.X - NPC.Center.X; + float y = Main.player[targetIndex].Center.Y - NPC.Center.Y; rotateTowards = Vector2.Normalize(new Vector2(x, y)) * baseVelocity; } @@ -550,42 +550,37 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo NPC.rotation = NPC.rotation.AngleTowards((float)Math.Atan2(rotateTowards.Y, rotateTowards.X) + MathHelper.PiOver2, rateOfRotation); // Despawn if target is dead - if (player.dead) + if (Main.player[targetIndex].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; - for (int i = 0; i < maxCharges; i++) - chargeLocations[i] = default; + AIState = (float)Phase.Normal; + NPC.localAI[0] = 0f; + NPC.localAI[1] = 0f; + NPC.localAI[2] = 0f; + calamityGlobalNPC.newAI[2] = 0f; + calamityGlobalNPC.newAI[3] = 0f; + for (int i = 0; i < maxCharges; i++) + chargeLocations[i] = default; - NPC.dontTakeDamage = true; + NPC.dontTakeDamage = true; + NPC.velocity.Y -= 1f; + if ((double)NPC.position.Y < Main.topWorld + 16f) NPC.velocity.Y -= 1f; - if ((double)NPC.position.Y < Main.topWorld + 16f) - NPC.velocity.Y -= 1f; - if ((double)NPC.position.Y < Main.topWorld + 16f) + if ((double)NPC.position.Y < Main.topWorld + 16f) + { + for (int a = 0; a < Main.maxNPCs; a++) { - 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; - } + 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; } + + return; } // Cause the charge visual effects to begin while performing or preparing for a combo @@ -673,8 +668,8 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo if (Main.netMode != NetmodeID.MultiplayerClient) { // Spawn the fuckers - NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); - NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); + NPC.SpawnOnPlayer(Main.player[targetIndex].whoAmI, ModContent.NPCType()); + NPC.SpawnOnPlayer(Main.player[targetIndex].whoAmI, ModContent.NPCType()); } } } @@ -989,7 +984,7 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo int damage = NPC.GetProjectileDamage(type); Vector2 plasmaVelocity = Vector2.Normalize(aimedVector) * projectileVelocity; Vector2 offset = Vector2.Normalize(plasmaVelocity) * 70f; - Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center + offset, plasmaVelocity, type, damage, 0f, Main.myPlayer, player.Center.X, player.Center.Y); + Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center + offset, plasmaVelocity, type, damage, 0f, Main.myPlayer, Main.player[targetIndex].Center.X, Main.player[targetIndex].Center.Y); } } } @@ -1053,7 +1048,7 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo int damage = NPC.GetProjectileDamage(type); Vector2 rocketVelocity = Vector2.Normalize(aimedVector) * projectileVelocity * 1.2f; Vector2 offset = Vector2.Normalize(rocketVelocity) * 70f; - Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center + offset, rocketVelocity, type, damage, 0f, Main.myPlayer, 0f, player.Center.Y); + Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center + offset, rocketVelocity, type, damage, 0f, Main.myPlayer, 0f, Main.player[targetIndex].Center.Y); } } diff --git a/NPCs/ExoMechs/Ares/AresGaussNuke.cs b/NPCs/ExoMechs/Ares/AresGaussNuke.cs index b10fa96e8e..dec6dd8459 100644 --- a/NPCs/ExoMechs/Ares/AresGaussNuke.cs +++ b/NPCs/ExoMechs/Ares/AresGaussNuke.cs @@ -196,8 +196,8 @@ namespace CalamityMod.NPCs.ExoMechs.Ares // Whether Ares should be buffed while in berserk phase bool shouldGetBuffedByBerserkPhase = berserk && !otherMechIsBerserk; - // Target variable - Player player = Main.player[Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target]; + // Target variables + int targetIndex = Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target; if (NPC.ai[2] > 0f) NPC.realLife = (int)NPC.ai[2]; @@ -237,8 +237,8 @@ namespace CalamityMod.NPCs.ExoMechs.Ares if (passivePhase) predictionAmt *= 0.5f; - Vector2 predictionVector = player.velocity * predictionAmt; - Vector2 rotationVector = player.Center + predictionVector - NPC.Center; + Vector2 predictionVector = Main.player[targetIndex].velocity * predictionAmt; + Vector2 rotationVector = Main.player[targetIndex].Center + predictionVector - NPC.Center; float projectileVelocity = passivePhase ? 9.6f : 12f; if (lastMechAlive) @@ -260,7 +260,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares NPC.rotation = NPC.rotation.AngleTowards(rotation, rateOfRotation); // Direction - int direction = Math.Sign(player.Center.X - NPC.Center.X); + int direction = Math.Sign(Main.player[targetIndex].Center.X - NPC.Center.X); if (direction != 0) { NPC.direction = direction; @@ -272,35 +272,31 @@ namespace CalamityMod.NPCs.ExoMechs.Ares } // Despawn if target is dead - if (player.dead) + if (Main.player[targetIndex].dead) { - player = Main.player[Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target]; - if (player.dead) - { - AIState = (float)Phase.Nothing; - calamityGlobalNPC.newAI[1] = 0f; - calamityGlobalNPC.newAI[2] = 0f; - NPC.dontTakeDamage = true; + AIState = (float)Phase.Nothing; + calamityGlobalNPC.newAI[1] = 0f; + calamityGlobalNPC.newAI[2] = 0f; + NPC.dontTakeDamage = true; + NPC.velocity.Y -= 1f; + if ((double)NPC.position.Y < Main.topWorld + 16f) NPC.velocity.Y -= 1f; - if ((double)NPC.position.Y < Main.topWorld + 16f) - NPC.velocity.Y -= 1f; - if ((double)NPC.position.Y < Main.topWorld + 16f) + if ((double)NPC.position.Y < Main.topWorld + 16f) + { + for (int a = 0; a < Main.maxNPCs; a++) { - 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; - } + 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; } + + return; } // Default vector to fly to @@ -424,7 +420,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares int type = ModContent.ProjectileType(); int damage = NPC.GetProjectileDamage(type); float offset = 40f; - Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center + Vector2.Normalize(gaussNukeVelocity) * offset, gaussNukeVelocity, type, damage, 0f, Main.myPlayer, 0f, player.Center.Y); + Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center + Vector2.Normalize(gaussNukeVelocity) * offset, gaussNukeVelocity, type, damage, 0f, Main.myPlayer, 0f, Main.player[targetIndex].Center.Y); } // Recoil diff --git a/NPCs/ExoMechs/Ares/AresLaserCannon.cs b/NPCs/ExoMechs/Ares/AresLaserCannon.cs index 6622b7d54c..cbaacc311a 100644 --- a/NPCs/ExoMechs/Ares/AresLaserCannon.cs +++ b/NPCs/ExoMechs/Ares/AresLaserCannon.cs @@ -199,8 +199,8 @@ namespace CalamityMod.NPCs.ExoMechs.Ares // Whether Ares should be buffed while in berserk phase bool shouldGetBuffedByBerserkPhase = berserk && !otherMechIsBerserk; - // Target variable - Player player = Main.player[Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target]; + // Target variables + int targetIndex = Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target; if (NPC.ai[2] > 0f) NPC.realLife = (int)NPC.ai[2]; @@ -266,7 +266,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares bool horizontalLaserSweep = calamityGlobalNPC.newAI[3] == 0f; float rateOfRotation = AIState == (int)Phase.Deathray ? 0.08f : 0.04f; float lookAtX = flyLeft ? 1000f : -1000f; - Vector2 lookAt = AIState == (int)Phase.Deathray && !fireNormalLasers ? (horizontalLaserSweep ? new Vector2(NPC.Center.X, NPC.Center.Y + 1000f) : new Vector2(NPC.Center.X + lookAtX, NPC.Center.Y)) : player.Center; + Vector2 lookAt = AIState == (int)Phase.Deathray && !fireNormalLasers ? (horizontalLaserSweep ? new Vector2(NPC.Center.X, NPC.Center.Y + 1000f) : new Vector2(NPC.Center.X + lookAtX, NPC.Center.Y)) : Main.player[targetIndex].Center; float rotation = (float)Math.Atan2(lookAt.Y - NPC.Center.Y, lookAt.X - NPC.Center.X); if (NPC.spriteDirection == 1) @@ -279,7 +279,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares NPC.rotation = NPC.rotation.AngleTowards(rotation, rateOfRotation); // Direction - int direction = Math.Sign(((AIState == (int)Phase.Deathray && !horizontalLaserSweep) || fireNormalLasers ? lookAt.X : player.Center.X) - NPC.Center.X); + int direction = Math.Sign(((AIState == (int)Phase.Deathray && !horizontalLaserSweep) || fireNormalLasers ? lookAt.X : Main.player[targetIndex].Center.X) - NPC.Center.X); if (direction != 0) { NPC.direction = direction; @@ -291,35 +291,31 @@ namespace CalamityMod.NPCs.ExoMechs.Ares } // Despawn if target is dead - if (player.dead) + if (Main.player[targetIndex].dead) { - player = Main.player[Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target]; - if (player.dead) - { - AIState = (float)Phase.Nothing; - calamityGlobalNPC.newAI[1] = 0f; - calamityGlobalNPC.newAI[2] = 0f; - NPC.dontTakeDamage = true; + AIState = (float)Phase.Nothing; + calamityGlobalNPC.newAI[1] = 0f; + calamityGlobalNPC.newAI[2] = 0f; + NPC.dontTakeDamage = true; + NPC.velocity.Y -= 1f; + if ((double)NPC.position.Y < Main.topWorld + 16f) NPC.velocity.Y -= 1f; - if ((double)NPC.position.Y < Main.topWorld + 16f) - NPC.velocity.Y -= 1f; - if ((double)NPC.position.Y < Main.topWorld + 16f) + if ((double)NPC.position.Y < Main.topWorld + 16f) + { + for (int a = 0; a < Main.maxNPCs; a++) { - 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; - } + 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; } + + return; } // Velocity and acceleration values @@ -351,7 +347,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares deathrayPhaseVelocity *= 1.1f; // If Laser Cannon can fire normal lasers, cannot fire if too close to the target and in deathray spiral phase - bool canFire = Vector2.Distance(NPC.Center, player.Center) > 320f || !fireNormalLasers; + bool canFire = Vector2.Distance(NPC.Center, Main.player[targetIndex].Center) > 320f || !fireNormalLasers; // Telegraph duration for deathray spiral float deathraySpiralTelegraphDuration = bossRush ? AresBody.deathrayTelegraphDuration_BossRush : death ? AresBody.deathrayTelegraphDuration_Death : @@ -454,9 +450,9 @@ namespace CalamityMod.NPCs.ExoMechs.Ares { int type = ModContent.ProjectileType(); int damage = NPC.GetProjectileDamage(type); - Vector2 laserVelocity = Vector2.Normalize(player.Center - NPC.Center); + Vector2 laserVelocity = Vector2.Normalize(Main.player[targetIndex].Center - NPC.Center); Vector2 offset = laserVelocity * 70f + Vector2.UnitY * 16f; - Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center + offset, player.Center, type, damage, 0f, Main.myPlayer, 0f, NPC.whoAmI); + Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center + offset, Main.player[targetIndex].Center, type, damage, 0f, Main.myPlayer, 0f, NPC.whoAmI); } } } diff --git a/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.cs b/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.cs index 7a649370d7..9aef9f09fb 100644 --- a/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.cs +++ b/NPCs/ExoMechs/Ares/AresPlasmaFlamethrower.cs @@ -195,8 +195,8 @@ namespace CalamityMod.NPCs.ExoMechs.Ares // Whether Ares should be buffed while in berserk phase bool shouldGetBuffedByBerserkPhase = berserk && !otherMechIsBerserk; - // Target variable - Player player = Main.player[Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target]; + // Target variables + int targetIndex = Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target; if (NPC.ai[2] > 0f) NPC.realLife = (int)NPC.ai[2]; @@ -236,8 +236,8 @@ namespace CalamityMod.NPCs.ExoMechs.Ares if (passivePhase) predictionAmt *= 0.5f; - Vector2 predictionVector = player.velocity * predictionAmt; - Vector2 rotationVector = player.Center + predictionVector - NPC.Center; + Vector2 predictionVector = Main.player[targetIndex].velocity * predictionAmt; + Vector2 rotationVector = Main.player[targetIndex].Center + predictionVector - NPC.Center; float projectileVelocity = passivePhase ? 9.6f : 12f; if (lastMechAlive) @@ -259,7 +259,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares NPC.rotation = NPC.rotation.AngleTowards(rotation, rateOfRotation); // Direction - int direction = Math.Sign(player.Center.X - NPC.Center.X); + int direction = Math.Sign(Main.player[targetIndex].Center.X - NPC.Center.X); if (direction != 0) { NPC.direction = direction; @@ -284,35 +284,31 @@ namespace CalamityMod.NPCs.ExoMechs.Ares float setTimerTo = (int)(plasmaBoltPhaseGateValue * 0.95f) - 1; // Despawn if target is dead - if (player.dead) + if (Main.player[targetIndex].dead) { - player = Main.player[Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target]; - if (player.dead) - { - AIState = (float)Phase.Nothing; - calamityGlobalNPC.newAI[1] = setTimerTo; - calamityGlobalNPC.newAI[2] = 0f; - NPC.dontTakeDamage = true; + AIState = (float)Phase.Nothing; + calamityGlobalNPC.newAI[1] = setTimerTo; + calamityGlobalNPC.newAI[2] = 0f; + NPC.dontTakeDamage = true; + NPC.velocity.Y -= 1f; + if ((double)NPC.position.Y < Main.topWorld + 16f) NPC.velocity.Y -= 1f; - if ((double)NPC.position.Y < Main.topWorld + 16f) - NPC.velocity.Y -= 1f; - if ((double)NPC.position.Y < Main.topWorld + 16f) + if ((double)NPC.position.Y < Main.topWorld + 16f) + { + for (int a = 0; a < Main.maxNPCs; a++) { - 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; - } + 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; } + + return; } // Default vector to fly to @@ -351,7 +347,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares bool boltsSplitLess = fireMoreBolts && !lastMechAlive; // If Plasma Cannon can fire projectiles, cannot fire if too close to the target and in deathray spiral phase - bool canFire = Vector2.Distance(NPC.Center, player.Center) > 320f || calamityGlobalNPC_Body.newAI[0] != (float)AresBody.Phase.Deathrays; + bool canFire = Vector2.Distance(NPC.Center, Main.player[targetIndex].Center) > 320f || calamityGlobalNPC_Body.newAI[0] != (float)AresBody.Phase.Deathrays; // Telegraph duration for deathray spiral float deathrayTelegraphDuration = bossRush ? AresBody.deathrayTelegraphDuration_BossRush : death ? AresBody.deathrayTelegraphDuration_Death : @@ -450,7 +446,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares if (boltsSplitLess) Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center + offset, plasmaBoltVelocity, type, damage, 0f, Main.myPlayer, -1f); else - Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center + offset, plasmaBoltVelocity, type, damage, 0f, Main.myPlayer, player.Center.X, player.Center.Y); + Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center + offset, plasmaBoltVelocity, type, damage, 0f, Main.myPlayer, Main.player[targetIndex].Center.X, Main.player[targetIndex].Center.Y); } // Recoil diff --git a/NPCs/ExoMechs/Ares/AresTeslaCannon.cs b/NPCs/ExoMechs/Ares/AresTeslaCannon.cs index 5c2f2b8e2c..09d77162ed 100644 --- a/NPCs/ExoMechs/Ares/AresTeslaCannon.cs +++ b/NPCs/ExoMechs/Ares/AresTeslaCannon.cs @@ -194,8 +194,8 @@ namespace CalamityMod.NPCs.ExoMechs.Ares // Whether Ares should be buffed while in berserk phase bool shouldGetBuffedByBerserkPhase = berserk && !otherMechIsBerserk; - // Target variable - Player player = Main.player[Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target]; + // Target variables + int targetIndex = Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target; if (NPC.ai[2] > 0f) NPC.realLife = (int)NPC.ai[2]; @@ -237,8 +237,8 @@ namespace CalamityMod.NPCs.ExoMechs.Ares if (lastMechAlive) predictionAmt *= 1.5f; - Vector2 predictionVector = player.velocity * predictionAmt; - Vector2 rotationVector = player.Center + predictionVector - NPC.Center; + Vector2 predictionVector = Main.player[targetIndex].velocity * predictionAmt; + Vector2 rotationVector = Main.player[targetIndex].Center + predictionVector - NPC.Center; bool fireMoreOrbs = calamityGlobalNPC_Body.newAI[0] == (float)AresBody.Phase.Deathrays; float projectileVelocity = (passivePhase || fireMoreOrbs) ? 5.2f : 7.8f; @@ -261,7 +261,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares NPC.rotation = NPC.rotation.AngleTowards(rotation, rateOfRotation); // Direction - int direction = Math.Sign(player.Center.X - NPC.Center.X); + int direction = Math.Sign(Main.player[targetIndex].Center.X - NPC.Center.X); if (direction != 0) { NPC.direction = direction; @@ -285,35 +285,31 @@ namespace CalamityMod.NPCs.ExoMechs.Ares float setTimerTo = (int)(teslaOrbPhaseGateValue * 0.3f) - 1; // Despawn if target is dead - if (player.dead) + if (Main.player[targetIndex].dead) { - player = Main.player[Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target]; - if (player.dead) - { - AIState = (float)Phase.Nothing; - calamityGlobalNPC.newAI[1] = setTimerTo; - calamityGlobalNPC.newAI[2] = 0f; - NPC.dontTakeDamage = true; + AIState = (float)Phase.Nothing; + calamityGlobalNPC.newAI[1] = setTimerTo; + calamityGlobalNPC.newAI[2] = 0f; + NPC.dontTakeDamage = true; + NPC.velocity.Y -= 1f; + if ((double)NPC.position.Y < Main.topWorld + 16f) NPC.velocity.Y -= 1f; - if ((double)NPC.position.Y < Main.topWorld + 16f) - NPC.velocity.Y -= 1f; - if ((double)NPC.position.Y < Main.topWorld + 16f) + if ((double)NPC.position.Y < Main.topWorld + 16f) + { + for (int a = 0; a < Main.maxNPCs; a++) { - 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; - } + 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; } + + return; } // Default vector to fly to @@ -349,7 +345,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares float movementDistanceGateValue = 50f; // If Tesla Cannon can fire projectiles, cannot fire if too close to the target and in deathray spiral phase - bool canFire = Vector2.Distance(NPC.Center, player.Center) > 320f || calamityGlobalNPC_Body.newAI[0] != (float)AresBody.Phase.Deathrays; + bool canFire = Vector2.Distance(NPC.Center, Main.player[targetIndex].Center) > 320f || calamityGlobalNPC_Body.newAI[0] != (float)AresBody.Phase.Deathrays; // Telegraph duration for deathray spiral float deathrayTelegraphDuration = bossRush ? AresBody.deathrayTelegraphDuration_BossRush : death ? AresBody.deathrayTelegraphDuration_Death : diff --git a/NPCs/ExoMechs/Artemis/Artemis.cs b/NPCs/ExoMechs/Artemis/Artemis.cs index d346637495..705b0c02f0 100644 --- a/NPCs/ExoMechs/Artemis/Artemis.cs +++ b/NPCs/ExoMechs/Artemis/Artemis.cs @@ -286,7 +286,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis NPC.TargetClosest(); // Target variable - Player player = Main.player[NPC.target]; + int targetIndex = NPC.target; // Check if the other exo mechs are alive int otherExoMechsAlive = 0; @@ -299,7 +299,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis if (Main.npc[CalamityGlobalNPC.draedonExoMechTwinGreen].active) { // Set target to Apollo's target if Apollo is alive - player = Main.player[Main.npc[CalamityGlobalNPC.draedonExoMechTwinGreen].target]; + targetIndex = Main.npc[CalamityGlobalNPC.draedonExoMechTwinGreen].target; // Link the HP of both twins if (NPC.life > Main.npc[CalamityGlobalNPC.draedonExoMechTwinGreen].life) @@ -314,7 +314,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis if (Main.npc[CalamityGlobalNPC.draedonExoMechWorm].active) { // Set target to Thanatos' target if Thanatos is alive - player = Main.player[Main.npc[CalamityGlobalNPC.draedonExoMechWorm].target]; + targetIndex = Main.npc[CalamityGlobalNPC.draedonExoMechWorm].target; otherExoMechsAlive++; exoWormAlive = true; @@ -325,7 +325,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis if (Main.npc[CalamityGlobalNPC.draedonExoMechPrime].active) { // Set target to Ares' target if Ares is alive - player = Main.player[Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target]; + targetIndex = Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target; otherExoMechsAlive++; exoPrimeAlive = true; @@ -409,7 +409,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis { NPC.ai[0] += 1f; if (NPC.ai[0] == 10f && !NPC.AnyNPCs(ModContent.NPCType())) - NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); + NPC.SpawnOnPlayer(Main.player[targetIndex].whoAmI, ModContent.NPCType()); } else { @@ -465,7 +465,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis // Spin variables float spinRadius = 500f; float spinLocationDistance = 50f; - Vector2 spinLocation = player.Center; + Vector2 spinLocation = Main.player[targetIndex].Center; switch ((int)NPC.ai[3]) { // Laser from top @@ -557,11 +557,11 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis // 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) : - SecondaryAIState == (float)SecondaryPhase.Passive ? new Vector2(player.Center.X + destinationX, destinationY + 360f) : + float destinationY = Main.player[targetIndex].Center.Y; + Vector2 destination = SecondaryAIState == (float)SecondaryPhase.PassiveAndImmune ? new Vector2(Main.player[targetIndex].Center.X + destinationX * 1.6f, destinationY) : + SecondaryAIState == (float)SecondaryPhase.Passive ? new Vector2(Main.player[targetIndex].Center.X + destinationX, destinationY + 360f) : AIState == (float)Phase.Deathray ? spinLocation : - new Vector2(player.Center.X + destinationX, destinationY); + new Vector2(Main.player[targetIndex].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) @@ -588,10 +588,10 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis bool canFire = distanceFromDestination.Length() <= 320f && canFireLasers; // Rotation - Vector2 predictionVector = AIState == (float)Phase.Deathray ? Vector2.Zero : player.velocity * predictionAmt; - Vector2 aimedVector = player.Center + predictionVector - NPC.Center; + Vector2 predictionVector = AIState == (float)Phase.Deathray ? Vector2.Zero : Main.player[targetIndex].velocity * predictionAmt; + Vector2 aimedVector = Main.player[targetIndex].Center + predictionVector - NPC.Center; float rateOfRotation = 0.1f; - Vector2 rotateTowards = player.Center - NPC.Center; + Vector2 rotateTowards = Main.player[targetIndex].Center - NPC.Center; bool stopRotatingAndSlowDown = !phase2 && AIState == (float)Phase.Normal && lineUpAttack; if (!stopRotatingAndSlowDown) { @@ -616,8 +616,8 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis } else { - float x = player.Center.X + predictionVector.X - NPC.Center.X; - float y = player.Center.Y + predictionVector.Y - NPC.Center.Y; + float x = Main.player[targetIndex].Center.X + predictionVector.X - NPC.Center.X; + float y = Main.player[targetIndex].Center.Y + predictionVector.Y - NPC.Center.Y; rotateTowards = Vector2.Normalize(new Vector2(x, y)) * baseVelocity; } @@ -627,45 +627,40 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis } // Despawn if target is dead - if (player.dead) + if (Main.player[targetIndex].dead) { - NPC.TargetClosest(false); - player = Main.player[NPC.target]; - if (player.dead) - { - AIState = (float)Phase.Normal; - NPC.ai[1] = 0f; - NPC.ai[2] = 0f; - NPC.localAI[0] = 0f; - NPC.localAI[1] = 0f; - NPC.localAI[2] = 0f; - calamityGlobalNPC.newAI[2] = 0f; - calamityGlobalNPC.newAI[3] = 0f; - rotationDirection = 0; - chargeVelocityNormalized = default; - spinningPoint = default; - spinVelocity = default; - NPC.dontTakeDamage = true; + AIState = (float)Phase.Normal; + NPC.ai[1] = 0f; + NPC.ai[2] = 0f; + NPC.localAI[0] = 0f; + NPC.localAI[1] = 0f; + NPC.localAI[2] = 0f; + calamityGlobalNPC.newAI[2] = 0f; + calamityGlobalNPC.newAI[3] = 0f; + rotationDirection = 0; + chargeVelocityNormalized = default; + spinningPoint = default; + spinVelocity = default; + NPC.dontTakeDamage = true; + NPC.velocity.Y -= 1f; + if ((double)NPC.position.Y < Main.topWorld + 16f) NPC.velocity.Y -= 1f; - if ((double)NPC.position.Y < Main.topWorld + 16f) - NPC.velocity.Y -= 1f; - if ((double)NPC.position.Y < Main.topWorld + 16f) + if ((double)NPC.position.Y < Main.topWorld + 16f) + { + for (int a = 0; a < Main.maxNPCs; a++) { - 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; - } + 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; } + + return; } // Duration of deathray spin to do a full circle @@ -778,7 +773,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis else { Vector2 laserVelocity = Vector2.Normalize(aimedVector); - Vector2 projectileDestination = player.Center + predictionVector; + Vector2 projectileDestination = Main.player[targetIndex].Center + predictionVector; pointToLookAt = projectileDestination; SoundEngine.PlaySound(CommonCalamitySounds.ExoLaserShootSound, NPC.Center); if (Main.netMode != NetmodeID.MultiplayerClient) @@ -948,9 +943,9 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis int baseSpread = ((nerfedAttacks || nerfedLaserShotgun) ? 9 : lastMechAlive ? 20 : 15) + numLasersAddedByDifficulty * 2; int spread = baseSpread + (int)(calamityGlobalNPC.newAI[2] / divisor2) * (baseSpread / 4); float rotation = MathHelper.ToRadians(spread); - float distanceFromTarget = Vector2.Distance(NPC.Center, player.Center + predictionVector); + float distanceFromTarget = Vector2.Distance(NPC.Center, Main.player[targetIndex].Center + predictionVector); float setVelocityInAI = death ? 6.5f : revenge ? 6.25f : expertMode ? 6f : 5.5f; - pointToLookAt = player.Center + predictionVector; + pointToLookAt = Main.player[targetIndex].Center + predictionVector; for (int i = 0; i < numLasersPerSpread + 1; i++) { @@ -1049,7 +1044,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis // Laser from top case 0: case 1: - if (player.Center.X >= NPC.Center.X) + if (Main.player[targetIndex].Center.X >= NPC.Center.X) rotationDirection = 1; else rotationDirection = -1; @@ -1057,7 +1052,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis // Laser from bottom case 2: - if (player.Center.X >= NPC.Center.X) + if (Main.player[targetIndex].Center.X >= NPC.Center.X) rotationDirection = -1; else rotationDirection = 1; @@ -1066,7 +1061,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis // Laser from left case 3: - if (player.Center.Y >= NPC.Center.Y) + if (Main.player[targetIndex].Center.Y >= NPC.Center.Y) rotationDirection = -1; else rotationDirection = 1; @@ -1075,7 +1070,7 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis // Laser from right case 4: - if (player.Center.Y >= NPC.Center.Y) + if (Main.player[targetIndex].Center.Y >= NPC.Center.Y) rotationDirection = 1; else rotationDirection = -1; diff --git a/NPCs/ExoMechs/Thanatos/ThanatosHead.cs b/NPCs/ExoMechs/Thanatos/ThanatosHead.cs index 8ca44fe51a..3c7d01279b 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosHead.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosHead.cs @@ -250,7 +250,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos public float GetSlowdownAreaEdgeRadius(bool lastMechAlive) => (BossRushEvent.BossRushActive ? 400f : CalamityWorld.death ? 600f : CalamityWorld.revenge ? 700f : Main.expertMode ? 800f : 1000f) * (lastMechAlive ? 0.6f : 1f) * (Main.zenithWorld && !exoMechdusa ? 2 : Main.getGoodWorld ? 0.5f : 1f); - public int CheckForOtherMechs(ref Player target, out bool exoPrimeAlive, out bool exoTwinsAlive) + public int CheckForOtherMechs(ref int targetIndex, out bool exoPrimeAlive, out bool exoTwinsAlive) { exoPrimeAlive = false; exoTwinsAlive = false; @@ -260,7 +260,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos if (Main.npc[CalamityGlobalNPC.draedonExoMechPrime].active) { // Set target to Ares' target if Ares is alive. - target = Main.player[Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target]; + targetIndex = Main.npc[CalamityGlobalNPC.draedonExoMechPrime].target; otherExoMechsAlive++; exoPrimeAlive = true; @@ -303,10 +303,10 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos NPC.TargetClosest(); // Target variable - Player player = Main.player[NPC.target]; + int targetIndex = NPC.target; // Check if the other exo mechs are alive - int otherExoMechsAlive = CheckForOtherMechs(ref player, out bool exoPrimeAlive, out bool exoTwinsAlive); + int otherExoMechsAlive = CheckForOtherMechs(ref targetIndex, out bool exoPrimeAlive, out bool exoTwinsAlive); // These are 5 by default to avoid triggering passive phases after the other mechs are dead float exoPrimeLifeRatio = defaultLifeRatio; @@ -438,36 +438,31 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos // Despawn if target is dead bool targetDead = false; - if (player.dead) + if (Main.player[targetIndex].dead) { - NPC.TargetClosest(false); - player = Main.player[NPC.target]; - if (player.dead) - { - targetDead = true; - AIState = (float)Phase.Charge; - NPC.localAI[0] = 0f; - NPC.localAI[2] = 0f; - calamityGlobalNPC.newAI[2] = 0f; - calamityGlobalNPC.newAI[3] = 0f; - chargeVelocityScalar = 0f; - NPC.dontTakeDamage = true; + targetDead = true; + AIState = (float)Phase.Charge; + NPC.localAI[0] = 0f; + NPC.localAI[2] = 0f; + calamityGlobalNPC.newAI[2] = 0f; + calamityGlobalNPC.newAI[3] = 0f; + chargeVelocityScalar = 0f; + NPC.dontTakeDamage = true; + NPC.velocity.Y -= 1f; + if ((double)NPC.position.Y < Main.topWorld + 16f) NPC.velocity.Y -= 1f; - if ((double)NPC.position.Y < Main.topWorld + 16f) - NPC.velocity.Y -= 1f; - if ((double)NPC.position.Y < Main.topWorld + 16f) + if ((double)NPC.position.Y < Main.topWorld + 16f) + { + for (int a = 0; a < Main.maxNPCs; a++) { - 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; - } + 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; } } } @@ -480,7 +475,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos NPC.netUpdate = true; // Default vector to fly to - Vector2 destination = player.Center; + Vector2 destination = Main.player[targetIndex].Center; // Move destination to somewhere far below the target for the first 3 seconds so that Thanatos can fully uncoil quickly bool speedUp = false; @@ -577,9 +572,9 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos if (Main.netMode != NetmodeID.MultiplayerClient) { // Spawn the fuckers - NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); - NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); - NPC.SpawnOnPlayer(player.whoAmI, ModContent.NPCType()); + NPC.SpawnOnPlayer(Main.player[targetIndex].whoAmI, ModContent.NPCType()); + NPC.SpawnOnPlayer(Main.player[targetIndex].whoAmI, ModContent.NPCType()); + NPC.SpawnOnPlayer(Main.player[targetIndex].whoAmI, ModContent.NPCType()); } } } @@ -993,7 +988,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos { // Increase velocity if velocity is ever zero if (NPC.velocity == Vector2.Zero) - NPC.velocity = Vector2.Normalize(player.Center - NPC.Center).SafeNormalize(Vector2.Zero) * baseVelocity; + NPC.velocity = Vector2.Normalize(Main.player[targetIndex].Center - NPC.Center).SafeNormalize(Vector2.Zero) * baseVelocity; // Acceleration if (!((destination - NPC.Center).Length() < turnDistance)) @@ -1143,7 +1138,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos float lifeRatio = NPC.life / (float)NPC.lifeMax; // Yes, this is bizarre as fuck. - Player completelyUseless = null; + int completelyUseless = 0; int otherExoMechsAlive = CheckForOtherMechs(ref completelyUseless, out _, out _); // A general factor for the aura. diff --git a/NPCs/NormalNPCs/SkeletronPrime2.cs b/NPCs/NormalNPCs/SkeletronPrime2.cs index f98e80ad41..6164daf879 100644 --- a/NPCs/NormalNPCs/SkeletronPrime2.cs +++ b/NPCs/NormalNPCs/SkeletronPrime2.cs @@ -100,14 +100,6 @@ namespace CalamityMod.NPCs.NormalNPCs bool bossRush = BossRushEvent.BossRushActive; bool death = CalamityWorld.death || bossRush; - // 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(); - // Percent life remaining float lifeRatio = NPC.life / (float)NPC.lifeMax; @@ -145,9 +137,6 @@ namespace CalamityMod.NPCs.NormalNPCs } else { - // Set target to the lead head's target - Main.player[NPC.target] = Main.player[Main.npc[(int)NPC.ai[0]].target]; - // Link the HP of both heads if (NPC.life > Main.npc[(int)NPC.ai[0]].life) NPC.life = Main.npc[(int)NPC.ai[0]].life; @@ -231,12 +220,8 @@ namespace CalamityMod.NPCs.NormalNPCs } // Despawn - if (Main.player[NPC.target].dead || Math.Abs(NPC.Center.X - Main.player[NPC.target].Center.X) > 6000f || Math.Abs(NPC.Center.Y - Main.player[NPC.target].Center.Y) > 6000f) - { - NPC.TargetClosest(); - if (Main.player[NPC.target].dead || Math.Abs(NPC.Center.X - Main.player[NPC.target].Center.X) > 6000f || Math.Abs(NPC.Center.Y - Main.player[NPC.target].Center.Y) > 6000f) - NPC.ai[1] = 3f; - } + if (Main.npc[(int)NPC.ai[0]].ai[1] == 3f) + NPC.ai[1] = 3f; // Activate daytime enrage if (Main.IsItDay() && !bossRush && NPC.ai[1] != 3f && NPC.ai[1] != 2f) @@ -273,7 +258,7 @@ namespace CalamityMod.NPCs.NormalNPCs bool normalLaserRotation = NPC.localAI[1] % 2f == 0f; // Prevents cheap hits - bool canUseAttackInMaster = NPC.position.Y < Main.player[NPC.target].position.Y - 350f; + bool canUseAttackInMaster = NPC.position.Y < Main.player[Main.npc[(int)NPC.ai[0]].target].position.Y - 350f; // Float near player if (NPC.ai[1] == 0f || NPC.ai[1] == 4f) @@ -289,8 +274,8 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.ai[2] += phase3 ? 1.2f : 0.8f; if (NPC.ai[2] >= (90f - (death ? 15f * (1f - lifeRatio) : 0f)) && (!otherHeadChargingOrSpinning || phase3) && canUseAttackInMaster) { - bool shouldSpinAround = NPC.ai[1] == 4f && NPC.position.Y < Main.player[NPC.target].position.Y - 400f && - Vector2.Distance(Main.player[NPC.target].Center, NPC.Center) < 600f && Vector2.Distance(Main.player[NPC.target].Center, NPC.Center) > 400f; + bool shouldSpinAround = NPC.ai[1] == 4f && NPC.position.Y < Main.player[Main.npc[(int)NPC.ai[0]].target].position.Y - 400f && + Vector2.Distance(Main.player[Main.npc[(int)NPC.ai[0]].target].Center, NPC.Center) < 600f && Vector2.Distance(Main.player[Main.npc[(int)NPC.ai[0]].target].Center, NPC.Center) > 400f; if (shouldSpinAround || NPC.ai[1] != 4f) { @@ -337,7 +322,7 @@ namespace CalamityMod.NPCs.NormalNPCs float headDecelerationUpDist = 0f; float headDecelerationDownDist = 0f; float headDecelerationHorizontalDist = 0f; - int headHorizontalDirection = ((!(Main.player[NPC.target].Center.X < NPC.Center.X)) ? 1 : (-1)); + int headHorizontalDirection = ((!(Main.player[Main.npc[(int)NPC.ai[0]].target].Center.X < NPC.Center.X)) ? 1 : (-1)); if (NPC.IsMechQueenUp) { headDecelerationHorizontalDist = -150f * (float)headHorizontalDirection; @@ -345,7 +330,7 @@ namespace CalamityMod.NPCs.NormalNPCs headDecelerationDownDist = 50f; } - if (NPC.position.Y > Main.player[NPC.target].position.Y - (400f + headDecelerationUpDist)) + if (NPC.position.Y > Main.player[Main.npc[(int)NPC.ai[0]].target].position.Y - (400f + headDecelerationUpDist)) { if (NPC.velocity.Y > 0f) NPC.velocity.Y *= deceleration; @@ -355,7 +340,7 @@ namespace CalamityMod.NPCs.NormalNPCs if (NPC.velocity.Y > topVelocity) NPC.velocity.Y = topVelocity; } - else if (NPC.position.Y < Main.player[NPC.target].position.Y - (450f + headDecelerationDownDist)) + else if (NPC.position.Y < Main.player[Main.npc[(int)NPC.ai[0]].target].position.Y - (450f + headDecelerationDownDist)) { if (NPC.velocity.Y < 0f) NPC.velocity.Y *= deceleration; @@ -366,7 +351,7 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.velocity.Y = -topVelocity; } - if (NPC.Center.X > Main.player[NPC.target].Center.X + (400f + headDecelerationHorizontalDist)) + if (NPC.Center.X > Main.player[Main.npc[(int)NPC.ai[0]].target].Center.X + (400f + headDecelerationHorizontalDist)) { if (NPC.velocity.X > 0f) NPC.velocity.X *= deceleration; @@ -376,7 +361,7 @@ namespace CalamityMod.NPCs.NormalNPCs if (NPC.velocity.X > topVelocity) NPC.velocity.X = topVelocity; } - if (NPC.Center.X < Main.player[NPC.target].Center.X - (400f + headDecelerationHorizontalDist)) + if (NPC.Center.X < Main.player[Main.npc[(int)NPC.ai[0]].target].Center.X - (400f + headDecelerationHorizontalDist)) { if (NPC.velocity.X < 0f) NPC.velocity.X *= deceleration; @@ -459,8 +444,8 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.rotation += NPC.direction * 0.3f; Vector2 headPosition = NPC.Center; - float headTargetX = Main.player[NPC.target].Center.X - headPosition.X; - float headTargetY = Main.player[NPC.target].Center.Y - headPosition.Y; + float headTargetX = Main.player[Main.npc[(int)NPC.ai[0]].target].Center.X - headPosition.X; + float headTargetY = Main.player[Main.npc[(int)NPC.ai[0]].target].Center.Y - headPosition.Y; float headTargetDistance = (float)Math.Sqrt(headTargetX * headTargetX + headTargetY * headTargetY); float speed = bossRush ? 12f : 8f; @@ -487,7 +472,7 @@ namespace CalamityMod.NPCs.NormalNPCs if (NPC.IsMechQueenUp) { - float mechdusaAccelMult = Vector2.Distance(NPC.Center, Main.player[NPC.target].Center); + float mechdusaAccelMult = Vector2.Distance(NPC.Center, Main.player[Main.npc[(int)NPC.ai[0]].target].Center); if (mechdusaAccelMult < 0.1f) mechdusaAccelMult = 0f; @@ -512,8 +497,8 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.rotation += NPC.direction * 0.3f; Vector2 enragedHeadPosition = NPC.Center; - float enragedHeadTargetX = Main.player[NPC.target].Center.X - enragedHeadPosition.X; - float enragedHeadTargetY = Main.player[NPC.target].Center.Y - enragedHeadPosition.Y; + float enragedHeadTargetX = Main.player[Main.npc[(int)NPC.ai[0]].target].Center.X - enragedHeadPosition.X; + float enragedHeadTargetY = Main.player[Main.npc[(int)NPC.ai[0]].target].Center.Y - enragedHeadPosition.Y; float enragedHeadTargetDist = (float)Math.Sqrt(enragedHeadTargetX * enragedHeadTargetX + enragedHeadTargetY * enragedHeadTargetY); float enragedHeadSpeed = 10f; @@ -534,11 +519,11 @@ namespace CalamityMod.NPCs.NormalNPCs { NPC.localAI[0] = 0f; 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)) + if (Collision.CanHit(headCenter, 1, 1, Main.player[Main.npc[(int)NPC.ai[0]].target].position, Main.player[Main.npc[(int)NPC.ai[0]].target].width, Main.player[Main.npc[(int)NPC.ai[0]].target].height)) { enragedHeadSpeed = 7f; - float enragedHeadSkullTargetX = Main.player[NPC.target].Center.X - headCenter.X + Main.rand.Next(-20, 21); - float enragedHeadSkullTargetY = Main.player[NPC.target].Center.Y - headCenter.Y + Main.rand.Next(-20, 21); + float enragedHeadSkullTargetX = Main.player[Main.npc[(int)NPC.ai[0]].target].Center.X - headCenter.X + Main.rand.Next(-20, 21); + float enragedHeadSkullTargetY = Main.player[Main.npc[(int)NPC.ai[0]].target].Center.Y - headCenter.Y + Main.rand.Next(-20, 21); float enragedHeadSkullTargetDist = (float)Math.Sqrt(enragedHeadSkullTargetX * enragedHeadSkullTargetX + enragedHeadSkullTargetY * enragedHeadSkullTargetY); enragedHeadSkullTargetDist = enragedHeadSpeed / enragedHeadSkullTargetDist; enragedHeadSkullTargetX *= enragedHeadSkullTargetDist; @@ -627,12 +612,12 @@ namespace CalamityMod.NPCs.NormalNPCs SoundEngine.PlaySound(SoundID.ForceRoar, NPC.Center); // Set spin direction - if (Main.player[NPC.target].velocity.X > 0f) + if (Main.player[Main.npc[(int)NPC.ai[0]].target].velocity.X > 0f) calamityGlobalNPC.newAI[0] = 1f; - else if (Main.player[NPC.target].velocity.X < 0f) + else if (Main.player[Main.npc[(int)NPC.ai[0]].target].velocity.X < 0f) calamityGlobalNPC.newAI[0] = -1f; else - calamityGlobalNPC.newAI[0] = Main.player[NPC.target].direction; + calamityGlobalNPC.newAI[0] = Main.player[Main.npc[(int)NPC.ai[0]].target].direction; // Set spin velocity NPC.velocity.X = MathHelper.Pi * NPC.localAI[3] / spinVelocity; @@ -652,7 +637,7 @@ namespace CalamityMod.NPCs.NormalNPCs { NPC.localAI[0] += 1f; - if (Vector2.Distance(Main.player[NPC.target].Center, NPC.Center) > 64f) + if (Vector2.Distance(Main.player[Main.npc[(int)NPC.ai[0]].target].Center, NPC.Center) > 64f) { SoundEngine.PlaySound(SoundID.Item61, NPC.Center); CreateParticles(NPC, new Vector2(NPC.Center.X + Main.rand.Next(NPC.width / 2), NPC.Center.Y + 4f)); @@ -661,8 +646,8 @@ namespace CalamityMod.NPCs.NormalNPCs { Vector2 headCenter = NPC.Center; float enragedHeadSpeed = 6f + (death ? 2f * (1f - lifeRatio) : 0f); - float enragedHeadBombTargetX = Main.player[NPC.target].Center.X - headCenter.X + Main.rand.Next(-20, 21); - float enragedHeadBombTargetY = Main.player[NPC.target].Center.Y - headCenter.Y + Main.rand.Next(-20, 21); + float enragedHeadBombTargetX = Main.player[Main.npc[(int)NPC.ai[0]].target].Center.X - headCenter.X + Main.rand.Next(-20, 21); + float enragedHeadBombTargetY = Main.player[Main.npc[(int)NPC.ai[0]].target].Center.Y - headCenter.Y + Main.rand.Next(-20, 21); float enragedHeadBombTargetDist = (float)Math.Sqrt(enragedHeadBombTargetX * enragedHeadBombTargetX + enragedHeadBombTargetY * enragedHeadBombTargetY); enragedHeadBombTargetDist = enragedHeadSpeed / enragedHeadBombTargetDist; enragedHeadBombTargetX *= enragedHeadBombTargetDist; @@ -724,7 +709,7 @@ namespace CalamityMod.NPCs.NormalNPCs float flightVelocity = bossRush ? 32f : death ? 28f : 24f; float flightAcceleration = bossRush ? 1.28f : death ? 1.12f : 0.96f; - Vector2 destination = new Vector2(Main.player[NPC.target].Center.X, Main.player[NPC.target].Center.Y - 500f); + Vector2 destination = new Vector2(Main.player[Main.npc[(int)NPC.ai[0]].target].Center.X, Main.player[Main.npc[(int)NPC.ai[0]].target].Center.Y - 500f); NPC.SimpleFlyMovement((destination - NPC.Center).SafeNormalize(Vector2.UnitY) * flightVelocity, flightAcceleration); // Spit bombs and then go to floating phase diff --git a/NPCs/VanillaNPCAIOverrides/Bosses/DestroyerAI.cs b/NPCs/VanillaNPCAIOverrides/Bosses/DestroyerAI.cs index e3c8676753..8872b6bebe 100644 --- a/NPCs/VanillaNPCAIOverrides/Bosses/DestroyerAI.cs +++ b/NPCs/VanillaNPCAIOverrides/Bosses/DestroyerAI.cs @@ -800,7 +800,7 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses // Despawn bool oblivionWasAlive = npc.localAI[3] == 1f && !oblivionAlive; - bool oblivionFightDespawn = (oblivionAlive && lifeRatio < 0.7f) || oblivionWasAlive; + bool oblivionFightDespawn = (oblivionAlive && lifeRatio < 0.75f) || oblivionWasAlive; if (player.dead || oblivionFightDespawn) { shouldFly = false; @@ -1064,10 +1064,11 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses } // Force the fucker to turn around in ground phase in Master + // Turns slower if Oblivion is alive, for fairness if (npc.type == NPCID.TheDestroyer && masterMode && !flyAtTarget) { if (npc.Distance(player.Center) > 2000f) - npc.velocity += (player.Center - npc.Center).SafeNormalize(Vector2.UnitY) * turnSpeed; + npc.velocity += (player.Center - npc.Center).SafeNormalize(Vector2.UnitY) * (oblivionAlive ? speed : turnSpeed); } if (NPC.IsMechQueenUp && npc.type == NPCID.TheDestroyer) diff --git a/NPCs/VanillaNPCAIOverrides/Bosses/SkeletronPrimeAI.cs b/NPCs/VanillaNPCAIOverrides/Bosses/SkeletronPrimeAI.cs index a062ee9db8..96febd4b2a 100644 --- a/NPCs/VanillaNPCAIOverrides/Bosses/SkeletronPrimeAI.cs +++ b/NPCs/VanillaNPCAIOverrides/Bosses/SkeletronPrimeAI.cs @@ -49,6 +49,7 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses { int head = NPC.NewNPC(npc.GetSource_FromAI(), (int)npc.Center.X, (int)npc.Center.Y, ModContent.NPCType(), npc.whoAmI); Main.npc[head].ai[0] = npc.whoAmI; + Main.npc[head].target = npc.target; Main.npc[head].netUpdate = true; npc.ai[0] = head; diff --git a/NPCs/VanillaNPCAIOverrides/Bosses/TwinsAI.cs b/NPCs/VanillaNPCAIOverrides/Bosses/TwinsAI.cs index 9391dd89e0..7f270bebca 100644 --- a/NPCs/VanillaNPCAIOverrides/Bosses/TwinsAI.cs +++ b/NPCs/VanillaNPCAIOverrides/Bosses/TwinsAI.cs @@ -129,7 +129,7 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses } // Phase HP ratios - float phase2LifeRatio = masterMode ? 0.85f : 0.7f; + float phase2LifeRatio = oblivionAlive ? 0.5f : masterMode ? 0.85f : 0.7f; float finalPhaseLifeRatio = masterMode ? 0.4f : 0.25f; // Movement variables @@ -170,7 +170,7 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses // Despawn bool oblivionWasAlive = npc.localAI[3] == 1f && !oblivionAlive; - bool oblivionFightDespawn = (oblivionAlive && lifeRatio < 0.7f) || oblivionWasAlive || (oblivionAlive && !spazAlive && lifeRatio < 0.9f); + bool oblivionFightDespawn = (oblivionAlive && lifeRatio < 0.75f) || oblivionWasAlive || (oblivionAlive && !spazAlive && lifeRatio < 0.95f); if (Main.player[npc.target].dead || oblivionFightDespawn) { npc.velocity.Y -= 0.04f; @@ -1108,7 +1108,7 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses } // Phase HP ratios - float phase2LifeRatio = masterMode ? 0.85f : 0.7f; + float phase2LifeRatio = oblivionAlive ? 0.5f : masterMode ? 0.85f : 0.7f; float finalPhaseLifeRatio = masterMode ? 0.4f : 0.25f; // Movement variables @@ -1151,7 +1151,7 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses // Despawn bool oblivionWasAlive = npc.localAI[3] == 1f && !oblivionAlive; - bool oblivionFightDespawn = (oblivionAlive && lifeRatio < 0.7f) || oblivionWasAlive || (oblivionAlive && !retAlive && lifeRatio < 0.9f); + bool oblivionFightDespawn = (oblivionAlive && lifeRatio < 0.75f) || oblivionWasAlive || (oblivionAlive && !retAlive && lifeRatio < 0.95f); if (Main.player[npc.target].dead || oblivionFightDespawn) { npc.velocity.Y -= 0.04f;