fix(trenta): the Muspell no longer swings the weapon in hand

The Muspell was the one form without the attack blocks every other form
has. Each stomp and spike also started the hidden human's attack, and the
Elder clone's CharacterAnimEvent fired a held bow or crossbow through
OnAttackTrigger, several shots a swing.

StartAttack, PlayerAttackInput and OnAttackTrigger are shut while the
Muspell is up, and the guard is cleared after SetControls, since the
spike sits on Right Mouse, which is also Block.
This commit is contained in:
kanym 2026-10-29 01:50:33 +01:00
commit 99ec4134be

View file

@ -498,4 +498,48 @@ namespace RacesOfValheim
target.Damage(hitData);
}
}
/// <summary>
/// The hidden human does not fight under the Muspell. Every other form already had these
/// (see Fenrir's BlockPlayerLogicAttackPatch); the Muspell had none, so each stomp and spike
/// also swung the weapon in hand, and the Elder clone's own CharacterAnimEvent fired the held
/// bow or crossbow through OnAttackTrigger on top of that: a tester's bow shot several times a
/// swing. Right Mouse is the spike and the Block button at once, so the guard is cleared too,
/// as BlockPlayerGuardPatch does it.
/// </summary>
internal static class TrentaMuspellAttackBlock
{
private static bool LocalInForm(Character character) =>
TrentaMuspell.IsTransformed && character != null && character == Player.m_localPlayer;
[HarmonyPatch(typeof(Humanoid), nameof(Humanoid.StartAttack))]
public static class Trenta_MuspellBlockNativeAttack_Patch
{
public static bool Prefix(Humanoid __instance) => !LocalInForm(__instance);
}
[HarmonyPatch(typeof(Player), "PlayerAttackInput")]
public static class Trenta_MuspellBlockAttackInput_Patch
{
public static bool Prefix(Player __instance) => !LocalInForm(__instance);
}
[HarmonyPatch(typeof(Humanoid), nameof(Humanoid.OnAttackTrigger))]
public static class Trenta_MuspellBlockAttackTrigger_Patch
{
public static bool Prefix(Humanoid __instance) => !LocalInForm(__instance);
}
[HarmonyPatch(typeof(Player), nameof(Player.SetControls))]
public static class Trenta_MuspellBlockGuard_Patch
{
private static readonly AccessTools.FieldRef<Character, bool> Blocking =
AccessTools.FieldRefAccess<Character, bool>("m_blocking");
public static void Postfix(Player __instance)
{
if (LocalInForm(__instance)) Blocking(__instance) = false;
}
}
}
}