From 0fc186b4f3e72c2234a9aa088dcaf01e70cb9f55 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 7 Mar 2026 14:27:24 +0000 Subject: [PATCH] feat: serialize effective stats in entity state broadcast Co-Authored-By: Claude Opus 4.6 --- server/src/network/stateSerializer.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/server/src/network/stateSerializer.ts b/server/src/network/stateSerializer.ts index d1b600a..1052207 100644 --- a/server/src/network/stateSerializer.ts +++ b/server/src/network/stateSerializer.ts @@ -1,13 +1,27 @@ import type { EntityState, WorldState, StateUpdate, - Position, Movement, Appearance, Needs, NPCBrain, PlayerControlled, SocialState, + Position, Movement, Appearance, Needs, NPCBrain, PlayerControlled, SocialState, Stats, } from '@dflike/shared'; 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'; export function serializeEntity(world: World, entityId: number): EntityState { const socialState = world.getComponent(entityId, 'socialState'); + const statsComponent = world.getComponent(entityId, 'stats'); + const stats = statsComponent ? { + strength: getEffectiveStat(world, entityId, 'strength'), + dexterity: getEffectiveStat(world, entityId, 'dexterity'), + constitution: getEffectiveStat(world, entityId, 'constitution'), + intelligence: getEffectiveStat(world, entityId, 'intelligence'), + perception: getEffectiveStat(world, entityId, 'perception'), + sociability: getEffectiveStat(world, entityId, 'sociability'), + courage: getEffectiveStat(world, entityId, 'courage'), + curiosity: getEffectiveStat(world, entityId, 'curiosity'), + empathy: getEffectiveStat(world, entityId, 'empathy'), + temperament: getEffectiveStat(world, entityId, 'temperament'), + } : undefined; return { id: entityId, position: world.getComponent(entityId, 'position')!, @@ -22,6 +36,7 @@ export function serializeEntity(world: World, entityId: number): EntityState { partnerId: socialState.partnerId, outcome: socialState.outcome, } : undefined, + stats, }; }