feat: serialize effective stats in entity state broadcast

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-03-07 14:27:24 +00:00
parent c7b998dbd0
commit 0fc186b4f3
+16 -1
View File
@@ -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<SocialState>(entityId, 'socialState');
const statsComponent = world.getComponent<Stats>(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<Position>(entityId, 'position')!,
@@ -22,6 +36,7 @@ export function serializeEntity(world: World, entityId: number): EntityState {
partnerId: socialState.partnerId,
outcome: socialState.outcome,
} : undefined,
stats,
};
}