Exemple #1
0
    IEnumerator EnemyTurn()
    {
        dialogueText.text = enemyUnit.unitName + "Attack!";

        yield return(new WaitForSeconds(2f));

        bool isDead = playerUnit.TakeDamage(enemyUnit.damage);

        yield return(new WaitForSeconds(1f));

        playerHUD.SetHP(playerUnit.currentHP);
        dialogueText.text = "You got hurt...";

        yield return(new WaitForSeconds(3f));

        if (isDead)
        {
            state = BattleState.LOST;
            EndBattle();
        }
        else
        {
            state = BattleState.PLAYERTURN;
            PlayerTurn();
        }
    }
Exemple #2
0
    void Battleturn()
    {
        #region 玩家的死亡判定

        bool isdead0 = player0unit.TakeDamage(player1unit.damage | player2unit.damage | player3unit.damage);
        bool isdead1 = player1unit.TakeDamage(player0unit.damage | player2unit.damage | player3unit.damage);
        bool isdead2 = player2unit.TakeDamage(player0unit.damage | player1unit.damage | player3unit.damage);
        bool isdead3 = player3unit.TakeDamage(player0unit.damage | player1unit.damage | player2unit.damage);
        #endregion

        #region 玩家的血量更新

        player0Hud.SetHP(player0unit.currentHP);
        player1Hud.SetHP(player1unit.currentHP);
        player2Hud.SetHP(player2unit.currentHP);
        player3Hud.SetHP(player3unit.currentHP);
        #endregion


        if (isdead0 || isdead1 || isdead2 || isdead3)
        {
            //如果死亡結束戰鬥
            state = BattleState.Won;
            //EndBattle();
        }



        else
        {
            state = BattleState.ChooseTurn;
            //回到戰鬥畫面
        }
    }
    IEnumerator PlayerHeal(Unit CurrentUnit)
    {
        CurrentUnit.Heal(CurrentUnit.damage);

        if (state == BattleState.PLAYERTURN)
        {
            playerHud.SetHP(CurrentUnit.currentHP);
        }
        else
        {
            Party2Hud.SetHP(CurrentUnit.currentHP);
        }

        dialogueText.text = CurrentUnit.unitName + " healed";

        BattleState currentstate = state;

        state = BattleState.NOATTACK;
        yield return(new WaitForSeconds(2f));

        state = currentstate;


        if (Party2Unit.currentHP > 0 && state == BattleState.PLAYERTURN)
        {
            state = BattleState.PARTY2TURN;
            Party2Turn();
        }
        else
        {
            state = BattleState.ENEMYTURN;
            StartCoroutine(enemyTurn());
        }
    }
Exemple #4
0
    IEnumerator PlayerHeal()
    {
        playerUnit.selected_minion.Heal(5);

        playerHUD.SetHP(playerUnit.currentHP);
        dialogueText.text = "You feel renewed strength!";

        if (extracting_simulation_data)
        {
            yield return(new WaitForSeconds(0f));
        }

        else
        {
            yield return(new WaitForSeconds(2f));
        }

        state = BattleState.ENEMYTURN;
        StartCoroutine(EnemyTurn());
    }
Exemple #5
0
    IEnumerator EnemyTurn()
    {
        //idk this is the best way I've found rn for sorting the enemy attacks. I think each attack will have its own function so
        //that this one doesn't get cluttered
        dialogueText.text = enemyUnit.unitName + " attacks!";

        yield return(new WaitForSeconds(1f));

        if (enemyUnit.unitName == "Wrapuchin")
        {
            StartCoroutine(wrapuchinAttacks());
        }
        else if (enemyUnit.unitName == "Octopeel")
        {
            StartCoroutine(octopeelAttacks());
        }
        else if (enemyUnit.unitName == "Twocan")
        {
            StartCoroutine(twocanAttacks());
        }
        else if (enemyUnit.unitName == "Glass Cannon")
        {
            StartCoroutine(glassCannonAttacks());
        }
        else if (enemyUnit.unitName == "Capling")
        {
            StartCoroutine(caplingAttacks());
        }
        else
        {
            bool isDead = playerUnit.TakeDamage(1);

            Debug.Log("Something went wrong...");
            playerHUD.SetHP(playerUnit.currentHP);

            yield return(new WaitForSeconds(1f));

            //bool isDead;
            if (isDead)
            {
                state = BattleState.LOST;
                StartCoroutine(EndBattle());
            }
            else
            {
                state = BattleState.PLAYERTURN;
                PlayerTurn();
            }
        }
    }
    IEnumerator PlayerAttack(Unit CurrentUnit)
    {
        bool isdead = enemyUnit.TakeDamage(CurrentUnit.damage);

        enemyHud.SetHP(enemyUnit.currentHP);
        dialogueText.text = enemyUnit.unitName + " took " + CurrentUnit.damage + " points of damage";

        if (CurrentUnit.unitName == "Player")
        {
            PlayerAnimation.Play("Player-Attack");
        }

        StartCoroutine(cameraShake.Shake(0.1f, 5f));

        BattleState currentstate = state;

        state = BattleState.NOATTACK;
        yield return(new WaitForSeconds(2f));

        state = currentstate;

        if (isdead)
        {
            state = BattleState.WON;
            EndBattle();
        }
        else
        {
            if (Party2Unit.currentHP > 0 && state == BattleState.PLAYERTURN)
            {
                state = BattleState.PARTY2TURN;
                Party2Turn();
            }
            else
            {
                state = BattleState.ENEMYTURN;
                StartCoroutine(enemyTurn());
            }
        }
    }
Exemple #7
0
    IEnumerator EnemyTurn()
    {
        dialogueText.text = enemyUnit.unitName + " Attacks";

        yield return(new WaitForSeconds(1f));

        bool isDead = playerUnit.TakeDamage(enemyUnit.damage);

        playerHUD.SetHP(playerUnit.currentHP);

        yield return(new WaitForSeconds(1f));

        if (isDead)
        {
            state = BattleState.LOST;
            EndBattle();
        }
        else
        {
            state = BattleState.PLAYERTURN;
            TechController.instance.DrawCard(3);
            playerTurn();
        }
    }
Exemple #8
0
    public bool TakeDamage(int dmg)
    {
        currentHP -= dmg;


        if (currentHP <= 0)
        {
            return(true);
        }
        else
        {
            return(false);
        }

        hud.SetHP(currentHP);
    }
Exemple #9
0
    public void TechPlayed(Techs lastTechPlayed)
    {
        //spend energy
        //playerUnit.SpendEnergy(lastTechPlayed.EnergyCost);
        //update energy HUD
        playerHUD.SetEnergy(playerUnit.currentEnergy);

        if (lastTechPlayed.doesDamage)
        {
            enemyUnit.TakeDamage(lastTechPlayed.damageAmount);
            enemyHUD.SetHP(enemyUnit.currentHP);
        }
        if (lastTechPlayed.restoresHP)
        {
            playerUnit.Heal(lastTechPlayed.healingAmount);
            playerHUD.SetHP(playerUnit.currentHP);
        }
    }
Exemple #10
0
    IEnumerator PlayerAttack()
    {
        bool isDead = enemyUnit.TakeDamage(playerUnit.damage);

        yield return(new WaitForSeconds(1f));

        enemyHUD.SetHP(enemyUnit.currentHP);
        dialogueText.text = "Attack damaged the enemy!";

        yield return(new WaitForSeconds(3f));

        if (isDead)
        {
            state = BattleState.WON;
            EndBattle();
        }
        else
        {
            state = BattleState.ENEMYTURN;
            StartCoroutine(EnemyTurn());
        }
    }
Exemple #11
0
    IEnumerator Hit(String enemyToHit)
    {
        state = DimragStateOne.PLAYERACTION;
        bool doesHit;

        Enemy enemyUnit = enemyUnitOne;

        if (enemyToHit == "EnemyOne")
        {
            enemyUnit = enemyUnitOne;
        }
        else if (enemyToHit == "EnemyTwo")
        {
            enemyUnit = enemyUnitTwo;
        }
        else if (enemyToHit == "EnemyThree")
        {
            Debug.Log("enemy three");
            enemyUnit = enemyUnitThree;
        }
        else
        {
            Debug.Log("Something went wrong in enemy select");
            yield break;
        }

        //need to check for hit before we can determine damage
        System.Random getRandom = new System.Random();
        int           randomNum = getRandom.Next(0, 101);

        dialogueText.text = "You attack the enemy!";

        int hitChance = 95 - (enemyUnit.stats[4] - playerLevel.stats[4]);

        if (hitChance < 50)
        {
            hitChance = 50;
        }

        if (randomNum < hitChance)
        {
            Debug.Log("Player hits!");
            doesHit = true;
        }
        else
        {
            Debug.Log("Player misses :(");
            doesHit = false;
        }

        //If the player's attack misses, all we need to do is let them know and then proceed with the enemy's turn
        if (!doesHit)
        {
            yield return(new WaitForSeconds(2f));

            dialogueText.text = "The attack missed!";
            state             = DimragStateOne.FIRSTENEMYTURN;
            StartCoroutine(FirstEnemyTurn());
        }

        //On a hit, we need to start with calculating base damage for the attack
        //Uses this formula: (Your Attack * 2) - (Opponent Defense) to a minimum of 1.
        int totalDamage = (playerLevel.stats[0] * 2) - enemyUnit.stats[1];

        if (totalDamage < 1)
        {
            totalDamage = 1;
        }

        bool isDead = enemyUnit.TakeDamage(totalDamage);

        if (enemyToHit == "EnemyOne")
        {
            enemyHUD.SetHP(enemyUnit.currentHP);
        }
        else if (enemyToHit == "EnemyTwo")
        {
            enemyHUD2.SetHP(enemyUnit.currentHP);;
        }
        else if (enemyToHit == "EnemyThree")
        {
            enemyHUD3.SetHP(enemyUnit.currentHP);
        }
        else
        {
            Debug.Log("Something went wrong in enemy select");
            yield break;
        }

        if (isDead)
        {
            enemyUnit.isKilled = true;
            enemiesAlive      -= 1;
            dialogueText.text  = "You defeated " + enemyUnit.unitName + "!";
            yield return(new WaitForSeconds(2f));

            //System.Random randomDrop = new System.Random();
            //int dropChance = randomDrop.Next(0, 101);
            //Debug.Log("drop number generated: " + dropChance);
            //if (dropChance <= enemyUnit.dropChance)
            //{
            //	dialogueText.text = "The enemy dropped a " + enemyUnit.itemName + "!";
            //	playerUnit.addItemFromDrop(enemyUnit.GetComponent<Item>());
            //	yield return new WaitForSeconds(2f);
            //}

            System.Random thisRandom   = new System.Random();
            int           itemsDropped = thisRandom.Next(1, 4);
            Debug.Log("number of items dropped: " + itemsDropped);
            for (int i = 0; i <= itemsDropped; i++)
            {
                playerUnit.addItemFromDrop(enemyUnit.GetComponent <Item>());
            }
            if (itemsDropped == 1)
            {
                dialogueText.text = "The enemy dropped a " + "seaweed scrap!";
            }
            else
            {
                dialogueText.text = "The enemy dropped " + itemsDropped + "seaweed scraps!";
            }
            yield return(new WaitForSeconds(2f));
        }

        //check if the enemy is dead
        //change state based on result
        if (enemiesAlive == 0)
        {
            //End the battle
            state = DimragStateOne.WON;
            StartCoroutine(EndBattle());
        }
        else
        {
            //Enemy Turn
            if (!enemyUnitOne.isKilled)
            {
                state = DimragStateOne.FIRSTENEMYTURN;
                StartCoroutine(FirstEnemyTurn());
                yield break;
            }
            else if (!enemyUnitTwo.isKilled)
            {
                state = DimragStateOne.SECONDENEMYTURN;
                StartCoroutine(SecondEnemyTurn());
                yield break;
            }
            else
            {
                state = DimragStateOne.THIRDENEMYTURN;
                StartCoroutine(ThirdEnemyTurn());
                yield break;
            }
        }
    }
Exemple #12
0
    IEnumerator FirstEnemyTurn()
    {
        dialogueText.text = "First Capling's turn!";
        //StartCoroutine(ReadDialogue("First Capling's turn!"));

        yield return(new WaitForSeconds(2f));

        //while (!Input.GetMouseButtonDown(0))
        //{
        //	yield return null;
        //}

        //There is a lot of randomness in enemy attacks, so it needs to start with randomly picking between x enemy attacks
        System.Random getRandom = new System.Random();

        int  randomNum        = getRandom.Next(1, 5);
        bool causesBubblebutt = false;

        //IDLE
        if (randomNum == 1)
        {
            dialogueText.text = "Capling tries to hoist a flag that is no longer there.";
            //StartCoroutine(ReadDialogue("Capling tries to hoist a flag that is no longer there."));
            //while (!Input.GetMouseButtonDown(0))
            //{
            //	yield return null;
            //}
            yield return(new WaitForSeconds(2f));

            state = DimragStateOne.PLAYERTURN;
            PlayerTurn();
            yield break;
            //ATTACK
        }
        else
        {
            if (randomNum == 2)
            {
                //Flavor text
                dialogueText.text = "Capling jumps down your throat.";

                //StartCoroutine(ReadDialogue("Capling jumps down your throat"));
                //while (!Input.GetMouseButtonDown(0))
                //{
                //	yield return null;
                //}

                yield return(new WaitForSeconds(2f));

                randomNum = getRandom.Next(1, 5);
                if (randomNum == 4)
                {
                    Debug.Log("bubblebutt :P");
                    causesBubblebutt = true;
                }
            }
            else
            {
                dialogueText.text = "Capling scratches you with its hook hand.";
                //StartCoroutine(ReadDialogue("Capling scratches  you with its hook hand"));

                //while (!Input.GetMouseButtonDown(0))
                //{
                //	yield return null;
                //}

                yield return(new WaitForSeconds(2f));
            }
            //Determine hit chance
            System.Random hitRandom = new System.Random();
            randomNum = hitRandom.Next(0, 101);

            int hitChance = 95 - (playerLevel.stats[4] - enemyUnitOne.stats[4]);

            if (hitChance < 50)
            {
                hitChance = 50;
            }

            //Determine if attack hits
            bool doesHit;
            if (randomNum < hitChance)
            {
                Debug.Log("Capling hits!");
                doesHit = true;
            }
            else
            {
                Debug.Log("Capling misses :(");
                doesHit = false;
            }

            //If attack does not hit, inform player and then switch back to PLAYERTURN
            if (!doesHit)
            {
                yield return(new WaitForSeconds(2f));

                dialogueText.text = "The attack missed!";
                //StartCoroutine(ReadDialogue("The attack missed!"));
                //while (!Input.GetMouseButtonDown(0))
                //{
                //	yield return null;
                //}
                yield return(new WaitForSeconds(2f));

                state = DimragStateOne.PLAYERTURN;
                PlayerTurn();
                yield break;
            }

            //If attack does hit, calculate damage
            //For Capling, damage changes depending on which of its two attacks it uses. If the randomNum generated is 2, it needs
            //to do skill damage and check for bubblebutt. 50% of the time is regular attack damage (randomNums 3 and 4)

            int totalDamage = 1;

            if (randomNum == 2)
            {
                Debug.Log(" a throat jump");
                totalDamage = (enemyUnitOne.stats[2] * 2) - playerLevel.stats[3];
            }
            else
            {
                totalDamage = (enemyUnitOne.stats[0] * 2) - playerLevel.stats[1];
            }

            if (totalDamage < 1)
            {
                totalDamage = 1;
            }

            Debug.Log("Total Enemy Damage by Capling: " + totalDamage);

            //Use this TakeDamage() function to deal the proper amount of damage to player
            bool isDead = playerUnit.TakeDamage(totalDamage);

            playerHUD.SetHP(playerUnit.currentHP);

            yield return(new WaitForSeconds(2f));

            if (causesBubblebutt)
            {
                dialogueText.text = "You have been inflicted with Bubblebutt. Gases built up inside of you cause you to float! Your mobility is reduced to 0.";
                //StartCoroutine(ReadDialogue("You have been inflicted with Bubblebutt. Gases built up inside of you cause you to float! Your mobility is reduced to 0."));
                //while (!Input.GetMouseButtonDown(0))
                //{
                //	yield return null;
                //}
                playerLevel.stats[4] = 0;
                hasBubbleButt        = true;
                yield return(new WaitForSeconds(2f));
            }

            if (isDead)
            {
                state = DimragStateOne.LOST;
                StartCoroutine(EndBattle());
                yield break;
            }

            else
            {
                if (!enemyUnitTwo.isKilled)
                {
                    state = DimragStateOne.SECONDENEMYTURN;
                    StartCoroutine(SecondEnemyTurn());
                    yield break;
                }
                else if (!enemyUnitThree.isKilled)
                {
                    state = DimragStateOne.THIRDENEMYTURN;
                    StartCoroutine(ThirdEnemyTurn());
                    yield break;
                }
                else
                {
                    state = DimragStateOne.PLAYERTURN;
                    PlayerTurn();
                    yield break;
                }
            }
        }
    }
    IEnumerator Hit(String enemyToHit)
    {
        state = SecondBattleState.PLAYERACTION;
        bool doesHit;

        Enemy enemyUnit = enemyUnitOne;

        if (enemyToHit == "EnemyOne")
        {
            enemyUnit = enemyUnitOne;
        }
        else if (enemyToHit == "EnemyTwo")
        {
            enemyUnit = enemyUnitTwo;
        }
        else if (enemyToHit == "EnemyThree")
        {
            Debug.Log("enemy three");
            enemyUnit = enemyUnitThree;
        }
        else
        {
            Debug.Log("Something went wrong in enemy select");
            yield break;
        }

        //need to check for hit before we can determine damage
        System.Random getRandom = new System.Random();
        int           randomNum = getRandom.Next(0, 101);

        dialogueText.text = "You attack the enemy!";

        int hitChance = 95 - (enemyUnit.stats [4] - playerLevel.stats [4]);

        if (hitChance < 50)
        {
            hitChance = 50;
        }

        if (randomNum < hitChance)
        {
            Debug.Log("Player hits!");
            doesHit = true;
        }
        else
        {
            Debug.Log("Player misses :(");
            doesHit = false;
        }

        //If the player's attack misses, all we need to do is let them know and then proceed with the enemy's turn
        if (!doesHit)
        {
            yield return(new WaitForSeconds(2f));

            dialogueText.text = "The attack missed!";
            state             = SecondBattleState.FIRSTENEMYTURN;
            StartCoroutine(FirstEnemyTurn());
        }

        //On a hit, we need to start with calculating base damage for the attack
        //Uses this formula: (Your Attack * 2) - (Opponent Defense) to a minimum of 1.
        int totalDamage = (playerLevel.stats [0] * 2) - enemyUnit.stats [1];

        if (totalDamage < 1)
        {
            totalDamage = 1;
        }

        bool isDead = enemyUnit.TakeDamage(totalDamage);

        if (enemyToHit == "EnemyOne")
        {
            enemyHUD.SetHP(enemyUnit.currentHP);
        }
        else if (enemyToHit == "EnemyTwo")
        {
            enemyHUD2.SetHP(enemyUnit.currentHP);;
        }
        else if (enemyToHit == "EnemyThree")
        {
            enemyHUD3.SetHP(enemyUnit.currentHP);
        }
        else
        {
            Debug.Log("Something went wrong in enemy select");
            yield break;
        }

        if (isDead)
        {
            enemyUnit.isKilled = true;
            enemiesAlive      -= 1;
            yield return(new WaitForSeconds(2f));

            dialogueText.text = "You killed " + enemyUnit.unitName;
            yield return(new WaitForSeconds(2f));
        }

        //dialogueText.text = "You hit the enemy!";
        yield return(new WaitForSeconds(2f));

        //check if the enemy is dead
        //change state based on result
        if (enemiesAlive == 0)
        {
            //End the battle
            state = SecondBattleState.WON;
            StartCoroutine(EndBattle());
        }
        else
        {
            //Enemy Turn
            if (!enemyUnitOne.isKilled)
            {
                state = SecondBattleState.FIRSTENEMYTURN;
                StartCoroutine(FirstEnemyTurn());
                yield break;
            }
            else if (!enemyUnitTwo.isKilled)
            {
                state = SecondBattleState.SECONDENEMYTURN;
                StartCoroutine(SecondEnemyTurn());
                yield break;
            }
            else
            {
                state = SecondBattleState.THIRDENEMYTURN;
                StartCoroutine(ThirdEnemyTurn());
                yield break;
            }
        }
    }
    IEnumerator FirstEnemyTurn()
    {
        dialogueText.text = "First Wrapuchin's turn!";
        yield return(new WaitForSeconds(2f));

        if (currentTurn == 3)
        {
            currentTurn = 0;
        }
        else
        {
            currentTurn++;
        }

        Debug.Log(currentTurn);
        //There is a lot of randomness in enemy attacks, so it needs to start with randomly picking between x enemy attacks
        System.Random getRandom = new System.Random();

        //Wrapuchin has 2 attacks, so we will pick between those.
        int randomNum = getRandom.Next(1, 3);

        //IDLE
        if (randomNum == 1)
        {
            dialogueText.text = "Wrapuchin thinks about what it did.";
            yield return(new WaitForSeconds(2f));

            if (!enemyUnitTwo.isKilled)
            {
                state = SecondBattleState.SECONDENEMYTURN;
                StartCoroutine(SecondEnemyTurn());
                yield break;
            }
            else if (!enemyUnitThree.isKilled)
            {
                state = SecondBattleState.THIRDENEMYTURN;
                StartCoroutine(ThirdEnemyTurn());
                yield break;
            }
            else
            {
                state = SecondBattleState.PLAYERTURN;
                PlayerTurn();
                yield break;
            }
            //ATTACK
        }
        else
        {
            //Flavor text
            dialogueText.text = "Wrapuchin swings towards you!";

            //Determine hit chance
            System.Random hitRandom = new System.Random();
            randomNum = hitRandom.Next(0, 101);

            int hitChance = 95 - (playerLevel.stats [4] - enemyUnitOne.stats [4]);

            if (hitChance < 50)
            {
                hitChance = 50;
            }

            //Determine if attack hits
            bool doesHit;
            if (randomNum < hitChance)
            {
                Debug.Log("Player hits!");
                doesHit = true;
            }
            else
            {
                Debug.Log("Player misses :(");
                doesHit = false;
            }

            //If attack does not hit, inform player and then switch back to PLAYERTURN
            if (!doesHit)
            {
                yield return(new WaitForSeconds(2f));

                dialogueText.text = "The attack missed!";
                state             = SecondBattleState.PLAYERTURN;
                PlayerTurn();
                yield break;
            }

            int totalDamage = (enemyUnitOne.stats [0] * 2) - playerLevel.stats [1];

            //If attack does hit, calculate damage
            if (totalDamage < 1 && isGuarding)
            {
                totalDamage = 0;
            }
            else if (isGuarding)
            {
                totalDamage = totalDamage / 2;
                Debug.Log("player is guarding");
            }

            if (totalDamage < 1 & isGuarding == false)
            {
                totalDamage = 1;
                Debug.Log("Player is not guarding");
            }

            Debug.Log("Total Enemy Damage by Wrapuchin: " + totalDamage);

            //Use this TakeDamage() function to deal the proper amount of damage to player
            bool isDead = playerUnit.TakeDamage(totalDamage);

            playerHUD.SetHP(playerUnit.currentHP);

            yield return(new WaitForSeconds(2f));

            if (isDead)
            {
                state = SecondBattleState.LOST;
                StartCoroutine(EndBattle());
                yield break;
            }
            else
            {
                if (!enemyUnitTwo.isKilled)
                {
                    state = SecondBattleState.SECONDENEMYTURN;
                    StartCoroutine(SecondEnemyTurn());
                    yield break;
                }
                else if (!enemyUnitThree.isKilled)
                {
                    state = SecondBattleState.THIRDENEMYTURN;
                    StartCoroutine(ThirdEnemyTurn());
                    yield break;
                }
                else
                {
                    state = SecondBattleState.PLAYERTURN;
                    PlayerTurn();
                    yield break;
                }
            }
        }
    }
Exemple #15
0
    void OnHealbutton()
    {
        Player.Heal(10);

        playerhud.SetHP(Player.currentHP);
    }
    public IEnumerator PlayerAttack(float damage, int attack)
    {
        if (attack == 0)
        {
            playerGO.GetComponent <CharacterAnimator>().baseAttack = true;
        }
        else if (attack == 1)
        {
            playerGO.GetComponent <CharacterAnimator>().specialAttack = true;
        }
        else if (attack == 2)
        {
            playerGO.GetComponent <CharacterAnimator>().ultimateAttack = true;
        }

        while (playerGO.GetComponent <CharacterAnimator>().baseAttack == true ||
               playerGO.GetComponent <CharacterAnimator>().specialAttack == true ||
               playerGO.GetComponent <CharacterAnimator>().ultimateAttack == true)
        {
            yield return(null);
        }

        bool isDead = enemyUnit.TakeDamage(Mathf.RoundToInt(damage));

        if (attack != 2)
        {
            usc.TakeDamage(Mathf.RoundToInt(damage));
        }

        enemyHUD.SetHP(enemyUnit.currentHP);

        if (isDead)
        {
            state = BattleState.WIN;
            EndBattle();
        }
        else
        {
            state = BattleState.ENEMYTURN;
            StartCoroutine(EnemyTurn());
        }

        IEnumerator EnemyTurn()
        {
            bool isDeadP = false;

            enemyGo.GetComponent <CharacterAnimator>().baseAttack = true;
            while (enemyGo.GetComponent <CharacterAnimator>().baseAttack == true)
            {
                yield return(null);
            }

            if (defenseCounter == 0)
            {
                isDeadP = playerUnit.TakeDamage(UnityEngine.Random.Range(enemyUnit.enemyMinDamage, enemyUnit.enemyMaxDamage + 1));
                if (ultimateHealCounter == 0)
                {
                    playerHUD.transform.Find("Slider").Find("Fill Area").Find("Fill").GetComponent <Image>().color = new Color(0.8207547f, 0.2748754f, 0.2748754f, 1f);
                }
            }
            else
            {
                defenseCounter--;
                playerGO.GetComponent <CharacterAnimator>().defend = true;
                while (playerGO.GetComponent <CharacterAnimator>().defend == true)
                {
                    yield return(null);
                }
            }

            if (ultimateHealCounter > 0)
            {
                ultimateHealCounter--;
                yield return(new WaitForSeconds(0.2f));

                playerUnit.currentHP += 10;
                if (playerUnit.currentHP > playerUnit.maxHP)
                {
                    playerUnit.currentHP = playerUnit.maxHP;
                }
                playerHUD.SetHP(playerUnit.currentHP);
                if (ultimateHealCounter == 0)
                {
                    playerHUD.transform.Find("Slider").Find("Fill Area").Find("Fill").GetComponent <Image>().color = new Color(0.8207547f, 0.2748754f, 0.2748754f, 1f);
                }
            }

            if (drCounter > 0)
            {
                isDeadP = playerUnit.TakeDamage(UnityEngine.Random.Range(Mathf.RoundToInt(enemyUnit.enemyMinDamage * 0.5f), Mathf.RoundToInt((enemyUnit.enemyMaxDamage + 1) * 0.5f)));
                drCounter--;
            }

            playerHUD.SetHP(playerUnit.currentHP);

            yield return(new WaitForSeconds(1f));

            if (isDeadP)
            {
                state = BattleState.LOST;
                EndBattle();
            }
            else
            {
                state = BattleState.PLAYERTURN;
            }
        }

        void EndBattle()
        {
            attackButtons.SetActive(false);
            if (state == BattleState.WIN)
            {
                enemyUnit.EnemyDie();
                levelScript.addXP(enemyUnit.xpDrop, attacksUnlocker);
                levelScript.WonBattle(transform.parent.name.Split('-')[1]);
                Note.SetActive(true);
                Text noteText = Note.GetComponentInChildren <Text>();
                noteText.text = "You Defeated " + EnemyPrefab.name + "\n\n";
                noteText.text = noteText.text + "XP: +" + enemyUnit.xpDrop.ToString() + "\n";
                noteText.text = noteText.text + "Gold: +" + enemyUnit.goldDrop.ToString();
            }
            else if (state == BattleState.LOST)
            {
                Note.SetActive(true);
                Text noteText = Note.GetComponentInChildren <Text>();
                noteText.text = "You Lost To " + EnemyPrefab.name + "\n\n";
                Note.transform.Find("Back").gameObject.SetActive(false);
                transform.parent.parent.parent.Find("Death").gameObject.SetActive(true);
            }
        }

        if (state != BattleState.WIN && state != BattleState.LOST)
        {
            attacking = false;
        }

        for (int i = 0; i < attacksUnlocker.coolDownCounters.Length; i++)
        {
            if (attacksUnlocker.coolDownCounters[i] > 0)
            {
                print(attacksUnlocker.coolDownCounters[i]);
                attacksUnlocker.coolDownCounters[i]--;
                attacksUnlocker.countDownCoolDown(i);
                if (attacksUnlocker.coolDownCounters[i] == 0)
                {
                    attacksUnlocker.EndCoolDown(i);
                }
            }
            else
            {
                attacksUnlocker.coolDownCounters[i] = 0;
            }
        }
    }
Exemple #17
0
    IEnumerator PlayerAttack()
    {
        if (bot_vs_bot && !playerAttack) //If the combat is simulated or spected by the player
        {
            enemyUnit.ChooseMinion();
            playerUnit.ChooseMinion(true);
        }

        if (playerUnit.selected_minion.speed >= enemyUnit.selected_minion.speed || playerAttack)
        {
            float damage_taken = enemyUnit.selected_minion.CalculateTakenDamage(playerUnit.selected_minion);
            enemyUnit.currentHP -= damage_taken;

            bool isDead = false;
            if (enemyUnit.currentHP <= 0)
            {
                isDead = true;
            }
            else
            {
                isDead = false;
            }

            enemyHUD.SetHP(enemyUnit.currentHP);
            dialogueText.text = playerUnit.selected_minion.name + ", attack!";


            if (extracting_simulation_data)
            {
                yield return(new WaitForSeconds(0f));
            }

            else
            {
                yield return(new WaitForSeconds(2f));
            }

            if (isDead)
            {
                state = BattleState.WON;
                enemyUnit.RestMinion();

                EndBattle();
                yield break;
            }

            if (playerAttack)
            {
                state = BattleState.ENDTURN;
                StartCoroutine(EndTurn());
            }

            else
            {
                state = BattleState.ENEMYTURN;
                StartCoroutine(EnemyTurn());
            }

            playerAttack = false;
        }

        else
        {
            state = BattleState.ENEMYTURN;
            StartCoroutine(EnemyTurn());
        }
    }
Exemple #18
0
    IEnumerator PlayerAttack(Button button)
    {
        //damage the enemy
        bool   isDead;
        Attack thisAttack = button.GetComponent <Attack>();

        //if the character uses a 'skill' attack vs an 'attack' attack, we need to remove SP so it's important to have a variable let
        //us know.
        //After the character selects a skill, we stop displaying them and instead display dialogue
        skills.SetActive(false);
        dialogueBox.SetActive(true);

        //Hit chance: 95% - (Opponent Mobility - Your Mobility) to a minimum of 50%
        bool doesHit;

        //need to check for hit before we can determine damage
        System.Random getRandom = new System.Random();
        int           randomNum = getRandom.Next(0, 101);

        dialogueText.text = "You attack the enemy!";

        int hitChance = 95 - (enemyUnit.stats [4] - playerLevel.stats [4]);

        if (hitChance < 50)
        {
            hitChance = 50;
        }

        if (randomNum < hitChance)
        {
            Debug.Log("Player hits!");
            doesHit = true;
        }
        else
        {
            Debug.Log("Player misses :(");
            doesHit = false;
        }

        //If the player's attack misses, all we need to do is let them know and then proceed with the enemy's turn
        if (!doesHit)
        {
            yield return(new WaitForSeconds(2f));

            dialogueText.text = "The attack missed!";
            yield return(new WaitForSeconds(2f));

            state = BattleState.ENEMYTURN;
            StartCoroutine(EnemyTurn());
        }

        int totalDamage = 1;

        //On a hit, we need to start with calculating base damage for the attack
        if (doesHit)
        {
            //Uses this formula: (Your Attack * 2) - (Opponent Defense) to a minimum of 1.
            if (!thisAttack.isSkill)
            {
                totalDamage = (playerLevel.stats [0] * 2) - enemyUnit.stats [1];
            }
            else
            {
                totalDamage = (playerLevel.stats [2] * 2) - enemyUnit.stats [3];
            }

            if (totalDamage < 1)
            {
                totalDamage = 1;
            }

            Debug.Log("Total Damage " + totalDamage);

            if (enemyUnit.type == "trash")
            {
                if (thisAttack.type == "trash")
                {
                    isDead            = enemyUnit.TakeDamage(totalDamage * 2 * thisAttack.damage);
                    dialogueText.text = "You deal extra damage with the correct waste disposal method!";
                }
                else
                {
                    isDead            = enemyUnit.TakeDamage(totalDamage * thisAttack.damage);
                    dialogueText.text = "There may be a more proper way to handle this enemy";
                }
            }
            else if (enemyUnit.type == "recycle")
            {
                print(thisAttack.type);
                if (thisAttack.type == "recycle")
                {
                    isDead            = enemyUnit.TakeDamage(totalDamage * 2 * thisAttack.damage);
                    dialogueText.text = "You deal extra damage with the correct waste disposal method!";
                }
                else
                {
                    isDead            = enemyUnit.TakeDamage(totalDamage * thisAttack.damage);
                    dialogueText.text = "There may be a more proper way to handle this enemy";
                }
            }
            else
            {
                if (thisAttack.type == "compost")
                {
                    isDead            = enemyUnit.TakeDamage(totalDamage * 2 * thisAttack.damage);
                    dialogueText.text = "You deal extra damage with the correct waste disposal method!";
                }
                else
                {
                    isDead            = enemyUnit.TakeDamage(totalDamage * thisAttack.damage);
                    dialogueText.text = "There may be a more proper way to handle this enemy";
                }
            }

            //We need to reset enemy HP after they take damage
            enemyHUD.SetHP(enemyUnit.currentHP);

            yield return(new WaitForSeconds(2f));

            //check if the enemy is dead
            //change state based on result
            if (isDead)
            {
                //End the battle
                state = BattleState.WON;
                StartCoroutine(EndBattle());
            }
            else
            {
                //Enemy Turn
                state = BattleState.ENEMYTURN;
                StartCoroutine(EnemyTurn());
            }
        }
    }