Rework Skadi dragon flight, enforce form duration, surface timers in HUD

Flight ran on the debug-fly noclip, so it ignored aim entirely and needed
Space/Ctrl for height. It now uses Character's native flying-creature
movement with the camera's full look direction fed in each frame:

- Aim steers, including climb and dive; W powers forward, releasing it
  holds level briefly and then settles into a glide instead of coasting
  along the aim vector (which let you climb forever without input).
- The body actually turns now. m_flyTurnSpeed sat at Character's 12 deg/s
  default because the Player prefab was never set up to fly, so a quarter
  turn took over seven seconds and read as no rotation at all.
- Touching down no longer slides you forward forever. Zeroing the fly
  speeds stops the character without fighting the AddForce UpdateFlying
  queues, which had caused frame-to-frame jitter and TAA ghosting.

DurationMinutes was never wired to anything, so timed forms never expired
and their cooldown, which only starts on reversion, was unreachable in
practice. Timed forms now drop on their own, and both the remaining time
and the cooldown show up beside the minimap as a Moder trophy icon.

Attack capability was snapshotted when the form was entered, so reaching
the Bonemass tier while already transformed left the drake unarmed until
the player reverted and transformed again; it is re-read live now.
This commit is contained in:
kanym 2026-07-31 16:25:06 +02:00
commit cccabe16ef
5 changed files with 193 additions and 21 deletions

View file

@ -6,11 +6,21 @@ namespace RacesOfValheim
{
public class DrakeFormBehavior : MonoBehaviour
{
// Single active instance, read by SkadiDirectedFlightPatch to feed a
// look-direction-based m_moveDir into Character.UpdateFlying every frame.
public static DrakeFormBehavior Active { get; private set; }
private Animator anim;
private bool isFlying = false;
private bool isLanding = false;
private float lastAttackTime = 0f;
public bool IsFlying => isFlying;
// Time.time of the last powered/grounded moment. SkadiDirectedFlightPatch holds the form
// level for a short window past this before letting it start sinking.
public float LastPoweredTime;
private SkadiProgression.FormRules formRules;
public void Initialize(SkadiProgression.FormRules rules)
@ -18,15 +28,37 @@ namespace RacesOfValheim
this.formRules = rules;
}
// formRules is a snapshot taken when the form was entered, so a progression change while
// still transformed (defeating a boss, or the increaseprogression debug command) wouldn't
// grant the attack until the player reverted and transformed again. Re-read the rules for
// the form we're currently in so the unlock applies as soon as the tier is reached.
private bool CanAttackNow()
{
if (formRules == null) return false;
int state = BossProgressionManager.GetCurrentProgressionState();
SkadiProgression.FormRules live = null;
switch (formRules.Form)
{
case SkadiProgression.FormType.Drake: live = SkadiProgression.GetGKeyRules(state); break;
case SkadiProgression.FormType.Moder: live = SkadiProgression.GetHKeyRules(state); break;
case SkadiProgression.FormType.SkeletonDragon: live = SkadiProgression.GetJKeyRules(state); break;
}
return live != null && live.Form == formRules.Form && live.CanAttackInForm;
}
private const float ATTACK_COST = 20f;
private const float ATTACK_COOLDOWN = 3f;
private void Start()
{
Active = this;
anim = GetComponentInChildren<Animator>();
if (Player.m_localPlayer != null)
{
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(false);
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(false);
}
}
@ -40,20 +72,22 @@ namespace RacesOfValheim
if (!isFlying && !isLanding)
{
isFlying = true;
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(true);
LastPoweredTime = Time.time;
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(true);
}
else if (isFlying && !isLanding)
{
isLanding = true;
isFlying = false;
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(false);
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(false);
}
else if (isLanding)
{
// Cancel landing, resume flight
isLanding = false;
isFlying = true;
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(true);
LastPoweredTime = Time.time;
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(true);
}
}
@ -88,7 +122,7 @@ namespace RacesOfValheim
}
// Handle Attack
if (formRules != null && formRules.CanAttackInForm)
if (CanAttackNow())
{
if (Input.GetMouseButtonDown(0))
{
@ -345,9 +379,10 @@ namespace RacesOfValheim
private void OnDestroy()
{
if (Active == this) Active = null;
if (Player.m_localPlayer != null)
{
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(false);
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(false);
}
}
}