diff --git a/JotunnModStub/Aswid/AswidPatches.cs b/JotunnModStub/Aswid/AswidPatches.cs index a65bcef..a5bc9d2 100644 --- a/JotunnModStub/Aswid/AswidPatches.cs +++ b/JotunnModStub/Aswid/AswidPatches.cs @@ -521,7 +521,7 @@ namespace RacesOfValheim ZNetView nview = __instance.GetComponent(); if (nview != null && nview.IsValid() && nview.GetZDO().GetString("RacesOfValheim_Race", "Human") == "Aswid") { - if (__instance == Player.m_localPlayer && Input.GetKeyDown(KeyCode.I)) + if (__instance == Player.m_localPlayer && RaceInput.Allowed && Input.GetKeyDown(KeyCode.I)) { AswidRace.DevourEnabled = !AswidRace.DevourEnabled; string msg = AswidRace.DevourEnabled ? "Devour Ability: ENABLED" : "Devour Ability: DISABLED"; diff --git a/JotunnModStub/Aswid/AswidRace.cs b/JotunnModStub/Aswid/AswidRace.cs index f89ea6f..3b1f9ec 100644 --- a/JotunnModStub/Aswid/AswidRace.cs +++ b/JotunnModStub/Aswid/AswidRace.cs @@ -504,8 +504,7 @@ namespace RacesOfValheim int state = BossProgressionManager.GetCurrentProgressionState(); - bool takeInput = HarmonyLib.Traverse.Create(Player.m_localPlayer).Method("TakeInput").GetValue(); - if (takeInput) + if (RaceInput.Allowed) { if (Input.GetKeyDown(KeyCode.G)) { TryTransformWithRules(AswidProgression.GetGKeyRules(state)); return; } if (Input.GetKeyDown(KeyCode.H)) { TryToggleMistForm(); return; } diff --git a/JotunnModStub/Fenrir/FenrirBehaviors.cs b/JotunnModStub/Fenrir/FenrirBehaviors.cs index 7954de1..e2628aa 100644 --- a/JotunnModStub/Fenrir/FenrirBehaviors.cs +++ b/JotunnModStub/Fenrir/FenrirBehaviors.cs @@ -56,7 +56,7 @@ namespace RacesOfValheim fenrirAnim.SetFloat("sideway_speed", playerAnim.GetFloat("sideway_speed")); } } - if (isGrounded) + if (isGrounded && RaceInput.Allowed) { if (Input.GetKeyDown(KeyCode.O)) { @@ -311,8 +311,12 @@ namespace RacesOfValheim if (isGrounded) { + // Gated per-read rather than around the block, so opening a GUI mid-stream + // still falls through to StopFire() instead of leaving the flames running. + bool canAct = RaceInput.Allowed; + // Fire attack on Right Click - if (Input.GetMouseButton(1)) + if (canAct && Input.GetMouseButton(1)) { if (Player.m_localPlayer.GetEitr() > 0) { @@ -335,18 +339,18 @@ namespace RacesOfValheim StopFire(); } - if (Input.GetKeyDown(KeyCode.O)) + if (canAct && Input.GetKeyDown(KeyCode.O)) { StartCoroutine(HowlRoutine()); } // Attacks on Left Click - if (Input.GetMouseButtonDown(0) && !isShootingFire) + if (canAct && Input.GetMouseButtonDown(0) && !isShootingFire) { StartCoroutine(ClawRoutine()); // Single claw } // Double claw on Middle Click - else if (Input.GetMouseButtonDown(2) && !isShootingFire) + else if (canAct && Input.GetMouseButtonDown(2) && !isShootingFire) { StartCoroutine(DoubleClawRoutine()); } @@ -671,7 +675,7 @@ namespace RacesOfValheim } } - if (isGrounded) + if (isGrounded && RaceInput.Allowed) { if (Input.GetMouseButtonDown(0)) // Left Click { @@ -844,7 +848,7 @@ namespace RacesOfValheim } } - if (isGrounded) + if (isGrounded && RaceInput.Allowed) { if (Input.GetMouseButtonDown(0)) // Left Click { diff --git a/JotunnModStub/Fenrir/FenrirRace.cs b/JotunnModStub/Fenrir/FenrirRace.cs index 3768190..5adc796 100644 --- a/JotunnModStub/Fenrir/FenrirRace.cs +++ b/JotunnModStub/Fenrir/FenrirRace.cs @@ -143,6 +143,8 @@ namespace RacesOfValheim { } } + if (!RaceInput.Allowed) return; + int state = BossProgressionManager.GetCurrentProgressionState(); if (Input.GetKeyDown(KeyCode.G)) { TryTransformWithRules(FenrirProgression.GetGKeyRules(state)); return; } diff --git a/JotunnModStub/RaceInput.cs b/JotunnModStub/RaceInput.cs new file mode 100644 index 0000000..4c92a55 --- /dev/null +++ b/JotunnModStub/RaceInput.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using HarmonyLib; + +namespace RacesOfValheim +{ + /// + /// Gate for race ability input. + /// + /// UnityEngine.Input reads the device directly, so abilities bound to keys or mouse buttons + /// kept firing while the map, the inventory, a chest, the chat or a menu had focus - dragging + /// an item inside a container also swung the transformed attack, for instance. Valheim runs + /// its own controls through Player.TakeInput, which reports false for exactly those states + /// (InventoryGui covers the backpack and chests alike), so mirror that instead of maintaining + /// a parallel list of GUI checks that would drift as the game changes. + /// + public static class RaceInput + { + // Not public on Player, hence the reflection; resolved once rather than per frame. + private static readonly MethodInfo TakeInputMethod = AccessTools.Method(typeof(Player), "TakeInput"); + + public static bool Allowed + { + get + { + Player player = Player.m_localPlayer; + if (player == null) return false; + + // Fail open: if a game update ever renames the method, abilities stay usable + // rather than silently going dead. + if (TakeInputMethod == null) return true; + + return (bool)TakeInputMethod.Invoke(player, null); + } + } + } +} diff --git a/JotunnModStub/RacesOfValheim.cs b/JotunnModStub/RacesOfValheim.cs index 0b744a3..f0e1453 100644 --- a/JotunnModStub/RacesOfValheim.cs +++ b/JotunnModStub/RacesOfValheim.cs @@ -643,6 +643,8 @@ namespace RacesOfValheim Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_FenrirCurse".GetStableHashCode()); Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_AswidStats".GetStableHashCode()); Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_SkeletonStats".GetStableHashCode()); + Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_SkadiStats".GetStableHashCode()); + Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_SkadiCooldown".GetStableHashCode()); ZNetView nview = Player.m_localPlayer.GetComponent(); if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", "Human"); diff --git a/JotunnModStub/RacesOfValheim.csproj b/JotunnModStub/RacesOfValheim.csproj index 7122411..6029e4c 100644 --- a/JotunnModStub/RacesOfValheim.csproj +++ b/JotunnModStub/RacesOfValheim.csproj @@ -93,11 +93,15 @@ - + + + $(SolutionDir)dist\ + + - - - + + + diff --git a/JotunnModStub/Skadi/DrakeFormBehavior.cs b/JotunnModStub/Skadi/DrakeFormBehavior.cs index 53a4122..62941b0 100644 --- a/JotunnModStub/Skadi/DrakeFormBehavior.cs +++ b/JotunnModStub/Skadi/DrakeFormBehavior.cs @@ -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(); 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); } } @@ -35,25 +67,27 @@ namespace RacesOfValheim if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return; // Handle Flight Toggle (RMB) - Disabled for Fader - if (Input.GetMouseButtonDown(1) && formRules != null && formRules.Form != SkadiProgression.FormType.SkeletonDragon) + if (RaceInput.Allowed && Input.GetMouseButtonDown(1) && formRules != null && formRules.Form != SkadiProgression.FormType.SkeletonDragon) { 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() && RaceInput.Allowed) { 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); } } } diff --git a/JotunnModStub/Skadi/SkadiPatches.cs b/JotunnModStub/Skadi/SkadiPatches.cs index 3b35c9a..e38a81e 100644 --- a/JotunnModStub/Skadi/SkadiPatches.cs +++ b/JotunnModStub/Skadi/SkadiPatches.cs @@ -28,52 +28,58 @@ namespace RacesOfValheim [HarmonyPatch(typeof(VisEquipment), "UpdateVisuals")] public static class Skadi_MultiplayerVisuals_Patch { + private const string FormSuffix = "_multiplayer"; + public static void Postfix(VisEquipment __instance) { if (!__instance.m_isPlayer) return; Player player = __instance.GetComponent(); if (player == null || player.IsOwner()) return; // Only process remote players - - ZNetView nview = player.GetComponent(); - if (nview != null && nview.IsValid() && nview.GetZDO().GetString("RacesOfValheim_Race", "Human") == "Skadi") - { - string formName = nview.GetZDO().GetString("RacesOfValheim_SkadiForm", ""); - - Transform playerVisual = player.transform.Find("Visual"); - Transform formBody = player.transform.Find("SkadiBody_Form"); - - if (!string.IsNullOrEmpty(formName)) { - if (formBody != null && formBody.gameObject.name != formName + "_multiplayer") { - UnityEngine.Object.Destroy(formBody.gameObject); - formBody = null; - } - if (formBody == null) { - GameObject prefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab(formName); - if (prefab != null) { - Transform visual = prefab.transform.Find("Visual"); - if (visual != null) { - GameObject formInstance = UnityEngine.Object.Instantiate(visual.gameObject, player.transform); - formInstance.name = formName + "_multiplayer"; - if (formName == "Hatchling") formInstance.transform.localPosition = new Vector3(0f, -1.0f, 0f); - else formInstance.transform.localPosition = Vector3.zero; - formInstance.transform.localRotation = Quaternion.identity; - } - } - } - if (playerVisual != null) playerVisual.gameObject.SetActive(false); - } else { - if (formBody != null) UnityEngine.Object.Destroy(formBody.gameObject); - - // Fader form has a different name? "SkadiBody_Form" was used earlier, we just find all children and destroy them if they have "_multiplayer" - foreach (Transform child in player.transform) { - if (child.name.EndsWith("_multiplayer")) { - UnityEngine.Object.Destroy(child.gameObject); - } - } - if (playerVisual != null) playerVisual.gameObject.SetActive(true); + ZNetView nview = player.GetComponent(); + if (nview == null || !nview.IsValid()) return; + if (nview.GetZDO().GetString("RacesOfValheim_Race", "Human") != "Skadi") return; + + string formName = nview.GetZDO().GetString("RacesOfValheim_SkadiForm", ""); + Transform playerVisual = player.transform.Find("Visual"); + string wanted = formName + FormSuffix; + + // VisEquipment.UpdateVisuals runs every frame off CustomUpdate, so the spawned model + // has to be found again by the exact name it was given. This used to search for + // "SkadiBody_Form" - a name nothing is ever assigned - so the lookup missed every + // time and a fresh dragon was instantiated each frame. Remote players watched the + // models pile up on the spot and their client degraded until the Skadi player + // reverted; the transformed player saw nothing, since owners return above. + // Anything left over from that, or from a previous form, is cleaned up here too. + Transform formBody = null; + foreach (Transform child in player.transform) + { + if (!child.name.EndsWith(FormSuffix)) continue; + + if (formBody == null && child.name == wanted) formBody = child; + else UnityEngine.Object.Destroy(child.gameObject); + } + + if (string.IsNullOrEmpty(formName)) + { + if (playerVisual != null) playerVisual.gameObject.SetActive(true); + return; + } + + if (formBody == null) + { + GameObject prefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab(formName); + Transform visual = prefab != null ? prefab.transform.Find("Visual") : null; + if (visual != null) + { + GameObject formInstance = UnityEngine.Object.Instantiate(visual.gameObject, player.transform); + formInstance.name = wanted; + formInstance.transform.localPosition = formName == "Hatchling" ? new Vector3(0f, -1.0f, 0f) : Vector3.zero; + formInstance.transform.localRotation = Quaternion.identity; } } + + if (playerVisual != null) playerVisual.gameObject.SetActive(false); } } @@ -98,6 +104,10 @@ namespace RacesOfValheim if (rules.FreezingToCold) { + // Strip any real Freezing that may already be active (e.g. applied + // before this tier's conversion kicked in) so it can't linger + // alongside the converted Cold status. + __instance.RemoveStatusEffect("Freezing".GetStableHashCode(), true); nameHash = "Cold".GetStableHashCode(); } } @@ -106,6 +116,73 @@ namespace RacesOfValheim } } + // SE_SkadiStats grants a "Resistant" (or higher) Frost damage modifier from tier 1 onward, + // exactly like drinking a Frost Resistance potion. Valheim's own Player.UpdateEnvStatusEffects + // checks that same Frost damage modifier before deciding whether to apply Cold/Freezing at + // all, and skips both entirely once the character is Frost-resistant. That means real Mountain + // exposure (which applies Freezing, not Cold, per vanilla rules) never even reaches + // SkadiSEManPatch above from tier 1 onward, so the tier 2 "Freezing to Cold" conversion never + // gets a chance to run. These two patches scope out just that one environmental check: while + // Player.UpdateEnvStatusEffects is running for the local Skadi player, GetDamageModifiers is + // reported as Normal for Frost, so vanilla always attempts to apply the real status and + // SkadiSEManPatch's per-tier logic (block/convert/allow) is what actually decides the outcome. + // Frost damage resistance from hits (SkadiDamagePatch) is untouched by this. + [HarmonyPatch(typeof(Player), "UpdateEnvStatusEffects")] + public static class SkadiEnvCheckScope + { + public static bool Active = false; + + public static void Prefix(Player __instance) + { + Active = __instance == Player.m_localPlayer && SkadiRace.Instance != null && SkadiRace.Instance.IsSkadi(); + } + + public static void Postfix() + { + Active = false; + } + } + + [HarmonyPatch(typeof(Character), "GetDamageModifiers")] + public static class SkadiEnvFrostModifierPatch + { + public static void Postfix(Character __instance, ref HitData.DamageModifiers __result) + { + if (SkadiEnvCheckScope.Active && __instance == Player.m_localPlayer) + { + __result.m_frost = HitData.DamageModifier.Normal; + } + } + } + + // Valheim's Player.UpdateEnvStatusEffects always tries RemoveStatusEffect(Cold, quiet:true) + // as the first step of applying Freezing. Since SkadiSEManPatch redirects Freezing into Cold, + // that removal would strip our converted Cold status every other frame (a permanent + // add/remove flicker that cancels the buff out). Blocking just this "quiet" removal for the + // FreezingToCold player forces Valheim to always fall through to AddStatusEffect(Freezing,...), + // which SkadiSEManPatch converts to a stable, non-resetting Cold re-application instead. + [HarmonyPatch(typeof(SEMan), "RemoveStatusEffect", new System.Type[] { typeof(int), typeof(bool) })] + public static class SkadiColdRemovalGuardPatch + { + public static bool Prefix(SEMan __instance, int nameHash, bool quiet, ref bool __result) + { + if (quiet && nameHash == "Cold".GetStableHashCode()) + { + Character character = Traverse.Create(__instance).Field("m_character").Value; + if (character == Player.m_localPlayer && SkadiRace.Instance != null && SkadiRace.Instance.IsSkadi()) + { + var rules = SkadiProgression.GetRules(BossProgressionManager.GetCurrentProgressionState()); + if (rules.FreezingToCold && !rules.ImmuneToFreezing) + { + __result = false; + return false; + } + } + } + return true; + } + } + [HarmonyPatch(typeof(Character), "ApplyDamage")] public static class SkadiDamagePatch { @@ -129,6 +206,79 @@ namespace RacesOfValheim + // DrakeFormBehavior flips the player into Character's native flying-creature movement + // (m_flying = true) instead of the old debug-fly noclip, which lets us feed it a full 3D + // 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. + [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; + // Tangent of the unpowered descent angle: 0.4 sinks at roughly 22 degrees below level. + private const float DESCENT_SLOPE = 0.4f; + + public static void Prefix(Character __instance) + { + if (__instance != Player.m_localPlayer) return; + + DrakeFormBehavior form = DrakeFormBehavior.Active; + if (form == null || !form.IsFlying) return; + + var traverse = Traverse.Create(__instance); + Vector3 lookDir = Player.m_localPlayer.GetLookDir(); + bool boost = RaceInput.Allowed && Input.GetKey(KeyCode.W); + bool onGround = __instance.IsOnGround(); + + traverse.Field("m_run").SetValue(boost); + traverse.Field("m_flyFastSpeed").SetValue(BOOST_SPEED); + + // 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 + // up as a flying creature - a 90 degree turn would take over seven seconds, so the + // 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; + + Vector3 moveDir = lookDir; + float coastSpeed; + + 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 + // 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; + } + 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; + } + + traverse.Field("m_moveDir").SetValue(moveDir); + traverse.Field("m_flySlowSpeed").SetValue(coastSpeed); + } + } + [HarmonyPatch(typeof(Humanoid), "StartAttack")] public static class SkadiAttackPatch { diff --git a/JotunnModStub/Skadi/SkadiRace.cs b/JotunnModStub/Skadi/SkadiRace.cs index ca23977..1b45633 100644 --- a/JotunnModStub/Skadi/SkadiRace.cs +++ b/JotunnModStub/Skadi/SkadiRace.cs @@ -11,6 +11,7 @@ namespace RacesOfValheim public static SkadiRace Instance; public static SE_SkadiStats skadiCurseSE; public static SE_FormCooldown skadiCdSE; + public static SE_SkadiForm skadiFormSE; private float auraTimer = 0f; private float lastSpellTime = 0f; @@ -18,6 +19,8 @@ namespace RacesOfValheim private bool isTransformed = false; private bool isTransformingSequence = false; private SkadiProgression.FormRules activeRules = null; + // Time.time at which a timed form drops; 0 means the current form has no time limit. + private float formExpireTime = 0f; private float lastAuraTime = 0f; private GameObject frostAuraVFX = null; @@ -47,18 +50,33 @@ namespace RacesOfValheim ItemManager.Instance.AddStatusEffect(skadiStats); skadiCurseSE = skadiStats.StatusEffect as SE_SkadiStats; + // Timed forms and their cooldown are Moder's, so they carry her trophy rather than the + // drake one used for the passive blessing. + Sprite dragonIcon = GetTrophyIcon("TrophyDragonQueen") ?? GetTrophyIcon("TrophyHatchling"); + skadiCdSE = ScriptableObject.CreateInstance(); skadiCdSE.name = "SE_SkadiCooldown"; skadiCdSE.m_name = "Dragon Form Cooldown"; - if (drakeTrophy != null) - { - ItemDrop trophyDrop = drakeTrophy.GetComponent(); - if (trophyDrop != null && trophyDrop.m_itemData.m_shared.m_icons.Length > 0) - { - skadiCdSE.m_icon = trophyDrop.m_itemData.m_shared.m_icons[0]; - } - } + skadiCdSE.m_icon = dragonIcon; ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(skadiCdSE, fixReference: false)); + + skadiFormSE = ScriptableObject.CreateInstance(); + skadiFormSE.name = "SE_SkadiForm"; + skadiFormSE.m_name = "Dragon Form"; + skadiFormSE.m_tooltip = "Your dragon shape holds for a while longer."; + skadiFormSE.m_icon = dragonIcon; + ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(skadiFormSE, fixReference: false)); + } + + private static Sprite GetTrophyIcon(string prefabName) + { + GameObject trophy = PrefabManager.Cache.GetPrefab(prefabName)?.gameObject; + ItemDrop drop = trophy != null ? trophy.GetComponent() : null; + if (drop != null && drop.m_itemData.m_shared.m_icons.Length > 0) + { + return drop.m_itemData.m_shared.m_icons[0]; + } + return null; } @@ -132,13 +150,26 @@ namespace RacesOfValheim } } - if (rules.ColdSpell) + if (rules.ColdSpell && RaceInput.Allowed) { HandleColdSpell(rules); } if (isTransformingSequence) return; + // Forms with a DurationMinutes budget drop on their own once it runs out, which is + // also what starts their cooldown - without this the timed tiers never expired. + if (isTransformed && formExpireTime > 0f && Time.time >= formExpireTime) + { + formExpireTime = 0f; + Player.m_localPlayer.Message(MessageHud.MessageType.Center, "Your dragon form fades."); + StartCoroutine(RevertToHumanRoutine()); + return; + } + + // Form keys and the debug dump are ability input: they stay inert while a GUI has focus. + if (!RaceInput.Allowed) return; + int state = BossProgressionManager.GetCurrentProgressionState(); if (Input.GetKeyDown(KeyCode.G)) { TryTransformWithRules(SkadiProgression.GetGKeyRules(state)); return; } if (Input.GetKeyDown(KeyCode.H)) { TryTransformWithRules(SkadiProgression.GetHKeyRules(state)); return; } @@ -230,7 +261,7 @@ namespace RacesOfValheim if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return; if (isTransformed) return; // Do not cast human spell while in dragon form - // Middle Mouse Button to cast (Kick) + // Middle Mouse Button to cast if (Input.GetMouseButtonDown(2)) { float cooldown = rules.ImprovedColdSpell ? 2.0f : 1.5f; @@ -246,10 +277,11 @@ namespace RacesOfValheim lastSpellTime = Time.time; var zanim = HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_zanim").Value; - if (zanim != null) + if (zanim != null) { - // Forcing secondary attack trigger, which is kick when unarmed - zanim.SetTrigger("secondary"); + // Raised-arms Galdr cast gesture instead of the unarmed kick, so the cast + // reads as a spell instead of a leg swing near the ground. + zanim.SetTrigger("galdr_cast"); } StartCoroutine(ColdSpellKickCoroutine(rules)); @@ -258,7 +290,7 @@ namespace RacesOfValheim private IEnumerator ColdSpellKickCoroutine(SkadiProgression.FormRules rules) { - // Wait for the kick animation to reach the extension point + // Wait for the cast animation to reach the release point yield return new WaitForSeconds(0.4f); if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) yield break; @@ -287,16 +319,16 @@ namespace RacesOfValheim { if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) break; - // Spawn from the foot (low position, forward) + // Spawn from chest height, forward Vector3 lookDir = Player.m_localPlayer.GetLookDir(); - + // Add a small spread for the improved blast if (rules.ImprovedColdSpell && i > 0) { lookDir = Quaternion.Euler(UnityEngine.Random.Range(-5f, 5f), UnityEngine.Random.Range(-5f, 5f), 0f) * lookDir; } - Vector3 spawnPos = Player.m_localPlayer.transform.position + Vector3.up * 0.4f + lookDir * 0.6f; + Vector3 spawnPos = Player.m_localPlayer.transform.position + Vector3.up * 1.4f + lookDir * 0.6f; GameObject projInstance = Instantiate(projPrefab, spawnPos, Quaternion.LookRotation(lookDir)); @@ -588,10 +620,33 @@ namespace RacesOfValheim else if (prefabName == "Fader") Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You are Fader!"); isTransformed = true; + StartFormTimer(rules); } } } + // Drives both the expiry check in Update and the HUD icon: the status effect exists purely + // so Valheim draws Moder's trophy with its own countdown next to the minimap. + private void StartFormTimer(SkadiProgression.FormRules rules) + { + int hash = "SE_SkadiForm".GetStableHashCode(); + SEMan seman = Player.m_localPlayer.GetSEMan(); + seman.RemoveStatusEffect(hash, true); + + if (rules.DurationMinutes <= 0f) + { + formExpireTime = 0f; + return; + } + + float seconds = rules.DurationMinutes * 60f; + formExpireTime = Time.time + seconds; + + seman.AddStatusEffect(hash, true); + StatusEffect se = seman.GetStatusEffect(hash); + if (se != null) se.m_ttl = seconds; + } + private void ExecuteReversion() { Transform playerVisual = Player.m_localPlayer.transform.Find("Visual"); @@ -614,6 +669,8 @@ namespace RacesOfValheim } isTransformed = false; + formExpireTime = 0f; + Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_SkadiForm".GetStableHashCode(), true); Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You returned to human form."); if (activeRules != null && activeRules.CooldownMinutes > 0) diff --git a/JotunnModStub/Skadi/SkadiStatusEffects.cs b/JotunnModStub/Skadi/SkadiStatusEffects.cs index 536e8de..b6517af 100644 --- a/JotunnModStub/Skadi/SkadiStatusEffects.cs +++ b/JotunnModStub/Skadi/SkadiStatusEffects.cs @@ -4,6 +4,12 @@ using UnityEngine; namespace RacesOfValheim { + // Timed dragon forms. m_ttl is set when the form is entered, which is all Valheim needs to + // render the countdown: StatusEffect.GetIconText() prints the remaining time by itself. + public class SE_SkadiForm : StatusEffect + { + } + public class SE_SkadiStats : SE_Stats { public override void Setup(Character character) diff --git a/JotunnModStub/Trol/TrolRace.cs b/JotunnModStub/Trol/TrolRace.cs index ee82086..5b7eb15 100644 --- a/JotunnModStub/Trol/TrolRace.cs +++ b/JotunnModStub/Trol/TrolRace.cs @@ -119,14 +119,17 @@ namespace RacesOfValheim { if (!IsTrol()) return; - if (Input.GetKeyDown(KeyCode.G)) + if (RaceInput.Allowed) { - TryThrowRock(); - } + if (Input.GetKeyDown(KeyCode.G)) + { + TryThrowRock(); + } - if (Input.GetKeyDown(KeyCode.H)) - { - TryTrueForm(); + if (Input.GetKeyDown(KeyCode.H)) + { + TryTrueForm(); + } } // Check log durability diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 0000000..d5f366b --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/README.md b/README.md index d344612..3b53be4 100644 --- a/README.md +++ b/README.md @@ -81,13 +81,18 @@ This mod currently introduces 6 custom races: ### Skadi Progression - **Base (No Bosses)**: Immune to Cold, Bonus Frost Damage, 50% Frost Resistance. -- **Eikthyr**: +20% Eitr Regen, Freezing to Cold, Cold Spell. -- **The Elder**: Drake Form (Cannot attack). -- **Bonemass**: Drake Form (Can attack). -- **Moder**: Moder Form (1 min duration, 10 min cooldown). -- **Yagluth**: Improved Cold Spell. Moder Form (1 min duration, 5 min cooldown). -- **The Queen**: Moder Form (Unlimited duration, no cooldown). -- **Fader**: Skeleton Dragon Form. +- **Eikthyr**: +20% Eitr Regen, Freezing to Cold, Cold Spell (Middle Mouse). +- **The Elder**: Drake Form ('G' Key) (Cannot attack). +- **Bonemass**: Drake Form ('G' Key) (Can attack). +- **Moder**: Moder Form ('H' Key) (1 min duration, 10 min cooldown). +- **Yagluth**: Improved Cold Spell. Moder Form ('H' Key) (1 min duration, 5 min cooldown). +- **The Queen**: Moder Form ('H' Key) (Unlimited duration, no cooldown). +- **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. ### Skeleton Progression - **Base (No Bosses)**: +50 Max Health. Undead Diet (Cannot eat mortal food, no stamina bar).