/// <summary> /// Attack the player /// We won't do this like this eventually, but for now, this can be how it's done /// This needs to be fixed /// </summary> public IEnumerator Attack() { Debug.Log("we are calculating hit chance : " + targetUnit.armorType.ToString() + " " + damageType.ToString()); float hitChance = damageCalculations.calculateHitChance(targetUnit.armorType, damageType); bool criticalStrike = false; float criticalDamage = 1.0f; // tell our battle manager that we are done GameBoyBattleManager batMan = Camera.main.GetComponent <GameBoyBattleManager> (); double randomNum = Random.Range(0, 101) / 100.00; Debug.Log("MISS CHANCE : " + hitChance + " AND RANDOM ROLL : " + randomNum); if (randomNum > hitChance) { attackDodged = true; // start dodging attackDone = "'s attack is dodged by " + targetUnit.playerName + "!"; } float critChance = damageCalculations.calculateCritChance(targetUnit.armorType, damageType); // if we hit, then calculate to see if we got our crit if (!attackDodged && (randomNum <= hitChance * critChance)) { Debug.Log("RANDOM NUM : " + randomNum + " <= " + (hitChance * critChance)); criticalStrike = true; // otherwise, calculate crit chance anim.SetTrigger("IsAttacking"); attackFinished = false; hasRetreated = false; criticalDamage = 1.5f; } else { // otherwise, calculate crit chance anim.SetTrigger("IsAttacking"); attackFinished = false; hasRetreated = false; } // until the animation is done.... keep moving while (!attackFinished) { yield return(null); } // if critical strike, increase the damage dealt damageDealt = Mathf.RoundToInt(Random.Range(attackDamageBase * 0.8f, attackDamageBase * 1.2f) * criticalDamage); // If the player has health to lose... if (targetUnit.currentHealth > 0 && attackDodged == false) { // ... damage the player. targetUnit.underAttack = true; StartCoroutine(targetUnit.TakeDamage(damageDealt)); while (targetUnit.underAttack) { yield return(null); } attackDone = " attacks " + targetUnit.playerName; if (criticalStrike) { attackDone += ". Critical."; } } // reset our bool attackDodged = false; anim.SetTrigger("IsRetreating"); while (!hasRetreated) { yield return(null); } anim.SetTrigger("HasRetreated"); batMan.turnFinished = true; batMan.attackDone = attackDone; Toolbox.Instance.isLocked = false; yield return(new WaitForSeconds(0.3f)); }