Add NPC interaction system with memory and quest generation

- Introduced a new NPC system with dynamic NPCs and conversation handling.
- Implemented NPC memory using SQLite to log conversations and manage relationships.
- Added commands for talking to NPCs, listing available NPCs, and generating quests.
- Updated database schema to support NPC conversations and relationships.
- Refactored code structure to separate concerns into cogs and handlers.
This commit is contained in:
2025-09-30 14:12:22 +02:00
parent c8980f785f
commit 7e76353c6a
24 changed files with 7468 additions and 14 deletions
+46
View File
@@ -0,0 +1,46 @@
import sqlite3
class NPCMemory:
def __init__(self):
self.conn = sqlite3.connect('npc_memory.db')
self.create_tables()
def create_tables(self):
self.conn.execute('''
CREATE TABLE IF NOT EXISTS npc_conversations (
npc_id TEXT,
player_id TEXT,
message TEXT,
response TEXT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
)
''')
self.conn.execute('''
CREATE TABLE IF NOT EXISTS npc_relationships (
npc_id TEXT,
player_id TEXT,
affinity INTEGER DEFAULT 0,
last_interaction DATETIME
)
''')
self.conn.commit()
def log_conversation(self, npc_id, player_id, message, response):
self.conn.execute(
'INSERT INTO npc_conversations (npc_id, player_id, message, response) VALUES (?, ?, ?, ?)',
(npc_id, player_id, message, response)
)
self.conn.commit()
def update_affinity(self, npc_id, player_id, delta):
cur = self.conn.cursor()
cur.execute('SELECT affinity FROM npc_relationships WHERE npc_id=? AND player_id=?', (npc_id, player_id))
row = cur.fetchone()
if row:
new_affinity = row[0] + delta
cur.execute('UPDATE npc_relationships SET affinity=?, last_interaction=CURRENT_TIMESTAMP WHERE npc_id=? AND player_id=?',
(new_affinity, npc_id, player_id))
else:
cur.execute('INSERT INTO npc_relationships (npc_id, player_id, affinity, last_interaction) VALUES (?, ?, ?, CURRENT_TIMESTAMP)',
(npc_id, player_id, delta))
self.conn.commit()