diff --git a/JotunnModStub/PieceDensityLimit.cs b/JotunnModStub/PieceDensityLimit.cs
index e39f9b4..1546e21 100644
--- a/JotunnModStub/PieceDensityLimit.cs
+++ b/JotunnModStub/PieceDensityLimit.cs
@@ -199,4 +199,46 @@ namespace RacesOfValheim
return PieceDensityLimit.Allow(__instance, Utils.GetPrefabName(__0.gameObject), __1);
}
}
+
+ ///
+ /// What makes "a prefix returning false spends nothing" TRUE, which on its own it is not.
+ ///
+ /// Read off the 1.0 IL: nothing is paid inside PlacePiece. TryPlacePiece calls it and then does an
+ /// unconditional `ldc.i4.1; ret`, and it is UpdatePlacement that, on that true, runs
+ /// ConsumeResources and UseStamina. So every race lock in the mod - this class's gates, the Trol
+ /// totem, the Dvergar bank and barrel, the Trenta Root - stopped the building and still took the
+ /// wood: "Only the Sverm can raise a hive", and 40 wood and 20 resin gone.
+ ///
+ /// Fixed here once rather than in each lock: a last-priority prefix on the same PlacePiece
+ /// overload sees __runOriginal after every other prefix has had its say, and if any of them said
+ /// no, TryPlacePiece reports false - the path vanilla already takes for a blocked placement, which
+ /// charges nothing. Any lock added later is covered without knowing this exists.
+ ///
+ [HarmonyPatch(typeof(Player), "PlacePiece",
+ new[] { typeof(Piece), typeof(Vector3), typeof(Quaternion), typeof(bool), typeof(bool) })]
+ public static class PlacementRefusalWatch
+ {
+ internal static bool Refused;
+
+ [HarmonyPriority(Priority.Last)]
+ public static void Prefix(bool __runOriginal)
+ {
+ if (!__runOriginal) Refused = true;
+ }
+ }
+
+ [HarmonyPatch(typeof(Player), "TryPlacePiece")]
+ public static class PlacementRefusalCharge
+ {
+ public static void Prefix()
+ {
+ PlacementRefusalWatch.Refused = false;
+ }
+
+ public static void Postfix(ref bool __result)
+ {
+ if (PlacementRefusalWatch.Refused) __result = false;
+ PlacementRefusalWatch.Refused = false;
+ }
+ }
}
diff --git a/JotunnModStub/Skadi/SkadiPatches.cs b/JotunnModStub/Skadi/SkadiPatches.cs
index 6db166c..1a793db 100644
--- a/JotunnModStub/Skadi/SkadiPatches.cs
+++ b/JotunnModStub/Skadi/SkadiPatches.cs
@@ -549,7 +549,10 @@ namespace RacesOfValheim
// the live button state (via the configured shortcut, so a rebind stays in sync)
// rather than a flag set during our Update, so it does not depend on whether
// PlayerController's FixedUpdate happens to run first.
- if (secondaryAttack && SkadiConfig.ColdSpellKey.Value.IsPressedIgnoringHeldKeys() &&
+ // The pad's secondary attack casts only bare-handed (SkadiRace.PadCastsColdSpell), so it
+ // swallows the kick only then; with a weapon in hand the weapon's secondary goes through.
+ bool padCast = RaceInput.PadAttackHeld(2) && SkadiRace.PadCastsColdSpell(Player.m_localPlayer);
+ if (secondaryAttack && (SkadiConfig.ColdSpellKey.Value.IsPressedIgnoringHeldKeys() || padCast) &&
SkadiRace.Instance != null && SkadiRace.Instance.IsSkadi())
{
var rules = SkadiProgression.GetRules(BossProgressionManager.GetCurrentProgressionState());
diff --git a/JotunnModStub/Skadi/SkadiRace.cs b/JotunnModStub/Skadi/SkadiRace.cs
index fe7a3ef..34886e8 100644
--- a/JotunnModStub/Skadi/SkadiRace.cs
+++ b/JotunnModStub/Skadi/SkadiRace.cs
@@ -339,9 +339,18 @@ namespace RacesOfValheim
if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return;
if (isTransformed) return; // Do not cast human spell while in dragon form
+ // Hammer, hoe or cultivator in hand: every build button is vanilla's. Middle mouse is
+ // Remove on the keyboard, and on the pad JoySecondaryAttack shares its physical button
+ // with JoyRemove (Classic) or JoyPlace (Alt2) - read off ZInput.AddGamepad*Buttons - so
+ // each piece built or removed also cast the spell and drained the stamina for it.
+ if (Player.m_localPlayer.InPlaceMode()) return;
+
// Middle Mouse Button to cast, by default - rebindable via SkadiConfig.ColdSpellKey.
- // On a gamepad, the secondary attack button (the pad's own middle-mouse equivalent).
- if (SkadiConfig.ColdSpellKey.Value.IsDownIgnoringHeldKeys() || RaceInput.PadAttackDown(2))
+ // On a gamepad, the secondary attack button (the pad's own middle-mouse equivalent) -
+ // but only bare-handed: the pad has no separate spell key, so with a weapon or a tool
+ // that button belongs to the item's own secondary attack, as it does in vanilla.
+ if (SkadiConfig.ColdSpellKey.Value.IsDownIgnoringHeldKeys() ||
+ (RaceInput.PadAttackDown(2) && PadCastsColdSpell(Player.m_localPlayer)))
{
// The improved cast is a burst rather than a rapid-fire, so it waits longer.
float cooldown = rules.ImprovedColdSpell ? IMPROVED_SPELL_COOLDOWN : SPELL_COOLDOWN;
@@ -373,6 +382,19 @@ namespace RacesOfValheim
}
}
+ ///
+ /// Whether the pad's secondary attack button casts the Cold Spell right now: out of build
+ /// mode and with nothing in either hand. Shared with SkadiAttackPatch, which swallows the
+ /// unarmed kick under exactly the same condition.
+ ///
+ public static bool PadCastsColdSpell(Player player)
+ {
+ if (player == null || player.InPlaceMode()) return false;
+ var hands = HarmonyLib.Traverse.Create(player);
+ return hands.Field("m_rightItem").Value == null &&
+ hands.Field("m_leftItem").Value == null;
+ }
+
private IEnumerator ColdSpellKickCoroutine(SkadiProgression.FormRules rules)
{
// Wait for the cast animation to reach the release point