Hello, please someone tell me why what I made is wrong.
I’m trying to make mechanism of passing turns between AI and Player.
Currently, when AI perception notice Player, its check for distance to Player and position (both must be in appropriate tiles) and if all is true – registers itself through Enter Combat event on Game Mode.
Enter Combat checks if that Enemy was already registered, if not – adds it to Enemy Parties array, calls Start Combat (just adjusts rotation to “face” Player) on it and then depending on who called Enter Combat (currently only AI can do it) passes first turn to Enemy or Player by calling Your Turn on them.
Your Turn on Enemy currently simply checks if Player in adjacent tile, if yes – “attacks” if no – moves one tile closer. Then it calls Pass Turn on Game Mode.
Pass Turn checks who called it, if Player – pass turn to AI, if AI - passes to next registered Enemies until it covers all of them and then - pass back to Player.
Problem: currently there are two Enemies, combat starts with Player adjacent to one of them, so expected result – one Attack message and one move. Instead one of the enemies acts twice.
I suspect there is something fundamentally wrong in my Pass Turn – You Turn combination.