167 lines
6.6 KiB
C#
167 lines
6.6 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>
|
|
/// 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();
|
|
}
|
|
}
|
|
}
|