From 3419cb4292ca91d514ae47121b38c30a5e12e4bd Mon Sep 17 00:00:00 2001 From: DominicKarma42 <51094361+DominicKarma@users.noreply.github.com> Date: Wed, 25 Mar 2020 16:06:07 -0500 Subject: [PATCH] skyfins be flying --- NPCs/AcidRain/Skyfin.cs | 180 ++++++++++++++++++++++++++-------------- 1 file changed, 118 insertions(+), 62 deletions(-) diff --git a/NPCs/AcidRain/Skyfin.cs b/NPCs/AcidRain/Skyfin.cs index 87fa304f56..0253db23cb 100644 --- a/NPCs/AcidRain/Skyfin.cs +++ b/NPCs/AcidRain/Skyfin.cs @@ -5,6 +5,7 @@ using CalamityMod.Items.Weapons.Rogue; using CalamityMod.World; using Microsoft.Xna.Framework; using System; +using System.IO; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -16,6 +17,7 @@ namespace CalamityMod.NPCs.AcidRain public const float DiveDelay = 120f; public const float DiveTime = 90f; public const float TotalTime = DiveDelay + DiveTime; + public bool Flying = false; public override void SetStaticDefaults() { DisplayName.SetDefault("Skyfin"); @@ -57,78 +59,137 @@ namespace CalamityMod.NPCs.AcidRain banner = npc.type; bannerItem = ModContent.ItemType(); } + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(Flying); + } + public override void ReceiveExtraAI(BinaryReader reader) + { + Flying = reader.ReadBoolean(); + } public override void AI() { npc.TargetClosest(false); Player player = Main.player[npc.target]; - npc.ai[0] += 1f; - if (npc.ai[1] > 0f) - npc.ai[1] -= 1f; - if (npc.wet) + if (!Flying) { - // Swim around, moving towards the player - bool canSwimToPlayer = Collision.CanHit(npc.position, npc.width, npc.height, player.position, player.width, player.height); - if (canSwimToPlayer) + npc.ai[0] += 1f; + if (npc.ai[1] > 0f) + npc.ai[1] -= 1f; + if (npc.wet) { - if (npc.ai[0] % 55f == 54f) + // Swim around, moving towards the player + bool canSwimToPlayer = Collision.CanHit(npc.position, npc.width, npc.height, player.position, player.width, player.height); + if (canSwimToPlayer) { - npc.velocity = Vector2.UnitX * (player.Center.X - npc.Center.X > 0).ToDirectionInt() * 27f; - } - if ((Math.Abs(player.Center.Y - npc.Center.Y) > 50f && player.wet) || (!player.wet && npc.ai[1] <= 0f)) - { - float speedY = CalamityWorld.downedPolterghast ? 15f : 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 - { - // 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.135f : 0.085f; - if (CalamityWorld.downedPolterghast) + if (npc.ai[0] % 55f == 54f) { - flySpeed = 0.185f; + npc.velocity = Vector2.UnitX * (player.Center.X - npc.Center.X > 0).ToDirectionInt() * 27f; } - npc.velocity.Y -= flySpeed; + if ((Math.Abs(player.Center.Y - npc.Center.Y) > 50f && player.wet) || (!player.wet && npc.ai[1] <= 0f)) + { + float speedY = CalamityWorld.downedPolterghast ? 15f : 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 + else if (!canSwimToPlayer && Math.Abs(npc.velocity.Y) < 4f) { - npc.ai[1] = TotalTime - DiveTime; - npc.velocity.Y += 0.2f; + 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 { - // Don't fall too fast because of wings - npc.ai[1] = TotalTime - DiveTime; - npc.velocity.Y += 0.1f; + // 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.135f : 0.085f; + if (CalamityWorld.downedPolterghast) + { + flySpeed = 0.185f; + } + 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; + } + } + else + { + npc.noTileCollide = true; + npc.ai[0]++; + if (npc.ai[0] % 300f >= 180f) + { + if (npc.ai[0] % 300f == 205f) + { + npc.velocity.Y = -6.5f; + } + if (npc.ai[0] % 300f == 235f) + { + float chargeSpeed = 11f; + if (CalamityWorld.downedAquaticScourge) + { + chargeSpeed = 17f; + } + if (CalamityWorld.downedPolterghast) + { + chargeSpeed = 24f; + } + npc.velocity = npc.DirectionTo(player.Center) * chargeSpeed; + } + } + else + { + if (Math.Abs(player.Center.X - npc.Center.X) > 320f) + { + 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; + } } } int idealDirection = (npc.velocity.X > 0).ToDirectionInt(); @@ -137,11 +198,6 @@ namespace CalamityMod.NPCs.AcidRain { 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; - } npc.rotation = npc.velocity.ToRotation() + (npc.direction > 0).ToInt() * MathHelper.Pi; }