Sverm Ravager Strain (replacing the Stinger Morph), Trenta Elder Root, the Trol food and Black Forest truce work, and the faction FindEnemy patch. Conflicts resolved: - FactionHostilityPatch.cs: both sides added a class at the same spot and they cover different holes, so both are kept - FactionStaticTargetPatch (main, stops same-faction mobs smashing structures) and FactionHuntPlayerPatch (war-vulture, closes the HuntPlayer fall-through). - RaceCompendium.cs: both branches independently fixed the same off-by-one in the Trol's progression gates. Took main's wording, which matches the code - Axes are in the melee bonus (TrolDamagePatches sends them to m_slash), the 4th food slot has no gate at all, and Yagluth is +5 not +10 (TrolConfig.YagluthMeleeBonus). Kept war-vulture's two new lines, the Kindling fire weakness and the Black Forest truce. - Package/manifest.json: 1.4.8, which is what the root manifest and PluginVersion already said. RacesOfValheim.cs referenced SvermConfig.StingerSE/StingerCdSE, which war-vulture renamed to Ravager. Git merged those lines without a conflict and the result did not compile; renamed. Also in this commit: - Factions on/off switches (FactionsConfig): "Faction truce" and "Faction merchants", both default on, both read live so they take effect without a restart. The truce gates its three postfixes; the merchants gate the Character.Awake setup plus every behavioural patch, so turning them off drops the prompt and the trade window on mobs already awake. - SerpentMeat sells for 200 instead of 1 at the Fuling bench, moved to keep the list's ascending price order (the sell panel renders it as declared). - DraughFoodPatches mapped "SerpentMeatRaw", which is not a prefab; the internal id is SerpentMeat, so serpent meat never cooked for a Draugh. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
201 lines
9 KiB
C#
201 lines
9 KiB
C#
using HarmonyLib;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Jotunn.Entities;
|
|
using Jotunn.Managers;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
[HarmonyPatch]
|
|
public static class DraughFoodPatches
|
|
{
|
|
private static List<object> hiddenFoods = new List<object>();
|
|
|
|
// Mapping from raw prefab/item name to the cooked prefab name
|
|
public static readonly Dictionary<string, string> rawToCookedMapping = new Dictionary<string, string>
|
|
{
|
|
{ "RawMeat", "CookedMeat" },
|
|
{ "NeckTail", "NeckTailGrilled" },
|
|
{ "FishRaw", "FishCooked" },
|
|
{ "LoxMeat", "CookedLoxMeat" },
|
|
{ "SerpentMeat", "SerpentMeatCooked" },
|
|
{ "WolfMeat", "CookedWolfMeat" },
|
|
{ "DeerMeat", "CookedDeerMeat" },
|
|
{ "HareMeat", "CookedHareMeat" },
|
|
{ "ChickenMeat", "CookedChickenMeat" },
|
|
{ "BugMeat", "CookedBugMeat" },
|
|
{ "VoltureMeat", "RoastedVoltureMeat" },
|
|
{ "GreydwarfEye", "DeerStew" },
|
|
{ "Entrails", "Sausages" },
|
|
{ "Bloodbag", "BloodPudding" }
|
|
};
|
|
|
|
[HarmonyPatch(typeof(Humanoid), "UseItem")]
|
|
[HarmonyPrefix]
|
|
public static bool UseItem_Prefix(Humanoid __instance, Inventory inventory, ItemDrop.ItemData item, bool fromInventoryGui)
|
|
{
|
|
Player player = __instance as Player;
|
|
if (player == null || player != Player.m_localPlayer || item == null || item.m_shared == null) return true;
|
|
|
|
// Prevent non-Draughs from eating Human Meat
|
|
if (item.m_dropPrefab != null && item.m_dropPrefab.name == "HumanMeat")
|
|
{
|
|
if (!DraughRace.IsDraugh())
|
|
{
|
|
player.Message(MessageHud.MessageType.Center, "This rotting flesh is fatal to the living.");
|
|
return false; // Block consumption
|
|
}
|
|
// If it IS a Draugh, let them consume it via native mechanics
|
|
return true;
|
|
}
|
|
|
|
// Normal Draugh Food restrictions
|
|
if (!DraughRace.IsDraugh()) return true;
|
|
|
|
// Intercept right click on raw items.
|
|
// In UseItem, if it's a Consumable, Valheim will process it. If it's our EdibleUncooked_, it's a Consumable!
|
|
if (item.m_shared.m_name.StartsWith("$item_edibleuncooked_") || item.m_dropPrefab?.name.StartsWith("EdibleUncooked_") == true)
|
|
{
|
|
return true; // Let native EatFood process our custom item
|
|
}
|
|
|
|
string prefabName = item.m_dropPrefab != null ? item.m_dropPrefab.name : "";
|
|
string cleanName = prefabName;
|
|
if (string.IsNullOrEmpty(cleanName)) cleanName = item.m_shared.m_name.Replace("$item_", "");
|
|
|
|
// Is it one of the raw items in our mapping?
|
|
if (rawToCookedMapping.ContainsKey(cleanName))
|
|
{
|
|
// We want to seamlessly swap it with EdibleUncooked_<cleanName>
|
|
string customPrefabName = "EdibleUncooked_" + cleanName;
|
|
GameObject customPrefab = ObjectDB.instance.GetItemPrefab(customPrefabName);
|
|
if (customPrefab != null)
|
|
{
|
|
ItemDrop customItemDrop = customPrefab.GetComponent<ItemDrop>();
|
|
if (customItemDrop != null)
|
|
{
|
|
// Check if we can eat it (duplicate check bypass logic handled inside EatFood)
|
|
bool ate = player.EatFood(customItemDrop.m_itemData);
|
|
if (ate)
|
|
{
|
|
inventory.RemoveItem(item, 1);
|
|
|
|
var consumeEffects = Traverse.Create(player).Field("m_consumeItemEffects").GetValue<EffectList>();
|
|
if (consumeEffects != null) consumeEffects.Create(player.transform.position, Quaternion.identity, player.transform, 1f, -1);
|
|
|
|
var zanim = Traverse.Create(player).Field("m_zanim").GetValue<ZSyncAnimation>();
|
|
if (zanim != null) zanim.SetTrigger("eat");
|
|
}
|
|
return false; // Skip native UseItem
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Jotunn.Logger.LogWarning($"[DraughFood] Could not find custom prefab: {customPrefabName}");
|
|
}
|
|
}
|
|
|
|
// If it's a normal consumable (like standard cooked food or berries), we should block it!
|
|
if (item.m_shared.m_itemType == ItemDrop.ItemData.ItemType.Consumable)
|
|
{
|
|
bool isFood = item.m_shared.m_food > 0 || item.m_shared.m_foodStamina > 0 || item.m_shared.m_foodEitr > 0;
|
|
if (isFood)
|
|
{
|
|
player.Message(MessageHud.MessageType.Center, "Draugr consume only raw flesh, eyes, entrails or blood.");
|
|
return false; // Block it
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Player), "EatFood")]
|
|
[HarmonyPrefix]
|
|
public static bool EatFood_Prefix(Player __instance, ItemDrop.ItemData item, ref bool __result)
|
|
{
|
|
hiddenFoods.Clear();
|
|
|
|
if (__instance != Player.m_localPlayer || !DraughRace.IsDraugh()) return true;
|
|
if (item == null || item.m_shared == null) return true;
|
|
|
|
// Handle the bypass logic (duplicate food) ONLY for our custom uncooked foods
|
|
string prefabName = item.m_dropPrefab != null ? item.m_dropPrefab.name : "";
|
|
if (prefabName.StartsWith("EdibleUncooked_"))
|
|
{
|
|
var m_foods = Traverse.Create(__instance).Field("m_foods").GetValue<System.Collections.IList>();
|
|
if (m_foods != null)
|
|
{
|
|
if (m_foods.Count >= 3)
|
|
{
|
|
// Check if we can refresh an existing identical food (if time is low)
|
|
bool refreshed = false;
|
|
foreach (object foodObj in m_foods)
|
|
{
|
|
Player.Food f = foodObj as Player.Food;
|
|
if (f != null && f.m_item.m_shared.m_name == item.m_shared.m_name && f.CanEatAgain())
|
|
{
|
|
f.m_time = 0f;
|
|
f.m_item = item.Clone();
|
|
|
|
var consumeEffects = Traverse.Create(__instance).Field("m_consumeItemEffects").GetValue<EffectList>();
|
|
if (consumeEffects != null) consumeEffects.Create(__instance.transform.position, Quaternion.identity, __instance.transform, 1f, -1);
|
|
|
|
var zanim = Traverse.Create(__instance).Field("m_zanim").GetValue<ZSyncAnimation>();
|
|
if (zanim != null) zanim.SetTrigger("eat");
|
|
|
|
if (item.m_shared.m_food > 0f) __instance.Heal(item.m_shared.m_food, true);
|
|
|
|
refreshed = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (refreshed)
|
|
{
|
|
__result = true;
|
|
return false; // Skip native EatFood
|
|
}
|
|
|
|
// Inventory full
|
|
__result = false;
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
// Temporarily hide duplicates to force Valheim to add a new slot
|
|
for (int i = m_foods.Count - 1; i >= 0; i--)
|
|
{
|
|
var foodObj = m_foods[i];
|
|
var foodItem = Traverse.Create(foodObj).Field("m_item").GetValue<ItemDrop.ItemData>();
|
|
if (foodItem != null && foodItem.m_shared.m_name == item.m_shared.m_name)
|
|
{
|
|
hiddenFoods.Add(foodObj);
|
|
m_foods.RemoveAt(i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Player), "EatFood")]
|
|
[HarmonyPostfix]
|
|
public static void EatFood_Postfix(Player __instance, ItemDrop.ItemData item, ref bool __result)
|
|
{
|
|
if (hiddenFoods.Count > 0)
|
|
{
|
|
var m_foods = Traverse.Create(__instance).Field("m_foods").GetValue<System.Collections.IList>();
|
|
if (m_foods != null)
|
|
{
|
|
foreach (var h in hiddenFoods)
|
|
{
|
|
m_foods.Add(h);
|
|
}
|
|
}
|
|
hiddenFoods.Clear();
|
|
}
|
|
}
|
|
}
|
|
}
|