Add first player hit lifecycle regression

This commit is contained in:
Admin 2026-09-18 00:40:37 +00:00
parent 39c13fbeb4
commit dffba721e1

View File

@ -6,6 +6,7 @@ import {
PLAYER_HIT_COOLDOWN_MS,
PLAYER_MAX_HULL,
normalizePlayerDamage,
processQueuedPlayerHits,
reducePlayerHitQueue,
} from '../src/game-logic.js';
@ -24,6 +25,43 @@ test('first pirate hit removes exactly the default damage and does not end the g
assert.equal(result.gameOver, false);
});
test('actual queued first player hit destroys the projectile, applies 6 damage, and leaves gameplay active', () => {
const shot = {
active: true,
destroyed: false,
destroy() {
this.destroyed = true;
this.active = false;
},
};
const firstFrame = processQueuedPlayerHits({
hull: PLAYER_MAX_HULL,
lastHitAt: -Infinity,
now: 1000,
hits: [{ shot, damage: DEFAULT_PIRATE_SHOT_DAMAGE }],
});
assert.equal(shot.destroyed, true);
assert.equal(shot.active, false);
assert.equal(firstFrame.hull, 94);
assert.equal(firstFrame.appliedHits, 1);
assert.equal(firstFrame.ignoredHits, 0);
assert.equal(firstFrame.gameOver, false);
const followingFrame = processQueuedPlayerHits({
hull: firstFrame.hull,
lastHitAt: firstFrame.lastHitAt,
now: 1016,
hits: [],
});
assert.equal(followingFrame.hull, 94);
assert.equal(followingFrame.gameOver, false);
assert.equal(followingFrame.appliedHits, 0);
});
test('three cannonballs arriving in one broadside only apply one hull hit', () => {
const result = reducePlayerHitQueue({
hull: 100,