warvulture

This commit is contained in:
Ferdinando 2026-08-14 15:24:33 +02:00
commit 8580d65a56
4 changed files with 90 additions and 7 deletions

View file

@ -89,6 +89,36 @@ namespace RacesOfValheim
"cloned from vanilla's mount stamina bar."));
}
/// <summary>
/// The race of a player, read m_customData first and the ZDO second.
///
/// That order is the one the summon has always used, and it is kept rather than swapped for
/// the ZDO-first order the visuals use, for a reason: this only ever asks about the LOCAL
/// player, whose m_customData is authoritative and is written before the ZDO on a race
/// change. The ZDO is the fallback for the one frame after a load where m_customData has not
/// been filled in yet - without it the crafting list would flicker the recipe away.
/// </summary>
public static string RaceOf(Player player)
{
if (player == null) return null;
if (player.m_customData != null &&
player.m_customData.TryGetValue("Race", out string custom) &&
!string.IsNullOrEmpty(custom))
{
return custom;
}
ZNetView nview = player.GetComponent<ZNetView>();
if (nview != null && nview.IsValid())
{
string race = nview.GetZDO().GetString("RacesOfValheim_Race", "");
if (!string.IsNullOrEmpty(race)) return race;
}
return null;
}
/// <summary>
/// Whether a race id may call the bird. An empty list means everyone, which is the honest
/// reading of "no restriction" and is also what makes this testable on any character.

View file

@ -1,4 +1,6 @@
using System.Collections.Generic;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using UnityEngine;
@ -36,6 +38,12 @@ namespace RacesOfValheim
private const string TrophyPrefab = "TrophyVolture";
private const string Label = "WarVulture";
/// <summary>The three materials. Ids, not display names: the ingot is BlackMetal (the SCRAP
/// is the ore), and the raw lox meat is LoxMeat, with CookedLoxMeat being the other one.</summary>
private const string GreydwarfEye = "GreydwarfEye";
private const string BlackMetalIngot = "BlackMetal";
private const string RawLoxMeat = "LoxMeat";
public static void Register()
{
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(PrefabName, SourcePrefab);
@ -73,9 +81,24 @@ namespace RacesOfValheim
// is not. Getting that wrong once put a live Ashlands predator in the player's world.
WarVultureVisual.BuildTemplate();
// No recipe, on purpose and for now: the item is spawned from the console
// ("spawn WarVulture") while the flight is being proven. A recipe costs nothing to add
// later and would only be materials invented before anyone knows what this is worth.
// The forge, and not the workbench, for the same reason Trol's Hammer sits on a
// workbench: the station is picked by the material that is hardest to have. Eyes and
// meat are picked up off the ground; a black metal ingot means a blast furnace already
// exists, and the forge is where that metal is worked.
ItemManager.Instance.AddRecipe(new CustomRecipe(new RecipeConfig
{
Item = PrefabName,
Amount = 1,
CraftingStation = CraftingStations.Forge,
MinStationLevel = 1,
Requirements = new[]
{
new RequirementConfig(GreydwarfEye, 10, 0, true),
new RequirementConfig(BlackMetalIngot, 2, 0, true),
new RequirementConfig(RawLoxMeat, 2, 0, true),
},
}));
Jotunn.Logger.LogInfo($"[{Label}] {DisplayName} registered: no eitr, no health, no stamina, no skeleton.");
}
@ -251,6 +274,35 @@ namespace RacesOfValheim
}
}
/// <summary>
/// Who gets to see the recipe: the same list the bird itself answers to
/// (WarVultureConfig.AllowedRaces, "Furling,Dvergar" out of the box), read through the same
/// helper, so the crafting menu and the summon can never disagree. A race that could craft the
/// item but not call the bird would just be selling someone ten greydwarf eyes' worth of stick.
///
/// Player.GetAvailableRecipes is the single funnel the crafting list is built from, and it is
/// public and takes the list by ref - so a Postfix that removes one entry is the whole gate.
/// The recipe is still REGISTERED for everybody, which is deliberate: it stays in ObjectDB, so
/// a character who changes race sees it appear or vanish with no world edit and no re-register.
///
/// Filtering here rather than at the craft click also means the refusal never has to be
/// explained - an item that was never in the list cannot be clicked.
/// </summary>
[HarmonyPatch(typeof(Player), nameof(Player.GetAvailableRecipes))]
public static class WarVultureRecipeRacePatch
{
private static void Postfix(Player __instance, ref List<Recipe> available)
{
if (__instance == null || available == null) return;
if (WarVultureConfig.RaceAllowed(WarVultureConfig.RaceOf(__instance))) return;
available.RemoveAll(recipe =>
recipe != null &&
recipe.m_item != null &&
Utils.GetPrefabName(recipe.m_item.gameObject) == WarVultureItem.PrefabName);
}
}
/// <summary>
/// The click. Attack.OnAttackTrigger is used rather than Attack.Start because it takes NO
/// parameters - its signature cannot drift - and it fires when the animation reaches its

View file

@ -107,8 +107,9 @@ namespace RacesOfValheim
private static void Summon(Player rider)
{
string race = null;
if (rider.m_customData != null) rider.m_customData.TryGetValue("Race", out race);
// Through WarVultureConfig.RaceOf rather than reading m_customData here, so this gate
// and the one hiding the recipe (WarVultureRecipeRacePatch) are literally the same read.
string race = WarVultureConfig.RaceOf(rider);
if (!WarVultureConfig.RaceAllowed(race))
{