diff --git a/JotunnModStub/Aswid/AswidPatches.cs b/JotunnModStub/Aswid/AswidPatches.cs index af2c430..c6ce67b 100644 --- a/JotunnModStub/Aswid/AswidPatches.cs +++ b/JotunnModStub/Aswid/AswidPatches.cs @@ -661,19 +661,56 @@ namespace RacesOfValheim } } + /// + /// True while the local Aswid is holding a blood magic item. The three eitr patches below + /// all turn on exactly this condition, so it lives in one place rather than three. + /// + public static bool IsLocalAswidWieldingBloodMagic(Character character) + { + if (character == null || character != Player.m_localPlayer) return false; + if (!AswidRace.IsAswid()) return false; + + ItemDrop.ItemData weapon = Player.m_localPlayer.GetCurrentWeapon(); + return weapon != null && weapon.m_shared != null && + weapon.m_shared.m_skillType == Skills.SkillType.BloodMagic; + } + + /// + /// The gate that actually decides whether a blood magic attack may start, and the reason + /// Blood Magic Mastery did nothing. + /// + /// Attack.Start asks Character.TryUseEitr, whose very first test is: + /// + /// if (GetMaxEitr() == 0) { Message("$hud_eitrrequired"); return false; } + /// + /// An Aswid carrying no eitr food has a maximum of zero, so the attack was refused right + /// there - before HaveEitr was ever consulted, which is why forcing HaveEitr true (below) + /// changed nothing on its own. Freeing the cast has to happen here. + /// + /// TryUseEitr only ever gates; the spend happens separately through UseEitr, so returning + /// true costs nothing. The health price of blood magic is charged elsewhere and is left + /// completely alone - it is meant to be the whole price. + /// + [HarmonyPatch(typeof(Character), "TryUseEitr")] + public static class Character_TryUseEitr_Patch + { + public static bool Prefix(Character __instance, ref bool __result) + { + if (!IsLocalAswidWieldingBloodMagic(__instance)) return true; + + __result = true; + return false; + } + } + [HarmonyPatch(typeof(Player), "HaveEitr")] public static class Player_HaveEitr_Patch { public static void Postfix(Player __instance, ref bool __result) { - if (__instance != null && __instance == Player.m_localPlayer && AswidRace.IsAswid()) - { - var weapon = __instance.GetCurrentWeapon(); - if (weapon != null && weapon.m_shared != null && weapon.m_shared.m_skillType == Skills.SkillType.BloodMagic) - { - __result = true; - } - } + // Still needed for the paths that ask HaveEitr directly rather than through + // TryUseEitr - Attack.FireProjectileBurst and the bow/crossbow draw among them. + if (IsLocalAswidWieldingBloodMagic(__instance)) __result = true; } } @@ -682,14 +719,7 @@ namespace RacesOfValheim { public static bool Prefix(Player __instance) { - if (__instance != null && __instance == Player.m_localPlayer && AswidRace.IsAswid()) - { - var weapon = __instance.GetCurrentWeapon(); - if (weapon != null && weapon.m_shared != null && weapon.m_shared.m_skillType == Skills.SkillType.BloodMagic) - { - return false; // Skip spending Eitr - } - } + if (IsLocalAswidWieldingBloodMagic(__instance)) return false; // Skip spending Eitr return true; } }