Version bumped in manifest.json, the packaging manifest and PluginVersion. Valheim 1.0's new creatures for the Aswid and the Draugh (seal, moose, Elaking, Jotun, Barka, Deep North Goblin and every Dvergr), the Elaking Hair Bundle in the blood refinery, and the Skeleton choosing its look at the barber. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
124 lines
4.6 KiB
C#
124 lines
4.6 KiB
C#
using HarmonyLib;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// The barber's own window, put to work for the Skeleton. Hair and beard are hidden on this
|
|
/// race, so the two hair arrows would change nothing anyone can see; for a Skeleton they step
|
|
/// through the bodies this tier has unlocked instead (normal, green, flames), the label
|
|
/// between them names the one worn, Apply keeps it and Cancel puts the old one back.
|
|
///
|
|
/// The look is cosmetic - see SkeletonProgression.ResolveModel - and lives in m_customData,
|
|
/// which SkeletonRace copies to the ZDO so everyone else sees it too.
|
|
/// </summary>
|
|
public static class SkeletonBarber
|
|
{
|
|
// What was worn when the chair was sat in, for Cancel.
|
|
private static string lookOnOpen = "";
|
|
|
|
private static bool Active =>
|
|
Player.m_localPlayer != null && SkeletonRace.IsSkeleton();
|
|
|
|
private static void Step(int direction)
|
|
{
|
|
Player player = Player.m_localPlayer;
|
|
int state = BossProgressionManager.GetCurrentProgressionState();
|
|
var models = SkeletonProgression.UnlockedModels(state);
|
|
int at = models.IndexOf(SkeletonVisuals.GetModel(player, state));
|
|
int next = (at + direction + models.Count) % models.Count;
|
|
SetLook(player, models[next]);
|
|
}
|
|
|
|
private static void SetLook(Player player, string look)
|
|
{
|
|
player.m_customData[SkeletonVisuals.LookDataKey] = look;
|
|
|
|
// Rebuild the body now, so the mirror-less barber still shows the result.
|
|
VisEquipment vis = player.GetComponent<VisEquipment>();
|
|
if (vis != null) Traverse.Create(vis).Method("UpdateVisuals").GetValue();
|
|
}
|
|
|
|
private static string LabelFor(string model)
|
|
{
|
|
return ModText.Get(model == SkeletonProgression.FireModel ? "rov_msg_skeleton_look_flames"
|
|
: model == SkeletonProgression.PoisonModel ? "rov_msg_skeleton_look_green"
|
|
: "rov_msg_skeleton_look_normal");
|
|
}
|
|
|
|
[HarmonyPatch(typeof(PlayerCustomizaton), nameof(PlayerCustomizaton.ShowBarberGui))]
|
|
public static class ShowBarberGui_Patch
|
|
{
|
|
public static void Postfix()
|
|
{
|
|
if (!Active) return;
|
|
lookOnOpen = SkeletonVisuals.GetModel(Player.m_localPlayer, BossProgressionManager.GetCurrentProgressionState());
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(PlayerCustomizaton), "OnHairLeft")]
|
|
public static class OnHairLeft_Patch
|
|
{
|
|
public static bool Prefix()
|
|
{
|
|
if (!Active) return true;
|
|
Step(-1);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(PlayerCustomizaton), "OnHairRight")]
|
|
public static class OnHairRight_Patch
|
|
{
|
|
public static bool Prefix()
|
|
{
|
|
if (!Active) return true;
|
|
Step(1);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// The beard arrows have nothing to do for a Skeleton.
|
|
[HarmonyPatch(typeof(PlayerCustomizaton), "OnBeardLeft")]
|
|
public static class OnBeardLeft_Patch
|
|
{
|
|
public static bool Prefix() => !Active;
|
|
}
|
|
|
|
[HarmonyPatch(typeof(PlayerCustomizaton), "OnBeardRight")]
|
|
public static class OnBeardRight_Patch
|
|
{
|
|
public static bool Prefix() => !Active;
|
|
}
|
|
|
|
[HarmonyPatch(typeof(PlayerCustomizaton), "OnCancel")]
|
|
public static class OnCancel_Patch
|
|
{
|
|
public static void Prefix()
|
|
{
|
|
if (!Active) return;
|
|
SetLook(Player.m_localPlayer, lookOnOpen);
|
|
}
|
|
}
|
|
|
|
// The window refreshes its labels every frame, so the name is written after it.
|
|
[HarmonyPatch(typeof(PlayerCustomizaton), "Update")]
|
|
public static class Update_Patch
|
|
{
|
|
public static void Postfix(PlayerCustomizaton __instance)
|
|
{
|
|
if (!Active || !PlayerCustomizaton.IsBarberGuiVisible()) return;
|
|
|
|
if (__instance.m_selectedHair != null)
|
|
{
|
|
__instance.m_selectedHair.text = LabelFor(
|
|
SkeletonVisuals.GetModel(Player.m_localPlayer, BossProgressionManager.GetCurrentProgressionState()));
|
|
}
|
|
if (__instance.m_beardPanel != null && __instance.m_beardPanel.gameObject.activeSelf)
|
|
{
|
|
__instance.m_beardPanel.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|