public void UseMagic(string skillName) { // Get the info of the skill. BattleSkills skillUsed = null; for (int i = 0; i < skillsList.Length; i++) { if (skillsList[i].skillName == skillName) { skillUsed = skillsList[i]; } } if (activeBattleCharacters[currentTurn].currentMP >= skillUsed.manaCost) { // Close the magic info and magic window. CloseAllWindows(); OpenTargetWindow(skillName); manaCost = skillUsed.manaCost; } else { // Not enough MP. battleNotifications.notificationsText.text = activeBattleCharacters[currentTurn].characterName + " does not have enough MP."; battleNotifications.Activate(); magicInfoWindow.SetActive(false); } }
// Open the magic info window. public void OpenMagicInfoWindow(string skillName) { magicInfoWindow.SetActive(true); useMagicButton.skillName = skillName; // Get the info of the skill. BattleSkills skillUsed = null; for (int i = 0; i < skillsList.Length; i++) { if (skillsList[i].skillName == skillName) { skillUsed = skillsList[i]; } } magicNameText.text = skillUsed.skillName; if (skillUsed.isAHealMove) { magicPowerText.text = "Factor: " + (skillUsed.damagePower * (-100)).ToString() + "%"; } else { magicPowerText.text = "Power: " + (skillUsed.damagePower * 100).ToString() + "%"; } magicMPCostText.text = "MP: " + skillUsed.manaCost.ToString(); magicInfoText.text = skillUsed.skillInfo; }
// Let the enemy attack. private IEnumerator EnemyAttack() { List <int> characters = new List <int>(); for (int i = 0; i < activeBattleCharacters.Count; i++) { if (activeBattleCharacters[i].isPlayer && activeBattleCharacters[i].currentHP > 0) { characters.Add(i); } } //Target to attack of the enemy int target = characters[Random.Range(0, characters.Count)]; BattleSkills skillUsed = null; // Select a skill to use. int selectedAttack = Random.Range(0, activeBattleCharacters[currentTurn].skillsAvailable.Length); for (int i = 0; i < skillsList.Length; i++) { if (skillsList[i].skillName == activeBattleCharacters[currentTurn].skillsAvailable[selectedAttack]) { skillUsed = skillsList[i]; } } // Roll the dice to get the dice values. Dice.selfReference.playerNumberOfDiceFaces = activeBattleCharacters[target].numberOfDiceFaces; Dice.selfReference.enemyNumberOfDiceFaces = activeBattleCharacters[currentTurn].numberOfDiceFaces; yield return(StartCoroutine(Dice.selfReference.RollTheDice())); yield return(new WaitForSeconds(0.5f)); // Play the enemy's attack effect. if (activeBattleCharacters[currentTurn].isABoss) { activeBattleCharacters[currentTurn].GetComponent <Animator>().SetTrigger("Attack"); } else { Instantiate(enemyAttackEffect, activeBattleCharacters[currentTurn].transform.position, activeBattleCharacters[currentTurn].transform.rotation); } //Play the skill's animation. Instantiate(skillUsed.visualEffect, activeBattleCharacters[target].transform.position, activeBattleCharacters[target].transform.rotation); // Inflict damage/heal a target int damageInflicted = inflictDamage(target, skillUsed.damagePower, skillUsed.isAHealMove, Dice.selfReference.enemyValue, Dice.selfReference.playerValue); activeBattleCharacters[target].currentHP -= damageInflicted; DamagePopup.Create(activeBattleCharacters[target].transform.position, System.Math.Abs(damageInflicted), false); // Update stats to the screen. UpdateStats(); }
// Open the target window. public void OpenTargetWindow(string skillName) { targetWindow.SetActive(true); // A list of targets. List <int> targets = new List <int>(); // Get the info of the skill. BattleSkills skillUsed = null; for (int i = 0; i < skillsList.Length; i++) { if (skillsList[i].skillName == skillName) { skillUsed = skillsList[i]; } } // If it is a heal move, the targets are members of the team. for (int i = 0; i < activeBattleCharacters.Count; i++) { if (!skillUsed.isAHealMove) { if (!activeBattleCharacters[i].isPlayer) { targets.Add(i); } } else { if (activeBattleCharacters[i].isPlayer) { targets.Add(i); } } } // Update the target buttons. for (int i = 0; i < targetButtons.Length; i++) { if (targets.Count > i && activeBattleCharacters[targets[i]].currentHP > 0) { targetButtons[i].gameObject.SetActive(true); targetButtons[i].skillName = skillName; targetButtons[i].target = targets[i]; targetButtons[i].targetName.text = activeBattleCharacters[targets[i]].characterName; } else { targetButtons[i].gameObject.SetActive(false); } } }
// Let a player attack (coroutine function). private IEnumerator PlayerAttackCo(string skillName, int target) { // Close the target window targetWindow.SetActive(false); // Let the game know the player is attacking. playerIsAttacking = true; BattleSkills skillUsed = null; for (int i = 0; i < skillsList.Length; i++) { if (skillsList[i].skillName == skillName) { skillUsed = skillsList[i]; } } // Roll the dice to get the dice values. Dice.selfReference.playerNumberOfDiceFaces = activeBattleCharacters[currentTurn].numberOfDiceFaces; Dice.selfReference.enemyNumberOfDiceFaces = activeBattleCharacters[target].numberOfDiceFaces; yield return(StartCoroutine(Dice.selfReference.RollTheDice())); yield return(new WaitForSeconds(0.5f)); // Play the attack animation of the battle character. activeBattleCharacters[currentTurn].GetComponent <Animator>().SetTrigger("Attack"); yield return(new WaitForSeconds(0.5f)); //Play the skill's animation. Instantiate(skillUsed.visualEffect, activeBattleCharacters[target].transform.position, activeBattleCharacters[target].transform.rotation); // Inflict damage/heal a target int damageInflicted = inflictDamage(target, skillUsed.damagePower, skillUsed.isAHealMove, Dice.selfReference.playerValue, Dice.selfReference.enemyValue); activeBattleCharacters[target].currentHP -= damageInflicted; DamagePopup.Create(activeBattleCharacters[target].transform.position, System.Math.Abs(damageInflicted), false); // Update stats to the screen. UpdateStats(); yield return(new WaitForSeconds(0.5f)); // Let the game know the player is not attacking. playerIsAttacking = false; NextTurn(); }