feat: Free Bat Flight, the old bat flight as a choice
The old bat flight is back as Free Flight: vanilla debug fly, up to 50 m/s, no stamina and no weight limit, Jump rises and Left Ctrl sinks. Each player picks it with Aswid - Bat Form / Free Bat Flight (local, never synced). The synced Bat Flight Rule (PlayerChoice, AlwaysStaminaFlight, AlwaysFreeFlight) lets the host or server decide for everyone. The mode is read when the form goes up, so a change counts from the next transform. Debug fly makes vanilla treat the player as absent: no monster sees, hears or wakes for them, and hits are dropped. The six patches removed in v1.6.1 are back in AswidBatForm, for bats only and with no switch, so a free bat is fast but not invisible or immortal. Turning flight off now clears both flags, so death and reset end either flight. The compendium shows the Free Flight line when it is the active mode. Asked for by MrBiffty, who builds tall with the bat.
This commit is contained in:
parent
fc5d6b8abc
commit
6f439f37c3
8 changed files with 176 additions and 23 deletions
|
|
@ -14,17 +14,25 @@ namespace RacesOfValheim
|
|||
///
|
||||
/// Other clients learn the bat is airborne from Aswid_IsBatForm in the ZDO, which
|
||||
/// Aswid_MultiplayerVisuals_Patch mirrors into their copy's m_flying.
|
||||
///
|
||||
/// FREE FLIGHT. A player who picks it (or a server that forces it, AswidConfig.UsesFreeBatFlight)
|
||||
/// gets the old flight back: vanilla's debug fly, both halves (the field for the local physics,
|
||||
/// s_debugFly in the ZDO for everyone else), and no DirectedFlight. The mode is read once, when
|
||||
/// the form goes up. AswidBatForm keeps monsters seeing and hurting a free-flying bat.
|
||||
/// </summary>
|
||||
public class BatFormBehavior : MonoBehaviour, IDirectedFlyer
|
||||
{
|
||||
private static readonly System.Reflection.FieldInfo FlyingField =
|
||||
AccessTools.Field(typeof(Character), "m_flying");
|
||||
private static readonly System.Reflection.FieldInfo DebugFlyField =
|
||||
AccessTools.Field(typeof(Player), "m_debugFly");
|
||||
|
||||
private Animator anim;
|
||||
private AswidProgression.FormRules formRules;
|
||||
private float startTime;
|
||||
private bool warnedTooHeavy;
|
||||
private bool expired;
|
||||
private bool free;
|
||||
|
||||
public void Initialize(AswidProgression.FormRules rules)
|
||||
{
|
||||
|
|
@ -73,8 +81,9 @@ namespace RacesOfValheim
|
|||
anim = GetComponentInChildren<Animator>();
|
||||
startTime = Time.time;
|
||||
LastPoweredTime = Time.time;
|
||||
DirectedFlight.Register(this);
|
||||
SetFlying(true);
|
||||
free = AswidConfig.UsesFreeBatFlight();
|
||||
if (!free) DirectedFlight.Register(this);
|
||||
Hold();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
|
@ -85,16 +94,20 @@ namespace RacesOfValheim
|
|||
// Held every frame rather than set once, for the same reason the debug-fly flag was:
|
||||
// anything that clears it mid-form (a vanilla reset, another mod) would drop the bat
|
||||
// into walking with the model still on.
|
||||
SetFlying(true);
|
||||
Hold();
|
||||
|
||||
if (!CanPower && !warnedTooHeavy)
|
||||
// Free Flight ignores weight, so only Stamina Flight warns about it.
|
||||
if (!free)
|
||||
{
|
||||
warnedTooHeavy = true;
|
||||
player.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_aswid_bat_too_heavy_to_beat"));
|
||||
}
|
||||
else if (CanPower)
|
||||
{
|
||||
warnedTooHeavy = false;
|
||||
if (!CanPower && !warnedTooHeavy)
|
||||
{
|
||||
warnedTooHeavy = true;
|
||||
player.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_aswid_bat_too_heavy_to_beat"));
|
||||
}
|
||||
else if (CanPower)
|
||||
{
|
||||
warnedTooHeavy = false;
|
||||
}
|
||||
}
|
||||
|
||||
float max = MaxDuration();
|
||||
|
|
@ -120,15 +133,37 @@ namespace RacesOfValheim
|
|||
SetFlying(false);
|
||||
}
|
||||
|
||||
private void Hold()
|
||||
{
|
||||
if (free) SetDebugFly(true);
|
||||
else SetFlying(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The local half of flight. The remote half is the Aswid_IsBatForm ZDO flag AswidRace
|
||||
/// already writes, so there is nothing to replicate here.
|
||||
/// The local half of Stamina Flight. The remote half is the Aswid_IsBatForm ZDO flag
|
||||
/// AswidRace already writes, so there is nothing to replicate here. Turning it off also
|
||||
/// turns debug fly off, so every exit path ends both flights whichever one was up.
|
||||
/// </summary>
|
||||
public static void SetFlying(bool flying)
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null || FlyingField == null) return;
|
||||
FlyingField.SetValue(player, flying);
|
||||
if (player == null) return;
|
||||
if (FlyingField != null) FlyingField.SetValue(player, flying);
|
||||
if (!flying) SetDebugFly(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Both halves of debug fly, for Free Flight. The ZDO write every frame is not network
|
||||
/// spam: ZDO.Set returns early when the value is unchanged.
|
||||
/// </summary>
|
||||
private static void SetDebugFly(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()) nview.GetZDO().Set(ZDOVars.s_debugFly, flying);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue