Files
claudeandClaude Opus 5.5 70b7ea51e8
Ashlar checks / tooling (push) Successful in 5s
Add parry, ignoreStagger and low-stamina phases to the combat scenario
The headless duel now drops the player's shield and holds Block to parry
with the blade, has the duelist set ignoreStagger on hits it takes for a
window, then holds the player's fatigue below the attack fatigue
threshold and below the attack fatigue cap.

The engine logs refused attacks (once per press, any actor) and capped
attack strength at verbose level as "Ashlar stamina:" lines, and
docker/ashlar-run.sh counts parries, refused and capped attacks, and the
duelist's flinches inside the ignoreStagger window. The scenario's
default run time is now 150 s.

Closes #25

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

156 lines
5.8 KiB
Lua

-- Ashlar headless combat scenario (CC0): the player faces the duelist and runs through timed phases:
-- block (2-14 s) holds Block with the shield, so the duelist's attacks hit the shield
-- parry (14-24 s) drops the shield and holds Block with the blade alone
-- attack (24-40 s) attacks repeatedly so the duelist's AI gets to block; from 32 s the duelist sets
-- ignoreStagger on the hits it takes, which must not make it flinch
-- tired (40-50 s) fatigue is held at 5% of maximum, below [Game] attack fatigue threshold; attacks are refused
-- capped (50-64 s) fatigue is held at 25%, below [Game] attack fatigue cap; full wind-ups are capped
local self = require('openmw.self')
local types = require('openmw.types')
local util = require('openmw.util')
local I = require('openmw.interfaces')
local Actor = types.Actor
-- Phase start times in seconds after the scenario starts; each phase runs until the next one starts.
local PHASES = {
{ name = 'block', at = 2 },
{ name = 'parry', at = 14 },
{ name = 'attack', at = 24 },
{ name = 'ignorestagger', at = 32 },
{ name = 'tired', at = 40, fatigue = 0.05 },
{ name = 'capped', at = 50, fatigue = 0.25 },
{ name = 'done', at = 64 },
}
local kit
local t = 0
local phase = { name = 'idle', at = 0 }
local swing = 0
local hits = { taken = 0, zero = 0 }
local function log(...)
print('ASHLAR_COMBAT', ...)
end
-- Stats can only be changed by the actor's own local script.
local function toughen(actor)
local stats = types.Actor.stats
for _, name in ipairs({ 'health', 'fatigue' }) do
local stat = stats.dynamic[name](actor)
stat.base = 5000
stat.current = 5000
end
stats.attributes.agility(actor).base = 100
stats.attributes.strength(actor).base = 60
types.NPC.stats.skills.block(actor).base = 100
types.NPC.stats.skills.shortblade(actor).base = 100
end
I.Combat.addOnHitHandler(function(attack)
local health = attack.damage and attack.damage.health or 0
hits.taken = hits.taken + 1
if attack.successful and health <= 0 then
hits.zero = hits.zero + 1
end
print(string.format('ASHLAR_COMBAT player hit successful=%s health=%.2f blockHeld=%s',
tostring(attack.successful), health, tostring(self.controls.block)))
end)
local function faceEnemy()
local delta = kit.enemy.position - self.position
local target = math.atan2(delta.x, delta.y)
local diff = util.normalizeAngle(target - self.rotation:getYaw())
self.controls.yawChange = util.clamp(diff, -0.1, 0.1)
end
local function setFatigueRatio(ratio)
local fatigue = types.Actor.stats.dynamic.fatigue(self)
fatigue.current = fatigue.base * ratio
end
-- Holds Use for `hold` seconds out of every `period`, so each press winds up and releases one attack.
local function pulseAttack(dt, hold, period)
swing = swing + dt
self.controls.use = (swing % period < hold) and 1 or 0
end
local function enterPhase(p)
phase = p
swing = 0
log('player phase ' .. p.name)
if p.name == 'parry' then
-- Drop the shield; holding Block with only the blade equipped is a parry.
local eq = Actor.getEquipment(self)
eq[Actor.EQUIPMENT_SLOT.CarriedLeft] = nil
Actor.setEquipment(self, eq)
elseif p.name == 'ignorestagger' then
kit.enemy:sendEvent('AshlarIgnoreStagger', true)
elseif p.name == 'tired' then
kit.enemy:sendEvent('AshlarIgnoreStagger', false)
elseif p.name == 'done' then
self.controls.use = 0
self.controls.block = false
setFatigueRatio(1)
log(string.format('player done hitsTaken=%d zeroDamage=%d enemyDistance=%.0f', hits.taken, hits.zero,
(kit.enemy.position - self.position):length()))
end
end
return {
eventHandlers = {
AshlarCombatStart = function(data)
kit = data
toughen(self)
local eq = Actor.getEquipment(self)
eq[Actor.EQUIPMENT_SLOT.CarriedLeft] = data.shield
eq[Actor.EQUIPMENT_SLOT.CarriedRight] = data.blade
Actor.setEquipment(self, eq)
I.Controls.overrideMovementControls(true)
I.Controls.overrideCombatControls(true)
phase, t = { name = 'draw', at = 0 }, 0
end,
},
engineHandlers = {
onFrame = function(dt)
if not kit or phase.name == 'done' then
return
end
t = t + dt
faceEnemy()
self.controls.movement = 0
self.controls.sideMovement = 0
local nextPhase = PHASES[1]
for _, p in ipairs(PHASES) do
if t >= p.at then
nextPhase = p
end
end
if t >= nextPhase.at and nextPhase ~= phase then
enterPhase(nextPhase)
if phase.name == 'done' then
return
end
end
if phase.fatigue then
-- Hold fatigue where the phase wants it; attacks and regeneration would move it.
setFatigueRatio(phase.fatigue)
end
local name = phase.name
if name == 'draw' then
Actor.setStance(self, Actor.STANCE.Weapon)
elseif name == 'block' or name == 'parry' then
self.controls.block = true
self.controls.use = 0
elseif name == 'attack' or name == 'ignorestagger' then
self.controls.block = false
pulseAttack(dt, 0.6, 1.4)
elseif name == 'tired' then
pulseAttack(dt, 0.6, 1.4)
elseif name == 'capped' then
-- A long hold so the wind-up reaches full strength before release.
pulseAttack(dt, 1.5, 2.2)
end
end,
},
}