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.
682 lines
28 KiB
C#
682 lines
28 KiB
C#
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;
|
|
public static SE_SkadiForm skadiFormSE;
|
|
private float auraTimer = 0f;
|
|
private float lastSpellTime = 0f;
|
|
|
|
private GameObject currentTransformation;
|
|
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;
|
|
|
|
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;
|
|
|
|
// 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<SE_FormCooldown>();
|
|
skadiCdSE.name = "SE_SkadiCooldown";
|
|
skadiCdSE.m_name = "Dragon Form Cooldown";
|
|
skadiCdSE.m_icon = dragonIcon;
|
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(skadiCdSE, fixReference: false));
|
|
|
|
skadiFormSE = ScriptableObject.CreateInstance<SE_SkadiForm>();
|
|
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<ItemDrop>(prefabName)?.gameObject;
|
|
ItemDrop drop = trophy != null ? trophy.GetComponent<ItemDrop>() : null;
|
|
if (drop != null && drop.m_itemData.m_shared.m_icons.Length > 0)
|
|
{
|
|
return drop.m_itemData.m_shared.m_icons[0];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
// 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;
|
|
}
|
|
|
|
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
|
|
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)
|
|
{
|
|
// 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));
|
|
}
|
|
}
|
|
|
|
private IEnumerator ColdSpellKickCoroutine(SkadiProgression.FormRules rules)
|
|
{
|
|
// 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;
|
|
|
|
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 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 * 1.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;
|
|
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");
|
|
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;
|
|
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)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|