From e7b74c827a06f23850f6cdc7b707c6ebe4140f8e Mon Sep 17 00:00:00 2001 From: Ethan J Lewis Date: Tue, 12 May 2026 20:31:50 -0500 Subject: [PATCH] fix(engine): burn lamp one segment per wait --- src/engine/dispatcher.test.ts | 22 ++++++++++++++++------ src/engine/dispatcher.ts | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/engine/dispatcher.test.ts b/src/engine/dispatcher.test.ts index ef5d706..82c0521 100644 --- a/src/engine/dispatcher.test.ts +++ b/src/engine/dispatcher.test.ts @@ -501,22 +501,32 @@ describe('light/extinguish verbs (implicit lighter)', () => { expect(texts).toContain('The book is empty.') }) - it('burns two segments on wait and extinguishes on the third wait', () => { + it('burns one segment on each wait and extinguishes when the last segment expires', () => { const world = w() let state = initialStateFor(world) state = { ...state, inventory: [{ id: 'lamp', state: { lit: true, burn: 6 } }] } const first = dispatch(state, { kind: 'verb-only', verb: 'wait' }, world) - expect(first.state.inventory.find((i) => i.id === 'lamp')?.state['burn']).toBe(4) + expect(first.state.inventory.find((i) => i.id === 'lamp')?.state['burn']).toBe(5) expect(first.state.inventory.find((i) => i.id === 'lamp')?.state['lit']).toBe(true) const second = dispatch(first.state, { kind: 'verb-only', verb: 'wait' }, world) - expect(second.state.inventory.find((i) => i.id === 'lamp')?.state['burn']).toBe(2) + expect(second.state.inventory.find((i) => i.id === 'lamp')?.state['burn']).toBe(4) const third = dispatch(second.state, { kind: 'verb-only', verb: 'wait' }, world) - expect(third.state.inventory.find((i) => i.id === 'lamp')?.state['burn']).toBe(0) - expect(third.state.inventory.find((i) => i.id === 'lamp')?.state['lit']).toBe(false) - expect(third.appended.map((l) => l.text)).toContain('The flame dies.') + expect(third.state.inventory.find((i) => i.id === 'lamp')?.state['burn']).toBe(3) + + const fourth = dispatch(third.state, { kind: 'verb-only', verb: 'wait' }, world) + expect(fourth.state.inventory.find((i) => i.id === 'lamp')?.state['burn']).toBe(2) + + const fifth = dispatch(fourth.state, { kind: 'verb-only', verb: 'wait' }, world) + expect(fifth.state.inventory.find((i) => i.id === 'lamp')?.state['burn']).toBe(1) + expect(fifth.state.inventory.find((i) => i.id === 'lamp')?.state['lit']).toBe(true) + + const sixth = dispatch(fifth.state, { kind: 'verb-only', verb: 'wait' }, world) + expect(sixth.state.inventory.find((i) => i.id === 'lamp')?.state['burn']).toBe(0) + expect(sixth.state.inventory.find((i) => i.id === 'lamp')?.state['lit']).toBe(false) + expect(sixth.appended.map((l) => l.text)).toContain('The flame dies.') }) it('burns one segment on movement', () => { diff --git a/src/engine/dispatcher.ts b/src/engine/dispatcher.ts index 2043dd9..304d36b 100644 --- a/src/engine/dispatcher.ts +++ b/src/engine/dispatcher.ts @@ -421,7 +421,7 @@ function passOutFromDrunk(state: GameState, world: World, preface: string): Disp } function handleWait(state: GameState, world: World): DispatchResult { - const lightTick = advanceLightState(state, 2, world) + const lightTick = advanceLightState(state, 1, world) return narrate(lightTick.state, [ { kind: 'narration', text: 'Time passes.' }, ...lightTick.lines,