NPC Schedules, Routines, and Contextual Behavior
What This System Is
NPC routines provide an authoritative layer above the local NPC AI schedule. The existing AI package remains the movement fallback, while assets/gameplay/npc_routine_catalog.json controls weekly activities, cross-scene destinations, contextual interaction, interruptions, and persistent routine state.
How Authors Use It
Each NPC can own one routine containing:
- named anchors with scene, tile, facing, and optional navigation-region references;
- daily or weekly activity windows, including windows that cross midnight;
- explicit activity priorities for deterministic overlap resolution;
- quest/world-state conditions and required or forbidden scene phases;
- dialogue topic, NPC service, animation, emote, and interaction overrides;
- navigation failure behavior;
- player, party, instance, or global persistence scope.
Activities include idle, travel, work, patrol, guard, sleep, socialize, shop, service, hide, craft, and quest behaviors.
Rules And Invariants
The resolver selects eligible activities from weekday, world minute, shared gameplay conditions, active scene phases, and an optional interruption type. Highest priority wins, with stable ID ordering as a deterministic final tie-breaker. Authoring validation rejects same-priority time overlaps so designers must state the intended winner.
Contextual activities can activate for player interaction, combat, quests, world events, or emergencies. They use the same activity contract as scheduled work, allowing an invasion to relocate an NPC, change animation and dialogue, and disable services in one decision.
Navigation recovery and persistence
Every activity defines a fallback: resume the previous activity, return home, hold position, skip the activity, or despawn. The recovery projection includes the resolved home destination when required.
The runtime registry stores complete decisions by scope key and revision. Commits replace the NPC's routine state atomically and reject stale revisions, making the state suitable for durable server snapshots.
Validation And Debugging
Open Scene → Detailed Scene Tools → Characters And Dialogue → NPC Routine Timeline. Select a weekday and world minute to inspect each relevant NPC's activity, destination scene and anchor, interaction state, contextual dialogue/service, navigation fallback, and priority. The timeline also consumes candidate scene phases selected in the Dynamic Scene Phases preview.
Server startup requires the routine catalog and validates NPC IDs, dialogue sequence conventions, service event handles, scene phases, anchors, conditions, activity overlaps, and time ranges. The authoring dependency graph tracks routine dependencies on NPCs, dialogue, services, phases, and every destination scene.
Examples
The shipped examples give the blacksmith a forge/tavern/home routine with invasion and rebuilding overrides, while the Lantern Guide patrols roads, watches the cave, supports festivals, and warns villagers during attacks.