diff --git a/server/src/game/GameLoop.ts b/server/src/game/GameLoop.ts index 2fe9393..ebbf084 100644 --- a/server/src/game/GameLoop.ts +++ b/server/src/game/GameLoop.ts @@ -4,6 +4,7 @@ import { GameMap } from '../map/GameMap.js'; import { needsDecaySystem } from '../systems/needsDecaySystem.js'; import { npcBrainSystem } from '../systems/npcBrainSystem.js'; import { movementSystem } from '../systems/movementSystem.js'; +import { socialSystem } from '../systems/socialSystem.js'; import { spawnNPC } from './spawner.js'; export class GameLoop { @@ -62,6 +63,7 @@ export class GameLoop { // Run systems in order needsDecaySystem(this.world); npcBrainSystem(this.world, this.map); + socialSystem(this.world); movementSystem(this.world); // Broadcast state periodically diff --git a/server/src/game/spawner.ts b/server/src/game/spawner.ts index 94c2c3e..06cbb6a 100644 --- a/server/src/game/spawner.ts +++ b/server/src/game/spawner.ts @@ -2,7 +2,7 @@ import type { World } from '../ecs/World.js'; import type { GameMap } from '../map/GameMap.js'; import { generateRandomAppearance } from '../spawner/appearanceGenerator.js'; import { generateName } from '../spawner/nameGenerator.js'; -import type { EntityId, Position, Needs, Movement, NPCBrain, Appearance } from '@dflike/shared'; +import type { EntityId, Position, Needs, Movement, NPCBrain, Appearance, SocialState } from '@dflike/shared'; export function spawnNPC(world: World, map: GameMap): EntityId { const entity = world.createEntity(); @@ -26,6 +26,14 @@ export function spawnNPC(world: World, map: GameMap): EntityId { }); world.addComponent(entity, 'appearance', generateRandomAppearance()); world.addComponent(entity, 'name', generateName()); + world.addComponent(entity, 'socialState', { + phase: 'none', + partnerId: null, + phaseTimer: 0, + outcome: null, + globalCooldown: 0, + pairCooldowns: new Map(), + }); return entity; } diff --git a/server/src/network/stateSerializer.ts b/server/src/network/stateSerializer.ts index 7e2def3..d1b600a 100644 --- a/server/src/network/stateSerializer.ts +++ b/server/src/network/stateSerializer.ts @@ -1,12 +1,13 @@ import type { EntityState, WorldState, StateUpdate, - Position, Movement, Appearance, Needs, NPCBrain, PlayerControlled, + Position, Movement, Appearance, Needs, NPCBrain, PlayerControlled, SocialState, } from '@dflike/shared'; import { TILE_SIZE } from '@dflike/shared'; import type { World } from '../ecs/World.js'; import type { GameMap } from '../map/GameMap.js'; export function serializeEntity(world: World, entityId: number): EntityState { + const socialState = world.getComponent(entityId, 'socialState'); return { id: entityId, position: world.getComponent(entityId, 'position')!, @@ -16,6 +17,11 @@ export function serializeEntity(world: World, entityId: number): EntityState { npcBrain: world.getComponent(entityId, 'npcBrain'), playerControlled: world.getComponent(entityId, 'playerControlled'), name: world.getComponent(entityId, 'name'), + socialState: socialState ? { + phase: socialState.phase, + partnerId: socialState.partnerId, + outcome: socialState.outcome, + } : undefined, }; }