RacesOfValheim/JotunnModStub/BossProgressionManager.cs
kanym 5350ebda5d Add the Race Menu Ward; WIP on remote Trol/Skadi visuals
Race Menu Ward: a buildable ward (2 wood, hammer/Misc, no crafting station)
that manages your race outside the debug console - reset the race, switch
between the server's boss progression and your own, and advance that personal
progression by offering a boss's secondary drop to it. One is placed near the
sacrificial stones on first load of a world, by the host only.

BossProgressionManager grows a personal mode alongside the world one. The tier
is stored on the character rather than the world, so a personal tier travels
with the player between servers instead of being tied to whichever world
unlocked it. resetrace and the ward now share RacesOfValheim.ResetRace so both
paths clean up identical state.

Also in progress, and NOT yet working: remote Trol sizing and remote Skadi
flight. Both are computed from the observer instead of the observed -

- Remote Trols are scaled from the observing player's own progression, and
  never show True Form, because SE_TrolTrueForm only exists on the transformed
  player's client. Each Trol now publishes its state and True Form flag onto
  its own ZDO for others to read.
- Remote Skadi dragons sink to the terrain regardless of the altitude being
  replicated: Character.m_flying is only ever set on the flying player's
  client, so observers run grounded motion under gravity. Flight is mirrored
  through the ZDO and the remote copy's rigidbody gravity is disabled while it
  lasts.

Neither has fixed the symptom yet, so both paths keep a throttled diagnostic
log reporting what each observer actually computes. Committed to get the
instrumentation onto the branch, not because it works.

Packaging no longer hardcodes another machine's desktop path: Thunderstore and
Nexus zips go to dist/ on Release builds only, and the DLL is copied into
Valheim only when VALHEIM_INSTALL actually points at a plugins folder.
2026-08-02 08:45:47 +02:00

137 lines
5.2 KiB
C#

using Jotunn.Managers;
using System.Collections.Generic;
namespace RacesOfValheim
{
public static class BossProgressionManager
{
public static int DebugState = -1; // [DEBUG] Da rimuovere in seguito
// Valheim Global Keys for bosses
public const string Eikthyr = "defeated_eikthyr";
public const string TheElder = "defeated_gdking";
public const string Bonemass = "defeated_bonemass";
public const string Moder = "defeated_dragon";
public const string Yagluth = "defeated_goblinking";
public const string TheQueen = "defeated_queen";
public const string Fader = "defeated_fader";
public const int MinState = 1;
public const int MaxState = 8;
// Stored on the character rather than the world, so a personal tier travels with the
// player between servers instead of being tied to whichever world unlocked it.
private const string PersonalStateKey = "RacesOfValheim_PersonalState";
private const string PersonalModeKey = "RacesOfValheim_PersonalMode";
/// <summary>
/// Boss secondary drops, and the progression state each one unlocks when offered to the
/// Race Menu Ward. Keyed by prefab name, which is what the item stack carries.
/// </summary>
public static readonly Dictionary<string, int> BossDropStates = new Dictionary<string, int>
{
{ "HardAntler", 2 }, // Eikthyr
{ "CryptKey", 3 }, // The Elder
{ "Wishbone", 4 }, // Bonemass
{ "DragonTear", 5 }, // Moder
{ "YagluthDrop", 6 }, // Yagluth
{ "QueenDrop", 7 }, // The Queen - Majestic carapace
{ "FaderDrop", 8 } // Fader - Fader relic
};
public static string GetBossNameForState(int state)
{
switch (state)
{
case 2: return "Eikthyr";
case 3: return "The Elder";
case 4: return "Bonemass";
case 5: return "Moder";
case 6: return "Yagluth";
case 7: return "The Queen";
case 8: return "Fader";
default: return "No bosses";
}
}
/// <summary>
/// True when the player has chosen to advance on their own unlocks rather than on whatever
/// the server has already killed.
/// </summary>
public static bool UsePersonalProgression
{
get
{
Player player = Player.m_localPlayer;
if (player == null || player.m_customData == null) return false;
return player.m_customData.TryGetValue(PersonalModeKey, out string value) && value == "true";
}
set
{
Player player = Player.m_localPlayer;
if (player == null || player.m_customData == null) return;
player.m_customData[PersonalModeKey] = value ? "true" : "false";
}
}
public static int PersonalState
{
get
{
Player player = Player.m_localPlayer;
if (player == null || player.m_customData == null) return MinState;
if (player.m_customData.TryGetValue(PersonalStateKey, out string value) &&
int.TryParse(value, out int state))
{
return UnityEngine.Mathf.Clamp(state, MinState, MaxState);
}
return MinState;
}
set
{
Player player = Player.m_localPlayer;
if (player == null || player.m_customData == null) return;
player.m_customData[PersonalStateKey] = UnityEngine.Mathf.Clamp(value, MinState, MaxState).ToString();
}
}
/// <summary>
/// Returns the current progression state of the world based on defeated bosses.
/// 1 = No bosses defeated
/// 2 = Eikthyr defeated
/// 3 = The Elder defeated
/// 4 = Bonemass defeated
/// 5 = Moder defeated
/// 6 = Yagluth defeated
/// 7 = The Queen defeated
/// 8 = Fader defeated
/// </summary>
public static int GetWorldProgressionState()
{
if (ZoneSystem.instance == null)
{
return MinState; // Default to 1 if ZoneSystem isn't ready
}
// We check in reverse order (highest tier first)
if (ZoneSystem.instance.GetGlobalKey(Fader)) return 8;
if (ZoneSystem.instance.GetGlobalKey(TheQueen)) return 7;
if (ZoneSystem.instance.GetGlobalKey(Yagluth)) return 6;
if (ZoneSystem.instance.GetGlobalKey(Moder)) return 5;
if (ZoneSystem.instance.GetGlobalKey(Bonemass)) return 4;
if (ZoneSystem.instance.GetGlobalKey(TheElder)) return 3;
if (ZoneSystem.instance.GetGlobalKey(Eikthyr)) return 2;
return MinState; // No bosses defeated
}
public static int GetCurrentProgressionState()
{
if (DebugState != -1) return DebugState; // [DEBUG]
if (UsePersonalProgression) return PersonalState;
return GetWorldProgressionState();
}
}
}