fix(aswid): let Blood Magic Mastery actually free the cast
Mastery forced Player.HaveEitr true and skipped Player.UseEitr, and neither is what refuses the attack. Attack.Start gates on Character.TryUseEitr, whose first test is GetMaxEitr() == 0 - an Aswid carrying no eitr food has a maximum of zero, so the cast was rejected there and HaveEitr was never consulted at all. That is also why it looked intermittent: it appeared to work for anyone who happened to be eating eitr food and failed for exactly the player it was written for, one leaning on blood magic without eitr. TryUseEitr only gates - the spend is a separate UseEitr call - so returning true there costs nothing, and the existing UseEitr prefix still blocks the drain. The health price is untouched; it is meant to be the whole price. The local-Aswid-holding-blood-magic test was written out three times and now lives in one helper, so the weapon lookup cannot drift between them.
This commit is contained in:
parent
329cf33149
commit
bc9bb302db
1 changed files with 46 additions and 16 deletions
|
|
@ -661,19 +661,56 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue