diff --git a/NPCs/Leviathan/Siren.cs b/NPCs/Leviathan/Siren.cs index 59e5c088a1..46b6f581b5 100644 --- a/NPCs/Leviathan/Siren.cs +++ b/NPCs/Leviathan/Siren.cs @@ -20,6 +20,17 @@ namespace CalamityMod.NPCs.Leviathan private bool spawnedLevi = false; private bool forceChargeFrames = false; private int frameUsed = 0; + public bool HasBegunSummoningLeviathan = false; + public bool WaitingForLeviathan + { + get + { + if (Main.npc.IndexInRange(CalamityGlobalNPC.leviathan) && Main.npc[CalamityGlobalNPC.leviathan].life / (float)Main.npc[CalamityGlobalNPC.leviathan].lifeMax >= 0.4f) + return true; + + return CalamityUtils.FindFirstProjectile(ModContent.ProjectileType()) != -1; + } + } //IMPORTANT: Do NOT remove the empty space on the sprites. This is intentional for framing. The sprite is centered and hitbox is fine already. @@ -149,20 +160,52 @@ namespace CalamityMod.NPCs.Leviathan // Spawn Leviathan and change music if (npc.life / (float)npc.lifeMax < 0.4f) { - if (!spawnedLevi) + if (!HasBegunSummoningLeviathan) { - music = CalamityMod.Instance.GetMusicFromMusicMod("LeviathanAndSiren") ?? MusicID.Boss3; + // Use charging frames. + npc.ai[0] = 3f; - if (Main.netMode != NetmodeID.MultiplayerClient) + // Look towards the ocean. + npc.direction = (npc.Center.X < Main.maxTilesX * 8f).ToDirectionInt(); + + if (npc.alpha <= 0) { - int levi = NPC.NewNPC((int)vector.X, (int)vector.Y, ModContent.NPCType(), npc.whoAmI); - CalamityUtils.BossAwakenMessage(levi); + float moveDirection = 1f; + if (Math.Abs(npc.Center.X - Main.maxTilesX * 16f) > Math.Abs(npc.Center.X)) + moveDirection = -1f; + npc.velocity.X = moveDirection * 6f; + npc.spriteDirection = (int)-moveDirection; + npc.velocity.Y = MathHelper.Clamp(npc.velocity.Y + 0.2f, -3f, 16f); } - spawnedLevi = true; + float idealRotation = npc.velocity.ToRotation(); + if (npc.spriteDirection == 1) + idealRotation += MathHelper.Pi; + + npc.rotation = npc.rotation.AngleTowards(idealRotation, 0.08f); + + if (BossRushEvent.BossRushActive || Collision.WetCollision(npc.position, npc.width, npc.height) || npc.position.Y > (Main.worldSurface - 125f) * 16f) + { + int oldAlpha = npc.alpha; + npc.alpha = Utils.Clamp(npc.alpha + 9, 0, 255); + if (Main.netMode != NetmodeID.MultiplayerClient && npc.alpha >= 255 && oldAlpha < 255) + { + Projectile.NewProjectile(npc.Center, Vector2.Zero, ModContent.ProjectileType(), 0, 0f); + HasBegunSummoningLeviathan = true; + npc.netUpdate = true; + } + + npc.velocity *= 0.9f; + } + npc.dontTakeDamage = true; + return; } } + // Change music. + if (leviAlive) + music = CalamityMod.Instance.GetMusicFromMusicMod("LeviathanAndSiren") ?? MusicID.Boss3; + // Ice Shield if (npc.localAI[2] < 3f) { @@ -212,46 +255,38 @@ namespace CalamityMod.NPCs.Leviathan npc.dontTakeDamage = true; } - if (npc.life / (float)npc.lifeMax < 0.4f) + // Hover near the target, invisible if the Leviathan is present and not sufficiently injured. + if (npc.life / (float)npc.lifeMax < 0.4f && WaitingForLeviathan) { - if (CalamityGlobalNPC.leviathan != -1) + ChargeRotation(player, vector); + ChargeLocation(player, vector, false, true); + + npc.alpha += 3; + if (npc.alpha >= 255) + npc.alpha = 255; + else { - if (Main.npc[CalamityGlobalNPC.leviathan].active) + for (int k = 0; k < 3; k++) { - if (Main.npc[CalamityGlobalNPC.leviathan].life / (float)Main.npc[CalamityGlobalNPC.leviathan].lifeMax >= 0.4f) - { - ChargeRotation(player, vector); - ChargeLocation(player, vector, false, true); - - npc.alpha += 3; - if (npc.alpha >= 255) - npc.alpha = 255; - else - { - for (int k = 0; k < 3; k++) - { - int dust = Dust.NewDust(npc.position, npc.width, npc.height, 172, 0f, 0f, 100, default, 2f); - Main.dust[dust].noGravity = true; - Main.dust[dust].noLight = true; - } - } - - npc.dontTakeDamage = true; - npc.damage = 0; - - if (npc.ai[0] != -1f) - { - npc.ai[0] = -1f; - npc.ai[1] = 0f; - npc.ai[2] = 0f; - npc.localAI[0] = 0f; - npc.netUpdate = true; - } - - return; - } + int dust = Dust.NewDust(npc.position, npc.width, npc.height, 172, 0f, 0f, 100, default, 2f); + Main.dust[dust].noGravity = true; + Main.dust[dust].noLight = true; } } + + npc.dontTakeDamage = true; + npc.damage = 0; + + if (npc.ai[0] != -1f) + { + npc.ai[0] = -1f; + npc.ai[1] = 0f; + npc.ai[2] = 0f; + npc.localAI[0] = 0f; + npc.netUpdate = true; + } + + return; } // Alpha diff --git a/Projectiles/Boss/LeviathanSpawner.cs b/Projectiles/Boss/LeviathanSpawner.cs new file mode 100644 index 0000000000..68db9f667c --- /dev/null +++ b/Projectiles/Boss/LeviathanSpawner.cs @@ -0,0 +1,94 @@ +using CalamityMod.World; +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.GameContent.Shaders; +using Terraria.Graphics.Effects; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.World.Generation; +using LeviathanNPC = CalamityMod.NPCs.Leviathan.Leviathan; + +namespace CalamityMod.Projectiles.Boss +{ + public class LeviathanSpawner : ModProjectile + { + internal ref float Time => ref projectile.ai[0]; + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public override void SetStaticDefaults() => DisplayName.SetDefault("Spawner"); + + public override void SetDefaults() + { + projectile.width = projectile.height = 20; + projectile.hostile = true; + projectile.tileCollide = false; + projectile.ignoreWater = true; + projectile.netImportant = true; + projectile.timeLeft = 450; + } + + public override void AI() + { + projectile.Opacity = CalamityUtils.Convert01To010(projectile.timeLeft / 120f) * 4f; + if (projectile.Opacity > 1f) + projectile.Opacity = 1f; + + Main.LocalPlayer.Calamity().GeneralScreenShakePower = (float)Math.Pow(Utils.InverseLerp(180f, 290f, Time, true), 0.3D) * 6f; + Main.LocalPlayer.Calamity().GeneralScreenShakePower += CalamityUtils.Convert01To010((float)Math.Pow(Utils.InverseLerp(300f, 440f, Time, true), 0.5D)) * 10f; + + if (projectile.timeLeft == 45) + { + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/LeviathanRoarCharge"), projectile.Center); + if (Main.netMode != NetmodeID.Server) + { + WaterShaderData ripple = (WaterShaderData)Filters.Scene["WaterDistortion"].GetShader(); + Vector2 ripplePos = projectile.Center; + + for (int i = 0; i < 3; i++) + ripple.QueueRipple(ripplePos, Color.White, Vector2.One * 1000f, RippleShape.Square, Main.rand.NextFloat(MathHelper.TwoPi)); + } + + if (Main.netMode == NetmodeID.MultiplayerClient) + return; + + int leviathan = NPC.NewNPC((int)projectile.Center.X, (int)projectile.Center.Y, ModContent.NPCType()); + if (Main.npc.IndexInRange(leviathan)) + Main.npc[leviathan].velocity = Vector2.UnitY * -7f; + } + + CreateVisuals(); + Time++; + } + + public void CreateVisuals() + { + if (Main.netMode == NetmodeID.Server) + return; + + WorldUtils.Find((projectile.Center - Vector2.UnitY * 1200f).ToTileCoordinates(), Searches.Chain(new Searches.Down(150), new CustomConditions.IsWater()), out Point waterTop); + + // Create bubbling water. + if (Time % 4f == 3f && Time > 90f) + { + float xArea = MathHelper.Lerp(400f, 1150f, Time / 300f); + Vector2 dustSpawnPosition = waterTop.ToWorldCoordinates() + Vector2.UnitY * 25f; + dustSpawnPosition.X += Main.rand.NextFloatDirection() * xArea * 0.35f; + Dust bubble = Dust.NewDustPerfect(dustSpawnPosition, 267, Vector2.UnitY * -12f); + bubble.noGravity = true; + bubble.scale = 1.9f; + bubble.color = Color.CornflowerBlue; + + // As well as liquid disruption. + for (float x = -xArea; x <= xArea; x += 110f) + { + float ripplePower = MathHelper.Lerp(4f, 10f, (float)Math.Sin(Main.GlobalTime + x / xArea * MathHelper.TwoPi) * 0.5f + 0.5f); + ripplePower *= MathHelper.Lerp(0.5f, 1f, Time / 300f); + + WaterShaderData ripple = (WaterShaderData)Filters.Scene["WaterDistortion"].GetShader(); + Vector2 ripplePos = waterTop.ToWorldCoordinates() + new Vector2(x, 32f) + Main.rand.NextVector2CircularEdge(50f, 50f); + ripple.QueueRipple(ripplePos, Color.White, Vector2.One * ripplePower, RippleShape.Square, Main.rand.NextFloat(-0.7f, 0.7f) + MathHelper.PiOver2); + } + } + } + } +} diff --git a/World/CustomConditions.cs b/World/CustomConditions.cs index 786fb031a8..27c7f73e60 100644 --- a/World/CustomConditions.cs +++ b/World/CustomConditions.cs @@ -20,6 +20,16 @@ namespace CalamityMod.World return _random.NextFloat(oneInThisValue) <= 1f; } } + + public class IsWater : GenCondition + { + protected override bool CheckValidity(int x, int y) + { + Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); + return tile.liquid >= 200 && !tile.honey() && !tile.lava(); + } + } + public class IsNotTouchingAir : GenCondition { private bool _useDiagonals;