67 lines
1.6 KiB
C#
67 lines
1.6 KiB
C#
using System;
|
|
using ai.behaviours;
|
|
|
|
namespace IdleSpectator;
|
|
|
|
/// <summary>
|
|
/// Observe → confirm → emit bridge. Patches stay thin sensors; feeds only run after
|
|
/// <see cref="EventOutcome"/> confirms the catalog claim matches game state.
|
|
/// </summary>
|
|
public static class EventObservation
|
|
{
|
|
/// <summary>
|
|
/// If <paramref name="confirmed"/>, run <paramref name="emit"/>; otherwise record a drop.
|
|
/// </summary>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Prefix/Postfix helper: snapshot before a behaviour, confirm with a predicate after.
|
|
/// </summary>
|
|
public static bool ConfirmAfter(
|
|
string source,
|
|
string eventId,
|
|
EventOutcome.ActorFlags before,
|
|
Actor actor,
|
|
BehResult result,
|
|
Func<EventOutcome.ActorFlags, Actor, BehResult, bool> 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);
|
|
}
|
|
}
|