brynnb / idlequest

A idle / incremental game based on the 1999 classic EverQuest
1 stars 0 forks source link

LLM-based questing system #20

Open brynnb opened 1 week ago

brynnb commented 1 week ago

I want to scrape a bunch of quests off the project1999 wiki, which is based on the old game EverQuest. The original questing structure for the game is actually LUA scripts, but instead of a strictly scripted interaction, I want to use an LLM for a more dynamic text based roleplay. So I need the LLM to stay sort of on script and not allow the user to convince them to give a quest reward when they haven't actually earned it. But structuring this all into a relational database format that integrates with an LLM is a bit complex.

1. Data Model

The main entities are:

Entity Tables

  1. Quests Table

    Field Data Type Description
    QuestID INT Primary Key
    Name VARCHAR Quest name
    Description TEXT Brief description of the quest
    StartNPCID INT NPC who gives the quest
    EndNPCID INT NPC who completes the quest
    MinimumLevel INT Minimum level required to start the quest
    Classes VARCHAR Classes that can undertake the quest
    RelatedZones VARCHAR Zones involved in the quest
  2. NPCs Table

    Field Data Type Description
    NPCID INT Primary Key
    Name VARCHAR NPC name
    Zone VARCHAR Zone where the NPC is located
    Location VARCHAR Coordinates or description
    Faction VARCHAR Faction alignment
    DialogueID INT Reference to initial dialogue
  3. Items Table

    Field Data Type Description
    ItemID INT Primary Key
    Name VARCHAR Item name
    Description TEXT Item description
    QuestID INT Associated quest
  4. Dialogue Table

    Field Data Type Description
    DialogueID INT Primary Key
    NPCID INT Reference to NPC
    Text TEXT Dialogue text
    ResponseType VARCHAR Type of response (greeting, question, answer, etc.)
    Conditions TEXT Any conditions required for this dialogue
  5. QuestSteps Table

    Field Data Type Description
    StepID INT Primary Key
    QuestID INT Reference to the quest
    StepNumber INT Order of the step in the quest
    Description TEXT What the player needs to do in this step
    NPCID INT NPC involved in this step
    RequiredItem INT ItemID required to complete this step
    NextStepID INT Reference to the next step
  6. Requirements Table

    Field Data Type Description
    RequirementID INT Primary Key
    QuestID INT Reference to the quest
    RequirementType VARCHAR Type (Item, Level, Faction, etc.)
    Value VARCHAR Specific requirement value or threshold
  7. Rewards Table

    Field Data Type Description
    RewardID INT Primary Key
    QuestID INT Reference to the quest
    RewardType VARCHAR Type of reward (Item, XP, etc.)
    Value VARCHAR Specific reward details

2. Parsing and Populating the Database

Need to parse the quest descriptions and extract relevant information to populate the database tables.

Example Parsing Steps

3. Interacting with the LLM

To ensure the LLM stays on script and doesn't grant rewards prematurely, you need to manage the conversation context and state.

State Management

Prompt Engineering

Example Interaction Flow

  1. Player Initiates Conversation

    • Input to LLM:

      Player says: "Hail, Kalatrina Plossen."
      
      Context: The player is starting the "SoulFire" quest and has not completed any steps.
    • LLM Response:

      Kalatrina Plossen says: "Greetings, traveler. Are you here to serve the will of the Truthbringer?"
  2. Player Proceeds

    • Player Input:

      "I serve the will of the Truthbringer."
    • LLM, with updated context:

      Kalatrina Plossen says: "Very well. I have an important task for you. Please deliver this note to Guard Alayle."
    • Update User State: The player has received the note and the quest has progressed to the next step.

  3. Preventing Premature Rewards

    • If the player tries to skip steps:

      • Player Input:
      "Can I have the SoulFire sword now?"
      • LLM, guided by context and policies:
      Kalatrina Plossen says: "I'm afraid I cannot help you until you've proven yourself by completing the tasks I've given."

4. Enforcing Quest Logic

To prevent the LLM from being manipulated into giving rewards prematurely:

5. Integration Workflow

  1. User Input Handling

    • Capture the player's input.
    • Update the user's state if they provide items or meet conditions.
  2. Contextual Prompt Creation

    • Build a prompt that includes:

      • The NPC's dialogue history with the player.
      • The player's current quest state.
      • Any relevant quest or NPC information.
  3. LLM Response Generation

    • Send the prompt to the LLM.
    • Receive the NPC's response.
  4. Response Validation

    • Ensure the response aligns with the quest logic.
    • If the response is inappropriate, adjust the prompt or provide corrective feedback to the LLM.
  5. Output to Player

    • Present the validated response to the player.

6. Example Database Entries

Quests Table Entry

QuestID Name Description StartNPCID EndNPCID MinimumLevel Classes RelatedZones
1 SoulFire A quest to obtain the SoulFire 101 102 1 All (Paladin) North Freeport, Various others

NPCs Table Entries

NPCID Name Zone Location Faction DialogueID
101 Kalatrina Plossen North Freeport [Coords] Knights of Truth 1001
102 Brother Hayle Splitpaw Lair [Coords] Priests of Life 2001

Items Table Entries

ItemID Name Description QuestID
1001 A Sealed Note A note sealed by Zimel 1
1002 Glowing Sword Hilt The hilt of SoulFire 1
1003 Brilliant Sword of Faith A holy sword 1
1004 SoulFire The legendary sword 1

7. Additional Tips

8. Potential Challenges and Solutions

brynnb commented 1 week ago

Example implementation of QuestSteps:

The NPCID and ItemID values are example values


QuestSteps Table Entries

StepID QuestID StepNumber Description NPCID RequiredItemIDs NextStepID
1 1 1 Obtain Bog Juice: Brew or purchase Bog Juice. NULL NULL 2
2 1 2 Obtain Edible Goo: Cook or purchase Edible Goo. NULL NULL 3
3 1 3 Collect Drom's Champagne: Buy 4 Drom's Champagne from the bartender in Seafarer's Roost bar in East Freeport. NULL NULL 4
4 1 4 Turn in Champagnes: Hand 4 Drom's Champagne to Tykar Renlin in Seafarer's Roost to receive Bunker Cell #1. 102 4 × Drom's Champagne (203) 5
5 1 5 Deliver Items to Prisoner: Give Bog Juice, Edible Goo, and Bunker Cell #1 to a prisoner in West Freeport Arena prison to receive H.K. 102. 103 Bog Juice (201), Edible Goo (202), Bunker Cell #1 (204) 6
6 1 6 Turn in H.K. 102: Hand H.K. 102 to Bank Clerk Jaylin in Highpass Keep bank to receive A Sealed Note. 104 H.K. 102 (205) 7
7 1 7 Obtain Spider Venom Sac: Kill giant spiders to loot a Spider Venom Sac. NULL NULL 8
8 1 8 Acquire Cloth Shirt: Purchase a medium-sized Cloth Shirt from a vendor. NULL NULL 9
9 1 9 Turn in Cloth Shirt: Give the Cloth Shirt to Altunic Jartin in East Commons to receive the Token of Generosity. 105 Cloth Shirt (208) 10
10 1 10 Turn in Spider Venom Sac: Give the Spider Venom Sac to Merko Quetalis in North Freeport to receive the Token of Bravery. 106 Spider Venom Sac (207) 11
11 1 11 Combine Tokens: Hand both the Token of Generosity and Token of Bravery to Merko Quetalis to spawn Guard Willia. 106 Token of Generosity (209), Token of Bravery (210) 12
12 1 12 Defeat Guard Willia: Kill Guard Willia and loot the Token of Truth. 107 NULL 13
13 1 13 Return Token of Truth: Give the Token of Truth to Merko Quetalis to receive the Testimony. 106 Token of Truth (211) 14
14 1 14 Defeat Xicotl: Kill Xicotl in Mistmoore Castle to loot the Glowing Sword Hilt. 108 NULL 15
15 1 15 Defeat Sir Lucan D'Lere: Kill Sir Lucan D'Lere (both forms) in West Freeport to loot the Testimony of Truth. 109 NULL 16
16 1 16 Improve Faction with Knights of Truth: Achieve high warmly faction with the Knights of Truth. NULL NULL 17
17 1 17 Turn in Testimony of Truth: Give the Testimony of Truth to Valeron Dushire in North Freeport to receive the Brilliant Sword of Faith. 110 Testimony of Truth (214) 18
18 1 18 Improve Faction with Priests of Life: Achieve warmly faction with the Priests of Life. NULL NULL 19
19 1 19 First Turn-in to Brother Hayle: Give A Sealed Note to Brother Hayle in Splitpaw. He returns an unsealed note. 111 A Sealed Note (206) 20
20 1 20 Final Turn-in to Brother Hayle: Give the Unsealed Note, Testimony, Glowing Sword Hilt, and Brilliant Sword of Faith to Brother Hayle to receive SoulFire. 111 Unsealed Note (206), Testimony (212), Glowing Sword Hilt (213), Brilliant Sword of Faith (215) NULL

Explanation of Fields

Notes on Specific Steps

NPCs Involved

NPCID Name Zone
101 Kalatrina Plossen North Freeport
102 Tykar Renlin East Freeport
103 a prisoner West Freeport
104 Bank Clerk Jaylin Highpass Keep
105 Altunic Jartin East Commons
106 Merko Quetalis North Freeport
107 Guard Willia North Freeport
108 Xicotl Mistmoore Castle
109 Sir Lucan D'Lere West Freeport
110 Valeron Dushire North Freeport
111 Brother Hayle Splitpaw Lair

Items Involved

ItemID Name
201 Bog Juice
202 Edible Goo
203 Drom's Champagne
204 Bunker Cell #1
205 H.K. 102
206 A Sealed Note / Unsealed Note
207 Spider Venom Sac
208 Cloth Shirt
209 Token of Generosity
210 Token of Bravery
211 Token of Truth
212 Testimony
213 Glowing Sword Hilt
214 Testimony of Truth
215 Brilliant Sword of Faith
216 SoulFire

Faction Requirements

Special Considerations


By structuring the quest steps in this way, you can programmatically control the flow of the quest within your application. Each step can be checked for completion before allowing the player to proceed, ensuring that the LLM remains aligned with the quest logic and cannot be manipulated into granting rewards prematurely.

Integration with LLM

When interacting with the player, the LLM should be provided with context about the current quest step. For example:

By updating the context for each interaction based on the quest steps, the LLM will provide accurate and relevant responses.

State Management

Ensure application keeps track of:

brynnb commented 1 week ago

Source of example LUA scripts: https://github.com/EQMacEmu/quests

Example quest walkthrough: https://wiki.project1999.com/Zimel%27s_Blades_(SoulFire)

Would be amazing to get an Alla clone working with its quest database, however the only open source version I can find basically says "go find quests.sql" which doesnt seem available on the internet anywhere. Would be a lot of effort to run an extraction tool myself but might be possible? At minimum they all seem to be here in PHP format:

https://github.com/EQMacEmu/allaclone/tree/master/quests