57 lines
2.7 KiB
C#
57 lines
2.7 KiB
C#
using HarmonyLib;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// How fast the bat flies, as a factor on vanilla's own debug-fly speed.
|
|
///
|
|
/// The form flies on Player.m_debugFly (see AswidBatForm for why), so its speed is whatever
|
|
/// Character.UpdateDebugFly decides. Read out of assembly_valheim rather than assumed, that
|
|
/// method ends with:
|
|
///
|
|
/// m_currentVel = Vector3.Lerp(m_currentVel, b, 0.5f);
|
|
/// m_body.linearVelocity = m_currentVel;
|
|
///
|
|
/// where b is m_moveDir times m_debugFlySpeed - a public STATIC INT, 20 by default, times 2.5
|
|
/// while the run key is held.
|
|
///
|
|
/// Two ways to make that faster were rejected before this one:
|
|
///
|
|
/// Retuning m_debugFlySpeed around the call. It is shared by every character in the game and
|
|
/// it is an int, so a 1.35x multiplier would land on 27 and a 1.37x on the same 27 - the
|
|
/// slider would move in 5% steps and would be writing a global while it did it.
|
|
///
|
|
/// Scaling m_currentVel itself, which is what WarVultureMount does for the bird. That field
|
|
/// is the input to the NEXT frame's lerp, so scaling it feeds back: with a factor s the
|
|
/// velocity settles at 0.5s/(1-0.5s) times vanilla, not s times it, and at s >= 2 it does
|
|
/// not settle at all.
|
|
///
|
|
/// So only the rigidbody is scaled, and m_currentVel is left exactly as vanilla wrote it. The
|
|
/// lerp keeps smoothing the same trajectory it always did - the ramp up, the ease off, the
|
|
/// standstill at zero input - and the bat simply covers it faster. Linear in the slider, with
|
|
/// nothing to accumulate.
|
|
/// </summary>
|
|
[HarmonyPatch(typeof(Character), "UpdateDebugFly")]
|
|
public static class Aswid_BatFlightSpeed_Patch
|
|
{
|
|
public static void Postfix(Character __instance, Vector3 ___m_currentVel, Rigidbody ___m_body)
|
|
{
|
|
// Bound from RacesOfValheim.Awake(), before harmony.PatchAll() - the null check is for
|
|
// the config that failed to bind at all, not for a race between the two.
|
|
if (AswidConfig.BatFormFlightSpeed == null) return;
|
|
|
|
float multiplier = AswidConfig.BatFormFlightSpeed.Value;
|
|
if (Mathf.Approximately(multiplier, 1f)) return;
|
|
|
|
// Local player only. Every other machine's bat moves on its replicated position, and
|
|
// scaling velocity here would fight that sync rather than help it.
|
|
Player player = __instance as Player;
|
|
if (player == null || player != Player.m_localPlayer) return;
|
|
if (___m_body == null) return;
|
|
if (!AswidBatForm.IsBat(player)) return;
|
|
|
|
___m_body.linearVelocity = ___m_currentVel * multiplier;
|
|
}
|
|
}
|
|
}
|