worldbox-observer-mod/IdleSpectator/ActorChroniclePatches.cs
2026-07-14 16:25:28 -05:00

72 lines
1.8 KiB
C#

using HarmonyLib;
namespace IdleSpectator;
/// <summary>
/// Feeds character History from kills, deaths, lovers, and best friends.
/// </summary>
[HarmonyPatch]
public static class ActorChroniclePatches
{
[HarmonyPatch(typeof(Actor), "newKillAction")]
[HarmonyPostfix]
public static void PostfixNewKill(Actor __instance, Actor pDeadUnit)
{
Chronicle.NoteKill(__instance, pDeadUnit);
}
[HarmonyPatch(typeof(Actor), "die")]
[HarmonyPrefix]
public static void PrefixDie(Actor __instance, out Actor __state)
{
__state = null;
try
{
if (__instance == null)
{
return;
}
BaseSimObject attacker = __instance.attackedBy;
if (attacker != null && !attacker.isRekt() && attacker.isActor() && attacker != __instance)
{
__state = attacker.a;
}
}
catch
{
__state = null;
}
}
[HarmonyPatch(typeof(Actor), "die")]
[HarmonyPostfix]
public static void PostfixDie(Actor __instance, AttackType pType, bool pCountDeath, Actor __state)
{
if (!pCountDeath || __instance == null)
{
return;
}
Chronicle.NoteDeath(__instance, pType, __state);
}
[HarmonyPatch(typeof(Actor), nameof(Actor.becomeLoversWith))]
[HarmonyPostfix]
public static void PostfixLovers(Actor __instance, Actor pTarget)
{
Chronicle.NoteLovers(__instance, pTarget);
}
[HarmonyPatch(typeof(Actor), nameof(Actor.setBestFriend))]
[HarmonyPostfix]
public static void PostfixBestFriend(Actor __instance, Actor pActor, bool pNew)
{
if (!pNew)
{
return;
}
Chronicle.NoteBestFriends(__instance, pActor);
}
}