feat: wire relationship system into spawner, game loop, and serializer
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import { npcBrainSystem } from '../systems/npcBrainSystem.js';
|
||||
import { movementSystem } from '../systems/movementSystem.js';
|
||||
import { socialSystem } from '../systems/socialSystem.js';
|
||||
import { statModifierSystem } from '../systems/statModifierSystem.js';
|
||||
import { relationshipSystem } from '../systems/relationshipSystem.js';
|
||||
import { spawnNPC } from './spawner.js';
|
||||
|
||||
export class GameLoop {
|
||||
@@ -66,6 +67,7 @@ export class GameLoop {
|
||||
needsDecaySystem(this.world);
|
||||
npcBrainSystem(this.world, this.map);
|
||||
socialSystem(this.world);
|
||||
relationshipSystem(this.world);
|
||||
movementSystem(this.world);
|
||||
|
||||
// Broadcast state periodically
|
||||
|
||||
@@ -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 } from '@dflike/shared';
|
||||
import type { EntityId, Position, Needs, Movement, NPCBrain, Appearance, SocialState, Stats, StatModifiers, Relationships } from '@dflike/shared';
|
||||
|
||||
export function spawnNPC(world: World, map: GameMap, positionHint?: Position): EntityId {
|
||||
const entity = world.createEntity();
|
||||
@@ -40,6 +40,7 @@ export function spawnNPC(world: World, map: GameMap, positionHint?: Position): E
|
||||
});
|
||||
world.addComponent<Stats>(entity, 'stats', generateStats());
|
||||
world.addComponent<StatModifiers>(entity, 'statModifiers', { modifiers: [] });
|
||||
world.addComponent<Relationships>(entity, 'relationships', new Map());
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import type {
|
||||
EntityState, WorldState, StateUpdate,
|
||||
Position, Movement, Appearance, Needs, NPCBrain, PlayerControlled, SocialState, Stats,
|
||||
Position, Movement, Appearance, Needs, NPCBrain, PlayerControlled, SocialState, Stats, Relationships,
|
||||
} 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';
|
||||
import { classify } from '../systems/relationshipHelpers.js';
|
||||
|
||||
export function serializeEntity(world: World, entityId: number): EntityState {
|
||||
const socialState = world.getComponent<SocialState>(entityId, 'socialState');
|
||||
@@ -22,6 +23,16 @@ export function serializeEntity(world: World, entityId: number): EntityState {
|
||||
empathy: getEffectiveStat(world, entityId, 'empathy'),
|
||||
temperament: getEffectiveStat(world, entityId, 'temperament'),
|
||||
} : undefined;
|
||||
const relationshipsComponent = world.getComponent<Relationships>(entityId, 'relationships');
|
||||
const relationships = relationshipsComponent && relationshipsComponent.size > 0
|
||||
? [...relationshipsComponent.entries()].map(([otherId, rel]) => ({
|
||||
entityId: otherId,
|
||||
name: world.getComponent<string>(otherId, 'name') ?? `NPC #${otherId}`,
|
||||
value: Math.round(rel.value * 10) / 10,
|
||||
classification: classify(rel.value),
|
||||
status: rel.status,
|
||||
}))
|
||||
: undefined;
|
||||
return {
|
||||
id: entityId,
|
||||
position: world.getComponent<Position>(entityId, 'position')!,
|
||||
@@ -37,6 +48,7 @@ export function serializeEntity(world: World, entityId: number): EntityState {
|
||||
outcome: socialState.outcome,
|
||||
} : undefined,
|
||||
stats,
|
||||
relationships,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user