worldbox-observer-mod/IdleSpectator/Events/Feeds/DeferredInterestFeed.cs
2026-07-16 00:40:53 -05:00

199 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,
EventCatalog.Spell.GetOrFallback,
related: null,
locationOnly: false);
}
public static void EmitItem(string itemId, Actor craftsman)
{
EmitFromCatalog(
"item",
itemId,
craftsman,
EventCatalog.Item.GetOrFallback,
related: null,
locationOnly: false);
}
public static void EmitDecision(string decisionId, Actor actor)
{
EmitFromCatalog(
"decision",
decisionId,
actor,
EventCatalog.Decision.GetOrFallback,
related: null,
locationOnly: false);
}
public static void EmitPower(string powerId, Vector3 position, Actor nearUnit)
{
DiscreteEventEntry entry = EventCatalog.Power.GetOrFallback(powerId);
if (!entry.CreatesInterest || AgentHarness.Busy)
{
return;
}
if (nearUnit != null && nearUnit.isAlive())
{
EmitFromCatalog("power", powerId, nearUnit, EventCatalog.Power.GetOrFallback, null, false);
return;
}
if (position == Vector3.zero)
{
return;
}
EventFeedUtil.Register(
"power:" + entry.Id,
"power",
entry.Category,
EventReason.HumanizeId(entry.Id),
entry.Id,
entry.EventStrength,
position,
follow: null,
locationOnly: true);
}
public static void EmitSubspeciesTrait(string traitId, Actor anchor)
{
EmitFromCatalog(
"subspecies_trait",
traitId,
anchor,
EventCatalog.SubspeciesTrait.GetOrFallback,
related: null,
locationOnly: false);
}
public static void EmitGene(string geneId, Actor actor)
{
EmitFromCatalog(
"gene",
geneId,
actor,
EventCatalog.Gene.GetOrFallback,
related: null,
locationOnly: false);
}
public static void EmitPhenotype(string phenotypeId, Actor actor)
{
EmitFromCatalog(
"phenotype",
phenotypeId,
actor,
EventCatalog.Phenotype.GetOrFallback,
related: null,
locationOnly: false);
}
public static void EmitWorldLaw(string lawId, Vector3 position)
{
if (AgentHarness.Busy || position == Vector3.zero)
{
return;
}
DiscreteEventEntry entry = EventCatalog.WorldLaw.GetOrFallback(lawId);
if (!entry.CreatesInterest)
{
return;
}
EventFeedUtil.Register(
"worldlaw:" + entry.Id,
"worldlaw",
entry.Category,
EventReason.HumanizeId(entry.Id),
entry.Id,
entry.EventStrength,
position,
follow: null,
locationOnly: true);
}
public static void EmitBiome(string biomeId, Vector3 position)
{
if (AgentHarness.Busy || position == Vector3.zero)
{
return;
}
DiscreteEventEntry entry = EventCatalog.Biome.GetOrFallback(biomeId);
if (!entry.CreatesInterest)
{
return;
}
EventFeedUtil.Register(
"biome:" + entry.Id,
"biome",
entry.Category,
EventReason.HumanizeId(entry.Id),
entry.Id,
entry.EventStrength,
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 = EventReason.Library(follow, source, entry.Id);
if (follow == null)
{
label = EventReason.HumanizeId(entry.Id);
}
string key = source + ":" + entry.Id + ":" + EventFeedUtil.SafeId(follow);
EventFeedUtil.Register(
key,
source,
entry.Category,
label,
entry.Id,
entry.EventStrength,
follow != null ? follow.current_position : Vector3.zero,
follow,
related: related,
locationOnly: locationOnly);
}
}