Files
claudeandClaude Opus 5.5 2c5f6e4e7d
Ashlar checks / tooling (push) Successful in 5s
Add hit reactions for real time combat
With [Game] real time combat and the new [Game] hit reactions setting on
(default), melee hits cause short reactions:

- A connecting hit queues a flinch of 0.2 to 0.7 s, growing with damage
  up to a quarter of max health and halved at zero attack strength. It
  starts when the hit's stagger is applied, so Lua's ignoreStagger and
  god mode prevent it.
- A blocked hit or parry makes the blocker recoil for 0.1 to 0.25 s, and
  a blocked blow at 0.75 strength or more staggers the attacker for 0.25
  to 0.6 s.
- During any reaction, an attack wind-up is interrupted and no new attack
  starts. Hit animations still play where the content has them; the
  timer works without them, as on the Game Template.

The rules are in mwmechanics/hitreaction.cpp. The shield block and parry
resolution moves into resolveMeleeBlock, shared by NPCs and creatures.
The combat scenario now counts reactions. Also moves a stray line of the
ai active blocking docs back under that setting.

Closes #22

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 03:50:14 -05:00

52 lines
2.5 KiB
C++

#ifndef OPENMW_MECHANICS_HITREACTION_H
#define OPENMW_MECHANICS_HITREACTION_H
namespace MWWorld
{
class Ptr;
}
namespace MWMechanics
{
// Ashlar hit reactions. With [Game] real time combat and [Game] hit reactions on, a connecting melee hit makes the
// victim flinch: its attack wind-up is interrupted and it can't start an attack until the flinch ends. A blocked
// hit gives the blocker a shorter recoil, and a strong blow that is blocked staggers the attacker. Hit animations
// play as before where the content has them; the timing works without them.
/// Shortest and longest flinch from a connecting hit, in seconds, before scaling by attack strength.
constexpr float sMinFlinch = 0.2f;
constexpr float sMaxFlinch = 0.7f;
/// Share of maximum health at which a hit gives the longest flinch.
constexpr float sFullFlinchDamageRatio = 0.25f;
/// Attack strength from which a blocked blow staggers the attacker.
constexpr float sStaggerStrength = 0.75f;
/// Flinch length for a hit of \a damage against \a maxHealth at \a attackStrength (0 to 1). Grows with the
/// damage ratio up to sFullFlinchDamageRatio, and is halved at zero strength. 0 for no damage.
float getFlinchDuration(float damage, float maxHealth, float attackStrength);
/// Recoil length for the blocker of a blow at \a attackStrength: 0.1 s to 0.25 s.
float getBlockRecoilDuration(float attackStrength);
/// Stagger length for an attacker whose blow at \a attackStrength was blocked: 0 below sStaggerStrength, then
/// 0.25 s rising to 0.6 s at full strength.
float getBlockedAttackerStaggerDuration(float attackStrength);
/// True if hit reactions are in use (real time combat and hit reactions on).
bool usesHitReactions();
/// Remembers the flinch for a connecting melee hit on \a victim. It starts when the hit's stagger is applied, so
/// Lua's ignoreStagger prevents it.
void queueFlinch(const MWWorld::Ptr& victim, float damage, float attackStrength);
/// Resolves a shield block or parry of a melee hit of \a damage from \a attacker on \a victim, applies the hit
/// reactions, and returns the damage that gets through.
float resolveMeleeBlock(const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim, const MWWorld::Ptr& weapon,
float damage, float attackStrength);
/// Starts the recoil on \a blocker and, for a strong blow, a stagger on \a attacker after a successful block.
void applyBlockReactions(const MWWorld::Ptr& attacker, const MWWorld::Ptr& blocker, float attackStrength);
}
#endif