Hello people who most likely are vastly more experienced in programming and specifically game-programming than myself!
Beware of tl;dr.
I am currently developing a board/chess/tilebased game. And I am about to implement Unit-Magic in the game, a.k.a each unit in the game will have its own magic. And I have been thinking about using a design I came up with that will probably help me be able to implement this magic in the game. But I am not sure if the solution will work, and I would prefer not spending countless hours on a solution that will not work. So I was thinking of presenting it here and hearing your thoughts and ideas.
So the problem is: Implementing a system where each unit can have unique magic abilities without having to implement code in every part of my system just to handle a new type of magic. Also having an easy implementation of movement and combat between units and the Gameboard.
Example: Unit A has the magic: "Throw a fireball at enemy Unit B". Unit C has the magic "Fly forward five tiles then shoot a rocket launcher at enemy Unit B". Unit D has the magic "Put a firewall up on Tile 1, 2 and 3". And so on...
My Idea of a solution: Keep each class separated from each other. That means that all units reside in one class, the gameboard in another class and the all the magic-abilities reside in a third class. Then have a MessagePasser-class combine them all and force each class to send messages to the other classes through a MessagePasser. The MessagePasser in turn has a queue of messages that it will process one at a time so a class can send three messages simultaneous without problems. (See Picture below).
Examples of the solution: In this solution when you click a certain unit it could work like this:
If the state is Movement: The UnitContainer sends a message to the Gameboard to let it calculate which tiles the clicked unit can move to. A tile that the unit can move to is then clicked and the Gameboard sends a message to the UnitContainer to tell it where the unit should move.
If the state is Magic: The UnitContainer sends a message to the Magic-class to ask what this unit can do for magic. The Magic is "Throw Fireball at enemy unit". The magic-class then sends a message back to the UnitContainer telling it, that the unit should "equip" a fireball-projectile and update the units range attack values. The UnitContainer then sends a message to the Gameboard to let it calculate units in range of the fireball-attack. The Gameboard then sends back on which positions the enemy units in range are on to the UnitContainer. An enemy unit in range is clicked and the unit throws the fireball at the clicked enemy unit.
With this solution "Throw Fireball at enemy unit" would probably be split into several messages such as: Update projectile range, Update projectile damage, Update projectile animation, Do Projectile Attack.
So do you think this solution would work in a game design?
Is there any other design that you think would work or solve the problem better?
It is most definitely some kind of event-system, do you have any suggestion of design-patterns or the like I should take a look on?
And any other comments and suggestions are also more than welcome!
Thank you for your time, I hope my description of the design was sufficient to make it understandable of what I am trying to accomplish.
EDIT: Using Unreal Engine 4 to build it.