The jaw hung off the side of the skull because a creature rig carries bones a human rig has no answer for. Unmatched bones fell back to bones[0] - the root - so the mandible was skinned to the hips and followed them. The remap now walks the creature'''s own hierarchy upward until something matches, which lands a jaw on the head. It no longer opens, which no player will notice, and it is attached, which every player did. Teeth and any other facial part the model carries are fixed by the same walk. The head flame never appeared. It was built by hand out of the smoke material with a hand-rolled fire gradient, which at best would have read as a wisp rather than a burning skull, and at worst never resolved a source at all and returned in silence. It now clones real fire particles off a vanilla prefab - the torch first, ground torches and the fire pit behind it - and says in the log which one it took, or warns if none of them resolved. The torch light comes with it, at half range and reduced intensity, since a light tuned to fill a corridor from waist height blows out a face at point-blank range. Fader now stands 15% taller. That scale goes on the player root, which is how this race has always sized itself, so the collider, the camera pivot and every equipment attachment scale with the mesh rather than leaving the model to drift away from them.
614 lines
28 KiB
C#
614 lines
28 KiB
C#
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;
|
|
|
|
// Model names already reported as missing. The body swap runs from a visual refresh, so
|
|
// without this a mistyped prefab id would log every time equipment changes.
|
|
private static readonly System.Collections.Generic.HashSet<string> warnedMissingModels =
|
|
new System.Collections.Generic.HashSet<string>();
|
|
|
|
private static void WarnMissingModelOnce(string prefabName)
|
|
{
|
|
if (!warnedMissingModels.Add(prefabName)) return;
|
|
|
|
Jotunn.Logger.LogWarning(
|
|
$"[Skeleton] Body model prefab '{prefabName}' not found - the race has no mesh at this tier. " +
|
|
"Check the id in SkeletonProgression.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Makes the Skeleton's max health exactly what its progression promises.
|
|
///
|
|
/// A Skeleton cannot eat, so SkeletonRace fakes three permanent foods whose values are
|
|
/// scaled to add up to the tier's bonus. That is a good way to keep food-based health
|
|
/// regeneration working - Valheim regenerates from the food list, so a Skeleton with no
|
|
/// food would never heal - but a bad way to land an exact number: the value the game reads
|
|
/// is Food.m_health, which UpdateFood recomputes every second as
|
|
/// Pow(remaining/burnTime, 0.3) * m_food, and anything that leaves those three foods
|
|
/// partly burnt, partly rebuilt or one short quietly costs health. A Bonemass-tier
|
|
/// Skeleton reported 95 max health where the table promises 25 + 140.
|
|
///
|
|
/// So the foods stay, for regeneration, and the total they feed into is overwritten here.
|
|
/// GetTotalFoodValue has exactly one caller, Player.UpdateFood, which passes the result
|
|
/// straight to SetMaxHealth - so this is the single point where the number is decided, and
|
|
/// it now comes from the progression table rather than from three scaled sausages.
|
|
/// </summary>
|
|
[HarmonyPatch(typeof(Player), "GetTotalFoodValue")]
|
|
public static class Player_GetTotalFoodValue_SkeletonHealth_Patch
|
|
{
|
|
public static void Postfix(Player __instance, ref float hp)
|
|
{
|
|
if (__instance != Player.m_localPlayer || !SkeletonRace.IsSkeleton()) return;
|
|
|
|
int state = BossProgressionManager.GetCurrentProgressionState();
|
|
hp = __instance.m_baseHP + SkeletonProgression.GetMaxHealthBonus(state);
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Player), "UseStamina")]
|
|
public static class Player_UseStamina_Patch
|
|
{
|
|
public static bool Prefix(Player __instance)
|
|
{
|
|
if ((SkeletonRace.IsSkeleton() || AswidRace.IsAswid() || DraughRace.IsDraugh()) && __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(MessageHud), "ShowMessage")]
|
|
public static class MessageHud_ShowMessage_Patch
|
|
{
|
|
private static System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<float>> messageTimestamps = new System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<float>>();
|
|
private static System.Collections.Generic.Dictionary<string, float> messageBans = new System.Collections.Generic.Dictionary<string, float>();
|
|
|
|
public static bool Prefix(MessageHud __instance, MessageHud.MessageType type, string text)
|
|
{
|
|
if (Player.m_localPlayer != null && SkeletonRace.IsSkeleton())
|
|
{
|
|
if (string.IsNullOrEmpty(text)) return true;
|
|
|
|
// Exception for resting messages to never be filtered
|
|
string lowerText = text.ToLower();
|
|
if (text == "$se_resting_name" || text == "$se_resting" || lowerText.Contains("resting") || lowerText.Contains("riposo"))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
float currentTime = Time.time;
|
|
|
|
// Check if message is currently banned (4 hours = 14400 seconds)
|
|
if (messageBans.TryGetValue(text, out float banTime))
|
|
{
|
|
if (currentTime - banTime < 14400f)
|
|
{
|
|
return false; // Still banned
|
|
}
|
|
else
|
|
{
|
|
messageBans.Remove(text); // Ban expired
|
|
if (messageTimestamps.ContainsKey(text))
|
|
{
|
|
messageTimestamps[text].Clear(); // Reset spam count
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!messageTimestamps.ContainsKey(text))
|
|
{
|
|
messageTimestamps[text] = new System.Collections.Generic.List<float>();
|
|
}
|
|
|
|
// Remove timestamps older than 5 seconds
|
|
messageTimestamps[text].RemoveAll(t => currentTime - t > 5f);
|
|
|
|
if (messageTimestamps[text].Count >= 2)
|
|
{
|
|
// Trigger a 4-hour ban
|
|
messageBans[text] = currentTime;
|
|
return false;
|
|
}
|
|
|
|
messageTimestamps[text].Add(currentTime);
|
|
}
|
|
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)
|
|
{
|
|
// The human body was switched off two lines up, so an unresolved
|
|
// model leaves an invisible player rather than an obvious error.
|
|
// Say so once per tier instead of failing silently.
|
|
WarnMissingModelOnce(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++)
|
|
{
|
|
newBones[i] = ResolveBone(playerBones, newSmr.bones[i]);
|
|
}
|
|
newSmr.bones = newBones;
|
|
|
|
if (newSmr.rootBone != null)
|
|
{
|
|
newSmr.rootBone = ResolveBone(playerBones, newSmr.rootBone);
|
|
}
|
|
}
|
|
|
|
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) { }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Finds the player bone a creature bone should be skinned to.
|
|
///
|
|
/// A creature rig carries bones a human rig has no answer for - a jaw above all, but
|
|
/// also teeth and tails. Those used to fall back to bones[0], the root, which skinned
|
|
/// the mandible to the hips and left it hanging off the side of the skull. Follow the
|
|
/// creature's own hierarchy upward instead until something matches, so a jaw lands on
|
|
/// the head and rides it. It cannot open any more, which no player will notice, and it
|
|
/// is attached, which every player did.
|
|
/// </summary>
|
|
private static Transform ResolveBone(Transform[] playerBones, Transform sourceBone)
|
|
{
|
|
if (sourceBone == null) return playerBones[0];
|
|
|
|
Transform direct = FindBoneByName(playerBones, sourceBone.name);
|
|
if (direct != null) return direct;
|
|
|
|
for (Transform parent = sourceBone.parent; parent != null; parent = parent.parent)
|
|
{
|
|
Transform match = FindBoneByName(playerBones, parent.name);
|
|
if (match != null) return match;
|
|
}
|
|
|
|
return playerBones[0];
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|