feat: update thought system to recognize sleeping NPCs

Skip sleeping NPCs in the thought generation loop and update
describeState to output 'sleeping' when currentGoal is 'sleep'.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-03-09 17:59:03 +00:00
parent 65ee23c5be
commit b67d491b9d
+8 -3
View File
@@ -43,12 +43,15 @@ export function createThoughtSystem(
for (const entityId of npcs) {
if (!followedEntityIds.has(entityId)) continue;
// Skip sleeping NPCs - they don't think
const brain = world.getComponent<any>(entityId, 'npcBrain');
if (brain?.currentGoal === 'sleep') continue;
const cooldownUntil = cooldowns.get(entityId) ?? 0;
if (tick < cooldownUntil) continue;
const needs = world.getComponent<Needs>(entityId, 'needs');
const social = world.getComponent<SocialState>(entityId, 'socialState');
const brain = world.getComponent<any>(entityId, 'npcBrain');
const context = determineTrigger(needs, social, brain, tick);
eligible.push({ entityId, context });
@@ -139,12 +142,14 @@ function determineTrigger(
function describeState(needs: Needs | undefined, brain: any): string {
const parts: string[] = [];
if (needs) {
if (brain?.currentGoal === 'sleep') {
parts.push('sleeping');
} else if (needs) {
if (needs.hunger < 30) parts.push('hungry');
if (needs.energy < 30) parts.push('tired');
if (parts.length === 0) parts.push('content');
}
if (brain?.currentGoal) {
if (brain?.currentGoal && brain.currentGoal !== 'sleep') {
parts.push(brain.currentGoal === 'wander' ? 'wandering' : brain.currentGoal);
}
return parts.join(', ') || 'idle';