This is a planned feature for Phase 2 of the Flower Engine roadmap. Implementation details may change during development.
Overview
The stateful NPC system will enable persistent characters and factions that remember interactions across sessions. NPCs will maintain consistent personalities, relationships, and standing values that dynamically influence narrative outcomes and AI behavior.Core Features
Relationship Tracking
A comprehensive system for managing how NPCs and factions perceive the player:- Numerical Standing: Integer values representing relationship quality (-100 to +100)
- Multiple Dimensions: Track trust, respect, fear, affection separately
- Historical Context: Record of significant interactions that shaped the relationship
- Dynamic Adjustment: Standing changes based on player actions and dialogue choices
- Threshold Triggers: Special events or dialogue options unlock at certain standing levels
Persistent NPCs
NPCs will maintain continuity across different sessions and story arcs:- Registration System: Formally register recurring NPCs with unique identifiers
- Core Attributes: Name, description, personality traits, motivations
- Memory Retention: NPCs remember past conversations and events
- State Tracking: Current location, emotional state, ongoing goals
- Consistency Enforcement: AI must respect established NPC characteristics
Dynamic Standing Injection
Relevant relationship data automatically enhances AI context:- Scene Analysis: Detect which NPCs are present in the current scene
- Context Injection: Insert relationship data into system prompt
- Behavioral Modulation: AI adapts NPC dialogue based on standing
- Faction Influence: Group affiliations affect individual NPC behavior
- Conflict Resolution: Handle competing loyalties and faction tensions
Data Structure
NPC Registry
Core information stored for each registered NPC:Relationship Values
Multi-dimensional relationship tracking:Faction System
Group-level relationships that influence member NPCs:Database Schema
NPCs Table
Relationships Table
Factions Table
Interaction History Table
Implementation Details
Registration Command
Players or the system can register NPCs:- NPC appears in 3+ consecutive messages
- NPC is named by the player
- AI indicates NPC is important (via hidden flag)
Standing Calculation
Total standing is calculated as:| Total Standing | Status | Description |
|---|---|---|
| 80-100 | Devoted | Unwavering loyalty and support |
| 60-79 | Friendly | Positive relationship, willing to help |
| 30-59 | Neutral-Positive | Cordial but cautious |
| 0-29 | Neutral | Indifferent, transactional |
| -29 to -1 | Neutral-Negative | Distrustful, unhelpful |
| -59 to -30 | Hostile | Actively oppositional |
| -100 to -60 | Enemy | Seeks to harm or sabotage |
Context Injection
When an NPC appears in a scene, inject into system prompt:Standing Modification
Actions automatically adjust standing: Positive Actions:- Complete a quest for the NPC: +10-25
- Give a gift: +5-15 (based on value/thoughtfulness)
- Defend from threat: +15-30
- Share valuable information: +5-10
- Support their goals: +10-20
- Betray trust: -30-50
- Steal from them: -20-40
- Harm their allies: -15-25
- Insult or threaten: -10-20
- Fail a promised task: -10-15
Use Cases
Merchant Reputation
Build standing with a shopkeeper over time:- First Meeting (0): Standard prices, limited inventory
- Regular Customer (30): 5% discount, occasional rumors shared
- Trusted Patron (60): 15% discount, access to rare items, side quests
- Close Friend (85): Special items at cost, insider information, personal favors
Faction Conflicts
Navigate competing loyalties:- High standing with City Guard (+70)
- Low standing with Thieves Guild (-40)
- Helping thieves lowers guard standing
- Betraying thieves risks revenge attack
- Must balance relationships or commit to one side
Romantic Relationships
Slow-burn relationship progression:- Strangers (0): Formal, distant interactions
- Acquaintances (25): Small talk, basic kindness
- Friends (50): Personal conversations, trust building
- Close Friends (75): Deep discussions, emotional support
- Romantic Interest (90+): Special dialogue options, relationship events
NPC Memory Callbacks
NPCs reference past interactions:Technical Architecture
Backend Components
New File:engine/npcs.py
register_npc(): Add NPC to persistent registryupdate_standing(): Modify relationship valuesget_npc_context(): Generate context injection for AIcalculate_faction_impact(): Apply group standing to individual NPCsdetect_scene_npcs(): Identify NPCs mentioned in current context
engine/factions.py
register_faction(): Create new factionupdate_faction_standing(): Adjust player reputationget_faction_members(): List NPCs affiliated with factioncalculate_faction_conflicts(): Determine relationship consequences
WebSocket Events
New events for NPC system:Commands
Player Commands:AI Integration
System Prompt Enhancements
Add to AI instructions:Standing Triggers
AI can trigger standing changes via special syntax:Configuration
Settings inconfig.yaml:
Future Enhancements
Potential expansions beyond Phase 2:- NPC Schedules: Time-based location and availability
- NPC-to-NPC Relationships: Complex social webs
- Reputation Propagation: NPCs hear about player actions from others
- Dynamic Events: NPCs initiate quests based on relationship level
- Emotional States: Mood tracking that affects interactions
- NPC Portraits: Visual representation in TUI
- Conversation History: Full transcript of past dialogues
- Gift Preferences: Learn what individual NPCs value
Design Philosophy
The stateful NPC system is designed to:- Create Continuity: Make the world feel alive and responsive
- Reward Investment: Relationship building yields tangible benefits
- Enable Consequences: Actions have lasting impact on social standing
- Support Roleplay: Provide hooks for character-driven storytelling
- Maintain Complexity: Allow for nuanced, multi-dimensional relationships