using System;
using ai.behaviours;
namespace IdleSpectator;
///
/// Observe → confirm → emit bridge. Patches stay thin sensors; feeds only run after
/// confirms the catalog claim matches game state.
///
public static class EventObservation
{
///
/// If , run ; otherwise record a drop.
///
public static bool Confirm(
string source,
string eventId,
bool confirmed,
Action emit)
{
string id = string.IsNullOrEmpty(eventId) ? "unknown" : eventId.Trim();
string src = string.IsNullOrEmpty(source) ? "observe" : source.Trim();
if (!confirmed)
{
InterestDropLog.Record("outcome_unconfirmed", src + ":" + id);
return false;
}
if (emit == null)
{
return false;
}
emit();
return true;
}
///
/// Prefix/Postfix helper: snapshot before a behaviour, confirm with a predicate after.
///
public static bool ConfirmAfter(
string source,
string eventId,
EventOutcome.ActorFlags before,
Actor actor,
BehResult result,
Func outcome,
Action emit)
{
if (outcome == null)
{
return false;
}
bool ok = false;
try
{
ok = outcome(before, actor, result);
}
catch
{
ok = false;
}
return Confirm(source, eventId, ok, emit);
}
}