Past Fader the Trol's True Form never expires (SE ttl 0) and the key toggles it off with no cooldown. The True Form log throw now fires one projectile read off the Gammeltroll's own weapons at runtime, hitting with the rock's damage formula, and falls back to the old physical log if none is found; 'dumpgammel' logs what was resolved. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
126 lines
6.2 KiB
C#
126 lines
6.2 KiB
C#
using System.Collections.Generic;
|
|
using Jotunn.Entities;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// The thrown log in True Form borrows ONE projectile from the Gammeltroll (Valheim 1.0), the
|
|
/// one it fires a whole rose of. The prefab names live in compressed asset bundles, so nothing
|
|
/// here is hard-coded past the monster itself: the projectile is read off the Gammeltroll's own
|
|
/// weapons at runtime, the same way Attack.Start would find it. Two shapes are handled:
|
|
/// - the rose is m_projectiles > 1 on the attack: the attack's projectile already IS one log;
|
|
/// - the rose is a single projectile that splits on hit (m_spawnOnHit with m_spawnCount > 1):
|
|
/// then the log is the child, and the parent would bring the whole rose along with it.
|
|
/// If none of that resolves, GetProjectile returns null and TrolRace falls back to the old
|
|
/// physical log. "dumpgammel" in the console logs what was actually found.
|
|
/// </summary>
|
|
public static class TrolGammelLog
|
|
{
|
|
private const string GammeltrollPrefab = "Gammeltroll";
|
|
|
|
private static GameObject cachedProjectile;
|
|
private static float cachedVelocity;
|
|
private static bool warned;
|
|
|
|
public static GameObject GetProjectile(out float velocity)
|
|
{
|
|
if (cachedProjectile == null && ZNetScene.instance != null)
|
|
{
|
|
Resolve(out cachedProjectile, out cachedVelocity, null);
|
|
if (cachedProjectile == null && !warned)
|
|
{
|
|
warned = true;
|
|
Jotunn.Logger.LogWarning("[Trol] Gammeltroll log projectile not found - falling back to the physical log throw. Run 'dumpgammel' to see why.");
|
|
}
|
|
}
|
|
velocity = cachedVelocity > 0f ? cachedVelocity : TrolConfig.ThrowLogVelocity.Value;
|
|
return cachedProjectile;
|
|
}
|
|
|
|
/// <summary>log is null for the silent path; the dump command passes a sink.</summary>
|
|
internal static void Resolve(out GameObject projectile, out float velocity, System.Action<string> log)
|
|
{
|
|
projectile = null;
|
|
velocity = 0f;
|
|
|
|
GameObject troll = FindGammeltroll();
|
|
if (troll == null) { log?.Invoke("Gammeltroll prefab not found in ZNetScene."); return; }
|
|
log?.Invoke($"Monster prefab: '{troll.name}'");
|
|
|
|
Humanoid humanoid = troll.GetComponent<Humanoid>();
|
|
if (humanoid == null) { log?.Invoke(" no Humanoid on it."); return; }
|
|
|
|
// Prefer the attack that fires several projectiles at once (the rose); any other
|
|
// projectile attack is only a fallback.
|
|
Attack best = null;
|
|
foreach (GameObject item in ItemsOf(humanoid))
|
|
{
|
|
ItemDrop drop = item != null ? item.GetComponent<ItemDrop>() : null;
|
|
if (drop == null) continue;
|
|
var shared = drop.m_itemData.m_shared;
|
|
foreach (Attack attack in new[] { shared.m_attack, shared.m_secondaryAttack })
|
|
{
|
|
if (attack == null) continue;
|
|
log?.Invoke($" item '{item.name}' anim='{attack.m_attackAnimation}' projectile='{(attack.m_attackProjectile != null ? attack.m_attackProjectile.name : "-")}' count={attack.m_projectiles} bursts={attack.m_projectileBursts} vel={attack.m_projectileVel} acc={attack.m_projectileAccuracy}");
|
|
if (attack.m_attackProjectile == null) continue;
|
|
if (best == null || (attack.m_projectiles > 1 && best.m_projectiles <= 1)) best = attack;
|
|
}
|
|
}
|
|
if (best == null) { log?.Invoke(" no attack with a projectile."); return; }
|
|
|
|
projectile = best.m_attackProjectile;
|
|
velocity = best.m_projectileVel;
|
|
|
|
Projectile p = projectile.GetComponent<Projectile>();
|
|
if (p != null)
|
|
{
|
|
log?.Invoke($" chosen '{projectile.name}': spawnOnHit='{(p.m_spawnOnHit != null ? p.m_spawnOnHit.name : "-")}' spawnCount={p.m_spawnCount} randomSpawns={(p.m_randomSpawnOnHit != null ? p.m_randomSpawnOnHit.Count : 0)} damage={p.m_damage.GetTotalDamage()}");
|
|
if (p.m_spawnOnHit != null && p.m_spawnCount > 1 && p.m_spawnOnHit.GetComponent<Projectile>() != null)
|
|
{
|
|
projectile = p.m_spawnOnHit;
|
|
log?.Invoke($" it splits on hit - using the child '{projectile.name}' instead.");
|
|
}
|
|
}
|
|
log?.Invoke($"=> thrown log: '{projectile.name}', velocity {velocity}");
|
|
}
|
|
|
|
private static GameObject FindGammeltroll()
|
|
{
|
|
GameObject exact = ZNetScene.instance.GetPrefab(GammeltrollPrefab);
|
|
if (exact != null) return exact;
|
|
foreach (GameObject prefab in ZNetScene.instance.m_prefabs)
|
|
{
|
|
if (prefab != null && prefab.name.ToLowerInvariant().Contains("gammel") && prefab.GetComponent<Humanoid>() != null)
|
|
return prefab;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private static IEnumerable<GameObject> ItemsOf(Humanoid h)
|
|
{
|
|
if (h.m_defaultItems != null) foreach (var go in h.m_defaultItems) yield return go;
|
|
if (h.m_randomWeapon != null) foreach (var go in h.m_randomWeapon) yield return go;
|
|
if (h.m_randomSets != null)
|
|
foreach (var set in h.m_randomSets)
|
|
if (set.m_items != null) foreach (var go in set.m_items) yield return go;
|
|
if (h.m_randomItems != null) foreach (var ri in h.m_randomItems) yield return ri.m_prefab;
|
|
}
|
|
}
|
|
|
|
public class DumpGammelCommand : ConsoleCommand
|
|
{
|
|
public override string Name => "dumpgammel";
|
|
public override string Help => "[DEBUG] Logs the Gammeltroll's projectile attacks and which one the Trol throws as a log";
|
|
|
|
public override void Run(string[] args)
|
|
{
|
|
if (ZNetScene.instance == null) { Console.instance.Print("Load a world first."); return; }
|
|
TrolGammelLog.Resolve(out _, out _, line =>
|
|
{
|
|
Jotunn.Logger.LogInfo("[dumpgammel] " + line);
|
|
Console.instance.Print(line);
|
|
});
|
|
}
|
|
}
|
|
}
|