Example #1
0
 public void AddCharacter(int classNumber)
 {
     CheckForDuplicates(classNumber);
     if (notAcceptable == true)
     {
         Debug.Log("This is not acceptable");
     }
     else
     {
         foreach (GenericPlayerChar toAddCharacter in playerParty)
         {
             if (toAddCharacter == null)
             {
                 slotNumber = playerParty.IndexOf(toAddCharacter);
             }
         }
         GenericPlayerChar tempHolder = playerParty[slotNumber];
         playerParty[slotNumber] = playerCharacterList[classNumber];
         string tempHolderClassName = tempHolder.classType.ToString();
         CheckTempHolder(tempHolderClassName);
         slotNumber++;
         if (slotNumber > 2)
         {
             slotNumber = 0;
         }
         Debug.Log(playerParty[0].classType);
         Debug.Log(playerParty[1].classType);
         Debug.Log(playerParty[2].classType);
     }
 }
Example #2
0
    private void SpecialAttackTarget()
    {
        if (BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Barbarian)
        {
            BattleController.instance.currentChar.isAggro = true;
            //PlayAttackSound(_attackSounds[0]);
        }
        else if (BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Cleric)
        {
            GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
            foreach (GameObject player in players)
            {
                GenericPlayerChar stats = player.GetComponent <GenericPlayerChar>();
                stats.Heal(stats.maxHealth / 3);
                PlayAttackSound(_attackSounds[1]);
            }
        }
        else if (BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Knight)
        {
            _target.GetComponent <GenericPlayerChar>().isShielded = true;
            //PlayAttackSound(_attackSounds[0]);
        }
        else if (BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Ranger)
        {
            int chanceToMiss = Random.Range(0, 101);
            if (chanceToMiss < BattleController.instance.currentChar.accuracy / 2)
            {
                int damage = (int)Mathf.Round(100 * (1 - ((float)_target.GetComponent <GenericPlayerChar>().defense / 100)));
                PlayAttackSound(_attackSounds[2]);
            }
        }
        else if (BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Rogue)
        {
            BattleController.instance.currentChar.isEvading = true;
            //PlayAttackSound(_attackSounds[0]);
        }
        else if (BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Wizard)
        {
            GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
            foreach (GameObject enemy in enemies)
            {
                GenericPlayerChar stats = enemy.GetComponent <GenericPlayerChar>();
                int damage = (int)Mathf.Round(BattleController.instance.currentChar.attack * (1 - ((float)stats.defense / 100)) / 2);
                stats.Hurt(damage);
            }
            PlayAttackSound(_attackSounds[4]);
        }

        BattleController.instance.currentChar.SetCooldown();
        BattleController.instance.NextTurn();
    }
 // Use this for initialization
 void Start()
 {
     _character = gameObject.GetComponent <GenericPlayerChar>();
     if (!_isEnemy)
     {
         _healthSlider = Instantiate(_sliderPrefab, transform.position + new Vector3(-1.4f, 2, 0), Quaternion.identity);
     }
     else
     {
         _healthSlider = Instantiate(_sliderPrefab, transform.position + new Vector3(4.4f, 2, 0), Quaternion.identity);
     }
     _healthSlider.transform.parent = GameObject.Find("Canvas").transform;
     _healthSlider.value            = gameObject.GetComponent <GenericPlayerChar>().health / 100;
 }
Example #4
0
    public void NextTurn()
    {
        if (!CheckIfBattleEnded())
        {
            _currentChar = _allUnits[0];
            _allUnits.Remove(_currentChar);

            if (_currentChar.health > 0)
            {
                _allUnits.Add(_currentChar);

                _turnPromptText.text = _currentChar.classType + "'s Turn";

                if (_currentChar.tag == "Player")
                {
                    currentChar.UpkeepCooldown();


                    //Upkeep for classes with lasting buffs.
                    if (currentChar.classType == GenericPlayerChar.CharClass.Barbarian)
                    {
                        currentChar.isAggro = false;
                    }
                    if (currentChar.classType == GenericPlayerChar.CharClass.Knight)
                    {
                        foreach (GenericPlayerChar chara in _allUnits)
                        {
                            chara.isShielded = false;
                        }
                    }
                    if (currentChar.classType == GenericPlayerChar.CharClass.Rogue)
                    {
                        currentChar.isEvading = false;
                    }

                    GameObject.Find("UIController").GetComponent <UIController>().SwitchAttackButtonVisibility(true, true);
                    GameObject.Find("UIController").GetComponent <UIController>().ChangeAttackButtonText();
                    CharacterInfoAndIconUIElement.iconName = currentChar.classType.ToString();
                    GameObject.Find("UIController").GetComponent <UIController>().SwitchAttackButtonVisibility(false, false);

                    if (currentChar.classType == GenericPlayerChar.CharClass.Barbarian ||
                        currentChar.classType == GenericPlayerChar.CharClass.Cleric ||
                        currentChar.classType == GenericPlayerChar.CharClass.Rogue ||
                        currentChar.classType == GenericPlayerChar.CharClass.Wizard)
                    {
                        GameObject.Find("UIController").GetComponent <UIController>().SwitchAttackButtonVisibility(false, true);
                    }
                }
                else
                {
                    GameObject.Find("UIController").GetComponent <UIController>().SwitchAttackButtonVisibility(false, false);
                    StartCoroutine("EnemyAttack");
                }
            }
            else
            {
                GameObject.Find("UIController").GetComponent <UIController>().SwitchAttackButtonVisibility(false, false);
                NextTurn();
            }
        }
    }
Example #5
0
    public IEnumerator PlayerAttack(GenericPlayerChar targetOfAttack)
    {
        //LERP MOVEMENT
        if (BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Barbarian ||
            BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Knight ||
            BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Barbarian ||
            BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Rogue)
        {
            currentCharPos = BattleController.instance.currentChar.transform.position;
            float startTimeAttack = Time.time;
            while (Time.time - startTimeAttack <= 2)
            {
                BattleController.instance.currentChar.gameObject.GetComponent <CharacterFlipper>().FlipFoward();
                BattleController.instance.currentChar.gameObject.GetComponent <Character>().Animator.SetBool("Movement", true);

                BattleController.instance.currentChar.gameObject.transform.position = Vector3.Lerp(BattleController.instance.currentChar.gameObject.transform.position, targetOfAttack.gameObject.transform.position + new Vector3(-1.5f, 0, 0), (Time.time - startTimeAttack) * 0.1f);
                //Animation PLAY HERE
                yield return(1);
            }

            BattleController.instance.currentChar.gameObject.GetComponent <Character>().Animator.SetBool("MeleeAttack", true);
            yield return(new WaitForSeconds(0.10f));

            BattleController.instance.currentChar.gameObject.GetComponent <Character>().Animator.SetBool("Movement", false);
            yield return(new WaitForSeconds(0.10f));



            yield return(new WaitForSeconds(1f));


            //SET DAMAGE
            int chanceToMiss = Random.Range(0, 101);
            if (chanceToMiss < BattleController.instance.currentChar.accuracy)
            {
                Debug.Log("attack hit");
                if (BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Barbarian ||
                    BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Knight ||
                    BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Rogue)
                {
                    int damage = (int)Mathf.Round(BattleController.instance.currentChar.attack * (1 - ((float)targetOfAttack.defense / 100)));
                    targetOfAttack.Hurt(damage);
                    PlayAttackSound(_attackSounds[0]);
                }
                else if (BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Ranger)
                {
                    int damage = (int)Mathf.Round(BattleController.instance.currentChar.attack * (1 - ((float)targetOfAttack.defense / 100)));
                    targetOfAttack.Hurt(damage);
                    PlayAttackSound(_attackSounds[2]);
                }
                else if (BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Wizard)
                {
                    int damage = (int)Mathf.Round(BattleController.instance.currentChar.attack * (1 - ((float)targetOfAttack.defense / 100)));
                    targetOfAttack.Hurt(damage);
                    PlayAttackSound(_attackSounds[3]);
                }
                else if (BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Cleric)
                {
                    targetOfAttack.Heal(targetOfAttack.maxHealth / 2);
                    PlayAttackSound(_attackSounds[1]);
                }
            }



            BattleController.instance.currentChar.gameObject.GetComponent <Character>().Animator.SetBool("MeleeAttack", false);


            yield return(new WaitForSeconds(1f));

            float startTime = Time.time;
            while (Time.time - startTime <= 2)
            {
                BattleController.instance.currentChar.gameObject.GetComponent <CharacterFlipper>().FlipBack();
                BattleController.instance.currentChar.gameObject.GetComponent <Character>().Animator.SetBool("Movement", true);

                BattleController.instance.currentChar.gameObject.transform.position = Vector3.Lerp(BattleController.instance.currentChar.gameObject.transform.position, GetPos(), (Time.time - startTime) * 0.1f);
                //Animation PLAY HERE


                //SOUND PLAY HERE
                yield return(1);
            }

            BattleController.instance.currentChar.gameObject.GetComponent <Character>().Animator.SetBool("Movement", false);
            BattleController.instance.currentChar.gameObject.GetComponent <CharacterFlipper>().FlipFoward();
            yield return(new WaitForSeconds(0.25f));

            BattleController.instance.NextTurn();
        }
        else if (BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Ranger ||
                 BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Wizard ||
                 BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Cleric)
        {
            //SET DAMAGE
            int chanceToMiss = Random.Range(0, 101);
            if (chanceToMiss < BattleController.instance.currentChar.accuracy)
            {
                Debug.Log("attack hit");
                if (BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Barbarian ||
                    BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Knight ||
                    BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Rogue)
                {
                    int damage = (int)Mathf.Round(BattleController.instance.currentChar.attack * (1 - ((float)targetOfAttack.defense / 100)));
                    targetOfAttack.Hurt(damage);
                    PlayAttackSound(_attackSounds[0]);
                }
                else if (BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Ranger)
                {
                    int damage = (int)Mathf.Round(BattleController.instance.currentChar.attack * (1 - ((float)targetOfAttack.defense / 100)));
                    targetOfAttack.Hurt(damage);
                    PlayAttackSound(_attackSounds[2]);
                }
                else if (BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Wizard)
                {
                    int damage = (int)Mathf.Round(BattleController.instance.currentChar.attack * (1 - ((float)targetOfAttack.defense / 100)));
                    targetOfAttack.Hurt(damage);
                    PlayAttackSound(_attackSounds[3]);
                }
                else if (BattleController.instance.currentChar.classType == GenericPlayerChar.CharClass.Cleric)
                {
                    targetOfAttack.Heal(targetOfAttack.maxHealth / 2);
                    PlayAttackSound(_attackSounds[1]);
                }
            }


            yield return(new WaitForSeconds(0.25f));

            BattleController.instance.NextTurn();
        }
    }
Example #6
0
 private void AttackTarget(GenericPlayerChar targetOfAttack)
 {
     StartCoroutine("PlayerAttack", targetOfAttack);
 }