I'm developing a card-based combat system for my game. (imagine a game like Magic The Gathering, or Hearthstone, or any CCG) I was writing the logic of the effect that I call "thorn". If a player has the thorn effect, everytime he got struck with some damage, he deals damage to his attacker.
I already had an event raised everytime a character is being damaged, so it seemed logical to me to use it.
the thorn effect starts to listen to the onDamage event and then it deals its damage.
The issue with this solution is that it can create an endless chain of thorn effect, if both parties have the thorn effect.
Player 1 attacks player 2.
Player 2 raises onDamage event.
player 2 resolves its thorn effect, and it deals damage to player 1.
player 1 raises onDamage event.
player 1 resolves its thorn effect, and it deals damage to player 2.
and it goes on.
There are many solutions I can think of, but none of them are actually satisfying to me. Any suggestions? Thanks for the answers