diff --git a/.gitignore b/.gitignore index afd519a..d5d2cff 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,9 @@ temp_test_zip/ test_extract/ *.dll +# Release packaging output - a Release build drops the Thunderstore and Nexus zips here. +/dist/ + # OS generated files .DS_Store Thumbs.db diff --git a/JotunnModStub/Fenrir/FenrirRace.cs b/JotunnModStub/Fenrir/FenrirRace.cs index d217328..fc2e349 100644 --- a/JotunnModStub/Fenrir/FenrirRace.cs +++ b/JotunnModStub/Fenrir/FenrirRace.cs @@ -329,7 +329,12 @@ namespace RacesOfValheim { if (prefab != null && playerVisual != null) { - playerVisual.localScale = Vector3.one * 0.001f; + // Shrinking the Visual to nothing was how this hid the human body, and it stopped + // working: the scale reset that keeps a non-Trol player at normal size runs from a + // postfix on this same update and puts it straight back to 1, so the man reappeared + // standing inside his own wolf. Hide the renderers instead - that is what Skadi and + // the Aswid already do, and nothing resets it. + PlayerVisualHider.Hide(playerVisual, "fenrir-local-form"); Transform visual = prefab.transform.Find("Visual"); if (visual != null) @@ -409,11 +414,9 @@ namespace RacesOfValheim { nview.GetZDO().Set("RacesOfValheim_FenrirForm", ""); } - if (playerVisual != null) - { - playerVisual.localScale = Vector3.one; - playerVisual.gameObject.SetActive(true); - } + // Show undoes the scale and the SetActive of the older hiding paths as well, so a form + // entered before this change still reverts cleanly. + PlayerVisualHider.Show(playerVisual, "fenrir-local-revert"); Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_FenrirForm".GetStableHashCode()); Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_CultistForm".GetStableHashCode()); diff --git a/JotunnModStub/RaceCompendium.cs b/JotunnModStub/RaceCompendium.cs index c827de8..4030117 100644 --- a/JotunnModStub/RaceCompendium.cs +++ b/JotunnModStub/RaceCompendium.cs @@ -257,7 +257,7 @@ namespace RacesOfValheim if (state >= 3) { sb.AppendLine("[The Elder Unlock] Drake Form ('G' Key):"); - sb.AppendLine("Take the shape of a frost drake. Right Mouse lifts you into flight: you glide wherever you aim, hold W to climb and gather speed, and release to hold level a moment before settling into a slow descent. In this shape you cannot yet strike.\n"); + sb.AppendLine("Take the shape of a frost drake. Right Mouse lifts you into flight: you glide wherever you aim, hold W to climb and gather speed, hold Shift with it to spend stamina on a burst of speed, and press S to beat backwards along your aim while your gaze stays where it was. Release everything and you hold level for five seconds before settling into a slow descent. Water cannot hold you - your wings drag you free of the sea as readily as they lift you from the shore. In this shape you cannot yet strike.\n"); } if (state >= 4) diff --git a/JotunnModStub/RacesOfValheim.csproj b/JotunnModStub/RacesOfValheim.csproj index 16e98a7..2487ffe 100644 --- a/JotunnModStub/RacesOfValheim.csproj +++ b/JotunnModStub/RacesOfValheim.csproj @@ -34,6 +34,9 @@ ..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Valheim\valheim_Data\Managed\assembly_valheim.dll + + @@ -52,15 +55,40 @@ + + + + C:\Program Files (x86)\Steam\steamapps\common\Valheim + $(VALHEIM_INSTALL)\BepInEx $(VALHEIM_INSTALL)/valheim_Data/Managed + + true + + $(BEPINEX_PATH)\plugins $(ProjectDir)..\ $(REPO_ROOT)JotunnModStubUnity + + false @@ -94,7 +122,15 @@ - + + + + + + + + @@ -102,13 +138,11 @@ $(REPO_ROOT)dist\ - + - - diff --git a/JotunnModStub/Skadi/SkadiPatches.cs b/JotunnModStub/Skadi/SkadiPatches.cs index 5652033..88cce4b 100644 --- a/JotunnModStub/Skadi/SkadiPatches.cs +++ b/JotunnModStub/Skadi/SkadiPatches.cs @@ -1,3 +1,4 @@ +using System.Reflection; using HarmonyLib; using UnityEngine; @@ -244,32 +245,64 @@ namespace RacesOfValheim // move direction. Character.UpdateFlying normally reads whatever m_moveDir the vanilla input // pipeline last wrote (ground-plane WASD relative to camera yaw only); this patch overwrites // it every frame with the camera's actual look direction (pitch included) so the player always - // glides toward wherever the mouse is aiming, with W adding a speed boost (m_run) on top of the - // base glide speed instead of being required just to move. + // glides toward wherever the mouse is aiming, with W powering forward, Shift spending stamina + // for a burst of speed, and S beating backwards away from whatever you are looking at. [HarmonyPatch(typeof(Character), "UpdateFlying")] public static class SkadiDirectedFlightPatch { private const float TURN_SPEED = 120f; private const float GLIDE_SPEED = 5f; private const float BOOST_SPEED = 12f; - private const float HOVER_SECONDS = 2f; + private const float SPRINT_SPEED = 22f; + private const float REVERSE_SPEED = 7f; + // Climbing out of water is deliberately slower than a powered climb in open air - the + // wings are dragging themselves free, not racing. + private const float LIFTOFF_SPEED = 9f; + private const float HOVER_SECONDS = 5f; + // Per second, drained only while the sprint is actually being granted. + private const float SPRINT_STAMINA_PER_SECOND = 15f; // Tangent of the unpowered descent angle: 0.4 sinks at roughly 22 degrees below level. private const float DESCENT_SLOPE = 0.4f; + // How much of the aim heading survives the climb out of water. Mostly up, with enough + // forward in it that the player still chooses which shore they surface towards. + private const float LIFTOFF_HEADING_BLEND = 0.35f; - public static void Prefix(Character __instance) + /// + /// True while the local player is beating backwards this frame. Read by + /// SkadiReverseFacingPatch, which keeps the body pointed at the camera while it happens. + /// + public static bool Reversing { get; private set; } + + public static void Prefix(Character __instance, float dt) { if (__instance != Player.m_localPlayer) return; DrakeFormBehavior form = DrakeFormBehavior.Active; - if (form == null || !form.IsFlying) return; + if (form == null || !form.IsFlying) + { + Reversing = false; + return; + } var traverse = Traverse.Create(__instance); Vector3 lookDir = Player.m_localPlayer.GetLookDir(); - bool boost = RaceInput.Allowed && Input.GetKey(KeyCode.W); + bool input = RaceInput.Allowed; + bool forward = input && Input.GetKey(KeyCode.W); + // Forward wins a W+S mash rather than the two cancelling into a dead hover. + bool backward = input && !forward && Input.GetKey(KeyCode.S); + bool sprintKey = input && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)); bool onGround = __instance.IsOnGround(); + // IsSwimming is the exact test UpdateMotion uses to hand the frame to UpdateSwimming + // instead of UpdateFlying, so it is also the one condition SkadiWaterFlightPatch has + // to take back. Its half-second tail past leaving the water is welcome here - it + // keeps the climb going just long enough to clear the surface properly. + bool inWater = __instance.IsSwimming(); - traverse.Field("m_run").SetValue(boost); - traverse.Field("m_flyFastSpeed").SetValue(BOOST_SPEED); + Reversing = backward; + + // m_run only picks between the two fly speeds. Every mode now has its own speed, so + // leave it off and drive all of them through m_flySlowSpeed. + traverse.Field("m_run").SetValue(false); // UpdateFlying rotates the body toward m_moveDir on its own, but at m_flyTurnSpeed, // which sits at Character's 12 deg/s default because the Player prefab was never set @@ -277,38 +310,145 @@ namespace RacesOfValheim // model reads as not turning at all. Give it a speed that suits a flying mount. traverse.Field("m_flyTurnSpeed").SetValue(TURN_SPEED); - // Powered flight and ground contact both refresh the hover window. - if (boost || onGround) form.LastPoweredTime = Time.time; + // Powered flight, ground contact and clawing out of water all refresh the hover + // window, so none of them can be followed by an immediate sink. + if (forward || backward || onGround || inWater) form.LastPoweredTime = Time.time; Vector3 moveDir = lookDir; - float coastSpeed; + float speed; - if (onGround || Time.time - form.LastPoweredTime < HOVER_SECONDS) + if (inWater) + { + // Wet wings still beat. Water used to be a trap: UpdateMotion hands a swimming + // character to UpdateSwimming before it ever looks at m_flying, so a dragon that + // touched the sea was stuck paddling with the flight controls doing nothing. + // SkadiWaterFlightPatch gives the frame back to flight, and this branch spends it + // climbing regardless of where the camera points, so the surface is always + // something you break out of rather than something you sit in. + moveDir = (Vector3.up + FlatHeading(__instance, lookDir) * LIFTOFF_HEADING_BLEND).normalized; + speed = LIFTOFF_SPEED; + } + else if (backward) + { + // Straight reverse thrust along the aim, pitch included: look down and beat back + // and you rise away from what you are looking at, which is the whole point of + // having a reverse - you can retreat without taking your eyes (or your breath + // attack, which fires along the same vector) off the target. + moveDir = -lookDir; + speed = REVERSE_SPEED; + } + else if (forward) + { + speed = BOOST_SPEED; + // The sprint is the only part of flight that costs anything. Base flight stays + // free on purpose - the drake arrives at the Elder, long before the player has + // the stamina pool to pay for simply staying airborne. + if (sprintKey && TrySpendSprintStamina(dt)) speed = SPRINT_SPEED; + } + else if (onGround || Time.time - form.LastPoweredTime < HOVER_SECONDS) { // Holding station: on the ground this keeps a touchdown from sliding the player - // forward forever, and in the air it gives the beat of level flight before the + // forward forever, and in the air it gives the beats of level flight before the // form starts to sink. m_moveDir stays full length so the body still turns to // face the camera, and zeroing the speed (rather than the rigidbody velocity) // avoids fighting the AddForce UpdateFlying queues, which caused visible jitter. - coastSpeed = 0f; + speed = 0f; } else { // Unpowered flight is a glide, not a hover with a joystick: drift along the // heading the camera faces while losing height, so aiming at the sky without // holding W no longer climbs. - Vector3 heading = new Vector3(lookDir.x, 0f, lookDir.z); - if (heading.sqrMagnitude < 0.0001f) - { - heading = __instance.transform.forward; - heading.y = 0f; - } - moveDir = (heading.normalized + Vector3.down * DESCENT_SLOPE).normalized; - coastSpeed = GLIDE_SPEED; + moveDir = (FlatHeading(__instance, lookDir) + Vector3.down * DESCENT_SLOPE).normalized; + speed = GLIDE_SPEED; } traverse.Field("m_moveDir").SetValue(moveDir); - traverse.Field("m_flySlowSpeed").SetValue(coastSpeed); + traverse.Field("m_flySlowSpeed").SetValue(speed); + } + + /// Aim flattened onto the ground plane, falling back to the body's own facing + /// when the player is looking straight up or down. + private static Vector3 FlatHeading(Character character, Vector3 lookDir) + { + Vector3 heading = new Vector3(lookDir.x, 0f, lookDir.z); + if (heading.sqrMagnitude < 0.0001f) + { + heading = character.transform.forward; + heading.y = 0f; + } + return heading.normalized; + } + + /// + /// Charges this frame of sprint. Returns false when the player cannot pay, which drops + /// them back to the free boost speed rather than out of the sky. + /// + private static bool TrySpendSprintStamina(float dt) + { + Player player = Player.m_localPlayer; + if (player == null) return false; + + float cost = SPRINT_STAMINA_PER_SECOND * dt; + if (!player.HaveStamina(cost)) return false; + + player.UseStamina(cost); + return true; + } + } + + /// + /// Character.UpdateMotion asks IsSwimming before it asks m_flying, so a flying dragon that + /// touched water was handed to UpdateSwimming every frame: the flight patch above never ran, + /// the form paddled on the surface, and there was no way back into the air short of finding + /// land. (The Aswid's bat escapes this because debug-fly is checked at the very top of + /// UpdateMotion, before water is considered at all - which is exactly why it can take off + /// from the sea.) Hand those frames back to UpdateFlying, which is the only motion path the + /// two methods contend over: nothing else calls either of them, and everything that merely + /// asks IsSwimming - the Wet status, the animator, stamina - is left alone. + /// + [HarmonyPatch(typeof(Character), "UpdateSwimming")] + public static class SkadiWaterFlightPatch + { + private static readonly MethodInfo UpdateFlyingMethod = AccessTools.Method(typeof(Character), "UpdateFlying"); + + public static bool Prefix(Character __instance, float dt) + { + if (__instance != Player.m_localPlayer) return true; + + DrakeFormBehavior form = DrakeFormBehavior.Active; + if (form == null || !form.IsFlying) return true; + + // Fail open: if a game update ever renames the method, swim normally rather than + // freezing the player in place with no motion update at all. + if (UpdateFlyingMethod == null) return true; + + UpdateFlyingMethod.Invoke(__instance, new object[] { dt }); + return false; + } + } + + /// + /// UpdateFlying turns the body to face m_moveDir, which is right for every direction of + /// travel except backwards - reverse thrust would spin the dragon around to fly nose-first + /// away from the camera, putting its tail where its breath comes out. Claiming + /// AlwaysRotateCamera for the duration switches UpdateRotation over to the camera's yaw + /// instead, so the form keeps facing whatever it is retreating from. Scoped to the frames + /// the reverse is actually held. + /// + [HarmonyPatch(typeof(Player), "AlwaysRotateCamera")] + public static class SkadiReverseFacingPatch + { + public static bool Prefix(Player __instance, ref bool __result) + { + if (__instance != Player.m_localPlayer) return true; + if (!SkadiDirectedFlightPatch.Reversing) return true; + + DrakeFormBehavior form = DrakeFormBehavior.Active; + if (form == null || !form.IsFlying) return true; + + __result = true; + return false; } } diff --git a/JotunnModStub/ZdoVisualSync.cs b/JotunnModStub/ZdoVisualSync.cs index dc29a07..887ce22 100644 --- a/JotunnModStub/ZdoVisualSync.cs +++ b/JotunnModStub/ZdoVisualSync.cs @@ -182,11 +182,14 @@ namespace RacesOfValheim { if (string.IsNullOrEmpty(currentForm)) { - playerVisual.localScale = Vector3.one; + PlayerVisualHider.Show(playerVisual, "fenrir-remote-revert"); } else { - playerVisual.localScale = Vector3.one * 0.001f; + // Same story as the local form: the scale trick this used to hide the body + // is undone every frame by the reset that keeps non-Trol players at normal + // size, so other players saw the man standing in his own wolf too. + PlayerVisualHider.Hide(playerVisual, "fenrir-remote-form"); GameObject prefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab(currentForm); if (prefab != null) { diff --git a/README.md b/README.md index 6ca1c15..1f200bd 100644 --- a/README.md +++ b/README.md @@ -125,9 +125,12 @@ This mod currently introduces 8 custom races: - **Fader**: Skeleton Dragon Form ('J' Key). While transformed, Right Mouse toggles flight. You glide toward wherever you are aiming; hold W -to power forward and climb. Let go and the form holds level for a couple of seconds before -settling into a gentle descent. Timed forms show their remaining seconds, and their cooldown, -as a Moder trophy icon beside the minimap. +to power forward and climb, and add Shift to spend stamina on a burst of speed. S beats backwards +along your aim - look down and press it to rise away from whatever you are watching, without +turning to face away from it. Let go of everything and the form holds level for five seconds +before settling into a gentle descent. Water is no obstacle: a flying form beats its way back +out of the sea instead of being stuck paddling on the surface. Timed forms show their remaining +seconds, and their cooldown, as a Moder trophy icon beside the minimap. ### Skeleton Progression - **Base (No Bosses)**: +50 Max Health. Undead Diet (Cannot eat mortal food, no stamina bar). diff --git a/dist/icon.png b/dist/icon.png deleted file mode 100644 index 90b7b14..0000000 Binary files a/dist/icon.png and /dev/null differ