worldbox-observer-mod/IdleSpectator/Events/Patches/BuildingEventPatches.cs
2026-07-16 20:46:22 -05:00

70 lines
2 KiB
C#

using ai.behaviours;
using HarmonyLib;
namespace IdleSpectator;
/// <summary>Building damage/destroy/eat interest patches from mutation discovery.</summary>
[HarmonyPatch]
public static class BuildingEventPatches
{
[HarmonyPatch(typeof(BehDealDamageToTargetBuilding), nameof(BehDealDamageToTargetBuilding.execute))]
[HarmonyPostfix]
public static void PostfixDamageBuilding(Actor pActor, BehResult __result)
{
// Routine siege chips are Layer B noise. Camera waits for consume.
_ = pActor;
_ = __result;
}
[HarmonyPatch(typeof(BehConsumeTargetBuilding), nameof(BehConsumeTargetBuilding.execute))]
[HarmonyPostfix]
public static void PostfixConsumeBuilding(Actor pActor, BehResult __result)
{
if (pActor == null || !pActor.isAlive() || __result == BehResult.Stop)
{
return;
}
Building food = null;
try
{
food = pActor.beh_building_target;
}
catch
{
food = null;
}
string label = EventReason.BuildingEat(pActor, food);
Emit("building_consume", 78f, pActor, label);
}
[HarmonyPatch(typeof(Building), "startDestroyBuilding")]
[HarmonyPostfix]
public static void PostfixStartDestroy(Building __instance)
{
// Ambient object/building falls are Layer B only.
// Nearest-unit attach + "A Tree falls near X" was winning Watching then blanking via identity_filter.
// Intentional spectacle remains building_consume (actor-led eat).
_ = __instance;
}
private static void Emit(string eventId, float strength, Actor actor, string label)
{
if (!AgentHarness.LiveFeedsAllowed)
{
return;
}
string key = "building:" + eventId + ":" + EventFeedUtil.SafeId(actor);
EventFeedUtil.Register(
key,
"building",
"Spectacle",
label,
eventId,
strength,
actor.current_position,
actor);
}
}