diff --git a/NPCs/SunkenSea/GhostBell.cs b/NPCs/SunkenSea/GhostBell.cs index 66bf6ece38..640c48a995 100644 --- a/NPCs/SunkenSea/GhostBell.cs +++ b/NPCs/SunkenSea/GhostBell.cs @@ -1,16 +1,12 @@ -using System; -using System.Collections.Generic; -using System.IO; +using System.IO; using CalamityMod.BiomeManagers; using CalamityMod.Buffs.DamageOverTime; -using CalamityMod.Enums; using CalamityMod.Items.Accessories; using CalamityMod.Items.Placeables.Banners; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; -using Terraria.DataStructures; using Terraria.GameContent; using Terraria.GameContent.Bestiary; using Terraria.GameContent.ItemDropRules; @@ -20,58 +16,23 @@ using Terraria.ModLoader.Utilities; namespace CalamityMod.NPCs.SunkenSea { - public class GhostBell : SunkenSeaNPC + public class GhostBell : ModNPC { - public enum JellyColor - { - Blue = 0, - Pink = 1, - Green = 2 - } + public bool hasBeenHit = false; - public static Asset PinkTexture; - public static Asset GreenTexture; public static Asset GlowTexture; - public static Asset PinkGlowTexture; - public static Asset GreenGlowTexture; - - public ref float Variant => ref NPC.ai[1]; - - public ref float Role => ref NPC.ai[2]; - - public ref float Aggro => ref NPC.ai[3]; - - protected override List PreyIDs => new List() - { - ModContent.NPCType(), - ModContent.NPCType(), - ModContent.NPCType(), - ModContent.NPCType(), - ModContent.NPCType(), - ModContent.NPCType(), - }; - - protected override List PredatorIDs => new List(); - - protected override SunkenSeaBiomeFlags BiomeDesignation => SunkenSeaBiomeFlags.GleamingBurrows | SunkenSeaBiomeFlags.PolypForest; public override void SetStaticDefaults() { - Main.npcFrameCount[Type] = 1; + Main.npcFrameCount[Type] = 6; if (!Main.dedServ) { - PinkTexture = ModContent.Request(Texture + "Pink"); - GreenTexture = ModContent.Request(Texture + "Green"); - GlowTexture = ModContent.Request(Texture + "Glow"); - PinkGlowTexture = ModContent.Request(Texture + "PinkGlow"); - GreenGlowTexture = ModContent.Request(Texture + "GreenGlow"); + GlowTexture = ModContent.Request(Texture + "Glow", AssetRequestMode.AsyncLoad); } - base.SetStaticDefaults(); } public override void SetDefaults() { - base.SetDefaults(); NPC.noGravity = true; NPC.aiStyle = -1; AIType = -1; @@ -109,80 +70,23 @@ namespace CalamityMod.NPCs.SunkenSea public override void SendExtraAI(BinaryWriter writer) { writer.Write(NPC.chaseable); + writer.Write(hasBeenHit); } public override void ReceiveExtraAI(BinaryReader reader) { NPC.chaseable = reader.ReadBoolean(); - } - - public override void OnSpawn(IEntitySource source) - { - Variant = Main.rand.Next(0, 3); - pathfinding = new PathfindingManager(NPC) - { - Acceleration = 0.1f, - MaxSpeed = 3f, - }; - if (Role == 0) - { - NPC.TargetClosest(); - int jellyAmt; - // Large swarm in polyp forest ft babies, otherwise just a few - if (Main.player[NPC.target].Calamity().ZonePolypForest) - { - jellyAmt = Main.rand.Next(3, 6); - // Spawn a bunch of babies too - for (int i = 0; i < Main.rand.Next(4, 8); i++) - { - if (Main.netMode != NetmodeID.MultiplayerClient) - { - NPC.NewNPC(NPC.GetSource_FromThis(), (int)NPC.Center.X, (int)NPC.Center.Y, ModContent.NPCType()); - } - } - } - else - { - jellyAmt = Main.rand.Next(1, 3); - } - // Spawn more Ghost Bells - // Newly spawned Ghost Bells have their Role set to 1 as to not spawn further Ghost Bells - for (int i = 0; i < jellyAmt; i++) - { - if (Main.netMode != NetmodeID.MultiplayerClient) - { - NPC.NewNPC(NPC.GetSource_FromThis(), (int)NPC.Center.X, (int)NPC.Center.Y, Type, ai2: 1); - } - } - } + hasBeenHit = reader.ReadBoolean(); } public override void AI() { - // Lite - Color lightColor = Color.LightBlue; - switch (Variant) + Lighting.AddLight(NPC.Center, 0f, (255 - NPC.alpha) * 1.5f / 255f, (255 - NPC.alpha) * 1.5f / 255f); + if (NPC.justHit) { - case (int)JellyColor.Pink: - lightColor = Color.Pink; - break; - case (int)JellyColor.Green: - lightColor = Color.LightGreen; - break; - } - Lighting.AddLight(NPC.Center, (lightColor.R - NPC.alpha) * 1f / 255f, (lightColor.G - NPC.alpha) * 1f / 255f, (lightColor.B - NPC.alpha) * 1f / 255f); - NPC.chaseable = Aggro == 1; - // De-aggro - if (Aggro == 1) - { - if (Main.player[NPC.target] != null) - { - if (Main.player[NPC.target].dead) - { - Aggro = 0; - } - } + hasBeenHit = true; } + NPC.chaseable = hasBeenHit; if (NPC.localAI[0] == 0f) { NPC.localAI[0] = 1f; @@ -192,35 +96,25 @@ namespace CalamityMod.NPCs.SunkenSea if (NPC.wet) { NPC.noGravity = true; - bool hasTarget = CurrentPrey != null || (Aggro == 1 && Main.player[NPC.target] != null); - if (hasTarget) + if (NPC.localAI[2] > 0f) { - Entity target = CurrentPrey != null ? CurrentPrey : Main.player[NPC.target]; - pathfinding.DoPathfinding(new PathfindingParameters(NPC.Center, target.Center, SunkenSeaTileValidity)); + NPC.localAI[2] -= 1f; } - else + if (NPC.localAI[2] <= 0f) { - if (NPC.localAI[2] > 0f) + if (NPC.velocity.Y == 0f) { - NPC.localAI[2] -= 1f; + NPC.localAI[1] += 1f; } - if (NPC.localAI[2] <= 0f) + else { - if (NPC.velocity.Y == 0f) - { - NPC.localAI[1] += 1f; - } - else - { - NPC.localAI[1] = 0f; - } - NPC.velocity.Y += 0.1f; - if (NPC.velocity.Y > 3f || NPC.localAI[1] >= 6f) - { - NPC.velocity.Y = -3f; - } + NPC.localAI[1] = 0f; + } + NPC.velocity.Y += 0.1f; + if (NPC.velocity.Y > 3f || NPC.localAI[1] >= 6f) + { + NPC.velocity.Y = -3f; } - NPC.velocity.X *= 0.95f; } } else @@ -230,29 +124,6 @@ namespace CalamityMod.NPCs.SunkenSea NPC.localAI[2] = 75f; NPC.netUpdate = true; } - - float SAImovement = 0.05f; - for (int k = 0; k < Main.maxNPCs; k++) - { - NPC otherJelly = Main.npc[k]; - // Short circuits to make the loop as fast as possible - if (!otherJelly.active || k == NPC.whoAmI || (otherJelly.type != ModContent.NPCType())) - continue; - - float taxicabDist = Math.Abs(NPC.position.X - otherJelly.position.X) + Math.Abs(NPC.position.Y - otherJelly.position.Y); - if (taxicabDist < NPC.width * 2f) - { - if (NPC.position.X < otherJelly.position.X) - NPC.velocity.X -= SAImovement; - else - NPC.velocity.X += SAImovement; - - if (NPC.position.Y < otherJelly.position.Y) - NPC.velocity.Y -= SAImovement; - else - NPC.velocity.Y += SAImovement; - } - } } public override void FindFrame(int frameHeight) @@ -267,14 +138,12 @@ namespace CalamityMod.NPCs.SunkenSea { if (spawnInfo.Player.Calamity().ZoneSunkenSea && spawnInfo.Water && !spawnInfo.Player.Calamity().clamity) { - // Drastically smaller in the Polyp Forest due to a bunch spawning at once - float multiplier = spawnInfo.Player.Calamity().ZonePolypForest ? 0.1f : 0.9f; - return SpawnCondition.CaveJellyfish.Chance * multiplier; + return SpawnCondition.CaveJellyfish.Chance * 0.9f; } return 0f; } - public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) + public override void PostDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) { SpriteEffects spriteEffects = SpriteEffects.None; if (NPC.spriteDirection == 1) @@ -284,32 +153,11 @@ namespace CalamityMod.NPCs.SunkenSea Vector2 center = new Vector2(NPC.Center.X, NPC.Center.Y); Vector2 halfSizeTexture = new Vector2((float)(TextureAssets.Npc[Type].Value.Width / 2), (float)(TextureAssets.Npc[Type].Value.Height / Main.npcFrameCount[Type] / 2)); Vector2 vector = center - screenPos; - vector -= new Vector2((float)GlowTexture.Value.Width, (float)(GlowTexture.Value.Height / Main.npcFrameCount[Type])) / 2f; + vector -= new Vector2((float)GlowTexture.Value.Width, (float)(GlowTexture.Value.Height / Main.npcFrameCount[Type])) * 1f / 2f; vector += halfSizeTexture * 1f + new Vector2(0f, 4f + NPC.gfxOffY); - - Texture2D tex = TextureAssets.Npc[NPC.type].Value; - Texture2D glowTex = GlowTexture.Value; - Color color = Color.LightBlue; - - switch (Variant) - { - case (int)JellyColor.Pink: - tex = PinkTexture.Value; - glowTex = PinkGlowTexture.Value; - color = Color.LightPink; - break; - case (int)JellyColor.Green: - tex = GreenTexture.Value; - glowTex = GreenGlowTexture.Value; - color = Color.SeaGreen; - break; - } - - color = new Color(127 - NPC.alpha, 127 - NPC.alpha, 127 - NPC.alpha, 0).MultiplyRGBA(color); - - Main.spriteBatch.Draw(tex, vector, NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, halfSizeTexture, NPC.scale, spriteEffects, 0f); - Main.spriteBatch.Draw(glowTex, vector, NPC.frame, color, NPC.rotation, halfSizeTexture, NPC.scale, spriteEffects, 0f); - return false; + Color color = new Color(127 - NPC.alpha, 127 - NPC.alpha, 127 - NPC.alpha, 0).MultiplyRGBA(Microsoft.Xna.Framework.Color.LightBlue); + Main.spriteBatch.Draw(GlowTexture.Value, vector, + new Microsoft.Xna.Framework.Rectangle?(NPC.frame), color, NPC.rotation, halfSizeTexture, 1f, spriteEffects, 0f); } // Can only hit the target if they're touching the tentacles @@ -351,36 +199,5 @@ namespace CalamityMod.NPCs.SunkenSea LeadingConditionRule postDS = npcLoot.DefineConditionalDropSet(DropHelper.PostDS()); postDS.Add(ModContent.ItemType(), 5); } - public override bool CanBeHitByNPC(NPC attacker) => PredatorIDs.Contains(attacker.type); - - public override void OnHitByProjectile(Projectile projectile, NPC.HitInfo hit, int damageDone) - { - if (projectile.friendly) - { - if (projectile.owner != -1) - { - BecomeHostile(projectile.owner); - } - } - } - - public override void OnHitByItem(Player player, Item item, NPC.HitInfo hit, int damageDone) - { - BecomeHostile(player.whoAmI); - } - - public void BecomeHostile(int player) - { - NPC.target = player; - Aggro = 1; - foreach (NPC n in Main.ActiveNPCs) - { - if (n.type == Type && n.whoAmI != NPC.whoAmI) - { - n.ai[3] = 1; - n.target = player; - } - } - } } } diff --git a/NPCs/SunkenSea/GhostBell.png b/NPCs/SunkenSea/GhostBell.png index fc0278b843..0a9a975802 100644 Binary files a/NPCs/SunkenSea/GhostBell.png and b/NPCs/SunkenSea/GhostBell.png differ diff --git a/NPCs/SunkenSea/GhostBellGlow.png b/NPCs/SunkenSea/GhostBellGlow.png index 24548367a2..0a9a975802 100644 Binary files a/NPCs/SunkenSea/GhostBellGlow.png and b/NPCs/SunkenSea/GhostBellGlow.png differ diff --git a/NPCs/SunkenSea/GhostBellGreen.png b/NPCs/SunkenSea/GhostBellGreen.png deleted file mode 100644 index 4f9ad193c7..0000000000 Binary files a/NPCs/SunkenSea/GhostBellGreen.png and /dev/null differ diff --git a/NPCs/SunkenSea/GhostBellGreenGlow.png b/NPCs/SunkenSea/GhostBellGreenGlow.png deleted file mode 100644 index 135a49aca6..0000000000 Binary files a/NPCs/SunkenSea/GhostBellGreenGlow.png and /dev/null differ diff --git a/NPCs/SunkenSea/GhostBellPink.png b/NPCs/SunkenSea/GhostBellPink.png deleted file mode 100644 index bfd5bc24b6..0000000000 Binary files a/NPCs/SunkenSea/GhostBellPink.png and /dev/null differ diff --git a/NPCs/SunkenSea/GhostBellPinkGlow.png b/NPCs/SunkenSea/GhostBellPinkGlow.png deleted file mode 100644 index 5887f7064b..0000000000 Binary files a/NPCs/SunkenSea/GhostBellPinkGlow.png and /dev/null differ diff --git a/NPCs/SunkenSea/PrismaticGuppy.cs b/NPCs/SunkenSea/PrismaticGuppy.cs index ebd038bf07..4310a62e1c 100644 --- a/NPCs/SunkenSea/PrismaticGuppy.cs +++ b/NPCs/SunkenSea/PrismaticGuppy.cs @@ -206,7 +206,6 @@ namespace CalamityMod.NPCs.SunkenSea { return; } - NPC.TargetClosest(); // Red/Green in reefs, Green/Blue elsewhere if (Main.player[NPC.target].Calamity().ZoneRadiantReefs) { @@ -216,6 +215,7 @@ namespace CalamityMod.NPCs.SunkenSea { CurrentColor = Main.rand.Next(0, 2); } + NPC.TargetClosest(); // 1 in 30 chance for a rare fish variant (rfv) if (Main.rand.NextBool(30)) {