Currently, the only way to subscribe to Polymorph events is to use the EventsPlugin and leverage scripthandlers. A "nice to have" here would be to have a more Anvil-specific way to register to polymorph and unpolymorph events.
Here is a current example of how I am doing it:
public class CharacterPolymorphService
{
private readonly Logger Log = LogManager.GetCurrentClassLogger();
public CharacterPolymorphService()
{
Log.Info("CharacterPolymorphService initialized.");
EventsPlugin.SubscribeEvent(EventsPlugin.NWNX_ON_POLYMORPH_BEFORE, "polymorph_before");
EventsPlugin.SubscribeEvent(EventsPlugin.NWNX_ON_UNPOLYMORPH_AFTER, "unpolymorph_after");
}
[ScriptHandler("unpolymorph_after")]
private void OnUnpolymorphAfter(CallInfo info)
{
if (!info.ObjectSelf.IsPlayerControlled(out NwPlayer? player)) return;
RestoreSpells(player);
}
[ScriptHandler("polymorph_before")]
private void OnPolymorphBefore(CallInfo info)
{
if (!info.ObjectSelf.IsPlayerControlled(out NwPlayer? player)) return;
SaveSpells(player);
}
// other stuff
Currently, the only way to subscribe to Polymorph events is to use the EventsPlugin and leverage scripthandlers. A "nice to have" here would be to have a more Anvil-specific way to register to polymorph and unpolymorph events.
Here is a current example of how I am doing it: