Every message the mod puts in the middle or corner of the screen now reads its text through ModText.Get, and messages.json holds 191 texts in English and Italian. Values computed in code become $1, $2 in the text, so a translator can put them wherever the sentence needs them. Branching messages get one key per branch. A few messages travel through a field before they are shown: thralls' refusals and the building limits now hold a token or key there. Boss and form names inside messages use tokens too, the bosses the game's own, so "The Elder" arrives translated. ModText.Get now localizes each argument before inserting it. A token argument left for a later pass ran into the text after it: "$1's power" became the unknown token "enemy_eikthyr's". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
187 lines
7.5 KiB
C#
187 lines
7.5 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
|
|
};
|
|
|
|
/// <summary>
|
|
/// The boss's name as the game's own localization token, for text shown to players:
|
|
/// Valheim translates it wherever it is localized, so "The Elder" arrives in every language.
|
|
/// GetBossNameForState stays English, for logs and anything not localized.
|
|
/// </summary>
|
|
public static string GetBossTokenForState(int state)
|
|
{
|
|
switch (state)
|
|
{
|
|
case 2: return "$enemy_eikthyr";
|
|
case 3: return "$enemy_gdking";
|
|
case 4: return "$enemy_bonemass";
|
|
case 5: return "$enemy_dragon";
|
|
case 6: return "$enemy_goblinking";
|
|
case 7: return "$enemy_seekerqueen";
|
|
case 8: return "$enemy_fader";
|
|
default: return GetBossNameForState(state);
|
|
}
|
|
}
|
|
|
|
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>
|
|
/// Whether this character carries a claimed personal tier at all. Distinct from
|
|
/// "PersonalState == MinState": the getter answers MinState for a character who has never
|
|
/// claimed anything AND for one who has been reset, and the Reset Progression button needs
|
|
/// to tell the player which of the two just happened.
|
|
/// </summary>
|
|
public static bool HasPersonalState
|
|
{
|
|
get
|
|
{
|
|
Player player = Player.m_localPlayer;
|
|
if (player == null || player.m_customData == null) return false;
|
|
return player.m_customData.ContainsKey(PersonalStateKey);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gives back every tier claimed with a boss relic. The key is removed rather than written
|
|
/// back as MinState so the character reads as one that never claimed anything - which is
|
|
/// what a reset means, and what HasPersonalState above then reports.
|
|
///
|
|
/// The relics themselves do not come back: RaceMenuWardBehavior.UseItem consumed them.
|
|
/// </summary>
|
|
public static void ClearPersonalState()
|
|
{
|
|
Player player = Player.m_localPlayer;
|
|
if (player == null || player.m_customData == null) return;
|
|
player.m_customData.Remove(PersonalStateKey);
|
|
}
|
|
|
|
/// <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();
|
|
}
|
|
}
|
|
}
|