NPC Dialogs

This describes the NPC dialogs, focusing on how database structure looks like, how are they loaded, sent to client, displayed.

This was last updated when game had version: dev - 1.6.3
Top

1 Introduction

TDOD

2 Requested functionality

We want a player to be able to click on an NPC, and then read some text the NPC will be telling. Player might also be able to choose options.


2.1 Example

Here is an example of a dialog:
NPC: Yes?
Player: has following choices:

3 Data representation

One dialog tree will be represented by rooted N-ary tree, which can be seen at following image:

Now, one NPC may have as many dialog trees as needed. On the image above is visible, that some nodes are user choices.
There are axioms for a dialog tree, explained below:

4 Dialog tree axioms

The following axioms apply to any dialog tree:

5 Data source

The dialogs are going to be saved in a database (for easier management and access)


5.1 Database diagram

The dialogs database structure is displayed by following diagram:

6 Client side

Let's now have a look at how client side handles the dialogs


6.1 Displaying

For displaying, we classically create HTML base, and create a javascript class that will allow to fill in / change data in the HTML.


6.2 How to send data to client

Server will send entire tree (or sub-tree) of dialogs to the client. Client will then just display options / text to user, and traverse the received tree locally.
(For interaction with server, see below)


6.3 When to send data to client

When client will interact with an NPC, or do some action which will make the dialogs to emerge, then server sends the relevant tree to the client.

7 Contacting the server when getting to marked node

The problem can be, that if a player has fulfilled some quest, he shall get different dialogs than the orhers. Morfeover, we might need to start a quest, when player gets to certain point in the dialog, or grant an item to the player.
For this, a mechanics which would allow that, must be implemented:

8 Marked node

A marked node is a node in a dialog tree, to which, when client gets to, when traversing the tree locally, client will contact the server, telling that he has reached the marked node.
Server will then use some logic to give player some item, or cahnge some settings

9 Request forgery security flaw

Considering the lines above, player might forge a request, informing server about reaching dialog node, without really going through the dialogs.
This will be avoided by validating correct tree / whether player is close to NPC / whether he has started the quest, and so on, but because of the nature of the solution, dialogs can still be skipped by forging packets.
I am fully aware of that, and considering the fact that dialogs and quests are not anything crucial, we will just leave this flaw in the system, since the gravity of the flaw is meaningless.