The staff opened a pair of client-side portals into a claimed troll cave, and that whole mechanism broke in multiplayer. The two Harmony patches it needed were the sharpest edge: SkadiNokkelCastPatch prefixed Attack.OnAttackTrigger and SkadiNokkelFreeCastPatch postfixed the three cost getters, so every attack by every character in the game went through mod code before being filtered. Nothing is put in its place, on purpose. The Crystal Golem is the Skadi's station now and the balance was already settled around it, and the part of the hollow that was actually worth having - Skadi and Trol building inside any troll cave - lives in RaceCaveBuilding and is untouched. Removed: SkadiNokkel.cs, SkadiHollow.cs, SkadiHollowPortal.cs, the "Skadi - Hidden Hollow" config section, the HOLLOW_COOLDOWN_SE status effect, the F8 dump, and the "Nothing takes root here" rule in PieceDensityLimit, which existed only for the hollow. Kept: SkadiIce, which the staff's file happened to host but the Frost Heart and the golem both use - moved to its own file. Greater Frost Heart stays on sale from the Fenring_Cultist at 1500 as it was. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
309 lines
15 KiB
C#
309 lines
15 KiB
C#
using HarmonyLib;
|
|
using Jotunn.Entities;
|
|
using Jotunn.Managers;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// The War Vulture item: a Dead Raiser with the skeleton taken out of it and a vulture trophy
|
|
/// hung in its place. Clicked, it puts the player on a flying bird; clicked again, it brings
|
|
/// them down and takes the bird away.
|
|
///
|
|
/// Why a staff and not a trinket: the game lets a WEAPON be used without any trickery. Cloning
|
|
/// StaffSkeleton buys the click, the cast gesture and the effects for free - which is exactly
|
|
/// the reasoning that produced Skadis Nokkel, whose file this one was written as a twin of. The
|
|
/// Nokkel has since been removed - it opened a portal pair, which broke in multiplayer - so this
|
|
/// file is now the only copy of that pattern and there is no sibling to keep it in step with.
|
|
///
|
|
/// Three things are removed from the vanilla staff, and each is removed TWICE on purpose:
|
|
/// - the eitr, health and stamina costs are zeroed on the clone AND forced to zero in the
|
|
/// getters every cost check flows through (WarVultureFreeCastPatch). The eitr cost is not
|
|
/// cosmetic: it is checked BEFORE the attack starts, so a player without eitr would never
|
|
/// reach the code that summons;
|
|
/// - the summon is nulled on the clone AND the attack trigger itself is taken over, so
|
|
/// vanilla's spawn code is not merely defused but unreachable (WarVultureCastPatch);
|
|
/// - the staff's model is replaced by the trophy under the item's "attach" child, which is
|
|
/// the ONLY child VisEquipment draws - a model hung anywhere else is present, correct and
|
|
/// invisible (design doc 15.11, half an hour paid for once already).
|
|
/// </summary>
|
|
public static class WarVultureItem
|
|
{
|
|
public const string PrefabName = "WarVulture";
|
|
public const string DisplayName = "War Vulture";
|
|
|
|
private const string SourcePrefab = "StaffSkeleton";
|
|
private const string TrophyPrefab = "TrophyVolture";
|
|
private const string Label = "WarVulture";
|
|
|
|
public static void Register()
|
|
{
|
|
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(PrefabName, SourcePrefab);
|
|
if (prefab == null)
|
|
{
|
|
Jotunn.Logger.LogWarning($"[{Label}] Could not clone {SourcePrefab}; {DisplayName} not registered.");
|
|
return;
|
|
}
|
|
|
|
ItemDrop drop = prefab.GetComponent<ItemDrop>();
|
|
if (drop == null || drop.m_itemData == null || drop.m_itemData.m_shared == null)
|
|
{
|
|
Jotunn.Logger.LogWarning($"[{Label}] {SourcePrefab} clone has no usable ItemDrop; {DisplayName} not registered.");
|
|
return;
|
|
}
|
|
|
|
ItemDrop.ItemData.SharedData shared = drop.m_itemData.m_shared;
|
|
shared.m_name = DisplayName;
|
|
shared.m_description = "A vulture's head, kept. Raise it and the bird comes back under you, " +
|
|
"and it will carry you as long as you care to stay up - though it only " +
|
|
"has so much haste in it before it settles into a glide.";
|
|
shared.m_useDurability = false;
|
|
|
|
// ItemType is left exactly as the vanilla staff has it: it decides the equip slot and
|
|
// which animation set the arms use, and the cast gesture is the whole reason this is a
|
|
// staff rather than a trinket.
|
|
|
|
Strip(shared);
|
|
SwapHandModel(prefab);
|
|
|
|
ItemManager.Instance.AddItem(new CustomItem(prefab, fixReference: false));
|
|
|
|
// Built HERE and not at the summon, and the comment on WarVultureVisual explains why in
|
|
// full: this is a context where components may be destroyed immediately, and the summon
|
|
// 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.
|
|
Jotunn.Logger.LogInfo($"[{Label}] {DisplayName} registered: no eitr, no health, no stamina, no skeleton.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes the skeleton staff apart. Every field is zeroed on BOTH attacks, because the
|
|
/// secondary is a separate Attack carrying its own copy of every cost.
|
|
///
|
|
/// The summon hangs off a SpawnAbility on a prefab referenced by the attack, and WHICH
|
|
/// field carries it is not knowable from the game files - so all three candidates go.
|
|
/// Nulling three fields that might each be the culprit costs nothing; guessing wrong costs
|
|
/// a skeleton on every click.
|
|
///
|
|
/// The animation is the one thing deliberately left alone. It is the whole point: the
|
|
/// player raises the trophy, and the bird answers.
|
|
/// </summary>
|
|
private static void Strip(ItemDrop.ItemData.SharedData shared)
|
|
{
|
|
StripAttack(shared.m_attack);
|
|
StripAttack(shared.m_secondaryAttack);
|
|
}
|
|
|
|
private static void StripAttack(Attack attack)
|
|
{
|
|
if (attack == null) return;
|
|
|
|
attack.m_attackEitr = 0f;
|
|
attack.m_drawEitrDrain = 0f;
|
|
attack.m_reloadEitrDrain = 0f;
|
|
|
|
attack.m_attackHealth = 0f;
|
|
attack.m_attackHealthPercentage = 0f;
|
|
attack.m_attackHealthLowBlockUse = false;
|
|
attack.m_attackHealthReturnHit = 0f;
|
|
|
|
attack.m_attackStamina = 0f;
|
|
attack.m_drawStaminaDrain = 0f;
|
|
attack.m_reloadStaminaDrain = 0f;
|
|
|
|
attack.m_attackProjectile = null;
|
|
attack.m_spawnOnTrigger = null;
|
|
attack.m_spawnOnHit = null;
|
|
attack.m_spawnOnHitChance = 0f;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Puts the vulture trophy in the hand where the staff's model was.
|
|
///
|
|
/// "attach" is not a name picked for tidiness: VisEquipment instantiates that child and
|
|
/// nothing else, so this is the only place a held model can live.
|
|
///
|
|
/// The size is a MULTIPLIER rather than a measurement in metres, which is the opposite of
|
|
/// what ModelBorrow does and is right here for one reason: the brief was "the trophy, 40%
|
|
/// smaller". The trophy's own size is the measurement; 0.6 is the relation applied to it.
|
|
/// </summary>
|
|
private static void SwapHandModel(GameObject prefab)
|
|
{
|
|
Transform attach = FindChild(prefab.transform, "attach");
|
|
if (attach == null)
|
|
{
|
|
Jotunn.Logger.LogWarning($"[{Label}] The {SourcePrefab} clone has no 'attach' child, so the " +
|
|
"held model was left as the vanilla staff. VisEquipment draws " +
|
|
"nothing else, so there was nowhere else to put it.");
|
|
return;
|
|
}
|
|
|
|
GameObject trophy = PrefabManager.Cache.GetPrefab<GameObject>(TrophyPrefab);
|
|
if (trophy == null)
|
|
{
|
|
Jotunn.Logger.LogWarning($"[{Label}] No '{TrophyPrefab}' to borrow; the item keeps the " +
|
|
"skeleton staff's look.");
|
|
return;
|
|
}
|
|
|
|
// The old staff mesh goes first, or the hand holds both.
|
|
for (int i = attach.childCount - 1; i >= 0; i--)
|
|
{
|
|
Object.DestroyImmediate(attach.GetChild(i).gameObject);
|
|
}
|
|
foreach (Renderer renderer in attach.GetComponents<Renderer>())
|
|
{
|
|
if (renderer != null) Object.DestroyImmediate(renderer);
|
|
}
|
|
|
|
// Instantiate into a holder that is ALREADY INACTIVE - the one line ModelBorrow exists
|
|
// for. A trophy is an ItemDrop, and Instantiate runs Awake first: waking one for a
|
|
// single frame drops a real trophy on the floor.
|
|
GameObject holder = new GameObject("WarVultureTrophy");
|
|
holder.transform.SetParent(attach, false);
|
|
holder.SetActive(false);
|
|
|
|
GameObject copy = Object.Instantiate(trophy, holder.transform);
|
|
copy.name = "model";
|
|
copy.transform.localPosition = Vector3.zero;
|
|
copy.transform.localRotation = Quaternion.identity;
|
|
copy.transform.localScale = Vector3.one * WarVultureConfig.HandModelScale.Value;
|
|
|
|
StripToMeshesOnly(copy);
|
|
|
|
holder.SetActive(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The trophy reduced to nothing but its shape.
|
|
///
|
|
/// This used to be a BLACKLIST - scripts, colliders, rigidbodies, ZNetView - and it let
|
|
/// through exactly what a blacklist always lets through: the things nobody thought to name.
|
|
/// A vanilla item prefab carries the sparkle that makes dropped loot findable in long grass,
|
|
/// and that lives in ParticleSystems, ParticleSystemRenderers and Lights. None of those is a
|
|
/// MonoBehaviour, so all of them survived, and the item glittered in the player's hand like
|
|
/// something they had just thrown away.
|
|
///
|
|
/// So it is a whitelist now, the same shape as WarVultureVisual's: MeshFilter,
|
|
/// MeshRenderer, SkinnedMeshRenderer, Transform. Note it is deliberately NARROWER than the
|
|
/// mount's whitelist - "Renderer" would be wrong here, because ParticleSystemRenderer IS a
|
|
/// Renderer and it is half of what we are trying to be rid of.
|
|
///
|
|
/// Passes, because Unity refuses to destroy a component another one still requires, and the
|
|
/// refusal only unblocks once the dependent is gone.
|
|
/// </summary>
|
|
private static void StripToMeshesOnly(GameObject copy)
|
|
{
|
|
for (int pass = 0; pass < 6; pass++)
|
|
{
|
|
bool destroyedSomething = false;
|
|
|
|
foreach (Component component in copy.GetComponentsInChildren<Component>(true))
|
|
{
|
|
if (component == null) continue;
|
|
if (component is Transform) continue;
|
|
if (component is MeshFilter) continue;
|
|
if (component is MeshRenderer) continue;
|
|
if (component is SkinnedMeshRenderer) continue;
|
|
|
|
Object.DestroyImmediate(component);
|
|
|
|
if (component == null) destroyedSomething = true;
|
|
}
|
|
|
|
if (!destroyedSomething) break;
|
|
}
|
|
}
|
|
|
|
private static Transform FindChild(Transform root, string name)
|
|
{
|
|
if (root.name == name) return root;
|
|
for (int i = 0; i < root.childCount; i++)
|
|
{
|
|
Transform found = FindChild(root.GetChild(i), name);
|
|
if (found != null) return found;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static bool IsWarVulture(ItemDrop.ItemData item)
|
|
{
|
|
return item != null && item.m_dropPrefab != null && item.m_dropPrefab.name == PrefabName;
|
|
}
|
|
|
|
/// <summary>
|
|
/// True when a cost being asked about belongs to this item.
|
|
///
|
|
/// The fallback on the equipped weapon is necessary rather than belt-and-braces: the cost
|
|
/// getters are called from Attack.Start and m_weapon is not guaranteed to be assigned yet.
|
|
/// It is only consulted when m_weapon is null, so a creature's own attack cannot be zeroed
|
|
/// just because the player happens to be holding the trophy at the time.
|
|
/// </summary>
|
|
public static bool IsWarVultureContext(ItemDrop.ItemData weapon)
|
|
{
|
|
if (weapon != null) return IsWarVulture(weapon);
|
|
|
|
Player local = Player.m_localPlayer;
|
|
return local != null && IsWarVulture(local.GetCurrentWeapon());
|
|
}
|
|
}
|
|
|
|
/// <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
|
|
/// release point, which is when a summon should land.
|
|
///
|
|
/// A Prefix returning FALSE, so for this item vanilla's attack-trigger code never runs at all.
|
|
/// m_weapon and m_character are private on Attack and arrive through Harmony's triple
|
|
/// underscore injection, which is checked at patch time: a rename becomes a startup error
|
|
/// instead of a silent null on every click.
|
|
/// </summary>
|
|
[HarmonyPatch(typeof(Attack), "OnAttackTrigger")]
|
|
public static class WarVultureCastPatch
|
|
{
|
|
public static bool Prefix(ItemDrop.ItemData ___m_weapon, Humanoid ___m_character)
|
|
{
|
|
if (!WarVultureItem.IsWarVulture(___m_weapon)) return true;
|
|
|
|
// Still returns false while riding, so vanilla's trigger never runs - but the dismount
|
|
// is NOT taken from here. In the saddle this event is unreliable: the cast clip loses
|
|
// to the sitting pose before its event fires. WarVultureMount reads the button itself.
|
|
WarVultureMount.Toggle(___m_character as Player);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The item costs nothing, guaranteed.
|
|
///
|
|
/// Zeroing the fields on the clone ought to be enough by every reading of the game's own code.
|
|
/// On the Skadi staff the cost came back in game anyway, which means the write to a clone's
|
|
/// SharedData does not survive something - so relying on it alone is relying on a mechanism
|
|
/// already observed to fail. These three getters are the single funnel every cost check flows
|
|
/// through: Attack.Start asks them before it will start, and the tooltip asks them for what to
|
|
/// print. All three are private and take no parameters, so they are addressed by name.
|
|
/// </summary>
|
|
[HarmonyPatch]
|
|
public static class WarVultureFreeCastPatch
|
|
{
|
|
[HarmonyTargetMethods]
|
|
private static System.Collections.Generic.IEnumerable<System.Reflection.MethodBase> TargetMethods()
|
|
{
|
|
yield return AccessTools.Method(typeof(Attack), "GetAttackEitr");
|
|
yield return AccessTools.Method(typeof(Attack), "GetAttackHealth");
|
|
yield return AccessTools.Method(typeof(Attack), "GetAttackStamina");
|
|
}
|
|
|
|
[HarmonyPostfix]
|
|
private static void Postfix(ItemDrop.ItemData ___m_weapon, ref float __result)
|
|
{
|
|
if (__result == 0f) return;
|
|
if (!WarVultureItem.IsWarVultureContext(___m_weapon)) return;
|
|
|
|
__result = 0f;
|
|
}
|
|
}
|
|
}
|