For example, you are presented with an event like this:
Event Description: You encountered a man in strange clothes standing in the shadow. His face is covered and he has his hand behind his back and looks like he is holding something in it. Could it be a weapon? or maybe something valuable he is trying to protect from you?
The man doesn’t look like any of the pathetic locals you’ve seen in this town so far and you can’t figure out how strong he might be.
Choice1: Greet the man Choice2: Attack the man, and attempt to take the item Choice3: Walk away
The event screen would consist of a text and two or three buttons depends on the event. What would be the most straightforward approach of making something like this, keeping in mind that the choices would change based on the event?
I’m not trying to make an extremely fancy system or anything. Just something that works and is flexible enough so I can put different functions for the choices and that’s it.
I believe you can’t get away with “flexible enough” in your case. You are trying to make a completely modular, linear/randomly generated story-line based on users’ decisions. Whatever you do, there’s no simple solution and all of it involves a lot of work; if you want it done right that is.
I would first start off by generalizing all steps of your single playthrough. Something like this:
public class Encounter
{
// Common logic
}
public class Combat : Encounter
{
// Combat logic
}
public class Choice : Encounter
{
// Choice Logic
}
Now, depending on the style of game you are making, you either want to create your story by hand, or you want the story to be randomly generated.
If you decide to go by hand, your best path would be to have a makeshift graph editor that lines out all possible choices and paths. This is a TON of work and consider if it’s even worth your time doing something like this.
If you decide to go with a randomly generated story, you have a much easier time. In theory, all you have to do is create all possible encounters like in the code snipper bellow, throw them into some very simple logic that randomly picks the next encounter, and see what works and what doesn’t.
There’s not much I can tell you here without you actually attempting to do something yourself. A ton of ways to go about this, just pick something and see how it goes.
I did something similar as @Dextozz I called them Commands instead of Encounter but that doesn’t really matter and the base class had a virtual Start/Update/Cleanup method and a IsDone property which can be used for the game logic, because some commands could take multiple frames, for example wait for user interaction etc. combined with a “CommandManager” class, which handled the List of commands, updates the current command, check if it is done and starts the next command etc.
The commands can add “sub” commands, that’s why I used a list instead of a stack or queue, because the sub commands can be inserted at the start (if it should be executed after the current command) or at the end (after all commands which are currently in the list).
So in your example I would have a “ChoiceCommand” which contains sub commands for each choice and depending on which choice you select (this logic is inside the ChoiceCommand) it will insert the correct sub command to the command manager, so it will be executed next. So you can add any kind of commands you want like “ShowTextCommand” or “StartBattleCommand” or whatever you need.
I saw this idea in a RPG tutorial video, he doesn’t use Unity / C#, he uses C++ but the basic idea is easy to convert to C#, I can send you the link if you want.