worldbox-observer-mod/IdleSpectator/ActorActivityPatches.cs
2026-07-14 23:11:51 -05:00

97 lines
2.7 KiB
C#

using ai.behaviours;
using HarmonyLib;
namespace IdleSpectator;
/// <summary>
/// Feeds <see cref="ActivityLog"/> from task changes and curated behaviour beats.
/// </summary>
[HarmonyPatch]
public static class ActorActivityPatches
{
[HarmonyPatch(typeof(Actor), nameof(Actor.setTask))]
[HarmonyPostfix]
public static void PostfixSetTask(Actor __instance, string pTaskId)
{
if (__instance == null || string.IsNullOrEmpty(pTaskId))
{
return;
}
ActivityLog.NoteTask(__instance, pTaskId);
}
[HarmonyPatch(typeof(BehPollinate), nameof(BehPollinate.execute))]
[HarmonyPostfix]
public static void PostfixPollinate(Actor pActor, BehResult __result)
{
if (pActor == null || __result == BehResult.Stop)
{
return;
}
string target = ActivityInterestTable.TargetLabel(pActor);
if (string.IsNullOrEmpty(target))
{
target = "flower";
}
ActivityLog.NoteActionBeat(pActor, "BehPollinate", "Pollinates " + target, target);
}
[HarmonyPatch(typeof(BehUnloadResources), nameof(BehUnloadResources.execute))]
[HarmonyPrefix]
public static void PrefixUnload(Actor pActor, out bool __state)
{
__state = false;
try
{
__state = pActor != null && pActor.isCarryingResources();
}
catch
{
__state = false;
}
}
[HarmonyPatch(typeof(BehUnloadResources), nameof(BehUnloadResources.execute))]
[HarmonyPostfix]
public static void PostfixUnload(Actor pActor, bool __state)
{
if (pActor == null || !__state)
{
return;
}
ActivityLog.NoteActionBeat(pActor, "BehUnloadResources", "Unloads resources", "town");
}
[HarmonyPatch(typeof(BehAttackActorHuntingTarget), nameof(BehAttackActorHuntingTarget.execute))]
[HarmonyPostfix]
public static void PostfixHuntAttack(Actor pActor, BehResult __result)
{
if (pActor == null)
{
return;
}
string target = ActivityInterestTable.TargetLabel(pActor);
ActivityLog.NoteActionBeat(
pActor,
"BehAttackActorHuntingTarget",
string.IsNullOrEmpty(target) ? "Hunts prey" : "Hunts " + target,
target);
}
[HarmonyPatch(typeof(BehCityActorRemoveFire), nameof(BehCityActorRemoveFire.execute))]
[HarmonyPostfix]
public static void PostfixRemoveFire(Actor pActor, BehResult __result)
{
if (pActor == null)
{
return;
}
ActivityLog.NoteActionBeat(pActor, "BehCityActorRemoveFire", "Fights fire", "blaze");
}
}