Sequence of actions (Turn Based)

Hey fellas!

I have a question related to operations in turn based games.
I would like to know how handling of actions sequences should be implemented.

Maybe I’ll explain what I mean with an attack action.
A character should run to an opponent and attack him.
The opponent may counterattack before or after the attack (depending on his ability) or not counterattack at all.

I understand that in order for this to work there are some event dispatchers required, however should characters be comunicating directly with each other by dynamically creating and removing bindings (like call PerformCounterattack and bind/unbind OnCounterattackEnd), or should there be some sort of global messeging system to which all the characters are bound and constantly listening to?
Are there any major advantages or disadvantages to either approach, e.g. greater flexibility or does it all depend on the project itself? Is there an even better way of doing this?

Blueprint interface is the way to go there.

It allows you to attack ( for example ) any actor. When the event occurs, a message is sent to the actor saying ‘an attack has happened’ ( params can be passed ).

The actor in question, may or may not, implement the interface. Every actor that does implement it can have a different reaction. A foe, for example, could counter attack, a branch could break, and a rock could do nothing:

Well, that would only cover one part of the problem, because the attacks are not instantaneous. My problem is more about defining when and if these actions are to be performed. For example if an enemy is able to perform a counterattack before the attack, the attacker would have to wait till the enemy’s action (animation etc.) is finished and only then execute it’s action.

Such cases can get complicated very fast, like when a second friendly character (with a special ability) is standing next to the attacked enemy. This friendly character could then perform a secondary attack (after the current attacker and before the enemy’s counter). This may seem a bit confusing at first, but recently I stumbled across such case and I really don’t know what mechanism would be most appropriate for this.

Now that’s more like state machines. It’s really up to you how you do that.

I mean UE has state machines for the animations, but you might need a sort of ‘fight state machine’ which overlooks a group of characters.

You still could still use BP interfaces for this. You can have a message ‘Im going to do attack A’ before A occurs, which gives the opponent time to make a move first.

EDIT: Was thinking about this a bit more. Unless you accidentally come across someone here who has already implemented such a system, you’ll need to use your ‘cunning’ to find the best path, I think.

Once strategy that can yield results is to put something like ‘combat’ into a market place search and then sort by oldest first. Then look for ones with a lot of stars. There’ll be a reason for that.

Depending on price, it’s possible to learn a lot by picking something like that apart…

Wow, I haven’t really thought about it, but a state machine seems like a nice starting point. And thank you very much for the tips mate : )

Incidentally, I’ve had my eye on this for a while

It turns any part of the engine into a state machine :slight_smile: