Initial commit
This commit is contained in:
commit
c4a24c9fdf
142 changed files with 15491 additions and 0 deletions
480
JotunnModStub/Skeleton/SkeletonPatches.cs
Normal file
480
JotunnModStub/Skeleton/SkeletonPatches.cs
Normal file
|
|
@ -0,0 +1,480 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using Jotunn.Managers;
|
||||
using System.Linq;
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
public static class SkeletonPatches
|
||||
{
|
||||
// Cache the skeleton mesh and materials for performance
|
||||
private static Mesh skeletonMesh = null;
|
||||
private static Material[] skeletonMaterials = null;
|
||||
|
||||
[HarmonyPatch(typeof(Player), "UseStamina")]
|
||||
public static class Player_UseStamina_Patch
|
||||
{
|
||||
public static bool Prefix(Player __instance)
|
||||
{
|
||||
if ((SkeletonRace.IsSkeleton() || AswidRace.IsAswid()) && __instance == Player.m_localPlayer)
|
||||
{
|
||||
// Infinite stamina: skip the original UseStamina method
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "ConsumeItem")]
|
||||
public static class Player_ConsumeItem_Patch
|
||||
{
|
||||
public static bool Prefix(Player __instance, ItemDrop.ItemData item, ref bool __result)
|
||||
{
|
||||
if (__instance == Player.m_localPlayer)
|
||||
{
|
||||
if (SkeletonRace.IsSkeleton() && item.m_shared.m_itemType == ItemDrop.ItemData.ItemType.Consumable && (item.m_shared.m_food > 0 || item.m_shared.m_foodStamina > 0 || item.m_shared.m_foodEitr > 0))
|
||||
{
|
||||
__instance.Message(MessageHud.MessageType.Center, "Skeletons do not need to eat.");
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
else if (AswidRace.IsAswid() && !AswidRace.BypassAswidFoodCheck && item.m_shared.m_itemType == ItemDrop.ItemData.ItemType.Consumable && (item.m_shared.m_food > 0 || item.m_shared.m_foodStamina > 0 || item.m_shared.m_foodEitr > 0))
|
||||
{
|
||||
__instance.Message(MessageHud.MessageType.Center, "Mortal food disgusts you.");
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Player), "Message")]
|
||||
public static class Player_Message_Patch
|
||||
{
|
||||
public static bool Prefix(Player __instance, MessageHud.MessageType type, string msg)
|
||||
{
|
||||
if (__instance == Player.m_localPlayer)
|
||||
{
|
||||
if (msg == "$msg_eatanother" || msg.ToLower().Contains("eat") || msg.ToLower().Contains("mangiare") || msg.ToLower().Contains("boccone"))
|
||||
{
|
||||
if (AswidRace.IsAswid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Hud), "UpdateFood")]
|
||||
public static class Hud_UpdateFood_Patch
|
||||
{
|
||||
private static readonly string[] foodElements = new string[]
|
||||
{
|
||||
"hudroot/healthpanel/foodicon",
|
||||
"hudroot/healthpanel/foodicon (1)",
|
||||
"hudroot/healthpanel/food0",
|
||||
"hudroot/healthpanel/food1",
|
||||
"hudroot/healthpanel/food2",
|
||||
"hudroot/healthpanel/FoodText",
|
||||
"hudroot/healthpanel/Food"
|
||||
};
|
||||
|
||||
public static bool Prefix(Hud __instance, Player player)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (player == Player.m_localPlayer && SkeletonRace.IsSkeleton())
|
||||
{
|
||||
if (__instance.m_foodBarRoot != null && __instance.m_foodBarRoot.gameObject.activeSelf)
|
||||
{
|
||||
__instance.m_foodBarRoot.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
foreach (string path in foodElements)
|
||||
{
|
||||
Transform t = __instance.transform.Find(path);
|
||||
if (t != null && t.gameObject.activeSelf)
|
||||
{
|
||||
t.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
return false; // Safely skip original Valheim Hud.UpdateFood
|
||||
}
|
||||
else
|
||||
{
|
||||
if (__instance.m_foodBarRoot != null && !__instance.m_foodBarRoot.gameObject.activeSelf)
|
||||
{
|
||||
__instance.m_foodBarRoot.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
foreach (string path in foodElements)
|
||||
{
|
||||
Transform t = __instance.transform.Find(path);
|
||||
if (t != null && !t.gameObject.activeSelf)
|
||||
{
|
||||
t.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
if (player == Player.m_localPlayer && SkeletonRace.IsSkeleton()) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(VisEquipment), "UpdateVisuals")]
|
||||
public static class VisEquipment_UpdateVisuals_Patch
|
||||
{
|
||||
public static void Postfix(VisEquipment __instance)
|
||||
{
|
||||
if (!__instance.m_isPlayer) return;
|
||||
Player p = __instance.GetComponent<Player>();
|
||||
if (p == null) return;
|
||||
ZNetView nview = p.GetComponent<ZNetView>();
|
||||
if (nview == null || !nview.IsValid()) return;
|
||||
|
||||
string race = nview.GetZDO().GetString("RacesOfValheim_Race", "Human");
|
||||
|
||||
if (race == "Skeleton")
|
||||
{
|
||||
if (__instance.m_bodyModel != null)
|
||||
{
|
||||
// Ensure the base model is hidden
|
||||
__instance.m_bodyModel.enabled = false;
|
||||
|
||||
int state = nview.GetZDO().GetInt("RacesOfValheim_SkeletonState", 0);
|
||||
SkeletonProgression.SkeletonRules rules = SkeletonProgression.GetRules(state);
|
||||
string targetBodyName = $"SkeletonBody_{rules.ModelPrefab}";
|
||||
|
||||
// Check if we already created the Skeleton body for this VisEquipment
|
||||
Transform parentTransform = __instance.m_bodyModel.transform.parent;
|
||||
|
||||
// Destroy old bodies if state changed
|
||||
for (int i = parentTransform.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
Transform child = parentTransform.GetChild(i);
|
||||
if (child.name.StartsWith("SkeletonBody") && child.name != targetBodyName)
|
||||
{
|
||||
UnityEngine.Object.Destroy(child.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
Transform skeletonBodyTransform = parentTransform.Find(targetBodyName);
|
||||
|
||||
if (skeletonBodyTransform == null)
|
||||
{
|
||||
GameObject skelPrefab = PrefabManager.Cache.GetPrefab<GameObject>(rules.ModelPrefab);
|
||||
if (skelPrefab != null)
|
||||
{
|
||||
GameObject skelObj = new GameObject(targetBodyName);
|
||||
skelObj.transform.SetParent(parentTransform, false);
|
||||
|
||||
SkinnedMeshRenderer[] smrs = skelPrefab.GetComponentsInChildren<SkinnedMeshRenderer>(true);
|
||||
foreach (SkinnedMeshRenderer smr in smrs)
|
||||
{
|
||||
GameObject partObj = UnityEngine.Object.Instantiate(smr.gameObject, skelObj.transform);
|
||||
partObj.name = smr.gameObject.name;
|
||||
SkinnedMeshRenderer newSmr = partObj.GetComponent<SkinnedMeshRenderer>();
|
||||
|
||||
// Map bones by name
|
||||
Transform[] playerBones = __instance.m_bodyModel.bones;
|
||||
Transform[] newBones = new Transform[newSmr.bones.Length];
|
||||
for (int i = 0; i < newSmr.bones.Length; i++)
|
||||
{
|
||||
Transform matchedBone = FindBoneByName(playerBones, newSmr.bones[i].name);
|
||||
newBones[i] = matchedBone != null ? matchedBone : playerBones[0];
|
||||
}
|
||||
newSmr.bones = newBones;
|
||||
|
||||
if (newSmr.rootBone != null)
|
||||
{
|
||||
newSmr.rootBone = FindBoneByName(playerBones, newSmr.rootBone.name) ?? playerBones[0];
|
||||
}
|
||||
}
|
||||
|
||||
skeletonBodyTransform = skelObj.transform;
|
||||
}
|
||||
}
|
||||
|
||||
if (skeletonBodyTransform != null)
|
||||
{
|
||||
skeletonBodyTransform.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
// Prevent Animator from freezing when body is disabled
|
||||
Animator anim = __instance.GetComponentInChildren<Animator>();
|
||||
if (anim != null)
|
||||
{
|
||||
anim.cullingMode = AnimatorCullingMode.AlwaysAnimate;
|
||||
}
|
||||
|
||||
HideItemInstances(__instance, "m_hairItemInstances");
|
||||
HideItemInstances(__instance, "m_beardItemInstances");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not a skeleton, ensure human body is visible and skeleton is hidden
|
||||
if (__instance.m_bodyModel != null)
|
||||
{
|
||||
__instance.m_bodyModel.enabled = true;
|
||||
Transform parentTransform = __instance.m_bodyModel.transform.parent;
|
||||
if (parentTransform != null)
|
||||
{
|
||||
for (int i = 0; i < parentTransform.childCount; i++)
|
||||
{
|
||||
Transform child = parentTransform.GetChild(i);
|
||||
if (child.name.StartsWith("SkeletonBody"))
|
||||
{
|
||||
child.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ShowItemInstances(__instance, "m_hairItemInstances");
|
||||
ShowItemInstances(__instance, "m_beardItemInstances");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void HideItemInstances(VisEquipment visEq, string fieldName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var field = typeof(VisEquipment).GetField(fieldName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||
if (field != null)
|
||||
{
|
||||
var list = field.GetValue(visEq) as System.Collections.Generic.List<GameObject>;
|
||||
if (list != null)
|
||||
{
|
||||
foreach (GameObject go in list)
|
||||
{
|
||||
if (go != null) go.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"Failed to hide {fieldName}: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ShowItemInstances(VisEquipment visEq, string fieldName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var field = typeof(VisEquipment).GetField(fieldName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||
if (field != null)
|
||||
{
|
||||
var list = field.GetValue(visEq) as System.Collections.Generic.List<GameObject>;
|
||||
if (list != null)
|
||||
{
|
||||
foreach (GameObject go in list)
|
||||
{
|
||||
if (go != null) go.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (System.Exception e) { }
|
||||
}
|
||||
|
||||
private static Transform FindBoneByName(Transform[] bones, string skelBoneName)
|
||||
{
|
||||
// Exact match first
|
||||
foreach (Transform b in bones)
|
||||
{
|
||||
if (b != null && b.name == skelBoneName) return b;
|
||||
}
|
||||
|
||||
// Fuzzy match
|
||||
string sName = skelBoneName.ToLower().Replace("skeleton_", "").Replace("skel_", "").Replace(" skeleton", "");
|
||||
|
||||
// Some specific Valheim mappings if needed
|
||||
if (sName == "pelvis") sName = "hips";
|
||||
if (sName == "clavicle.l") sName = "leftshoulder";
|
||||
if (sName == "clavicle.r") sName = "rightshoulder";
|
||||
if (sName == "upperarm.l") sName = "leftarm";
|
||||
if (sName == "upperarm.r") sName = "rightarm";
|
||||
if (sName == "lowerarm.l") sName = "leftforearm";
|
||||
if (sName == "lowerarm.r") sName = "rightforearm";
|
||||
if (sName == "thigh.l") sName = "leftupleg";
|
||||
if (sName == "thigh.r") sName = "rightupleg";
|
||||
if (sName == "calf.l") sName = "leftleg";
|
||||
if (sName == "calf.r") sName = "rightleg";
|
||||
|
||||
foreach (Transform b in bones)
|
||||
{
|
||||
if (b != null)
|
||||
{
|
||||
string pName = b.name.ToLower();
|
||||
if (pName == sName || pName.Contains(sName) || sName.Contains(pName))
|
||||
{
|
||||
return b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Character), "Damage")]
|
||||
public static class Character_Damage_Patch
|
||||
{
|
||||
private static float lastStunTime = 0f;
|
||||
|
||||
public static bool Prefix(Character __instance, HitData hit)
|
||||
{
|
||||
if (Player.m_localPlayer == null) return true;
|
||||
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
var rules = SkeletonProgression.GetRules(state);
|
||||
|
||||
// Auto-Resurrect check
|
||||
if (__instance == Player.m_localPlayer && SkeletonRace.IsSkeleton() && rules.AutoResurrect)
|
||||
{
|
||||
if (hit.GetTotalDamage() >= __instance.GetHealth())
|
||||
{
|
||||
if (!Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_SkeletonResurrectCooldown".GetStableHashCode()))
|
||||
{
|
||||
// Cancel death!
|
||||
Player.m_localPlayer.Heal(Player.m_localPlayer.GetMaxHealth(), true);
|
||||
Player.m_localPlayer.GetSEMan().AddStatusEffect("SE_SkeletonResurrectCooldown".GetStableHashCode(), true);
|
||||
|
||||
// Spawn VFX
|
||||
GameObject vfx = PrefabManager.Cache.GetPrefab<GameObject>("vfx_skeleton_spawn") ??
|
||||
PrefabManager.Cache.GetPrefab<GameObject>("vfx_bloodmagic_aoe");
|
||||
if (vfx != null)
|
||||
{
|
||||
UnityEngine.Object.Instantiate(vfx, Player.m_localPlayer.transform.position, Quaternion.identity);
|
||||
}
|
||||
|
||||
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You have been resurrected by dark magic!");
|
||||
return false; // Skip applying this lethal damage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Outgoing damage (Lifesteal, Poison, Stun)
|
||||
Character attacker = hit.GetAttacker();
|
||||
if (attacker != null && attacker == Player.m_localPlayer && SkeletonRace.IsSkeleton())
|
||||
{
|
||||
// Auto Stun
|
||||
if (rules.AutoStunFirstHit && Time.time - lastStunTime > 5f)
|
||||
{
|
||||
hit.m_staggerMultiplier = 100f; // Force stagger
|
||||
lastStunTime = Time.time;
|
||||
}
|
||||
|
||||
// Poison Attacks
|
||||
if (rules.PoisonAttacks)
|
||||
{
|
||||
hit.m_damage.m_poison += 20f; // Add flat 20 poison damage
|
||||
}
|
||||
|
||||
// Lifesteal
|
||||
if (rules.LifestealPercent > 0f)
|
||||
{
|
||||
float physDamage = hit.m_damage.m_blunt + hit.m_damage.m_slash + hit.m_damage.m_pierce;
|
||||
if (physDamage > 0)
|
||||
{
|
||||
float healAmount = physDamage * rules.LifestealPercent;
|
||||
Player.m_localPlayer.Heal(healAmount, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Character), "OnDeath")]
|
||||
public static class Character_OnDeath_Patch
|
||||
{
|
||||
public static System.Collections.Generic.List<Character> activeMinions = new System.Collections.Generic.List<Character>();
|
||||
|
||||
public static void Prefix(Character __instance)
|
||||
{
|
||||
if (Player.m_localPlayer == null || !SkeletonRace.IsSkeleton()) return;
|
||||
|
||||
HitData lastHit = HarmonyLib.Traverse.Create(__instance).Field("m_lastHit").GetValue<HitData>();
|
||||
if (lastHit != null && lastHit.GetAttacker() == Player.m_localPlayer)
|
||||
{
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
var rules = SkeletonProgression.GetRules(state);
|
||||
|
||||
if (rules.SummonOnKill && !string.IsNullOrEmpty(rules.SummonPrefab))
|
||||
{
|
||||
// Clean up dead minions
|
||||
activeMinions.RemoveAll(m => m == null || m.IsDead());
|
||||
|
||||
if (activeMinions.Count < rules.MaxSummons)
|
||||
{
|
||||
GameObject minionPrefab = PrefabManager.Cache.GetPrefab<GameObject>(rules.SummonPrefab);
|
||||
if (minionPrefab != null)
|
||||
{
|
||||
GameObject minion = UnityEngine.Object.Instantiate(minionPrefab, __instance.transform.position, Quaternion.identity);
|
||||
Character minionChar = minion.GetComponent<Character>();
|
||||
|
||||
if (minionChar != null)
|
||||
{
|
||||
// Make it friendly
|
||||
minionChar.m_faction = Character.Faction.Players;
|
||||
BaseAI ai = minion.GetComponent<BaseAI>();
|
||||
if (ai != null)
|
||||
{
|
||||
MonsterAI monsterAI = minion.GetComponent<MonsterAI>();
|
||||
if (monsterAI != null)
|
||||
{
|
||||
monsterAI.SetFollowTarget(Player.m_localPlayer.gameObject);
|
||||
}
|
||||
}
|
||||
activeMinions.Add(minionChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
[HarmonyPatch(typeof(BaseAI), "IsEnemy", typeof(Character), typeof(Character))]
|
||||
public static class BaseAI_IsEnemy_Patch
|
||||
{
|
||||
public static void Postfix(Character a, Character b, ref bool __result)
|
||||
{
|
||||
if (!__result || !SkeletonRace.IsSkeleton() || Player.m_localPlayer == null) return;
|
||||
|
||||
Character playerChar = Player.m_localPlayer;
|
||||
Character otherChar = null;
|
||||
|
||||
if (a == playerChar) otherChar = b;
|
||||
else if (b == playerChar) otherChar = a;
|
||||
|
||||
if (otherChar != null)
|
||||
{
|
||||
string name = otherChar.gameObject.name.Replace("(Clone)", "").ToLower();
|
||||
if (name == "skeleton" ||
|
||||
name == "skeleton_noarcher" ||
|
||||
name == "skeleton_poison" ||
|
||||
name == "skeleton_friendly" ||
|
||||
name.StartsWith("draugr") ||
|
||||
name == "ghost" ||
|
||||
name == "wraith")
|
||||
{
|
||||
__result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
98
JotunnModStub/Skeleton/SkeletonProgression.cs
Normal file
98
JotunnModStub/Skeleton/SkeletonProgression.cs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
using System;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
public static class SkeletonProgression
|
||||
{
|
||||
public static float GetMaxHealthBonus(int state)
|
||||
{
|
||||
if (state == 0) return 0f;
|
||||
if (state == 1) return 50f;
|
||||
if (state == 2) return 80f;
|
||||
if (state == 3) return 110f;
|
||||
if (state == 4) return 140f;
|
||||
if (state == 5) return 170f;
|
||||
if (state == 6) return 200f;
|
||||
if (state == 7) return 230f;
|
||||
if (state >= 8) return 275f;
|
||||
return 50f;
|
||||
}
|
||||
|
||||
public struct SkeletonRules
|
||||
{
|
||||
public float LifestealPercent;
|
||||
public bool EnhancedRegen;
|
||||
public bool PoisonImmunity;
|
||||
public bool PoisonAttacks;
|
||||
public bool AutoResurrect;
|
||||
public bool SummonOnKill;
|
||||
public int MaxSummons;
|
||||
public string SummonPrefab;
|
||||
public bool AutoStunFirstHit;
|
||||
public bool FireAura;
|
||||
public string ModelPrefab;
|
||||
public UnityEngine.Vector3 ScaleMultiplier;
|
||||
}
|
||||
|
||||
public static SkeletonRules GetRules(int state)
|
||||
{
|
||||
SkeletonRules rules = new SkeletonRules
|
||||
{
|
||||
LifestealPercent = 0f,
|
||||
EnhancedRegen = false,
|
||||
PoisonImmunity = false,
|
||||
PoisonAttacks = false,
|
||||
AutoResurrect = false,
|
||||
SummonOnKill = false,
|
||||
MaxSummons = 0,
|
||||
SummonPrefab = "",
|
||||
AutoStunFirstHit = false,
|
||||
FireAura = false,
|
||||
ModelPrefab = "Skeleton",
|
||||
ScaleMultiplier = UnityEngine.Vector3.one
|
||||
};
|
||||
|
||||
if (state >= 2)
|
||||
{
|
||||
rules.ModelPrefab = "Skeleton_Poison";
|
||||
rules.LifestealPercent = 0.20f;
|
||||
}
|
||||
if (state >= 3)
|
||||
{
|
||||
rules.EnhancedRegen = true;
|
||||
}
|
||||
if (state >= 4)
|
||||
{
|
||||
rules.PoisonImmunity = true;
|
||||
rules.PoisonAttacks = true;
|
||||
}
|
||||
if (state >= 5)
|
||||
{
|
||||
rules.AutoResurrect = true;
|
||||
}
|
||||
if (state >= 6)
|
||||
{
|
||||
rules.ModelPrefab = "Skeleton_Poison";
|
||||
rules.LifestealPercent = 0.30f;
|
||||
rules.SummonOnKill = true;
|
||||
rules.MaxSummons = 2;
|
||||
rules.SummonPrefab = "Skeleton_friendly";
|
||||
rules.ScaleMultiplier = UnityEngine.Vector3.one * 1.1f;
|
||||
}
|
||||
if (state >= 7)
|
||||
{
|
||||
rules.AutoStunFirstHit = true;
|
||||
rules.LifestealPercent = 0.40f;
|
||||
}
|
||||
if (state >= 8)
|
||||
{
|
||||
rules.ModelPrefab = "Charred_Twitcher";
|
||||
rules.SummonPrefab = "Charred_Twitcher";
|
||||
rules.FireAura = true;
|
||||
rules.ScaleMultiplier = new UnityEngine.Vector3(0.85f, 1.20f, 0.85f);
|
||||
}
|
||||
|
||||
return rules;
|
||||
}
|
||||
}
|
||||
}
|
||||
466
JotunnModStub/Skeleton/SkeletonRace.cs
Normal file
466
JotunnModStub/Skeleton/SkeletonRace.cs
Normal file
|
|
@ -0,0 +1,466 @@
|
|||
using UnityEngine;
|
||||
using Jotunn.Managers;
|
||||
using Jotunn.Entities;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
public class SkeletonRace : MonoBehaviour
|
||||
{
|
||||
public static SkeletonRace Instance;
|
||||
public static SE_SkeletonStats skeletonStatsSE;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void CreateModAssets()
|
||||
{
|
||||
var se = ScriptableObject.CreateInstance<SE_SkeletonStats>();
|
||||
se.name = "SE_SkeletonStats";
|
||||
se.m_name = "Undead Fortitude";
|
||||
|
||||
// Icon
|
||||
GameObject skelTrophy = PrefabManager.Cache.GetPrefab<ItemDrop>("TrophySkeleton")?.gameObject;
|
||||
if (skelTrophy != null)
|
||||
{
|
||||
ItemDrop trophyDrop = skelTrophy.GetComponent<ItemDrop>();
|
||||
if (trophyDrop != null && trophyDrop.m_itemData.m_shared.m_icons.Length > 0)
|
||||
{
|
||||
se.m_icon = trophyDrop.m_itemData.m_shared.m_icons[0];
|
||||
}
|
||||
}
|
||||
|
||||
CustomStatusEffect skeletonStats = new CustomStatusEffect(se, fixReference: false);
|
||||
ItemManager.Instance.AddStatusEffect(skeletonStats);
|
||||
skeletonStatsSE = skeletonStats.StatusEffect as SE_SkeletonStats;
|
||||
|
||||
var resurrectSE = ScriptableObject.CreateInstance<SE_SkeletonResurrectCooldown>();
|
||||
resurrectSE.name = "SE_SkeletonResurrectCooldown";
|
||||
CustomStatusEffect customResurrectSE = new CustomStatusEffect(resurrectSE, fixReference: false);
|
||||
ItemManager.Instance.AddStatusEffect(customResurrectSE);
|
||||
}
|
||||
|
||||
public static bool IsSkeleton()
|
||||
{
|
||||
return Player.m_localPlayer != null &&
|
||||
Player.m_localPlayer.m_customData.ContainsKey("Race") &&
|
||||
Player.m_localPlayer.m_customData["Race"] == "Skeleton";
|
||||
}
|
||||
|
||||
private float lastAuraTime = 0f;
|
||||
private GameObject fireAuraVFX = null;
|
||||
private static List<ItemDrop.ItemData>[] cachedRealFoods = new List<ItemDrop.ItemData>[9];
|
||||
|
||||
private List<ItemDrop.ItemData> GetBestRealFoods(int state)
|
||||
{
|
||||
if (state < 1) state = 1;
|
||||
if (state > 8) state = 8;
|
||||
if (cachedRealFoods[state] != null) return cachedRealFoods[state];
|
||||
|
||||
if (ObjectDB.instance == null || ObjectDB.instance.m_items == null) return null;
|
||||
|
||||
float targetHealth = SkeletonProgression.GetMaxHealthBonus(state);
|
||||
|
||||
List<ItemDrop.ItemData> allFoods = new List<ItemDrop.ItemData>();
|
||||
foreach (GameObject obj in ObjectDB.instance.m_items)
|
||||
{
|
||||
ItemDrop drop = obj.GetComponent<ItemDrop>();
|
||||
if (drop != null && drop.m_itemData != null && drop.m_itemData.m_shared.m_itemType == ItemDrop.ItemData.ItemType.Consumable && drop.m_itemData.m_shared.m_food > 0)
|
||||
{
|
||||
allFoods.Add(drop.m_itemData);
|
||||
}
|
||||
}
|
||||
|
||||
if (allFoods.Count < 3) return null;
|
||||
|
||||
float bestDiff = float.MaxValue;
|
||||
float bestRegen = -1f;
|
||||
List<ItemDrop.ItemData> bestCombo = null;
|
||||
|
||||
if (state == 8)
|
||||
{
|
||||
ItemDrop.ItemData f1 = null, f2 = null, f3 = null;
|
||||
foreach(var drop in allFoods)
|
||||
{
|
||||
string n = drop.m_shared.m_name.ToLower();
|
||||
string p = drop.m_dropPrefab != null ? drop.m_dropPrefab.name.ToLower() : "";
|
||||
|
||||
if (f1 == null && ((n.Contains("asksvin") && n.Contains("tail")) || (p.Contains("asksvin") && p.Contains("tail")))) f1 = drop;
|
||||
else if (f2 == null && ((n.Contains("mashed") && n.Contains("meat")) || (p.Contains("mashed") && p.Contains("meat")))) f2 = drop;
|
||||
else if (f3 == null && ((n.Contains("piquant") && n.Contains("pie")) || (p.Contains("piquant") && p.Contains("pie")))) f3 = drop;
|
||||
}
|
||||
|
||||
if (f1 != null && f2 != null && f3 != null)
|
||||
{
|
||||
bestCombo = new List<ItemDrop.ItemData> { f1.Clone(), f2.Clone(), f3.Clone() };
|
||||
}
|
||||
}
|
||||
|
||||
if (bestCombo == null)
|
||||
{
|
||||
for (int i = 0; i < allFoods.Count; i++)
|
||||
{
|
||||
for (int j = i; j < allFoods.Count; j++)
|
||||
{
|
||||
for (int k = j; k < allFoods.Count; k++)
|
||||
{
|
||||
var f1 = allFoods[i];
|
||||
var f2 = allFoods[j];
|
||||
var f3 = allFoods[k];
|
||||
|
||||
float hpSum = f1.m_shared.m_food + f2.m_shared.m_food + f3.m_shared.m_food;
|
||||
float regenSum = f1.m_shared.m_foodRegen + f2.m_shared.m_foodRegen + f3.m_shared.m_foodRegen;
|
||||
|
||||
float diff = Mathf.Abs(hpSum - targetHealth);
|
||||
|
||||
if (diff < bestDiff || (Mathf.Abs(diff - bestDiff) < 0.1f && regenSum > bestRegen))
|
||||
{
|
||||
bestDiff = diff;
|
||||
bestRegen = regenSum;
|
||||
bestCombo = new List<ItemDrop.ItemData> { f1.Clone(), f2.Clone(), f3.Clone() };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bestCombo != null)
|
||||
{
|
||||
float actualSum = 0f;
|
||||
foreach(var c in bestCombo) actualSum += c.m_shared.m_food;
|
||||
|
||||
float scale = actualSum > 0f ? (targetHealth / actualSum) : 1f;
|
||||
|
||||
foreach(var c in bestCombo)
|
||||
{
|
||||
c.m_shared = (ItemDrop.ItemData.SharedData)typeof(object).GetMethod("MemberwiseClone", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(c.m_shared, null);
|
||||
|
||||
// Modificatore per scalare perfettamente gli HP
|
||||
c.m_shared.m_food = c.m_shared.m_food * scale;
|
||||
|
||||
// Azzerare completamente l'Eitr e la Stamina
|
||||
c.m_shared.m_foodEitr = 0f;
|
||||
c.m_shared.m_foodStamina = 0f;
|
||||
|
||||
c.m_shared.m_foodBurnTime = 999999f;
|
||||
}
|
||||
}
|
||||
|
||||
cachedRealFoods[state] = bestCombo;
|
||||
return bestCombo;
|
||||
}
|
||||
|
||||
private void DumpTransformHierarchy(Transform t, string indent)
|
||||
{
|
||||
if (t == null) return;
|
||||
Jotunn.Logger.LogInfo(indent + t.name + " (Active: " + t.gameObject.activeSelf + ")");
|
||||
for(int i = 0; i < t.childCount; i++)
|
||||
{
|
||||
DumpTransformHierarchy(t.GetChild(i), indent + " ");
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.F8))
|
||||
{
|
||||
if (Hud.instance != null)
|
||||
{
|
||||
Jotunn.Logger.LogInfo("--- HUD HIERARCHY DUMP ---");
|
||||
DumpTransformHierarchy(Hud.instance.transform, "");
|
||||
Jotunn.Logger.LogInfo("--------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
if (Player.m_localPlayer == null) return;
|
||||
|
||||
if (!IsSkeleton() || Player.m_localPlayer.IsDead())
|
||||
{
|
||||
EnsureFireAuraVFX(false);
|
||||
if (Player.m_localPlayer.transform.localScale != Vector3.one)
|
||||
{
|
||||
Player.m_localPlayer.transform.localScale = Vector3.one;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Force hide hair and beard
|
||||
var profile = Game.instance?.GetPlayerProfile();
|
||||
if (profile != null)
|
||||
{
|
||||
var hair = HarmonyLib.Traverse.Create(profile).Field<string>("m_hairItem");
|
||||
var beard = HarmonyLib.Traverse.Create(profile).Field<string>("m_beardItem");
|
||||
|
||||
if (!string.IsNullOrEmpty(hair.Value) || !string.IsNullOrEmpty(beard.Value))
|
||||
{
|
||||
hair.Value = "";
|
||||
beard.Value = "";
|
||||
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_hairItem").SetValue("");
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_beardItem").SetValue("");
|
||||
|
||||
VisEquipment vis = Player.m_localPlayer.GetComponent<VisEquipment>();
|
||||
if (vis != null)
|
||||
{
|
||||
vis.SetHairItem("");
|
||||
vis.SetBeardItem("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
var rules = SkeletonProgression.GetRules(state);
|
||||
|
||||
// Continuously adjust equipment
|
||||
VisEquipment currentVis = Player.m_localPlayer.GetComponent<VisEquipment>();
|
||||
if (currentVis != null)
|
||||
{
|
||||
// Hide Helmets (Valheim uses singular GameObject for helmet)
|
||||
var helmetObj = HarmonyLib.Traverse.Create(currentVis).Field<GameObject>("m_helmetItemInstance").Value;
|
||||
if (helmetObj != null && helmetObj.transform.localScale != Vector3.zero)
|
||||
{
|
||||
helmetObj.transform.localScale = Vector3.zero;
|
||||
}
|
||||
|
||||
// Scale Body Armor (Chest, Legs, Shoulder) by 5%
|
||||
string[] armorFields = { "m_chestItemInstances", "m_legItemInstances", "m_shoulderItemInstances" };
|
||||
foreach (string field in armorFields)
|
||||
{
|
||||
var armorList = HarmonyLib.Traverse.Create(currentVis).Field<System.Collections.Generic.List<GameObject>>(field).Value;
|
||||
if (armorList != null)
|
||||
{
|
||||
foreach (GameObject armor in armorList)
|
||||
{
|
||||
if (armor != null && Mathf.Abs(armor.transform.localScale.x - 1.05f) > 0.01f)
|
||||
{
|
||||
armor.transform.localScale = new Vector3(1.05f, 1.05f, 1.05f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Hide Charred Twitcher Jaw
|
||||
if (currentVis != null && currentVis.m_bodyModel != null && currentVis.m_bodyModel.bones != null)
|
||||
{
|
||||
foreach (Transform bone in currentVis.m_bodyModel.bones)
|
||||
{
|
||||
if (bone != null && bone.name.ToLower().Contains("jaw"))
|
||||
{
|
||||
if (state >= 8)
|
||||
{
|
||||
if (bone.localScale != Vector3.zero) bone.localScale = Vector3.zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bone.localScale == Vector3.zero) bone.localScale = Vector3.one;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Apply Scale
|
||||
Vector3 targetScale = rules.ScaleMultiplier;
|
||||
if (Player.m_localPlayer.transform.localScale != targetScale)
|
||||
{
|
||||
Player.m_localPlayer.transform.localScale = targetScale;
|
||||
}
|
||||
|
||||
// Ensure ZDO is synced for visuals
|
||||
ZNetView nview = Player.m_localPlayer.GetComponent<ZNetView>();
|
||||
if (nview != null && nview.IsValid())
|
||||
{
|
||||
nview.GetZDO().Set("RacesOfValheim_SkeletonState", state);
|
||||
}
|
||||
|
||||
// Manage Fake Foods
|
||||
var foods = Player.m_localPlayer.GetFoods();
|
||||
bool needsFood = false;
|
||||
|
||||
if (foods.Count != 3)
|
||||
{
|
||||
needsFood = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach(var food in foods)
|
||||
{
|
||||
food.m_time = 0f; // Always reset time so they never degrade!
|
||||
}
|
||||
|
||||
float expectedHp = 0f;
|
||||
var expectedFoods = GetBestRealFoods(state);
|
||||
if (expectedFoods != null)
|
||||
{
|
||||
foreach(var f in expectedFoods) expectedHp += f.m_shared.m_food;
|
||||
}
|
||||
|
||||
float currentHp = 0f;
|
||||
foreach(var food in foods)
|
||||
{
|
||||
if (food.m_item != null && food.m_item.m_shared != null)
|
||||
currentHp += food.m_item.m_shared.m_food;
|
||||
}
|
||||
|
||||
if (Mathf.Abs(currentHp - expectedHp) > 1f)
|
||||
{
|
||||
needsFood = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (needsFood)
|
||||
{
|
||||
Player.m_localPlayer.ClearFood();
|
||||
var newDiet = GetBestRealFoods(state);
|
||||
if (newDiet != null)
|
||||
{
|
||||
foreach (var dietItem in newDiet)
|
||||
{
|
||||
Player.Food newFood = new Player.Food();
|
||||
newFood.m_name = dietItem.m_dropPrefab != null ? dietItem.m_dropPrefab.name : "";
|
||||
newFood.m_item = dietItem;
|
||||
newFood.m_health = dietItem.m_shared.m_food;
|
||||
newFood.m_stamina = dietItem.m_shared.m_foodStamina;
|
||||
newFood.m_eitr = dietItem.m_shared.m_foodEitr;
|
||||
newFood.m_time = 0f;
|
||||
foods.Add(newFood);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Enhanced Health Regeneration
|
||||
if (rules.EnhancedRegen)
|
||||
{
|
||||
if (skeletonStatsSE != null)
|
||||
{
|
||||
skeletonStatsSE.m_healthRegenMultiplier = 1.5f;
|
||||
}
|
||||
|
||||
// Speed up regen ticks by 20% (1.25x faster timer accumulation)
|
||||
float currentTimer = HarmonyLib.Traverse.Create(Player.m_localPlayer).Field<float>("m_foodRegenTimer").Value;
|
||||
HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_foodRegenTimer").SetValue(currentTimer + Time.deltaTime * 0.25f);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (skeletonStatsSE != null)
|
||||
{
|
||||
skeletonStatsSE.m_healthRegenMultiplier = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
if (rules.FireAura)
|
||||
{
|
||||
EnsureFireAuraVFX(true);
|
||||
if (Time.time - lastAuraTime >= 1f)
|
||||
{
|
||||
ApplyFireAura();
|
||||
lastAuraTime = Time.time;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EnsureFireAuraVFX(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureFireAuraVFX(bool enable)
|
||||
{
|
||||
if (enable && Player.m_localPlayer != null)
|
||||
{
|
||||
if (fireAuraVFX == null)
|
||||
{
|
||||
// Look for a smoke or fog effect to tint as fire fog
|
||||
GameObject sourceVFX = PrefabManager.Cache.GetPrefab<GameObject>("vfx_smoke") ??
|
||||
PrefabManager.Cache.GetPrefab<GameObject>("vfx_surtling_death");
|
||||
|
||||
fireAuraVFX = new GameObject("SkeletonFireAuraVFX");
|
||||
fireAuraVFX.transform.SetParent(Player.m_localPlayer.transform, false);
|
||||
fireAuraVFX.transform.localPosition = new Vector3(0, 1f, 0);
|
||||
|
||||
if (sourceVFX != null)
|
||||
{
|
||||
ParticleSystem[] pss = sourceVFX.GetComponentsInChildren<ParticleSystem>();
|
||||
if (pss.Length > 0)
|
||||
{
|
||||
ParticleSystem ps = fireAuraVFX.AddComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.loop = true;
|
||||
main.duration = 1f;
|
||||
main.startLifetime = 1.5f;
|
||||
main.startSize = new ParticleSystem.MinMaxCurve(1.5f, 3f);
|
||||
main.startSpeed = 0f;
|
||||
main.simulationSpace = ParticleSystemSimulationSpace.World;
|
||||
|
||||
var renderer = fireAuraVFX.GetComponent<ParticleSystemRenderer>();
|
||||
renderer.material = pss[0].GetComponent<ParticleSystemRenderer>().material;
|
||||
|
||||
var shape = ps.shape;
|
||||
shape.shapeType = ParticleSystemShapeType.Sphere;
|
||||
shape.radius = 4.5f; // Similar to the damage radius
|
||||
|
||||
var emission = ps.emission;
|
||||
emission.rateOverTime = 40f;
|
||||
|
||||
// Add a fire-like color gradient
|
||||
var colorOverLifetime = ps.colorOverLifetime;
|
||||
colorOverLifetime.enabled = true;
|
||||
Gradient grad = new Gradient();
|
||||
grad.SetKeys(
|
||||
new GradientColorKey[] {
|
||||
new GradientColorKey(new Color(1f, 0.8f, 0.2f), 0.0f), // Yellow
|
||||
new GradientColorKey(new Color(1f, 0.3f, 0.0f), 0.5f), // Orange/Red
|
||||
new GradientColorKey(new Color(0.2f, 0.0f, 0.0f), 1.0f) // Dark red/smoke
|
||||
},
|
||||
new GradientAlphaKey[] {
|
||||
new GradientAlphaKey(0.0f, 0.0f),
|
||||
new GradientAlphaKey(0.6f, 0.2f),
|
||||
new GradientAlphaKey(0.6f, 0.8f),
|
||||
new GradientAlphaKey(0.0f, 1.0f)
|
||||
}
|
||||
);
|
||||
colorOverLifetime.color = grad;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!fireAuraVFX.activeSelf)
|
||||
{
|
||||
fireAuraVFX.SetActive(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fireAuraVFX != null && fireAuraVFX.activeSelf)
|
||||
{
|
||||
fireAuraVFX.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyFireAura()
|
||||
{
|
||||
if (Player.m_localPlayer == null) return;
|
||||
|
||||
Vector3 center = Player.m_localPlayer.transform.position;
|
||||
float radius = 5f;
|
||||
|
||||
HitData hitData = new HitData();
|
||||
hitData.m_damage.m_fire = 30f; // 30 fire damage per second
|
||||
hitData.SetAttacker(Player.m_localPlayer);
|
||||
hitData.m_dir = Vector3.zero;
|
||||
|
||||
int hits = 0;
|
||||
foreach (Collider collider in Physics.OverlapSphere(center, radius))
|
||||
{
|
||||
Character character = collider.GetComponentInParent<Character>();
|
||||
if (character != null && character != Player.m_localPlayer && BaseAI.IsEnemy(Player.m_localPlayer, character))
|
||||
{
|
||||
character.Damage(hitData);
|
||||
hits++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
46
JotunnModStub/Skeleton/SkeletonStatusEffects.cs
Normal file
46
JotunnModStub/Skeleton/SkeletonStatusEffects.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
public class SE_SkeletonStats : SE_Stats
|
||||
{
|
||||
public override void Setup(Character character)
|
||||
{
|
||||
base.Setup(character);
|
||||
|
||||
// Apply Damage Modifiers
|
||||
int state = BossProgressionManager.GetCurrentProgressionState();
|
||||
SkeletonProgression.SkeletonRules rules = SkeletonProgression.GetRules(state);
|
||||
|
||||
m_mods = new List<HitData.DamageModPair>();
|
||||
m_mods.Add(new HitData.DamageModPair { m_type = HitData.DamageType.Pierce, m_modifier = HitData.DamageModifier.Resistant });
|
||||
m_mods.Add(new HitData.DamageModPair { m_type = HitData.DamageType.Slash, m_modifier = HitData.DamageModifier.Resistant });
|
||||
m_mods.Add(new HitData.DamageModPair { m_type = HitData.DamageType.Blunt, m_modifier = HitData.DamageModifier.Weak });
|
||||
|
||||
if (rules.PoisonImmunity)
|
||||
{
|
||||
m_mods.Add(new HitData.DamageModPair { m_type = HitData.DamageType.Poison, m_modifier = HitData.DamageModifier.Immune });
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateStatusEffect(float dt)
|
||||
{
|
||||
base.UpdateStatusEffect(dt);
|
||||
// Health is handled in SkeletonPatches.Player_GetMaxHealth_Patch
|
||||
}
|
||||
}
|
||||
|
||||
public class SE_SkeletonResurrectCooldown : StatusEffect
|
||||
{
|
||||
public override void Setup(Character character)
|
||||
{
|
||||
base.Setup(character);
|
||||
m_name = "Resurrection Cooldown";
|
||||
m_tooltip = "Your skeletal body is too weak to resurrect again right now.";
|
||||
m_icon = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>("TrophySkeletonPoison")?.GetComponent<ItemDrop>()?.m_itemData.GetIcon()
|
||||
?? Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>("TrophySkeleton")?.GetComponent<ItemDrop>()?.m_itemData.GetIcon();
|
||||
m_ttl = 300f; // 5 minutes
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue