Initial commit

This commit is contained in:
Ferdinando 2026-07-30 19:00:13 +02:00
commit c4a24c9fdf
142 changed files with 15491 additions and 0 deletions

View file

@ -0,0 +1,354 @@
using UnityEngine;
using System.Collections;
using Jotunn.Managers;
namespace RacesOfValheim
{
public class DrakeFormBehavior : MonoBehaviour
{
private Animator anim;
private bool isFlying = false;
private bool isLanding = false;
private float lastAttackTime = 0f;
private SkadiProgression.FormRules formRules;
public void Initialize(SkadiProgression.FormRules rules)
{
this.formRules = rules;
}
private const float ATTACK_COST = 20f;
private const float ATTACK_COOLDOWN = 3f;
private void Start()
{
anim = GetComponentInChildren<Animator>();
if (Player.m_localPlayer != null)
{
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(false);
}
}
private void Update()
{
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 (!isFlying && !isLanding)
{
isFlying = true;
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(true);
}
else if (isFlying && !isLanding)
{
isLanding = true;
isFlying = false;
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(false);
}
else if (isLanding)
{
// Cancel landing, resume flight
isLanding = false;
isFlying = true;
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(true);
}
}
if (isLanding)
{
// Prevent fall damage by keeping maxAirAltitude equal to current height
var altitudeField = HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_maxAirAltitude");
if (altitudeField.FieldExists())
{
altitudeField.SetValue(Player.m_localPlayer.transform.position.y);
}
if (Player.m_localPlayer.IsOnGround())
{
isLanding = false;
}
}
// Sync Animator
if (anim != null)
{
bool grounded = !isFlying && !isLanding && Player.m_localPlayer.IsOnGround();
// Use standard Valheim monster animator parameters
anim.SetBool("onGround", grounded);
anim.SetBool("flying", isFlying || isLanding);
Vector3 vel = Player.m_localPlayer.GetVelocity();
vel.y = 0f;
float speed = vel.magnitude;
anim.SetFloat("forward_speed", speed);
}
// Handle Attack
if (formRules != null && formRules.CanAttackInForm)
{
if (Input.GetMouseButtonDown(0))
{
if (Time.time - lastAttackTime >= ATTACK_COOLDOWN)
{
StartCoroutine(PerformAttackCoroutine(0));
}
}
else if (Input.GetMouseButtonDown(2)) // MMB
{
if (Time.time - lastAttackTime >= ATTACK_COOLDOWN)
{
StartCoroutine(PerformAttackCoroutine(2));
}
}
else if (Input.GetMouseButtonDown(1) && formRules.Form == SkadiProgression.FormType.SkeletonDragon) // RMB for Fader Spin
{
if (Time.time - lastAttackTime >= ATTACK_COOLDOWN)
{
StartCoroutine(PerformAttackCoroutine(1));
}
}
}
}
private IEnumerator PerformAttackCoroutine(int button)
{
lastAttackTime = Time.time;
if (formRules.Form == SkadiProgression.FormType.Drake)
{
if (button == 2) yield break; // Drake only uses LMB
Player.m_localPlayer.UseEitr(ATTACK_COST);
if (anim != null) anim.SetTrigger("attack");
// Delay to match animation spit timing
yield return new WaitForSeconds(0.3f);
GameObject projPrefab = PrefabManager.Cache.GetPrefab<GameObject>("hatchling_cold_projectile");
if (projPrefab == null) yield break;
ItemDrop staffDrop = PrefabManager.Cache.GetPrefab<GameObject>("StaffIceShards")?.GetComponent<ItemDrop>();
if (staffDrop == null) yield break;
float vel = staffDrop.m_itemData.m_shared.m_attack.m_projectileVel;
for (int i = 0; i < 3; i++)
{
Vector3 spawnPos = Player.m_localPlayer.GetEyePoint() + Player.m_localPlayer.GetLookDir() * 1.5f;
Vector3 targetDir = Player.m_localPlayer.GetLookDir();
Vector3 right = Vector3.Cross(Vector3.up, targetDir);
targetDir += right * UnityEngine.Random.Range(-0.1f, 0.1f) + Vector3.up * UnityEngine.Random.Range(-0.1f, 0.1f);
targetDir.Normalize();
GameObject projInstance = Instantiate(projPrefab, spawnPos, Quaternion.LookRotation(targetDir));
Projectile proj = projInstance.GetComponent<Projectile>();
if (proj != null)
{
HitData hitData = new HitData();
hitData.m_damage = staffDrop.m_itemData.m_shared.m_damages;
hitData.SetAttacker(Player.m_localPlayer);
proj.Setup(Player.m_localPlayer, targetDir * vel, -1f, hitData, staffDrop.m_itemData, null);
}
yield return new WaitForSeconds(0.2f);
}
}
else if (formRules.Form == SkadiProgression.FormType.Moder)
{
string attackTrigger = "attack_bite";
string projName = null;
int projCount = 1;
float projDelay = 0.5f;
bool isMelee = true;
if (isFlying || isLanding)
{
// Air attack (Ice Barrage)
attackTrigger = "attack_iceball";
projName = "dragon_ice_projectile";
projCount = 16;
projDelay = 0.8f;
isMelee = false;
}
else
{
if (button == 2)
{
// Ground MMB (Breath)
attackTrigger = "attack_breath";
projName = "hatchling_cold_projectile"; // Use cold explosion projectiles for a breath stream
projCount = 20;
projDelay = 0.5f; // Wait for the head to lower before breathing
isMelee = false;
}
else
{
// Ground LMB (Bite/Claw)
attackTrigger = UnityEngine.Random.value > 0.5f ? "attack_bite" : (UnityEngine.Random.value > 0.5f ? "attack_claw_left" : "attack_claw_right");
isMelee = true;
projDelay = 0.5f;
}
}
Player.m_localPlayer.UseEitr(ATTACK_COST);
if (anim != null) anim.SetTrigger(attackTrigger);
yield return new WaitForSeconds(projDelay);
if (!isMelee && projName != null)
{
GameObject projPrefab = PrefabManager.Cache.GetPrefab<GameObject>(projName);
if (projPrefab == null) yield break;
ItemDrop staffDrop = PrefabManager.Cache.GetPrefab<GameObject>("StaffIceShards")?.GetComponent<ItemDrop>();
if (staffDrop == null) yield break;
float vel = staffDrop.m_itemData.m_shared.m_attack.m_projectileVel;
for (int i = 0; i < projCount; i++)
{
Vector3 spawnPos = Player.m_localPlayer.GetEyePoint() + Player.m_localPlayer.GetLookDir() * 3.0f;
Vector3 targetDir = Player.m_localPlayer.GetLookDir();
if (projCount > 1)
{
Vector3 right = Vector3.Cross(Vector3.up, targetDir);
targetDir += right * UnityEngine.Random.Range(-0.3f, 0.3f) + Vector3.up * UnityEngine.Random.Range(-0.3f, 0.3f);
targetDir.Normalize();
}
GameObject projInstance = Instantiate(projPrefab, spawnPos, Quaternion.LookRotation(targetDir));
Projectile proj = projInstance.GetComponent<Projectile>();
if (proj != null)
{
HitData hitData = new HitData();
hitData.m_damage = staffDrop.m_itemData.m_shared.m_damages;
hitData.SetAttacker(Player.m_localPlayer);
proj.Setup(Player.m_localPlayer, targetDir * vel, -1f, hitData, staffDrop.m_itemData, null);
}
if (projCount > 1) yield return new WaitForSeconds(0.05f);
}
}
}
else if (formRules.Form == SkadiProgression.FormType.SkeletonDragon)
{
string attackTrigger = "attack_bite";
string projName = null;
int projCount = 1;
float projDelay = 0.5f;
bool isMelee = true;
if (isFlying || isLanding)
{
// Air attack (Meteors replacement -> Ice Barrage)
attackTrigger = "attack_roar"; // taunt animation has issues in air
projName = "dragon_ice_projectile"; // spawn_fader_meteors is buggy without Fader boss script
projCount = 16;
projDelay = 1.0f;
isMelee = false;
}
else
{
if (button == 2)
{
// Ground MMB (Frost Breath stream)
attackTrigger = "attack_flamebreath";
projName = "hatchling_cold_projectile";
projCount = 60; // Tripled!
projDelay = 0.5f;
isMelee = false;
}
else if (button == 1)
{
// Ground RMB (Spin)
attackTrigger = "attack_Spin";
isMelee = true;
projDelay = 0.5f;
}
else
{
// Ground LMB (Melee mix - bite/claws)
float rand = UnityEngine.Random.value;
if (rand < 0.33f) attackTrigger = "attack_bite";
else if (rand < 0.66f) attackTrigger = "attack_ClawL";
else attackTrigger = "attack_ClawR";
isMelee = true;
projDelay = 0.5f;
}
}
Player.m_localPlayer.UseEitr(ATTACK_COST);
if (anim != null) anim.SetTrigger(attackTrigger);
yield return new WaitForSeconds(projDelay);
if (!isMelee && projName != null)
{
GameObject projPrefab = PrefabManager.Cache.GetPrefab<GameObject>(projName);
if (projPrefab == null) yield break;
ItemDrop staffDrop = PrefabManager.Cache.GetPrefab<GameObject>("StaffIceShards")?.GetComponent<ItemDrop>();
if (staffDrop == null) yield break;
float vel = staffDrop.m_itemData.m_shared.m_attack.m_projectileVel;
for (int i = 0; i < projCount; i++)
{
Vector3 spawnPos = Player.m_localPlayer.GetEyePoint() + Player.m_localPlayer.GetLookDir() * 4.0f;
Vector3 targetDir = Player.m_localPlayer.GetLookDir();
if (projCount > 1)
{
Vector3 right = Vector3.Cross(Vector3.up, targetDir);
targetDir += right * UnityEngine.Random.Range(-0.2f, 0.2f) + Vector3.up * UnityEngine.Random.Range(-0.2f, 0.2f);
targetDir.Normalize();
}
GameObject projInstance = Instantiate(projPrefab, spawnPos, Quaternion.LookRotation(targetDir));
Projectile proj = projInstance.GetComponent<Projectile>();
HitData hitData = new HitData();
hitData.m_damage = staffDrop.m_itemData.m_shared.m_damages;
// Convert Fire to Frost
hitData.m_damage.m_frost += hitData.m_damage.m_fire;
hitData.m_damage.m_fire = 0f;
hitData.SetAttacker(Player.m_localPlayer);
if (proj != null)
{
proj.Setup(Player.m_localPlayer, targetDir * vel, -1f, hitData, staffDrop.m_itemData, null);
}
// Turn fire VFX to blue/frost
foreach (ParticleSystem ps in projInstance.GetComponentsInChildren<ParticleSystem>())
{
var main = ps.main;
main.startColor = new Color(0.4f, 0.8f, 1f, 1f); // Ice blue
}
foreach (Light l in projInstance.GetComponentsInChildren<Light>())
{
l.color = new Color(0.4f, 0.8f, 1f, 1f);
}
if (projCount > 1) yield return new WaitForSeconds(0.05f);
}
}
}
}
private void OnDestroy()
{
if (Player.m_localPlayer != null)
{
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(false);
}
}
}
}

View file

@ -0,0 +1,144 @@
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)
{
nameHash = "Cold".GetStableHashCode();
}
}
}
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();
}
}
}
}
}
[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;
}
}
}

View file

@ -0,0 +1,128 @@
using System;
using UnityEngine;
namespace RacesOfValheim
{
public static class SkadiProgression
{
public class FormRules
{
public bool ImmuneToCold = false;
public bool ImmuneToFreezing = false;
public bool FreezingToCold = false;
public bool BonusFrostDamage = false;
public bool FrostAura = false;
public float FrostResistance = 0f;
public float EitrRegenMultiplier = 1f;
public bool ColdSpell = false;
public bool ImprovedColdSpell = false;
public FormType Form = FormType.None;
public float DurationMinutes = 0f;
public float CooldownMinutes = 0f;
public bool CanAttackInForm = false;
}
public enum FormType
{
None,
Drake,
Moder,
SkeletonDragon
}
public static FormRules GetRules(int state)
{
FormRules rules = new FormRules();
if (state >= 1)
{
rules.ImmuneToCold = true;
rules.BonusFrostDamage = true;
rules.FrostResistance = 0.5f; // 50% resistance? Valheim uses DamageModifiers.
// Wait, FrostResistance isn't a percentage, it's a category.
// We'll map this to DamageModifier.Resistant (which is 50% reduction).
}
if (state >= 2)
{
rules.EitrRegenMultiplier = 1.20f;
rules.FreezingToCold = true;
rules.ColdSpell = true;
}
if (state >= 6)
{
rules.EitrRegenMultiplier = 1.50f;
rules.ImmuneToFreezing = true;
rules.FreezingToCold = false; // Immunity overrides conversion
rules.ImprovedColdSpell = true;
}
if (state >= 7)
{
// Immunity to frost damage => DamageModifier.Immune
rules.FrostResistance = 1f; // 1 means Immune in our logic
rules.FrostAura = true;
}
return rules;
}
public static FormRules GetGKeyRules(int state)
{
FormRules rules = new FormRules();
if (state >= 4) // Bonemass
{
rules.Form = FormType.Drake;
rules.CanAttackInForm = true;
}
else if (state >= 3) // Elder
{
rules.Form = FormType.Drake;
rules.CanAttackInForm = false;
}
return rules.Form != FormType.None ? rules : null;
}
public static FormRules GetHKeyRules(int state)
{
FormRules rules = new FormRules();
if (state >= 7) // Queen
{
rules.Form = FormType.Moder;
rules.DurationMinutes = 0f;
rules.CooldownMinutes = 0f;
rules.CanAttackInForm = true;
}
else if (state >= 6) // Yagluth
{
rules.Form = FormType.Moder;
rules.DurationMinutes = 1f;
rules.CooldownMinutes = 5f;
rules.CanAttackInForm = true;
}
else if (state >= 5) // Moder
{
rules.Form = FormType.Moder;
rules.DurationMinutes = 1f;
rules.CooldownMinutes = 10f;
rules.CanAttackInForm = true;
}
return rules.Form != FormType.None ? rules : null;
}
public static FormRules GetJKeyRules(int state)
{
FormRules rules = new FormRules();
if (state >= 8) // Fader
{
rules.Form = FormType.SkeletonDragon;
rules.DurationMinutes = 0f; // Assuming unlimited
rules.CooldownMinutes = 0f;
rules.CanAttackInForm = true;
}
return rules.Form != FormType.None ? rules : null;
}
}
}

View file

@ -0,0 +1,628 @@
using System;
using System.Collections;
using UnityEngine;
using Jotunn.Managers;
using Jotunn.Entities;
namespace RacesOfValheim
{
public class SkadiRace : MonoBehaviour
{
public static SkadiRace Instance;
public static SE_SkadiStats skadiCurseSE;
public static SE_FormCooldown skadiCdSE;
private float auraTimer = 0f;
private float lastSpellTime = 0f;
private GameObject currentTransformation;
private bool isTransformed = false;
private bool isTransformingSequence = false;
private SkadiProgression.FormRules activeRules = null;
private float lastAuraTime = 0f;
private GameObject frostAuraVFX = null;
private void Awake()
{
Instance = this;
}
public void CreateModAssets()
{
var se = ScriptableObject.CreateInstance<SE_SkadiStats>();
se.name = "SE_SkadiStats";
se.m_name = "Skadi's Blessing";
// Icon
GameObject drakeTrophy = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophyHatchling")?.gameObject;
if (drakeTrophy != null)
{
ItemDrop trophyDrop = drakeTrophy.GetComponent<ItemDrop>();
if (trophyDrop != null && trophyDrop.m_itemData.m_shared.m_icons.Length > 0)
{
se.m_icon = trophyDrop.m_itemData.m_shared.m_icons[0];
}
}
CustomStatusEffect skadiStats = new CustomStatusEffect(se, fixReference: false);
ItemManager.Instance.AddStatusEffect(skadiStats);
skadiCurseSE = skadiStats.StatusEffect as SE_SkadiStats;
skadiCdSE = ScriptableObject.CreateInstance<SE_FormCooldown>();
skadiCdSE.name = "SE_SkadiCooldown";
skadiCdSE.m_name = "Dragon Form Cooldown";
if (drakeTrophy != null)
{
ItemDrop trophyDrop = drakeTrophy.GetComponent<ItemDrop>();
if (trophyDrop != null && trophyDrop.m_itemData.m_shared.m_icons.Length > 0)
{
skadiCdSE.m_icon = trophyDrop.m_itemData.m_shared.m_icons[0];
}
}
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(skadiCdSE, fixReference: false));
}
public bool IsSkadi()
{
return Player.m_localPlayer != null &&
Player.m_localPlayer.m_customData.ContainsKey("Race") &&
Player.m_localPlayer.m_customData["Race"] == "Skadi";
}
private void Update()
{
if (!IsSkadi()) return;
if (Player.m_localPlayer.IsDead() && isTransformed)
{
ExecuteReversion();
}
var rules = SkadiProgression.GetRules(BossProgressionManager.GetCurrentProgressionState());
// Update the stats SE
if (skadiCurseSE != null)
{
skadiCurseSE.UpdateStats(rules);
if (!Player.m_localPlayer.GetSEMan().HaveStatusEffect(skadiCurseSE.name.GetStableHashCode()))
{
Player.m_localPlayer.GetSEMan().AddStatusEffect(skadiCurseSE.name.GetStableHashCode(), true);
}
}
if (rules.FrostAura)
{
EnsureFrostAuraVFX(true);
if (Time.time - lastAuraTime >= 1f)
{
ApplyColdAura();
lastAuraTime = Time.time;
}
}
else
{
EnsureFrostAuraVFX(false);
}
if (rules.EitrRegenMultiplier > 1f && !Player.m_localPlayer.IsDead())
{
try
{
var eitrTimerField = HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_eitrRegenTimer");
if (eitrTimerField.FieldExists())
{
float currentTimer = eitrTimerField.GetValue<float>();
if (currentTimer > 0f)
{
float bonus = rules.EitrRegenMultiplier - 1f;
if (bonus > 0f && bonus < 1f)
{
float targetTime = 1f - bonus;
float requiredSpeed = 1f / targetTime;
float additionalSpeed = requiredSpeed - 1f;
eitrTimerField.SetValue(currentTimer - (additionalSpeed * Time.deltaTime));
}
}
}
}
catch (Exception e)
{
// Ignore, to prevent breaking the rest of the Update loop
}
}
if (rules.ColdSpell)
{
HandleColdSpell(rules);
}
if (isTransformingSequence) 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; }
if (Input.GetKeyDown(KeyCode.J)) { TryTransformWithRules(SkadiProgression.GetJKeyRules(state)); return; }
// Debug Dump
if (Input.GetKeyDown(KeyCode.F8))
{
DumpPrefabDebugInfo("Dragon");
DumpPrefabDebugInfo("Hatchling");
DumpPrefabDebugInfo("Fader");
if (Player.m_localPlayer != null) Player.m_localPlayer.Message(MessageHud.MessageType.Center, "Dumped Dragon/Drake/Fader debug info to console!");
}
}
private void DumpPrefabDebugInfo(string prefabName)
{
GameObject prefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(prefabName);
if (prefab == null)
{
Jotunn.Logger.LogWarning($"{prefabName} prefab not found!");
return;
}
Jotunn.Logger.LogInfo($"=== {prefabName.ToUpper()} DEBUG INFO ===");
Animator anim = prefab.GetComponentInChildren<Animator>();
if (anim != null)
{
Jotunn.Logger.LogInfo("--- Animator Parameters ---");
foreach (UnityEngine.AnimatorControllerParameter param in anim.parameters)
{
Jotunn.Logger.LogInfo($"Param: {param.name} (Type: {param.type})");
}
}
Humanoid humanoid = prefab.GetComponent<Humanoid>();
if (humanoid != null)
{
Jotunn.Logger.LogInfo("--- Weapons (Default Items) ---");
if (humanoid.m_defaultItems != null)
{
foreach (GameObject item in humanoid.m_defaultItems)
{
if (item == null) continue;
ItemDrop drop = item.GetComponent<ItemDrop>();
if (drop != null)
{
var attack = drop.m_itemData.m_shared.m_attack;
Jotunn.Logger.LogInfo($"Weapon Prefab: {item.name}");
Jotunn.Logger.LogInfo($" - Attack Anim: {attack.m_attackAnimation}");
if (attack.m_attackProjectile != null)
Jotunn.Logger.LogInfo($" - Projectile: {attack.m_attackProjectile.name}");
}
}
}
Jotunn.Logger.LogInfo("--- Random Weapons ---");
if (humanoid.m_randomWeapon != null)
{
foreach (var item in humanoid.m_randomWeapon)
{
if (item == null) continue;
ItemDrop drop = item.GetComponent<ItemDrop>();
if (drop != null)
{
var attack = drop.m_itemData.m_shared.m_attack;
Jotunn.Logger.LogInfo($"Random Weapon Prefab: {item.name}");
Jotunn.Logger.LogInfo($" - Attack Anim: {attack.m_attackAnimation}");
if (attack.m_attackProjectile != null)
Jotunn.Logger.LogInfo($" - Projectile: {attack.m_attackProjectile.name}");
}
}
}
}
ZSFX[] sfxs = prefab.GetComponentsInChildren<ZSFX>(true);
Jotunn.Logger.LogInfo("--- Sounds (ZSFX) ---");
foreach (ZSFX sfx in sfxs)
{
Jotunn.Logger.LogInfo($"Sound: {sfx.gameObject.name}");
}
Jotunn.Logger.LogInfo($"=== END {prefabName.ToUpper()} DEBUG INFO ===");
}
private void HandleColdSpell(SkadiProgression.FormRules rules)
{
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)
if (Input.GetMouseButtonDown(2))
{
float cooldown = rules.ImprovedColdSpell ? 2.0f : 1.5f;
if (Time.time - lastSpellTime < cooldown) return;
if (!Player.m_localPlayer.HaveEitr(10f))
{
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "Not enough Eitr");
return;
}
Player.m_localPlayer.UseEitr(10f);
lastSpellTime = Time.time;
var zanim = HarmonyLib.Traverse.Create(Player.m_localPlayer).Field<ZSyncAnimation>("m_zanim").Value;
if (zanim != null)
{
// Forcing secondary attack trigger, which is kick when unarmed
zanim.SetTrigger("secondary");
}
StartCoroutine(ColdSpellKickCoroutine(rules));
}
}
private IEnumerator ColdSpellKickCoroutine(SkadiProgression.FormRules rules)
{
// Wait for the kick animation to reach the extension point
yield return new WaitForSeconds(0.4f);
if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) yield break;
GameObject staffPrefab = PrefabManager.Cache.GetPrefab<GameObject>("StaffIceShards");
if (staffPrefab == null) yield break;
ItemDrop staffDrop = staffPrefab.GetComponent<ItemDrop>();
if (staffDrop == null) yield break;
string projName = rules.ImprovedColdSpell ? "hatchling_cold_projectile" : null;
GameObject projPrefab = null;
if (projName != null)
{
projPrefab = PrefabManager.Cache.GetPrefab<GameObject>(projName);
}
if (projPrefab == null)
{
projPrefab = staffDrop.m_itemData.m_shared.m_attack.m_attackProjectile; // Default Staff of Frost projectile
}
if (projPrefab == null) yield break;
int count = rules.ImprovedColdSpell ? 10 : 1;
for (int i = 0; i < count; i++)
{
if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) break;
// Spawn from the foot (low position, 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;
GameObject projInstance = Instantiate(projPrefab, spawnPos, Quaternion.LookRotation(lookDir));
Projectile proj = projInstance.GetComponent<Projectile>();
if (proj != null)
{
HitData hitData = new HitData();
hitData.m_damage = staffDrop.m_itemData.m_shared.m_damages;
hitData.SetAttacker(Player.m_localPlayer);
proj.Setup(Player.m_localPlayer, lookDir * staffDrop.m_itemData.m_shared.m_attack.m_projectileVel, -1f, hitData, staffDrop.m_itemData, null);
}
if (count > 1) yield return new WaitForSeconds(0.05f);
}
}
private void EnsureFrostAuraVFX(bool enable)
{
if (Player.m_localPlayer == null) return;
if (enable)
{
if (frostAuraVFX == null)
{
frostAuraVFX = new GameObject("SkadiFrostAuraVFX");
frostAuraVFX.transform.SetParent(Player.m_localPlayer.transform, false);
frostAuraVFX.transform.localPosition = new Vector3(0, 1f, 0); // Center of player
ParticleSystem ps = frostAuraVFX.AddComponent<ParticleSystem>();
var main = ps.main;
main.duration = 5f;
main.loop = true;
main.startLifetime = 3f;
main.startSpeed = 0.2f; // Slow moving
main.startSize = new ParticleSystem.MinMaxCurve(0.005f, 0.01f); // 1cm max
main.startColor = new Color(0.7f, 0.9f, 1f, 0.4f); // Light blue, semi-transparent
main.maxParticles = 300;
main.simulationSpace = ParticleSystemSimulationSpace.World; // Leaves a trail when walking
var emission = ps.emission;
emission.rateOverTime = 90; // Dense mist
var shape = ps.shape;
shape.shapeType = ParticleSystemShapeType.Sphere;
shape.radius = 3f; // 3 meters radius
var colorOverLifetime = ps.colorOverLifetime;
colorOverLifetime.enabled = true;
Gradient grad = new Gradient();
grad.SetKeys(
new GradientColorKey[] { new GradientColorKey(Color.white, 0.0f), new GradientColorKey(Color.white, 1.0f) },
new GradientAlphaKey[] { new GradientAlphaKey(0.0f, 0.0f), new GradientAlphaKey(1.0f, 0.2f), new GradientAlphaKey(1.0f, 0.8f), new GradientAlphaKey(0.0f, 1.0f) }
);
colorOverLifetime.color = grad;
var renderer = frostAuraVFX.GetComponent<ParticleSystemRenderer>();
// Steal material from an existing Valheim effect
GameObject freezingVfx = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>("vfx_Freezing");
if (freezingVfx != null)
{
ParticleSystemRenderer origRenderer = freezingVfx.GetComponentInChildren<ParticleSystemRenderer>();
if (origRenderer != null)
{
renderer.material = origRenderer.material;
}
}
}
if (!frostAuraVFX.activeSelf)
{
frostAuraVFX.SetActive(true);
}
}
else
{
if (frostAuraVFX != null && frostAuraVFX.activeSelf)
{
frostAuraVFX.SetActive(false);
}
}
}
private void ApplyColdAura()
{
if (Player.m_localPlayer == null) return;
Vector3 center = Player.m_localPlayer.transform.position;
foreach (Character c in Character.GetAllCharacters())
{
if (c == Player.m_localPlayer) continue;
if (c.IsTamed() || c.IsPlayer()) continue;
if (Vector3.Distance(center, c.transform.position) <= 3f)
{
HitData hit = new HitData();
hit.m_damage.m_frost = 10f;
hit.m_point = c.transform.position;
hit.m_dir = (c.transform.position - center).normalized;
hit.SetAttacker(Player.m_localPlayer);
c.ApplyDamage(hit, true, false);
}
}
}
private void TryTransformWithRules(SkadiProgression.FormRules rules)
{
if (rules == null || rules.Form == SkadiProgression.FormType.None) return;
if (isTransformed)
{
StartCoroutine(RevertToHumanRoutine());
return;
}
if (rules.CooldownMinutes > 0)
{
var cdSE = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_SkadiCooldown".GetStableHashCode());
if (cdSE != null)
{
float m_time = HarmonyLib.Traverse.Create(cdSE).Field<float>("m_time").Value;
float remaining = cdSE.m_ttl - m_time;
if (remaining < 0) remaining = 0;
int rMin = Mathf.FloorToInt(remaining / 60f);
int rSec = Mathf.FloorToInt(remaining % 60f);
Player.m_localPlayer.Message(MessageHud.MessageType.Center, $"Dragon Form is on cooldown ({rMin}:{rSec:00}).");
return;
}
}
activeRules = rules;
StartCoroutine(TransformRoutine(rules));
}
private Vector3 GetFormScale(SkadiProgression.FormType form)
{
if (form == SkadiProgression.FormType.Moder) return Vector3.one * 0.5f; // Increased to 50%
if (form == SkadiProgression.FormType.SkeletonDragon) return Vector3.one * 0.55f; // 10% larger than Moder
return Vector3.one * 0.9f; // Drake (reduced by 10%)
}
private IEnumerator TransformRoutine(SkadiProgression.FormRules rules)
{
isTransformingSequence = true;
ZSyncAnimation zAnim = Player.m_localPlayer.GetComponent<ZSyncAnimation>();
if (zAnim != null) zAnim.SetTrigger("gpower");
yield return new WaitForSeconds(1.1f);
SpawnPoofEffect();
ExecuteTransformation(rules);
if (currentTransformation != null)
{
float elapsed = 0f;
float duration = 0.5f;
Vector3 endScale = GetFormScale(rules.Form);
Vector3 startScale = endScale * 0.5f;
currentTransformation.transform.localScale = startScale;
while (elapsed < duration)
{
if (currentTransformation == null) break;
currentTransformation.transform.localScale = Vector3.Lerp(startScale, endScale, elapsed / duration);
elapsed += Time.deltaTime;
yield return null;
}
if (currentTransformation != null) currentTransformation.transform.localScale = endScale;
}
isTransformingSequence = false;
}
private System.Collections.IEnumerator RevertToHumanRoutine()
{
isTransformingSequence = true;
if (Player.m_localPlayer.GetComponent<ZNetView>() != null) {
Player.m_localPlayer.GetComponent<ZNetView>().GetZDO().Set("Skadi_Form", "");
}
if (currentTransformation != null)
{
DrakeFormBehavior drakeBehavior = currentTransformation.GetComponent<DrakeFormBehavior>();
if (drakeBehavior != null) drakeBehavior.enabled = false;
float elapsed = 0f;
float duration = 0.5f;
Vector3 startScale = currentTransformation.transform.localScale;
float endMultiplier = 0.5f;
Vector3 endScale = startScale * endMultiplier;
while (elapsed < duration)
{
if (currentTransformation == null) break;
currentTransformation.transform.localScale = Vector3.Lerp(startScale, endScale, elapsed / duration);
elapsed += Time.deltaTime;
yield return null;
}
}
SpawnPoofEffect();
yield return new WaitForSeconds(0.1f);
ExecuteReversion();
isTransformingSequence = false;
}
private void SpawnPoofEffect()
{
if (Player.m_localPlayer == null) return;
Vector3 pos = Player.m_localPlayer.transform.position + Vector3.up;
GameObject smoke = PrefabManager.Cache.GetPrefab<GameObject>("vfx_corpse_destruction");
if (smoke != null) Instantiate(smoke, pos, Quaternion.identity);
GameObject sparks = PrefabManager.Cache.GetPrefab<GameObject>("vfx_HitSparks");
if (sparks != null) Instantiate(sparks, pos, Quaternion.identity);
}
private void ExecuteTransformation(SkadiProgression.FormRules rules)
{
Transform playerVisual = Player.m_localPlayer.transform.Find("Visual");
string prefabName = "";
switch (rules.Form)
{
case SkadiProgression.FormType.Drake: prefabName = "Hatchling"; break;
case SkadiProgression.FormType.Moder: prefabName = "Dragon"; break;
case SkadiProgression.FormType.SkeletonDragon: prefabName = "Fader"; break;
}
if (Player.m_localPlayer.GetComponent<ZNetView>() != null) {
Player.m_localPlayer.GetComponent<ZNetView>().GetZDO().Set("Skadi_Form", prefabName);
}
GameObject prefab = PrefabManager.Cache.GetPrefab<GameObject>(prefabName);
// Sync to ZDO
ZNetView nview = Player.m_localPlayer.GetComponent<ZNetView>();
if (nview != null && nview.IsValid())
{
nview.GetZDO().Set("RacesOfValheim_SkadiForm", prefabName);
}
if (prefab != null && playerVisual != null)
{
playerVisual.localScale = Vector3.one * 0.001f;
Transform visual = prefab.transform.Find("Visual");
if (visual != null)
{
currentTransformation = Instantiate(visual.gameObject, Player.m_localPlayer.transform);
if (prefabName == "Hatchling")
{
currentTransformation.transform.localPosition = new Vector3(0f, -1.0f, 0f);
}
else if (prefabName == "Fader")
{
// Turn Fader into a Frost Skeleton Dragon
foreach (Renderer r in currentTransformation.GetComponentsInChildren<Renderer>())
{
if (r.material != null)
{
r.material.SetColor("_Color", new Color(0.6f, 0.8f, 1f, 1f));
if (r.material.HasProperty("_EmissionColor"))
{
r.material.SetColor("_EmissionColor", new Color(0f, 0.5f, 1f, 1f));
}
}
}
}
else
{
currentTransformation.transform.localPosition = Vector3.zero;
}
currentTransformation.transform.localRotation = Quaternion.identity;
// Keep AnimEvent so native sounds (footsteps, attack shouts) play correctly!
DrakeFormBehavior behavior = currentTransformation.AddComponent<DrakeFormBehavior>();
behavior.Initialize(rules);
if (prefabName == "Hatchling") Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You are a Drake!");
else if (prefabName == "Dragon") Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You are Moder!");
else if (prefabName == "Fader") Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You are Fader!");
isTransformed = true;
}
}
}
private void ExecuteReversion()
{
Transform playerVisual = Player.m_localPlayer.transform.Find("Visual");
if (currentTransformation != null) Destroy(currentTransformation);
// Sync to ZDO
ZNetView nview = Player.m_localPlayer.GetComponent<ZNetView>();
if (nview != null && nview.IsValid())
{
nview.GetZDO().Set("RacesOfValheim_SkadiForm", "");
}
var forms1 = Player.m_localPlayer.GetComponentsInChildren<DrakeFormBehavior>(true);
foreach (var f in forms1) Destroy(f.gameObject);
if (playerVisual != null)
{
playerVisual.localScale = Vector3.one;
playerVisual.gameObject.SetActive(true);
}
isTransformed = false;
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You returned to human form.");
if (activeRules != null && activeRules.CooldownMinutes > 0)
{
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_SkadiCooldown".GetStableHashCode(), true);
var cdSE = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_SkadiCooldown".GetStableHashCode());
if (cdSE != null) cdSE.m_ttl = activeRules.CooldownMinutes * 60f;
}
activeRules = null;
}
}
}

View file

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace RacesOfValheim
{
public class SE_SkadiStats : SE_Stats
{
public override void Setup(Character character)
{
base.Setup(character);
name = "SE_SkadiStats";
m_name = "Skadi's Aura";
m_tooltip = "Empowered by the frost.";
}
public void UpdateStats(SkadiProgression.FormRules rules)
{
m_mods = new List<HitData.DamageModPair>();
if (rules.FrostResistance >= 1f)
{
m_mods.Add(new HitData.DamageModPair() { m_type = HitData.DamageType.Frost, m_modifier = HitData.DamageModifier.Immune });
}
else if (rules.FrostResistance >= 0.5f)
{
m_mods.Add(new HitData.DamageModPair() { m_type = HitData.DamageType.Frost, m_modifier = HitData.DamageModifier.Resistant });
}
m_eitrRegenMultiplier = rules.EitrRegenMultiplier;
}
}
}

View file

@ -0,0 +1 @@
// Add logic to SkadiRace.cs using powershell