feat: Trol True Form can block and roll

Right click blocks in True Form with a raised-arms guard, rooted in place.
Block + jump rolls at half distance with the troll's jump animation at
double speed. The slam moves to middle click (secondary attack on a pad).
trolpose is a debug command for trying guard and roll states live.
This commit is contained in:
kanym 2026-10-28 13:53:35 +01:00
commit 3cc1bee2c0
4 changed files with 382 additions and 1 deletions

View file

@ -27,6 +27,9 @@ namespace RacesOfValheim
private bool isAttacking;
private float busySince = -1f;
private bool guarding;
private bool dodging;
private readonly TrolGuardPose guardPose = new TrolGuardPose();
private GameObject heldLog;
private string heldLogName;
@ -42,6 +45,8 @@ namespace RacesOfValheim
private void OnDestroy()
{
TrolTrueFormModel.LocalAttacking = false;
TrolTrueFormModel.EndDodge();
if (guarding && Player.m_localPlayer != null) TrolTrueFormModel.PublishGuard(Player.m_localPlayer, false);
}
private void Start()
@ -84,22 +89,60 @@ namespace RacesOfValheim
SetAttacking(false);
}
// The guard: right click blocks, as it does for the human underneath, and the troll
// holds a pose for it. A roll out of the guard drops it, so the roll is not hidden
// behind a frozen troll.
bool guard = !isAttacking && !player.IsDead() && player.IsBlocking() && !player.InDodge();
TrolTrueFormModel.TickDodge();
if (guard) TrolTrueFormModel.EndDodge();
Guard(player, guard);
if (isAttacking || player.IsDead()) return;
bool grounded = locomotion.Mirror(anim, playerAnim, player);
if (guard) return;
if (player.InDodge())
{
if (!dodging) TrolTrueFormModel.PlayDodge(anim);
dodging = true;
return;
}
dodging = false;
if (!grounded || !RaceInput.Allowed) return;
// Left punches, middle slams: the vanilla primary and secondary attack. Right click is
// the block, so the slam no longer goes off every time the troll raises its guard.
bool log = heldLogName != null;
if (RaceInput.AttackDown(0))
{
Play(log ? TrolTrueFormModel.AttackKind.LogSwingH : TrolTrueFormModel.AttackKind.Punch);
}
else if (RaceInput.AttackDown(1))
else if (RaceInput.AttackDown(2))
{
Play(log ? TrolTrueFormModel.AttackKind.LogSwingV : TrolTrueFormModel.AttackKind.Slam);
}
}
/// <summary>Holds the guard pose while blocking and lets go after, and tells every other
/// client which pose to hold.</summary>
private void Guard(Player player, bool on)
{
if (on)
{
guardPose.Hold(anim, TrolTrueFormModel.GuardState, TrolTrueFormModel.GuardTime);
TrolTrueFormModel.PublishGuard(player, true);
guarding = true;
}
else if (guarding)
{
guardPose.Release(anim);
TrolTrueFormModel.PublishGuard(player, false);
guarding = false;
}
}
private void Play(TrolTrueFormModel.AttackKind kind)
{
TrolTrueFormModel.Profile profile = TrolTrueFormModel.Get(kind);
@ -406,6 +449,8 @@ namespace RacesOfValheim
private Animator playerAnim;
private ZNetView nview;
private string lastAttack;
private bool guarding;
private readonly TrolGuardPose guardPose = new TrolGuardPose();
private readonly FormLocomotion locomotion = new FormLocomotion();
private GameObject heldLog;
@ -438,6 +483,17 @@ namespace RacesOfValheim
ReplayAttack();
locomotion.Mirror(anim, playerAnim, player);
if (TrolTrueFormModel.ReadGuard(nview.GetZDO(), out string guardState, out float guardTime))
{
guardPose.Hold(anim, guardState, guardTime);
guarding = true;
}
else if (guarding)
{
guardPose.Release(anim);
guarding = false;
}
}
private void ReplayAttack()