diff --git a/server/src/network/stateSerializer.ts b/server/src/network/stateSerializer.ts index efe0cd8..191535b 100644 --- a/server/src/network/stateSerializer.ts +++ b/server/src/network/stateSerializer.ts @@ -6,7 +6,9 @@ import { TILE_SIZE } from '@dflike/shared'; import type { World } from '../ecs/World.js'; import type { GameMap } from '../map/GameMap.js'; import { getEffectiveStat } from '../systems/statHelpers.js'; -import { classify } from '../systems/relationshipHelpers.js'; +import { getEffectiveClassification } from '../systems/relationshipHelpers.js'; +import type { BondRegistry } from '../systems/bondRegistry.js'; +import { hasBond } from '../systems/bondRegistry.js'; export function serializeEntity(world: World, entityId: number): EntityState { const socialState = world.getComponent(entityId, 'socialState'); @@ -24,14 +26,29 @@ export function serializeEntity(world: World, entityId: number): EntityState { temperament: getEffectiveStat(world, entityId, 'temperament'), } : undefined; const relationshipsComponent = world.getComponent(entityId, 'relationships'); + const registry = world.getSingleton('bondRegistry'); const relationships = relationshipsComponent && relationshipsComponent.size > 0 - ? [...relationshipsComponent.entries()].map(([otherId, rel]) => ({ - entityId: otherId, - name: world.getComponent(otherId, 'name') ?? `NPC #${otherId}`, - value: Math.round(rel.value * 10) / 10, - classification: classify(rel.value), - status: rel.status, - })) + ? [...relationshipsComponent.entries()].map(([otherId, rel]) => { + const sociability = statsComponent ? getEffectiveStat(world, entityId, 'sociability') : 10; + const empathy = statsComponent ? getEffectiveStat(world, entityId, 'empathy') : 10; + const classification = getEffectiveClassification( + otherId, rel.value, relationshipsComponent, sociability, empathy, + registry, entityId, + ); + let bond: string | null = null; + if (registry) { + if (hasBond(registry, entityId, otherId, 'partner')) bond = 'partner'; + else if (hasBond(registry, entityId, otherId, 'partner', 'former')) bond = 'former_partner'; + } + return { + entityId: otherId, + name: world.getComponent(otherId, 'name') ?? `NPC #${otherId}`, + value: Math.round(rel.value * 10) / 10, + classification, + status: rel.status, + bond, + }; + }) : undefined; return { id: entityId,