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
+50
View File
@@ -0,0 +1,50 @@
import json
import random
NPC_DATABASE = {
"barkeep_boris": {
"personality": "Jovial and gossipy, knows everyone's business",
"backstory": "Retired adventurer who settled down after losing party to dragon",
"quirks": ["Offers free drinks to good storytellers", "Hates elves"]
},
"mad_wizard": {
"personality": "Eccentric and forgetful, brilliant but scattered",
"backstory": "Expelled from wizard college for 'creative' spellcasting",
"quirks": ["Speaks to imaginary familiar", "Offers dangerous experimental potions"]
}
}
class DynamicNPC:
def __init__(self, name, data):
self.name = name
self.personality = data["personality"]
self.backstory = data["backstory"]
self.quirks = data["quirks"]
class NPCHandler:
def __init__(self, memory):
self.memory = memory
self.npcs = {name: DynamicNPC(name, data) for name, data in NPC_DATABASE.items()}
def chat_with_npc(self, npc_name, message, player_context):
npc = self.npcs.get(npc_name)
if not npc:
return "That NPC doesn't exist."
# Simple response logic (replace with LLM call as needed)
response = f"{npc.name} ({npc.personality}): I heard you say '{message}'."
self.memory.log_conversation(npc_name, player_context['id'], message, response)
self.memory.update_affinity(npc_name, player_context['id'], 1)
return response
def generate_quest(self, npc_name, player_level):
npc = self.npcs.get(npc_name)
if not npc:
return None
# Replace this with LLM call if available
quest = {
"title": f"{npc.name}'s Request",
"description": f"Help {npc.name} with a task suitable for level {player_level}.",
"reward": f"{random.randint(10, 100)} coins",
"difficulty": random.choice(["easy", "medium", "hard"])
}
return quest