start draugh race
This commit is contained in:
parent
73da3bacd3
commit
d387131086
7 changed files with 522 additions and 16 deletions
119
JotunnModStub/Draugh/DraughPatches.cs
Normal file
119
JotunnModStub/Draugh/DraughPatches.cs
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
[HarmonyPatch(typeof(VisEquipment), "UpdateColors")]
|
||||
public static class DraughSkinColorPatch
|
||||
{
|
||||
public static void Postfix(VisEquipment __instance)
|
||||
{
|
||||
if (!__instance.m_isPlayer) return;
|
||||
Player player = __instance.GetComponent<Player>();
|
||||
if (player == null) return;
|
||||
|
||||
string race = "Human";
|
||||
ZNetView nview = player.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid())
|
||||
race = nview.GetZDO().GetString("RacesOfValheim_Race", "Human");
|
||||
else if (player.m_customData != null && player.m_customData.TryGetValue("Race", out string savedRace))
|
||||
race = savedRace;
|
||||
|
||||
if (race != "Draugh") return;
|
||||
|
||||
if (__instance.m_bodyModel != null && __instance.m_bodyModel.material != null)
|
||||
{
|
||||
// Sickly grayish-green undead skin color (corpse green)
|
||||
Color draughColor = new Color(0.25f, 0.4f, 0.28f, 1f);
|
||||
__instance.m_bodyModel.material.SetColor("_SkinColor", draughColor);
|
||||
}
|
||||
|
||||
// Desaturate and darken hair and beard
|
||||
Vector3 origHairVec = Traverse.Create(__instance).Field("m_hairColor").GetValue<Vector3>();
|
||||
Color origHair = new Color(origHairVec.x, origHairVec.y, origHairVec.z);
|
||||
float l = 0.299f * origHair.r + 0.587f * origHair.g + 0.114f * origHair.b;
|
||||
Color desatHair = Color.Lerp(origHair, new Color(l, l, l), 0.75f) * 0.7f; // 75% desaturated, 30% darker
|
||||
desatHair.a = 1f;
|
||||
|
||||
var hairObj = Traverse.Create(__instance).Field("m_hairItemInstance").GetValue<GameObject>();
|
||||
if (hairObj != null)
|
||||
{
|
||||
foreach (var r in hairObj.GetComponentsInChildren<Renderer>())
|
||||
if (r.material != null && r.material.HasProperty("_SkinColor")) r.material.SetColor("_SkinColor", desatHair);
|
||||
}
|
||||
var hairList = Traverse.Create(__instance).Field("m_hairItemInstances").GetValue<System.Collections.Generic.List<GameObject>>();
|
||||
if (hairList != null)
|
||||
{
|
||||
foreach (var h in hairList)
|
||||
if (h != null)
|
||||
foreach (var r in h.GetComponentsInChildren<Renderer>())
|
||||
if (r.material != null && r.material.HasProperty("_SkinColor")) r.material.SetColor("_SkinColor", desatHair);
|
||||
}
|
||||
|
||||
var beardObj = Traverse.Create(__instance).Field("m_beardItemInstance").GetValue<GameObject>();
|
||||
if (beardObj != null)
|
||||
{
|
||||
foreach (var r in beardObj.GetComponentsInChildren<Renderer>())
|
||||
if (r.material != null && r.material.HasProperty("_SkinColor")) r.material.SetColor("_SkinColor", desatHair);
|
||||
}
|
||||
var beardList = Traverse.Create(__instance).Field("m_beardItemInstances").GetValue<System.Collections.Generic.List<GameObject>>();
|
||||
if (beardList != null)
|
||||
{
|
||||
foreach (var b in beardList)
|
||||
if (b != null)
|
||||
foreach (var r in b.GetComponentsInChildren<Renderer>())
|
||||
if (r.material != null && r.material.HasProperty("_SkinColor")) r.material.SetColor("_SkinColor", desatHair);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(VisEquipment), "UpdateVisuals")]
|
||||
public static class Draugh_VisEquipment_UpdateVisuals_Patch
|
||||
{
|
||||
public static string GetPlayerRace(VisEquipment visEq)
|
||||
{
|
||||
Player player = visEq.GetComponent<Player>();
|
||||
if (player != null)
|
||||
{
|
||||
ZNetView nview = player.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid())
|
||||
return nview.GetZDO().GetString("RacesOfValheim_Race", "Human");
|
||||
|
||||
if (player.m_customData != null && player.m_customData.TryGetValue("Race", out string r))
|
||||
return r;
|
||||
}
|
||||
return "Human";
|
||||
}
|
||||
|
||||
public static void Postfix(VisEquipment __instance)
|
||||
{
|
||||
if (!__instance.m_isPlayer) return;
|
||||
string race = GetPlayerRace(__instance);
|
||||
if (race != "Draugh") return;
|
||||
|
||||
// Future model swaps (e.g. Draugr head) or hiding items can go here
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Character), "Damage")]
|
||||
public static class Draugh_Damage_Patch
|
||||
{
|
||||
public static void Prefix(Character __instance, HitData hit)
|
||||
{
|
||||
if (hit == null || __instance == null || !__instance.IsPlayer()) return;
|
||||
if (__instance != Player.m_localPlayer) return;
|
||||
|
||||
if (!DraughRace.IsDraugh()) return;
|
||||
|
||||
// Apply specific damage modifiers for Draugh
|
||||
// -20% damage received from slash, pierce, blunt
|
||||
hit.m_damage.m_blunt *= 0.8f;
|
||||
hit.m_damage.m_slash *= 0.8f;
|
||||
hit.m_damage.m_pierce *= 0.8f;
|
||||
|
||||
// +50% damage received from fire, spirit
|
||||
hit.m_damage.m_fire *= 1.5f;
|
||||
hit.m_damage.m_spirit *= 1.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue