fix(sverm): the Ravager stands still to attack and its slam digs

The hidden player kept walking under the costume, so every swing slid
toward whatever WASD held. A SetControls prefix holds it still while an
attack runs, as Fenrir and the True Form troll do. The middle-click slam
now digs a crater on bare terrain (digg_v3), never inside a ward without
access, behind a new Ground Slam Crater option.
This commit is contained in:
kanym 2026-10-17 19:51:33 +02:00
commit 1c2da77603
2 changed files with 64 additions and 5 deletions

View file

@ -45,6 +45,7 @@ namespace RacesOfValheim
public static ConfigEntry<float> RavagerScaleMultiplier;
public static ConfigEntry<float> RavagerYawDegrees;
public static ConfigEntry<float> RavagerAttackOffsetValue;
public static ConfigEntry<bool> RavagerSlamCraterValue;
// ─── Colony caps ─────────────────────────────────────────────────────
// Every ceiling on how many things the colony can have alive at once, in one section, so
@ -226,6 +227,10 @@ namespace RacesOfValheim
"Raise it if a swing visibly connects short of the model's mouth/claws; lower it " +
"if it connects well past them.");
RavagerSlamCraterValue = config.Bind(ravager, "Ground Slam Crater", true,
"The middle-click slam digs into the ground where it lands, like a pickaxe blow. " +
"Never inside a ward you have no access to.");
EmberGlowStrength = config.Bind(ember, "Glow Strength", SvermConfig.EmberGlowStrength,
"How hot the chitin burns at Fader. This multiplies an HDR colour and it is applied " +
"to the chest, the legs and the helmet at once, so it goes a very long way. Settled " +
@ -358,6 +363,7 @@ namespace RacesOfValheim
public static float RavagerScale => RavagerScaleMultiplier?.Value ?? 1f;
public static float RavagerYaw => RavagerYawDegrees?.Value ?? 0f;
public static float RavagerAttackOffset => RavagerAttackOffsetValue?.Value ?? 1.5f;
public static bool RavagerSlamCrater => RavagerSlamCraterValue?.Value ?? true;
public static bool Spines => SpinesEnabled?.Value ?? false;
public static float SizeSmall => SpineSizeSmall?.Value ?? SvermConfig.SpineSizeSmall;

View file

@ -28,6 +28,10 @@ namespace RacesOfValheim
{
public static bool IsActive { get; private set; }
/// <summary>True while the local Brute is inside a swing or the roar.
/// Sverm_RavagerHoldStill_Patch holds the player still for exactly that long.</summary>
public static bool LocalAttacking { get; set; }
// Read by Sverm_RavagerRemoteVisuals_Patch (SvermPatches.cs) so every other client can
// tell the form is up at all - without this the whole thing was local-only, exactly like
// DrakeFormBehavior's flight flag and Fenrir's own form key, and other players saw nothing
@ -302,6 +306,7 @@ namespace RacesOfValheim
private static void Exit(Player player, bool spendCooldown)
{
IsActive = false;
LocalAttacking = false;
ZNetView exitNview = player.GetComponent<ZNetView>();
if (exitNview != null && exitNview.IsValid()) exitNview.GetZDO().Set(ActiveKey, false);
@ -471,6 +476,30 @@ namespace RacesOfValheim
/// equipped never swings and never deals damage while this is up; RavagerFormBehavior's
/// own coroutines are the only thing that can land a hit.
/// </summary>
/// <summary>
/// Holds the Brute still through its attack clips, the way Fenrir_FormHoldStill_Patch and
/// Trol_TrueFormHoldStill_Patch do for their forms. The hidden player kept walking under the
/// costume, so a bite or a slam slid toward whatever WASD held.
/// </summary>
[HarmonyPatch(typeof(Player), "SetControls")]
public static class Sverm_RavagerHoldStill_Patch
{
public static void Prefix(Player __instance, ref Vector3 __0, ref bool jump, ref bool crouch, ref bool dodge)
{
if (__instance != Player.m_localPlayer || !LocalAttacking) return;
if (!IsActive)
{
LocalAttacking = false;
return;
}
__0 = Vector3.zero;
jump = false;
crouch = false;
dodge = false;
}
}
[HarmonyPatch(typeof(Humanoid), "StartAttack")]
public static class Sverm_RavagerBlockNativeAttack_Patch
{
@ -545,7 +574,8 @@ namespace RacesOfValheim
// gate FenrirFormBehavior's own isAttacking flag uses, and the direct answer to "the
// animation has to finish before the Brute can move": nothing here can start moving the
// model again, or start a second attack, until the coroutine below clears it.
private bool isAttacking;
private bool isAttacking { get => attacking; set { attacking = value; SvermRavagerForm.LocalAttacking = value; } }
private bool attacking;
// The taunt's own cooldown - short, and tracked separately from the other three, which
// have no cooldown of their own beyond their own lock duration.
@ -655,15 +685,15 @@ namespace RacesOfValheim
// be the only reliable option.
if (RaceInput.AttackDown(1))
{
StartCoroutine(AttackRoutine(SvermRavagerAttacks.Ram, 2f, 0.3f, 0.7f));
StartCoroutine(AttackRoutine(SvermRavagerAttacks.Ram, 2f, 0.3f, 0.7f, false));
}
else if (RaceInput.AttackDown(0))
{
StartCoroutine(AttackRoutine(SvermRavagerAttacks.Bite, 2f, 0.3f, 0.6f));
StartCoroutine(AttackRoutine(SvermRavagerAttacks.Bite, 2f, 0.3f, 0.6f, false));
}
else if (RaceInput.AttackDown(2))
{
StartCoroutine(AttackRoutine(SvermRavagerAttacks.Slam, 1.2f, 0.4f, 1.0f));
StartCoroutine(AttackRoutine(SvermRavagerAttacks.Slam, 1.2f, 0.4f, 1.0f, true));
}
else if ((SvermConfigManagement.RavagerKey.Value.IsDown() ||
RaceInput.ConsumePress(SvermConfigManagement.RavagerKey.Value)) && Time.time >= nextTauntAt)
@ -680,7 +710,7 @@ namespace RacesOfValheim
/// (SvermRavagerAttacks) instead of one tuned float.
/// </summary>
private System.Collections.IEnumerator AttackRoutine(SvermRavagerAttacks.Profile profile, float radius,
float hitDelay, float lockDuration)
float hitDelay, float lockDuration, bool digs)
{
isAttacking = true;
@ -695,6 +725,7 @@ namespace RacesOfValheim
yield return new WaitForSeconds(hitDelay);
ExecuteDamage(profile, radius);
if (digs) DigCrater();
float remaining = lockDuration - hitDelay;
if (remaining > 0f) yield return new WaitForSeconds(remaining);
@ -768,6 +799,28 @@ namespace RacesOfValheim
ApplyDamageInSphere(attackPoint, radius, profile.Damage);
}
private const string CraterPrefab = "digg_v3";
private static readonly int GroundMask = LayerMask.GetMask("terrain", "Default", "static_solid", "piece");
/// <summary>
/// The slam digs where it lands, the way the True Form troll's does (TrolTrueFormBehavior.Slam):
/// a pickaxe's dig on bare terrain only. TerrainOp does not check wards on its own, so the
/// ward check is done here.
/// </summary>
private static void DigCrater()
{
Player player = Player.m_localPlayer;
if (player == null || !SvermConfigManagement.RavagerSlamCrater) return;
Vector3 impact = player.transform.position + player.transform.forward * SvermConfigManagement.RavagerAttackOffset;
if (!Physics.Raycast(impact + Vector3.up * 3f, Vector3.down, out RaycastHit ground, 8f, GroundMask)) return;
if (ground.collider == null || ground.collider.GetComponent<Heightmap>() == null) return;
if (!PrivateArea.CheckAccess(ground.point, 0f, false)) return;
GameObject crater = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(CraterPrefab);
if (crater != null) Object.Instantiate(crater, ground.point, Quaternion.identity);
}
/// <summary>
/// The actual sweep, shared by every attack this form has (the three forward swings and
/// the taunt's own AoE) - only the sphere's centre and radius differ between them.