Files
CalamityModPublic/Systems/World/BestiaryRegistrySystem.cs
T
fryzahh d57fc7d223 Force bestiary critter registration for certain NPCs
* Certain NPC that don't fit the Vanilla criteria of "critter" can now be forcibly registered as one in the bestiary via simply adding them to the CalamaityNPCSets.ForciblyRegisterAsCritterInBestiary list
* Removed all instances of critters manually registering kills to unlock their entries in the bestiary
* Returned Divine Swine's health back to  99999999 now that it doesn't need to abide by Vanilla's critter criteria to be automatically registered
* Moved variant bestiary credit matching to a new Dictionary, CalamaityNPCSets.CountVariantsAsTheSameInBestiary
* BaseWormNPCHitbox NPCs are now automatically hidden from the bestiary
2026-07-29 15:13:53 -04:00

71 lines
3.2 KiB
C#

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;
namespace CalamityMod.Systems
{
public class BestiaryRegistrySystem : ModSystem
{
public override void PostSetupContent()
{
On_BestiaryDatabaseNPCsPopulator.AddEmptyEntries_CrittersAndEnemies_Automated += ForciblyAddEmptyEntriesForCritters;
On_NPCWasNearPlayerTracker.ScanWorldForFinds += ForciblySetWasSeenByPlayer;
// Manually register variants post-initiailization
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<int> exclusions = BestiaryDatabaseNPCsPopulator.GetExclusions();
foreach (KeyValuePair<int, NPC> 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);
}
}
}
}
}
}