IEnumerator StartBattling()
    {
        for (int i = 0; i < 4; i++)
        {
            meButtons [i].SetActive(false);
        }
        battleLog.SetActive(true);
        playerTurn = false;
        currentChar++;
        print(new Time());
        yield return(SelectAIMove());

        print(new Time());
        //MakeMoves (); method is under this
        print(pressedEnter);
        pressedEnter = false;
        for (int i = 0; i < moveList.Count && moveList[i] != null; i++)
        {
            print(i);
            MoveMessenger m = (MoveMessenger)(moveList.GetKey(i));
            if (m.getAttackedPlayer().isAlive() != true)
            {
                updateBattleLog(m.getAttackingPlayer().getName() + "'s target was dead before move.  Attacking next person in the enemy line");
                yield return(chatEnter());

                int newTarget = m.getIndexOfAttackedPlayer();
                if (m.getAttackingPlayer().getTeam() == "team")
                {
                    if (newTarget > aliveEnemyList.Capacity - 1)
                    {
                        newTarget = 0;
                    }
                    m.setAttackedPlayer(aliveEnemyList [newTarget]);
                }
                else
                {
                    if (newTarget > aliveTeammateList.Capacity - 1)
                    {
                        newTarget = 0;
                    }
                    m.setAttackedPlayer(aliveTeammateList [newTarget]);
                }
                m.setIndexOfAttackedPlayer(newTarget);
                m.recalculateDamage(m.getAttackingPlayer().moveList [m.getIndexOfMove()].getDamage());
            }
            updateBattleLog(m.getAttackingPlayer().getName() + " is attacking " + m.getAttackedPlayer().getName() + " with damage: " + m.getRecalculatedDamage());
            updateBattleLog(m.getAttackedPlayer().getName() + "'s health before the move is: " + m.getAttackedPlayer().getHealth());
            int health = m.getAttackedPlayer().receiveDamage((MoveMessenger)moveList.GetKey(i));
            updateBattleLog(m.getAttackedPlayer().getName() + "'s health after the move is: " + health);
            yield return(chatEnter());

            m.getAttackedPlayer().setHealth(health);
            if (health <= 0)
            {
                updateBattleLog(m.getAttackedPlayer().getName() + " has died");
                if (m.getAttackedPlayer().team == "team")
                {
                    aliveTeammateList.Remove(m.getAttackedPlayer());
                }
                else                   //no need to check if he's enemy, because he will be
                {
                    aliveEnemyList.Remove(m.getAttackedPlayer());
                }
                yield return(chatEnter());

                moveList [moveList.IndexOfValue(m.getAttackedPlayer().getName())] = null;
                //moveList.RemoveAt (moveList.IndexOfValue (m.getAttackedPlayer ().getName ())); //the line that causes skipped turns
                if (isBattleOver())
                {
                    updateBattleLog("Battle's over.");
                    BattleOver();
                }
            }
        }
        moveList.Clear();
        print("MoveList cleared");
        currentChar = 0;
        print("CurrentChar has been reset");
        currentPageOfMovesOrTargets = 0;
        battleLog.SetActive(false);
        playerTurn = true;
        updateMovesForChar();
        EventSystem.current.SetSelectedGameObject(meButtons[0]);
        needToPrint = true;
    }
Ejemplo n.º 2
0
    IEnumerator StartBattling()
    {
        aliveTeammateList.TrimExcess();
        aliveEnemyList.TrimExcess();
        for (int i = 0; i < 4; i++)
        {
            meButtons [i].SetActive(false);
        }
        battleLog.SetActive(true);
        playerTurn = false;
        yield return(SelectAIMove());

        //MakeMoves (); method is under this
        print(pressedEnter);          //says its true because we hit enter for the final selection of target
        pressedEnter = false;
        for (int i = 0; i < moveList.Count; i++)
        {
            print("i is " + i);
            MoveMessenger m = (MoveMessenger)(moveList.GetKey(i));
            if (m.getAttackingPlayer().getHealth() > 0)
            {
                if (m.getAttackedPlayer().isAlive() != true)
                {
                    updateBattleLog(m.getAttackingPlayer().getName() + "'s target was dead before move.  Attacking next person in the enemy line");
                    yield return(StartCoroutine(chatEnter()));

                    int newTarget = m.getIndexOfAttackedPlayer();
                    if (m.getAttackingPlayer().getTeam() == "team")
                    {
                        if (newTarget > aliveEnemyList.Capacity - 1)
                        {
                            newTarget = 0;
                        }
                        m.setAttackedPlayer(aliveEnemyList [newTarget]);
                    }
                    else
                    {
                        if (newTarget > aliveTeammateList.Capacity - 1)
                        {
                            newTarget = 0;
                        }
                        m.setAttackedPlayer(aliveTeammateList [newTarget]);
                    }
                    m.setIndexOfAttackedPlayer(newTarget);
                    m.recalculateDamage(m.getAttackingPlayer().moveList [m.getIndexOfMove()].getDamage());
                }
                updateBattleLog(m.getAttackingPlayer().getName() + " is attacking " + m.getAttackedPlayer().getName() + " with damage: " + m.getRecalculatedDamage());
                updateBattleLog(m.getAttackedPlayer().getName() + "'s health before the move is: " + m.getAttackedPlayer().getHealth());
                int health = m.getAttackedPlayer().receiveDamage((MoveMessenger)moveList.GetKey(i));
                updateBattleLog(m.getAttackedPlayer().getName() + "'s health after the move is: " + health);
                yield return(StartCoroutine(chatEnter()));

                m.getAttackedPlayer().setHealth(health);
                if (health <= 0)
                {
                    updateBattleLog(m.getAttackedPlayer().getName() + " has died");
                    if (m.getAttackedPlayer().team == "team")
                    {
                        relocateToDeadTeammateList(m);
                    }
                    else                         //no need to check if he's enemy, because he will be
                    {
                        relocateToDeadEnemyList(m);
                    }
                    yield return(StartCoroutine(chatEnter()));

                    //moveList.RemoveAt (moveList.IndexOfValue (m.getAttackedPlayer ().getName ())); //the line that causes skipped turns
                    if (isBattleOver())
                    {
                        yield return(StartCoroutine(chatEnter()));

                        updateBattleLog("Switching back to movement scene...");
                        yield return(new WaitForSeconds(1f));

                        BattleOver();
                    }
                }
            }
            else
            {
                updateBattleLog(m.getAttackingPlayer().getName() + "'s hp was " + m.getAttackingPlayer().getHealth() + " so his turn is skipped.");
                yield return(StartCoroutine(chatEnter()));
            }
        }
        moveList.Clear();
        print("MoveList cleared");
        currentChar = 0;
        print("CurrentChar has been reset");
        currentPageOfMovesOrTargets = 0;
        battleLog.SetActive(false);
        playerTurn = true;
        updateMovesForChar();
        EventSystem.current.SetSelectedGameObject(meButtons[0]);
        needToPrint = true;
    }