feat(aswid): bat form waits until 2.5 s after the last hit

An Aswid could take wing in the middle of a fight. Taking bat form is
now refused until Combat Lock seconds (default 2.5, 0 turns it off)
after the local player last lost health. Health is compared around
Character.ApplyDamage, so direct hits and fire, poison and bleeding
ticks all count, and a fully blocked or absorbed hit does not.
Turning back from bat form is never blocked.
This commit is contained in:
kanym 2026-11-05 11:06:33 +01:00
commit 71721caa8d
6 changed files with 39 additions and 0 deletions

View file

@ -118,6 +118,27 @@ namespace RacesOfValheim
}
}
/// <summary>
/// Notes when the local player last lost health, for the bat's combat lock. ApplyDamage is the
/// one final stage for direct hits, burning, poison and bleeding, so comparing health around it
/// catches them all, and a hit fully blocked or absorbed (Alfar shield, Heimkall) is no hurt.
/// </summary>
[HarmonyPatch(typeof(Character), "ApplyDamage",
new[] { typeof(HitData), typeof(bool), typeof(bool), typeof(HitData.DamageModifier) })]
public static class Aswid_BatCombatLock_Patch
{
public static void Prefix(Character __instance, ref float __state)
{
__state = __instance == Player.m_localPlayer ? __instance.GetHealth() : -1f;
}
public static void Postfix(Character __instance, float __state)
{
if (__state < 0f) return;
if (__instance.GetHealth() < __state) AswidRace.LastHurtTime = Time.time;
}
}
/// <summary>
/// Sleepers. UpdateSleep picks the closest player itself, possibly a remote bat, so the counter
/// goes up for the whole call and the bat test happens in the IsDebugFlying postfix, which only

View file

@ -107,6 +107,7 @@ namespace RacesOfValheim
public static ConfigEntry<float> BatMaxDuration;
public static ConfigEntry<float> BatDurationPerState;
public static ConfigEntry<float> BatCooldown;
public static ConfigEntry<float> BatCombatLock;
// ─── Vampiric Aura (passive, always active) ──────────────────────────────
public static ConfigEntry<float> AuraTickInterval;
@ -292,6 +293,8 @@ namespace RacesOfValheim
new ConfigDescription("Seconds added to the max duration per progression state. Does nothing while the max duration is 0.", new AcceptableValueRange<float>(0f, 600f)));
BatCooldown = config.Bind(batform, "Cooldown", 0f,
new ConfigDescription("Seconds after leaving bat form before you can take it again. 0 means none.", new AcceptableValueRange<float>(0f, 3600f)));
BatCombatLock = config.Bind(batform, "Combat Lock", 2.5f,
new ConfigDescription("Seconds after you last lost health (a hit, or a tick of fire, poison or bleeding) before you can take bat form. Turning back from bat form is never blocked. 0 means none.", new AcceptableValueRange<float>(0f, 30f)));
const string aura = "Aswid - Vampiric Aura";
AuraTickInterval = config.Bind(aura, "Tick Interval", 0.25f,

View file

@ -615,6 +615,14 @@ namespace RacesOfValheim
return;
}
// No escaping a fight by taking wing mid-blow: the form waits until the hits stop.
float hurtLeft = AswidConfig.BatCombatLock.Value - (Time.time - LastHurtTime);
if (hurtLeft > 0f)
{
Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_aswid_bat_combat_lock", Mathf.CeilToInt(hurtLeft)));
return;
}
float cooldownLeft = AswidConfig.BatCooldown.Value - (Time.time - lastBatEndTime);
if (cooldownLeft > 0f)
{
@ -629,6 +637,10 @@ namespace RacesOfValheim
// fresh session never begins on cooldown.
private float lastBatEndTime = -100000f;
// When the local player last lost health, for the bat's combat lock. Written by
// Aswid_BatCombatLock_Patch for every race; only the Aswid reads it.
public static float LastHurtTime = -100000f;
// The one bat or mist routine in flight, if any. Kept so ResetRace can stop it: a
// TransformIntoBatRoutine left running through a reset finishes its 1.1s gesture and
// turns a freshly reset Human into a bat.