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.
288 lines
13 KiB
C#
288 lines
13 KiB
C#
using HarmonyLib;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
[HarmonyPatch(typeof(VisEquipment), "UpdateColors")]
|
|
public static class SkadiSkinColorPatch
|
|
{
|
|
public static void Postfix(VisEquipment __instance)
|
|
{
|
|
if (!__instance.m_isPlayer) return;
|
|
Player player = __instance.GetComponent<Player>();
|
|
if (player == null) return;
|
|
|
|
ZNetView nview = player.GetComponent<ZNetView>();
|
|
if (nview != null && nview.IsValid() && nview.GetZDO().GetString("RacesOfValheim_Race", "Human") == "Skadi")
|
|
{
|
|
if (__instance.m_bodyModel != null && __instance.m_bodyModel.material != null)
|
|
{
|
|
// Azzurro molto chiaro
|
|
Color skadiColor = new Color(0.6f, 0.8f, 1f, 1f);
|
|
__instance.m_bodyModel.material.SetColor("_SkinColor", skadiColor);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(VisEquipment), "UpdateVisuals")]
|
|
public static class Skadi_MultiplayerVisuals_Patch
|
|
{
|
|
public static void Postfix(VisEquipment __instance)
|
|
{
|
|
if (!__instance.m_isPlayer) return;
|
|
Player player = __instance.GetComponent<Player>();
|
|
if (player == null || player.IsOwner()) return; // Only process remote players
|
|
|
|
ZNetView nview = player.GetComponent<ZNetView>();
|
|
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<GameObject>(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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(SEMan), "AddStatusEffect", new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float) })]
|
|
public static class SkadiSEManPatch
|
|
{
|
|
public static bool Prefix(SEMan __instance, ref int nameHash)
|
|
{
|
|
Character character = Traverse.Create(__instance).Field<Character>("m_character").Value;
|
|
if (character == Player.m_localPlayer && SkadiRace.Instance != null && SkadiRace.Instance.IsSkadi())
|
|
{
|
|
var rules = SkadiProgression.GetRules(BossProgressionManager.GetCurrentProgressionState());
|
|
|
|
if (nameHash == "Cold".GetStableHashCode() && rules.ImmuneToCold)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (nameHash == "Freezing".GetStableHashCode())
|
|
{
|
|
if (rules.ImmuneToFreezing) return false;
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
// 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<Character>("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
|
|
{
|
|
public static void Prefix(Character __instance, ref HitData hit)
|
|
{
|
|
if (hit.GetAttacker() != null && hit.GetAttacker() == Player.m_localPlayer)
|
|
{
|
|
if (SkadiRace.Instance != null && SkadiRace.Instance.IsSkadi())
|
|
{
|
|
var rules = SkadiProgression.GetRules(BossProgressionManager.GetCurrentProgressionState());
|
|
if (rules.BonusFrostDamage)
|
|
{
|
|
hit.m_damage.m_frost += 2f * BossProgressionManager.GetCurrentProgressionState();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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 = 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
|
|
{
|
|
public static bool Prefix(Humanoid __instance)
|
|
{
|
|
if (__instance == Player.m_localPlayer && __instance.GetComponentInChildren<DrakeFormBehavior>() != null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|