I didn't check your code yet, but, for a starter, you'll probably have to create a whole interface just for dialogues. It's not only what your character talk, but what options he has and how the other character will react to each of them. It's called a dialogue tree and it's quite complex to implement. Also, if you want dialogues to have an impact in the game, like changing the state of an item, inventory, etc, the interface becomes even more complex! I'll take a look at the file you sent and I'll let you now if I come up with anything.
When everything is catastrophic, thank the Gods things aren't worse!