Merge branch 'feat-fenrir-eye-glow': Fenrir eyes glow at night, bright when a form is ready
This commit is contained in:
commit
e5a9dc0046
5 changed files with 337 additions and 1 deletions
|
|
@ -28,6 +28,7 @@ namespace RacesOfValheim
|
|||
{
|
||||
"Aswid - Claws",
|
||||
"Aswid - Eyes",
|
||||
"Fenrir - Appearance",
|
||||
"Skeleton - Visuals",
|
||||
"Sverm - Dorsal Spines",
|
||||
"Sverm - Emberform",
|
||||
|
|
|
|||
|
|
@ -85,6 +85,12 @@ namespace RacesOfValheim
|
|||
// ─── Debug ─────────────────────────────────────────────────────────────
|
||||
public static ConfigEntry<bool> DebugFormHits;
|
||||
|
||||
// ─── Appearance (per player, never synced) ──────────────────────────────
|
||||
public static ConfigEntry<bool> ReadyMessage;
|
||||
public static ConfigEntry<bool> EyeGlow;
|
||||
public static ConfigEntry<float> EyeNightStrength;
|
||||
public static ConfigEntry<float> EyeReadyStrength;
|
||||
|
||||
public static void Bind(ConfigFile config)
|
||||
{
|
||||
const string keybinds = "Fenrir - Keybinds";
|
||||
|
|
@ -188,6 +194,20 @@ namespace RacesOfValheim
|
|||
UlvPushForce = config.Bind(ulv, "Push Force", 25f,
|
||||
new ConfigDescription("Knockback applied on a hit.", new AcceptableValueRange<float>(0f, 100f)));
|
||||
|
||||
// The whole section stays local - see ConfigSync.LocalSections.
|
||||
const string appearance = "Fenrir - Appearance";
|
||||
ReadyMessage = config.Bind(appearance, "Ready Message", true,
|
||||
new ConfigDescription("Shows \"<form> is Ready!\" when a form's cooldown ends. The eyes say the same thing; turn this off if they are enough."));
|
||||
EyeGlow = config.Bind(appearance, "Eye Glow", true,
|
||||
new ConfigDescription("Fenrir eyes glow at night in the Fenring's own orange: faint while no form can be taken, bright when one can, yellow when the Cultist is back from its cooldown. Off hides them on every Fenrir you see."));
|
||||
// Above 0.5 so the red channel (2.0 x strength) passes 1 and the bloom pass picks it
|
||||
// up: at 0.35 the faint state read as no glow at all. 0.675 is what looked right in game.
|
||||
EyeNightStrength = config.Bind(appearance, "Eye Night Strength", 0.675f,
|
||||
new ConfigDescription("Glow at night while no form is ready.", new AcceptableValueRange<float>(0f, 3f)));
|
||||
// Tried at 1.2 in game: the orange was too strong. 0.9 checked and kept.
|
||||
EyeReadyStrength = config.Bind(appearance, "Eye Ready Strength", 0.9f,
|
||||
new ConfigDescription("Glow at night while a form is ready.", new AcceptableValueRange<float>(0f, 3f)));
|
||||
|
||||
// "debug" in the key keeps it local - see ConfigSync.
|
||||
DebugFormHits = config.Bind("Fenrir - Debug", "Debug: Log Form Hits", false,
|
||||
new ConfigDescription("Writes one log line per claw or bite: what was in reach, what it hit, and why anything was skipped. For bug reports about attacks that do no damage."));
|
||||
|
|
|
|||
|
|
@ -150,6 +150,8 @@ namespace RacesOfValheim {
|
|||
}
|
||||
wasNight = isNight;
|
||||
|
||||
FenrirVisuals.SetReady(Player.m_localPlayer, GetReadyState());
|
||||
|
||||
if (isTransformed)
|
||||
{
|
||||
bool hasAnyForm = Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_FenrirForm".GetStableHashCode()) ||
|
||||
|
|
@ -171,6 +173,42 @@ namespace RacesOfValheim {
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace RacesOfValheim
|
|||
public override void Stop()
|
||||
{
|
||||
base.Stop();
|
||||
if (Player.m_localPlayer != null)
|
||||
if (Player.m_localPlayer != null && FenrirConfig.ReadyMessage.Value)
|
||||
{
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_fenrir_ready", m_name));
|
||||
}
|
||||
|
|
|
|||
277
JotunnModStub/Fenrir/FenrirVisuals.cs
Normal file
277
JotunnModStub/Fenrir/FenrirVisuals.cs
Normal file
|
|
@ -0,0 +1,277 @@
|
|||
using System.Collections.Generic;
|
||||
using HarmonyLib;
|
||||
using Jotunn.Managers;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// The Fenrir's eyes catch the light at night, the way a wolf's do: a faint glow while no form
|
||||
/// can be taken, a bright one when a key would transform right now, and the Cultist's yellow
|
||||
/// when that form is back from its cooldown. Dark by day and while in a
|
||||
/// beast form, whose own eyes take over. A community suggestion (lexsonn), meant to say what
|
||||
/// the "Ready!" text says without the text.
|
||||
///
|
||||
/// Built the way AswidVisuals builds the Aswid's eyes, which is where the long story lives: the
|
||||
/// vanilla Skeleton's eye_l/eye_r borrowed for mesh and material, placed on the head bone the
|
||||
/// body mesh is skinned to, sized from the source's world scale. The placement numbers are the
|
||||
/// Aswid's playtested defaults, fixed here rather than exposed again.
|
||||
///
|
||||
/// The colour is the Fenring's own: its body material's _EmissionColor, (2.0, 0.372, 0.0) in
|
||||
/// bundle c4210710, read offline with UnityPy rather than picked by eye.
|
||||
///
|
||||
/// Runs for remote players too. Night is the same for everyone; whether a form is ready is
|
||||
/// only known to the owner, who writes it to the ZDO (SetReady) for everyone else to read.
|
||||
/// </summary>
|
||||
public static class FenrirVisuals
|
||||
{
|
||||
public const string RaceId = "Fenrir";
|
||||
public const string ReadyKey = "RacesOfValheim_FenrirReady";
|
||||
|
||||
/// <summary>Written to the ZDO as an int, so the values are part of the network contract.</summary>
|
||||
public enum ReadyState
|
||||
{
|
||||
None = 0,
|
||||
Form = 1,
|
||||
Cultist = 2,
|
||||
}
|
||||
private const string FormKey = "RacesOfValheim_FenrirForm";
|
||||
private const string EyesName = "FenrirEyes";
|
||||
private const string SourceModel = "Skeleton";
|
||||
private static readonly string[] SourceEyeNames = { "eye_l", "eye_r" };
|
||||
|
||||
private static readonly Color FenringGlow = new Color(2.0f, 0.372f, 0f, 1f);
|
||||
|
||||
// The Cultist's body is the Fenring's material and its breath is white flame tinted by
|
||||
// texture, so neither tells it apart. Its own death effect (vfx_fenring_cultist_death)
|
||||
// does: FlameRoundYellowParticle's _EmissionColor, same bundle.
|
||||
private static readonly Color CultistGlow = new Color(2.691f, 1.797f, 0.455f, 1f);
|
||||
|
||||
// AswidVisuals' base placement plus its Configuration Manager defaults, which are what
|
||||
// playtesting settled on for this same pair of eyes on this same rig.
|
||||
private const float EyeForward = 0.081f + 0.013f;
|
||||
private const float EyeHeight = 0.181f + 0.004f;
|
||||
private const float EyeSeparation = 0.032f + 0.007f;
|
||||
private const float EyeSize = 1.1f;
|
||||
private const float EyeYaw = 22.068f;
|
||||
private const float EyeRoll = -180f;
|
||||
|
||||
/// <summary>Owner only, and only on a change: one ZDO write per transition, not per frame.</summary>
|
||||
public static void SetReady(Player player, ReadyState ready)
|
||||
{
|
||||
ZNetView nview = player != null ? player.GetComponent<ZNetView>() : null;
|
||||
if (nview == null || !nview.IsValid() || !nview.IsOwner()) return;
|
||||
|
||||
ZDO zdo = nview.GetZDO();
|
||||
if (zdo.GetInt(ReadyKey, 0) != (int)ready) zdo.Set(ReadyKey, (int)ready);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Keeps the eyes on a living Fenrir and takes them off anyone else. Called from
|
||||
/// VisEquipment.UpdateColors, which is what notices a race change; the ticker below then
|
||||
/// follows night, readiness and forms frame by frame.
|
||||
/// </summary>
|
||||
public static void ApplyEyes(Player player)
|
||||
{
|
||||
if (player == null) return;
|
||||
|
||||
Transform headBone = FindHeadBone(player);
|
||||
if (headBone == null) return; // rig not up yet; the ticker or the next refresh retries
|
||||
|
||||
Transform eyes = headBone.Find(EyesName);
|
||||
|
||||
if (DvergarVisuals.GetPlayerRace(player) != RaceId || player.IsDead())
|
||||
{
|
||||
if (eyes != null)
|
||||
{
|
||||
// Renamed first: Destroy waits for the end of the frame.
|
||||
eyes.name = EyesName + "_Removed";
|
||||
Object.Destroy(eyes.gameObject);
|
||||
}
|
||||
EyeTicker ticker = player.GetComponent<EyeTicker>();
|
||||
if (ticker != null) Object.Destroy(ticker);
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.GetComponent<EyeTicker>() == null) player.gameObject.AddComponent<EyeTicker>();
|
||||
|
||||
float strength = GetGlowStrength(player, out Color hue);
|
||||
if (strength <= 0f)
|
||||
{
|
||||
if (eyes != null && eyes.gameObject.activeSelf) eyes.gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (eyes == null)
|
||||
{
|
||||
// The skull's facing is measured once, at build time. A head turned by sitting,
|
||||
// an attack or sleep would measure wrong; see AswidVisuals.ApplyEyes.
|
||||
if (player.IsAttached() || player.IsAttachedToShip() || player.InAttack() || player.IsSleeping()) return;
|
||||
eyes = BuildEyes(player, headBone);
|
||||
if (eyes == null) return;
|
||||
}
|
||||
|
||||
if (!eyes.gameObject.activeSelf) eyes.gameObject.SetActive(true);
|
||||
PaintEyes(eyes, hue * strength);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 0 means dark: day, a beast form, or the viewer turned the glow off. Otherwise faint
|
||||
/// orange with nothing ready, bright orange with a form ready, bright yellow when the
|
||||
/// Cultist is back from its cooldown.
|
||||
/// </summary>
|
||||
private static float GetGlowStrength(Player player, out Color hue)
|
||||
{
|
||||
hue = FenringGlow;
|
||||
if (!FenrirConfig.EyeGlow.Value) return 0f;
|
||||
if (EnvMan.instance == null || !EnvMan.IsNight()) return 0f;
|
||||
|
||||
ZNetView nview = player.GetComponent<ZNetView>();
|
||||
if (nview == null || !nview.IsValid()) return 0f;
|
||||
|
||||
ZDO zdo = nview.GetZDO();
|
||||
if (!string.IsNullOrEmpty(zdo.GetString(FormKey, ""))) return 0f;
|
||||
|
||||
ReadyState ready = (ReadyState)zdo.GetInt(ReadyKey, 0);
|
||||
if (ready == ReadyState.None) return FenrirConfig.EyeNightStrength.Value;
|
||||
|
||||
if (ready == ReadyState.Cultist) hue = CultistGlow;
|
||||
return FenrirConfig.EyeReadyStrength.Value;
|
||||
}
|
||||
|
||||
public class EyeTicker : MonoBehaviour
|
||||
{
|
||||
private Player m_player;
|
||||
|
||||
private void Awake() => m_player = GetComponent<Player>();
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (m_player == null) { Destroy(this); return; }
|
||||
ApplyEyes(m_player);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The body mesh's own Head bone, never the Animator's. See AswidVisuals.FindHeadBone.</summary>
|
||||
private static Transform FindHeadBone(Player player)
|
||||
{
|
||||
VisEquipment visEq = player.GetComponent<VisEquipment>();
|
||||
if (visEq == null || visEq.m_bodyModel == null || visEq.m_bodyModel.bones == null) return null;
|
||||
|
||||
foreach (Transform bone in visEq.m_bodyModel.bones)
|
||||
{
|
||||
if (bone != null && bone.name == AswidVisuals.PlayerHeadBoneName) return bone;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Transform BuildEyes(Player player, Transform headBone)
|
||||
{
|
||||
List<Transform> sources = FindSourceEyes();
|
||||
if (sources.Count == 0) return null;
|
||||
|
||||
float lossy = headBone.lossyScale.x;
|
||||
if (Mathf.Abs(lossy) < 0.0001f) return null; // rig still coming up
|
||||
float toLocal = 1f / lossy;
|
||||
|
||||
GameObject holder = new GameObject(EyesName);
|
||||
holder.transform.SetParent(headBone, false);
|
||||
|
||||
RigBindPose.MeasureHeadFrame(player, headBone, RaceId,
|
||||
out Vector3 forward, out Vector3 up, out Vector3 right);
|
||||
Quaternion facing = Quaternion.LookRotation(forward, up);
|
||||
|
||||
// The player's own scale cancels the rig's, as in AswidVisuals.PlaceEyes.
|
||||
float scale = player.transform.localScale.x * toLocal;
|
||||
|
||||
foreach (Transform source in sources)
|
||||
{
|
||||
GameObject eye = Object.Instantiate(source.gameObject, holder.transform);
|
||||
eye.name = source.name;
|
||||
|
||||
float side = source.name.ToLowerInvariant().Contains("_l") ? -1f : 1f;
|
||||
|
||||
eye.transform.localPosition = forward * (EyeForward * scale)
|
||||
+ up * (EyeHeight * scale)
|
||||
+ right * (side * EyeSeparation * scale);
|
||||
// Yaw mirrored per eye so the pair turns in towards the nose together.
|
||||
eye.transform.localRotation = Quaternion.Euler(0f, EyeYaw * side, EyeRoll) * facing;
|
||||
eye.transform.localScale = source.lossyScale * toLocal * EyeSize;
|
||||
|
||||
// Allowlist: whatever else rode along on the skeleton goes.
|
||||
foreach (Component comp in eye.GetComponentsInChildren<Component>(true))
|
||||
{
|
||||
if (comp is Transform || comp is MeshRenderer || comp is MeshFilter) continue;
|
||||
if (comp is ParticleSystem || comp is ParticleSystemRenderer)
|
||||
{
|
||||
// The skeleton's eye smoke, on a child of the eye: too loud for a reflection.
|
||||
if (comp.gameObject != eye) comp.gameObject.SetActive(false);
|
||||
continue;
|
||||
}
|
||||
Object.Destroy(comp);
|
||||
}
|
||||
|
||||
foreach (Renderer renderer in eye.GetComponentsInChildren<Renderer>(true))
|
||||
{
|
||||
renderer.enabled = true;
|
||||
renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
|
||||
renderer.receiveShadows = false;
|
||||
}
|
||||
|
||||
eye.SetActive(true);
|
||||
}
|
||||
|
||||
return holder.transform;
|
||||
}
|
||||
|
||||
/// <summary>Every colour property the borrowed material has; see AswidVisuals.PaintEyes.</summary>
|
||||
private static void PaintEyes(Transform holder, Color glow)
|
||||
{
|
||||
glow.a = 1f;
|
||||
foreach (Renderer renderer in holder.GetComponentsInChildren<Renderer>(true))
|
||||
{
|
||||
Material material = renderer.material;
|
||||
if (material == null) continue;
|
||||
|
||||
if (material.HasProperty("_Color")) material.SetColor("_Color", glow);
|
||||
if (material.HasProperty("_TintColor")) material.SetColor("_TintColor", glow);
|
||||
if (material.HasProperty("_BaseColor")) material.SetColor("_BaseColor", glow);
|
||||
if (material.HasProperty("_EmissionColor")) material.SetColor("_EmissionColor", glow);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool warnedSource;
|
||||
|
||||
private static List<Transform> FindSourceEyes()
|
||||
{
|
||||
List<Transform> found = new List<Transform>();
|
||||
|
||||
GameObject prefab = PrefabManager.Cache.GetPrefab<GameObject>(SourceModel);
|
||||
if (prefab != null)
|
||||
{
|
||||
foreach (Transform t in prefab.GetComponentsInChildren<Transform>(true))
|
||||
{
|
||||
string lower = t.name.ToLower();
|
||||
if (lower == SourceEyeNames[0] || lower == SourceEyeNames[1]) found.Add(t);
|
||||
}
|
||||
}
|
||||
|
||||
if (found.Count == 0 && !warnedSource)
|
||||
{
|
||||
warnedSource = true;
|
||||
Jotunn.Logger.LogWarning($"[Fenrir] No eye_l/eye_r found on '{SourceModel}' - the eyes stay dark.");
|
||||
}
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(VisEquipment), "UpdateColors")]
|
||||
public static class FenrirEyesPatch
|
||||
{
|
||||
public static void Postfix(VisEquipment __instance)
|
||||
{
|
||||
if (!__instance.m_isPlayer) return;
|
||||
FenrirVisuals.ApplyEyes(__instance.GetComponent<Player>());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue