-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAgentInteractionInterfaceVMPatch.cs
38 lines (34 loc) · 1.34 KB
/
AgentInteractionInterfaceVMPatch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using HarmonyLib;
using TaleWorlds.MountAndBlade;
using TaleWorlds.MountAndBlade.ViewModelCollection.Multiplayer;
using TaleWorlds.Core;
using System.Diagnostics.CodeAnalysis;
namespace Bannerlord.HealthIndicator.Patches
{
public class AgentInteractionInterfaceVMPatch
{
[AllowNull]
static AgentInteractionInterfaceVM agentVm;
[HarmonyPatch(typeof(AgentInteractionInterfaceVM), "SetAgent")]
public class SetAgentPatch{
static void Postfix(Agent focusedAgent, AgentInteractionInterfaceVM __instance)
{
__instance.PrimaryInteractionMessage = __instance.PrimaryInteractionMessage + $" ({focusedAgent.Health}/{focusedAgent.HealthLimit})";
agentVm = __instance;
focusedAgent.OnAgentHealthChanged += HandleOnAgentHealthChanged;
}
}
[HarmonyPatch(typeof(AgentInteractionInterfaceVM), "OnFocusLost")]
public class OnFocusLostPatch
{
static void Postfix(Agent agent)
{
agent.OnAgentHealthChanged -= HandleOnAgentHealthChanged;
}
}
private static void HandleOnAgentHealthChanged(Agent agent, float oldHealth, float newHealth)
{
agentVm.PrimaryInteractionMessage = $"{agent.Name} ({newHealth}/{agent.HealthLimit})";
}
}
}