void LoadAttackState() { FEFriendlyUnit playerStats = player.GetComponent <FEFriendlyUnit>(); FEHostileUnit enemyStats = null; playerAnimator = player.GetComponent <Animator>(); enemyStats = enemy.GetComponent <CursorBlock>().enemy.GetComponent <FEHostileUnit>(); int accuracy = 69; if (enemy == null) { attacking = false; Debug.Log("No Enemy"); return; } int playerChance = accuracy + playerStats.skl * 2 + playerStats.lck / 2; int enemyChance = accuracy + enemyStats.skl * 2 + enemyStats.lck / 2; bool playerHit = (Random.Range(0, 100) <= playerChance); bool enemyHit = (Random.Range(0, 100) <= enemyChance); if (playerHit) { attacking = true; GetComponent <AudioSource>().PlayOneShot(hitSound); attackAnimation = StartCoroutine("AttackAnimation"); playerAnimator.SetBool("attackPhase", attacking); bool crit = (Random.Range(0, 100) <= playerStats.lck); bool outSpeed = playerStats.GetCurrentSpd() > (enemyStats.GetCurrentSpd() + 5); int damage = playerStats.atk - enemyStats.def; if (damage <= 1) { damage = 1; } if (outSpeed) { damage *= 2; } if (crit) { GetComponent <AudioSource>().PlayOneShot(critSound); damage *= 3; } if (damage >= enemyStats.GetCurrentHP()) { enemy.GetComponent <CursorBlock>().enemy.GetComponent <FEHostileUnit>().SendMessage("TakeDamage", damage); enemy = null; } else { enemy.GetComponent <CursorBlock>().enemy.GetComponent <FEHostileUnit>().SendMessage("TakeDamage", damage); } } if (enemyStats && enemy != null) { bool crit = (Random.Range(0, 100) <= playerStats.lck); bool outSpeed = enemyStats.GetCurrentSpd() > (playerStats.GetCurrentSpd() + 5); int damage = enemyStats.atk - playerStats.def; if (damage <= 1) { damage = 1; } if (outSpeed) { damage *= 2; } if (crit) { damage *= 3; } player.GetComponent <FEFriendlyUnit>().SendMessage("TakeDamage", damage); } attacking = false; }
IEnumerator MoveUnits() { while (!turnOver) { FEHostileUnit stats = units[currentUnit]; if (units[currentUnit].fade == null && units[currentUnit] != null) { FEFriendlyUnit playerStats = GameObject.Find("unit").GetComponent <FEFriendlyUnit>(); Vector3 position = stats.gameObject.transform.position; Vector3 playerPos = GameObject.Find("unit").transform.position; bool attack = false; GameObject player = null; foreach (var block in stats.blocking) { if (block.GetComponent <EnemyBlock>().canAttack) { attack = true; player = block.GetComponent <EnemyBlock>().player; } } if (attack) { int accuracy = 69; playerStats = player.GetComponent <FEFriendlyUnit>(); int playerChance = accuracy + playerStats.skl * 2 + playerStats.lck / 2; int chance = accuracy + stats.skl * 2 + stats.lck / 2; bool playerHit = (Random.Range(0, 100) <= playerChance); bool hit = (Random.Range(0, 100) <= chance); GetComponent <AudioSource>().PlayOneShot(hitSound); yield return(StartCoroutine("AttackAnimation")); if (hit) { bool crit = (Random.Range(0, 100) <= stats.lck); bool outSpeed = (stats.GetCurrentSpd() > (playerStats.GetCurrentSpd() + 5)); int damage = stats.atk - playerStats.def; if (damage <= 1) { damage = 1; } if (outSpeed) { damage *= 2; } if (crit) { GetComponent <AudioSource>().PlayOneShot(critSound); damage *= 3; } player.GetComponent <FEFriendlyUnit>().SendMessage("TakeDamage", damage); if (damage >= playerStats.GetCurrentHP()) { player = null; } } if (playerHit && player != null) { bool crit = (Random.Range(0, 100) <= playerStats.lck); bool outSpeed = (playerStats.GetCurrentSpd() > (stats.GetCurrentSpd() + 5)); int damage = playerStats.atk - stats.def; if (damage <= 1) { damage = 1; } if (outSpeed) { damage *= 2; } if (crit) { damage *= 3; } units[currentUnit].SendMessage("TakeDamage", damage); } unitMoves = 0; currentUnit++; if (currentUnit >= units.Length) { turnOver = true; break; } } else if (unitMoves < stats.mov && tempCounter == 0) { if (playerPos.y > position.y) { // Player north if (!stats.blocked[0]) { position.y += movSpeed; } else if (playerPos.x > position.x && !stats.blocked[2]) { position.x += movSpeed; } else if (playerPos.x < position.x && !stats.blocked[3]) { position.x -= movSpeed; } else if (!stats.blocked[1]) { position.y -= movSpeed; } } else if (playerPos.y < position.y) { // Player south if (!stats.blocked[1]) { position.y -= movSpeed; } else if (playerPos.x > position.x && !stats.blocked[2]) { position.x += movSpeed; } else if (playerPos.x < position.x && !stats.blocked[3]) { position.x -= movSpeed; } else if (!stats.blocked[0]) { position.y += movSpeed; } } else if (playerPos.x > position.x) { // Player east if (!stats.blocked[2]) { position.x += movSpeed; } else if (playerPos.y > position.y && !stats.blocked[0]) { position.y += movSpeed; } else if (playerPos.y < position.y && !stats.blocked[1]) { position.x -= movSpeed; } else if (!stats.blocked[3]) { position.x -= movSpeed; } } else if (playerPos.x < position.x) { // Player west if (!stats.blocked[3]) { position.x -= movSpeed; } else if (playerPos.y > position.y && !stats.blocked[0]) { position.y += movSpeed; } else if (playerPos.y < position.y && !stats.blocked[1]) { position.x -= movSpeed; } else if (!stats.blocked[2]) { position.x += movSpeed; } } unitMoves++; stats.gameObject.transform.position = position; tempCounter = 7; } else if (tempCounter > 0) { tempCounter--; } else { unitMoves = 0; currentUnit++; if (currentUnit >= units.Length) { turnOver = true; break; } } } else if (units[currentUnit] == null) { currentUnit++; } yield return(null); } StopCoroutine(moveUnits); moveUnits = null; }