diff --git a/server/src/game/GameLoop.ts b/server/src/game/GameLoop.ts index 86aa7e8..5c5576f 100644 --- a/server/src/game/GameLoop.ts +++ b/server/src/game/GameLoop.ts @@ -19,7 +19,10 @@ import { pickupSystem } from '../systems/pickupSystem.js'; import { RecipeRegistry } from '../industry/recipeRegistry.js'; import { spawnNPC } from './spawner.js'; import { createLlmService, type LlmService } from '../llm/llmService.js'; -import { generateBackstory } from '../llm/backstoryGenerator.js'; +import { generateBackstoryAndDesires } from '../llm/backstoryGenerator.js'; +import { desireFulfillmentSystem } from '../systems/desireFulfillmentSystem.js'; +import { createDesireGeneratorSystem } from '../systems/desireGeneratorSystem.js'; +import type { DesireGeneratorSystem } from '../systems/desireGeneratorSystem.js'; import { createNarrationService, type NarrationService } from '../llm/narrationService.js'; import { narrationEmitter } from '../systems/narrationEmitter.js'; import type { EntityId, InventionSummary, Position } from '@dflike/shared'; @@ -44,6 +47,7 @@ export class GameLoop { readonly eventMemoryService: EventMemoryService; readonly thoughtSystem: ThoughtSystem; readonly inventionSystem: InventionSystem; + private desireGeneratorSystem: DesireGeneratorSystem; public followedEntityIds: Set = new Set(); public onInventionCreated: ((summary: InventionSummary) => void) | null = null; public onStockpileEvent: ((entry: StockpileLogEntry) => void) | null = null; @@ -66,6 +70,7 @@ export class GameLoop { this.eventMemoryService, (summary) => this.onInventionCreated?.(summary), ); + this.desireGeneratorSystem = createDesireGeneratorSystem(this.llmService); this.saveManager = new SaveManager(options?.savePath ?? 'saves/default.db'); @@ -218,7 +223,7 @@ export class GameLoop { } generateNpcBackstory(entityId: number): void { - generateBackstory(this.world, entityId, this.llmService); + generateBackstoryAndDesires(this.world, entityId, this.llmService, this.tick); } private spawnInitialNPCs(count: number): void { @@ -274,6 +279,8 @@ export class GameLoop { socialSystem(this.world, this.eventMemoryService); narrationEmitter(this.world, this.narrationService, this.followedEntityIds, this.eventMemoryService); relationshipSystem(this.world, this.eventMemoryService); + desireFulfillmentSystem(this.world, this.tick); + this.desireGeneratorSystem.update(this.world, this.tick); industrySystem(this.world, this.map); pickupSystem(this.world, this.tick, (entry) => this.onStockpileEvent?.(entry)); gatheringSystem(this.world, this.map); diff --git a/server/src/game/spawner.ts b/server/src/game/spawner.ts index 85b8ddd..fa29567 100644 --- a/server/src/game/spawner.ts +++ b/server/src/game/spawner.ts @@ -3,7 +3,7 @@ import type { GameMap } from '../map/GameMap.js'; import { generateRandomAppearance } from '../spawner/appearanceGenerator.js'; import { generateName } from '../spawner/nameGenerator.js'; import { generateStats } from '../spawner/statGenerator.js'; -import type { EntityId, Position, Needs, Movement, NPCBrain, Appearance, SocialState, Stats, StatModifiers, Relationships } from '@dflike/shared'; +import type { EntityId, Position, Needs, Movement, NPCBrain, Appearance, SocialState, Stats, StatModifiers, Relationships, Desire } from '@dflike/shared'; import type { EventMemoryService } from '../llm/eventMemoryService.js'; export function spawnNPC(world: World, map: GameMap, positionHint?: Position, eventMemoryService?: EventMemoryService): EntityId { @@ -48,6 +48,7 @@ export function spawnNPC(world: World, map: GameMap, positionHint?: Position, ev world.addComponent(entity, 'relationships', new Map()); world.addComponent(entity, 'backstory', ''); world.addComponent>(entity, 'inventory', new Map()); + world.addComponent(entity, 'desires', []); eventMemoryService?.record(entity, { type: 'spawned',