50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using HarmonyLib;
|
|
using UnityEngine;
|
|
|
|
namespace IdleSpectator;
|
|
|
|
[HarmonyPatch(typeof(SubspeciesManager), nameof(SubspeciesManager.newSpecies))]
|
|
public static class SubspeciesNewSpeciesPatch
|
|
{
|
|
private static readonly Dictionary<string, float> LastLiveEnqueuedAt = new Dictionary<string, float>();
|
|
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;
|
|
}
|
|
|
|
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;
|
|
InterestCollector.EnqueueDirect(curiosity);
|
|
}
|
|
}
|