public void tryRunning() { //play audio if (audio != null) { audio.Play(); } float randomNumber = Random.value; //if there is a boss you cannot escape //check if they are able to run from battle by using a random number if (boss == false && randomNumber < this.runnningChance) { gameManager = FindObjectOfType <GameManager1>(); if (gameManager != null) { gameManager.UpdateLevelScene(); } //delete the enemies enemyUnits = GameObject.FindGameObjectsWithTag("EnemyUnit"); foreach (GameObject enemyUnit in enemyUnits) { Destroy(enemyUnit); } GameObject turnSystem = GameObject.Find("TurnSystem"); if (turnSystem != null) { turnSystem.GetComponent <TurnSystem1>().revivePlayers(); turnSystem.GetComponent <TurnSystem1>().controlPlayers(); } //if you escape delete the battle camera GameObject gameCamera = GameObject.Find("Main Camera"); Destroy(gameCamera); } else { //next turn GameObject turnSystem = GameObject.Find("TurnSystem"); // turnSystem.GetComponent<TurnSystem1>().IncreaseTurn(); GameObject.Find("PlayerParty").GetComponent <SelectUnit>().setMenus(); turnSystem.GetComponent <TurnSystem1>().nextTurn(); } }
public void nextTurn() { GameObject[] remainingEnemyUnits = GameObject.FindGameObjectsWithTag("EnemyUnit"); if (remainingEnemyUnits.Length == 0) { this.enemyEncounter.GetComponent <CollectReward>().collectReward(); //no enemies left //unload current level BGM.Stop(); //Re-enable the disabled/unconscious party members revivePlayers(); controlPlayers(); GameManager1 gameManager = FindObjectOfType <GameManager1>(); gameManager.UpdateLevelScene(); } GameObject[] remainingPlayerUnits = GameObject.FindGameObjectsWithTag("PlayerUnit"); if (remainingPlayerUnits.Length == 0) { // game Over if (gameOverMenu != null) { //TODO: play GameOver SFX actionsMenu.SetActive(false); gameOverMenu.SetActive(true); } } UnitStatFunctions currentUnitStats = unitsStats[0]; unitsStats.Remove(currentUnitStats); //if the current unit has stats and isn't dead if (currentUnitStats != null && !currentUnitStats.GetComponent <UnitStatFunctions>().isDead()) { GameObject currentUnit = currentUnitStats.gameObject; //set the current unit Here CurrentPlayer = currentUnit; currentUnitStats.GetComponent <UnitStatFunctions>().calculateNextActTurn(currentUnitStats.nextActTurn); unitsStats.Add(currentUnitStats); unitsStats.Sort(); if (currentUnit.tag == "PlayerUnit") { //regen Mana + 5% each player turn currentUnit.GetComponent <UnitStatFunctions>().mana += (currentUnit.GetComponent <UnitStatFunctions>().maxMana / 100) * 5; if (currentUnit.GetComponent <UnitStatFunctions>().mana > currentUnit.GetComponent <UnitStatFunctions>().maxMana) { currentUnit.GetComponent <UnitStatFunctions>().mana = currentUnit.GetComponent <UnitStatFunctions>().maxMana; } this.playerParty.GetComponent <SelectUnit>().selectCurrentUnit(currentUnit.gameObject); } else { currentUnit.GetComponent <EnemyUnitAction>().act(); } } else { this.nextTurn(); } }