I am currently building a AI system for a game. I am familiar with State design pattern and implemented different states for each agent in my game.
Different states are like Running, Attack, Idle, Cover, Support etc.
In this game, I have around 10 agents which have mainly two behaviours - Defender and Attacker.
I made a class AIManager which have reference of all agents in the game. This class decides which agent will do what but I am facing issues in managing this class. There are many rules in the game like -
- There will be two teams.
- Each team will have 2 defender and 3 attackers.
- Attacker will attack attackers and defenders.
- Defender only attack to defenders.
- At a time only two agents can attack a single agent.
- If defender is in cover, it will not go to support state.
- If defender is attacking, it will not go to run state.
- If attacker is attacking, it can run away on specific condition. ... etc
To make these rules applicable, my AIManager class is totally mess, contains lots of if/else, need to check every possibilities, for loops. I am sure I am not doing right in implementing these game logic because when I need to change some rules or need to add another state, I need to go through all my game logic. This manager code is totally unstable.
I want to know how to tackle this situation, Is there any design pattern which I should follow or any suggestion would be of great help.