RacesOfValheim/JotunnModStub/Sverm/SvermRavagerAttacks.cs
2026-08-19 19:18:24 +02:00

88 lines
3.9 KiB
C#

using UnityEngine;
namespace RacesOfValheim
{
/// <summary>
/// The Seeker Brute's three real damage profiles - a trigger name and a set of real damage
/// numbers, read once from the Brute's own weapons and cached. Nothing is cloned, registered
/// or equipped.
///
/// THIS REPLACES A WHOLE FILE (SvermRavagerWeapons.cs) THAT TRIED TO EQUIP THE REAL ITEMS AND
/// LET VALHEIM'S OWN Attack.Start RUN. It fought the game at every turn: Humanoid.
/// GetCurrentBlocker routed right-click into a parry because the source items were
/// m_blockable; player.InAttack() stopped rooting the player before the visible clip on the
/// model had actually finished; wiring a working secondary attack meant cloning and mutating
/// Attack objects by hand. None of that is necessary, because this mod already has two
/// working examples of "become a creature and attack" - FenrirBehaviors.cs and
/// DrakeFormBehavior.cs - and NEITHER of them equips anything. A trigger on the model's own
/// Animator plus a timed Physics.OverlapSphere, the same two calls every other transformation
/// in this mod already uses, is the whole mechanism. See RavagerFormBehavior.AttackRoutine.
/// </summary>
public static class SvermRavagerAttacks
{
public struct Profile
{
public string Trigger;
public HitData.DamageTypes Damage;
}
private static Profile bite;
private static Profile ram;
private static Profile slam;
private static Profile taunt;
private static bool read;
public static Profile Bite { get { EnsureRead(); return bite; } }
public static Profile Ram { get { EnsureRead(); return ram; } }
public static Profile Slam { get { EnsureRead(); return slam; } }
/// <summary>
/// type=None on the real Brute, so its Attack fields (range/angle/hitbox) were never
/// meant to land a hit - only m_attackAnimation and m_damages are trustworthy here, which
/// is why the taunt is handled by its own AoE routine rather than folded into
/// AttackRoutine's forward-swing shape.
/// </summary>
public static Profile Taunt { get { EnsureRead(); return taunt; } }
private static void EnsureRead()
{
if (read) return;
read = true;
bite = ReadOne(SvermConfig.RavagerBiteWeapon);
ram = ReadOne(SvermConfig.RavagerRamWeapon);
slam = ReadOne(SvermConfig.RavagerSlamWeapon);
taunt = ReadOne(SvermConfig.RavagerTauntWeapon);
}
private static Profile ReadOne(string sourcePrefabName)
{
GameObject source = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(sourcePrefabName);
ItemDrop drop = source != null ? source.GetComponent<ItemDrop>() : null;
ItemDrop.ItemData.SharedData shared = drop != null ? drop.m_itemData?.m_shared : null;
if (shared == null)
{
Jotunn.Logger.LogWarning($"[Sverm] No '{sourcePrefabName}' to read Ravager Strain damage " +
"from; that attack will land for nothing.");
return default;
}
Profile profile = new Profile
{
Trigger = shared.m_attack != null ? (shared.m_attack.m_attackAnimation ?? "") : "",
Damage = shared.m_damages,
};
Jotunn.Logger.LogInfo($"[Sverm] Ravager Strain reads '{profile.Trigger}' off '{sourcePrefabName}' - " +
$"{DumpDamage(profile.Damage)}.");
return profile;
}
private static string DumpDamage(HitData.DamageTypes d)
{
return $"blunt={d.m_blunt:0.#} slash={d.m_slash:0.#} pierce={d.m_pierce:0.#} " +
$"chop={d.m_chop:0.#} pickaxe={d.m_pickaxe:0.#}";
}
}
}