diff --git a/server/src/systems/__tests__/systems.test.ts b/server/src/systems/__tests__/systems.test.ts index 12ea214..9f04707 100644 --- a/server/src/systems/__tests__/systems.test.ts +++ b/server/src/systems/__tests__/systems.test.ts @@ -388,6 +388,84 @@ describe('npcBrainSystem', () => { const brain = world.getComponent(e, 'npcBrain')!; expect(brain.currentGoal).toBe('drink'); }); + + // Daytime nap tests + it('wakes from daytime nap at calculated energy target', () => { + const world = new World(); + const map = new GameMap(10, 10); + const e = createNPC(world, 5, 5, 80, 61); + addStats(world, e, { constitution: 10 }); + const brain = world.getComponent(e, 'npcBrain')!; + brain.currentGoal = 'sleep'; + npcBrainSystem(world, map, 0.5, undefined, rc); + expect(brain.currentGoal).not.toBe('sleep'); + }); + + it('stays asleep during daytime nap when energy below target', () => { + const world = new World(); + const map = new GameMap(10, 10); + const e = createNPC(world, 5, 5, 80, 55); + addStats(world, e, { constitution: 10 }); + const brain = world.getComponent(e, 'npcBrain')!; + brain.currentGoal = 'sleep'; + npcBrainSystem(world, map, 0.5, undefined, rc); + expect(brain.currentGoal).toBe('sleep'); + }); + + it('uses full sleep when nap target below voluntary threshold (near nightfall)', () => { + const world = new World(); + const map = new GameMap(10, 10); + const e = createNPC(world, 5, 5, 80, 70); + addStats(world, e, { constitution: 10 }); + const brain = world.getComponent(e, 'npcBrain')!; + brain.currentGoal = 'sleep'; + npcBrainSystem(world, map, 0.63, undefined, rc); + expect(brain.currentGoal).toBe('sleep'); + }); + + it('uses normal wake logic during nighttime sleep (nap does not apply)', () => { + const world = new World(); + const map = new GameMap(10, 10); + const e = createNPC(world, 5, 5, 80, 70); + addStats(world, e, { constitution: 10 }); + const brain = world.getComponent(e, 'npcBrain')!; + brain.currentGoal = 'sleep'; + npcBrainSystem(world, map, 0.8, undefined, rc); + expect(brain.currentGoal).toBe('sleep'); + }); + + it('high CON NPC has lower nap target (shorter nap)', () => { + const world = new World(); + const map = new GameMap(10, 10); + const e = createNPC(world, 5, 5, 80, 75); + addStats(world, e, { constitution: 14 }); + const brain = world.getComponent(e, 'npcBrain')!; + brain.currentGoal = 'sleep'; + npcBrainSystem(world, map, 0.4, undefined, rc); + expect(brain.currentGoal).not.toBe('sleep'); + }); + + it('low CON NPC has higher nap target (longer nap)', () => { + const world = new World(); + const map = new GameMap(10, 10); + const e = createNPC(world, 5, 5, 80, 75); + addStats(world, e, { constitution: 6 }); + const brain = world.getComponent(e, 'npcBrain')!; + brain.currentGoal = 'sleep'; + npcBrainSystem(world, map, 0.4, undefined, rc); + expect(brain.currentGoal).toBe('sleep'); + }); + + it('clamps nap target to 100 for early morning crashes', () => { + const world = new World(); + const map = new GameMap(10, 10); + const e = createNPC(world, 5, 5, 80, 99); + addStats(world, e, { constitution: 10 }); + const brain = world.getComponent(e, 'npcBrain')!; + brain.currentGoal = 'sleep'; + npcBrainSystem(world, map, 0.1, undefined, rc); + expect(brain.currentGoal).toBe('sleep'); + }); }); describe('movementSystem', () => {