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(); }
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(); } }