diff --git a/NPCs/AcidRain/AcidEel.cs b/NPCs/AcidRain/AcidEel.cs index d50512893d..1f25d972ac 100644 --- a/NPCs/AcidRain/AcidEel.cs +++ b/NPCs/AcidRain/AcidEel.cs @@ -1,3 +1,4 @@ +using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Dusts; using CalamityMod.Items.Placeables.Banners; using CalamityMod.Items.Materials; @@ -8,11 +9,13 @@ using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ID; using Terraria.ModLoader; -using CalamityMod.Buffs.StatDebuffs; + namespace CalamityMod.NPCs.AcidRain { public class AcidEel : ModNPC { + public Player Target => Main.player[npc.target]; + public ref float DirectionRedecideTimer => ref npc.ai[0]; public override void SetStaticDefaults() { DisplayName.SetDefault("Acid Eel"); @@ -35,7 +38,7 @@ namespace CalamityMod.NPCs.AcidRain { npc.DR_NERD(0.05f); npc.damage = 100; - npc.lifeMax = 6000; + npc.lifeMax = 3300; npc.defense = 20; npc.knockBackResist = 0.7f; } @@ -60,70 +63,15 @@ namespace CalamityMod.NPCs.AcidRain { npc.TargetClosest(false); + // Play a slither sound from time to time. if (Main.rand.NextBool(480)) - Main.PlaySound(SoundID.Zombie, npc.Center, 32); // Slither sound + Main.PlaySound(SoundID.Zombie, npc.Center, 32); - if (npc.ai[2] == 0f && !npc.wet) - { - npc.netUpdate = true; - npc.ai[2] = 1f; - } - if (npc.ai[2] == 1f && npc.wet) - { - npc.netUpdate = true; - npc.ai[2] = 0f; - } - - if (npc.ai[2] == 0f) - { - npc.ai[1] += 1f; - if (npc.ai[1] % 150f == 0f || npc.direction == 0) - { - npc.direction = (Main.player[npc.target].position.X > npc.position.X).ToDirectionInt(); - } - float acceleration = 0.3f; - float yAcceleration = 0.08f; - float maxSpeedX = 15f; - float maxSpeedY = 4f; - if (CalamityWorld.downedPolterghast) - { - acceleration = 0.6f; - yAcceleration = 0.15f; - maxSpeedX = 20f; - maxSpeedY = 7f; - } - npc.velocity.X += npc.direction * acceleration; - - if (npc.collideX) - npc.direction *= -1; - - npc.spriteDirection = npc.direction; - - npc.velocity.Y += (Main.player[npc.target].position.Y > npc.position.Y).ToDirectionInt() * yAcceleration; - if (npc.velocity.X > maxSpeedX) - { - npc.velocity.X = maxSpeedX; - npc.netUpdate = true; - } - if (npc.velocity.X < -maxSpeedX) - { - npc.velocity.X = -maxSpeedX; - npc.netUpdate = true; - } - if (npc.velocity.Y > maxSpeedY) - { - npc.velocity.Y = maxSpeedY; - npc.netUpdate = true; - } - if (npc.velocity.Y < -maxSpeedY) - { - npc.velocity.Y = -maxSpeedY; - npc.netUpdate = true; - } - npc.rotation = npc.velocity.X * 0.02f; - } + if (npc.wet) + SwimTowardsTarget(); else { + // Do nothing on land. npc.rotation = npc.rotation.AngleLerp(0f, 0.1f); npc.velocity.X *= 0.95f; if (npc.velocity.Y < 14f) @@ -131,6 +79,42 @@ namespace CalamityMod.NPCs.AcidRain } } + public void SwimTowardsTarget() + { + DirectionRedecideTimer++; + if (DirectionRedecideTimer % 150f == 0f || npc.direction == 0) + { + npc.direction = (Target.position.X > npc.position.X).ToDirectionInt(); + npc.netUpdate = true; + } + + float horizontalAcceleration = 0.3f; + float verticalAcceleration = 0.08f; + float maxSpeedX = 15f; + float maxSpeedY = 4f; + if (CalamityWorld.downedPolterghast) + { + horizontalAcceleration = 0.6f; + verticalAcceleration = 0.15f; + maxSpeedX = 20f; + maxSpeedY = 7f; + } + + npc.velocity.X += npc.direction * horizontalAcceleration; + + if (Main.netMode != NetmodeID.MultiplayerClient && npc.collideX) + { + npc.direction *= -1; + npc.netUpdate = true; + } + + npc.spriteDirection = npc.direction; + + npc.velocity.Y += (Target.position.Y > npc.position.Y).ToDirectionInt() * verticalAcceleration; + npc.velocity = Vector2.Clamp(npc.velocity, new Vector2(-maxSpeedX, -maxSpeedY), new Vector2(maxSpeedX, maxSpeedY)); + npc.rotation = npc.velocity.X * 0.02f; + } + public override void NPCLoot() { DropHelper.DropItemChance(npc, ModContent.ItemType(), 2 * (CalamityWorld.downedAquaticScourge ? 6 : 1), 1, 3); @@ -145,9 +129,7 @@ namespace CalamityMod.NPCs.AcidRain npc.frameCounter = 0; npc.frame.Y += frameHeight; if (npc.frame.Y >= Main.npcFrameCount[npc.type] * frameHeight) - { npc.frame.Y = 0; - } } } @@ -155,32 +137,23 @@ namespace CalamityMod.NPCs.AcidRain { CalamityGlobalNPC.DrawGlowmask(npc, spriteBatch, ModContent.GetTexture(Texture + "Glow")); if (npc.velocity.Length() > 1.5f) - { CalamityGlobalNPC.DrawAfterimage(npc, spriteBatch, drawColor, Color.Transparent, directioning: true); - } } public override void HitEffect(int hitDirection, double damage) { for (int k = 0; k < 8; k++) - { Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.SulfurousSeaAcid, hitDirection, -1f, 0, default, 1f); - } if (npc.life <= 0) { Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/AcidRain/AcidEelGore"), npc.scale); Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/AcidRain/AcidEelGore2"), npc.scale); Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/AcidRain/AcidEelGore3"), npc.scale); for (int k = 0; k < 20; k++) - { Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.SulfurousSeaAcid, hitDirection, -1f, 0, default, 1f); - } } } - public override void OnHitPlayer(Player target, int damage, bool crit) - { - target.AddBuff(ModContent.BuffType(), 180); - } + public override void OnHitPlayer(Player target, int damage, bool crit) => target.AddBuff(ModContent.BuffType(), 180); } } diff --git a/NPCs/AcidRain/CragmawMire.cs b/NPCs/AcidRain/CragmawMire.cs index 9d34066ccb..6920dfb8e9 100644 --- a/NPCs/AcidRain/CragmawMire.cs +++ b/NPCs/AcidRain/CragmawMire.cs @@ -17,6 +17,21 @@ namespace CalamityMod.NPCs.AcidRain { public class CragmawMire : ModNPC { + public Player Target => Main.player[npc.target]; + public ref float Time => ref npc.ai[0]; + public bool HasMadeShellBreakGore + { + get => npc.localAI[0] == 1f; + set => npc.localAI[0] = value.ToInt(); + } + public bool InPhase2 + { + get + { + float phase2CeilingRatio = CalamityWorld.revenge ? 0.85f : 0.7f; + return npc.life / (float)npc.lifeMax < phase2CeilingRatio && CalamityWorld.downedPolterghast; + } + } public override void SetStaticDefaults() { DisplayName.SetDefault("Cragmaw Mire"); @@ -38,7 +53,7 @@ namespace CalamityMod.NPCs.AcidRain if (CalamityWorld.downedPolterghast) { npc.damage = 160; - npc.lifeMax = 146600; + npc.lifeMax = 80630; npc.defense = 80; } @@ -50,41 +65,32 @@ namespace CalamityMod.NPCs.AcidRain npc.HitSound = SoundID.NPCHit1; npc.DeathSound = SoundID.NPCDeath1; } - public bool Phase2 - { - get - { - float ratio = CalamityWorld.revenge ? 0.85f : 0.7f; - return npc.life / (float)npc.lifeMax < ratio && CalamityWorld.downedPolterghast; - } - } + public override void AI() { + Time++; npc.TargetClosest(false); - Player player = Main.player[npc.target]; - - npc.ai[0]++; // Summons a spinning spiral of dust and a dust telegraph - if (npc.ai[0] % 420f > 240f && npc.ai[0] % 420f < 300f) + if (Time % 420f > 240f && Time % 420f < 300f) { - float vectorRotationAngle = (npc.ai[0] % 420f - 240f) / 60f * MathHelper.Pi * 4f; + float vectorRotationAngle = (Time % 420f - 240f) / 60f * MathHelper.Pi * 4f; for (int i = 0; i < 25; i++) { float angle = MathHelper.TwoPi * i / 25f; float y = (float)Math.Sin(angle) * (float)Math.Log(Math.Abs(Math.Cos(angle))); if (!float.IsNaN(y)) { - Vector2 velocity = new Vector2((float)Math.Cos(angle), y) * MathHelper.Lerp(2.4f, 4.2f, (npc.ai[0] - 240f) / 60f); + Vector2 velocity = new Vector2((float)Math.Cos(angle), y) * MathHelper.Lerp(2.4f, 4.2f, (Time - 240f) / 60f); Dust dust = Dust.NewDustPerfect(npc.Center, (int)CalamityDusts.SulfurousSeaAcid); dust.velocity = velocity.RotatedBy(vectorRotationAngle); dust.noGravity = true; - dust.scale = MathHelper.Lerp(1.2f, 2.5f, (npc.ai[0] - 240f) / 60f); + dust.scale = MathHelper.Lerp(1.2f, 2.5f, (Time - 240f) / 60f); } } - float length = MathHelper.Lerp(20f, 1200f, (npc.ai[0] % 420f - 240f) / 60f); - float outwardness = 1f - (npc.ai[0] % 420f - 240f) / 60f; + float length = MathHelper.Lerp(20f, 1200f, (Time % 420f - 240f) / 60f); + float outwardness = 1f - (Time % 420f - 240f) / 60f; for (float i = npc.Top.Y + 4f; i >= npc.Top.Y + 4f - length; i -= 6f) { float angle = i / 32f; @@ -96,18 +102,17 @@ namespace CalamityMod.NPCs.AcidRain dust.noGravity = true; } } - // Release a laser beam and create an explosion - if (npc.ai[0] % 420f == 300f) + + // Release a laser beam upward and create an explosion. + if (Time % 420f == 300f) { - npc.ai[1] = Main.rand.NextFloat(3f); - npc.ai[2] = Main.rand.NextFloat(4f); - npc.netUpdate = true; if (Main.netMode != NetmodeID.MultiplayerClient) { - Main.PlaySound(SoundID.Zombie, (int)npc.position.X, (int)npc.position.Y, 104); // Moon lord beam sound + Main.PlaySound(SoundID.Zombie, (int)npc.position.X, (int)npc.position.Y, 104); int damage = CalamityWorld.downedPolterghast ? 120 : 40; Projectile.NewProjectile(npc.Center, -Vector2.UnitY, ModContent.ProjectileType(), damage, 4f, Main.myPlayer, 0f, npc.whoAmI); } + Vector2 circlePointVector = -Vector2.UnitY; float lerpStart = Main.rand.Next(12, 16); float lerpEnd = Main.rand.Next(3, 6); @@ -134,133 +139,162 @@ namespace CalamityMod.NPCs.AcidRain circlePointVector = circlePointVector.RotatedBy(MathHelper.TwoPi / 9f); } } + npc.netUpdate = true; } - else if (npc.ai[0] % 420f > 300f && npc.ai[0] % 7f == 6f && CalamityWorld.downedPolterghast) + + // Release acid into the air. + else if (Time % 420f > 300f && Time % 7f == 6f && CalamityWorld.downedPolterghast) { if (Main.netMode != NetmodeID.MultiplayerClient) - { Projectile.NewProjectile(npc.Center, -Vector2.UnitY.RotatedByRandom(0.6f) * Main.rand.NextFloat(10f, 15f), ModContent.ProjectileType(), 69, 4f, Main.myPlayer, 0f, npc.whoAmI); - } } - if (!Phase2) - { - npc.Calamity().DR = 0.3f; - if (!player.wet) - npc.Calamity().DR = 0.5f; - npc.HitSound = SoundID.NPCHit42; - if (npc.ai[0] % 420f < 240f) - { - float bubbleShootTimer = CalamityWorld.downedPolterghast ? 24f : 50f; - if (npc.ai[0] % bubbleShootTimer == bubbleShootTimer - 1f && Main.netMode != NetmodeID.MultiplayerClient) - { - int damage = CalamityWorld.downedPolterghast ? 47 : 30; - int idx = Projectile.NewProjectile(npc.Top + new Vector2(0f, 5f), -Vector2.UnitY.RotatedByRandom(0.25f) * 4f, ModContent.ProjectileType(), damage, 1f); - Main.projectile[idx].timeLeft = Main.rand.Next(120, 180); - Main.projectile[idx].netUpdate = true; - } - if (npc.ai[0] % 50f == 49f && Main.rand.NextBool(4)) - { - if (Main.netMode != NetmodeID.MultiplayerClient) - { - List possibleEnemies = new List(); - if (CalamityWorld.downedPolterghast) - { - possibleEnemies.Add(ModContent.NPCType()); - possibleEnemies.Add(ModContent.NPCType()); - possibleEnemies.Add(ModContent.NPCType()); - } - else - { - possibleEnemies.Add(ModContent.NPCType()); - possibleEnemies.Add(ModContent.NPCType()); - } - - Vector2 spawnPosition = npc.Center + Utils.RandomVector2(Main.rand, -360f, 360f); - int attempts = 0; - while (!WorldGen.InWorld((int)spawnPosition.X / 16, (int)spawnPosition.Y / 16)) - { - spawnPosition = npc.Center + Utils.RandomVector2(Main.rand, -460f, 460f); - attempts++; - if (attempts > 200) - return; - } - attempts = 0; - - while (CalamityUtils.TileSelectionSolidSquare((int)spawnPosition.X / 16, (int)spawnPosition.Y / 16, 8, 8) || - CalamityUtils.ParanoidTileRetrieval((int)spawnPosition.X / 16, (int)spawnPosition.Y / 16).liquid != 255) - { - spawnPosition = npc.Center + Utils.RandomVector2(Main.rand, -620f, 620f); - attempts++; - if (attempts > 300) - return; - } - - NPC.NewNPC((int)spawnPosition.X, (int)spawnPosition.Y, Utils.SelectRandom(Main.rand, possibleEnemies.ToArray())); - } - } - } - } + if (InPhase2) + DoPhase2AI(); else + DoPhase1AI(); + } + + public void DoPhase1AI() + { + // Become harder to damage to if the target is not in water. + npc.Calamity().DR = Target.wet ? 0.3f : 0.5f; + + // Use a rock-like hit sound. + npc.HitSound = SoundID.NPCHit42; + + if (Time % 420f < 240f) { - if (npc.localAI[0] == 0f) + float bubbleShootRate = CalamityWorld.downedPolterghast ? 24f : 50f; + if (Main.netMode != NetmodeID.MultiplayerClient && Time % bubbleShootRate == bubbleShootRate - 1f) { - Gore.NewGore(npc.position, -Vector2.UnitY.RotatedByRandom(0.4f) * 4f, mod.GetGoreSlot("Gores/AcidRain/CragmawMireP1Gore"), npc.scale); - Gore.NewGore(npc.position, -Vector2.UnitY.RotatedByRandom(0.4f) * 4f, mod.GetGoreSlot("Gores/AcidRain/CragmawMireP1Gore2"), npc.scale); - Gore.NewGore(npc.position, -Vector2.UnitY.RotatedByRandom(0.4f) * 4f, mod.GetGoreSlot("Gores/AcidRain/CragmawMireP1Gore3"), npc.scale); - npc.localAI[0] = 1f; - } - npc.Calamity().DR = CalamityWorld.revenge ? 0.125f : 0f; - npc.HitSound = SoundID.NPCHit1; - if (Main.netMode != NetmodeID.MultiplayerClient) - { - if (npc.ai[0] % 600f == 20f) + int damage = CalamityWorld.downedPolterghast ? 47 : 30; + Vector2 bubbleSpawnPosition = npc.Top + Vector2.UnitY * 5f; + Vector2 bubbleShootVelocity = -Vector2.UnitY.RotatedByRandom(0.25f) * 4f; + int bubble = Projectile.NewProjectile(bubbleSpawnPosition, bubbleShootVelocity, ModContent.ProjectileType(), damage, 1f); + + if (Main.projectile.IndexInRange(bubble)) { - Projectile.NewProjectile(npc.Center, Vector2.UnitY, ModContent.ProjectileType(), 0, 0f, Main.myPlayer, npc.whoAmI, npc.target); + Main.projectile[bubble].timeLeft = Main.rand.Next(120, 180); + Main.projectile[bubble].netUpdate = true; } - if (npc.ai[0] % 600f == 240f) + } + + // Summon enemies from time to time. + if (Time % 50f == 49f && Main.rand.NextBool(4)) + { + List possibleEnemies = new List(); + if (CalamityWorld.downedPolterghast) { - int damage = CalamityWorld.downedPolterghast ? 52 : 33; - for (int i = 0; i < 16; i++) - { - float angle = MathHelper.TwoPi / 16f * i; - float angleDelta = Main.rand.NextFloat(MathHelper.TwoPi / 16f) * 0.6f; - angle += angleDelta - angleDelta / 2f; - Projectile.NewProjectile(npc.Center, angle.ToRotationVector2() * 6f, ModContent.ProjectileType(), damage, 4f); - } + possibleEnemies.Add(ModContent.NPCType()); + possibleEnemies.Add(ModContent.NPCType()); + possibleEnemies.Add(ModContent.NPCType()); + } + else + { + possibleEnemies.Add(ModContent.NPCType()); + possibleEnemies.Add(ModContent.NPCType()); + } + + SummonEnemyNearSelf(possibleEnemies); + } + } + } + + public void DoPhase2AI() + { + // Release shell gore the first frame this enemy is in the second phase. + if (!HasMadeShellBreakGore) + { + Gore.NewGore(npc.position, -Vector2.UnitY.RotatedByRandom(0.4f) * 4f, mod.GetGoreSlot("Gores/AcidRain/CragmawMireP1Gore"), npc.scale); + Gore.NewGore(npc.position, -Vector2.UnitY.RotatedByRandom(0.4f) * 4f, mod.GetGoreSlot("Gores/AcidRain/CragmawMireP1Gore2"), npc.scale); + Gore.NewGore(npc.position, -Vector2.UnitY.RotatedByRandom(0.4f) * 4f, mod.GetGoreSlot("Gores/AcidRain/CragmawMireP1Gore3"), npc.scale); + HasMadeShellBreakGore = true; + } + + // Have DR depend on the current mode. + npc.Calamity().DR = CalamityWorld.revenge ? 0.125f : 0f; + + // And use the squishy slime hit sound. + npc.HitSound = SoundID.NPCHit1; + + // Release a tether that attempts to grab the target and then release spikes upward a bit afterwards. + if (Main.netMode != NetmodeID.MultiplayerClient) + { + if (Time % 600f == 20f) + Projectile.NewProjectile(npc.Center, Vector2.UnitY, ModContent.ProjectileType(), 0, 0f, Main.myPlayer, npc.whoAmI, npc.target); + if (Time % 600f == 240f) + { + int damage = CalamityWorld.downedPolterghast ? 52 : 33; + for (int i = 0; i < 16; i++) + { + float shootDirectionAngle = MathHelper.TwoPi / 16f * i; + float offsetAngle = Main.rand.NextFloatDirection() * MathHelper.TwoPi / 27f; + shootDirectionAngle += offsetAngle; + Projectile.NewProjectile(npc.Center, shootDirectionAngle.ToRotationVector2() * 6f, ModContent.ProjectileType(), damage, 4f); } } } } + + public void SummonEnemyNearSelf(IList possibleEnemies) + { + if (Main.netMode == NetmodeID.MultiplayerClient) + return; + + int attempts = 0; + Vector2 spawnPosition = npc.Center + Utils.RandomVector2(Main.rand, -360f, 360f); + + // Ensure that the potential spawn position is actually in the world. + while (!WorldGen.InWorld((int)spawnPosition.X / 16, (int)spawnPosition.Y / 16)) + { + spawnPosition = npc.Center + Utils.RandomVector2(Main.rand, -460f, 460f); + attempts++; + if (attempts > 200) + return; + } + + attempts = 0; + + // As well as an open tile wiht water. + while (CalamityUtils.TileSelectionSolidSquare((int)spawnPosition.X / 16, (int)spawnPosition.Y / 16, 8, 8) || + CalamityUtils.ParanoidTileRetrieval((int)spawnPosition.X / 16, (int)spawnPosition.Y / 16).liquid != 255) + { + spawnPosition = npc.Center + Utils.RandomVector2(Main.rand, -620f, 620f); + attempts++; + if (attempts > 300) + return; + } + + NPC.NewNPC((int)spawnPosition.X, (int)spawnPosition.Y, Main.rand.Next(possibleEnemies)); + } + public override void ScaleExpertStats(int numPlayers, float bossLifeScale) { npc.lifeMax = (int)(npc.lifeMax * 0.8f * bossLifeScale); npc.damage = (int)(npc.damage * 0.85f); } + public override bool PreDraw(SpriteBatch spriteBatch, Color drawColor) { - Texture2D texture = Phase2 ? ModContent.GetTexture("CalamityMod/NPCs/AcidRain/CragmawMire2") : ModContent.GetTexture("CalamityMod/NPCs/AcidRain/CragmawMire"); + Texture2D texture = InPhase2 ? ModContent.GetTexture("CalamityMod/NPCs/AcidRain/CragmawMire2") : ModContent.GetTexture("CalamityMod/NPCs/AcidRain/CragmawMire"); CalamityMod.DrawTexture(spriteBatch, texture, 0, npc, drawColor, true); return false; } + public override void FindFrame(int frameHeight) { npc.frameCounter++; if (npc.frameCounter % 6 == 5) - { npc.frame.Y += frameHeight; - } if (npc.frame.Y >= frameHeight * 2) - { npc.frame.Y = 0; - } } + public override void HitEffect(int hitDirection, double damage) { for (int k = 0; k < 5; k++) - { Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.SulfurousSeaAcid, hitDirection, -1f, 0, default, 1f); - } if (npc.life <= 0) { Gore.NewGore(npc.position, -Vector2.UnitY.RotatedByRandom(0.4f) * 4f, mod.GetGoreSlot("Gores/AcidRain/CragmawMireP2Gore"), npc.scale); @@ -268,10 +302,9 @@ namespace CalamityMod.NPCs.AcidRain Gore.NewGore(npc.position, -Vector2.UnitY.RotatedByRandom(0.4f) * 4f, mod.GetGoreSlot("Gores/AcidRain/CragmawMireP2Gore3"), npc.scale); } } - public override void OnHitPlayer(Player target, int damage, bool crit) - { - target.AddBuff(ModContent.BuffType(), 300); - } + + public override void OnHitPlayer(Player target, int damage, bool crit) => target.AddBuff(ModContent.BuffType(), 300); + public override void NPCLoot() { DropHelper.DropItemChance(npc, ModContent.ItemType(), CalamityWorld.downedPolterghast ? 0.1f : 1f); diff --git a/NPCs/AcidRain/FlakCrab.cs b/NPCs/AcidRain/FlakCrab.cs index a599bffc02..4164b5e056 100644 --- a/NPCs/AcidRain/FlakCrab.cs +++ b/NPCs/AcidRain/FlakCrab.cs @@ -10,10 +10,19 @@ using System.IO; using Terraria; using Terraria.ID; using Terraria.ModLoader; + namespace CalamityMod.NPCs.AcidRain { public class FlakCrab : ModNPC { + public Player Target => Main.player[npc.target]; + public ref float ChasabilityTimer => ref npc.ai[0]; + public ref float AcidShootTimer => ref npc.ai[1]; + public ref float HopTimer => ref npc.ai[2]; + public ref float HopCounter => ref npc.ai[3]; + public ref float FleeCountdownTimer => ref npc.localAI[0]; + public ref float TotalHits => ref npc.localAI[1]; + public const int TotalHitsNeededToDoDamage = 10; public override void SetStaticDefaults() { DisplayName.SetDefault("Flak Crab"); @@ -32,7 +41,7 @@ namespace CalamityMod.NPCs.AcidRain if (CalamityWorld.downedPolterghast) { - npc.lifeMax = 7500; + npc.lifeMax = 4125; npc.DR_NERD(0.2f); } @@ -49,78 +58,68 @@ namespace CalamityMod.NPCs.AcidRain public override void SendExtraAI(BinaryWriter writer) { - writer.Write(npc.localAI[0]); - writer.Write(npc.localAI[1]); + writer.Write(FleeCountdownTimer); + writer.Write(TotalHits); } public override void ReceiveExtraAI(BinaryReader reader) { - npc.localAI[0] = reader.ReadSingle(); - npc.localAI[1] = reader.ReadSingle(); + FleeCountdownTimer = reader.ReadSingle(); + TotalHits = reader.ReadSingle(); } public override void AI() { - // Enables expert scaling, if damage is 0 in set defaults expert scaling will not happen + // Enables expert scaling, if damage is 0 in set defaults expert scaling will not happen. npc.damage = 0; - Player closest = Main.player[Player.FindClosest(npc.Top, 0, 0)]; - npc.ai[0]++; - npc.defense = npc.localAI[1] < 10f ? 999999 : 20; + ChasabilityTimer++; + npc.defense = TotalHits < TotalHitsNeededToDoDamage ? 999999 : 20; if (npc.justHit) { - npc.localAI[0] = 240; + FleeCountdownTimer = 240; npc.netUpdate = true; } - if (npc.localAI[0] == 0f || npc.localAI[1] < 10f) + + if (FleeCountdownTimer == 0f || TotalHits < TotalHitsNeededToDoDamage) { - if (npc.ai[0] < 300f) + if (ChasabilityTimer < 300f) { npc.chaseable = false; npc.knockBackResist = 0f; } - if (Math.Abs(closest.Center.X - npc.Center.X) < 320f && - closest.Center.Y - npc.Top.Y < -60f && - npc.ai[1]++ >= Main.rand.Next(90, 135)) - { - if (Main.netMode != NetmodeID.MultiplayerClient) - { - float speed = CalamityWorld.downedPolterghast ? 29f : 17f; - speed *= Main.rand.NextFloat(0.8f, 1.2f); - int damage = Main.expertMode ? CalamityWorld.downedPolterghast ? 32 : 18 : CalamityWorld.downedPolterghast ? 42 : 23; - Projectile.NewProjectile(npc.Top + Vector2.UnitY * 6f, npc.DirectionTo(closest.Center).RotatedByRandom(0.25f) * speed, - ModContent.ProjectileType(), damage, 2f); - npc.ai[1] = 0; - } - } + + AcidShootTimer++; + Player closestTargetToTop = Main.player[Player.FindClosest(npc.Top, 0, 0)]; + if (Math.Abs(closestTargetToTop.Center.X - npc.Center.X) < 320f && closestTargetToTop.Center.Y - npc.Top.Y < -60f && AcidShootTimer >= Main.rand.Next(90, 135)) + ShootFlakAcidAtTarget(closestTargetToTop); } else { - npc.localAI[0]--; - npc.chaseable = true; + FleeCountdownTimer--; if (npc.velocity.Y == 0f) { + HopTimer++; npc.knockBackResist = 0.6f; npc.TargetClosest(true); npc.velocity.X *= 0.85f; - npc.ai[2]++; - float hopRate = 10f + 15f * (npc.life / (float)npc.lifeMax); + + float hopRate = MathHelper.Lerp(25f, 10f, 1f - npc.life / (float)npc.lifeMax); float lungeForwardSpeed = 10f; float jumpSpeed = 9f; - if (Collision.CanHit(npc.Center, 1, 1, Main.player[npc.target].Center, 1, 1)) - { + if (Collision.CanHit(npc.Center, 1, 1, Target.Center, 1, 1)) lungeForwardSpeed *= 1.5f; - } - if (npc.ai[2] > hopRate) + + if (Main.netMode != NetmodeID.MultiplayerClient && HopTimer > hopRate) { - npc.ai[3] += 1f; - if (npc.ai[3] >= 3f) - { - npc.ai[3] = 0f; + HopCounter++; + + // Make a bigger leap every 3 hops. + if (HopCounter % 3f == 2f) lungeForwardSpeed *= 1.5f; - } - npc.ai[2] = 0f; + + HopTimer = 0f; npc.velocity.Y -= jumpSpeed; npc.velocity.X = lungeForwardSpeed * -npc.direction; npc.netUpdate = true; @@ -131,17 +130,34 @@ namespace CalamityMod.NPCs.AcidRain npc.knockBackResist = 0.2f; npc.velocity.X *= 0.995f; } - } - if (npc.ai[0] >= 300f && !npc.chaseable) - { npc.chaseable = true; } + + if (ChasabilityTimer >= 300f && !npc.chaseable) + npc.chaseable = true; + } + + public void ShootFlakAcidAtTarget(Player closestTargetToTop) + { + if (Main.netMode == NetmodeID.MultiplayerClient) + return; + + float speed = CalamityWorld.downedPolterghast ? 29f : 17f; + speed *= Main.rand.NextFloat(0.8f, 1.2f); + + int damage = Main.expertMode ? CalamityWorld.downedPolterghast ? 32 : 18 : CalamityWorld.downedPolterghast ? 42 : 23; + Vector2 spawnPosition = npc.Top + Vector2.UnitY * 6f; + Vector2 shootVelocity = (closestTargetToTop.Center - spawnPosition).SafeNormalize(Vector2.UnitY).RotatedByRandom(0.25f) * speed; + Projectile.NewProjectile(spawnPosition, shootVelocity, ModContent.ProjectileType(), damage, 2f); + + AcidShootTimer = 0; + npc.netUpdate = true; } public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position) { - // Don't draw the bar if in stealth mode - if (npc.localAI[0] == 0f || npc.localAI[1] < 10f) + // Don't draw the bar if in stealth mode. + if (FleeCountdownTimer == 0f || TotalHits < TotalHitsNeededToDoDamage) return false; return null; } @@ -154,12 +170,13 @@ namespace CalamityMod.NPCs.AcidRain public override void FindFrame(int frameHeight) { - if (npc.localAI[1] < 10f) + if (TotalHits < TotalHitsNeededToDoDamage) { npc.frame.Y = 0; return; } - if (npc.localAI[0] > 0f) + + if (FleeCountdownTimer > 0f) { if (npc.frameCounter++ % 6 == 5) { @@ -169,13 +186,11 @@ namespace CalamityMod.NPCs.AcidRain { npc.frame.Y = frameHeight * 3; // Frames 1 and 2 are for transitioning. Frame 0 is sitting still, and the rest are walking frames } - if (npc.localAI[0] <= 8) + if (FleeCountdownTimer <= 8) npc.frame.Y = frameHeight; } else - { npc.frame.Y = 0; - } } public override void HitEffect(int hitDirection, double damage) @@ -194,7 +209,9 @@ namespace CalamityMod.NPCs.AcidRain Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/FlakCrab2"), 1f); Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/FlakCrab3"), 1f); } - npc.localAI[1]++; + + TotalHits++; + npc.netUpdate = true; } } } diff --git a/NPCs/AcidRain/GammaSlime.cs b/NPCs/AcidRain/GammaSlime.cs index 299cd55a6e..48873cc830 100644 --- a/NPCs/AcidRain/GammaSlime.cs +++ b/NPCs/AcidRain/GammaSlime.cs @@ -6,22 +6,22 @@ using CalamityMod.Projectiles.Enemy; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; -using System.Collections.Generic; -using System.IO; using Terraria; using Terraria.ID; using Terraria.ModLoader; + namespace CalamityMod.NPCs.AcidRain { - public abstract class CalamityBoss : ModNPC - { - public abstract List Loot { get; } - } - public class GammaSlime : ModNPC { - public float angularMultiplier1; - public float angularMultiplier2; + public float DustAngleMultiplier1; + public float DustAngleMultiplier2; + public Player Target => Main.player[npc.target]; + public float LaserTelegraphPower => Utils.InverseLerp(540f, 480f, LaserShootCountdown, true); + public float LaserTelegraphLength => MathHelper.Lerp(20f, 550f, LaserTelegraphPower); + public float LaserTelegraphOpacity => MathHelper.Lerp(0.3f, 0.9f, LaserTelegraphPower); + public ref float GammaAcidShootTimer => ref npc.ai[0]; + public ref float LaserShootCountdown => ref npc.ai[1]; public override void SetStaticDefaults() { @@ -35,7 +35,7 @@ namespace CalamityMod.NPCs.AcidRain npc.height = 44; npc.damage = 110; - npc.lifeMax = 9200; + npc.lifeMax = 5060; npc.DR_NERD(0.15f); npc.defense = 25; @@ -54,98 +54,95 @@ namespace CalamityMod.NPCs.AcidRain bannerItem = ModContent.ItemType(); } - public override void SendExtraAI(BinaryWriter writer) - { - writer.Write(angularMultiplier1); - writer.Write(angularMultiplier2); - } - - public override void ReceiveExtraAI(BinaryReader reader) - { - angularMultiplier1 = reader.ReadSingle(); - angularMultiplier2 = reader.ReadSingle(); - } - public override void AI() { - Lighting.AddLight((int)((npc.position.X + (float)(npc.width / 2)) / 16f), (int)((npc.position.Y + (float)(npc.height / 2)) / 16f), 0.6f, 0.8f, 0.6f); + // Release green light at the position of the slime. + Lighting.AddLight((int)npc.Center.X / 16, (int)npc.Center.Y / 16, 0.6f, 0.8f, 0.6f); + npc.TargetClosest(false); - Player player = Main.player[npc.target]; - if (npc.velocity.Y == 0f && npc.ai[3] <= 0f && !player.npcTypeNoAggro[npc.type]) + + if (npc.velocity.Y == 0f && LaserShootCountdown <= 0f && !Target.npcTypeNoAggro[npc.type]) { npc.velocity.X *= 0.8f; - if (npc.ai[0]++ >= 30f) + + GammaAcidShootTimer++; + + // Jump into the air and release gamma acid upward. + if (GammaAcidShootTimer % 30f == 29f) { - npc.velocity.Y -= MathHelper.Clamp(Math.Abs(player.Center.Y - npc.Center.Y) / 16f, 5f, 15f); - npc.velocity.X = npc.DirectionTo(player.Center).X * 16f; - npc.ai[0] = 0f; - npc.ai[1]++; + npc.velocity.Y -= MathHelper.Clamp(Math.Abs(Target.Center.Y - npc.Center.Y) / 16f, 5f, 15f); + npc.velocity.X = npc.DirectionTo(Target.Center).X * 16f; + if (Main.netMode != NetmodeID.MultiplayerClient) { for (int i = 0; i < 5; i++) { - float angle = MathHelper.TwoPi / 5f * i + (npc.ai[1] % 2) * MathHelper.PiOver2; - Projectile.NewProjectile(npc.Center, angle.ToRotationVector2() * 7f, ModContent.ProjectileType(), - Main.expertMode ? 36 : 45, 3f); + float angle = MathHelper.TwoPi / 5f * i; + if (GammaAcidShootTimer % 60f == 58f) + angle += MathHelper.PiOver2; + Projectile.NewProjectile(npc.Center, angle.ToRotationVector2() * 7f, ModContent.ProjectileType(), Main.expertMode ? 36 : 45, 3f); } } npc.netUpdate = true; } } else - { npc.velocity.X *= 0.9935f; - } - if (npc.ai[3] > 0f) - npc.ai[3]--; - if (npc.ai[3] > 240f) + + if (LaserShootCountdown > 0f) + LaserShootCountdown--; + + // Stop moving for a bit after the laser. + if (LaserShootCountdown > 240f) { npc.velocity.X *= 0.95f; npc.velocity.Y += 0.2f; } + // Hold energy for laser - if (npc.ai[3] > 480f) + if (LaserShootCountdown > 480f) { - float scale = npc.ai[3] < 530 ? 2.25f : 1.65f; + float scale = LaserShootCountdown < 530f ? 2.25f : 1.65f; Vector2 destination = npc.Top + new Vector2(0f, 6f); - Dust dust = Dust.NewDustPerfect(destination + new Vector2(0f, 12f).RotatedByRandom(MathHelper.TwoPi), (int)CalamityDusts.SulfurousSeaAcid); + Dust dust = Dust.NewDustPerfect(destination + Main.rand.NextVector2CircularEdge(12f, 12f), (int)CalamityDusts.SulfurousSeaAcid); dust.velocity = Vector2.Normalize(destination - dust.position) * 3f; dust.scale = scale; dust.noGravity = true; - if (npc.ai[3] <= 540f) + + if (LaserShootCountdown <= 540f) { - float length = MathHelper.Lerp(20f, 550f, (npc.ai[3] - 480f) / 60f); - float outwardness = MathHelper.Lerp(1f, 0f, (npc.ai[3] - 480f) / 60f); - for (float i = npc.Top.Y + 4f; i >= npc.Top.Y + 4f - length; i -= 8f) + for (float i = npc.Top.Y + 4f; i >= npc.Top.Y + 4f - LaserTelegraphLength; i -= 8f) { float angle = i / 24f; Vector2 spawnPosition = new Vector2(npc.Center.X, i); dust = Dust.NewDustPerfect(spawnPosition, (int)CalamityDusts.SulfurousSeaAcid); dust.scale = 1.5f; - dust.velocity = Vector2.UnitX * (float)Math.Cos(angle) * 4f * outwardness; + dust.velocity = Vector2.UnitX * (float)Math.Cos(angle) * (1f - LaserTelegraphPower) * 4f; dust.noGravity = true; } } } - // Release laser - if (npc.ai[3] == 480f) + + // Release a gamma laser upward. + if (LaserShootCountdown == 480f) { - angularMultiplier1 = Main.rand.NextFloat(3f); - angularMultiplier2 = Main.rand.NextFloat(4f); - npc.netUpdate = true; + DustAngleMultiplier1 = Main.rand.NextFloat(3f); + DustAngleMultiplier2 = Main.rand.NextFloat(4f); if (Main.netMode != NetmodeID.MultiplayerClient) { - Main.PlaySound(SoundID.Zombie, (int)npc.position.X, (int)npc.position.Y, 104); // Moon lord beam sound + Main.PlaySound(SoundID.Zombie, (int)npc.position.X, (int)npc.position.Y, 104); Projectile.NewProjectile(npc.Center, -Vector2.UnitY, ModContent.ProjectileType(), Main.expertMode ? 96 : 120, 4f, Main.myPlayer, 0f, npc.whoAmI); } + npc.netUpdate = true; } + // Very complex particle effects while releasing the beam - else if (npc.ai[3] >= 300f) + else if (LaserShootCountdown >= 300f) { - float angle = (npc.ai[3] / 30f) % MathHelper.TwoPi; - float x = (float)Math.Sin(angle * angularMultiplier1) * (float)Math.Cos(angle); - float y = (float)Math.Cos(angle * angularMultiplier1) * (float)Math.Sin(angle); - Vector2 velocity = new Vector2(x * 4.5f, y * 2f); + float angle = LaserShootCountdown / 30f % MathHelper.TwoPi; + float horizontalSpeed = (float)Math.Sin(angle * DustAngleMultiplier1) * (float)Math.Cos(angle) * 4.5f; + float verticalSpeed = (float)Math.Cos(angle * DustAngleMultiplier1) * (float)Math.Sin(angle) * 2f; + Vector2 velocity = new Vector2(horizontalSpeed, verticalSpeed); Dust dust = Dust.NewDustPerfect(npc.Center + angle.ToRotationVector2() * 8f, (int)CalamityDusts.SulfurousSeaAcid); dust.velocity = velocity; dust.scale = (float)Math.Cos(angle) + 2f; @@ -156,12 +153,12 @@ namespace CalamityMod.NPCs.AcidRain dust.scale = (float)Math.Cos(angle) + 2f; dust.noGravity = true; } - if (Math.Abs(player.Center.X - npc.Center.X) < 250f && - player.Center.X - npc.Center.X < 0f && - npc.ai[3] == 0f && - Main.rand.NextBool(110) && !player.npcTypeNoAggro[npc.type]) + + // Randomly prepare to shoot a laser. + if (Main.netMode != NetmodeID.MultiplayerClient && Math.Abs(Target.Center.X - npc.Center.X) < 250f && Target.Center.X < npc.Center.X && + LaserShootCountdown == 0f && Main.rand.NextBool(110) && !Target.npcTypeNoAggro[npc.type]) { - npc.ai[3] = 600f; + LaserShootCountdown = 600f; npc.netUpdate = true; } } @@ -169,15 +166,11 @@ namespace CalamityMod.NPCs.AcidRain public override void HitEffect(int hitDirection, double damage) { for (int k = 0; k < 10; k++) - { Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.SulfurousSeaAcid, hitDirection, -1f, 0, default, 1f); - } if (npc.life <= 0) { for (int k = 0; k < 20; k++) - { Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.SulfurousSeaAcid, hitDirection, -1f, 0, default, 1f); - } Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/AcidRain/GammaSlimeGore"), npc.scale); Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/AcidRain/GammaSlimeGore2"), npc.scale); } @@ -185,23 +178,17 @@ namespace CalamityMod.NPCs.AcidRain public override void PostDraw(SpriteBatch spriteBatch, Color drawColor) { - if (npc.ai[3] >= 480f && npc.ai[3] <= 540f) + if (LaserShootCountdown >= 480f && LaserShootCountdown <= 540f) { - float length = MathHelper.Lerp(20f, 550f, (npc.ai[3] - 480f) / 60f); - float opacity = MathHelper.Lerp(0.3f, 0.9f, (npc.ai[3] - 480f) / 60f); - Utils.DrawLine(spriteBatch, npc.Top + new Vector2(0f, 4f), npc.Top + new Vector2(0f, 4f) - Vector2.UnitY * length, Color.Lerp(Color.Lime, Color.Transparent, opacity)); + Vector2 laserBottom = npc.Top + Vector2.UnitY * 4f; + Vector2 laserTop = laserBottom - Vector2.UnitY * LaserTelegraphLength; + Utils.DrawLine(spriteBatch, laserBottom, laserTop, Color.Lerp(Color.Lime, Color.Transparent, LaserTelegraphOpacity)); } CalamityGlobalNPC.DrawGlowmask(npc, spriteBatch, ModContent.GetTexture(Texture + "Glow")); } - public override void NPCLoot() - { - DropHelper.DropItemChance(npc, ModContent.ItemType(), 30); - } + public override void NPCLoot() => DropHelper.DropItemChance(npc, ModContent.ItemType(), 30); - public override void OnHitPlayer(Player target, int damage, bool crit) - { - target.AddBuff(ModContent.BuffType(), 300); - } + public override void OnHitPlayer(Player target, int damage, bool crit) => target.AddBuff(ModContent.BuffType(), 300); } } diff --git a/NPCs/AcidRain/NuclearTerror.cs b/NPCs/AcidRain/NuclearTerror.cs index 6bbf7312bf..56c8a00063 100644 --- a/NPCs/AcidRain/NuclearTerror.cs +++ b/NPCs/AcidRain/NuclearTerror.cs @@ -14,15 +14,52 @@ namespace CalamityMod.NPCs.AcidRain { public class NuclearTerror : ModNPC { + public enum SpecialAttackState + { + DivergingBullets, + ConeStreamOfBullets, + ShotgunBurstOfBullets + } + public int AttackIndex = 0; public int DelayTime = 0; public bool Dying = false; public bool Walking = false; public float JumpTimer = 0f; public Vector2 ShootPosition; - public static readonly int[] PhaseArray = new int[] + public Player Target => Main.player[npc.target]; + public ref float AttackTime => ref npc.ai[0]; + public ref float TeleportCountdown => ref npc.ai[1]; + public Vector2 TeleportLocation + { + get => new Vector2(npc.ai[2], npc.ai[3]); + set + { + npc.ai[2] = value.X; + npc.ai[3] = value.Y; + } + } + public ref float HorizontalCollisionCounterDelay => ref npc.localAI[0]; + public ref float HorizontalCollisionSpamCounter => ref npc.localAI[1]; + public static readonly SpecialAttackState[] PhaseArray = new SpecialAttackState[] { - 2, 0, 1, 1, 2, 1, 0, 2, 1, 1, 0, 1, 2, 1, 0, 2, 1 + SpecialAttackState.ShotgunBurstOfBullets, + SpecialAttackState.DivergingBullets, + SpecialAttackState.ConeStreamOfBullets, + SpecialAttackState.ConeStreamOfBullets, + SpecialAttackState.ShotgunBurstOfBullets, + SpecialAttackState.ConeStreamOfBullets, + SpecialAttackState.DivergingBullets, + SpecialAttackState.ShotgunBurstOfBullets, + SpecialAttackState.ConeStreamOfBullets, + SpecialAttackState.ConeStreamOfBullets, + SpecialAttackState.DivergingBullets, + SpecialAttackState.ConeStreamOfBullets, + SpecialAttackState.ShotgunBurstOfBullets, + SpecialAttackState.ConeStreamOfBullets, + SpecialAttackState.DivergingBullets, + SpecialAttackState.ShotgunBurstOfBullets, + SpecialAttackState.ConeStreamOfBullets }; public const int AttackCycleTime = 520; public const int SpecialAttackTime = 240; @@ -45,7 +82,7 @@ namespace CalamityMod.NPCs.AcidRain npc.height = 138; npc.aiStyle = aiType = -1; - npc.lifeMax = 360420; + npc.lifeMax = 198230; npc.defense = 50; npc.knockBackResist = 0f; @@ -77,144 +114,109 @@ namespace CalamityMod.NPCs.AcidRain JumpTimer = reader.ReadSingle(); ShootPosition = reader.ReadVector2(); } + public override void AI() { Lighting.AddLight(npc.Center, (Dying ? Color.Lime.ToVector3() : Color.White.ToVector3()) * 2f); if (Dying) return; + bool phase2 = npc.life / (float)npc.lifeMax < 0.5f; if (DelayTime > 0) { DelayTime--; npc.velocity.X *= 0.9f; if (npc.velocity.Y < 18f) - { npc.velocity.Y += 0.35f; - } return; } + if (npc.target < 0 || npc.target >= 255 || Main.player[npc.target].dead || !Main.player[npc.target].active) { npc.TargetClosest(false); npc.netUpdate = true; } - if (npc.ai[1] > -TeleportCooldown) - { + + if (TeleportCountdown > -TeleportCooldown) TeleportEffects(); - } - Player player = Main.player[npc.target]; + npc.defDamage = 170; npc.damage = Dying ? 0 : npc.defDamage; - TeleportCheck(player); - npc.ai[0]++; + TeleportCheck(); + + AttackTime++; + float wrappedAttackTime = AttackTime % AttackCycleTime; + Walking = false; - // For teleporting if constantly spam-colliding + + // Teleport if spam-collisions are done, they are pretty good indicators of being stuck. if (npc.collideX) { - if (npc.localAI[0] > 0) - { - npc.localAI[1]++; - } - npc.localAI[0] = 20f; + if (HorizontalCollisionCounterDelay > 0) + HorizontalCollisionSpamCounter++; + HorizontalCollisionCounterDelay = 20f; } - if (npc.localAI[0] > 0) - { - npc.localAI[0]--; - } - if (npc.ai[0] % AttackCycleTime < 240f) + + if (HorizontalCollisionCounterDelay > 0) + HorizontalCollisionCounterDelay--; + + if (wrappedAttackTime < 240f) { if (npc.velocity.Y == 0f) { + JumpTimer++; npc.velocity.X *= 0.8f; - if (JumpTimer++ >= 70f || !Collision.CanHit(npc.position, npc.width, npc.height, player.position, player.width, player.height)) + + // Jump towards the target if enough time has passed or they're not in this enemy's line of sight. + if (JumpTimer >= 70f || !Collision.CanHit(npc.position, npc.width, npc.height, Target.position, Target.width, Target.height)) { - npc.velocity.Y -= MathHelper.Clamp(Math.Abs(player.Center.Y - npc.Center.Y) / 12.5f, 8f, 18f); - npc.velocity.X = npc.DirectionTo(player.Center).X * 18f; JumpTimer = 0f; + npc.velocity.Y -= MathHelper.Clamp(Math.Abs(Target.Center.Y - npc.Center.Y) / 12.5f, 8f, 18f); + npc.velocity.X = npc.DirectionTo(Target.Center).X * 18f; npc.netUpdate = true; } else { - bool wasWalking = Walking; - if (wasWalking != Math.Abs(npc.velocity.X) > 4f) + if (Walking != Math.Abs(npc.velocity.X) > 4f) { Walking = Math.Abs(npc.velocity.X) > 4f; npc.netUpdate = true; } + + // Force a jump the next frame to overcome any horizontal obstacles if they exist. if (npc.collideX) { - JumpTimer = 50; // Force a jump the next frame to overcome the obstacle + JumpTimer = 50; npc.netUpdate = true; } - else if (Math.Abs(player.Center.X - npc.Center.X) > 125f) + + // Otherwise walk towards the target f they're not super close. + else if (Math.Abs(Target.Center.X - npc.Center.X) > 125f) { - npc.velocity.X += Math.Sign(npc.DirectionTo(player.Center).X) * 3f; + npc.velocity.X += Math.Sign(npc.DirectionTo(Target.Center).X) * 3f; npc.velocity.X = MathHelper.Clamp(npc.velocity.X, -28f, 28f); } + + // If they are close though, slow down horizontally. else - { npc.velocity.X *= 0.99f; - } } } npc.spriteDirection = (npc.velocity.X < 0).ToDirectionInt(); } else { - if (npc.ai[0] % AttackCycleTime == 255f) + npc.velocity.X *= 0.96f; + if (wrappedAttackTime == 255f) { - ShootPosition = player.Center; + ShootPosition = Target.Center; npc.netUpdate = true; npc.spriteDirection = (ShootPosition.X - npc.Center.X < 0).ToDirectionInt(); } - switch (PhaseArray[AttackIndex]) - { - // Tightly packed, diverging bullets - case 0: - npc.velocity.X *= 0.9f; - if (((npc.ai[0] % AttackCycleTime >= AttackCycleTime - SpecialAttackTime + 20f && npc.ai[0] % AttackCycleTime <= AttackCycleTime - SpecialAttackTime + 32f) || - (npc.ai[0] % AttackCycleTime >= AttackCycleTime - SpecialAttackTime + 50f && npc.ai[0] % AttackCycleTime <= AttackCycleTime - SpecialAttackTime + 62f) || - (npc.ai[0] % AttackCycleTime >= AttackCycleTime - SpecialAttackTime + 80f && npc.ai[0] % AttackCycleTime <= AttackCycleTime - SpecialAttackTime + 92f) || - (npc.ai[0] % AttackCycleTime >= AttackCycleTime - SpecialAttackTime + 110f && npc.ai[0] % AttackCycleTime <= AttackCycleTime - SpecialAttackTime + 122f) || - (npc.ai[0] % AttackCycleTime >= AttackCycleTime - SpecialAttackTime + 140f && npc.ai[0] % AttackCycleTime <= AttackCycleTime - SpecialAttackTime + 152f)) && npc.ai[0] % 3f == 0f) - { - if (Main.netMode != NetmodeID.MultiplayerClient) - { - float angle = (npc.ai[0] % AttackCycleTime - (AttackCycleTime - SpecialAttackTime + 20f)) % 12f / 12f * MathHelper.ToRadians(15f) - MathHelper.ToRadians(7.5f); - int idx = Projectile.NewProjectile(npc.Center, npc.DirectionTo(ShootPosition).RotatedBy(angle) * 14f, ModContent.ProjectileType(), 48, 4f); - Main.projectile[idx].localAI[0] = angle; - } - Main.PlaySound(SoundID.NPCDeath13, npc.Center); - } - if (npc.ai[0] % AttackCycleTime >= (AttackCycleTime - SpecialAttackTime + 35f) && npc.ai[0] % 10f == 9f) - { - Projectile.NewProjectile(npc.Center, npc.DirectionTo(player.Center) * 12f, ModContent.ProjectileType(), 48, 3f); - } - break; - // Cone of bullets - case 1: - npc.velocity.X *= 0.9f; - if (npc.ai[0] % AttackCycleTime >= AttackCycleTime - SpecialAttackTime + 35f && npc.ai[0] % 4f == 3f) - { - float angle = MathHelper.Lerp(MathHelper.ToRadians(35f), MathHelper.ToRadians(5f), (npc.ai[0] % AttackCycleTime - (AttackCycleTime - SpecialAttackTime + 35f)) / (SpecialAttackTime + 35f)); - Projectile.NewProjectile(npc.Center, npc.DirectionTo(player.Center).RotatedBy(angle) * 16f, ModContent.ProjectileType(), 48, 4.5f); - Projectile.NewProjectile(npc.Center, npc.DirectionTo(player.Center).RotatedBy(-angle) * 16f, ModContent.ProjectileType(), 48, 4.5f); - } - break; - // Shotgun bursts of bullets - case 2: - npc.velocity.X *= 0.9f; - if (npc.ai[0] % AttackCycleTime >= AttackCycleTime - SpecialAttackTime + 35f && npc.ai[0] % 20f == 19f) - { - for (int i = 0; i < 3; i++) - { - float angle = MathHelper.Lerp(-0.5f, 0.5f, i / 3f); - Projectile.NewProjectile(npc.Center, npc.DirectionTo(ShootPosition).RotatedBy(angle) * 13f, ModContent.ProjectileType(), 48, 4f); - } - } - break; - } - if (npc.ai[0] % AttackCycleTime == AttackCycleTime - 1f) + + PerformSpecialAttack(wrappedAttackTime); + + if (wrappedAttackTime == AttackCycleTime - 1f) { DelayTime = phase2 ? 45 : 75; AttackIndex++; @@ -222,83 +224,83 @@ namespace CalamityMod.NPCs.AcidRain } } } - public void TeleportCheck(Player player) + public void TeleportCheck() { - if (npc.ai[1] <= -TeleportCooldown) + float distanceFromTarget = npc.Distance(Target.Center); + bool targetIsFarOff = distanceFromTarget > 900f; + bool targetNotInLineOfSight = !Collision.CanHit(npc.position, npc.width, npc.height, Target.position, Target.width, Target.height); + if (TeleportCountdown <= -TeleportCooldown) { - if (npc.Distance(player.Center) > 2700f || - (!Collision.CanHit(npc.position, npc.width, npc.height, player.position, player.width, player.height) && npc.Distance(player.Center) > 900f) || - StuckOnPlatform(player) || - npc.wet || - npc.localAI[1] > 5f) + if (distanceFromTarget <= 2700f && !(targetIsFarOff && targetNotInLineOfSight) && !StuckOnPlatform() && !npc.wet && HorizontalCollisionSpamCounter <= 5f) + return; + + Point playerPositionTileCoords = Target.position.ToTileCoordinates(); + Point npcPositionTileCoords = npc.position.ToTileCoordinates(); + + for (int tries = 0; tries < 250; tries++) { - Point playerPositionTileCoords = player.position.ToTileCoordinates(); - Point npcPositionTileCoords = npc.position.ToTileCoordinates(); - int tries = 0; - int maxTeleportDistance = 20; - bool cannotTeleport = false; - while (!cannotTeleport && tries < 250) + int maxTeleportDistance = 30 + tries / 3; + int x = Main.rand.Next(playerPositionTileCoords.X - maxTeleportDistance, playerPositionTileCoords.X + maxTeleportDistance); + int yStart = Main.rand.Next(playerPositionTileCoords.Y - maxTeleportDistance, playerPositionTileCoords.Y + maxTeleportDistance); + + // Have a downward bias for the teleport if stuck on a platform above the target. + if (StuckOnPlatform()) + yStart = Main.rand.Next(playerPositionTileCoords.Y, playerPositionTileCoords.Y + maxTeleportDistance * 4); + + for (int y = yStart; y < playerPositionTileCoords.Y + maxTeleportDistance; y++) { - tries++; - int x = Main.rand.Next(playerPositionTileCoords.X - maxTeleportDistance, playerPositionTileCoords.X + maxTeleportDistance); - int yStart = Main.rand.Next(playerPositionTileCoords.Y - maxTeleportDistance, playerPositionTileCoords.Y + maxTeleportDistance); - if (StuckOnPlatform(player)) + Tile tileBelow = CalamityUtils.ParanoidTileRetrieval(x, y - 1); + bool veryCloseToTarget = Math.Abs(y - playerPositionTileCoords.Y) < 12 || Math.Abs(x - playerPositionTileCoords.X) < 12; + bool veryCloseToSelf = Math.Abs(y - npcPositionTileCoords.Y) < 12 || Math.Abs(x - npcPositionTileCoords.X) < 12; + bool solidGround = (Main.tileSolid[tileBelow.type] || Main.tileSolidTop[tileBelow.type]) && tileBelow.active(); + if (!veryCloseToTarget && !veryCloseToSelf && solidGround) { - yStart = Main.rand.Next(playerPositionTileCoords.Y, playerPositionTileCoords.Y + 4 * maxTeleportDistance); - } - for (int y = yStart; y < playerPositionTileCoords.Y + maxTeleportDistance; y++) - { - if ((y < playerPositionTileCoords.Y - 12 || y > playerPositionTileCoords.Y + 12 || x < playerPositionTileCoords.X - 12 || x > playerPositionTileCoords.X + 12) - && (y < npcPositionTileCoords.Y - 8 || y > npcPositionTileCoords.Y + 8 || x < npcPositionTileCoords.X - 7 || x > npcPositionTileCoords.X + 7) - && CalamityUtils.ParanoidTileRetrieval(x, y).nactive()) + // If the below tile has lava, skip it. + if (CalamityUtils.ParanoidTileRetrieval(x, y - 1).lava()) + continue; + + // If there's any tiles in the way, skip it. + if (Collision.SolidTiles(x - 12, x + 12, y - 7, y - 7)) + continue; + + // If there's any liquid near the tile, skip it. + for (int dy = y - 8; dy <= y + 8; dy++) { - bool canTeleport = true; - if (CalamityUtils.ParanoidTileRetrieval(x, y - 1).lava()) - { - canTeleport = false; - } - if (canTeleport && - Main.tileSolid[CalamityUtils.ParanoidTileRetrieval(x, y).type] && - !Collision.SolidTiles(x - 12, x + 12, y - 7, y - 7)) - { - for (int dy = y - 5; dy <= y; dy++) - { - if (CalamityUtils.ParanoidTileRetrieval(x, dy).liquid > 0) - { - continue; - } - } - npc.ai[1] = TeleportTime; - npc.ai[2] = x; - npc.ai[3] = y - 3; - cannotTeleport = true; - npc.localAI[1] = 0f; - break; - } + if (CalamityUtils.ParanoidTileRetrieval(x, dy).liquid > 0) + goto Continue; } + + TeleportCountdown = TeleportTime; + TeleportLocation = new Vector2(x, y - 6f); + HorizontalCollisionSpamCounter = 0f; + npc.netUpdate = true; + + return; + Continue: + continue; } } - npc.netUpdate = true; } } } + public void TeleportEffects() { - if (npc.ai[1] > TeleportTime) - npc.ai[1] = TeleportTime; - npc.ai[1]--; - if (npc.ai[1] >= 0f) + if (TeleportCountdown > TeleportTime) + TeleportCountdown = TeleportTime; + TeleportCountdown--; + if (TeleportCountdown >= 0f) { - if (npc.ai[1] == 0f && npc.ai[2] != 0f && npc.ai[3] != 0f) + if (TeleportCountdown == 0f && TeleportLocation != Vector2.Zero) { - npc.position.X = npc.ai[2] * 16f - npc.width / 2 + 8f; - npc.position.Y = npc.ai[3] * 16f - npc.height; + npc.position = TeleportLocation.ToWorldCoordinates(8f, 0f) - npc.Size; npc.netUpdate = true; npc.velocity = Vector2.Zero; } else { - npc.alpha = (int)MathHelper.Lerp(0f, 255f, 1f - npc.ai[1] / TeleportTime); + npc.Opacity = TeleportCountdown / TeleportTime; + int totalDust = (int)(30 * npc.alpha / 255f); for (int i = 0; i < totalDust; i++) { @@ -307,18 +309,20 @@ namespace CalamityMod.NPCs.AcidRain dust.velocity = npc.DirectionFrom(dust.position) * 2f; dust.scale = 1.6f; } + + // Fall and slow down horizontally. npc.velocity.X *= 0.95f; if (npc.velocity.Y < 18f) - { npc.velocity.Y += 0.35f; - } } return; } - else if (npc.ai[1] >= -TeleportFadeinTime) + + // Release some dust before going back to normal. + if (TeleportCountdown >= -TeleportFadeinTime) { - npc.alpha = (int)MathHelper.Lerp(255f, 0f, npc.ai[1] / -TeleportFadeinTime); - if (npc.ai[1] == -TeleportFadeinTime) + npc.Opacity = TeleportCountdown / -TeleportFadeinTime; + if (TeleportCountdown == -TeleportFadeinTime) { for (int i = 0; i < 48; i++) { @@ -330,16 +334,79 @@ namespace CalamityMod.NPCs.AcidRain } } } - public bool StuckOnPlatform(Player player) + + public bool StuckOnPlatform() { - for (int i = 0; i < 18; i++) + for (int i = -12; i < 12; i++) { Point bottom = (npc.Bottom + Vector2.UnitY * i).ToTileCoordinates(); - if (TileID.Sets.Platforms[CalamityUtils.ParanoidTileRetrieval(bottom.X, bottom.Y).type] && player.Top.Y > npc.Bottom.Y + 48) + if (TileID.Sets.Platforms[CalamityUtils.ParanoidTileRetrieval(bottom.X, bottom.Y).type] && Target.Top.Y > npc.Bottom.Y + 48) return true; } return false; } + + public void PerformSpecialAttack(float wrappedAttackTime) + { + Vector2 mouthPosition = npc.Center - Vector2.UnitY * 26f; + mouthPosition.X += npc.spriteDirection * -54f; + + TeleportCountdown = -TeleportCooldown; + Vector2 directionToTarget = (Target.Center - mouthPosition).SafeNormalize(Vector2.UnitX * npc.spriteDirection); + Vector2 directionToShootPosition = (ShootPosition - mouthPosition).SafeNormalize(Vector2.UnitX * npc.spriteDirection); + switch (PhaseArray[AttackIndex]) + { + case SpecialAttackState.DivergingBullets: + npc.velocity.X *= 0.9f; + float shootAdjustedTime = wrappedAttackTime - (AttackCycleTime - SpecialAttackTime); + bool shouldShoot = shootAdjustedTime >= 20f; + shouldShoot &= (shootAdjustedTime - 20f) % 30f < 12f; + shouldShoot &= shootAdjustedTime <= 152f; + shouldShoot &= shootAdjustedTime % 3f == 0f; + + if (shouldShoot) + { + if (Main.netMode != NetmodeID.MultiplayerClient) + { + float angle = (wrappedAttackTime - (AttackCycleTime - SpecialAttackTime + 20f)) % 12f / 12f * MathHelper.ToRadians(15f) - MathHelper.ToRadians(7.5f); + int bullet = Projectile.NewProjectile(mouthPosition, directionToShootPosition.RotatedBy(angle) * 14f, ModContent.ProjectileType(), 48, 4f); + Main.projectile[bullet].localAI[0] = angle; + } + npc.spriteDirection = (ShootPosition.X - npc.Center.X < 0).ToDirectionInt(); + Main.PlaySound(SoundID.NPCDeath13, mouthPosition); + } + if (wrappedAttackTime >= (AttackCycleTime - SpecialAttackTime + 35f) && AttackTime % 10f == 9f) + Projectile.NewProjectile(mouthPosition, directionToTarget * 12f, ModContent.ProjectileType(), 48, 3f); + break; + case SpecialAttackState.ConeStreamOfBullets: + if (wrappedAttackTime >= AttackCycleTime - SpecialAttackTime + 35f && AttackTime % 4f == 3f) + { + if (Main.netMode != NetmodeID.MultiplayerClient) + { + float angle = MathHelper.Lerp(MathHelper.ToRadians(35f), MathHelper.ToRadians(5f), (wrappedAttackTime - (AttackCycleTime - SpecialAttackTime + 35f)) / (SpecialAttackTime + 35f)); + Projectile.NewProjectile(mouthPosition, directionToTarget.RotatedBy(angle) * 16f, ModContent.ProjectileType(), 48, 4.5f); + Projectile.NewProjectile(mouthPosition, directionToTarget.RotatedBy(-angle) * 16f, ModContent.ProjectileType(), 48, 4.5f); + } + npc.spriteDirection = (Target.Center.X - npc.Center.X < 0).ToDirectionInt(); + } + break; + case SpecialAttackState.ShotgunBurstOfBullets: + if (wrappedAttackTime >= AttackCycleTime - SpecialAttackTime + 35f && AttackTime % 20f == 19f) + { + if (Main.netMode != NetmodeID.MultiplayerClient) + { + for (int i = 0; i < 3; i++) + { + float angle = MathHelper.Lerp(-0.5f, 0.5f, i / 3f); + Projectile.NewProjectile(mouthPosition, directionToShootPosition.RotatedBy(angle) * 13f, ModContent.ProjectileType(), 48, 4f); + } + } + npc.spriteDirection = (ShootPosition.X - npc.Center.X < 0).ToDirectionInt(); + } + break; + } + } + public override void ScaleExpertStats(int numPlayers, float bossLifeScale) { npc.lifeMax = (int)(npc.lifeMax * 0.8f * bossLifeScale); @@ -348,12 +415,13 @@ namespace CalamityMod.NPCs.AcidRain public override void FindFrame(int frameHeight) { npc.frameCounter++; - int framesNeeded = Dying ? 7 : 6; + int frameChangeRate = Dying ? 7 : 6; + + // Walk faster the faster this thing is moving. if (Walking) - { - framesNeeded = 8 - (int)Math.Ceiling(Math.Abs(npc.velocity.X) / 5f); // Walk faster the faster we're moving - } - if (npc.frameCounter >= framesNeeded) + frameChangeRate = 8 - (int)Math.Ceiling(Math.Abs(npc.velocity.X) / 5f); + + if (npc.frameCounter >= frameChangeRate) { npc.frame.Y += frameHeight; npc.frameCounter = 0; @@ -381,14 +449,10 @@ namespace CalamityMod.NPCs.AcidRain npc.frame.Y = frameHeight * 8; } if (npc.frame.Y >= frameHeight * Main.npcFrameCount[npc.type]) - { npc.StrikeNPCNoInteraction(9999, 0f, 0); - } } else if (npc.frame.Y >= (Walking ? 8 : 4) * frameHeight) - { npc.frame.Y = Walking ? 4 * frameHeight : 0; - } } public override bool PreDraw(SpriteBatch spriteBatch, Color drawColor) { @@ -401,31 +465,30 @@ namespace CalamityMod.NPCs.AcidRain } return false; } + public override bool CheckDead() { if (!Dying) { + Dying = true; npc.active = true; npc.life = 1; npc.dontTakeDamage = true; - Dying = true; npc.velocity = Vector2.Zero; npc.netUpdate = true; return false; } return Dying; } + public override void HitEffect(int hitDirection, double damage) { for (int k = 0; k < 10; k++) - { Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.SulfurousSeaAcid, hitDirection, -1f, 0, default, 1f); - } - } - public override void OnHitPlayer(Player target, int damage, bool crit) - { - target.AddBuff(ModContent.BuffType(), 300); } + + public override void OnHitPlayer(Player target, int damage, bool crit) => target.AddBuff(ModContent.BuffType(), 300); + public override void NPCLoot() { DropHelper.DropItemChance(npc, ModContent.ItemType(), 3); diff --git a/NPCs/AcidRain/NuclearToad.cs b/NPCs/AcidRain/NuclearToad.cs index dcd092969a..d31261d687 100644 --- a/NPCs/AcidRain/NuclearToad.cs +++ b/NPCs/AcidRain/NuclearToad.cs @@ -1,3 +1,4 @@ +using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Dusts; using CalamityMod.Projectiles.Enemy; using CalamityMod.Items.Placeables.Banners; @@ -7,11 +8,12 @@ using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ID; using Terraria.ModLoader; -using CalamityMod.Buffs.StatDebuffs; + namespace CalamityMod.NPCs.AcidRain { public class NuclearToad : ModNPC { + public Player Target => Main.player[npc.target]; public override void SetStaticDefaults() { DisplayName.SetDefault("Nuclear Toad"); @@ -33,7 +35,7 @@ namespace CalamityMod.NPCs.AcidRain if (CalamityWorld.downedPolterghast) { npc.damage = 80; - npc.lifeMax = 5000; + npc.lifeMax = 2750; npc.defense = 15; } else if (CalamityWorld.downedAquaticScourge) @@ -56,43 +58,39 @@ namespace CalamityMod.NPCs.AcidRain public override void AI() { npc.TargetClosest(false); - Player player = Main.player[npc.target]; - // Slow down over time on the X axis (to prevent endless sliding as a result of KB) + // Slow down over time on the X axis (to prevent endless sliding as a result of KB). npc.velocity.X *= 0.96f; - // Hover on the top of the water + // Bob on the top of the water. if (npc.wet) { if (npc.velocity.Y > 2f) - { npc.velocity.Y *= 0.9f; - } npc.velocity.Y -= 0.16f; if (npc.velocity.Y < -4f) - { npc.velocity.Y = -4f; - } } else { if (npc.velocity.Y < -2f) - { npc.velocity.Y *= 0.9f; - } npc.velocity.Y += 0.16f; if (npc.velocity.Y > 3f) - { npc.velocity.Y = 3f; - } npc.ai[0] = 5f; } + + // Make a frog croak sound from time to time. if (Main.rand.NextBool(480)) - Main.PlaySound(SoundID.Zombie, npc.Center, 13); // Ribbit sound + Main.PlaySound(SoundID.Zombie, npc.Center, 13); + float explodeDistance = CalamityWorld.downedAquaticScourge ? 295f : 195f; if (CalamityWorld.downedPolterghast) explodeDistance = 470f; - if (npc.Distance(player.Center) < explodeDistance) + + // Explode if a player gets too close. + if (npc.WithinRange(Target.Center, explodeDistance)) { if (Main.netMode != NetmodeID.MultiplayerClient) { @@ -103,11 +101,9 @@ namespace CalamityMod.NPCs.AcidRain speed *= 1.8f; damage = Main.expertMode ? 36 : 45; } + for (int i = 0; i < 7; i++) - { - float angle = Main.rand.NextFloat(MathHelper.TwoPi); - Projectile.NewProjectile(npc.Center, angle.ToRotationVector2() * speed, ModContent.ProjectileType(), damage, 1f); - } + Projectile.NewProjectile(npc.Center, Main.rand.NextVector2CircularEdge(speed, speed), ModContent.ProjectileType(), damage, 1f); } Main.PlaySound(SoundID.DD2_KoboldExplosion, npc.Center); npc.life = 0; @@ -125,18 +121,15 @@ namespace CalamityMod.NPCs.AcidRain npc.frameCounter = 0; npc.frame.Y += frameHeight; if (npc.frame.Y >= Main.npcFrameCount[npc.type] * frameHeight) - { npc.frame.Y = 0; - } } } public override void HitEffect(int hitDirection, double damage) { for (int k = 0; k < 8; k++) - { Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.SulfurousSeaAcid, hitDirection, -1f, 0, default, 1f); - } + if (npc.life <= 0) { Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/AcidRain/NuclearToadGore1"), npc.scale); @@ -144,20 +137,12 @@ namespace CalamityMod.NPCs.AcidRain Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/AcidRain/NuclearToadGore3"), npc.scale); Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/AcidRain/NuclearToadGore4"), npc.scale); for (int i = 0; i < 25; i++) - { Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.SulfurousSeaAcid, Main.rand.NextFloat(-2f, 2f), -1f, 0, default, 1f); - } } } - public override void OnHitPlayer(Player target, int damage, bool crit) - { - target.AddBuff(ModContent.BuffType(), 300); - } + public override void OnHitPlayer(Player target, int damage, bool crit) => target.AddBuff(ModContent.BuffType(), 300); - public override void PostDraw(SpriteBatch spriteBatch, Color drawColor) - { - CalamityGlobalNPC.DrawGlowmask(npc, spriteBatch, ModContent.GetTexture(Texture + "Glow"), true); - } + public override void PostDraw(SpriteBatch spriteBatch, Color drawColor) => CalamityGlobalNPC.DrawGlowmask(npc, spriteBatch, ModContent.GetTexture(Texture + "Glow"), true); } } diff --git a/NPCs/AcidRain/Orthocera.cs b/NPCs/AcidRain/Orthocera.cs index 0e34e7a0a5..8157990f5e 100644 --- a/NPCs/AcidRain/Orthocera.cs +++ b/NPCs/AcidRain/Orthocera.cs @@ -1,3 +1,4 @@ +using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Dusts; using CalamityMod.Items.Placeables.Banners; using CalamityMod.Items.Materials; @@ -9,11 +10,24 @@ using Terraria; using Terraria.ID; using Terraria.ModLoader; using Microsoft.Xna.Framework; -using CalamityMod.Buffs.StatDebuffs; + namespace CalamityMod.NPCs.AcidRain { public class Orthocera : ModNPC { + public ref float FallDelay => ref npc.ai[0]; + public ref float Time => ref npc.ai[1]; + public ref float HorizontalSpeed => ref npc.ai[2]; + public bool PerformingJump + { + get => npc.ai[3] == 1f; + set + { + if (Main.netMode == NetmodeID.Server && value != PerformingJump) + npc.netUpdate = true; + npc.ai[3] = value.ToInt(); + } + } public override void SetStaticDefaults() { DisplayName.SetDefault("Orthocera"); @@ -34,7 +48,7 @@ namespace CalamityMod.NPCs.AcidRain if (CalamityWorld.downedPolterghast) { npc.damage = 120; - npc.lifeMax = 7000; + npc.lifeMax = 3850; npc.defense = 35; npc.DR_NERD(0.15f); } @@ -52,110 +66,116 @@ namespace CalamityMod.NPCs.AcidRain public override void AI() { + Time++; npc.TargetClosest(false); - npc.ai[1] += 1f; float maxSpeed = CalamityWorld.downedPolterghast ? 12.8f : 10.5f; - if (npc.target >= 0 && npc.target < 255) + if (!Main.player.IndexInRange(npc.target)) + return; + + Player player = Main.player[npc.target]; + + // Swim. + if (Time % 250f < 180f) { - Player player = Main.player[npc.target]; - // Swim - if (npc.ai[1] % 250f < 180f) + if (npc.wet) { - if (npc.wet) - { - // Reset so we can jum again. - npc.ai[3] = 0f; + // Reset to allow a jumps. + if (PerformingJump) + PerformingJump = false; - // Swim towards the player if we're not too close. - // If we're close, simply resume our current movement. - if (npc.Distance(player.Center) > 150f) + // Swim towards the player if we're not too close. + // If close, simply resume current movement. + if (!npc.WithinRange(player.Center, 150f)) + { + npc.velocity = (npc.velocity * 17f + npc.DirectionTo(player.Center) * maxSpeed) / 18f; + if (FallDelay != 12f) { - npc.velocity = (npc.velocity * 17f + npc.DirectionTo(player.Center) * maxSpeed) / 18f; - if (npc.ai[0] != 12f) - { - npc.ai[0] = 12f; - npc.netUpdate = true; - } + FallDelay = 12f; + npc.netUpdate = true; } - // Variable for X movement later. - // It seems to slow down for some dumb reason in the jump phase without this value - npc.ai[2] = npc.velocity.X; - - // Make sure the value isn't 0 since we're relying on multiplication - if (npc.ai[2] == 0f) - npc.ai[2] = 0.1f; - - if (Math.Abs(npc.ai[2]) < 7f) - npc.ai[2] = Math.Abs(npc.ai[2]) * 7f; - if (Math.Abs(npc.ai[2]) > 16f) - npc.ai[2] = Math.Abs(npc.ai[2]) * 16f; - npc.ai[2] = Math.Abs(npc.ai[2]) * (player.Center.X - npc.Center.X > 0).ToDirectionInt(); } + + // Store for horizontal movement for later. + // It seems to slow down for some dumb reason in the jump phase without this value. + HorizontalSpeed = npc.velocity.X; + + // Make sure the value isn't 0 since we're relying on multiplication + if (HorizontalSpeed == 0f) + HorizontalSpeed = 0.1f; + + if (Math.Abs(HorizontalSpeed) < 7f) + HorizontalSpeed = Math.Abs(HorizontalSpeed) * 7f; + if (Math.Abs(HorizontalSpeed) > 16f) + HorizontalSpeed = Math.Abs(HorizontalSpeed) * 16f; + HorizontalSpeed = Math.Abs(HorizontalSpeed) * (player.Center.X - npc.Center.X > 0).ToDirectionInt(); + } + else + { + if (FallDelay <= 0f) + npc.velocity.Y += 0.2f; else - { - if (npc.ai[0] <= 0f) - npc.velocity.Y += 0.2f; - else - npc.ai[0] -= 1f; - } - npc.direction = npc.spriteDirection = (npc.velocity.X > 0).ToDirectionInt(); + FallDelay--; } - // And jump/shoot - else if (npc.ai[1] % 220f > 180f) - { - float yAcceleration = CalamityWorld.downedPolterghast ? 0.07f : 0.05f; - if (npc.ai[1] % 220f < 200f) - { - npc.velocity.Y -= yAcceleration; - } - else - { - npc.velocity.Y += yAcceleration; - } - if (npc.ai[1] % 220f == 219f) - npc.ai[3] = 1f; - if (!npc.wet) - npc.velocity.X = npc.ai[2]; - } - // Don't jump mid-air - if (npc.ai[1] % 220f > 180f && npc.ai[3] == 1f) - { - npc.ai[1] = 0f; - npc.netUpdate = true; - } - npc.rotation = npc.velocity.ToRotation() + MathHelper.PiOver4 + MathHelper.PiOver2 + MathHelper.Pi; - - if (npc.spriteDirection == -1) - npc.rotation -= MathHelper.PiOver2; - // If sitting on land, slow down and, if in the middle of a jump, release a stream of acid. - if (!npc.wet) - { - npc.velocity.X *= 0.92f; - // Spit out a stream of acid based on our rotation - if (npc.ai[1] % 220f == 195f) - { - float rotation = npc.rotation - MathHelper.Pi - MathHelper.PiOver2 - MathHelper.PiOver4; - if (npc.spriteDirection == -1) - rotation += MathHelper.PiOver2; - - int damage = CalamityWorld.downedPolterghast ? 40 : CalamityWorld.downedAquaticScourge ? 26 : 18; - if (Main.expertMode) - damage = (int)Math.Round(damage * 0.8); - - if (CalamityWorld.downedPolterghast) - { - for (int i = 0; i < 2; i++) - { - float angle = MathHelper.Lerp(-0.3f, 0.3f, i / 2f); - Projectile.NewProjectile(npc.Center, (rotation + angle).ToRotationVector2() * 10f, ModContent.ProjectileType(), damage, 2f); - } - } - Projectile.NewProjectile(npc.Center, rotation.ToRotationVector2() * 12f, ModContent.ProjectileType(), damage, 2f); - } - } - // Prevent yeeting into the sky at the speed of light - npc.velocity = Vector2.Clamp(npc.velocity, new Vector2(-maxSpeed), new Vector2(maxSpeed)); + npc.direction = npc.spriteDirection = (npc.velocity.X > 0).ToDirectionInt(); } + // And jump/shoot. + else if (Time % 220f > 180f) + { + float verticalAcceleration = CalamityWorld.downedPolterghast ? 0.07f : 0.05f; + if (Time % 220f < 200f) + npc.velocity.Y -= verticalAcceleration; + else + npc.velocity.Y += verticalAcceleration; + + if (Time % 220f == 219f) + PerformingJump = true; + if (!npc.wet) + npc.velocity.X = HorizontalSpeed; + } + + // Don't jump mid-air. + if (Time % 220f > 180f && PerformingJump) + { + Time = 0f; + npc.netUpdate = true; + } + + npc.rotation = npc.velocity.ToRotation() + MathHelper.PiOver4 + MathHelper.PiOver2 + MathHelper.Pi; + + if (npc.spriteDirection == -1) + npc.rotation -= MathHelper.PiOver2; + + // If sitting on land, slow down and, if in the middle of a jump, release a stream of acid. + if (!npc.wet) + { + npc.velocity.X *= 0.92f; + + // Spit out a stream of acid based on the rotation of this NPC. + if (Main.netMode != NetmodeID.MultiplayerClient && Time % 220f == 195f) + { + float spitDirection = npc.rotation - MathHelper.TwoPi * 0.875f; + if (npc.spriteDirection == -1) + spitDirection += MathHelper.PiOver2; + + int damage = CalamityWorld.downedPolterghast ? 40 : CalamityWorld.downedAquaticScourge ? 26 : 18; + if (Main.expertMode) + damage = (int)Math.Round(damage * 0.8); + + // Spit two extra streams of acid at the target post-Polterghast. + if (CalamityWorld.downedPolterghast) + { + for (int i = 0; i < 2; i++) + { + float offsetAngle = MathHelper.Lerp(-0.3f, 0.3f, i / 2f); + Projectile.NewProjectile(npc.Center, (spitDirection + offsetAngle).ToRotationVector2() * 10f, ModContent.ProjectileType(), damage, 2f); + } + } + Projectile.NewProjectile(npc.Center, spitDirection.ToRotationVector2() * 12f, ModContent.ProjectileType(), damage, 2f); + } + } + + // Prevent yeeting into the sky at the speed of light. + npc.velocity = Vector2.Clamp(npc.velocity, new Vector2(-maxSpeed), new Vector2(maxSpeed)); } public override void NPCLoot() @@ -172,32 +192,23 @@ namespace CalamityMod.NPCs.AcidRain npc.frameCounter = 0; npc.frame.Y += frameHeight; if (npc.frame.Y >= Main.npcFrameCount[npc.type] * frameHeight) - { npc.frame.Y = 0; - } } } public override void HitEffect(int hitDirection, double damage) { for (int k = 0; k < 5; k++) - { Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.SulfurousSeaAcid, hitDirection, -1f, 0, default, 1f); - } if (npc.life <= 0) { Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/AcidRain/OrthoceraGore"), npc.scale); Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/AcidRain/OrthoceraGore2"), npc.scale); for (int k = 0; k < 10; k++) - { Dust.NewDust(npc.position, npc.width, npc.height, DustID.Blood, hitDirection, -1f, 0, default, 1f); - } } } - public override void OnHitPlayer(Player target, int damage, bool crit) - { - target.AddBuff(ModContent.BuffType(), 180); - } + public override void OnHitPlayer(Player target, int damage, bool crit) => target.AddBuff(ModContent.BuffType(), 180); } } diff --git a/NPCs/AcidRain/Skyfin.cs b/NPCs/AcidRain/Skyfin.cs index 8eb2ff0767..45df423cec 100644 --- a/NPCs/AcidRain/Skyfin.cs +++ b/NPCs/AcidRain/Skyfin.cs @@ -2,6 +2,7 @@ using CalamityMod.Dusts; using CalamityMod.Items.Placeables.Banners; using CalamityMod.Items.Materials; using CalamityMod.Items.Weapons.Rogue; +using CalamityMod.Buffs.StatDebuffs; using CalamityMod.World; using Microsoft.Xna.Framework; using System; @@ -9,15 +10,20 @@ using System.IO; using Terraria; using Terraria.ID; using Terraria.ModLoader; -using CalamityMod.Buffs.StatDebuffs; + namespace CalamityMod.NPCs.AcidRain { public class Skyfin : ModNPC { + public bool Flying = false; + public Player Target => Main.player[npc.target]; + public ref float Time => ref npc.ai[0]; + public ref float DiveTimer => ref npc.ai[1]; + public ref float HorizontalDiveSpeed => ref npc.ai[2]; + public ref float WaitBeforeFlyingMovement => ref npc.ai[3]; public const float DiveDelay = 120f; public const float DiveTime = 90f; - public const float TotalTime = DiveDelay + DiveTime; - public bool Flying = false; + public const float TotalDiveTime = DiveDelay + DiveTime; public override void SetStaticDefaults() { @@ -40,7 +46,7 @@ namespace CalamityMod.NPCs.AcidRain { npc.knockBackResist = 0.8f; npc.damage = 88; - npc.lifeMax = 5500; + npc.lifeMax = 3025; npc.defense = 18; npc.DR_NERD(0.05f); } @@ -60,163 +66,150 @@ namespace CalamityMod.NPCs.AcidRain bannerItem = ModContent.ItemType(); } - public override void SendExtraAI(BinaryWriter writer) - { - writer.Write(Flying); - } + public override void SendExtraAI(BinaryWriter writer) => writer.Write(Flying); - public override void ReceiveExtraAI(BinaryReader reader) - { - Flying = reader.ReadBoolean(); - } + public override void ReceiveExtraAI(BinaryReader reader) => Flying = reader.ReadBoolean(); public override void AI() { npc.TargetClosest(false); - Player player = Main.player[npc.target]; - if (!Flying) - { - npc.ai[0] += 1f; - if (npc.ai[1] > 0f) - npc.ai[1] -= 1f; - if (npc.wet) - { - // Swim around, moving towards the player - bool canSwimToPlayer = Collision.CanHit(npc.position, npc.width, npc.height, player.position, player.width, player.height); - if (canSwimToPlayer) - { - if (npc.ai[0] % 55f == 54f) - { - float horizontalSchoolingSpeed = 9f; - if (CalamityWorld.downedAquaticScourge) - { - horizontalSchoolingSpeed = 15f; - } - if (CalamityWorld.downedPolterghast) - { - horizontalSchoolingSpeed = 24f; - } - npc.velocity = Vector2.UnitX * (player.Center.X - npc.Center.X > 0).ToDirectionInt() * horizontalSchoolingSpeed; - } - if ((Math.Abs(player.Center.Y - npc.Center.Y) > 50f && player.wet) || (!player.wet && npc.ai[1] <= 0f)) - { - float speedY = CalamityWorld.downedPolterghast ? 10f : 6f; - npc.velocity.Y = (player.Center.Y - npc.Center.Y > 0).ToDirectionInt() * speedY; - } - if (Math.Abs(npc.velocity.X) < 6f) - npc.velocity.X *= 1.04f; - } - else if (!canSwimToPlayer && Math.Abs(npc.velocity.Y) < 4f) - { - npc.velocity.Y *= 0.97f; - } - // Turn around if we hit a tile on the X axis - if (!canSwimToPlayer && npc.collideX) - { - npc.velocity.X *= -1f; - } - // Check if we can dive - if (player.Center.Y < npc.Top.Y - 10f && - npc.ai[1] <= 0f) - { - if (Main.rand.NextBool(10)) - { - npc.ai[1] = TotalTime; - } - npc.ai[2] = (player.Center.X - npc.Center.X > 0).ToDirectionInt() * 10f; - } - } - else + if (Flying) + FlyTowardsTarget(); + else + DoSwimMovement(); + int idealDirection = (npc.velocity.X > 0).ToDirectionInt(); + npc.direction = npc.spriteDirection = idealDirection; + if (idealDirection != npc.direction) + npc.netUpdate = true; + + npc.rotation = npc.velocity.ToRotation() + (npc.direction > 0).ToInt() * MathHelper.Pi; + } + + public void FlyTowardsTarget() + { + npc.noTileCollide = true; + Time++; + if (Time % 300f >= 180f) + { + // Rise upward. + if (Time % 300f <= 205f) + npc.velocity.Y = MathHelper.Lerp(npc.velocity.Y, -6.5f, 0.07f); + + // And fly towards the target. + if (Time % 300f == 235f) { - // Consistently update the enemy. - if (npc.ai[3] % 40f == 39f) - { - npc.netUpdate = true; - } - // Dive upward in an attempt to hit to the player - if (npc.ai[1] > TotalTime - DiveTime) - { - npc.velocity.X = npc.ai[2]; - if (npc.ai[1] > TotalTime - DiveTime * 0.5f) - { - float flySpeed = CalamityWorld.downedAquaticScourge ? 0.115f : 0.085f; - if (CalamityWorld.downedPolterghast) - { - flySpeed = 0.135f; - } - npc.velocity.Y -= flySpeed; - } - else - { - npc.ai[1] = TotalTime - DiveTime; - npc.velocity.Y += 0.2f; - } - } - else - { - // Don't fall too fast because of wings - npc.ai[1] = TotalTime - DiveTime; - npc.velocity.Y += 0.1f; - npc.ai[3]++; - if (npc.ai[3] > 420f) - { - npc.ai[0] = npc.ai[1] = npc.ai[2] = npc.ai[3] = 0f; - Flying = true; - npc.netUpdate = true; - } - } - } - // If sitting on land, rotate in a way that looks like we're stuck on the ground - if (!npc.wet) - { - npc.velocity.X *= 0.92f; + float chargeSpeed = 8f; + if (CalamityWorld.downedAquaticScourge) + chargeSpeed = 14f; + if (CalamityWorld.downedPolterghast) + chargeSpeed = 18f; + npc.velocity = npc.DirectionTo(Target.Center) * chargeSpeed; } } else { - npc.noTileCollide = true; - npc.ai[0]++; - if (npc.ai[0] % 300f >= 180f) + if (Math.Abs(Target.Center.X - npc.Center.X) > 320f) + npc.velocity.X = MathHelper.Lerp(npc.velocity.X, (Target.Center.X - npc.Center.X > 0).ToDirectionInt() * 10f, 0.05f); + if (Math.Abs(Target.Center.Y - npc.Center.Y) > 50f) + npc.velocity.Y = npc.DirectionTo(Target.Center).Y * 9f; + } + } + + public void DoSwimMovement() + { + Time++; + if (DiveTimer > 0f) + DiveTimer -= 1f; + if (npc.wet) + { + // Swim around, moving towards the player. + bool canSwimToPlayer = Collision.CanHit(npc.position, npc.width, npc.height, Target.position, Target.width, Target.height); + if (canSwimToPlayer) { - if (npc.ai[0] % 300f == 205f) + if (Time % 55f == 54f) { - npc.velocity.Y = -6.5f; - } - if (npc.ai[0] % 300f == 235f) - { - float chargeSpeed = 8f; + float horizontalSchoolingSpeed = 9f; if (CalamityWorld.downedAquaticScourge) - { - chargeSpeed = 14f; - } + horizontalSchoolingSpeed = 15f; if (CalamityWorld.downedPolterghast) - { - chargeSpeed = 18f; - } - npc.velocity = npc.DirectionTo(player.Center) * chargeSpeed; + horizontalSchoolingSpeed = 24f; + npc.velocity = Vector2.UnitX * (Target.Center.X - npc.Center.X > 0).ToDirectionInt() * horizontalSchoolingSpeed; + } + if ((Math.Abs(Target.Center.Y - npc.Center.Y) > 50f && Target.wet) || (!Target.wet && DiveTimer <= 0f)) + { + float verticalSwimSpeed = CalamityWorld.downedPolterghast ? 10f : 6f; + npc.velocity.Y = (Target.Center.Y - npc.Center.Y > 0).ToDirectionInt() * verticalSwimSpeed; + } + + // Speed up if there is little horizontal movement. + if (Math.Abs(npc.velocity.X) < 6f) + npc.velocity.X *= 1.04f; + } + + // Slow down increasingly vertically if it's already low. + else if (!canSwimToPlayer && Math.Abs(npc.velocity.Y) < 4f) + npc.velocity.Y *= 0.97f; + + // Turn around if we hit a tile on the X axis + if (!canSwimToPlayer && npc.collideX) + npc.velocity.X *= -1f; + + // Check if a dive is possible. + if (Target.Center.Y < npc.Top.Y - 10f && DiveTimer <= 0f) + { + if (Main.netMode != NetmodeID.MultiplayerClient && Main.rand.NextBool(10)) + { + DiveTimer = TotalDiveTime; + npc.netUpdate = true; + } + + HorizontalDiveSpeed = (Target.Center.X - npc.Center.X > 0).ToDirectionInt() * 10f; + } + } + else + { + // Dive upward in an attempt to hit to the player. + if (DiveTimer > TotalDiveTime - DiveTime) + { + npc.velocity.X = HorizontalDiveSpeed; + if (DiveTimer > TotalDiveTime - DiveTime * 0.5f) + { + float upwardDiveSpeed = CalamityWorld.downedAquaticScourge ? 0.115f : 0.085f; + if (CalamityWorld.downedPolterghast) + upwardDiveSpeed = 0.135f; + npc.velocity.Y -= upwardDiveSpeed; + } + else + { + DiveTimer = TotalDiveTime - DiveTime; + npc.velocity.Y += 0.2f; } } else { - if (Math.Abs(player.Center.X - npc.Center.X) > 320f) + // Don't fall too fast because of wings + DiveTimer = TotalDiveTime - DiveTime; + npc.velocity.Y += 0.1f; + WaitBeforeFlyingMovement++; + + // Consistently sync the enemy. + if (WaitBeforeFlyingMovement % 40f == 39f) + npc.netUpdate = true; + + if (WaitBeforeFlyingMovement > 180f) { - npc.velocity.X = MathHelper.Lerp(npc.velocity.X, (player.Center.X - npc.Center.X > 0).ToDirectionInt() * 10f, 0.05f); - } - if (Math.Abs(player.Center.Y - npc.Center.Y) > 50f) - { - npc.velocity.Y = npc.DirectionTo(player.Center).Y * 9f; + Time = DiveTimer = HorizontalDiveSpeed = WaitBeforeFlyingMovement = 0f; + Flying = true; + npc.netUpdate = true; } } } - int idealDirection = (npc.velocity.X > 0).ToDirectionInt(); - npc.direction = npc.spriteDirection = idealDirection; - if (idealDirection != npc.direction) + // If sitting on land, rotate in a way that looks like we're stuck on the ground + if (!npc.wet) { - npc.netUpdate = true; + npc.velocity.X *= 0.92f; } - npc.rotation = npc.velocity.ToRotation() + - (npc.direction > 0).ToInt() * MathHelper.Pi; } public override void FindFrame(int frameHeight) @@ -227,9 +220,7 @@ namespace CalamityMod.NPCs.AcidRain npc.frameCounter = 0; npc.frame.Y += frameHeight; if (npc.frame.Y >= Main.npcFrameCount[npc.type] * frameHeight) - { npc.frame.Y = 0; - } } } @@ -242,24 +233,17 @@ namespace CalamityMod.NPCs.AcidRain public override void HitEffect(int hitDirection, double damage) { for (int k = 0; k < 8; k++) - { Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.SulfurousSeaAcid, hitDirection, -1f, 0, default, 1f); - } if (npc.life <= 0) { Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/AcidRain/SkyfinGore"), npc.scale); Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/AcidRain/SkyfinGore2"), npc.scale); Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/AcidRain/SkyfinGore3"), npc.scale); for (int k = 0; k < 20; k++) - { Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.SulfurousSeaAcid, hitDirection, -1f, 0, default, 1f); - } } } - public override void OnHitPlayer(Player target, int damage, bool crit) - { - target.AddBuff(ModContent.BuffType(), 180); - } + public override void OnHitPlayer(Player target, int damage, bool crit) => target.AddBuff(ModContent.BuffType(), 180); } } diff --git a/NPCs/AcidRain/SulfurousSkater.cs b/NPCs/AcidRain/SulfurousSkater.cs index 2847e6cea1..930d5fdc27 100644 --- a/NPCs/AcidRain/SulfurousSkater.cs +++ b/NPCs/AcidRain/SulfurousSkater.cs @@ -18,6 +18,8 @@ namespace CalamityMod.NPCs.AcidRain public class SulfurousSkater : ModNPC { public bool Flying = false; + public Player Target => Main.player[npc.target]; + public ref float JumpTimer => ref npc.ai[0]; public override void SetStaticDefaults() { @@ -27,15 +29,9 @@ namespace CalamityMod.NPCs.AcidRain NPCID.Sets.TrailCacheLength[npc.type] = 6; } - public override void SendExtraAI(BinaryWriter writer) - { - writer.Write(Flying); - } + public override void SendExtraAI(BinaryWriter writer) => writer.Write(Flying); - public override void ReceiveExtraAI(BinaryReader reader) - { - Flying = reader.ReadBoolean(); - } + public override void ReceiveExtraAI(BinaryReader reader) => Flying = reader.ReadBoolean(); public override void SetDefaults() { @@ -49,7 +45,7 @@ namespace CalamityMod.NPCs.AcidRain if (CalamityWorld.downedPolterghast) { npc.damage = 85; - npc.lifeMax = 7000; + npc.lifeMax = 3850; npc.defense = 15; } @@ -69,102 +65,119 @@ namespace CalamityMod.NPCs.AcidRain public override void AI() { npc.TargetClosest(false); - Player player = Main.player[npc.target]; if (!Flying) + JumpToDestination(); + else + DoFlyMovement(); + } + + public void JumpToDestination() + { + npc.knockBackResist = 0.8f; + npc.DR_NERD(0.35f); + npc.noGravity = false; + Projectile closestBubble = SearchForNearestBubble(out float distanceToBubbele); + + Vector2 destination = Target.Center; + + // Jump towards any nearby bubbles if they exist. + if (closestBubble != null) + destination = closestBubble.Center; + + // Stay on water instead of falling into it + if (npc.wet && npc.velocity.Y >= 0f) + npc.velocity.Y = -3f; + + // If close to the bubble, try to fall onto it. + if (closestBubble != null && distanceToBubbele < 200f) { - npc.knockBackResist = 0.8f; - npc.DR_NERD(0.35f); - npc.noGravity = false; - float minimumDistance = float.PositiveInfinity; - Projectile closestBubble = null; - for (int i = 0; i < Main.npc.Length; i++) - { - if (Main.projectile[i].type == ModContent.ProjectileType() && Main.projectile[i].active) - { - if (Math.Abs(npc.Center.X - Main.projectile[i].Center.X) < minimumDistance && - Collision.CanHit(npc.position, npc.width, npc.height, Main.projectile[i].position, Main.projectile[i].width, Main.projectile[i].height) && - Main.projectile[i].Center.Y > npc.Bottom.Y) - { - minimumDistance = npc.Distance(Main.projectile[i].Center); - closestBubble = Main.projectile[i]; - } - } - } - if (minimumDistance >= 2400f) - { - closestBubble = null; - } + npc.velocity.Y += 0.2f; - Vector2 destination = player.Center; - - if (closestBubble != null) + if (closestBubble.Hitbox.Intersects(npc.Hitbox)) { - destination = closestBubble.Center; - } - // Stay on water instead of falling into it - if (npc.wet) - { - if (npc.velocity.Y >= 0f) - { - npc.velocity.Y = -3f; - } - } - - if (closestBubble != null && minimumDistance < 200f) - { - npc.velocity.Y += 0.2f; - - if (closestBubble.Hitbox.Intersects(npc.Hitbox)) - { - Flying = true; - closestBubble.Kill(); - npc.netSpam = 0; - npc.netUpdate = true; - } - } - if (npc.velocity.Y == 0f || npc.wet) - { - npc.TargetClosest(false); - npc.velocity.X *= 0.85f; - npc.ai[1]++; - float lungeForwardSpeed = 15f; - float jumpSpeed = 4f; - if (Collision.CanHit(npc.Center, 1, 1, Main.player[npc.target].Center, 1, 1)) - { - lungeForwardSpeed *= 1.2f; - } - if (npc.ai[1] >= 17) - { - npc.ai[1] = 0f; - npc.velocity.Y -= jumpSpeed; - npc.velocity.X = lungeForwardSpeed * (npc.Center.X - destination.X < 0).ToDirectionInt(); - npc.spriteDirection = (npc.Center.X - destination.X > 0).ToDirectionInt(); - npc.netSpam = 0; - npc.netUpdate = true; - } - } - else - { - npc.knockBackResist = 0f; + Flying = true; + npc.netSpam = 0; + npc.netUpdate = true; + closestBubble.Kill(); } } - else + + // Wait for a small amount of time and jump if there is little motion. + if (npc.velocity.Y == 0f || npc.wet) { - npc.knockBackResist = 0.5f; - npc.DR_NERD(0f); - float speed = CalamityWorld.downedPolterghast ? 17f : 14f; - float inertia = CalamityWorld.downedPolterghast ? 20f : 24.5f; - if (npc.Distance(player.Center) < 200f) - inertia *= 0.667f; - npc.velocity = (npc.velocity * inertia + npc.DirectionTo(player.Center) * speed) / (inertia + 1f); - npc.spriteDirection = (npc.velocity.X < 0).ToDirectionInt(); - if (npc.Distance(player.Center) < player.Size.Length()) + npc.TargetClosest(false); + + // Rapidly zero out horizontal movement. + npc.velocity.X *= 0.85f; + + JumpTimer++; + float lungeForwardSpeed = 15f; + float jumpSpeed = 4f; + if (Collision.CanHit(npc.Center, 1, 1, Target.Center, 1, 1)) + lungeForwardSpeed *= 1.2f; + + // Jump after a short amount of time. + if (JumpTimer >= 17) { - Flying = false; + JumpTimer = 0f; + npc.velocity.Y -= jumpSpeed; + npc.velocity.X = lungeForwardSpeed * (npc.Center.X - destination.X < 0).ToDirectionInt(); + npc.spriteDirection = (npc.Center.X - destination.X > 0).ToDirectionInt(); npc.netSpam = 0; npc.netUpdate = true; } } + else + npc.knockBackResist = 0f; + } + + public void DoFlyMovement() + { + npc.knockBackResist = 0.5f; + npc.DR_NERD(0f); + + float flySpeed = CalamityWorld.downedPolterghast ? 17f : 14f; + float flyInertia = CalamityWorld.downedPolterghast ? 20f : 24.5f; + + // Fly more sharply if close to the target. + if (npc.WithinRange(Target.Center, 200f)) + flyInertia *= 0.667f; + npc.velocity = (npc.velocity * flyInertia + npc.DirectionTo(Target.Center) * flySpeed) / (flyInertia + 1f); + npc.spriteDirection = (npc.velocity.X < 0).ToDirectionInt(); + + // Have the bubble pop and stop flying if within the circular hitbox area of the player. + if (npc.WithinRange(Target.Center, Target.Size.Length())) + { + Flying = false; + npc.netSpam = 0; + npc.netUpdate = true; + } + } + + public Projectile SearchForNearestBubble(out float distanceToBubble) + { + int bubbleType = ModContent.ProjectileType(); + float minimumDistance = 2400f; + Projectile closestBubble = null; + + for (int i = 0; i < Main.maxProjectiles; i++) + { + if (Main.projectile[i].type != bubbleType || !Main.projectile[i].active) + continue; + + if (Math.Abs(npc.Center.X - Main.projectile[i].Center.X) >= minimumDistance || + Main.projectile[i].Center.Y <= npc.Bottom.Y || + !Collision.CanHit(npc.position, npc.width, npc.height, Main.projectile[i].position, Main.projectile[i].width, Main.projectile[i].height)) + { + continue; + } + + minimumDistance = npc.Distance(Main.projectile[i].Center); + closestBubble = Main.projectile[i]; + } + + distanceToBubble = minimumDistance; + return closestBubble; } public override void FindFrame(int frameHeight) @@ -179,9 +192,7 @@ namespace CalamityMod.NPCs.AcidRain npc.frameCounter = 0; npc.frame.Y += frameHeight; if (npc.frame.Y >= Main.npcFrameCount[npc.type] * frameHeight) - { npc.frame.Y = frameHeight; - } } } } @@ -212,9 +223,6 @@ namespace CalamityMod.NPCs.AcidRain DropHelper.DropItemChance(npc, ModContent.ItemType(), 20); } - public override void OnHitPlayer(Player target, int damage, bool crit) - { - target.AddBuff(ModContent.BuffType(), 120); - } + public override void OnHitPlayer(Player target, int damage, bool crit) => target.AddBuff(ModContent.BuffType(), 120); } } diff --git a/NPCs/AcidRain/Trilobite.cs b/NPCs/AcidRain/Trilobite.cs index ee1f397bdb..86cc206618 100644 --- a/NPCs/AcidRain/Trilobite.cs +++ b/NPCs/AcidRain/Trilobite.cs @@ -14,9 +14,9 @@ namespace CalamityMod.NPCs.AcidRain { public class Trilobite : ModNPC { - // When the abs(velocity) is less than this, lunge in the water + public Player Target => Main.player[npc.target]; + public ref float SpikeShootCountdown => ref npc.ai[0]; public const float MinSpeedLungePrompt = 0.5f; - public const float MinYDriftSpeed = 0.9f; public override void SetStaticDefaults() { @@ -40,7 +40,7 @@ namespace CalamityMod.NPCs.AcidRain if (CalamityWorld.downedPolterghast) { npc.damage = 80; - npc.lifeMax = 7500; + npc.lifeMax = 4125; npc.defense = 30; } @@ -60,68 +60,71 @@ namespace CalamityMod.NPCs.AcidRain npc.TargetClosest(false); if (!npc.wet) { - if (npc.ai[0] > 0) - npc.ai[0]--; - npc.rotation += npc.velocity.X * 0.1f; - if (npc.velocity.Y == 0f) + GetStuckOnLand(); + return; + } + + // If this NPC doesn't have enough momentum, lunge towards its target. + if (npc.velocity.Length() < MinSpeedLungePrompt) + { + npc.TargetClosest(); + float lungeSpeed = CalamityWorld.downedPolterghast ? 18.5f : 15f; + + npc.velocity = npc.DirectionTo(Target.Center) * lungeSpeed; + npc.velocity.X *= 1.6f; + npc.rotation = npc.velocity.ToRotation() + MathHelper.PiOver2; + npc.netUpdate = true; + return; + } + + // Accelerate quickly through the water horizontally. + if (Math.Abs(npc.velocity.X) < 20f) + npc.velocity.X += npc.direction * 0.02f; + + npc.rotation = npc.velocity.X * 0.4f; + + // Slow down in terms of horizontal speed if there is little vertical speed. + if (Math.Abs(npc.velocity.Y) < 0.9f) + npc.velocity.X *= 0.96f; + + // Lunge towards the target if there is little horizontal speed but also a little bit of vertical speed. + else if (Main.netMode != NetmodeID.MultiplayerClient && Math.Abs(npc.velocity.X) < 3.5f) + { + float speedX = 18f; + float speedY = 9f; + if (CalamityWorld.downedPolterghast) { - npc.velocity.X *= 0.99f; - if (Math.Abs(npc.velocity.X) < 0.01f) - { - npc.velocity.X = 0f; - } - npc.netUpdate = true; - } - npc.velocity.Y += 0.3f; - if (npc.velocity.Y > 13f) - { - npc.velocity.Y = 13f; - npc.netUpdate = true; + speedX = 22f; + speedY = 11f; } + npc.velocity = npc.DirectionTo(Target.Center) * new Vector2(speedX, speedY); + npc.netUpdate = true; + } + npc.velocity.Y *= 0.98f; + } + + public void GetStuckOnLand() + { + if (SpikeShootCountdown > 0) + SpikeShootCountdown--; + npc.rotation += npc.velocity.X * 0.1f; + + // If not moving vertically, slow down hotizontally. + if (npc.velocity.Y == 0f) + { + npc.velocity.X *= 0.99f; + if (Math.Abs(npc.velocity.X) < 0.01f) + npc.velocity.X = 0f; + } + + // Fall and cap the vertical speed. + if (npc.velocity.Y > 13f) + { + npc.velocity.Y = 13f; + npc.netUpdate = true; } else - { - Player player = Main.player[npc.target]; - if (npc.velocity.Length() < MinSpeedLungePrompt) - { - npc.TargetClosest(true); - float speed = 15f; - if (CalamityWorld.downedPolterghast) - { - speed = 18.5f; - } - - npc.velocity = npc.DirectionTo(player.Center) * speed; - npc.velocity.X *= 1.6f; - npc.rotation = npc.velocity.ToRotation() + MathHelper.PiOver2; - npc.netUpdate = true; - } - else - { - if (Math.Abs(npc.velocity.X) < 20f) - { - npc.velocity.X += npc.direction * 0.02f; - } - npc.rotation = npc.velocity.X * 0.4f; - if (Math.Abs(npc.velocity.Y) < MinYDriftSpeed) - { - npc.velocity.X *= 0.96f; - } - else if (Math.Abs(npc.velocity.X) < 3.5f) - { - float speedX = 18f; - float speedY = 9f; - if (CalamityWorld.downedPolterghast) - { - speedX = 22f; - speedY = 11f; - } - npc.velocity = npc.DirectionTo(player.Center) * new Vector2(speedX, speedY); - npc.netUpdate = true; - } - npc.velocity.Y *= 0.98f; - } - } + npc.velocity.Y += 0.3f; } public override void NPCLoot() @@ -132,28 +135,23 @@ namespace CalamityMod.NPCs.AcidRain public override void PostDraw(SpriteBatch spriteBatch, Color drawColor) { if (npc.velocity.Length() > 0.5f) - { CalamityGlobalNPC.DrawAfterimage(npc, spriteBatch, drawColor, Color.Transparent, directioning: true); - } } public override void ModifyHitByProjectile(Projectile projectile, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) { - if (Main.netMode != NetmodeID.MultiplayerClient) + // No need for a netmode check- this code is only called by 1 client, the owner of the projectile that hit the NPC. + if (SpikeShootCountdown <= 0f) { - if (npc.ai[0] <= 0f) - { - Main.PlaySound(SoundID.NPCDeath11, npc.Center); - int projDamage = CalamityWorld.downedPolterghast ? 35 : CalamityWorld.downedAquaticScourge ? 29 : 21; - if (Main.expertMode) - projDamage = (int)Math.Round(projDamage * 0.8); + Main.PlaySound(SoundID.NPCDeath11, npc.Center); + int projDamage = CalamityWorld.downedPolterghast ? 35 : CalamityWorld.downedAquaticScourge ? 29 : 21; + if (Main.expertMode) + projDamage = (int)Math.Round(projDamage * 0.8); - Projectile.NewProjectile(npc.Center + Utils.NextVector2Unit(Main.rand) * npc.Size * 0.7f, - -npc.velocity.RotatedByRandom(MathHelper.ToRadians(10f)), ModContent.ProjectileType(), - projDamage, 3f); - npc.ai[0] = Main.rand.Next(50, 65); - npc.netUpdate = true; - } + Vector2 spikeVelocity = -npc.velocity.RotatedByRandom(0.18f); + Projectile.NewProjectile(npc.Center + Main.rand.NextVector2Unit() * npc.Size * 0.7f, spikeVelocity, ModContent.ProjectileType(), projDamage, 3f); + SpikeShootCountdown = Main.rand.Next(50, 65); + npc.netUpdate = true; } } @@ -165,9 +163,7 @@ namespace CalamityMod.NPCs.AcidRain npc.frameCounter = 0; npc.frame.Y += frameHeight; if (npc.frame.Y >= Main.npcFrameCount[npc.type] * frameHeight) - { npc.frame.Y = 0; - } } } diff --git a/NPCs/AcidRain/WaterLeech.cs b/NPCs/AcidRain/WaterLeech.cs index 55e1ac8611..c6f5ae2a28 100644 --- a/NPCs/AcidRain/WaterLeech.cs +++ b/NPCs/AcidRain/WaterLeech.cs @@ -6,7 +6,6 @@ using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; -using CalamityMod.Buffs.StatDebuffs; using System.IO; using CalamityMod.Buffs.DamageOverTime; @@ -14,6 +13,13 @@ namespace CalamityMod.NPCs.AcidRain { public class WaterLeech : ModNPC { + public Player Target => Main.player[npc.target]; + public bool LatchingOntoTarget + { + get => npc.ai[0] == 1f; + set => npc.ai[0] = value.ToInt(); + } + public ref float LackOfWaterDeathTimer => ref npc.ai[2]; public const float ChasePromptDistance = 55f; public const float ChaseMaxDistance = 140f; @@ -33,13 +39,11 @@ namespace CalamityMod.NPCs.AcidRain if (CalamityWorld.downedPolterghast) { - npc.lifeMax = 2250; + npc.lifeMax = 1235; npc.defense = 10; } else if (CalamityWorld.downedAquaticScourge) - { npc.lifeMax = 90; - } npc.value = Item.buyPrice(0, 0, 2, 5); npc.lavaImmune = false; @@ -51,86 +55,53 @@ namespace CalamityMod.NPCs.AcidRain bannerItem = ModContent.ItemType(); } - public override void SendExtraAI(BinaryWriter writer) - { - writer.Write(npc.dontTakeDamage); - } + public override void SendExtraAI(BinaryWriter writer) => writer.Write(npc.dontTakeDamage); - public override void ReceiveExtraAI(BinaryReader reader) - { - npc.dontTakeDamage = reader.ReadBoolean(); - } + public override void ReceiveExtraAI(BinaryReader reader) => npc.dontTakeDamage = reader.ReadBoolean(); public override void AI() { if (npc.localAI[0] == 0f) { - npc.TargetClosest(false); + npc.TargetClosest(); npc.localAI[0] = 1f; } - // Anti-sticky movement and player targeting detection (only one leech and attack the player at once) - Player player = Main.player[npc.target]; bool playerAlreadyTargeted = false; float antiStickyAcceleration = 0.25f; - for (int i = 0; i < Main.npc.Length; i++) + + // Repel other leeches from this one. Also determine if one is already targeting a player. + // Only one leech is allowed to target one player at a time. + for (int i = 0; i < Main.maxNPCs; i++) { - if (Main.npc[i].type == npc.type && - Main.npc[i].whoAmI != npc.whoAmI && - Main.npc[i].active) - { - if (Main.npc[i].target == npc.target && !playerAlreadyTargeted) - { - playerAlreadyTargeted = true; - } - if (Main.npc[i].Hitbox.Intersects(npc.Hitbox)) - { - npc.velocity += npc.DirectionFrom(Main.npc[i].Center) * antiStickyAcceleration; - } - } + if (Main.npc[i].type != npc.type || !Main.npc[i].active || Main.npc[i].whoAmI == npc.whoAmI) + continue; + + if (Main.npc[i].target == npc.target && !playerAlreadyTargeted) + playerAlreadyTargeted = true; + if (Main.npc[i].Hitbox.Intersects(npc.Hitbox)) + npc.velocity += npc.DirectionFrom(Main.npc[i].Center) * antiStickyAcceleration; } - if (!playerAlreadyTargeted || player.Calamity().waterLeechTarget == -1) - { - player.Calamity().waterLeechTarget = npc.whoAmI; - } + if (!playerAlreadyTargeted || Target.Calamity().waterLeechTarget == -1) + Target.Calamity().waterLeechTarget = npc.whoAmI; - // Latch onto player - if (npc.ai[0] == 1f) + if (LatchingOntoTarget) { - if (npc.dontTakeDamage) - { - npc.dontTakeDamage = false; - npc.netUpdate = true; - } - if (npc.Distance(player.Top) >= 140f) - { - npc.ai[0] = 0f; - npc.netUpdate = true; - return; - } - Vector2 destination = ((player.gravDir == 1f) ? player.Top : player.Bottom) + player.direction * 4 * Vector2.UnitX; - float speed = Utils.SmoothStep(10f, ChaseMaxDistance, npc.Distance(destination)) * 16f; - npc.velocity = npc.DirectionTo(destination) * (speed + 7f); - if (npc.Distance(destination) < 45f) - { - player.AddBuff(BuffID.Bleeding, 180, true); - player.AddBuff(ModContent.BuffType(), 30, true); - } - else if (!npc.wet && npc.Distance(destination) > 85f) - { - npc.ai[0] = 0f; - npc.netUpdate = true; - } + LatchOntoTarget(); return; } + npc.direction = npc.spriteDirection = (npc.velocity.X > 0).ToDirectionInt(); + + // If the leech is not in water, fall and quickly cease horizontal movement. + // After some time, if still not in water, die due to a lack of water. if (!npc.wet) { npc.velocity.X *= 0.97f; - npc.velocity.Y += 0.5f; - npc.ai[2] += 1f; - if (npc.ai[2] >= 300f) + npc.velocity.Y = MathHelper.Clamp(npc.velocity.Y + 0.4f, -4f, 16f); + LackOfWaterDeathTimer++; + if (LackOfWaterDeathTimer >= 300f) { npc.life = 0; npc.HitEffect(); @@ -138,28 +109,69 @@ namespace CalamityMod.NPCs.AcidRain npc.netUpdate = true; } } - else if (player.wet && player.Calamity().waterLeechTarget == npc.whoAmI) + + // Swim towards the target if they are in water. + else if (Target.wet && Target.Calamity().waterLeechTarget == npc.whoAmI) { - float speed = player.wet ? 23f : 17f; + float swimSpeed = Target.wet ? 23f : 17f; float swimIntertia = 24f; if (CalamityWorld.downedPolterghast) { - speed *= 1.6f; + swimSpeed *= 1.6f; swimIntertia = 17f; } - npc.velocity = (npc.velocity * (swimIntertia - 1f) + npc.DirectionTo(player.Center) * speed) / swimIntertia; - } - else if (!player.wet) - { - npc.velocity *= 0.9f; + npc.velocity = (npc.velocity * (swimIntertia - 1f) + npc.DirectionTo(Target.Center) * swimSpeed) / swimIntertia; } - if (npc.Distance(player.Top) < ChasePromptDistance && player.active && !player.dead) + // Rapidly slow down if the target is not in water. + else if (!Target.wet) + npc.velocity *= 0.9f; + + if (npc.WithinRange(Target.Top, ChasePromptDistance) && Target.active && !Target.dead) { - npc.ai[0] = 1f; + LatchingOntoTarget = true; + npc.netUpdate = true; + } + + // If the target is not in water, become invincible. + bool shouldNotTakeDamage = !Target.wet; + if (Main.netMode != NetmodeID.MultiplayerClient && npc.dontTakeDamage != shouldNotTakeDamage) + { + npc.dontTakeDamage = shouldNotTakeDamage; + npc.netUpdate = true; + } + } + + public void LatchOntoTarget() + { + if (Main.netMode != NetmodeID.MultiplayerClient && npc.dontTakeDamage) + { + npc.dontTakeDamage = false; + npc.netUpdate = true; + } + + // If the target moved far enough away, stop attempting to attach to them. + if (!npc.WithinRange(Target.Center, ChaseMaxDistance)) + { + LatchingOntoTarget = false; + npc.netUpdate = true; + return; + } + Vector2 destination = (Target.gravDir == 1f ? Target.Top : Target.Bottom) + Target.direction * Vector2.UnitX * 4f; + float speed = MathHelper.Lerp(7f, 23f, Utils.InverseLerp(10f, ChaseMaxDistance, npc.Distance(destination), true)); + npc.velocity = npc.DirectionTo(destination) * speed; + if (npc.WithinRange(destination, 45f)) + { + Target.AddBuff(BuffID.Bleeding, 180, true); + Target.AddBuff(ModContent.BuffType(), 30, true); + } + + // Stop searching if the target is not in water anymore and they're not close. + else if (!npc.wet && !npc.WithinRange(destination, 85f)) + { + LatchingOntoTarget = false; npc.netUpdate = true; } - npc.dontTakeDamage = !player.wet; } public override void FindFrame(int frameHeight) @@ -170,27 +182,22 @@ namespace CalamityMod.NPCs.AcidRain npc.frameCounter = 0; npc.frame.Y += frameHeight; if (npc.frame.Y >= Main.npcFrameCount[npc.type] * frameHeight) - { npc.frame.Y = 0; - } } } public override float SpawnChance(NPCSpawnInfo spawnInfo) { if (spawnInfo.playerSafe || !spawnInfo.player.Calamity().ZoneSulphur || !Main.raining) - { return 0f; - } + return 0.115f; } public override void HitEffect(int hitDirection, double damage) { for (int k = 0; k < 8; k++) - { Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.SulfurousSeaAcid, hitDirection, -1f, 0, default, 1f); - } } public override void NPCLoot()