This describes the NPC dialogs, focusing on how database structure looks like, how are they loaded, sent to client, displayed.
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.
Here is an example of a dialog:
Player: has following choices:
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:
The following axioms apply to any dialog tree:
The dialogs are going to be saved in a database (for easier management and access)
The dialogs database structure is displayed by following diagram:
Let's now have a look at how client side handles the dialogs
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)
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.
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:
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
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.