test: add failing tests for daytime nap wake logic
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -388,6 +388,84 @@ describe('npcBrainSystem', () => {
|
||||
const brain = world.getComponent<NPCBrain>(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<NPCBrain>(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<NPCBrain>(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<NPCBrain>(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<NPCBrain>(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<NPCBrain>(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<NPCBrain>(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<NPCBrain>(e, 'npcBrain')!;
|
||||
brain.currentGoal = 'sleep';
|
||||
npcBrainSystem(world, map, 0.1, undefined, rc);
|
||||
expect(brain.currentGoal).toBe('sleep');
|
||||
});
|
||||
});
|
||||
|
||||
describe('movementSystem', () => {
|
||||
|
||||
Reference in New Issue
Block a user