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:
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user