feat: wire backstory generation into NPC spawn flow

Trigger fire-and-forget backstory generation whenever an NPC spawns,
both during initial spawn and via player spawn-npc requests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-03-08 16:52:13 +00:00
parent aa3f5651dd
commit 8c793578ae
2 changed files with 9 additions and 2 deletions
+7 -1
View File
@@ -11,6 +11,7 @@ import { relationshipSystem } from '../systems/relationshipSystem.js';
import { createBondRegistry } from '../systems/bondRegistry.js';
import { spawnNPC } from './spawner.js';
import { createLlmService, type LlmService } from '../llm/llmService.js';
import { generateBackstory } from '../llm/backstoryGenerator.js';
export class GameLoop {
readonly world: World;
@@ -47,9 +48,14 @@ export class GameLoop {
}
}
generateNpcBackstory(entityId: number): void {
generateBackstory(this.world, entityId, this.llmService);
}
private spawnInitialNPCs(count: number): void {
for (let i = 0; i < count; i++) {
spawnNPC(this.world, this.map);
const entity = spawnNPC(this.world, this.map);
this.generateNpcBackstory(entity);
}
}
+2 -1
View File
@@ -70,7 +70,8 @@ export class SocketServer {
const target = map.findNearestWalkable(data.x, data.y, 3)
?? map.getRandomWalkable();
spawnNPC(world, map, target);
const npcEntity = spawnNPC(world, map, target);
this.gameLoop.generateNpcBackstory(npcEntity);
});
// Handle superlatives subscription