diff --git a/NPCs/BaseWormNPC.cs b/NPCs/BaseWormNPC.cs index f37a581f3d..15401cd837 100644 --- a/NPCs/BaseWormNPC.cs +++ b/NPCs/BaseWormNPC.cs @@ -645,6 +645,11 @@ namespace CalamityMod.NPCs //The segments near a player spawn a hitbox NPC to allow damaging players and taking damage public abstract class BaseWormHitboxNPC : ModNPC { + public override void SetStaticDefaults() + { + this.HideFromBestiary(); + } + public override void SetDefaults() { NPC.width = 200; diff --git a/NPCs/Deconstructors/Burrower.cs b/NPCs/Deconstructors/Burrower.cs index bbe26f240b..cedac1aebe 100644 --- a/NPCs/Deconstructors/Burrower.cs +++ b/NPCs/Deconstructors/Burrower.cs @@ -210,11 +210,6 @@ namespace CalamityMod.NPCs.Deconstructors public override void AI() { - //Force burrower bestiary to unlock - if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0) - { - Main.BestiaryTracker.Kills.RegisterKill(NPC); - } HandleAIStates(); MainTimer++; UpdateSegments(); diff --git a/NPCs/DraedonLabThings/Androomba.cs b/NPCs/DraedonLabThings/Androomba.cs index 90182bcdaa..4d4db9b7c9 100644 --- a/NPCs/DraedonLabThings/Androomba.cs +++ b/NPCs/DraedonLabThings/Androomba.cs @@ -151,12 +151,6 @@ namespace CalamityMod.NPCs.DraedonLabThings } break; } - - // Force bestiary unlock - if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0) - { - Main.BestiaryTracker.Kills.RegisterKill(NPC); - } } public void ChangeAI(int phase) diff --git a/NPCs/DraedonLabThings/RepairUnitCritter.cs b/NPCs/DraedonLabThings/RepairUnitCritter.cs index a3c7bcb9c1..cbd39311c1 100644 --- a/NPCs/DraedonLabThings/RepairUnitCritter.cs +++ b/NPCs/DraedonLabThings/RepairUnitCritter.cs @@ -137,13 +137,8 @@ namespace CalamityMod.NPCs.DraedonLabThings break; } Time++; - - // Force bestiary unlock - if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0) - { - Main.BestiaryTracker.Kills.RegisterKill(NPC); - } } + public override bool? CanFallThroughPlatforms() => CurrentState == BehaviorState.WalkOnWalls; public void WalkAroundOnGround() diff --git a/NPCs/NormalNPCs/DivineSwine.cs b/NPCs/NormalNPCs/DivineSwine.cs index 5c13c3055a..9dfea10249 100644 --- a/NPCs/NormalNPCs/DivineSwine.cs +++ b/NPCs/NormalNPCs/DivineSwine.cs @@ -118,7 +118,7 @@ namespace CalamityMod.NPCs.NormalNPCs Main.npcFrameCount[Type] = 14; NPCID.Sets.CountsAsCritter[Type] = true; NPCID.Sets.CantTakeLunchMoney[Type] = true; - NPCID.Sets.NormalGoldCritterBestiaryPriority.Insert(NPCID.Sets.NormalGoldCritterBestiaryPriority.IndexOf(NPCID.GoldBunny) + 1, Type); + NPCID.Sets.NormalGoldCritterBestiaryPriority.Add(Type); NPCID.Sets.ImmuneToAllBuffs[Type] = true; NPCID.Sets.ShimmerImmunity[Type] = true; } @@ -128,7 +128,7 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.damage = 0; NPC.width = 32; NPC.height = 34; - NPC.lifeMax = 5; + NPC.lifeMax = 99999999; NPC.defense = 99999999; NPC.rarity = 5; NPC.aiStyle = -1; diff --git a/NPCs/NormalNPCs/Piggy.cs b/NPCs/NormalNPCs/Piggy.cs index db8bafda5e..d6b6b79140 100644 --- a/NPCs/NormalNPCs/Piggy.cs +++ b/NPCs/NormalNPCs/Piggy.cs @@ -106,7 +106,7 @@ namespace CalamityMod.NPCs.NormalNPCs NPCID.Sets.CountsAsCritter[Type] = true; NPCID.Sets.CantTakeLunchMoney[Type] = true; NPCID.Sets.TakesDamageFromHostilesWithoutBeingFriendly[Type] = true; - NPCID.Sets.NormalGoldCritterBestiaryPriority.Insert(NPCID.Sets.NormalGoldCritterBestiaryPriority.IndexOf(NPCID.GoldBunny) + 1, Type); + NPCID.Sets.NormalGoldCritterBestiaryPriority.Add(Type); } public override void SetDefaults() @@ -142,10 +142,6 @@ namespace CalamityMod.NPCs.NormalNPCs public override void AI() { - // Force bestiary cause this doesn't count as Vanilla's definition of a critter for the Bestiary. - if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0) - Main.BestiaryTracker.Kills.SetKillCountDirectly(NPC.GetBestiaryCreditId(), 100); - if (NPC.direction == 0) NPC.direction = Utils.SelectRandom(Main.rand, -1, 1); diff --git a/NPCs/NormalNPCs/PiggyGold.cs b/NPCs/NormalNPCs/PiggyGold.cs index 5f6978d906..32043e3c04 100644 --- a/NPCs/NormalNPCs/PiggyGold.cs +++ b/NPCs/NormalNPCs/PiggyGold.cs @@ -23,7 +23,7 @@ namespace CalamityMod.NPCs.NormalNPCs NPCID.Sets.CantTakeLunchMoney[Type] = true; NPCID.Sets.TakesDamageFromHostilesWithoutBeingFriendly[Type] = true; NPCID.Sets.GoldCrittersCollection.Add(Type); - NPCID.Sets.NormalGoldCritterBestiaryPriority.Insert(NPCID.Sets.NormalGoldCritterBestiaryPriority.IndexOf(ModContent.NPCType()) + 1, Type); + NPCID.Sets.NormalGoldCritterBestiaryPriority.Add(Type); } public override void SetDefaults() @@ -32,16 +32,18 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.rarity = 3; NPC.catchItem = (short)ModContent.ItemType(); Banner = 0; + BannerItem = 0; } public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) { // All gold critters have the same Bestiary entry. - var flavorText = database.FindEntryByNPCID(NPCID.GoldBunny).Info.Where(info => info is FlavorTextBestiaryInfoElement).FirstOrDefault(); + string key = Lang.GetNPCName(NPCID.GoldBunny).Key.Replace("NPCName.", ""); + string flavorText = "Bestiary_FlavorText.npc_" + key; bestiaryEntry.AddTags( BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Times.DayTime, - BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Surface, - flavorText); + BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Surface, + new FlavorTextBestiaryInfoElement(flavorText)); } public override void AI() diff --git a/NPCs/NormalNPCs/Shroomble.cs b/NPCs/NormalNPCs/Shroomble.cs index 3dd653a19f..676fbd882e 100644 --- a/NPCs/NormalNPCs/Shroomble.cs +++ b/NPCs/NormalNPCs/Shroomble.cs @@ -49,12 +49,6 @@ namespace CalamityMod.NPCs.NormalNPCs public override void AI() { - // Force bestiary unlock - if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0) - { - Main.BestiaryTracker.Kills.RegisterKill(NPC); - } - bool walking = NPC.ai[0] == 1; // Do a cute lil' hop randomly int jumpChance = walking ? 600 : 100; diff --git a/Systems/Collections/CalamityNPCSets.cs b/Systems/Collections/CalamityNPCSets.cs index 76fd562898..b3c715c348 100644 --- a/Systems/Collections/CalamityNPCSets.cs +++ b/Systems/Collections/CalamityNPCSets.cs @@ -12,8 +12,10 @@ using CalamityMod.NPCs.CeaselessVoid; using CalamityMod.NPCs.Crabulon; using CalamityMod.NPCs.Crags; using CalamityMod.NPCs.Cryogen; +using CalamityMod.NPCs.Deconstructors; using CalamityMod.NPCs.DesertScourge; using CalamityMod.NPCs.DevourerofGods; +using CalamityMod.NPCs.DraedonLabThings; using CalamityMod.NPCs.ExoMechs.Apollo; using CalamityMod.NPCs.ExoMechs.Ares; using CalamityMod.NPCs.ExoMechs.Artemis; @@ -338,6 +340,35 @@ namespace CalamityMod.Systems.Collections NPCType(), 18000 // 5:00 (300 seconds) ); + + /// + /// Allows an NPC to be automatically registered as a critter in the Bestiary when the player is near them.
+ /// Should only be used in cases where an NPC does NOT follow the Vanilla definition of a critter. See . + ///
+ public static List ForciblyRegisterAsCritterInBestiary = new List + { + NPCType(), + NPCType(), + NPCType(), + NPCType(), + NPCType(), + NPCType(), + NPCType(), + NPCType() + }; + + /// + /// Allows a variant of an NPC to count as credits towards another in the Bestiary.
+ /// This exists to prevent cases where dupilcate entries are made for two variants of the same creature, such as worms and their segments. + ///
+ public static Dictionary CountVariantsAsTheSameInBestiary = new Dictionary + { + { NPCType(), NPCType() }, + { NPCType(), NPCType() }, + { NPCType(), NPCType() }, + { NPCType(), NPCType() }, + }; + /// /// Associates an NPC type with the base value of their max health in Boss Rush.
/// If an NPC type is not a key in this dictionary, then it will use its standard max health value. diff --git a/Systems/World/BestiaryRegistrySystem.cs b/Systems/World/BestiaryRegistrySystem.cs index ced469a837..806134b0a8 100644 --- a/Systems/World/BestiaryRegistrySystem.cs +++ b/Systems/World/BestiaryRegistrySystem.cs @@ -1,6 +1,11 @@ -using CalamityMod.NPCs.Abyss; +using System.Collections.Generic; +using CalamityMod.NPCs.Abyss; using CalamityMod.NPCs.Astral; using CalamityMod.NPCs.Crags; +using CalamityMod.NPCs.Deconstructors; +using CalamityMod.Systems.Collections; +using Terraria; +using Terraria.GameContent.Bestiary; using Terraria.ID; using Terraria.ModLoader; using static Terraria.ModLoader.ModContent; @@ -11,10 +16,55 @@ namespace CalamityMod.Systems { public override void PostSetupContent() { + On_BestiaryDatabaseNPCsPopulator.AddEmptyEntries_CrittersAndEnemies_Automated += ForciblyAddEmptyEntriesForCritters; + On_NPCWasNearPlayerTracker.ScanWorldForFinds += ForciblySetWasSeenByPlayer; + // Manually register variants post-initiailization - ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType()] = ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType()]; - ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType()] = ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType()]; - ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType()] = ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType()]; + foreach (var pair in CalamityNPCSets.CountVariantsAsTheSameInBestiary) + ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[pair.Key] = ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[pair.Value]; + } + + private void ForciblyAddEmptyEntriesForCritters(On_BestiaryDatabaseNPCsPopulator.orig_AddEmptyEntries_CrittersAndEnemies_Automated orig, BestiaryDatabaseNPCsPopulator self) + { + orig(self); + + // Run through all entries again and remove the empty Enemy entries that are added by tMod itself. + // Afterwards, mnually add empty Critter entries for all NPCs within the ID set. + HashSet exclusions = BestiaryDatabaseNPCsPopulator.GetExclusions(); + foreach (KeyValuePair pair in ContentSamples.NpcsByNetId) + { + if (!exclusions.Contains(pair.Key)) + { + if (CalamityNPCSets.ForciblyRegisterAsCritterInBestiary.Contains(pair.Value.type)) + { + if (BestiaryDatabaseNPCsPopulator._currentDatabase._byNpcId.TryGetValue(pair.Value.netID, out BestiaryEntry enemyEntry) && enemyEntry.UIInfoProvider is not CritterUICollectionInfoProvider) + BestiaryDatabaseNPCsPopulator._currentDatabase.Entries.Remove(enemyEntry); + + NPCLoader.SetBestiary(pair.Value, BestiaryDatabaseNPCsPopulator._currentDatabase, self.Register(BestiaryEntry.Critter(pair.Key))); + } + } + } + } + + private void ForciblySetWasSeenByPlayer(On_NPCWasNearPlayerTracker.orig_ScanWorldForFinds orig, NPCWasNearPlayerTracker self) + { + orig(self); + + // Allow NPCs with manully added empty critter entries to be registered by player proximity. + foreach (NPC npc in Main.ActiveNPCs) + { + if (!CalamityNPCSets.ForciblyRegisterAsCritterInBestiary.Contains(npc.type) || self._wasSeenNearPlayerByNetId.Contains(npc.netID)) + continue; + + for (int i = 0; i < self._playerHitboxesForBestiary.Count; i++) + { + if (npc.Hitbox.Intersects(self._playerHitboxesForBestiary[i])) + { + self._wasSeenNearPlayerByNetId.Add(npc.netID); + self.RegisterWasNearby(npc); + } + } + } } } }