worldbox-observer-mod/IdleSpectator/DeferredInterestFeed.cs
2026-07-15 22:16:24 -05:00

198 lines
5.1 KiB
C#

using UnityEngine;
namespace IdleSpectator;
/// <summary>Unit-owned emits for deferred Phase 2 libraries (spells/items/decisions/etc.).</summary>
public static class DeferredInterestFeed
{
public static void EmitSpell(string spellId, Actor caster)
{
EmitFromCatalog(
"spell",
spellId,
caster,
SpellInterestCatalog.GetOrFallback,
related: null,
locationOnly: false);
}
public static void EmitItem(string itemId, Actor craftsman)
{
EmitFromCatalog(
"item",
itemId,
craftsman,
ItemInterestCatalog.GetOrFallback,
related: null,
locationOnly: false);
}
public static void EmitDecision(string decisionId, Actor actor)
{
EmitFromCatalog(
"decision",
decisionId,
actor,
DecisionInterestCatalog.GetOrFallback,
related: null,
locationOnly: false);
}
public static void EmitPower(string powerId, Vector3 position, Actor nearUnit)
{
DiscreteEventEntry entry = PowerInterestCatalog.GetOrFallback(powerId);
if (!entry.CreatesInterest || AgentHarness.Busy)
{
return;
}
if (nearUnit != null && nearUnit.isAlive())
{
EmitFromCatalog("power", powerId, nearUnit, PowerInterestCatalog.GetOrFallback, null, false);
return;
}
if (position == Vector3.zero)
{
return;
}
EventFeedUtil.Register(
"power:" + entry.Id,
"power",
entry.Category,
entry.MakeLabel("", ""),
entry.Id,
entry.EventStrength,
entry.OwnsCamera,
position,
follow: null,
locationOnly: true);
}
public static void EmitSubspeciesTrait(string traitId, Actor anchor)
{
EmitFromCatalog(
"subspecies_trait",
traitId,
anchor,
SubspeciesTraitInterestCatalog.GetOrFallback,
related: null,
locationOnly: false);
}
public static void EmitGene(string geneId, Actor actor)
{
EmitFromCatalog(
"gene",
geneId,
actor,
GeneInterestCatalog.GetOrFallback,
related: null,
locationOnly: false);
}
public static void EmitPhenotype(string phenotypeId, Actor actor)
{
EmitFromCatalog(
"phenotype",
phenotypeId,
actor,
PhenotypeInterestCatalog.GetOrFallback,
related: null,
locationOnly: false);
}
public static void EmitWorldLaw(string lawId, Vector3 position)
{
if (AgentHarness.Busy || position == Vector3.zero)
{
return;
}
DiscreteEventEntry entry = WorldLawInterestCatalog.GetOrFallback(lawId);
if (!entry.CreatesInterest)
{
return;
}
EventFeedUtil.Register(
"worldlaw:" + entry.Id,
"worldlaw",
entry.Category,
entry.MakeLabel("", ""),
entry.Id,
entry.EventStrength,
entry.OwnsCamera,
position,
follow: null,
locationOnly: true);
}
public static void EmitBiome(string biomeId, Vector3 position)
{
if (AgentHarness.Busy || position == Vector3.zero)
{
return;
}
DiscreteEventEntry entry = BiomeInterestCatalog.GetOrFallback(biomeId);
if (!entry.CreatesInterest)
{
return;
}
EventFeedUtil.Register(
"biome:" + entry.Id,
"biome",
entry.Category,
entry.MakeLabel("", ""),
entry.Id,
entry.EventStrength,
entry.OwnsCamera,
position,
follow: null,
locationOnly: true);
}
private static void EmitFromCatalog(
string source,
string assetId,
Actor subject,
System.Func<string, DiscreteEventEntry> lookup,
Actor related,
bool locationOnly)
{
if (AgentHarness.Busy || lookup == null)
{
return;
}
DiscreteEventEntry entry = lookup(assetId);
if (!entry.CreatesInterest)
{
return;
}
Actor follow = subject != null && subject.isAlive() ? subject : null;
if (!locationOnly && follow == null)
{
return;
}
string label = entry.MakeLabel(EventFeedUtil.SafeName(follow), "");
string key = source + ":" + entry.Id + ":" + EventFeedUtil.SafeId(follow);
EventFeedUtil.Register(
key,
source,
entry.Category,
label,
entry.Id,
entry.EventStrength,
entry.OwnsCamera,
follow != null ? follow.current_position : Vector3.zero,
follow,
related: related,
locationOnly: locationOnly);
}
}