Search Unity

Iterating combat rounds

Discussion in 'Scripting' started by GameDevRick, Nov 15, 2018.

  1. GameDevRick

    GameDevRick

    Joined:
    Oct 8, 2011
    Posts:
    269
    I am having trouble figuring out how to step through combat rounds in a turn based combat system.
    My intention is to take input from each combatant during each combat round before the next round
    is allowed to begin. I have it waiting for input and everything runs successfully in that regard, but I
    do not know how to make it wait to advance combat rounds until everyone has taken their turn.

    The methods I implement are as follows:

    Code (CSharp):
    1.  
    2. void ExecuteCombatRounds() {
    3.            
    4.     if(aiCount > 0) {
    5.            
    6.         CombatRound();
    7.     }
    8. }
    Of course all that method does is advance through each combat round while there are AI still alive, but
    that is not exactly what needs to happen. I also need it to wait for all combatants involved to have taken
    their turn if there are AI still alive.

    Here is the CombatRound():

    Code (CSharp):
    1.  
    2. void CombatRound() {
    3.  
    4.     i_combatRound++;
    5.  
    6.     Debug.Log("** COMBAT ROUND: " + i_combatRound + " **");
    7.  
    8.     SetActiveCombatant();
    9.  
    10.     SelectTargets();
    11.  
    12.     SortTargetsByDistance();
    13.  
    14.     SetActiveTarget();
    15.  
    16.     ExecuteCombatantTurns();
    17. }
    And here is the ExecuteCombatTurns():

    Code (CSharp):
    1.  
    2. void ExecuteCombatantTurns() {
    3.        
    4.     if(_activeCombatant.GetComponent<AI>() != null) {
    5.  
    6.         StartCoroutine(EnemyActionSelection());
    7.     }
    8.        
    9.     if(_activeCombatant.GetComponent<Player>() != null) {
    10.            
    11.         StartCoroutine(PlayerActionSelection());
    12.     }
    13. }
    As I mentioned, those coroutines execute fine and take either AI or Player input. The problem
    is that I don't know how to hold the advance of each combat round until after they have all
    taken their turn. Thanks in advance for the help and advice.