The ready flag becomes an int: none, a form, or the Cultist. The Cultist wins only while its rules give it a cooldown (Yagluth and Queen), since that is the one return worth announcing. Its body shares the Fenring's material and its breath is white flame tinted by texture, so the colour comes from its death effect: FlameRoundYellowParticle's emission, (2.691, 1.797, 0.455), bundle c4210710.
632 lines
32 KiB
C#
632 lines
32 KiB
C#
using System;
|
|
using System.Collections;
|
|
using Jotunn.Configs;
|
|
using Jotunn.Entities;
|
|
using Jotunn.Managers;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim {
|
|
public class FenrirRace : MonoBehaviour {
|
|
public static FenrirRace Instance;
|
|
public static SE_FenrirCurse curseSE;
|
|
public static SE_Stats formBuffSE;
|
|
public static SE_Stats wolfFormBuffSE;
|
|
public static SE_Stats cultistFormBuffSE;
|
|
public static SE_FormCooldown fenrirCdSE;
|
|
public static SE_FormCooldown cultistCdSE;
|
|
|
|
private GameObject currentTransformation;
|
|
private bool isTransformed = false;
|
|
private bool isTransformingSequence = false;
|
|
|
|
private FenrirProgression.FormRules activeRules = null;
|
|
private bool wasNight = false;
|
|
private float sunSicknessTimer = 0f;
|
|
// Said instead of the usual "back to human" line by the next reversion, then cleared.
|
|
private string revertMessage;
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
public void CreateModAssets()
|
|
{
|
|
// The pack trough and its bloodline. Registered here because the faction merchant
|
|
// catalogue resolves its entries by prefab name, so both Ulvsblod have to exist before a
|
|
// Fenring is ever set up as a bench.
|
|
FenrirMangiatoia.Register();
|
|
|
|
// Same window, same reason: this method runs on PrefabManager.OnVanillaPrefabsAvailable,
|
|
// which is the one moment Jotunn will take a new item into ObjectDB. Registered later
|
|
// the prefab exists, logs its success, and cannot be spawned by anyone.
|
|
FenrirClaws.Instance.EnsureRegistered();
|
|
|
|
curseSE = ScriptableObject.CreateInstance<SE_FenrirCurse>();
|
|
curseSE.name = "SE_FenrirCurse";
|
|
curseSE.m_name = "$rov_se_fenrir_curse_name";
|
|
curseSE.m_tooltip = "$rov_se_fenrir_curse_tooltip";
|
|
curseSE.m_mods = new System.Collections.Generic.List<HitData.DamageModPair>()
|
|
{
|
|
new HitData.DamageModPair() { m_type = HitData.DamageType.Spirit, m_modifier = HitData.DamageModifier.Weak }
|
|
};
|
|
|
|
GameObject fenringTrophy = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophyFenring")?.gameObject;
|
|
Sprite fenringTrophyIcon = null;
|
|
if (fenringTrophy != null)
|
|
{
|
|
ItemDrop trophyDrop = fenringTrophy.GetComponent<ItemDrop>();
|
|
if (trophyDrop != null && trophyDrop.m_itemData.m_shared.m_icons.Length > 0)
|
|
{
|
|
fenringTrophyIcon = trophyDrop.m_itemData.m_shared.m_icons[0];
|
|
curseSE.m_icon = fenringTrophyIcon;
|
|
}
|
|
}
|
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(curseSE, fixReference: false));
|
|
|
|
fenrirCdSE = ScriptableObject.CreateInstance<SE_FormCooldown>();
|
|
fenrirCdSE.name = "SE_FenrirCooldown";
|
|
fenrirCdSE.m_name = "$rov_se_fenrir_formcd_name";
|
|
fenrirCdSE.m_icon = fenringTrophyIcon;
|
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(fenrirCdSE, fixReference: false));
|
|
|
|
cultistCdSE = ScriptableObject.CreateInstance<SE_FormCooldown>();
|
|
cultistCdSE.name = "SE_CultistCooldown";
|
|
cultistCdSE.m_name = "$rov_se_fenrir_cultistcd_name";
|
|
cultistCdSE.m_icon = fenringTrophyIcon;
|
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(cultistCdSE, fixReference: false));
|
|
|
|
formBuffSE = ScriptableObject.CreateInstance<SE_Stats>();
|
|
formBuffSE.name = "SE_FenrirForm";
|
|
formBuffSE.m_name = "$rov_se_fenrir_form_name";
|
|
formBuffSE.m_speedModifier = FenrirConfig.FullFormSpeedBonus.Value;
|
|
formBuffSE.m_jumpModifier = new Vector3(0, FenrirConfig.FullFormJumpBonus.Value, 0);
|
|
formBuffSE.m_fallDamageModifier = -FenrirConfig.FullFormFallDamageReduction.Value;
|
|
formBuffSE.m_staminaRegenMultiplier = FenrirConfig.FormStaminaRegenMultiplier.Value;
|
|
formBuffSE.m_runStaminaDrainModifier = -FenrirConfig.FormStaminaDrainReduction.Value;
|
|
formBuffSE.m_icon = fenringTrophyIcon;
|
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(formBuffSE, fixReference: false));
|
|
|
|
cultistFormBuffSE = ScriptableObject.CreateInstance<SE_Stats>();
|
|
cultistFormBuffSE.name = "SE_CultistForm";
|
|
cultistFormBuffSE.m_name = "$rov_se_fenrir_cultistform_name";
|
|
cultistFormBuffSE.m_speedModifier = FenrirConfig.FullFormSpeedBonus.Value;
|
|
cultistFormBuffSE.m_jumpModifier = new Vector3(0, FenrirConfig.FullFormJumpBonus.Value, 0);
|
|
cultistFormBuffSE.m_fallDamageModifier = -FenrirConfig.FullFormFallDamageReduction.Value;
|
|
cultistFormBuffSE.m_staminaRegenMultiplier = FenrirConfig.FormStaminaRegenMultiplier.Value;
|
|
cultistFormBuffSE.m_runStaminaDrainModifier = -FenrirConfig.FormStaminaDrainReduction.Value;
|
|
cultistFormBuffSE.m_icon = fenringTrophyIcon;
|
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(cultistFormBuffSE, fixReference: false));
|
|
|
|
wolfFormBuffSE = ScriptableObject.CreateInstance<SE_Stats>();
|
|
wolfFormBuffSE.name = "SE_WolfForm";
|
|
wolfFormBuffSE.m_name = "$rov_se_fenrir_wolfform_name";
|
|
wolfFormBuffSE.m_speedModifier = FenrirConfig.WolfFormSpeedBonus.Value;
|
|
wolfFormBuffSE.m_fallDamageModifier = -FenrirConfig.WolfFormFallDamageReduction.Value;
|
|
wolfFormBuffSE.m_staminaRegenMultiplier = FenrirConfig.FormStaminaRegenMultiplier.Value;
|
|
wolfFormBuffSE.m_runStaminaDrainModifier = -FenrirConfig.FormStaminaDrainReduction.Value;
|
|
wolfFormBuffSE.m_icon = fenringTrophyIcon;
|
|
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(wolfFormBuffSE, fixReference: false));
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Player.m_localPlayer == null || EnvMan.instance == null) return;
|
|
if (isTransformingSequence) return;
|
|
if (!Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_FenrirCurse".GetStableHashCode())) return;
|
|
|
|
if (sunSicknessTimer > 0f)
|
|
{
|
|
sunSicknessTimer -= Time.deltaTime;
|
|
}
|
|
|
|
bool isNight = EnvMan.IsNight();
|
|
if (isNight && !wasNight)
|
|
{
|
|
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_FenrirCooldown".GetStableHashCode());
|
|
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_CultistCooldown".GetStableHashCode());
|
|
|
|
var fenrirSE = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_FenrirForm".GetStableHashCode());
|
|
if (fenrirSE != null) fenrirSE.m_ttl = 0f;
|
|
|
|
var cultistSE = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_CultistForm".GetStableHashCode());
|
|
if (cultistSE != null) cultistSE.m_ttl = 0f;
|
|
|
|
var wolfSE = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_WolfForm".GetStableHashCode());
|
|
if (wolfSE != null) wolfSE.m_ttl = 0f;
|
|
}
|
|
else if (!isNight && wasNight)
|
|
{
|
|
// Sunrise: a form that was granted for the night only is taken back, and the
|
|
// beast is tired for a while. A form the progression lets through by day (Queen's
|
|
// Fenrir, Fader's Cultist, Bonemass's Wolf) is not the sun's to take: activeRules is
|
|
// what the transform was actually granted under.
|
|
if (activeRules == null || activeRules.NeedsNight)
|
|
{
|
|
sunSicknessTimer = FenrirConfig.SunSicknessDuration.Value;
|
|
if (isTransformed) revertMessage = SunTookFormMessage();
|
|
ForceRevert();
|
|
}
|
|
}
|
|
wasNight = isNight;
|
|
|
|
FenrirVisuals.SetReady(Player.m_localPlayer, GetReadyState());
|
|
|
|
if (isTransformed)
|
|
{
|
|
bool hasAnyForm = Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_FenrirForm".GetStableHashCode()) ||
|
|
Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_CultistForm".GetStableHashCode()) ||
|
|
Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_WolfForm".GetStableHashCode());
|
|
if (!hasAnyForm)
|
|
{
|
|
ForceRevert();
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (!RaceInput.Allowed) return;
|
|
|
|
int state = BossProgressionManager.GetCurrentProgressionState();
|
|
|
|
if (FenrirConfig.WolfFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(FenrirProgression.GetGKeyRules(state)); return; }
|
|
if (FenrirConfig.FenrirFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(FenrirProgression.GetHKeyRules(state)); return; }
|
|
if (FenrirConfig.CultistFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(FenrirProgression.GetJKeyRules(state)); return; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// What the eyes should say right now, using the same gates as TryTransformWithRules
|
|
/// below without its messages. The Cultist wins over the other forms only while its rules
|
|
/// give it a cooldown: that is the one form whose return is worth announcing.
|
|
/// </summary>
|
|
private FenrirVisuals.ReadyState GetReadyState()
|
|
{
|
|
if (isTransformed) return FenrirVisuals.ReadyState.None;
|
|
|
|
int state = BossProgressionManager.GetCurrentProgressionState();
|
|
FenrirProgression.FormRules cultist = FenrirProgression.GetJKeyRules(state);
|
|
|
|
if (CanTake(cultist) && cultist.CooldownMinutes > 0) return FenrirVisuals.ReadyState.Cultist;
|
|
|
|
if (CanTake(FenrirProgression.GetGKeyRules(state))
|
|
|| CanTake(FenrirProgression.GetHKeyRules(state))
|
|
|| CanTake(cultist))
|
|
{
|
|
return FenrirVisuals.ReadyState.Form;
|
|
}
|
|
return FenrirVisuals.ReadyState.None;
|
|
}
|
|
|
|
private bool CanTake(FenrirProgression.FormRules rules)
|
|
{
|
|
if (rules == null || rules.Form == FenrirProgression.FormType.None) return false;
|
|
if (rules.NeedsNight && (sunSicknessTimer > 0f || !EnvMan.IsNight())) return false;
|
|
|
|
if (rules.CooldownMinutes > 0)
|
|
{
|
|
string cdName = rules.Form == FenrirProgression.FormType.Cultist ? "SE_CultistCooldown" : "SE_FenrirCooldown";
|
|
if (Player.m_localPlayer.GetSEMan().HaveStatusEffect(cdName.GetStableHashCode())) return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void TryTransformWithRules(FenrirProgression.FormRules rules)
|
|
{
|
|
if (rules == null || rules.Form == FenrirProgression.FormType.None) return;
|
|
|
|
// The tiredness is the sun's doing, so it only stands in the way of a night form; the
|
|
// forms allowed by day would otherwise be locked out right after every sunrise.
|
|
if (rules.NeedsNight && sunSicknessTimer > 0f)
|
|
{
|
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_beast_tired"));
|
|
return;
|
|
}
|
|
|
|
if (isTransformed)
|
|
{
|
|
RunFormRoutine(RevertToHumanRoutine());
|
|
return;
|
|
}
|
|
|
|
if (rules.NeedsNight && !EnvMan.IsNight())
|
|
{
|
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_beast_rests_can_only_transform"));
|
|
return;
|
|
}
|
|
|
|
if (rules.CooldownMinutes > 0)
|
|
{
|
|
string cdName = rules.Form == FenrirProgression.FormType.Cultist ? "SE_CultistCooldown" : "SE_FenrirCooldown";
|
|
var cdSE = Player.m_localPlayer.GetSEMan().GetStatusEffect(cdName.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);
|
|
// A token, which the message's own localization pass translates along with the rest.
|
|
string formName = rules.Form == FenrirProgression.FormType.Cultist ? "$rov_msg_fenrir_formname_cultist" : "$rov_msg_fenrir_formname_fenrir";
|
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_form_cooldown", formName, rMin, (rSec).ToString("00")));
|
|
return;
|
|
}
|
|
}
|
|
|
|
RunFormRoutine(TransformIntoWolfRoutine(rules));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Says why sunrise took the form, and which key still works by day.
|
|
///
|
|
/// A player reported this as a bug: "sometimes" the day turned them human even though they
|
|
/// had unlocked day forms. Which forms go by day depends on the key as well as the tier - at
|
|
/// Moder the Ulv on the Wolf key walks by day while the Fenring on the Fenrir key is still
|
|
/// night-only - so from the outside the same sunrise looked random. The rule stays; this
|
|
/// makes it readable. Shown in place of "You returned to human form", which would otherwise
|
|
/// replace it on screen half a second later.
|
|
/// </summary>
|
|
private static string SunTookFormMessage()
|
|
{
|
|
int state = BossProgressionManager.GetCurrentProgressionState();
|
|
string[] day = DayFormFor(FenrirProgression.GetGKeyRules(state), FenrirConfig.WolfFormKey.Value)
|
|
?? DayFormFor(FenrirProgression.GetHKeyRules(state), FenrirConfig.FenrirFormKey.Value)
|
|
?? DayFormFor(FenrirProgression.GetJKeyRules(state), FenrirConfig.CultistFormKey.Value);
|
|
|
|
return day != null
|
|
? ModText.Get("rov_msg_fenrir_sun_takes_form_day_key", day[0], day[1])
|
|
: ModText.Get("rov_msg_fenrir_sun_takes_form");
|
|
}
|
|
|
|
// The form's name token and the key, or null when that key's form is night-only too.
|
|
private static string[] DayFormFor(FenrirProgression.FormRules rules, BepInEx.Configuration.KeyboardShortcut key)
|
|
{
|
|
if (rules == null || rules.Form == FenrirProgression.FormType.None || rules.NeedsNight) return null;
|
|
return new[] { FormNameToken(rules.Form), key.ToString() };
|
|
}
|
|
|
|
private static string FormNameToken(FenrirProgression.FormType form)
|
|
{
|
|
switch (form)
|
|
{
|
|
case FenrirProgression.FormType.Wolf: return "$rov_msg_fenrir_formname_wolf";
|
|
case FenrirProgression.FormType.Ulv: return "$rov_msg_fenrir_formname_ulv";
|
|
case FenrirProgression.FormType.Cultist: return "$rov_msg_fenrir_formname_cultist";
|
|
}
|
|
return "$rov_msg_fenrir_formname_fenrir";
|
|
}
|
|
|
|
// The one transform or revert routine in flight, if any, so ResetRace can stop it. A
|
|
// revert left to finish on its own lands its cooldown after the reset has already swept
|
|
// the status effects, and the next Fenrir starts locked out.
|
|
private Coroutine formRoutine;
|
|
|
|
private void RunFormRoutine(IEnumerator routine)
|
|
{
|
|
formRoutine = StartCoroutine(routine);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Drops whatever form is up, immediately, for ResetRace: no poof, no message, and no
|
|
/// cooldown - ExecuteReversion hands one out, which is right for a form running out and
|
|
/// wrong for a player leaving the race.
|
|
/// </summary>
|
|
/// <returns>True if there was a form to drop.</returns>
|
|
public bool HardResetForReset()
|
|
{
|
|
Player player = Player.m_localPlayer;
|
|
if (player == null) return false;
|
|
|
|
if (formRoutine != null)
|
|
{
|
|
StopCoroutine(formRoutine);
|
|
formRoutine = null;
|
|
}
|
|
|
|
bool hadForm = isTransformed || isTransformingSequence || currentTransformation != null;
|
|
if (hadForm)
|
|
{
|
|
if (currentTransformation != null) Destroy(currentTransformation);
|
|
currentTransformation = null;
|
|
DestroyAllForms();
|
|
|
|
ZNetView nview = player.GetComponent<ZNetView>();
|
|
if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_FenrirForm", "");
|
|
|
|
PlayerVisualHider.Show(player.transform.Find("Visual"), "fenrir-reset");
|
|
|
|
player.GetSEMan().RemoveStatusEffect("SE_FenrirForm".GetStableHashCode());
|
|
player.GetSEMan().RemoveStatusEffect("SE_CultistForm".GetStableHashCode());
|
|
player.GetSEMan().RemoveStatusEffect("SE_WolfForm".GetStableHashCode());
|
|
}
|
|
|
|
FenrirForms.LocalAttacking = false;
|
|
isTransformed = false;
|
|
isTransformingSequence = false;
|
|
activeRules = null;
|
|
revertMessage = null;
|
|
sunSicknessTimer = 0f;
|
|
return hadForm;
|
|
}
|
|
|
|
public void ForceRevert()
|
|
{
|
|
if (isTransformed && !isTransformingSequence)
|
|
{
|
|
RunFormRoutine(RevertToHumanRoutine());
|
|
}
|
|
}
|
|
|
|
private IEnumerator TransformIntoWolfRoutine(FenrirProgression.FormRules rules)
|
|
{
|
|
isTransformingSequence = true;
|
|
activeRules = rules;
|
|
|
|
ZSyncAnimation zAnim = Player.m_localPlayer.GetComponent<ZSyncAnimation>();
|
|
if (zAnim != null)
|
|
{
|
|
RaceInput.SuppressGuardianPowerBriefly();
|
|
zAnim.SetTrigger("gpower");
|
|
}
|
|
|
|
yield return new WaitForSeconds(1.1f);
|
|
|
|
SpawnPoofEffect();
|
|
|
|
// The howl of the creature being turned into, read off that creature. This used to look
|
|
// for "sfx_wolf_howl" and fall back to "sfx_fenring_idle": the first is not a prefab in
|
|
// this game, and the second is real but is the creature's ambient grunt, so every
|
|
// transformation announced itself with a small idle noise. FenrirCreatureSound exists for
|
|
// exactly this - see the note at the top of FenrirBehaviors for how it reads a creature's
|
|
// own voice off BaseAI.m_alertedEffects, which is the only route the Wolf and the Ulv
|
|
// have. The two Fenring forms could do better: vanilla does ship "sfx_fenring_howl", a
|
|
// real howl rather than an alert bark, and preferring it when it exists would cost four
|
|
// lines here.
|
|
FenrirCreatureSound.PlayHowl(CreaturePrefabFor(rules.Form), Player.m_localPlayer.transform.position);
|
|
|
|
yield return new WaitForSeconds(0.1f);
|
|
|
|
ExecuteTransformation(rules);
|
|
|
|
if (currentTransformation != null && currentTransformation.GetComponent<WolfFormBehavior>() == null && currentTransformation.GetComponent<UlvFormBehavior>() == null)
|
|
{
|
|
float elapsed = 0f;
|
|
float duration = 0.5f;
|
|
float startMultiplier = 0.5f;
|
|
Vector3 startScale = Vector3.one * startMultiplier;
|
|
Vector3 endScale = Vector3.one;
|
|
|
|
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 IEnumerator RevertToHumanRoutine()
|
|
{
|
|
isTransformingSequence = true;
|
|
|
|
if (currentTransformation != null)
|
|
{
|
|
FenrirFormBehavior fenrirBehavior = currentTransformation.GetComponent<FenrirFormBehavior>();
|
|
if (fenrirBehavior != null) fenrirBehavior.enabled = false;
|
|
|
|
CultistFormBehavior cultistBehavior = currentTransformation.GetComponent<CultistFormBehavior>();
|
|
if (cultistBehavior != null) cultistBehavior.enabled = false;
|
|
|
|
WolfFormBehavior wolfBehavior = currentTransformation.GetComponent<WolfFormBehavior>();
|
|
if (wolfBehavior != null) wolfBehavior.enabled = false;
|
|
|
|
UlvFormBehavior ulvBehavior = currentTransformation.GetComponent<UlvFormBehavior>();
|
|
if (ulvBehavior != null) ulvBehavior.enabled = false;
|
|
|
|
if (wolfBehavior == null && ulvBehavior == null)
|
|
{
|
|
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;
|
|
|
|
// Vanilla's puff carries a size suffix and has no bare "vfx_corpse_destruction" - so
|
|
// this used to resolve to nothing and the body swap happened in plain view, with only
|
|
// the sparks below to soften it. _medium is the one built for a body this size.
|
|
GameObject smoke = PrefabManager.Cache.GetPrefab<GameObject>("vfx_corpse_destruction_medium");
|
|
if (smoke != null) Instantiate(smoke, pos, Quaternion.identity);
|
|
|
|
GameObject sparks = PrefabManager.Cache.GetPrefab<GameObject>("vfx_HitSparks");
|
|
if (sparks != null) Instantiate(sparks, pos, Quaternion.identity);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The vanilla creature a form is built from. One place rather than two, because the howl
|
|
/// that announces a transformation has to be read off the same creature the body comes from.
|
|
/// </summary>
|
|
private static string CreaturePrefabFor(FenrirProgression.FormType form)
|
|
{
|
|
switch (form)
|
|
{
|
|
case FenrirProgression.FormType.Wolf: return "Wolf";
|
|
case FenrirProgression.FormType.Ulv: return "Ulv";
|
|
case FenrirProgression.FormType.Fenring: return "Fenring";
|
|
case FenrirProgression.FormType.Cultist: return "Fenring_Cultist";
|
|
}
|
|
return "";
|
|
}
|
|
|
|
private void ExecuteTransformation(FenrirProgression.FormRules rules)
|
|
{
|
|
Transform playerVisual = Player.m_localPlayer.transform.Find("Visual");
|
|
string prefabName = CreaturePrefabFor(rules.Form);
|
|
|
|
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_FenrirForm", prefabName);
|
|
}
|
|
|
|
if (prefab != null && playerVisual != null)
|
|
{
|
|
// Shrinking the Visual to nothing was how this hid the human body, and it stopped
|
|
// working: the scale reset that keeps a non-Trol player at normal size runs from a
|
|
// postfix on this same update and puts it straight back to 1, so the man reappeared
|
|
// standing inside his own wolf. Hide the renderers instead - that is what Skadi and
|
|
// the Aswid already do, and nothing resets it.
|
|
PlayerVisualHider.Hide(playerVisual, "fenrir-local-form");
|
|
|
|
Transform visual = prefab.transform.Find("Visual");
|
|
if (visual != null)
|
|
{
|
|
currentTransformation = Instantiate(visual.gameObject, Player.m_localPlayer.transform);
|
|
currentTransformation.transform.localPosition = Vector3.zero;
|
|
currentTransformation.transform.localRotation = Quaternion.identity;
|
|
// DEAD LINE, kept until somebody decides what it was for. The game has no type
|
|
// called "AnimEvent" - the animation-event dispatcher is CharacterAnimEvent - and
|
|
// GetComponent(string) matches a type name in full, so this has never found
|
|
// anything and the Destroy has never run.
|
|
Component animEvent = currentTransformation.GetComponent("AnimEvent");
|
|
if (animEvent != null) Destroy(animEvent);
|
|
|
|
FormFootsteps.Detach(currentTransformation, prefabName);
|
|
|
|
// The creature's own animations carry their sounds as events; this is what hears
|
|
// them. On the object that owns the Animator, because that is where Unity delivers
|
|
// an animation event - for the wolf that is WolfSmooth, two levels down, not the
|
|
// Visual this method has in hand.
|
|
Animator formAnimator = currentTransformation.GetComponentInChildren<Animator>(true);
|
|
if (formAnimator != null)
|
|
{
|
|
formAnimator.gameObject.AddComponent<FormAnimEventSound>();
|
|
Jotunn.Logger.LogInfo(
|
|
$"[FenrirForm] animation-event listener on '{formAnimator.gameObject.name}'.");
|
|
}
|
|
else
|
|
{
|
|
Jotunn.Logger.LogWarning(
|
|
"[FenrirForm] no Animator under the form; animation sounds will not play.");
|
|
}
|
|
|
|
float ttl = rules.DurationMinutes > 0 ? (rules.DurationMinutes * 60f) : 0f;
|
|
|
|
if (prefabName == "Ulv")
|
|
{
|
|
currentTransformation.AddComponent<UlvFormBehavior>();
|
|
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_WolfForm".GetStableHashCode(), true);
|
|
var se = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_WolfForm".GetStableHashCode());
|
|
if (se != null) se.m_ttl = ttl;
|
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_are_ulv"));
|
|
}
|
|
else if (prefabName == "Wolf")
|
|
{
|
|
currentTransformation.AddComponent<WolfFormBehavior>();
|
|
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_WolfForm".GetStableHashCode(), true);
|
|
var se = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_WolfForm".GetStableHashCode());
|
|
if (se != null) se.m_ttl = ttl;
|
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_are_wolf"));
|
|
}
|
|
else if (prefabName == "Fenring_Cultist")
|
|
{
|
|
currentTransformation.AddComponent<CultistFormBehavior>();
|
|
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_CultistForm".GetStableHashCode(), true);
|
|
var se = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_CultistForm".GetStableHashCode());
|
|
if (se != null) se.m_ttl = ttl;
|
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_are_cultist"));
|
|
}
|
|
else
|
|
{
|
|
currentTransformation.AddComponent<FenrirFormBehavior>();
|
|
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_FenrirForm".GetStableHashCode(), true);
|
|
var se = Player.m_localPlayer.GetSEMan().GetStatusEffect("SE_FenrirForm".GetStableHashCode());
|
|
if (se != null) se.m_ttl = ttl;
|
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_are_fenring"));
|
|
}
|
|
|
|
isTransformed = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void DestroyAllForms()
|
|
{
|
|
if (Player.m_localPlayer == null) return;
|
|
var forms1 = Player.m_localPlayer.GetComponentsInChildren<FenrirFormBehavior>(true);
|
|
foreach (var f in forms1) Destroy(f.gameObject);
|
|
|
|
var forms2 = Player.m_localPlayer.GetComponentsInChildren<CultistFormBehavior>(true);
|
|
foreach (var f in forms2) Destroy(f.gameObject);
|
|
|
|
var forms3 = Player.m_localPlayer.GetComponentsInChildren<WolfFormBehavior>(true);
|
|
foreach (var f in forms3) Destroy(f.gameObject);
|
|
|
|
var forms4 = Player.m_localPlayer.GetComponentsInChildren<UlvFormBehavior>(true);
|
|
foreach (var f in forms4) Destroy(f.gameObject);
|
|
}
|
|
|
|
private void ExecuteReversion()
|
|
{
|
|
Transform playerVisual = Player.m_localPlayer.transform.Find("Visual");
|
|
if (currentTransformation != null) Destroy(currentTransformation);
|
|
DestroyAllForms(); // Safety check to remove any leaked forms
|
|
|
|
// Sync to ZDO
|
|
ZNetView nview = Player.m_localPlayer.GetComponent<ZNetView>();
|
|
if (nview != null && nview.IsValid())
|
|
{
|
|
nview.GetZDO().Set("RacesOfValheim_FenrirForm", "");
|
|
}
|
|
|
|
// Show undoes the scale and the SetActive of the older hiding paths as well, so a form
|
|
// entered before this change still reverts cleanly.
|
|
PlayerVisualHider.Show(playerVisual, "fenrir-local-revert");
|
|
|
|
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_FenrirForm".GetStableHashCode());
|
|
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_CultistForm".GetStableHashCode());
|
|
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_WolfForm".GetStableHashCode());
|
|
|
|
FenrirForms.LocalAttacking = false;
|
|
isTransformed = false;
|
|
Player.m_localPlayer.Message(MessageHud.MessageType.Center, revertMessage ?? ModText.Get("rov_msg_fenrir_returned_human_form"));
|
|
revertMessage = null;
|
|
|
|
if (activeRules != null && activeRules.CooldownMinutes > 0)
|
|
{
|
|
string cdName = activeRules.Form == FenrirProgression.FormType.Cultist ? "SE_CultistCooldown" : "SE_FenrirCooldown";
|
|
Player.m_localPlayer.GetSEMan().AddStatusEffect(cdName.GetStableHashCode(), true);
|
|
var cdSE = Player.m_localPlayer.GetSEMan().GetStatusEffect(cdName.GetStableHashCode());
|
|
if (cdSE != null) cdSE.m_ttl = activeRules.CooldownMinutes * 60f;
|
|
}
|
|
activeRules = null;
|
|
}
|
|
}
|
|
}
|