function nextUnitsTurn(combatantsSorted) {
    if (battleIsOver == false) {
        do {
            if (currentUnitTurn >= combatantsSorted.length) {
                currentUnitTurn = 0;
            }
            if (combatantsSorted[currentUnitTurn].hpLeft == 0) {
                combatantsSorted.splice(currentUnitTurn, 1);
                if (currentUnitTurn >= combatantsSorted.length) {
                    currentUnitTurn = 0;
                }
            }
        } while (combatantsSorted[currentUnitTurn].hpLeft == 0);
        if (combatantsSorted[currentUnitTurn] instanceof Character) {
            document.getElementById("playerAbilities").style.visibility = "visible";
            document.getElementById("playerItems").style.visibility = "visible";
            document.getElementById("playerFlee").style.visibility = "visible";
            currentPlayer = combatantsSorted[currentUnitTurn];
            currentPlayerIndex = findRightChar(currentPlayer);
            console.log("It is " + currentPlayer.name + " turn. Index " + currentPlayerIndex);
        }
        else if (combatantsSorted[currentUnitTurn] instanceof Monster) {
            console.log("It is " + combatantsSorted[currentUnitTurn].name + "'s turn");
            currentPlayer = combatantsSorted[currentUnitTurn];
            currentMonsterIndex = findRightMonster(currentPlayer);
            randomMove(combatantsSorted[currentUnitTurn]);
        }
    }
}
/**
 * Find the next players turn, and removes dead combatants from the queue.
 * @param {array} combatantsSorted participating characters and monsters.
 */
Find the next players turn, and removes dead combatants from the queue.
@param {array} combatantsSorted participating characters and monsters.
Find the next players turn and removes dead combatants from the queue . @param { array } combatantsSorted participating characters and monsters .
function nextUnitsTurn(combatantsSorted) {
    if (battleIsOver == false) {
        do {
            if (currentUnitTurn >= combatantsSorted.length) {
                currentUnitTurn = 0;
            }
            if (combatantsSorted[currentUnitTurn].hpLeft == 0) {
                combatantsSorted.splice(currentUnitTurn, 1);
                if (currentUnitTurn >= combatantsSorted.length) {
                    currentUnitTurn = 0;
                }
            }
        } while (combatantsSorted[currentUnitTurn].hpLeft == 0);
        if (combatantsSorted[currentUnitTurn] instanceof Character) {
            document.getElementById("playerAbilities").style.visibility = "visible";
            document.getElementById("playerItems").style.visibility = "visible";
            document.getElementById("playerFlee").style.visibility = "visible";
            currentPlayer = combatantsSorted[currentUnitTurn];
            currentPlayerIndex = findRightChar(currentPlayer);
            console.log("It is " + currentPlayer.name + " turn. Index " + currentPlayerIndex);
        }
        else if (combatantsSorted[currentUnitTurn] instanceof Monster) {
            console.log("It is " + combatantsSorted[currentUnitTurn].name + "'s turn");
            currentPlayer = combatantsSorted[currentUnitTurn];
            currentMonsterIndex = findRightMonster(currentPlayer);
            randomMove(combatantsSorted[currentUnitTurn]);
        }
    }
}
function nextUnitsTurn ( combatantsSorted ) { if ( battleIsOver == false ) { do { if ( currentUnitTurn >= combatantsSorted . length ) { currentUnitTurn = 0 ; } if ( combatantsSorted [ currentUnitTurn ] . hpLeft == 0 ) { combatantsSorted . splice ( currentUnitTurn , 1 ) ; if ( currentUnitTurn >= combatantsSorted . length ) { currentUnitTurn = 0 ; } } } while ( combatantsSorted [ currentUnitTurn ] . hpLeft == 0 ) ; if ( combatantsSorted [ currentUnitTurn ] instanceof Character ) { document . getElementById ( "playerAbilities" ) . style . visibility = "visible" ; document . getElementById ( "playerItems" ) . style . visibility = "visible" ; document . getElementById ( "playerFlee" ) . style . visibility = "visible" ; currentPlayer = combatantsSorted [ currentUnitTurn ] ; currentPlayerIndex = findRightChar ( currentPlayer ) ; console . log ( "It is " + currentPlayer . name + " turn. Index " + currentPlayerIndex ) ; } else if ( combatantsSorted [ currentUnitTurn ] instanceof Monster ) { console . log ( "It is " + combatantsSorted [ currentUnitTurn ] . name + "'s turn" ) ; currentPlayer = combatantsSorted [ currentUnitTurn ] ; currentMonsterIndex = findRightMonster ( currentPlayer ) ; randomMove ( combatantsSorted [ currentUnitTurn ] ) ; } } }
Find the next players turn, and removes dead combatants from the queue.
Find the next players turn and removes dead combatants from the queue .