From 1bdf77e8d6ccb7c57e93ebe1af09c9e5f35b7814 Mon Sep 17 00:00:00 2001 From: Ferdinando Date: Sun, 2 Aug 2026 17:54:39 +0200 Subject: [PATCH] aswig and multiplayer fixes --- JotunnModStub/Aswid/AswidPatches.cs | 20 ++++++++++++++ JotunnModStub/Aswid/AswidRace.cs | 23 ++++++++++++++-- JotunnModStub/Skadi/SkadiPatches.cs | 33 +++++++++++++++++++++++ JotunnModStub/Skadi/SkadiRace.cs | 7 ++++- JotunnModStub/Trol/TrolPatches.cs | 26 ++++++++++++------ JotunnModStub/ZdoVisualSync.cs | 42 +++-------------------------- 6 files changed, 102 insertions(+), 49 deletions(-) diff --git a/JotunnModStub/Aswid/AswidPatches.cs b/JotunnModStub/Aswid/AswidPatches.cs index a5bc9d2..fe5a45e 100644 --- a/JotunnModStub/Aswid/AswidPatches.cs +++ b/JotunnModStub/Aswid/AswidPatches.cs @@ -804,4 +804,24 @@ namespace RacesOfValheim } } } + + [HarmonyPatch(typeof(Player), "ClearFood")] + public static class Aswid_Player_ClearFood_Patch + { + public static bool Prefix(Player __instance) + { + if (__instance == Player.m_localPlayer && AswidRace.IsAswid()) + { + // Retain food if the player is dead/dying. + // Allows Bukeperries to still clear food normally. + if (__instance.IsDead() || __instance.GetHealth() <= 0f) + { + Jotunn.Logger.LogInfo("[AswidRace] Preserving food buffs through death (Aswid racial trait)."); + return false; + } + } + return true; + } + } } + diff --git a/JotunnModStub/Aswid/AswidRace.cs b/JotunnModStub/Aswid/AswidRace.cs index 040534c..ca3947d 100644 --- a/JotunnModStub/Aswid/AswidRace.cs +++ b/JotunnModStub/Aswid/AswidRace.cs @@ -56,7 +56,9 @@ namespace RacesOfValheim { "Ulv", "BloodPudding" }, { "Seeker", "CookedBugMeat" }, { "SeekerBrute", "CookedBugMeat" }, - { "SeekerBrood", "CookedBugMeat" } + { "SeekerBrood", "CookedBugMeat" }, + { "Surtling", "BloodPudding" }, + { "Bear", "CookedBearMeat" } }; public static bool BypassAswidFoodCheck = false; @@ -139,11 +141,16 @@ namespace RacesOfValheim { burnTime = 1200f; // 20 minutes } + else if (mobName == "Greyling") { foodHp = 20f; burnTime = 1200f; } + else if (mobName == "Greydwarf") { foodHp = 25f; burnTime = 1200f; } + else if (mobName == "Greydwarf_Shaman") { foodHp = 30f; burnTime = 1200f; } + else if (mobName == "Greydwarf_Elite") { foodHp = 60f; burnTime = 1800f; } + customItem.ItemDrop.m_itemData.m_shared.m_food = foodHp; customItem.ItemDrop.m_itemData.m_shared.m_foodStamina = 0f; customItem.ItemDrop.m_itemData.m_shared.m_foodEitr = 0f; customItem.ItemDrop.m_itemData.m_shared.m_foodBurnTime = burnTime; - customItem.ItemDrop.m_itemData.m_shared.m_foodRegen = 1f; + customItem.ItemDrop.m_itemData.m_shared.m_foodRegen = Mathf.Max(1f, foodHp / 15f); } } } @@ -579,6 +586,11 @@ namespace RacesOfValheim if (playerVisual != null) { playerVisual.gameObject.SetActive(true); + + ZSyncAnimation zanim = Player.m_localPlayer.GetComponent(); + if (zanim != null) zanim.SetBool("sit", false); + Animator anim = playerVisual.GetComponent(); + if (anim != null) anim.SetBool("sit", false); } Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_BatForm".GetStableHashCode(), true); @@ -690,6 +702,11 @@ namespace RacesOfValheim if (playerVisual != null) { playerVisual.gameObject.SetActive(true); + + ZSyncAnimation zanim = Player.m_localPlayer.GetComponent(); + if (zanim != null) zanim.SetBool("sit", false); + Animator anim = playerVisual.GetComponent(); + if (anim != null) anim.SetBool("sit", false); } float elapsed = 0f; @@ -1092,3 +1109,5 @@ namespace RacesOfValheim + + diff --git a/JotunnModStub/Skadi/SkadiPatches.cs b/JotunnModStub/Skadi/SkadiPatches.cs index 7007e03..5b6bfec 100644 --- a/JotunnModStub/Skadi/SkadiPatches.cs +++ b/JotunnModStub/Skadi/SkadiPatches.cs @@ -76,6 +76,11 @@ namespace RacesOfValheim formInstance.name = wanted; formInstance.transform.localPosition = formName == "Hatchling" ? new Vector3(0f, -1.0f, 0f) : Vector3.zero; formInstance.transform.localRotation = Quaternion.identity; + + if (formInstance.GetComponent() == null) + { + formInstance.AddComponent(); + } } } @@ -83,6 +88,34 @@ namespace RacesOfValheim } } + public class RemoteSkadiAnimator : MonoBehaviour + { + private Animator anim; + private Player player; + + private void Start() + { + anim = GetComponent(); + if (anim == null) anim = GetComponentInChildren(); + player = GetComponentInParent(); + } + + private void Update() + { + if (anim == null || player == null) return; + + bool flying = HarmonyLib.Traverse.Create(player).Field("m_flying").Value; + bool grounded = !flying && player.IsOnGround(); + + anim.SetBool("onGround", grounded); + anim.SetBool("flying", flying); + + Vector3 vel = player.GetVelocity(); + vel.y = 0f; + anim.SetFloat("forward_speed", vel.magnitude); + } + } + [HarmonyPatch(typeof(SEMan), "AddStatusEffect", new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float) })] public static class SkadiSEManPatch { diff --git a/JotunnModStub/Skadi/SkadiRace.cs b/JotunnModStub/Skadi/SkadiRace.cs index abd1c4b..f8290bf 100644 --- a/JotunnModStub/Skadi/SkadiRace.cs +++ b/JotunnModStub/Skadi/SkadiRace.cs @@ -637,7 +637,7 @@ namespace RacesOfValheim if (prefab != null && playerVisual != null) { - playerVisual.localScale = Vector3.one * 0.001f; + playerVisual.gameObject.SetActive(false); Transform visual = prefab.transform.Find("Visual"); if (visual != null) @@ -726,6 +726,11 @@ namespace RacesOfValheim { playerVisual.localScale = Vector3.one; playerVisual.gameObject.SetActive(true); + + ZSyncAnimation zanim = Player.m_localPlayer.GetComponent(); + if (zanim != null) zanim.SetBool("sit", false); + Animator anim = playerVisual.GetComponent(); + if (anim != null) anim.SetBool("sit", false); } isTransformed = false; diff --git a/JotunnModStub/Trol/TrolPatches.cs b/JotunnModStub/Trol/TrolPatches.cs index d5c8ac1..4492d82 100644 --- a/JotunnModStub/Trol/TrolPatches.cs +++ b/JotunnModStub/Trol/TrolPatches.cs @@ -142,9 +142,11 @@ namespace RacesOfValheim if (visual == null) return; float targetScale = ScaleForState(state); + if (isTrueFormActive) + { + targetScale = state >= 7 ? 2.5f : 2.0f; + } - // TEMPORARY: remote Trol sizing still is not showing up for observers and static - // reading has not explained why, so report what each observer actually computes. if (!isLocal && Time.time - lastRemoteLog > 2f) { lastRemoteLog = Time.time; @@ -156,18 +158,26 @@ namespace RacesOfValheim if (race == "Trol") { - // Prevent overriding scale while transforming or in True Form + // Local player has a coroutine that smooth-scales during the active transformation, + // so don't fight it here. Otherwise, lerp the scale (for remote players, or to + // maintain base size). bool isTransforming = isLocal && TrolRace.Instance != null && TrolRace.Instance.isTransforming; - if (!isTrueFormActive && !isTransforming && - visual.transform.localScale != new Vector3(targetScale, targetScale, targetScale)) + if (!isTransforming) { - visual.transform.localScale = new Vector3(targetScale, targetScale, targetScale); + if (Mathf.Abs(visual.transform.localScale.x - targetScale) > 0.005f) + { + float newScale = Mathf.Lerp(visual.transform.localScale.x, targetScale, Time.deltaTime * 5f); + visual.transform.localScale = new Vector3(newScale, newScale, newScale); + } + else if (visual.transform.localScale.x != targetScale) + { + visual.transform.localScale = new Vector3(targetScale, targetScale, targetScale); + } } } - else if (visual.transform.localScale == new Vector3(targetScale, targetScale, targetScale)) + else if (Mathf.Abs(visual.transform.localScale.x - 1f) > 0.001f) { - // Reset scale if not Trol visual.transform.localScale = Vector3.one; } } diff --git a/JotunnModStub/ZdoVisualSync.cs b/JotunnModStub/ZdoVisualSync.cs index bcbeea8..ad21bcf 100644 --- a/JotunnModStub/ZdoVisualSync.cs +++ b/JotunnModStub/ZdoVisualSync.cs @@ -77,6 +77,10 @@ namespace RacesOfValheim { UpdateAswidVisuals(); } + else if (race == "Trol") + { + // Managed externally in TrolPatches.cs + } else { RevertAllVisuals(); @@ -230,44 +234,6 @@ namespace RacesOfValheim $"[SkadiSync] remote '{m_player.GetPlayerName()}' form='{currentForm}' flying={flying} " + $"y={m_player.transform.position.y:F1} gravity={(body != null ? body.useGravity.ToString() : "no-body")}"); } - - if (currentForm != m_lastSkadiForm) - { - // Form changed - if (m_currentFormInstance != null) Destroy(m_currentFormInstance); - - Transform playerVisual = m_player.transform.Find("Visual"); - if (playerVisual != null) - { - if (string.IsNullOrEmpty(currentForm)) - { - playerVisual.localScale = Vector3.one; - } - else - { - playerVisual.localScale = Vector3.one * 0.001f; - GameObject prefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab(currentForm); - if (prefab != null) - { - Transform visual = prefab.transform.Find("Visual"); - if (visual != null) - { - m_currentFormInstance = Instantiate(visual.gameObject, m_player.transform); - m_currentFormInstance.transform.localPosition = Vector3.zero; - m_currentFormInstance.transform.localRotation = Quaternion.identity; - Component animEvent = m_currentFormInstance.GetComponent("AnimEvent"); - if (animEvent != null) Destroy(animEvent); - - foreach (var col in m_currentFormInstance.GetComponentsInChildren()) - { - Destroy(col); - } - } - } - } - } - m_lastSkadiForm = currentForm; - } } private void RevertAllVisuals()