Two places in the mod used an item called "HumanMeat" and nothing registered it: the drop in Draugh_DeathAura_Patch and the "fatal to the living" block in DraughFoodPatches. Both check for null, so the perk has been a no-op since it was written - a README line with no item behind it. The two consumers are unchanged; what was missing was the producer. Built from two vanilla items, one for the look and one for the numbers. RawMeat gives the model and icon, because that is what a piece of somebody looks like and because raw flesh is the Draugh's whole food identity. BloodPudding gives the nourishment, copied field by field at start-up rather than written down here, so the item stays balanced against the game's own progression and follows any change made to it. Blood Pudding's stamina goes onto health and stamina is left at zero. A Draugh does not use stamina, so nourishment spent there is thrown away: the food slot would read full while giving the race half of what it cost. RawMeat is a Material in vanilla - raw meat is not edible - so m_itemType is forced to Consumable. That is the one assumption worth knowing about, and the registration logs what it produced so a silent failure cannot hide. The meat is tinted on copies of the materials, never the shared ones, or every piece of raw meat in the world would darken with it. The README said humanoids drop it. The patch is on Player.OnDeath and always was, so the line now says what the code does: a player who dies inside the death aura, the Draugh included. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
186 lines
7.3 KiB
C#
186 lines
7.3 KiB
C#
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
public class DraughRace : MonoBehaviour
|
|
{
|
|
public static DraughRace Instance;
|
|
|
|
public static bool isUndying = false;
|
|
public static float lastUndyingWillTime = -1000f;
|
|
|
|
public static float lastSeekerSpawnTime = -1000f;
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
public void CreateModAssets()
|
|
{
|
|
// The body pile and its thralls. Registered here because the faction merchant catalogue
|
|
// resolves its entries by prefab name, so the two cursed bones have to exist before a
|
|
// Draugr is ever set up as a bench.
|
|
DraughSpawner.Register();
|
|
|
|
// The Bonemass-tier drop. Registered here for the same reason as the pile: two places in
|
|
// the mod already look it up by name, and until now nothing created it.
|
|
DraughHumanMeat.Register();
|
|
|
|
// Generate EdibleUncooked prefabs for Draugh raw food logic
|
|
foreach (var mapping in DraughFoodPatches.rawToCookedMapping)
|
|
{
|
|
string rawPrefabName = mapping.Key;
|
|
string cookedPrefabName = mapping.Value;
|
|
|
|
GameObject rawPrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(rawPrefabName);
|
|
GameObject cookedPrefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(cookedPrefabName);
|
|
|
|
if (rawPrefab != null && cookedPrefab != null)
|
|
{
|
|
ItemDrop rawDrop = rawPrefab.GetComponent<ItemDrop>();
|
|
ItemDrop cookedDrop = cookedPrefab.GetComponent<ItemDrop>();
|
|
|
|
if (rawDrop != null && cookedDrop != null)
|
|
{
|
|
string customName = "EdibleUncooked_" + rawPrefabName;
|
|
Jotunn.Entities.CustomItem customItem = new Jotunn.Entities.CustomItem(customName, cookedPrefabName);
|
|
|
|
ItemDrop customDrop = customItem.ItemDrop;
|
|
customDrop.m_itemData.m_shared.m_name = rawDrop.m_itemData.m_shared.m_name;
|
|
customDrop.m_itemData.m_shared.m_description = rawDrop.m_itemData.m_shared.m_description;
|
|
customDrop.m_itemData.m_shared.m_icons = rawDrop.m_itemData.m_shared.m_icons;
|
|
customDrop.m_itemData.m_shared.m_foodBurnTime *= 1.5f;
|
|
|
|
Jotunn.Managers.ItemManager.Instance.AddItem(customItem);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static bool IsDraugh()
|
|
{
|
|
return Player.m_localPlayer != null &&
|
|
Player.m_localPlayer.m_customData.ContainsKey("Race") &&
|
|
Player.m_localPlayer.m_customData["Race"] == "Draugh";
|
|
}
|
|
|
|
private GameObject draughVFX = null;
|
|
private float foodCheckTimer = 0f;
|
|
private int lastProgressionState = -1;
|
|
|
|
private void Update()
|
|
{
|
|
if (Player.m_localPlayer == null) return;
|
|
|
|
if (IsDraugh() && !Player.m_localPlayer.IsDead())
|
|
{
|
|
EnsureVFX(true);
|
|
|
|
foodCheckTimer += Time.deltaTime;
|
|
if (foodCheckTimer >= 2f)
|
|
{
|
|
foodCheckTimer = 0f;
|
|
int currentState = BossProgressionManager.GetCurrentProgressionState();
|
|
if (currentState != lastProgressionState)
|
|
{
|
|
lastProgressionState = currentState;
|
|
UpdateFoodEitr(currentState >= 6); // 6 = Yagluth Defeated
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
EnsureVFX(false);
|
|
}
|
|
}
|
|
|
|
private void UpdateFoodEitr(bool enableEitr)
|
|
{
|
|
if (ObjectDB.instance == null) return;
|
|
|
|
foreach (var mapping in DraughFoodPatches.rawToCookedMapping)
|
|
{
|
|
string customPrefabName = "EdibleUncooked_" + mapping.Key;
|
|
GameObject customPrefab = ObjectDB.instance.GetItemPrefab(customPrefabName);
|
|
if (customPrefab != null)
|
|
{
|
|
ItemDrop drop = customPrefab.GetComponent<ItemDrop>();
|
|
if (drop != null && drop.m_itemData != null && drop.m_itemData.m_shared != null)
|
|
{
|
|
if (enableEitr)
|
|
{
|
|
drop.m_itemData.m_shared.m_foodEitr = drop.m_itemData.m_shared.m_food / 2f;
|
|
}
|
|
else
|
|
{
|
|
drop.m_itemData.m_shared.m_foodEitr = 0f;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The local player's half of the aura. The build itself moved to DraughVisuals so that
|
|
/// RacesVisualController can grow the same one on every remote Draugh - this script only
|
|
/// ever sees the player at the keyboard, which is why nobody else could see the rot.
|
|
/// </summary>
|
|
private void EnsureVFX(bool enable)
|
|
{
|
|
DraughVisuals.EnsureAura(Player.m_localPlayer, enable, ref draughVFX);
|
|
}
|
|
|
|
public System.Collections.IEnumerator UndyingWillRoutine(Player p)
|
|
{
|
|
p.Message(MessageHud.MessageType.Center, "Zombie Ritual Activated! Your borrowed time is fading...");
|
|
|
|
// Trigger a re-evaluation of visuals to apply the ghost effect
|
|
if (p.GetComponent<VisEquipment>() != null)
|
|
{
|
|
HarmonyLib.Traverse.Create(p.GetComponent<VisEquipment>()).Method("UpdateVisuals").GetValue();
|
|
HarmonyLib.Traverse.Create(p.GetComponent<VisEquipment>()).Method("UpdateColors").GetValue();
|
|
}
|
|
|
|
while (isUndying)
|
|
{
|
|
float currentEitr = p.GetEitr();
|
|
if (currentEitr <= 0f)
|
|
{
|
|
isUndying = false;
|
|
|
|
// Force death properly through the damage system
|
|
HitData killHit = new HitData();
|
|
killHit.m_damage.m_damage = 99999f;
|
|
killHit.m_point = p.transform.position;
|
|
p.Damage(killHit);
|
|
break;
|
|
}
|
|
|
|
p.UseEitr(DraughConfig.UndyingWillEitrDrainPerTick.Value);
|
|
|
|
yield return new WaitForSeconds(DraughConfig.UndyingWillTickInterval.Value);
|
|
}
|
|
|
|
// Restore visuals
|
|
if (p != null && p.GetComponent<VisEquipment>() != null)
|
|
{
|
|
HarmonyLib.Traverse.Create(p.GetComponent<VisEquipment>()).Method("UpdateVisuals").GetValue();
|
|
HarmonyLib.Traverse.Create(p.GetComponent<VisEquipment>()).Method("UpdateColors").GetValue();
|
|
}
|
|
}
|
|
|
|
public System.Collections.IEnumerator KillBroodAfterTime(Character brood, float time)
|
|
{
|
|
yield return new WaitForSeconds(time);
|
|
if (brood != null && !brood.IsDead())
|
|
{
|
|
// Force death naturally
|
|
HitData killHit = new HitData();
|
|
killHit.m_damage.m_damage = 9999f;
|
|
killHit.m_point = brood.transform.position;
|
|
brood.Damage(killHit);
|
|
}
|
|
}
|
|
}
|
|
}
|