diff --git a/JotunnModStub/Skadi/DrakeFormBehavior.cs b/JotunnModStub/Skadi/DrakeFormBehavior.cs index 62941b0..23884cf 100644 --- a/JotunnModStub/Skadi/DrakeFormBehavior.cs +++ b/JotunnModStub/Skadi/DrakeFormBehavior.cs @@ -49,9 +49,25 @@ namespace RacesOfValheim return live != null && live.Form == formRules.Form && live.CanAttackInForm; } - private const float ATTACK_COST = 20f; private const float ATTACK_COOLDOWN = 3f; + // Ranged volleys charge per projectile rather than a flat fee, so the 20- and 60-shard + // breaths cost what they are worth instead of the same as a three-shard drake spit. + // Stamina rather than eitr, for the same reason the Cold Spell uses it: eitr food only + // exists from the Mistlands on, while the drake form arrives at the Elder, so an eitr + // cost left the earliest dragon tiers with no attack they could actually pay for. + private const float STAMINA_PER_PROJECTILE = 1.5f; + // Ceiling so the widest breath stays castable: 60 shards would otherwise ask 90 stamina. + private const float MAX_VOLLEY_STAMINA = 85f; + + // Melee costs nothing at all - it is the baseline attack that has to work at every tier, + // including the long stretch where the player has no eitr whatsoever. + private const float MELEE_RADIUS = 3f; + private const float MODER_MELEE_DAMAGE = 90f; + private const float FADER_MELEE_DAMAGE = 120f; + private const float FADER_SPIN_DAMAGE = 100f; + private const float FADER_SPIN_RADIUS = 5f; + private void Start() { Active = this; @@ -126,7 +142,7 @@ namespace RacesOfValheim { if (Input.GetMouseButtonDown(0)) { - if (Time.time - lastAttackTime >= ATTACK_COOLDOWN) + if (HasAttackForButton(0) && Time.time - lastAttackTime >= ATTACK_COOLDOWN) { StartCoroutine(PerformAttackCoroutine(0)); } @@ -148,15 +164,44 @@ namespace RacesOfValheim } } + // Airborne Moder keeps the same hand as the ground: the ranged breath is Middle Mouse, and + // Left Mouse has no attack in the air (its ground bite and claws cannot reach from up + // there). Checked before the cooldown so a stray left click does not eat the next volley. + private bool HasAttackForButton(int button) + { + if (formRules == null) return false; + + bool airborne = isFlying || isLanding; + if (airborne && formRules.Form == SkadiProgression.FormType.Moder && button != 2) + { + return false; + } + + return true; + } + + private bool TrySpendVolleyStamina(int projCount) + { + float cost = Mathf.Min(STAMINA_PER_PROJECTILE * projCount, MAX_VOLLEY_STAMINA); + if (!Player.m_localPlayer.HaveStamina(cost)) + { + Player.m_localPlayer.Message(MessageHud.MessageType.Center, "Not enough stamina"); + return false; + } + Player.m_localPlayer.UseStamina(cost); + return true; + } + private IEnumerator PerformAttackCoroutine(int button) { lastAttackTime = Time.time; + SkadiRace.ApplyCooldownIcon(SkadiRace.ATTACK_COOLDOWN_SE, ATTACK_COOLDOWN); if (formRules.Form == SkadiProgression.FormType.Drake) { if (button == 2) yield break; // Drake only uses LMB - - Player.m_localPlayer.UseEitr(ATTACK_COST); + + if (!TrySpendVolleyStamina(3)) yield break; if (anim != null) anim.SetTrigger("attack"); // Delay to match animation spit timing @@ -229,12 +274,17 @@ namespace RacesOfValheim projDelay = 0.5f; } } - - Player.m_localPlayer.UseEitr(ATTACK_COST); + + if (!isMelee && !TrySpendVolleyStamina(projCount)) yield break; if (anim != null) anim.SetTrigger(attackTrigger); - + yield return new WaitForSeconds(projDelay); + if (isMelee) + { + ExecuteMeleeDamage(MODER_MELEE_DAMAGE, MELEE_RADIUS); + } + if (!isMelee && projName != null) { GameObject projPrefab = PrefabManager.Cache.GetPrefab(projName); @@ -277,51 +327,50 @@ namespace RacesOfValheim int projCount = 1; float projDelay = 0.5f; bool isMelee = true; + float meleeDamage = FADER_MELEE_DAMAGE; + float meleeRadius = MELEE_RADIUS; - if (isFlying || isLanding) + // No airborne branch here: the flight toggle in Update excludes SkeletonDragon, + // so this form never leaves the ground and any air attack would be unreachable. + if (button == 2) { - // Air attack (Meteors replacement -> Ice Barrage) - attackTrigger = "attack_roar"; // taunt animation has issues in air - projName = "dragon_ice_projectile"; // spawn_fader_meteors is buggy without Fader boss script - projCount = 16; - projDelay = 1.0f; + // Ground MMB (Frost Breath stream) + attackTrigger = "attack_flamebreath"; + projName = "hatchling_cold_projectile"; + projCount = 60; // Tripled! + projDelay = 0.5f; isMelee = false; } + else if (button == 1) + { + // Ground RMB (Spin) - hits all around rather than in a forward arc + attackTrigger = "attack_Spin"; + isMelee = true; + projDelay = 0.5f; + meleeDamage = FADER_SPIN_DAMAGE; + meleeRadius = FADER_SPIN_RADIUS; + } else { - if (button == 2) - { - // Ground MMB (Frost Breath stream) - attackTrigger = "attack_flamebreath"; - projName = "hatchling_cold_projectile"; - projCount = 60; // Tripled! - projDelay = 0.5f; - isMelee = false; - } - else if (button == 1) - { - // Ground RMB (Spin) - attackTrigger = "attack_Spin"; - isMelee = true; - projDelay = 0.5f; - } - else - { - // Ground LMB (Melee mix - bite/claws) - float rand = UnityEngine.Random.value; - if (rand < 0.33f) attackTrigger = "attack_bite"; - else if (rand < 0.66f) attackTrigger = "attack_ClawL"; - else attackTrigger = "attack_ClawR"; - isMelee = true; - projDelay = 0.5f; - } + // Ground LMB (Melee mix - bite/claws) + float rand = UnityEngine.Random.value; + if (rand < 0.33f) attackTrigger = "attack_bite"; + else if (rand < 0.66f) attackTrigger = "attack_ClawL"; + else attackTrigger = "attack_ClawR"; + isMelee = true; + projDelay = 0.5f; } - Player.m_localPlayer.UseEitr(ATTACK_COST); + if (!isMelee && !TrySpendVolleyStamina(projCount)) yield break; if (anim != null) anim.SetTrigger(attackTrigger); - + yield return new WaitForSeconds(projDelay); + if (isMelee) + { + ExecuteMeleeDamage(meleeDamage, meleeRadius); + } + if (!isMelee && projName != null) { GameObject projPrefab = PrefabManager.Cache.GetPrefab(projName); @@ -377,6 +426,69 @@ namespace RacesOfValheim } } + // The dragon forms never go through Humanoid.StartAttack - SkadiAttackPatch blocks it, and + // they carry no weapon - so the bite, claw and spin animations landed no damage at all and + // simply burned eitr. Sweep for targets the way FenrirBehaviors does for its claws. + private void ExecuteMeleeDamage(float baseDamage, float radius) + { + if (Player.m_localPlayer == null) return; + + Vector3 playerPos = Player.m_localPlayer.transform.position; + Vector3 forward = Player.m_localPlayer.transform.forward; + Vector3 attackPoint = playerPos + forward * 2f + Vector3.up * 1f; + + // Spin sweeps all around; the directional attacks stay in a forward arc. + bool fullCircle = radius >= FADER_SPIN_RADIUS; + float totalDamage = baseDamage + Player.m_localPlayer.GetSkillLevel(Skills.SkillType.Unarmed); + if (fullCircle) attackPoint = playerPos + Vector3.up * 1f; + + int layerMask = LayerMask.GetMask("Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "character", "character_net", "character_ghost", "hitbox", "character_noenv", "vehicle"); + Collider[] hits = Physics.OverlapSphere(attackPoint, radius, layerMask); + System.Collections.Generic.HashSet hitObjects = new System.Collections.Generic.HashSet(); + + foreach (Collider hit in hits) + { + if (hit.gameObject == Player.m_localPlayer.gameObject) continue; + if (hit.attachedRigidbody != null && hit.attachedRigidbody.gameObject == Player.m_localPlayer.gameObject) continue; + + IDestructible target = hit.GetComponentInParent(); + if (target == null) continue; + + Character characterTarget = target as Character; + if (characterTarget != null && characterTarget == Player.m_localPlayer) continue; + + GameObject targetObj = (target as MonoBehaviour)?.gameObject; + if (targetObj != null) + { + if (hitObjects.Contains(targetObj)) continue; + hitObjects.Add(targetObj); + } + + Vector3 targetCenter = hit.bounds.center; + Vector3 dirToTarget = (targetCenter - playerPos).normalized; + if (!fullCircle && Vector3.Angle(forward, dirToTarget) >= 70f) continue; + + Vector3 eyePos = playerPos + Vector3.up * 1.5f; + if (Physics.Linecast(eyePos, targetCenter, out RaycastHit rayHit, LayerMask.GetMask("Default", "static_solid", "terrain", "piece"))) continue; + + HitData hitData = new HitData(); + // Frost-flavoured maul; SkadiDamagePatch tops this up with the per-tier frost bonus. + hitData.m_damage.m_blunt = totalDamage * 0.6f; + hitData.m_damage.m_frost = totalDamage * 0.4f; + hitData.m_pushForce = 40f; + hitData.m_point = targetCenter; + hitData.m_dir = dirToTarget; + hitData.m_skill = Skills.SkillType.Unarmed; + hitData.m_dodgeable = true; + hitData.m_blockable = true; + hitData.m_hitType = HitData.HitType.PlayerHit; + hitData.m_toolTier = 0; + hitData.SetAttacker(Player.m_localPlayer); + + target.Damage(hitData); + } + } + private void OnDestroy() { if (Active == this) Active = null; diff --git a/JotunnModStub/Skadi/SkadiPatches.cs b/JotunnModStub/Skadi/SkadiPatches.cs index e38a81e..7007e03 100644 --- a/JotunnModStub/Skadi/SkadiPatches.cs +++ b/JotunnModStub/Skadi/SkadiPatches.cs @@ -282,12 +282,28 @@ namespace RacesOfValheim [HarmonyPatch(typeof(Humanoid), "StartAttack")] public static class SkadiAttackPatch { - public static bool Prefix(Humanoid __instance) + public static bool Prefix(Humanoid __instance, bool secondaryAttack) { - if (__instance == Player.m_localPlayer && __instance.GetComponentInChildren() != null) + if (__instance != Player.m_localPlayer) return true; + + if (__instance.GetComponentInChildren() != null) { return false; } + + // Valheim binds its own SecondaryAttack action to Middle Mouse, the same button the + // Cold Spell casts on, so pressing it also swung the unarmed secondary - the kick that + // kept showing up alongside the cast no matter which animation trigger we used. For a + // Skadi who has the spell, Middle Mouse belongs to the spell. Keyed off the live button + // state rather than a flag set during our Update, so it does not depend on whether + // PlayerController's FixedUpdate happens to run first. + if (secondaryAttack && Input.GetMouseButton(2) && + SkadiRace.Instance != null && SkadiRace.Instance.IsSkadi()) + { + var rules = SkadiProgression.GetRules(BossProgressionManager.GetCurrentProgressionState()); + if (rules.ColdSpell) return false; + } + return true; } } diff --git a/JotunnModStub/Skadi/SkadiRace.cs b/JotunnModStub/Skadi/SkadiRace.cs index 1b45633..abd1c4b 100644 --- a/JotunnModStub/Skadi/SkadiRace.cs +++ b/JotunnModStub/Skadi/SkadiRace.cs @@ -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(); 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(); + 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(); + 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(prefabName)?.gameObject; ItemDrop drop = trophy != null ? trophy.GetComponent() : 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("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(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); } diff --git a/JotunnModStub/Skadi/SkadiStatusEffects.cs b/JotunnModStub/Skadi/SkadiStatusEffects.cs index b6517af..dc6e3ee 100644 --- a/JotunnModStub/Skadi/SkadiStatusEffects.cs +++ b/JotunnModStub/Skadi/SkadiStatusEffects.cs @@ -10,6 +10,13 @@ namespace RacesOfValheim { } + // Short ability cooldowns, shown purely so the HUD can count them down. Silent by design, + // unlike SE_FormCooldown which announces "... is Ready!" when it stops: tolerable once every + // few minutes for a dragon form, unbearable every three seconds for an attack. + public class SE_SkadiAbilityCooldown : StatusEffect + { + } + public class SE_SkadiStats : SE_Stats { public override void Setup(Character character)