RacesOfValheim/JotunnModStub/Furling/FurlingRace.cs
kanym 5af7c0205d fix(furling): Through Fire and Flames goes out when the player changes race
The ability is vanilla's Burning set to 999 minutes. FurlingRace.Update
returned before ticking it for anyone who was not a Furling, and
ResetRace never removed it, so the fire followed the player onto any
race and came back visible if they picked the Furling again. The tick
now runs for every race and puts out a Burning longer than an hour when
the player is not a tier 8 Furling; ResetRace does the same at once.
2026-09-29 02:50:47 +02:00

76 lines
2.9 KiB
C#

using BepInEx;
using HarmonyLib;
using UnityEngine;
using System.Collections.Generic;
namespace RacesOfValheim
{
public class FurlingRace : MonoBehaviour
{
private static FurlingRace _instance;
// The plugin adds this component itself, so Instance must find that copy rather than build
// a second one on first read. Same fault as TrolRace's, where two Updates reading one key
// switched the True Form off as it came on; here the only per-frame work is idempotent, so
// it had no visible effect, but two copies of a race component is never intended.
private void Awake()
{
if (_instance != null && _instance != this)
{
Destroy(this);
return;
}
_instance = this;
}
public static FurlingRace Instance
{
get
{
if (_instance == null)
{
GameObject go = new GameObject("FurlingRace");
_instance = go.AddComponent<FurlingRace>();
DontDestroyOnLoad(go);
}
return _instance;
}
}
/// <summary>
/// Reads the race the same way every other race in the mod reads it.
///
/// This used to be `GetPlayerModel() == 5`, with a comment admitting the 5 was assumed.
/// GetPlayerModel returns the character's BODY MODEL index - 0 or 1, male or female, the
/// thing PlayerCustomizaton.SetPlayerModel writes - and has nothing to do with the race,
/// which SelectFurling stores in m_customData["Race"]. So it never returned true, and
/// everything gated behind it was dead code: the -19% visual scale, the +10% run speed, the
/// truce with the Fuling camps, and Through Fire and Flames.
/// </summary>
public static bool IsFurling()
{
return Player.m_localPlayer != null &&
Player.m_localPlayer.m_customData.ContainsKey("Race") &&
Player.m_localPlayer.m_customData["Race"] == "Furling";
}
public void CreateModAssets()
{
Jotunn.Logger.LogInfo("Initializing Furling Race...");
FurlingStatusEffects.RegisterStatusEffects();
// The metal flax and the rock berries. Registered here because the faction merchant
// catalogue resolves its entries by prefab name, so the five items have to exist before
// a Shaman is ever set up as a bench.
FurlingCrops.Register();
}
private void Update()
{
// Through Fire and Flames (Fader). Ticked for every race, not only the Furling: a
// player who stops being a tier 8 Furling has to lose the fire, and nothing else would
// be left running to notice.
FurlingFireAbility.Tick();
}
}
}