1.0 compatibility
This commit is contained in:
parent
5104f86ede
commit
6193b3ee2d
33 changed files with 712 additions and 49 deletions
182
JotunnModStub/Aswid/AswidBatAggro.cs
Normal file
182
JotunnModStub/Aswid/AswidBatAggro.cs
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// Why nothing in Valheim ever attacked the bat, and the smallest honest fix for it.
|
||||
///
|
||||
/// The bat flies on Player.m_debugFly - the developer no-clip flag - because that is the only
|
||||
/// flight vanilla actually has, and it is what BatFormBehavior sets and WarVultureMount reuses.
|
||||
/// What nobody noticed is that vanilla reads that same flag as "this player is not really
|
||||
/// here". Six places, all read out of assembly_valheim with Cecil rather than guessed:
|
||||
///
|
||||
/// BaseAI.CanHearTarget - first line: the target is a Player in debug fly -> return false.
|
||||
/// BaseAI.CanSeeTarget - the same first line, the same false.
|
||||
/// BaseAI.FindEnemy - its HuntPlayer fallback throws the player away for the same reason.
|
||||
/// MonsterAI.UpdateSleep - a sleeping monster refuses to wake for one, twice over.
|
||||
/// Character.ApplyDamage - first line: IsDebugFlying -> return, the hit does nothing.
|
||||
/// Character.RPC_Damage - the same.
|
||||
///
|
||||
/// So the bat was never merely ignored: it was invulnerable as well, and both facts came out of
|
||||
/// the one flag. There was nothing wrong with the Aswid's own code, which is why nothing in it
|
||||
/// looked wrong.
|
||||
///
|
||||
/// The fix keeps the flag - it IS the flight - and lies about it in exactly the places that
|
||||
/// decide aggro and damage, and nowhere else:
|
||||
///
|
||||
/// Player.InDebugFlyMode() is forced false for a bat unconditionally. That is safe, and it is
|
||||
/// the reason this file is short: a scan of the whole assembly says that method has
|
||||
/// exactly three callers, and all three are the sensing paths listed above. No part of
|
||||
/// flight, camera, stamina or motion goes through it.
|
||||
/// Player.IsDebugFlying() is NOT forced false, because Character.UpdateMotion reads it and
|
||||
/// that read is what holds the bat in the air. It is only forced false while the call
|
||||
/// stack is inside one of the three vanilla methods that must not honour it, which is
|
||||
/// what the depth counter below is for.
|
||||
///
|
||||
/// Both halves sit behind their own config toggle, so a bat can be made visible-but-immortal,
|
||||
/// or put back the way it was, without touching code.
|
||||
/// </summary>
|
||||
public static class AswidBatForm
|
||||
{
|
||||
/// <summary>
|
||||
/// The ZDO flag AswidRace writes when the form goes up. Replicated, so it answers for
|
||||
/// remote players too - which matters here, because the machine asking "is this player a
|
||||
/// bat" is whichever one owns the monster, not the bat's own.
|
||||
/// </summary>
|
||||
public const string BatZdoKey = "Aswid_IsBatForm";
|
||||
|
||||
private static readonly int BatFormHash = "SE_BatForm".GetStableHashCode();
|
||||
|
||||
// How deep we currently are inside vanilla calls that must not see the debug-fly flag. A
|
||||
// counter and not a bool: ApplyDamage runs inside RPC_Damage, so the frames nest.
|
||||
private static int unmaskDepth;
|
||||
|
||||
public static bool Unmasked => unmaskDepth > 0;
|
||||
public static void PushUnmask() { unmaskDepth++; }
|
||||
public static void PopUnmask() { if (unmaskDepth > 0) unmaskDepth--; }
|
||||
|
||||
/// <summary>
|
||||
/// The ZDO first and the status effect only as a fallback: the ZDO is the one that is true
|
||||
/// on every client, and the status effect covers the local player during the frames of the
|
||||
/// transform where the ZDO write has not landed yet.
|
||||
/// </summary>
|
||||
public static bool IsBat(Player player)
|
||||
{
|
||||
if (player == null) return false;
|
||||
|
||||
ZNetView nview = player.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid() && nview.GetZDO().GetBool(BatZdoKey, false)) return true;
|
||||
|
||||
return player == Player.m_localPlayer &&
|
||||
player.GetSEMan() != null &&
|
||||
player.GetSEMan().HaveStatusEffect(BatFormHash);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The whole of the aggro fix. See AswidBatForm for why patching this one method flat is safe,
|
||||
/// and why patching IsDebugFlying flat would drop the bat out of the sky instead.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Player), "InDebugFlyMode")]
|
||||
public static class Aswid_BatIsVisibleToAI_Patch
|
||||
{
|
||||
public static void Postfix(Player __instance, ref bool __result)
|
||||
{
|
||||
if (!__result) return;
|
||||
if (AswidConfig.BatFormAggro != null && !AswidConfig.BatFormAggro.Value) return;
|
||||
if (AswidBatForm.IsBat(__instance)) __result = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The scoped half. Only ever fires inside the three vanilla methods that push the counter, and
|
||||
/// only for a player who is a bat - so the flag still reads true everywhere flight, motion, the
|
||||
/// camera and Player.UpdateStats look at it.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Player), "IsDebugFlying")]
|
||||
public static class Aswid_BatIsDebugFlying_Patch
|
||||
{
|
||||
public static void Postfix(Player __instance, ref bool __result)
|
||||
{
|
||||
if (!__result || !AswidBatForm.Unmasked) return;
|
||||
if (AswidBatForm.IsBat(__instance)) __result = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A hit landing on a bat. Finalizer rather than Postfix throughout this file: the counter has
|
||||
/// to come back down even when the patched method throws, and a Postfix does not run then. A
|
||||
/// void Finalizer leaves the original exception alone, so nothing is swallowed either.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Character), "ApplyDamage")]
|
||||
public static class Aswid_BatTakesDamage_Patch
|
||||
{
|
||||
public static void Prefix(Character __instance, ref bool __state)
|
||||
{
|
||||
__state = (AswidConfig.BatFormVulnerable == null || AswidConfig.BatFormVulnerable.Value)
|
||||
&& __instance is Player player && AswidBatForm.IsBat(player);
|
||||
if (__state) AswidBatForm.PushUnmask();
|
||||
}
|
||||
|
||||
public static void Finalizer(bool __state)
|
||||
{
|
||||
if (__state) AswidBatForm.PopUnmask();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The networked half of the same thing: a hit sent by another machine.</summary>
|
||||
[HarmonyPatch(typeof(Character), "RPC_Damage")]
|
||||
public static class Aswid_BatTakesRemoteDamage_Patch
|
||||
{
|
||||
public static void Prefix(Character __instance, ref bool __state)
|
||||
{
|
||||
__state = (AswidConfig.BatFormVulnerable == null || AswidConfig.BatFormVulnerable.Value)
|
||||
&& __instance is Player player && AswidBatForm.IsBat(player);
|
||||
if (__state) AswidBatForm.PushUnmask();
|
||||
}
|
||||
|
||||
public static void Finalizer(bool __state)
|
||||
{
|
||||
if (__state) AswidBatForm.PopUnmask();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sleepers. Unlike the two above this cannot pre-check who the player is - UpdateSleep picks
|
||||
/// the closest one itself, and that may be a remote bat - so the counter goes up for the whole
|
||||
/// call and the per-player test happens in the IsDebugFlying postfix, where it costs nothing:
|
||||
/// that postfix only runs at all for a character who is already flying.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(MonsterAI), "UpdateSleep")]
|
||||
public static class Aswid_BatWakesSleepers_Patch
|
||||
{
|
||||
public static void Prefix(ref bool __state)
|
||||
{
|
||||
__state = AswidConfig.BatFormAggro == null || AswidConfig.BatFormAggro.Value;
|
||||
if (__state) AswidBatForm.PushUnmask();
|
||||
}
|
||||
|
||||
public static void Finalizer(bool __state)
|
||||
{
|
||||
if (__state) AswidBatForm.PopUnmask();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dying as a bat only became possible with the patches above, and the revert path could not
|
||||
/// handle it: AswidRace.Update() returns early on IsDead(), so the coroutine that takes the
|
||||
/// form down never starts. The debug-fly flag would stay on and the ZDO would stay true, which
|
||||
/// is a respawned player floating over the ground with a bat drawn on them.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Player), "OnDeath")]
|
||||
public static class Aswid_BatDiesAsBat_Patch
|
||||
{
|
||||
public static void Prefix(Player __instance)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer) return;
|
||||
if (AswidRace.Instance == null) return;
|
||||
AswidRace.Instance.HardResetBatForm();
|
||||
}
|
||||
}
|
||||
}
|
||||
57
JotunnModStub/Aswid/AswidBatFlight.cs
Normal file
57
JotunnModStub/Aswid/AswidBatFlight.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -33,6 +33,14 @@ namespace RacesOfValheim
|
|||
public static ConfigEntry<float> BloodMagicSkillGainMultiplier;
|
||||
public static ConfigEntry<float> SurtlingFormDamageBonus;
|
||||
|
||||
// ─── Bat Form ────────────────────────────────────────────────────────────
|
||||
// Both of these undo something vanilla does to any player on the debug-fly flag, which is
|
||||
// what the bat flies on. See AswidBatAggro for the six vanilla methods involved.
|
||||
public static ConfigEntry<bool> BatFormAggro;
|
||||
public static ConfigEntry<bool> BatFormVulnerable;
|
||||
// A factor on vanilla's debug-fly speed, not a speed in metres - see AswidBatFlight.
|
||||
public static ConfigEntry<float> BatFormFlightSpeed;
|
||||
|
||||
// ─── Vampiric Aura (passive, always active) ──────────────────────────────
|
||||
public static ConfigEntry<float> AuraTickInterval;
|
||||
public static ConfigEntry<float> AuraRadiusDay;
|
||||
|
|
@ -122,6 +130,14 @@ namespace RacesOfValheim
|
|||
SurtlingFormDamageBonus = config.Bind(combat, "Surtling Form Damage Bonus", 30f,
|
||||
new ConfigDescription("Flat damage added to every attack once the tier 8 Surtling form is unlocked.", new AcceptableValueRange<float>(0f, 100f)));
|
||||
|
||||
const string batform = "Aswid - Bat Form";
|
||||
BatFormAggro = config.Bind(batform, "Monsters Notice The Bat", true,
|
||||
new ConfigDescription("Lets monsters see, hear and wake up for a player in Bat Form. Vanilla refuses to notice anyone flying on the debug-fly flag, which is the flag the form uses - turn this off to go back to a bat nothing ever looks at."));
|
||||
BatFormVulnerable = config.Bind(batform, "The Bat Can Be Hurt", true,
|
||||
new ConfigDescription("Lets damage land on a player in Bat Form. Same cause as the setting above: vanilla drops every hit on a debug-flying character. Turn this off for a bat that is noticed and chased but cannot be killed."));
|
||||
BatFormFlightSpeed = config.Bind(batform, "Flight Speed", 1f,
|
||||
new ConfigDescription("How fast the bat flies, as a multiplier on the game's own flight speed (20 m/s, and 2.5x that while the run key is held). 1 is untouched, 2 is twice as fast, 0.5 is half. Local only - it changes how your own bat moves, not anyone else's.", new AcceptableValueRange<float>(0.25f, 3f)));
|
||||
|
||||
const string aura = "Aswid - Vampiric Aura";
|
||||
AuraTickInterval = config.Bind(aura, "Tick Interval", 0.25f,
|
||||
new ConfigDescription("Seconds between aura damage/lifesteal ticks.", new AcceptableValueRange<float>(0.05f, 2f)));
|
||||
|
|
|
|||
|
|
@ -53,7 +53,9 @@ namespace RacesOfValheim
|
|||
|
||||
|
||||
|
||||
[HarmonyPatch(typeof(SEMan), "AddStatusEffect", new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float) })]
|
||||
// Valheim 1.0 appended a 'short variant' parameter to this overload. The type array has to
|
||||
// match it exactly or the patch silently fails to bind and PatchAll throws.
|
||||
[HarmonyPatch(typeof(SEMan), "AddStatusEffect", new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float), typeof(short) })]
|
||||
public static class AswidSEManPatch
|
||||
{
|
||||
public static bool Prefix(SEMan __instance, ref int nameHash)
|
||||
|
|
|
|||
|
|
@ -416,6 +416,17 @@ namespace RacesOfValheim
|
|||
{
|
||||
StartCoroutine(RevertMistFormRoutine());
|
||||
}
|
||||
|
||||
// Same rule for a night-only bat: a form the sun forbids cannot be kept through the
|
||||
// sunrise, or the daylight gate above would only be one night's patience away from
|
||||
// meaningless. activeRules is what the transform was actually granted under, so an
|
||||
// Aswid who has killed The Elder (NeedsNight false) keeps flying into the morning.
|
||||
if (IsTransformed && !isTransformingSequence && activeRules != null && activeRules.NeedsNight &&
|
||||
EnvMan.instance != null && EnvMan.IsDay())
|
||||
{
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "The morning sun drives the bat back into your body");
|
||||
StartCoroutine(RevertToHumanRoutine());
|
||||
}
|
||||
}
|
||||
|
||||
private string DumpGameObject(GameObject go, string indent)
|
||||
|
|
@ -509,6 +520,17 @@ namespace RacesOfValheim
|
|||
return;
|
||||
}
|
||||
|
||||
// The night gate lives here, not in GetGKeyRules: the rules only say WHETHER night is
|
||||
// required (state 2, Eikthyr) or not (state 3+, The Elder). Nothing ever read the
|
||||
// NeedsNight flag, so an Aswid who had only killed Eikthyr could turn into a bat in
|
||||
// broad daylight. Placed after the revert branch on purpose - a bat caught by the
|
||||
// sunrise must always be able to turn back.
|
||||
if (rules.NeedsNight && (EnvMan.instance == null || !EnvMan.IsNight()))
|
||||
{
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "The sun burns. You can only take bat form at night.");
|
||||
return;
|
||||
}
|
||||
|
||||
StartCoroutine(TransformIntoBatRoutine(rules));
|
||||
}
|
||||
|
||||
|
|
@ -524,6 +546,49 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Everything RevertToHumanRoutine does, minus the puff of smoke and the scale animation,
|
||||
/// and without a coroutine - because the one moment this exists for is death, and by then
|
||||
/// Update() has already bailed out on IsDead(), so a coroutine started here would be the
|
||||
/// only thing still running on a corpse.
|
||||
///
|
||||
/// Leaving the form up costs more than a missing animation: m_debugFly stays on, so the
|
||||
/// respawned player floats; Aswid_IsBatForm stays true in the ZDO, so every other client
|
||||
/// keeps drawing a bat over a body that is walking around as a person; and the 5% scale
|
||||
/// stays on the transform. Called from Aswid_BatDiesAsBat_Patch.
|
||||
/// </summary>
|
||||
public void HardResetBatForm()
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null) return;
|
||||
if (!IsTransformed && !isTransformingSequence) return;
|
||||
|
||||
if (currentTransformation != null)
|
||||
{
|
||||
Destroy(currentTransformation);
|
||||
currentTransformation = null;
|
||||
}
|
||||
|
||||
PlayerVisualHider.Show(player.transform.Find("Visual"), "aswid-bat-death-reset");
|
||||
|
||||
if (player.GetSEMan() != null)
|
||||
player.GetSEMan().RemoveStatusEffect("SE_BatForm".GetStableHashCode(), true);
|
||||
|
||||
ZNetView nview = player.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid())
|
||||
{
|
||||
nview.GetZDO().Set("Aswid_IsBatForm", false);
|
||||
nview.GetZDO().Set(ZDOVars.s_debugFly, false);
|
||||
}
|
||||
Traverse.Create(player).Field("m_debugFly").SetValue(false);
|
||||
|
||||
player.transform.localScale = Vector3.one;
|
||||
|
||||
IsTransformed = false;
|
||||
activeRules = null;
|
||||
isTransformingSequence = false;
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator TransformIntoBatRoutine(AswidProgression.FormRules rules)
|
||||
{
|
||||
isTransformingSequence = true;
|
||||
|
|
@ -961,7 +1026,7 @@ namespace RacesOfValheim
|
|||
|
||||
// Create an invisible virtual inventory so the food never goes to the real bag
|
||||
Inventory virtualInv = new Inventory("AswidStomach", null, 1, 1);
|
||||
ItemDrop.ItemData addedItem = virtualInv.AddItem(foodPrefab.name, 1, 1, 0, 0, "");
|
||||
ItemDrop.ItemData addedItem = virtualInv.AddItem(foodPrefab.name, 1, 1, 0, 0, "", false);
|
||||
|
||||
if (addedItem != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -151,6 +151,10 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
// New in Valheim 1.0: Hoverable gained this. Every vanilla implementation returns a
|
||||
// serialised m_hoverOffset, which is 0 unless the prefab sets one, so 0 is vanilla behaviour.
|
||||
public float GetHoverOffset() => 0f;
|
||||
|
||||
public string GetHoverName()
|
||||
{
|
||||
return ""; // Character component already provides the name
|
||||
|
|
|
|||
|
|
@ -1,10 +1,29 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using Jotunn.Managers;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// The bat's flight, held on for as long as the worn model exists.
|
||||
///
|
||||
/// Debug fly has two halves, and this used to write only one. The field Player.m_debugFly is
|
||||
/// what the local player's own physics reads; ZDOVars.s_debugFly is what every OTHER client
|
||||
/// reads, because Character.IsDebugFlying consults the ZDO whenever it is not the owner. With
|
||||
/// only the field written, a bat flew on its own screen and fell, walked and swam on everyone
|
||||
/// else's - the fault WarVultureMount.SetFlying already names in its own summary. Both halves
|
||||
/// go through SetFlying below now, so there is one place that can ever get it wrong again.
|
||||
///
|
||||
/// Writing the ZDO every frame is not network spam: ZDO.Set(int, bool) bottoms out in
|
||||
/// ZDOExtraData.Set, which returns false when the value is unchanged, and only a true return
|
||||
/// bumps the data revision. Read out of the assembly rather than assumed, because "every frame"
|
||||
/// deserved the check.
|
||||
/// </summary>
|
||||
public class BatFormBehavior : MonoBehaviour
|
||||
{
|
||||
private static readonly System.Reflection.FieldInfo DebugFlyField =
|
||||
AccessTools.Field(typeof(Player), "m_debugFly");
|
||||
|
||||
private Animator anim;
|
||||
private AswidProgression.FormRules formRules;
|
||||
|
||||
|
|
@ -16,10 +35,7 @@ namespace RacesOfValheim
|
|||
private void Start()
|
||||
{
|
||||
anim = GetComponentInChildren<Animator>();
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(true);
|
||||
}
|
||||
SetFlying(true);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
|
@ -27,7 +43,7 @@ namespace RacesOfValheim
|
|||
if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return;
|
||||
|
||||
// Ensure flight remains on continuously
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(true);
|
||||
SetFlying(true);
|
||||
|
||||
// Sync Animator
|
||||
if (anim != null)
|
||||
|
|
@ -35,7 +51,7 @@ namespace RacesOfValheim
|
|||
Vector3 vel = Player.m_localPlayer.GetVelocity();
|
||||
vel.y = 0f;
|
||||
float speed = vel.magnitude;
|
||||
|
||||
|
||||
// Bats don't necessarily have a complex animator like players,
|
||||
// but if they do have a speed or flying parameter, we set it here.
|
||||
anim.SetFloat("forward_speed", speed);
|
||||
|
|
@ -45,9 +61,25 @@ namespace RacesOfValheim
|
|||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (Player.m_localPlayer != null)
|
||||
SetFlying(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Both halves of debug fly, always together. The field write survives a missing or invalid
|
||||
/// ZNetView on purpose: without it a bat whose networking went away mid-flight would keep
|
||||
/// flying on foot forever, which is the worse of the two failures.
|
||||
/// </summary>
|
||||
private static void SetFlying(bool flying)
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null) return;
|
||||
|
||||
if (DebugFlyField != null) DebugFlyField.SetValue(player, flying);
|
||||
|
||||
ZNetView nview = player.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid() && nview.IsOwner())
|
||||
{
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(false);
|
||||
nview.GetZDO().Set(ZDOVars.s_debugFly, flying);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue