The bat flew on vanilla's debug-fly flag: 50 m/s, free, blind to carry weight, and invisible to monsters until six patches lied about the flag. It now flies on m_flying with the drake's controls, moved out of SkadiPatches into a shared DirectedFlight core that both forms feed their own numbers into. Powered flight and the sprint cost stamina; out of stamina the bat glides. Encumbered flight costs 15% more, or is blocked with 'While Encumbered'. Optional duration and cooldown, off by default. The aggro/damage patches, the debug-fly speed patch and their three settings are removed; the drake's behaviour is unchanged.
59 lines
2.4 KiB
C#
59 lines
2.4 KiB
C#
using HarmonyLib;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// Whether a player is a bat, on any client.
|
|
///
|
|
/// This file used to be AswidBatAggro: while the bat flew on vanilla's debug-fly flag, vanilla
|
|
/// read that flag as "this player is not really here" - no monster could see, hear or wake for
|
|
/// it, and every hit on it was dropped - and six patches here lied about the flag in exactly
|
|
/// those places. The bat now flies on m_flying (DirectedFlight.cs), which vanilla's AI and
|
|
/// damage never look at, so monsters notice and hurt it with no help, and the lie went.
|
|
/// </summary>
|
|
public static class AswidBatForm
|
|
{
|
|
/// <summary>
|
|
/// The ZDO flag AswidRace writes when the form goes up. Replicated, so it answers for
|
|
/// remote players too.
|
|
/// </summary>
|
|
public const string BatZdoKey = "Aswid_IsBatForm";
|
|
|
|
private static readonly int BatFormHash = "SE_BatForm".GetStableHashCode();
|
|
|
|
/// <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 revert path cannot handle a bat that dies: AswidRace.Update() returns early on IsDead(),
|
|
/// so the coroutine that takes the form down never starts. The flight 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();
|
|
}
|
|
}
|
|
}
|