From 8c793578aed1d6bf0b53849f596358cee78bf2ee Mon Sep 17 00:00:00 2001 From: root Date: Sun, 8 Mar 2026 16:52:13 +0000 Subject: [PATCH] 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 --- server/src/game/GameLoop.ts | 8 +++++++- server/src/network/SocketServer.ts | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/server/src/game/GameLoop.ts b/server/src/game/GameLoop.ts index 1f7d7f1..53627cc 100644 --- a/server/src/game/GameLoop.ts +++ b/server/src/game/GameLoop.ts @@ -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); } } diff --git a/server/src/network/SocketServer.ts b/server/src/network/SocketServer.ts index ffc39eb..96843bf 100644 --- a/server/src/network/SocketServer.ts +++ b/server/src/network/SocketServer.ts @@ -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