Rework Skadi combat costs, fix dead melee, add cooldown icons

Dragon melee never dealt damage at all: the damage block sat behind
!isMelee, so bite, claw and spin played an animation, charged eitr and
did nothing. Melee now sweeps for targets the way Fenrir's claws do, and
costs nothing - it is the baseline attack that has to work at every tier.

Everything Skadi casts now runs on stamina rather than eitr. Eitr food
only exists from the Mistlands on, while the Cold Spell unlocks at
Eikthyr and the drake at the Elder, so the old costs were either
unpayable or, in the drake's case, silently ignored because UseEitr
never checked affordability. Ranged volleys are charged per projectile
so the sixty shard breath no longer costs the same as a three shard
spit, capped so the widest one stays castable.

The Cold Spell also stopped borrowing the Staff of Frost's damage, which
handed out Mistlands numbers from Eikthyr and multiplied them by every
shard. It now scales with progression, and the improved cast spreads one
budget across its shards: wider, not stronger.

The kick that played over every cast was Valheim's own SecondaryAttack,
bound to the same Middle Mouse button - suppressed for a Skadi holding
the spell. Moder now keeps its ranged attack on Middle Mouse in the air
as on the ground, with no left hand attack aloft, and Fader's airborne
branch is gone since its form cannot fly.

Ability cooldowns finally show on the HUD, each with its own icon and a
live countdown.
This commit is contained in:
kanym 2026-08-01 18:02:24 +02:00
commit fc7fd54404
4 changed files with 251 additions and 56 deletions

View file

@ -24,6 +24,21 @@ namespace RacesOfValheim
private float lastAuraTime = 0f;
private GameObject frostAuraVFX = null;
// Cold Spell tuning. Damage is 15 + 8 per progression state, so it runs from roughly 31 at
// Eikthyr to 79 at Fader - deliberately a notch under the melee options of the other races
// at each tier, which is the trade for hitting at range on a short cooldown.
public const string SPELL_COOLDOWN_SE = "SE_SkadiSpellCooldown";
public const string ATTACK_COOLDOWN_SE = "SE_SkadiAttackCooldown";
private const float SPELL_STAMINA_COST = 20f;
private const float SPELL_COOLDOWN = 1.5f;
private const float IMPROVED_SPELL_COOLDOWN = 4f;
private const float SPELL_BASE_DAMAGE = 15f;
private const float SPELL_DAMAGE_PER_STATE = 8f;
private const int IMPROVED_SPELL_SHARDS = 10;
// The improved cast spreads 1.6 casts worth of damage over its shards: wider, not stronger.
private const float IMPROVED_SPELL_DAMAGE_BUDGET = 1.6f;
private void Awake()
{
Instance = this;
@ -52,7 +67,7 @@ namespace RacesOfValheim
// Timed forms and their cooldown are Moder's, so they carry her trophy rather than the
// drake one used for the passive blessing.
Sprite dragonIcon = GetTrophyIcon("TrophyDragonQueen") ?? GetTrophyIcon("TrophyHatchling");
Sprite dragonIcon = GetItemIcon("TrophyDragonQueen") ?? GetItemIcon("TrophyHatchling");
skadiCdSE = ScriptableObject.CreateInstance<SE_FormCooldown>();
skadiCdSE.name = "SE_SkadiCooldown";
@ -66,9 +81,40 @@ namespace RacesOfValheim
skadiFormSE.m_tooltip = "Your dragon shape holds for a while longer.";
skadiFormSE.m_icon = dragonIcon;
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(skadiFormSE, fixReference: false));
// Per-ability cooldowns. Each gets its own icon so a spell on cooldown reads
// differently from a dragon attack on cooldown at a glance.
var spellCd = ScriptableObject.CreateInstance<SE_SkadiAbilityCooldown>();
spellCd.name = SPELL_COOLDOWN_SE;
spellCd.m_name = "Cold Spell";
spellCd.m_tooltip = "The frost must gather again before you may cast.";
spellCd.m_icon = GetItemIcon("StaffIceShards") ?? dragonIcon;
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(spellCd, fixReference: false));
var attackCd = ScriptableObject.CreateInstance<SE_SkadiAbilityCooldown>();
attackCd.name = ATTACK_COOLDOWN_SE;
attackCd.m_name = "Dragon Attack";
attackCd.m_tooltip = "Your dragon shape must ready itself to strike again.";
attackCd.m_icon = GetItemIcon("TrophyHatchling") ?? dragonIcon;
ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(attackCd, fixReference: false));
}
private static Sprite GetTrophyIcon(string prefabName)
// Drives the HUD countdown: Valheim prints the remaining time on any status effect whose
// m_ttl is set, so the cooldown only has to exist for the icon to tick down by itself.
public static void ApplyCooldownIcon(string effectName, float seconds)
{
if (Player.m_localPlayer == null || seconds <= 0f) return;
int hash = effectName.GetStableHashCode();
SEMan seman = Player.m_localPlayer.GetSEMan();
seman.RemoveStatusEffect(hash, true);
seman.AddStatusEffect(hash, true);
StatusEffect se = seman.GetStatusEffect(hash);
if (se != null) se.m_ttl = seconds;
}
private static Sprite GetItemIcon(string prefabName)
{
GameObject trophy = PrefabManager.Cache.GetPrefab<ItemDrop>(prefabName)?.gameObject;
ItemDrop drop = trophy != null ? trophy.GetComponent<ItemDrop>() : null;
@ -264,24 +310,29 @@ namespace RacesOfValheim
// Middle Mouse Button to cast
if (Input.GetMouseButtonDown(2))
{
float cooldown = rules.ImprovedColdSpell ? 2.0f : 1.5f;
// The improved cast is a burst rather than a rapid-fire, so it waits longer.
float cooldown = rules.ImprovedColdSpell ? IMPROVED_SPELL_COOLDOWN : SPELL_COOLDOWN;
if (Time.time - lastSpellTime < cooldown) return;
if (!Player.m_localPlayer.HaveEitr(10f))
// Stamina, never eitr: the spell unlocks at Eikthyr but eitr food only exists from
// the Mistlands onward, so the old HaveEitr gate left it unusable for five tiers.
if (!Player.m_localPlayer.HaveStamina(SPELL_STAMINA_COST))
{
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "Not enough Eitr");
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "Not enough stamina");
return;
}
Player.m_localPlayer.UseEitr(10f);
Player.m_localPlayer.UseStamina(SPELL_STAMINA_COST);
lastSpellTime = Time.time;
ApplyCooldownIcon(SPELL_COOLDOWN_SE, cooldown);
var zanim = HarmonyLib.Traverse.Create(Player.m_localPlayer).Field<ZSyncAnimation>("m_zanim").Value;
if (zanim != null)
{
// Raised-arms Galdr cast gesture instead of the unarmed kick, so the cast
// reads as a spell instead of a leg swing near the ground.
zanim.SetTrigger("galdr_cast");
// "galdr_cast" is not one of the triggers Valheim actually defines, so it
// never fired and the unarmed kick stayed. "gpower" is the guardian power
// raise: both arms up, which reads as casting rather than a leg swing.
zanim.SetTrigger("gpower");
}
StartCoroutine(ColdSpellKickCoroutine(rules));
@ -307,14 +358,23 @@ namespace RacesOfValheim
{
projPrefab = PrefabManager.Cache.GetPrefab<GameObject>(projName);
}
if (projPrefab == null)
if (projPrefab == null)
{
projPrefab = staffDrop.m_itemData.m_shared.m_attack.m_attackProjectile; // Default Staff of Frost projectile
}
if (projPrefab == null) yield break;
int count = rules.ImprovedColdSpell ? 10 : 1;
int count = rules.ImprovedColdSpell ? IMPROVED_SPELL_SHARDS : 1;
// The staff prefab is borrowed for its projectile visuals and velocity only. Its damage
// is Mistlands-tier, which the spell used to hand out in full from Eikthyr onward, and
// once per shard - so the improved cast was a ten times nuke rather than a wider one.
// Scale with progression instead, and split one budget across the shards.
int state = BossProgressionManager.GetCurrentProgressionState();
float castDamage = SPELL_BASE_DAMAGE + SPELL_DAMAGE_PER_STATE * state;
if (count > 1) castDamage *= IMPROVED_SPELL_DAMAGE_BUDGET;
float shardDamage = castDamage / count;
for (int i = 0; i < count; i++)
{
if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) break;
@ -336,7 +396,7 @@ namespace RacesOfValheim
if (proj != null)
{
HitData hitData = new HitData();
hitData.m_damage = staffDrop.m_itemData.m_shared.m_damages;
hitData.m_damage.m_frost = shardDamage;
hitData.SetAttacker(Player.m_localPlayer);
proj.Setup(Player.m_localPlayer, lookDir * staffDrop.m_itemData.m_shared.m_attack.m_projectileVel, -1f, hitData, staffDrop.m_itemData, null);
}