Merge branch 'main' into localisation

This commit is contained in:
kanym 2026-10-17 19:07:01 +02:00
commit d28f9e353a
4 changed files with 103 additions and 18 deletions

View file

@ -422,7 +422,7 @@ namespace RacesOfValheim
// The same helper the local behaviours use, so both views of the same wolf agree.
// Player.IsCrouching answers off the animator's current state, which is replicated, so
// it is true here too.
locomotion.Mirror(formAnim, playerAnim, player.IsCrouching());
locomotion.Mirror(formAnim, playerAnim, player);
}
// Written every frame while the flag is set, and only when the controller has the bool: a
@ -514,7 +514,10 @@ namespace RacesOfValheim
private readonly FormLocomotion locomotion = new FormLocomotion();
private float busySince = -1f;
private bool isAttacking = false;
// A property so every form tells FenrirForms.LocalAttacking too: Fenrir_FormHoldStill_Patch
// holds the player still for exactly as long as an attack clip runs.
private bool attacking;
private bool isAttacking { get => attacking; set { attacking = value; FenrirForms.LocalAttacking = value; } }
void Start()
{
@ -539,7 +542,7 @@ namespace RacesOfValheim
// Meglio continuare a sincronizzare i movimenti base.
if (!isAttacking)
{
bool isGrounded = locomotion.Mirror(fenrirAnim, playerAnim, Player.m_localPlayer.IsCrouching());
bool isGrounded = locomotion.Mirror(fenrirAnim, playerAnim, Player.m_localPlayer);
if (isGrounded && RaceInput.Allowed)
{
@ -766,7 +769,10 @@ namespace RacesOfValheim
private readonly FormLocomotion locomotion = new FormLocomotion();
private float busySince = -1f;
private bool isAttacking = false;
// A property so every form tells FenrirForms.LocalAttacking too: Fenrir_FormHoldStill_Patch
// holds the player still for exactly as long as an attack clip runs.
private bool attacking;
private bool isAttacking { get => attacking; set { attacking = value; FenrirForms.LocalAttacking = value; } }
private bool isShootingFire = false;
private float fireTimer = 0f;
@ -790,7 +796,7 @@ namespace RacesOfValheim
if (!isAttacking)
{
// Se tiene premuto Ctrl (Crouch), ferma il movimento per preparare l'attacco
bool isGrounded = locomotion.Mirror(cultistAnim, playerAnim, Player.m_localPlayer.IsCrouching());
bool isGrounded = locomotion.Mirror(cultistAnim, playerAnim, Player.m_localPlayer);
if (isGrounded)
{
@ -1150,7 +1156,10 @@ namespace RacesOfValheim
private Animator wolfAnim;
private readonly FormLocomotion locomotion = new FormLocomotion();
private float busySince = -1f;
private bool isAttacking = false;
// A property so every form tells FenrirForms.LocalAttacking too: Fenrir_FormHoldStill_Patch
// holds the player still for exactly as long as an attack clip runs.
private bool attacking;
private bool isAttacking { get => attacking; set { attacking = value; FenrirForms.LocalAttacking = value; } }
void Start()
{
@ -1172,7 +1181,7 @@ namespace RacesOfValheim
if (!isAttacking)
{
bool isGrounded = locomotion.Mirror(wolfAnim, playerAnim, Player.m_localPlayer.IsCrouching());
bool isGrounded = locomotion.Mirror(wolfAnim, playerAnim, Player.m_localPlayer);
if (isGrounded && RaceInput.Allowed)
{
@ -1363,7 +1372,10 @@ namespace RacesOfValheim
private readonly FormLocomotion locomotion = new FormLocomotion();
private float busySince = -1f;
private bool isAttacking = false;
// A property so every form tells FenrirForms.LocalAttacking too: Fenrir_FormHoldStill_Patch
// holds the player still for exactly as long as an attack clip runs.
private bool attacking;
private bool isAttacking { get => attacking; set { attacking = value; FenrirForms.LocalAttacking = value; } }
void Start()
{
@ -1384,7 +1396,7 @@ namespace RacesOfValheim
if (!isAttacking)
{
bool isGrounded = locomotion.Mirror(ulvAnim, playerAnim, Player.m_localPlayer.IsCrouching());
bool isGrounded = locomotion.Mirror(ulvAnim, playerAnim, Player.m_localPlayer);
if (isGrounded && RaceInput.Allowed)
{

View file

@ -14,6 +14,10 @@ namespace RacesOfValheim
/// SE_FenrirForm and the Cultist SE_CultistForm. Checking only SE_FenrirForm, as the attack
/// block used to, left three of the four forms out.
/// </summary>
/// <summary>True while the local form is inside an attack, a howl or a breath. Cleared by the
/// form's own routines, and on every revert.</summary>
public static bool LocalAttacking { get; set; }
public static bool LocalInForm(Character character)
{
if (character == null || character != Player.m_localPlayer) return false;
@ -40,25 +44,68 @@ namespace RacesOfValheim
private float airborneFor;
// Whether this form's controller has a "sleeping" bool, asked once per Animator: MonsterAI
// drives the creature's own sleep through it, and not every creature has one.
private Animator sleepChecked;
private bool hasSleeping;
private static readonly System.Collections.Generic.HashSet<string> sleepLogged = new System.Collections.Generic.HashSet<string>();
/// <summary>Copies the movement parameters, and says whether the form counts as grounded.</summary>
public bool Mirror(Animator form, Animator player, bool crouching)
public bool Mirror(Animator form, Animator playerAnim, Player player)
{
bool touching = player.GetBool("onGround");
bool touching = playerAnim.GetBool("onGround");
airborneFor = touching ? 0f : airborneFor + Time.deltaTime;
bool grounded = airborneFor <= AirborneGrace;
// try/catch as the behaviours always did it: a controller missing one of these must not
// throw once per frame.
try { form.SetBool("onGround", grounded); } catch {}
try { form.SetBool("inWater", player.GetBool("inWater")); } catch {}
try { form.SetBool("inWater", playerAnim.GetBool("inWater")); } catch {}
// Airborne and crouching both read as standing still, as before.
bool still = !grounded || crouching;
try { form.SetFloat("forward_speed", still ? 0f : player.GetFloat("forward_speed")); } catch {}
try { form.SetFloat("sideway_speed", still ? 0f : player.GetFloat("sideway_speed")); } catch {}
// Only airborne reads as standing still now. Crouching used to as well, so a player
// sneaking in a form slid across the ground in the idle pose. Crouched, the player moves
// at sneaking speed, and the creature's controller picks its walk for a speed that low:
// the sneak a player asked for, from animations the creature already has.
try { form.SetFloat("forward_speed", grounded ? playerAnim.GetFloat("forward_speed") : 0f); } catch {}
try { form.SetFloat("sideway_speed", grounded ? playerAnim.GetFloat("sideway_speed") : 0f); } catch {}
// Sitting puts the creature to sleep, on the "sleeping" bool its own MonsterAI uses - the
// Ulv curls up. IsSitting reads the animator's state, which is replicated, so it is right
// for an onlooker's copy too.
if (sleepChecked != form)
{
sleepChecked = form;
hasSleeping = false;
foreach (AnimatorControllerParameter p in form.parameters)
{
if (p.type == AnimatorControllerParameterType.Bool && p.name == "sleeping") { hasSleeping = true; break; }
}
string controller = form.runtimeAnimatorController != null ? form.runtimeAnimatorController.name : form.name;
if (sleepLogged.Add(controller))
{
Jotunn.Logger.LogInfo($"[FenrirForm] '{controller}' {(hasSleeping ? "has" : "has no")} sleeping animation; " +
(hasSleeping ? "sitting puts it to sleep." : "sitting keeps it idle."));
}
}
if (hasSleeping) form.SetBool("sleeping", IsSitting(player));
return grounded;
}
/// <summary>
/// The sit key, or a chair. The sit key is an EMOTE, not the "sitting" animator tag that
/// Humanoid.IsSitting asks about - that tag belongs to chairs and benches - so IsSitting alone
/// never saw it and the Ulv stayed on its feet. Player.StartEmote writes the emote's name on the
/// ZDO, which every client reads, so this is right for an onlooker's copy as well.
/// </summary>
private static bool IsSitting(Player player)
{
if (player == null) return false;
if (player.IsSitting()) return true;
ZNetView nview = player.GetComponent<ZNetView>();
return nview != null && nview.IsValid() && nview.GetZDO().GetString(ZDOVars.s_emote, "") == "sit";
}
}
/// <summary>
@ -187,4 +234,28 @@ namespace RacesOfValheim
Jotunn.Logger.LogInfo($"[FenrirForm] {form} swing: {candidates} collider(s) in reach.");
}
}
/// <summary>
/// Holds the player still through a form's attack clips, the way a human stands to swing. The
/// hidden player kept walking under the creature, so the bite slid toward whatever WASD held.
/// SkeletonRiseControlsPatch's arrangement: the move direction is SetControls' first argument,
/// bound by position. The Fenring's and the Ulv's leaps move the body directly and are untouched.
/// </summary>
[HarmonyLib.HarmonyPatch(typeof(Player), "SetControls")]
public static class Fenrir_FormHoldStill_Patch
{
public static void Prefix(Player __instance, ref Vector3 __0, ref bool jump, ref bool crouch, ref bool dodge)
{
if (__instance != Player.m_localPlayer || !FenrirForms.LocalAttacking) return;
if (!FenrirForms.LocalInForm(__instance))
{
FenrirForms.LocalAttacking = false;
return;
}
__0 = Vector3.zero;
jump = false;
crouch = false;
dodge = false;
}
}
}

View file

@ -300,6 +300,7 @@ namespace RacesOfValheim {
player.GetSEMan().RemoveStatusEffect("SE_WolfForm".GetStableHashCode());
}
FenrirForms.LocalAttacking = false;
isTransformed = false;
isTransformingSequence = false;
activeRules = null;
@ -575,6 +576,7 @@ namespace RacesOfValheim {
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_CultistForm".GetStableHashCode());
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_WolfForm".GetStableHashCode());
FenrirForms.LocalAttacking = false;
isTransformed = false;
Player.m_localPlayer.Message(MessageHud.MessageType.Center, revertMessage ?? ModText.Get("rov_msg_fenrir_returned_human_form"));
revertMessage = null;

View file

@ -86,7 +86,7 @@ namespace RacesOfValheim
if (isAttacking || player.IsDead()) return;
bool grounded = locomotion.Mirror(anim, playerAnim, player.IsCrouching());
bool grounded = locomotion.Mirror(anim, playerAnim, player);
if (!grounded || !RaceInput.Allowed) return;
bool log = heldLogName != null;
@ -437,7 +437,7 @@ namespace RacesOfValheim
TrolTrueFormModel.UpdateHeldLog(gameObject, rightPrefab, ref heldLog, ref heldLogName);
ReplayAttack();
locomotion.Mirror(anim, playerAnim, player.IsCrouching());
locomotion.Mirror(anim, playerAnim, player);
}
private void ReplayAttack()