diff --git a/JotunnModStub/Aswid/AswidBatForm.cs b/JotunnModStub/Aswid/AswidBatForm.cs index 1ce1fc3..2ac80c7 100644 --- a/JotunnModStub/Aswid/AswidBatForm.cs +++ b/JotunnModStub/Aswid/AswidBatForm.cs @@ -118,6 +118,27 @@ namespace RacesOfValheim } } + /// + /// 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. + /// + [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; + } + } + /// /// 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 diff --git a/JotunnModStub/Aswid/AswidConfig.cs b/JotunnModStub/Aswid/AswidConfig.cs index fa58ee2..57bc11a 100644 --- a/JotunnModStub/Aswid/AswidConfig.cs +++ b/JotunnModStub/Aswid/AswidConfig.cs @@ -107,6 +107,7 @@ namespace RacesOfValheim public static ConfigEntry BatMaxDuration; public static ConfigEntry BatDurationPerState; public static ConfigEntry BatCooldown; + public static ConfigEntry BatCombatLock; // ─── Vampiric Aura (passive, always active) ────────────────────────────── public static ConfigEntry 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(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(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(0f, 30f))); const string aura = "Aswid - Vampiric Aura"; AuraTickInterval = config.Bind(aura, "Tick Interval", 0.25f, diff --git a/JotunnModStub/Aswid/AswidRace.cs b/JotunnModStub/Aswid/AswidRace.cs index 556d8d5..d05d8bb 100644 --- a/JotunnModStub/Aswid/AswidRace.cs +++ b/JotunnModStub/Aswid/AswidRace.cs @@ -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. diff --git a/JotunnModStub/Translations/English/messages.json b/JotunnModStub/Translations/English/messages.json index ac5b9d4..b800d90 100644 --- a/JotunnModStub/Translations/English/messages.json +++ b/JotunnModStub/Translations/English/messages.json @@ -18,6 +18,7 @@ "rov_msg_aswid_vae_victis": "Vae Victis", "rov_msg_aswid_what_horrible_night_have_curse": "what a horrible night to have a curse", "rov_msg_aswid_bat_cooldown": "Your blood is not ready to take wing again ($1s)", + "rov_msg_aswid_bat_combat_lock": "Your blood runs too hot from the fight to take wing ($1s)", "rov_msg_aswid_bat_form_fades": "The bat form fades", "rov_msg_aswid_bat_too_heavy_to_beat": "Too heavy to beat your wings. You can only glide", "rov_msg_aswid_too_heavy_for_bat": "You carry too much to take bat form", diff --git a/JotunnModStub/Translations/Italian/messages.json b/JotunnModStub/Translations/Italian/messages.json index 4eb8257..1fb5a4d 100644 --- a/JotunnModStub/Translations/Italian/messages.json +++ b/JotunnModStub/Translations/Italian/messages.json @@ -18,6 +18,7 @@ "rov_msg_aswid_vae_victis": "Vae Victis", "rov_msg_aswid_what_horrible_night_have_curse": "what a horrible night to have a curse", "rov_msg_aswid_bat_cooldown": "Il tuo sangue non è pronto a spiccare il volo di nuovo ($1s)", + "rov_msg_aswid_bat_combat_lock": "Il sangue ti ribolle per lo scontro, non puoi spiccare il volo ($1s)", "rov_msg_aswid_bat_form_fades": "La forma di pipistrello svanisce", "rov_msg_aswid_bat_too_heavy_to_beat": "Troppo pesante per battere le ali. Puoi solo planare", "rov_msg_aswid_too_heavy_for_bat": "Porti troppo peso per prendere la forma di pipistrello", diff --git a/JotunnModStub/Translations/Russian/messages.json b/JotunnModStub/Translations/Russian/messages.json index a067cfb..a60d470 100644 --- a/JotunnModStub/Translations/Russian/messages.json +++ b/JotunnModStub/Translations/Russian/messages.json @@ -18,6 +18,7 @@ "rov_msg_aswid_vae_victis": "Vae Victis", "rov_msg_aswid_what_horrible_night_have_curse": "Какая ужасная ночь для носителя проклятия...", "rov_msg_aswid_bat_cooldown": "Ваша кровь еще не готова снова подняться в небо ($1 с)", + "rov_msg_aswid_bat_combat_lock": "Кровь слишком горяча после схватки, чтобы подняться в небо ($1 с)", "rov_msg_aswid_bat_form_fades": "Облик летучей мыши рассеивается", "rov_msg_aswid_bat_too_heavy_to_beat": "Слишком тяжело, чтобы махать крыльями. Вы можете только планировать", "rov_msg_aswid_too_heavy_for_bat": "Вы несете слишком много, чтобы принять облик летучей мыши",