Пример #1
0
    IEnumerator BattleLoop()
    {
        if (debug)
        {
            Debug.Log("BATTLELOOP START");
        }
        //TODO: clean this garbage
        while (state != BattleState.END)
        {
            if (debug)
            {
                Debug.Log("WHILELOOP BEGINNING");
            }
            if (state == BattleState.START)
            {
                state = BattleState.ACTION;
            }
            else if (state == BattleState.ACTION || state == BattleState.BAG)
            {
                while (state == BattleState.ACTION || state == BattleState.BAG)
                {
                    if (Input.GetKeyDown("escape") || Input.GetKeyDown("i"))
                    {
                        inv.closeInventory();
                        state = BattleState.ACTION;
                    }
                    //waits for the player to push an action button, as defined in the ui stuff
                    yield return(null);
                }
            }

            else if (state == BattleState.P1)//PLAYER GOES FIRST
            {
                switch (action)
                {
                case ActionType.ATTACK:

                    e_HP = Attack(effective_stats[(int)Stat.ATK], e_HP, enemy.GetDEF());
                    battleUI.PlayerAttacking();
                    statGen.addProb((int)Stat.ATK);    //ATTACK INCREASES WHEN PLAYER USES NORMAL ATTACK
                    if (debug)
                    {
                        Debug.Log("e_HP = " + e_HP);
                    }
                    yield return(new WaitForSecondsRealtime(delay));

                    if (e_HP <= 0)
                    {
                        battleUI.EnemyDeath();
                        result = 1;
                        state  = BattleState.END;
                    }
                    else
                    {
                        p_HP = Attack(enemy.GetATK(), p_HP, effective_stats[(int)Stat.DEF]);
                        battleUI.PlayerDefending();

                        statGen.addProb((int)Stat.DEF);    //DEFENCE INCREASES WHEN PLAYER IS HIT BY NORMAL ATTACK
                        if (debug)
                        {
                            Debug.Log("p_HP = " + p_HP);
                        }
                        yield return(new WaitForSecondsRealtime(delay));

                        if (p_HP <= 0)
                        {
                            battleUI.PlayerDeath();
                            result = -1;
                            state  = BattleState.END;
                        }
                        else
                        {
                            state = BattleState.ACTION;
                        }
                    }
                    break;

                case ActionType.ITEM:
                    //use item
                    if (used_item_prop.isEdible)
                    {
                        Heal(used_item_prop.Eat());
                        yield return(new WaitForSecondsRealtime(delay));
                    }
                    else if (used_item_prop.isEquipment)
                    {
                        UpdateStats();
                        yield return(new WaitForSecondsRealtime(delay));
                    }
                    //enemy attack
                    p_HP = Attack(enemy.GetATK(), p_HP, effective_stats[(int)Stat.DEF]);
                    battleUI.PlayerDefending();
                    statGen.addProb((int)Stat.DEF);    //DEFENCE INCREASES WHEN PLAYER IS HIT BY NORMAL ATTACK
                    if (debug)
                    {
                        Debug.Log("p_HP = " + p_HP);
                    }
                    yield return(new WaitForSecondsRealtime(delay));

                    if (p_HP <= 0)
                    {
                        battleUI.PlayerDeath();
                        result = -1;
                        state  = BattleState.END;
                    }
                    else
                    {
                        state = BattleState.ACTION;
                    }
                    break;

                case ActionType.SPECIAL:
                    //TODO: special stuff
                    break;
                }//switch end
            }
            else if (state == BattleState.P2)//PLAYER GOES SECOND
            {
                switch (action)
                {
                case ActionType.ATTACK:
                    //enemy attack
                    p_HP = Attack(enemy.GetATK(), p_HP, effective_stats[(int)Stat.DEF]);
                    battleUI.PlayerDefending();
                    statGen.addProb((int)Stat.DEF);    //DEFENCE INCREASES WHEN PLAYER IS HIT BY NORMAL ATTACK
                    if (debug)
                    {
                        Debug.Log("p_HP = " + p_HP);
                    }
                    yield return(new WaitForSecondsRealtime(delay));

                    if (p_HP <= 0)
                    {
                        battleUI.PlayerDeath();
                        result = -1;
                        state  = BattleState.END;
                    }
                    else
                    {
                        e_HP = Attack(effective_stats[(int)Stat.ATK], e_HP, enemy.GetDEF());
                        battleUI.PlayerAttacking();
                        statGen.addProb((int)Stat.ATK);    //ATTACK INCREASES WHEN PLAYER USES NORMAL ATTACK
                        if (debug)
                        {
                            Debug.Log("e_HP = " + e_HP);
                        }
                        yield return(new WaitForSecondsRealtime(delay));

                        if (e_HP <= 0)
                        {
                            battleUI.EnemyDeath();
                            result = 1;
                            state  = BattleState.END;
                        }
                        else
                        {
                            state = BattleState.ACTION;
                        }
                    }
                    break;

                case ActionType.ITEM:
                    //enemy attack
                    p_HP = Attack(enemy.GetATK(), p_HP, effective_stats[(int)Stat.DEF]);
                    statGen.addProb((int)Stat.DEF);    //DEFENCE INCREASES WHEN PLAYER IS HIT BY NORMAL ATTACK
                    battleUI.PlayerDefending();
                    if (debug)
                    {
                        Debug.Log("p_HP = " + p_HP);
                    }
                    yield return(new WaitForSecondsRealtime(delay));

                    if (p_HP <= 0)
                    {
                        battleUI.PlayerDeath();
                        result = -1;
                        state  = BattleState.END;
                    }
                    else
                    {
                        state = BattleState.ACTION;
                    }
                    //use item
                    if (used_item_prop.isEdible)    //heal
                    {
                        Heal(used_item_prop.Eat());
                        yield return(new WaitForSecondsRealtime(delay));
                    }
                    else if (used_item_prop.isEquipment)    //equip
                    {
                        UpdateStats();
                        yield return(new WaitForSecondsRealtime(delay));
                    }
                    break;

                case ActionType.SPECIAL:
                    //TODO: special stuff
                    break;
                }//switch end
            }
        }
        yield return(new WaitForSecondsRealtime(delay * 2));

        //do shit based on result of battle
        GameObject.FindGameObjectWithTag("ScreenWipe").GetComponent <Animator>().SetTrigger("Conceal");
        yield return(new WaitForSecondsRealtime(1));

        gameObject.GetComponent <UIManager>().MoveCanvas(GameObject.FindGameObjectWithTag("MainCanvas").GetComponent <Canvas>());
        player.SetCHP(p_HP);
        enemy.SetCHP(e_HP);
        if (result == 1)
        {
            EndWin();
        }
        else if (result == 2)
        {
            EndRun();
        }
        else
        {
            EndLose();
        }
        if (debug)
        {
            Debug.Log("BATTLELOOP END");
        }
    }