Merge pull request 'creating-race-totem' (#5) from creating-race-totem into main
Reviewed-on: #5
This commit is contained in:
commit
2e8d66f439
7 changed files with 636 additions and 76 deletions
|
|
@ -16,6 +16,85 @@ namespace RacesOfValheim
|
|||
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
|
||||
|
|
@ -27,13 +106,11 @@ namespace RacesOfValheim
|
|||
/// 7 = The Queen defeated
|
||||
/// 8 = Fader defeated
|
||||
/// </summary>
|
||||
public static int GetCurrentProgressionState()
|
||||
public static int GetWorldProgressionState()
|
||||
{
|
||||
if (DebugState != -1) return DebugState; // [DEBUG]
|
||||
|
||||
if (ZoneSystem.instance == null)
|
||||
{
|
||||
return 1; // Default to 1 if ZoneSystem isn't ready
|
||||
return MinState; // Default to 1 if ZoneSystem isn't ready
|
||||
}
|
||||
|
||||
// We check in reverse order (highest tier first)
|
||||
|
|
@ -45,7 +122,16 @@ namespace RacesOfValheim
|
|||
if (ZoneSystem.instance.GetGlobalKey(TheElder)) return 3;
|
||||
if (ZoneSystem.instance.GetGlobalKey(Eikthyr)) return 2;
|
||||
|
||||
return 1; // No bosses defeated
|
||||
return MinState; // No bosses defeated
|
||||
}
|
||||
|
||||
public static int GetCurrentProgressionState()
|
||||
{
|
||||
if (DebugState != -1) return DebugState; // [DEBUG]
|
||||
|
||||
if (UsePersonalProgression) return PersonalState;
|
||||
|
||||
return GetWorldProgressionState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
379
JotunnModStub/RaceMenuWard.cs
Normal file
379
JotunnModStub/RaceMenuWard.cs
Normal file
|
|
@ -0,0 +1,379 @@
|
|||
using Jotunn.Configs;
|
||||
using Jotunn.Entities;
|
||||
using Jotunn.Managers;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// A buildable ward that lets a player manage their race outside of the debug console: reset
|
||||
/// the race, switch between the server's boss progression and their own, and advance that
|
||||
/// personal progression by offering a boss's secondary drop to it.
|
||||
/// </summary>
|
||||
public static class RaceMenuWard
|
||||
{
|
||||
public const string PrefabName = "RaceMenuWard";
|
||||
|
||||
public static void Register()
|
||||
{
|
||||
// The Ward ("guard_stone") is only borrowed for its model and build sounds; its own
|
||||
// area-protection behaviour is stripped below so it never claims territory.
|
||||
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(PrefabName, "guard_stone");
|
||||
if (prefab == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning("Could not clone guard_stone; Race Menu Ward not registered.");
|
||||
return;
|
||||
}
|
||||
|
||||
PrivateArea privateArea = prefab.GetComponent<PrivateArea>();
|
||||
if (privateArea != null) Object.DestroyImmediate(privateArea);
|
||||
|
||||
// The Ward is a workbench recipe, and Player.HaveRequirements hides any piece whose
|
||||
// crafting station is not both known and in range - which is why a fresh character
|
||||
// never saw this in the hammer. Clearing the station makes it buildable anywhere.
|
||||
Piece piece = prefab.GetComponent<Piece>();
|
||||
if (piece != null)
|
||||
{
|
||||
piece.m_craftingStation = null;
|
||||
// The clone arrives carrying the Ward's own recipe (fine wood, surtling cores and
|
||||
// so on). Jotunn only overwrites m_resources when the config lists requirements,
|
||||
// so wipe the inherited ones here and let the config below set the real cost.
|
||||
piece.m_resources = new Piece.Requirement[0];
|
||||
}
|
||||
|
||||
prefab.AddComponent<RaceMenuWardBehavior>();
|
||||
|
||||
PieceConfig config = new PieceConfig
|
||||
{
|
||||
Name = "Race Menu Ward",
|
||||
Description = "Commune with your heritage. Offer a fallen boss's relic to claim its power.",
|
||||
PieceTable = PieceTables.Hammer,
|
||||
Category = PieceCategories.Misc,
|
||||
// Deliberately trivial: this is a utility the player needs early, not a reward.
|
||||
Requirements = new[]
|
||||
{
|
||||
new RequirementConfig("Wood", 2, 0, true)
|
||||
}
|
||||
};
|
||||
|
||||
PieceManager.Instance.AddPiece(new CustomPiece(prefab, fixReference: false, config));
|
||||
}
|
||||
|
||||
// Marks a world as already having its starter ward, so it is placed exactly once rather
|
||||
// than every time someone loads in.
|
||||
private const string PlacedKey = "RacesOfValheim_StarterWardPlaced";
|
||||
// Clear of the stone circle itself, which is why the first attempt ended up inside a stone.
|
||||
private const float SpawnRadius = 14f;
|
||||
private const float ClearanceRadius = 2.5f;
|
||||
|
||||
/// <summary>
|
||||
/// Drops a ward beside the sacrificial stones so a fresh world has one without anyone
|
||||
/// needing to build it. Only the host runs this, and only once per world.
|
||||
/// </summary>
|
||||
public static void TryPlaceAtSpawn()
|
||||
{
|
||||
if (ZoneSystem.instance == null || ZNetScene.instance == null) return;
|
||||
if (ZNet.instance == null || !ZNet.instance.IsServer()) return;
|
||||
if (ZoneSystem.instance.GetGlobalKey(PlacedKey)) return;
|
||||
|
||||
if (!ZoneSystem.instance.GetLocationIcon("StartTemple", out Vector3 templePos)) return;
|
||||
|
||||
GameObject prefab = ZNetScene.instance.GetPrefab(PrefabName);
|
||||
if (prefab == null) return;
|
||||
|
||||
if (!TryFindClearSpot(templePos, out Vector3 pos)) return;
|
||||
|
||||
Object.Instantiate(prefab, pos, Quaternion.identity);
|
||||
ZoneSystem.instance.SetGlobalKey(PlacedKey);
|
||||
Jotunn.Logger.LogInfo($"Placed the starter Race Menu Ward near spawn at {pos}.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A build piece only appears in the hammer once its name is in the player's known recipes
|
||||
/// (PieceTable.UpdateAvailable filters on exactly that), and the vanilla learning pass can
|
||||
/// miss a piece injected after the fact. Teach it directly and rebuild the list. Both
|
||||
/// methods are non-public, hence the reflection.
|
||||
/// </summary>
|
||||
public static void EnsureKnown(Player player)
|
||||
{
|
||||
if (player == null) return;
|
||||
|
||||
GameObject prefab = PrefabManager.Instance.GetPrefab(PrefabName);
|
||||
if (prefab == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"{PrefabName} prefab missing; cannot teach the piece.");
|
||||
return;
|
||||
}
|
||||
|
||||
Piece piece = prefab.GetComponent<Piece>();
|
||||
if (piece == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"{PrefabName} has no Piece component.");
|
||||
return;
|
||||
}
|
||||
|
||||
var traverse = HarmonyLib.Traverse.Create(player);
|
||||
traverse.Method("AddKnownPiece", piece).GetValue();
|
||||
traverse.Method("UpdateAvailablePiecesList").GetValue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Walks a ring around the sacrificial stones looking for open, level terrain. Uses the
|
||||
/// ground height rather than the solid height, since the latter happily reports the top of
|
||||
/// a standing stone and leaves the ward embedded in it.
|
||||
/// </summary>
|
||||
private static bool TryFindClearSpot(Vector3 centre, out Vector3 result)
|
||||
{
|
||||
int obstacleMask = LayerMask.GetMask("Default", "static_solid", "Default_small", "piece", "vehicle");
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
float angle = i * (360f / 12f) * Mathf.Deg2Rad;
|
||||
Vector3 candidate = centre + new Vector3(Mathf.Cos(angle), 0f, Mathf.Sin(angle)) * SpawnRadius;
|
||||
candidate.y = ZoneSystem.instance.GetGroundHeight(candidate);
|
||||
|
||||
// Skip anything underwater, and anything with a rock, tree or build piece on it.
|
||||
if (candidate.y < ZoneSystem.instance.m_waterLevel) continue;
|
||||
if (Physics.CheckSphere(candidate + Vector3.up * 1.5f, ClearanceRadius, obstacleMask)) continue;
|
||||
|
||||
result = candidate;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Nothing ideal: fall back to due south on the terrain rather than skipping entirely.
|
||||
result = centre + new Vector3(0f, 0f, -SpawnRadius);
|
||||
result.y = ZoneSystem.instance.GetGroundHeight(result);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// The spawn point only resolves once the world is up and the local player exists, so the
|
||||
// placement attempt rides along with the player spawning rather than world load.
|
||||
[HarmonyLib.HarmonyPatch(typeof(Player), "OnSpawned")]
|
||||
public static class RaceMenuWardSpawnPatch
|
||||
{
|
||||
public static void Postfix(Player __instance)
|
||||
{
|
||||
if (__instance != Player.m_localPlayer) return;
|
||||
RaceMenuWard.TryPlaceAtSpawn();
|
||||
RaceMenuWard.EnsureKnown(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
public class RaceMenuWardBehavior : MonoBehaviour, Hoverable, Interactable
|
||||
{
|
||||
public string GetHoverName() => "Race Menu Ward";
|
||||
|
||||
public string GetHoverText()
|
||||
{
|
||||
string mode = BossProgressionManager.UsePersonalProgression ? "Personal" : "World";
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
string boss = BossProgressionManager.GetBossNameForState(state);
|
||||
|
||||
return $"Race Menu Ward\n{mode} progression - {boss} ({state}/{BossProgressionManager.MaxState})\n" +
|
||||
"[<color=yellow><b>E</b></color>] Open\n" +
|
||||
"[<color=yellow><b>Use item</b></color>] Offer a boss relic";
|
||||
}
|
||||
|
||||
public bool Interact(Humanoid user, bool hold, bool alt)
|
||||
{
|
||||
if (hold) return false;
|
||||
if (user != Player.m_localPlayer) return false;
|
||||
|
||||
RaceMenuWardUI.Show();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Offering a boss's secondary drop unlocks that boss's tier of personal progression.
|
||||
/// Any tier may be claimed directly - holding a Dragon tear takes you straight to Moder's
|
||||
/// tier whether or not the earlier ones were ever claimed.
|
||||
/// </summary>
|
||||
public bool UseItem(Humanoid user, ItemDrop.ItemData item)
|
||||
{
|
||||
if (user != Player.m_localPlayer || item == null) return false;
|
||||
|
||||
string prefabName = item.m_dropPrefab != null ? item.m_dropPrefab.name : null;
|
||||
if (prefabName == null || !BossProgressionManager.BossDropStates.TryGetValue(prefabName, out int state))
|
||||
{
|
||||
user.Message(MessageHud.MessageType.Center, "The ward has no use for that.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!BossProgressionManager.UsePersonalProgression)
|
||||
{
|
||||
user.Message(MessageHud.MessageType.Center, "Switch to personal progression first.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (BossProgressionManager.PersonalState >= state)
|
||||
{
|
||||
user.Message(MessageHud.MessageType.Center,
|
||||
$"You already carry {BossProgressionManager.GetBossNameForState(state)}'s power.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = Player.m_localPlayer;
|
||||
player.GetInventory().RemoveOneItem(item);
|
||||
BossProgressionManager.PersonalState = state;
|
||||
|
||||
user.Message(MessageHud.MessageType.Center,
|
||||
$"{BossProgressionManager.GetBossNameForState(state)}'s power is yours.");
|
||||
|
||||
RefreshRaceState();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Progression drives stats and unlocks that are only recalculated when equipment is set
|
||||
// up, so nudge that after any change or the new tier will not show until something else
|
||||
// happens to trigger it.
|
||||
public static void RefreshRaceState()
|
||||
{
|
||||
if (Player.m_localPlayer == null) return;
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Method("SetupEquipment").GetValue();
|
||||
}
|
||||
}
|
||||
|
||||
public static class RaceMenuWardUI
|
||||
{
|
||||
private static GameObject panel;
|
||||
|
||||
public static bool IsOpen => panel != null;
|
||||
|
||||
public static void Show()
|
||||
{
|
||||
if (panel != null) return;
|
||||
if (GUIManager.Instance == null || GUIManager.CustomGUIFront == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning("GUIManager not ready; cannot open the Race Menu Ward.");
|
||||
return;
|
||||
}
|
||||
|
||||
panel = new GameObject("RaceMenuWardPanel");
|
||||
panel.transform.SetParent(GUIManager.CustomGUIFront.transform, false);
|
||||
|
||||
RectTransform rect = panel.AddComponent<RectTransform>();
|
||||
rect.anchorMin = Vector2.zero;
|
||||
rect.anchorMax = Vector2.one;
|
||||
rect.offsetMin = Vector2.zero;
|
||||
rect.offsetMax = Vector2.zero;
|
||||
|
||||
Image bg = panel.AddComponent<Image>();
|
||||
bg.color = new Color(0f, 0f, 0f, 0.85f);
|
||||
|
||||
AddLabel("Title", "Race Menu Ward", 46, new Vector2(0, 230), new Vector2(700, 90));
|
||||
|
||||
AddLabel("Status", BuildStatusText(), 24, new Vector2(0, 110), new Vector2(900, 160));
|
||||
|
||||
AddButton("WorldBtn", "Use World Progression", new Vector2(-170, -20), new Color(0.2f, 0.35f, 0.5f, 1f), () =>
|
||||
{
|
||||
BossProgressionManager.UsePersonalProgression = false;
|
||||
RaceMenuWardBehavior.RefreshRaceState();
|
||||
Refresh();
|
||||
});
|
||||
|
||||
AddButton("PersonalBtn", "Use Personal Progression", new Vector2(170, -20), new Color(0.35f, 0.3f, 0.5f, 1f), () =>
|
||||
{
|
||||
BossProgressionManager.UsePersonalProgression = true;
|
||||
RaceMenuWardBehavior.RefreshRaceState();
|
||||
Refresh();
|
||||
});
|
||||
|
||||
AddButton("ResetBtn", "Reset Race", new Vector2(0, -110), new Color(0.5f, 0.25f, 0.2f, 1f), () =>
|
||||
{
|
||||
Close();
|
||||
RacesOfValheim.ResetRace();
|
||||
});
|
||||
|
||||
AddButton("CloseBtn", "Close", new Vector2(0, -200), new Color(0.3f, 0.3f, 0.3f, 1f), Close);
|
||||
|
||||
GUIManager.BlockInput(true);
|
||||
}
|
||||
|
||||
public static void Close()
|
||||
{
|
||||
if (panel == null) return;
|
||||
Object.Destroy(panel);
|
||||
panel = null;
|
||||
GUIManager.BlockInput(false);
|
||||
}
|
||||
|
||||
private static void Refresh()
|
||||
{
|
||||
if (panel == null) return;
|
||||
Transform status = panel.transform.Find("Status");
|
||||
if (status != null)
|
||||
{
|
||||
Text text = status.GetComponent<Text>();
|
||||
if (text != null) text.text = BuildStatusText();
|
||||
}
|
||||
}
|
||||
|
||||
private static string BuildStatusText()
|
||||
{
|
||||
int world = BossProgressionManager.GetWorldProgressionState();
|
||||
int personal = BossProgressionManager.PersonalState;
|
||||
bool usingPersonal = BossProgressionManager.UsePersonalProgression;
|
||||
|
||||
string worldLine = $"World: {BossProgressionManager.GetBossNameForState(world)} ({world}/{BossProgressionManager.MaxState})";
|
||||
string personalLine = $"Personal: {BossProgressionManager.GetBossNameForState(personal)} ({personal}/{BossProgressionManager.MaxState})";
|
||||
|
||||
if (usingPersonal) personalLine = "> " + personalLine + " <";
|
||||
else worldLine = "> " + worldLine + " <";
|
||||
|
||||
return worldLine + "\n" + personalLine +
|
||||
"\n\nOffer a boss's relic to the ward to claim its tier for your personal progression.";
|
||||
}
|
||||
|
||||
private static void AddLabel(string name, string content, int fontSize, Vector2 position, Vector2 size)
|
||||
{
|
||||
GameObject obj = new GameObject(name);
|
||||
obj.transform.SetParent(panel.transform, false);
|
||||
|
||||
Text text = obj.AddComponent<Text>();
|
||||
text.font = GUIManager.Instance.AveriaSerifBold;
|
||||
text.text = content;
|
||||
text.fontSize = fontSize;
|
||||
text.alignment = TextAnchor.MiddleCenter;
|
||||
text.color = Color.white;
|
||||
|
||||
RectTransform textRect = obj.GetComponent<RectTransform>();
|
||||
textRect.anchoredPosition = position;
|
||||
textRect.sizeDelta = size;
|
||||
}
|
||||
|
||||
private static void AddButton(string name, string label, Vector2 position, Color colour, UnityEngine.Events.UnityAction onClick)
|
||||
{
|
||||
GameObject obj = new GameObject(name);
|
||||
obj.transform.SetParent(panel.transform, false);
|
||||
|
||||
RectTransform btnRect = obj.AddComponent<RectTransform>();
|
||||
btnRect.sizeDelta = new Vector2(300, 60);
|
||||
btnRect.anchoredPosition = position;
|
||||
|
||||
Image image = obj.AddComponent<Image>();
|
||||
image.color = colour;
|
||||
|
||||
Button button = obj.AddComponent<Button>();
|
||||
button.targetGraphic = image;
|
||||
button.onClick.AddListener(onClick);
|
||||
|
||||
GameObject textObj = new GameObject("Text");
|
||||
textObj.transform.SetParent(obj.transform, false);
|
||||
|
||||
Text text = textObj.AddComponent<Text>();
|
||||
text.font = GUIManager.Instance.AveriaSerifBold;
|
||||
text.text = label;
|
||||
text.fontSize = 22;
|
||||
text.alignment = TextAnchor.MiddleCenter;
|
||||
text.color = Color.white;
|
||||
|
||||
RectTransform textRect = textObj.GetComponent<RectTransform>();
|
||||
textRect.anchorMin = Vector2.zero;
|
||||
textRect.anchorMax = Vector2.one;
|
||||
textRect.offsetMin = Vector2.zero;
|
||||
textRect.offsetMax = Vector2.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -39,8 +39,53 @@ namespace RacesOfValheim
|
|||
CommandManager.Instance.AddConsoleCommand(new ResetProgressionCommand());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the current race and reopens the selection menu. Shared by the resetrace console
|
||||
/// command and the Race Menu Ward, so both paths clean up exactly the same state.
|
||||
/// </summary>
|
||||
public static void ResetRace()
|
||||
{
|
||||
Player player = Player.m_localPlayer;
|
||||
if (player == null) return;
|
||||
|
||||
player.m_customData.Remove("Race");
|
||||
player.m_customData.Remove("FenrirCurse_Active");
|
||||
|
||||
// Restore original skin color if it exists
|
||||
if (player.m_customData.ContainsKey("OriginalSkinColor_X"))
|
||||
{
|
||||
float x = float.Parse(player.m_customData["OriginalSkinColor_X"]);
|
||||
float y = float.Parse(player.m_customData["OriginalSkinColor_Y"]);
|
||||
float z = float.Parse(player.m_customData["OriginalSkinColor_Z"]);
|
||||
Vector3 origColor = new Vector3(x, y, z);
|
||||
|
||||
VisEquipment visEq = player.GetComponent<VisEquipment>();
|
||||
if (visEq != null)
|
||||
{
|
||||
Traverse.Create(visEq).Method("SetSkinColor", origColor).GetValue();
|
||||
visEq.GetType().GetMethod("UpdateColors", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)?.Invoke(visEq, null);
|
||||
}
|
||||
}
|
||||
|
||||
player.GetSEMan().RemoveStatusEffect("SE_FenrirCurse".GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect("SE_AswidStats".GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect("SE_SkeletonStats".GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect("SE_SkadiStats".GetStableHashCode());
|
||||
player.GetSEMan().RemoveStatusEffect("SE_SkadiCooldown".GetStableHashCode());
|
||||
|
||||
ZNetView nview = player.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", "Human");
|
||||
|
||||
if (Instance != null)
|
||||
{
|
||||
if (FenrirRace.Instance != null) FenrirRace.Instance.ForceRevert();
|
||||
Instance.ShowRaceSelectionMenu();
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateAllModAssets() {
|
||||
PrefabManager.OnVanillaPrefabsAvailable -= CreateAllModAssets;
|
||||
RaceMenuWard.Register();
|
||||
FenrirRace.Instance.CreateModAssets();
|
||||
SkadiRace.Instance.CreateModAssets();
|
||||
SkeletonRace.Instance.CreateModAssets();
|
||||
|
|
@ -621,40 +666,7 @@ namespace RacesOfValheim
|
|||
{
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
Player.m_localPlayer.m_customData.Remove("Race");
|
||||
Player.m_localPlayer.m_customData.Remove("FenrirCurse_Active");
|
||||
|
||||
// Restore original skin color if it exists
|
||||
if (Player.m_localPlayer.m_customData.ContainsKey("OriginalSkinColor_X"))
|
||||
{
|
||||
float x = float.Parse(Player.m_localPlayer.m_customData["OriginalSkinColor_X"]);
|
||||
float y = float.Parse(Player.m_localPlayer.m_customData["OriginalSkinColor_Y"]);
|
||||
float z = float.Parse(Player.m_localPlayer.m_customData["OriginalSkinColor_Z"]);
|
||||
Vector3 origColor = new Vector3(x, y, z);
|
||||
|
||||
VisEquipment visEq = Player.m_localPlayer.GetComponent<VisEquipment>();
|
||||
if (visEq != null)
|
||||
{
|
||||
Traverse.Create(visEq).Method("SetSkinColor", origColor).GetValue();
|
||||
visEq.GetType().GetMethod("UpdateColors", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)?.Invoke(visEq, null);
|
||||
}
|
||||
}
|
||||
|
||||
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_FenrirCurse".GetStableHashCode());
|
||||
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_AswidStats".GetStableHashCode());
|
||||
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_SkeletonStats".GetStableHashCode());
|
||||
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_SkadiStats".GetStableHashCode());
|
||||
Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_SkadiCooldown".GetStableHashCode());
|
||||
|
||||
ZNetView nview = Player.m_localPlayer.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", "Human");
|
||||
|
||||
if (RacesOfValheim.Instance != null)
|
||||
{
|
||||
if (FenrirRace.Instance != null) FenrirRace.Instance.ForceRevert();
|
||||
RacesOfValheim.Instance.ShowRaceSelectionMenu();
|
||||
}
|
||||
|
||||
RacesOfValheim.ResetRace();
|
||||
Console.instance.Print("Race has been reset. The selection menu should now appear.");
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -93,11 +93,15 @@
|
|||
<CallTarget Targets="CopyToUnity" Condition="Exists('$(UNITY_FOLDER)')" />
|
||||
</Target>
|
||||
|
||||
<Target Name="PackageThunderstore" AfterTargets="Build">
|
||||
<Target Name="PackageThunderstore" AfterTargets="Build" Condition="'$(Configuration)'=='Release'">
|
||||
<PropertyGroup>
|
||||
<PackageOutputDir>$(SolutionDir)dist\</PackageOutputDir>
|
||||
</PropertyGroup>
|
||||
<MakeDir Directories="$(PackageOutputDir)" Condition="!Exists('$(PackageOutputDir)')" />
|
||||
<Message Text="Packaging Thunderstore and Nexus Zips..." Importance="high" />
|
||||
<Exec Command="powershell -Command "if (!(Test-Path 'C:\Users\FERDINANDO\Desktop\Pacchetto_Rame\racesofvalheim')) { New-Item -ItemType Directory -Force -Path 'C:\Users\FERDINANDO\Desktop\Pacchetto_Rame\racesofvalheim' }; Compress-Archive -Path '$(TargetDir)$(TargetName).dll', '$(ProjectDir)..\manifest.json', '$(ProjectDir)..\README.md', '$(ProjectDir)Package\icon.png' -DestinationPath 'C:\Users\FERDINANDO\Desktop\Pacchetto_Rame\racesofvalheim\RacesOfValheim_Thunderstore.zip' -Force; Compress-Archive -Path '$(TargetDir)$(TargetName).dll' -DestinationPath 'C:\Users\FERDINANDO\Desktop\Pacchetto_Rame\racesofvalheim\RacesOfValheim_Nexus.zip' -Force"" />
|
||||
<Message Text="Copying DLL to Valheim BepInEx plugins..." Importance="high" />
|
||||
<Copy SourceFiles="$(TargetDir)$(TargetName).dll" DestinationFolder="C:\Program Files (x86)\Steam\steamapps\common\Valheim\BepInEx\plugins\" />
|
||||
<Exec Command="powershell -NoProfile -Command "Compress-Archive -Path '$(TargetDir)$(TargetName).dll', '$(ProjectDir)..\manifest.json', '$(ProjectDir)..\README.md', '$(ProjectDir)Package\icon.png' -DestinationPath '$(PackageOutputDir)RacesOfValheim_Thunderstore.zip' -Force; Compress-Archive -Path '$(TargetDir)$(TargetName).dll' -DestinationPath '$(PackageOutputDir)RacesOfValheim_Nexus.zip' -Force"" />
|
||||
<Message Text="Copying DLL to Valheim BepInEx plugins..." Importance="high" Condition="Exists('$(VALHEIM_INSTALL)\BepInEx\plugins')" />
|
||||
<Copy SourceFiles="$(TargetDir)$(TargetName).dll" DestinationFolder="$(VALHEIM_INSTALL)\BepInEx\plugins\" Condition="Exists('$(VALHEIM_INSTALL)\BepInEx\plugins')" />
|
||||
</Target>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using Jotunn.Managers;
|
||||
|
||||
|
|
@ -17,6 +17,17 @@ namespace RacesOfValheim
|
|||
|
||||
public bool IsFlying => isFlying;
|
||||
|
||||
// Read by RacesVisualController on other clients so they can keep this character airborne.
|
||||
public const string FlyingKey = "RacesOfValheim_SkadiFlying";
|
||||
|
||||
private void SetFlying(bool value)
|
||||
{
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(value);
|
||||
|
||||
ZNetView nview = Player.m_localPlayer.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid()) nview.GetZDO().Set(FlyingKey, value);
|
||||
}
|
||||
|
||||
// Time.time of the last powered/grounded moment. SkadiDirectedFlightPatch holds the form
|
||||
// level for a short window past this before letting it start sinking.
|
||||
public float LastPoweredTime;
|
||||
|
|
@ -74,7 +85,7 @@ namespace RacesOfValheim
|
|||
anim = GetComponentInChildren<Animator>();
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(false);
|
||||
SetFlying(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -89,13 +100,13 @@ namespace RacesOfValheim
|
|||
{
|
||||
isFlying = true;
|
||||
LastPoweredTime = Time.time;
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(true);
|
||||
SetFlying(true);
|
||||
}
|
||||
else if (isFlying && !isLanding)
|
||||
{
|
||||
isLanding = true;
|
||||
isFlying = false;
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(false);
|
||||
SetFlying(false);
|
||||
}
|
||||
else if (isLanding)
|
||||
{
|
||||
|
|
@ -103,7 +114,7 @@ namespace RacesOfValheim
|
|||
isLanding = false;
|
||||
isFlying = true;
|
||||
LastPoweredTime = Time.time;
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(true);
|
||||
SetFlying(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -494,7 +505,7 @@ namespace RacesOfValheim
|
|||
if (Active == this) Active = null;
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(false);
|
||||
SetFlying(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,45 +88,88 @@ namespace RacesOfValheim
|
|||
[HarmonyPatch(typeof(Player), "Update")]
|
||||
public static class Trol_PlayerUpdate_Patch
|
||||
{
|
||||
// Published by each player onto their own ZDO. The size a Trol should be depends on that
|
||||
// Trol's progression and True Form, both of which used to be read from whoever happened to
|
||||
// be looking - so observers sized remote Trols from their own tier, and never saw True
|
||||
// Form at all because the status effect only exists on the transformed player's client.
|
||||
public const string StateKey = "RacesOfValheim_State";
|
||||
public const string TrueFormKey = "RacesOfValheim_TrolTrueForm";
|
||||
|
||||
private static float lastRemoteLog = 0f;
|
||||
|
||||
private static float ScaleForState(int state)
|
||||
{
|
||||
if (state >= 6) return 1.30f;
|
||||
if (state >= 4) return 1.25f;
|
||||
return 1.2f;
|
||||
}
|
||||
|
||||
public static void Postfix(Player __instance)
|
||||
{
|
||||
if (__instance == null) return;
|
||||
|
||||
string race = "Human"; ZNetView nview = __instance.GetComponent<ZNetView>(); if (nview != null && nview.IsValid()) race = nview.GetZDO().GetString("RacesOfValheim_Race", "Human"); else if (__instance.m_customData != null && __instance.m_customData.TryGetValue("Race", out string savedRace)) race = savedRace; if (race == "Trol")
|
||||
{
|
||||
// Scale player visuals up by 20%
|
||||
GameObject visual = Traverse.Create(__instance).Field("m_visual").GetValue<GameObject>();
|
||||
// Prevent overriding scale while transforming or in True Form
|
||||
bool isTrueFormActive = __instance.GetSEMan() != null && __instance.GetSEMan().HaveStatusEffect("SE_TrolTrueForm".GetStableHashCode());
|
||||
bool isTransforming = (__instance == Player.m_localPlayer && TrolRace.Instance != null && TrolRace.Instance.isTransforming);
|
||||
|
||||
if (!isTrueFormActive && !isTransforming)
|
||||
{
|
||||
float targetScale = 1.2f;
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
if (state >= 6) targetScale = 1.30f;
|
||||
else if (state >= 4) targetScale = 1.25f;
|
||||
|
||||
if (visual != null && visual.transform.localScale != new Vector3(targetScale, targetScale, targetScale))
|
||||
{
|
||||
visual.transform.localScale = new Vector3(targetScale, targetScale, targetScale);
|
||||
}
|
||||
ZNetView nview = __instance.GetComponent<ZNetView>();
|
||||
bool zdoReady = nview != null && nview.IsValid();
|
||||
|
||||
string race = "Human";
|
||||
if (zdoReady) race = nview.GetZDO().GetString("RacesOfValheim_Race", "Human");
|
||||
else if (__instance.m_customData != null && __instance.m_customData.TryGetValue("Race", out string savedRace)) race = savedRace;
|
||||
|
||||
bool isLocal = __instance == Player.m_localPlayer;
|
||||
bool isTrueFormActive;
|
||||
int state;
|
||||
|
||||
if (isLocal)
|
||||
{
|
||||
state = BossProgressionManager.GetCurrentProgressionState();
|
||||
isTrueFormActive = __instance.GetSEMan() != null &&
|
||||
__instance.GetSEMan().HaveStatusEffect("SE_TrolTrueForm".GetStableHashCode());
|
||||
|
||||
// Publish so everyone else can size this character correctly.
|
||||
if (zdoReady)
|
||||
{
|
||||
nview.GetZDO().Set(StateKey, state);
|
||||
nview.GetZDO().Set(TrueFormKey, isTrueFormActive);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Reset scale if not Trol
|
||||
GameObject visual = Traverse.Create(__instance).Field("m_visual").GetValue<GameObject>();
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
float targetScale = 1.2f;
|
||||
if (state >= 6) targetScale = 1.30f;
|
||||
else if (state >= 4) targetScale = 1.25f;
|
||||
state = zdoReady ? nview.GetZDO().GetInt(StateKey, BossProgressionManager.MinState) : BossProgressionManager.MinState;
|
||||
isTrueFormActive = zdoReady && nview.GetZDO().GetBool(TrueFormKey, false);
|
||||
}
|
||||
|
||||
if (visual != null && visual.transform.localScale == new Vector3(targetScale, targetScale, targetScale))
|
||||
GameObject visual = Traverse.Create(__instance).Field("m_visual").GetValue<GameObject>();
|
||||
if (visual == null) return;
|
||||
|
||||
float targetScale = ScaleForState(state);
|
||||
|
||||
// TEMPORARY: remote Trol sizing still is not showing up for observers and static
|
||||
// reading has not explained why, so report what each observer actually computes.
|
||||
if (!isLocal && Time.time - lastRemoteLog > 2f)
|
||||
{
|
||||
lastRemoteLog = Time.time;
|
||||
Jotunn.Logger.LogInfo(
|
||||
$"[TrolSync] remote '{__instance.GetPlayerName()}' race='{race}' zdoReady={zdoReady} " +
|
||||
$"state={state} trueForm={isTrueFormActive} target={targetScale:F2} " +
|
||||
$"currentScale={visual.transform.localScale.x:F2} rootScale={__instance.transform.localScale.x:F2}");
|
||||
}
|
||||
|
||||
if (race == "Trol")
|
||||
{
|
||||
// Prevent overriding scale while transforming or in True Form
|
||||
bool isTransforming = isLocal && TrolRace.Instance != null && TrolRace.Instance.isTransforming;
|
||||
|
||||
if (!isTrueFormActive && !isTransforming &&
|
||||
visual.transform.localScale != new Vector3(targetScale, targetScale, targetScale))
|
||||
{
|
||||
visual.transform.localScale = Vector3.one;
|
||||
visual.transform.localScale = new Vector3(targetScale, targetScale, targetScale);
|
||||
}
|
||||
}
|
||||
else if (visual.transform.localScale == new Vector3(targetScale, targetScale, targetScale))
|
||||
{
|
||||
// Reset scale if not Trol
|
||||
visual.transform.localScale = Vector3.one;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ namespace RacesOfValheim
|
|||
private string m_lastSkadiForm = "";
|
||||
private GameObject m_currentFormInstance = null;
|
||||
private GameObject m_fireAuraVFX = null;
|
||||
private float m_lastFlightLog = 0f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
|
@ -205,7 +206,31 @@ namespace RacesOfValheim
|
|||
{
|
||||
ZNetView nview = m_player.GetComponent<ZNetView>();
|
||||
string currentForm = nview.GetZDO().GetString("RacesOfValheim_SkadiForm", "");
|
||||
|
||||
|
||||
// Flight lives in Character.m_flying, which DrakeFormBehavior only ever sets on the
|
||||
// flying player's own client. Observers left it false, so their copy of the character
|
||||
// kept running grounded motion under gravity and sank to the terrain no matter what
|
||||
// altitude was replicated. Mirror the flag from the ZDO so remote copies stay airborne.
|
||||
bool flying = nview.GetZDO().GetBool(DrakeFormBehavior.FlyingKey, false);
|
||||
HarmonyLib.Traverse.Create(m_player).Field("m_flying").SetValue(flying);
|
||||
|
||||
// Setting m_flying alone only helps if the remote copy runs Character motion at all.
|
||||
// Gravity on its rigidbody is what actually drags the body to the terrain while the
|
||||
// replicated position says otherwise, so switch that off directly for the duration.
|
||||
Rigidbody body = m_player.GetComponent<Rigidbody>();
|
||||
if (body != null && body.useGravity == flying)
|
||||
{
|
||||
body.useGravity = !flying;
|
||||
}
|
||||
|
||||
if (Time.time - m_lastFlightLog > 2f)
|
||||
{
|
||||
m_lastFlightLog = Time.time;
|
||||
Jotunn.Logger.LogInfo(
|
||||
$"[SkadiSync] remote '{m_player.GetPlayerName()}' form='{currentForm}' flying={flying} " +
|
||||
$"y={m_player.transform.position.y:F1} gravity={(body != null ? body.useGravity.ToString() : "no-body")}");
|
||||
}
|
||||
|
||||
if (currentForm != m_lastSkadiForm)
|
||||
{
|
||||
// Form changed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue