I am developing a RPG game for Android using LibGDX, at this moment the NPCs in the game have some moving AI (pathfinding), like random directions and stuff. Now I am working on the dialogue system, for that I have the following:
- DialogueManager class that just renders the current dialogue on the screen if any
- A Dialogue class which consists of an ArrayList of Strings which are the lines of the dialogue
- The NPC class holds a Dialogue object, so I can just add(text) to the dialogue.
The result of this is the following
- The player is near a NPC and presses Action key
- A window is opened showing the current line of the dialogue
- When the players touches the screen, the line is replaced by the next one until there is no more lines left and the dialogue window closes and the player can move again
- If the player talks to the same NPC, the same dialogue lines are presented
It works fine, but that is not what I really want. I need to make the dialogue to be different depending on some conditions the player has. My dialogues are stored in an XML file:
<npc>
<name>Alice</name>
<interaction>
<dialogue>
<line>Hello there!</line>
<line>This is a simple dialogue</line>
</dialogue>
</interaction>
</npc>
But I want to have something like this (and I have it in the XML):
<npc>
<name>Alice</name>
<interaction>
<dialogue condition="timesTalked" value="0">
<line>Hello there!</line>
<line>You are talking to me the first time!</line>
</dialogue>
<dialogue condition="timesTalked" value="1">
<line>Hmmm...I remember you! Have we met before?</line>
</dialogue>
<dialogue condition="haveItem" value="Apple">
<line>Is that an apple? Gimme!</line>
</dialogue>
</interaction>
</npc>
So for example "timesTalked" is a real variable name and "value" is the condition, so the first condition would say
if(timesTalked == 0)
// do stuff
Now the problem, how can I implement that? I know how to parse the XML, but how can I make it so the conditions work? I don't want to have it all hardcoded in Java, also I dont want to use a scripting language, I think it is good to have XML because is lightweight and easy to use. Thankyou!