Example #1
0
 //When our game starts, we want to set the DimragStateOne to START, and begin the setup.
 void Start()
 {
     state = DimragStateOne.START;
     skills.SetActive(false);
     dialogueBox.SetActive(true);
     //In order to have delay between battle setup and player turn, we need it to be a coroutine
     StartCoroutine(SetupBattle());
 }
Example #2
0
 public void OnHitButton()
 {
     if (state == DimragStateOne.PLAYERTURN)
     {
         //StartCoroutine (Hit ());
         dialogueText.text = "Please choose (click) the enemy you would like to attack.";
         state             = DimragStateOne.ENEMYSELECTHIT;
     }
 }
Example #3
0
 public void OnAttackButton()
 {
     actions.SetActive(false);
     //We want to make sure that if the player presses the attack button and it is not their turn, nothing happens
     if (state != DimragStateOne.PLAYERTURN)
     {
         return;
     }
     state = DimragStateOne.ENEMYSELECTSKILL;
     skills.SetActive(true);
 }
Example #4
0
    public void OnGuardButton()
    {
        //We want to make sure that if the player presses the attack button and it is not their turn, nothing happens
        if (state != DimragStateOne.PLAYERTURN)
        {
            return;
        }
        state = DimragStateOne.PLAYERACTION;

        StartCoroutine(PlayerGuard());
    }
Example #5
0
    IEnumerator PlayerGuard()
    {
        //playerUnit.HealDamage (5);
        //playerHUD.SetHP (playerUnit.currentHP);

        dialogueText.text = "You prepare for the next attack!";
        isGuarding        = true;

        yield return(new WaitForSeconds(2f));

        state = DimragStateOne.FIRSTENEMYTURN;
        StartCoroutine(FirstEnemyTurn());
    }
Example #6
0
 //This is attached to the skill button, so we are aware which button was pressed
 //Different from onAttackButton, because OnAttackButton only determines if player wishes to attack, not
 //what skill they choose.
 public void OnSkillSelected(Button button)
 {
     thisAttack = button.GetComponent <Attack>();
     Debug.Log(thisAttack.name);
     if (thisAttack.spCost > playerUnit.currentSP)
     {
         dialogueText.text = "Too little SP to use this skill, please try again";
     }
     else
     {
         playerUnit.currentSP -= thisAttack.spCost;
         state             = DimragStateOne.ENEMYSELECTSKILL;
         dialogueText.text = "Please select (click) an enemy to attack.";
     }
 }
Example #7
0
    IEnumerator sickDamage()
    {
        bool isDead = playerUnit.TakeDamage(playerUnit.maxHP / 20);

        playerHUD.SetHP(playerUnit.currentHP);

        dialogueText.text = "You take some damage from sickness!";

        yield return(new WaitForSeconds(2f));

        if (isDead)
        {
            state = DimragStateOne.LOST;
            StartCoroutine(EndBattle());
            yield break;
        }
        else
        {
            state = DimragStateOne.PLAYERTURN;
            PlayerTurn();
            yield break;
        }
    }
Example #8
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;
            }
        }
    }
Example #9
0
    IEnumerator SetupBattle()
    {
        //Instantiate both player and enemy into the battle
        enemiesAlive = 3;
        global       = GameObject.Find("GlobalObject");
        actions      = GameObject.Find("Actions");
        actions.SetActive(false);

        GameObject    player       = Instantiate(playerPrefab, playerBattleStation);
        GlobalControl globalObject = global.GetComponent <GlobalControl>();

        GameObject enemyOne   = (GameObject)Instantiate(Resources.Load("Capling"), enemyBattleStation);
        GameObject enemyTwo   = (GameObject)Instantiate(Resources.Load("Capling"), enemyBattleStation2);
        GameObject enemyThree = (GameObject)Instantiate(Resources.Load("Capling"), enemyBattleStation3);

        //Get the information about the enemy and player
        playerUnit = player.GetComponent <Player>();

        enemyUnitOne   = enemyOne.GetComponent <Enemy>();
        enemyUnitTwo   = enemyTwo.GetComponent <Enemy>();
        enemyUnitThree = enemyThree.GetComponent <Enemy>();

        playerLevel = player.GetComponent <PlayerLevel>();

        LoadPlayerData();

        playerHUD.SetPlayerHUD(playerUnit);

        storeMobility = playerLevel.stats[4];

        Debug.Log("Current player level: " + playerLevel.Level);
        Debug.Log("Player's HP when level is set: " + playerUnit.currentHP);
        playerUnit.attackList = new List <Attack>();

        setPlayerSkills();

        Debug.Log(playerUnit.attackList.Count);

        for (int i = 0; i < playerUnit.attackList.Count; i++)
        {
            GameObject newButton = Instantiate(skillPrefab, skillContent);
            Attack     toAdd     = newButton.GetComponent <Attack>();
            toAdd.SetValue(playerUnit.attackList[i].damage, playerUnit.attackList[i].type,
                           playerUnit.attackList[i].name, playerUnit.attackList[i].isSkill, playerUnit.attackList[i].spCost);
            newButton.GetComponentInChildren <Text>().text = toAdd.name;
            newButton.SetActive(true);
            print(toAdd.type);
        }

        print(playerUnit.attackList.Count);

        //StartCoroutine(ReadDialogue("Three Caplings appear in front of you!"));
        dialogueText.text = "Three Caplings appear in front of you!";

        playerUnit.unitLevel = playerLevel.Level;
        //passes in the information about player and enemy unit to set their hud displays
        playerHUD.SetPlayerHUD(playerUnit);

        enemyHUD.SetEnemyHUD(enemyUnitOne);
        enemyHUD2.SetEnemyHUD(enemyUnitTwo);
        enemyHUD3.SetEnemyHUD(enemyUnitThree);

        //This waits a second to progress
        yield return(new WaitForSeconds(2f));

        //Attack: 0
        //Defense: 1
        //Skill: 2
        //Technique: 3
        //Mobility: 4
        Debug.Log("Current Attack stat: " + playerLevel.stats[0]);
        Debug.Log("Current Defense stat: " + playerLevel.stats[1]);
        Debug.Log("Current Skill stat: " + playerLevel.stats[2]);
        Debug.Log("Current Technique stat: " + playerLevel.stats[3]);
        Debug.Log("Current Mobility stat: " + playerLevel.stats[4]);

        turnOrder   = new string[4];
        currentTurn = -1;

        if (playerLevel.stats[4] >= enemyUnitOne.stats[4])
        {
            turnOrder[0] = "Player";
            turnOrder[1] = "EnemyOne";
            turnOrder[2] = "EnemyTwo";
            turnOrder[3] = "EnemyThree";
            Debug.Log("Player attacks first");
            state = DimragStateOne.PLAYERTURN;
            PlayerTurn();
        }
        else
        {
            turnOrder[0] = "EnemyOne";
            turnOrder[1] = "EnemyTwo";
            turnOrder[2] = "EnemyThree";
            turnOrder[3] = "Player";
            Debug.Log("Enemy attacks first");
            state = DimragStateOne.FIRSTENEMYTURN;
            StartCoroutine(FirstEnemyTurn());
        }
    }
Example #10
0
    IEnumerator ThirdEnemyTurn()
    {
        dialogueText.text = "Third Capling's turn!";
        //StartCoroutine(ReadDialogue("Third Capling's turn!"));

        //while (!Input.GetMouseButtonDown(0))
        //{
        //	yield return null;
        //}
        yield return(new WaitForSeconds(2f));

        //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] - enemyUnitThree.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 = (enemyUnitThree.stats[2] * 2) - playerLevel.stats[3];
            }
            else
            {
                totalDamage = (enemyUnitThree.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;
                //}
                yield return(new WaitForSeconds(2f));

                playerLevel.stats[4] = 0;
                hasBubbleButt        = true;
                //yield return new WaitForSeconds(2f);
            }

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

            else
            {
                state = DimragStateOne.PLAYERTURN;
                PlayerTurn();
                yield break;
            }
        }
    }
Example #11
0
    IEnumerator PlayerAttack(Attack attack, String enemyToHit)
    {
        //damage the enemy
        bool isDead;

        //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);

        Enemy enemyUnit = enemyUnitOne;

        if (enemyToHit == "EnemyTwo")
        {
            enemyUnit = enemyUnitTwo;
        }
        else if (enemyToHit == "EnemyThree")
        {
            enemyUnit = enemyUnitThree;
        }

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

        //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 - (enemyUnitOne.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 = DimragStateOne.FIRSTENEMYTURN;
            StartCoroutine(FirstEnemyTurn());
        }

        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.
            totalDamage = (playerLevel.stats[2] * 2) - enemyUnit.stats[3];

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

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

            if (enemyUnit.type == "trash")
            {
                if (attack.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(attack.type);
                if (attack.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
            if (enemyToHit == "EnemyOne")
            {
                enemyHUD.SetHP(enemyUnitOne.currentHP);
            }
            else if (enemyToHit == "EnemyTwo")
            {
                enemyHUD2.SetHP(enemyUnitTwo.currentHP);
            }
            else
            {
                enemyHUD3.SetHP(enemyUnitThree.currentHP);
            }

            yield return(new WaitForSeconds(2f));

            //check if the enemy is dead
            //change state based on result
            if (isDead)
            {
                enemyUnit.isKilled = true;
                enemiesAlive      -= 1;
                dialogueText.text  = "You defeated " + enemyUnit.name + "!";
                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!";
                }
            }

            if (enemiesAlive == 0)
            {
                //End the battle
                state = DimragStateOne.WON;
                StartCoroutine(EndBattle());
            }
            else
            {
                //Enemy Turn
                if (!enemyUnitOne.isKilled)
                {
                    state = DimragStateOne.FIRSTENEMYTURN;
                    StartCoroutine(FirstEnemyTurn());
                }
                else if (!enemyUnitTwo.isKilled)
                {
                    state = DimragStateOne.SECONDENEMYTURN;
                    StartCoroutine(SecondEnemyTurn());
                }
                else
                {
                    state = DimragStateOne.THIRDENEMYTURN;
                    StartCoroutine(ThirdEnemyTurn());
                }
            }
        }
    }
Example #12
0
 public void OnBackSelected()
 {
     actions.SetActive(true);
     state = DimragStateOne.PLAYERTURN;
     PlayerTurn();
 }