using System.Collections.Generic; using HarmonyLib; using UnityEngine; namespace IdleSpectator; [HarmonyPatch(typeof(SubspeciesManager), nameof(SubspeciesManager.newSpecies))] public static class SubspeciesNewSpeciesPatch { private static readonly Dictionary LastLiveEnqueuedAt = new Dictionary(); private const float PerSpeciesCooldownSeconds = 45f; public static void Postfix(SubspeciesManager __instance, ActorAsset pAsset, WorldTile pTile, bool pMutation, Subspecies __result) { // Always remember first-seen assets (including during map gen) for later discovery drain. SpeciesDiscovery.NoteCreated(pAsset, pTile, pMutation, __result); if (!SpectatorMode.Active || pMutation) { return; } // Live path: only while the world is playable, not during SmoothLoader gen flood. if (SmoothLoader.isLoading()) { return; } string assetId = pAsset != null ? pAsset.id : null; if (string.IsNullOrEmpty(assetId)) { return; } // Drain already tipped this species (or live tip already fired). if (SpeciesDiscovery.WasPresented(assetId)) { return; } float now = Time.unscaledTime; if (LastLiveEnqueuedAt.TryGetValue(assetId, out float last) && now - last < PerSpeciesCooldownSeconds) { return; } InterestEvent curiosity = WorldActivityScanner.FromNewSpecies(__result, pAsset, pTile); if (curiosity == null) { return; } LastLiveEnqueuedAt[assetId] = now; SpeciesDiscovery.MarkPresented(assetId); InterestCollector.EnqueueDirect(curiosity); } }