Building forward my text adventure i stumbled upon how to actually drive the actions that can be caused by dialogs. I wrote the dialogues and the logic around handling them already, but i'm missing a key about how to turn a dialogue into an 'engine' specific action (like spawn item, drop, buy, sell).
My game is absolutely based on JSON therefore even dialogues are stored there:
An Option is what a player can choose by typing one of the defined Keywords for currently displayed dialogue.
Response is what a player sees when option is chosen
Goto is where the dialogue goes next after an option is chosen
Script is nothing more fancy than a list of strings with integers that get mapped into a
std::map<std::string,int> and later passed for the execution. Think of it as of flags.
Let's look at the example below - where you could buy something from inn keeper.
In above situation, you can talk to the keeper and choose:
- "1" to buy item "1"
- "2" to buy item "2"
- "back" to get back to previous dialogue (with a goto)
Let's say i want to choose option "1" and it boils down to the design now.
How would you turn that "1" into a real engine action of buying an item?
What i did.
As you might have seen i have defined a Script within the option of the dialogue, this would be just a map (string to int) of attributes passed to an interpreter.
Then the interpreter executes that based on 'action_type' - which is defined in json, mandatory and describes type of action like here:
Some questions then:
1) Is it the valid approach to write my own interpreter - maybe i can use it somewhere else? or i should start thinking about external scripts - which actually require me to focus on adding library and learning it, instead of doing the game itself.
2) Which class should be really responsible for actually executing the script with the data passed from dialogue.
Dialog class itself ?
std::string CDialogue::Process(const std::vector<std::string>& rvArguments)
Npc class handling talk action ?
void CEntityNPC::HandleTalk(CEntity *pFromWho, const std::vector<std::string>& rvArguments)
Command class that handles talk command?
void CCommandTalk::Execute(CEntity *pPlayer,const std::vector<std::string>& rvArguments)
3) Maybe you can think of a different way to handle this situation? Basically a translation of a text(json) data into a game logic.