Esempio n. 1
0
    //------------------------------------
    //Traditional system
    //-------------------------------------
    //[SerializeField]
    //private GameObject[] Units = new GameObject[4];
    //[SerializeField]
    //private int turnNumber = 0;

    //private void Start()
    //{
    //    //make a clone of player party in this scene
    //    this.playerParty = GameObject.Find("PlayerParty");

    //    StartParty();

    //    //create a list of ACTIVE player units
    //    GameObject[] playerUnits = GameObject.FindGameObjectsWithTag("PlayerUnit");

    //    //find enemies
    //    GameObject[] enemyUnits = GameObject.FindGameObjectsWithTag("EnemyUnit");

    //     Units[0] = playerUnits[0]; //Miku
    //     Units[1] = enemyUnits[0]; //1st enemy
    //     Units[2] = playerUnits[1]; //Miku's friend
    //     Units[3] = enemyUnits[1]; //1st enemy

    //        this.actionsMenu.SetActive(false);
    //        this.enemyUnitsMenu.SetActive(false);
    //        this.gameOverMenu.SetActive(false);

    //    this.nextTurn();

    //}
    //public void nextTurn()
    //{
    //    //check for win requirements
    //    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();

    //    }

    //    //check for lose requirements
    //    GameObject[] remainingPlayerUnits = GameObject.FindGameObjectsWithTag("PlayerUnit");
    //    if (remainingPlayerUnits.Length == 0)
    //    {

    //        // game Over
    //        if (gameOverMenu != null)
    //        {
    //            //TODO: play GameOver SFX
    //            actionsMenu.SetActive(false);
    //            gameOverMenu.SetActive(true);
    //        }
    //    }

    //    //check whose turn
    //    if (turnNumber % 2 == 0)
    //    {//player turn
    //         if (Units[turnNumber].GetComponent<UnitStatFunctions>().isDead() == false )
    //        {
    //            //player isn't dead
    //            //regen Mana + 5% each player turn
    //            Units[turnNumber].GetComponent<UnitStats>().mana += (Units[turnNumber].GetComponent<UnitStats>().maxMana / 100) * 5;
    //            Units[turnNumber].GetComponent<UnitStatFunctions>().mana += (Units[turnNumber].GetComponent<UnitStatFunctions>().maxMana / 100) * 5;
    //            if (Units[turnNumber].GetComponent<UnitStats>().mana > Units[turnNumber].GetComponent<UnitStats>().maxMana)
    //            {
    //                Units[turnNumber].GetComponent<UnitStats>().mana = Units[turnNumber].GetComponent<UnitStats>().maxMana;
    //            }
    //            if (Units[turnNumber].GetComponent<UnitStatFunctions>().mana > Units[turnNumber].GetComponent<UnitStatFunctions>().maxMana)
    //            {
    //                Units[turnNumber].GetComponent<UnitStatFunctions>().mana = Units[turnNumber].GetComponent<UnitStatFunctions>().maxMana;
    //            }

    //            this.playerParty.GetComponent<SelectUnit>().selectCurrentUnit(Units[turnNumber].gameObject);
    //        }
    //        else
    //        {
    //            IncreaseTurn();
    //        }
    //    }
    //    else
    //    {//enemy turn
    //        if (Units[turnNumber] != null)
    //        {//check if enemy is dead or deleted
    //            Units[turnNumber].GetComponent<EnemyUnitAction>().act();
    //            //wait until animation ends somehow
    //        }
    //        else
    //        {
    //            IncreaseTurn();
    //            nextTurn();
    //        }
    //    }
    //}

    //public void IncreaseTurn()
    //{        //if out of array loop around again
    //    if (turnNumber < 3)
    //    {
    //        turnNumber++;
    //    }
    //    else
    //    {
    //        turnNumber = 0;
    //    }

    //}
    //---------------------------
    //RPGMaker Style system-------------------
    //-----------------------------

    void Start()
    {
        //make a clone of player party in this scene
        this.playerParty = GameObject.Find("PlayerParty");

        StartParty();

        //create a list of ACTIVE player units
        GameObject[] playerUnits = GameObject.FindGameObjectsWithTag("PlayerUnit");

        //use the new list to get the player stats
        unitsStats = new List <UnitStatFunctions>();
        foreach (GameObject playerUnit in playerUnits)
        {
            UnitStatFunctions currentUnitStats = playerUnit.GetComponent <UnitStatFunctions>();
            currentUnitStats.GetComponent <UnitStatFunctions>().calculateNextActTurn(0);
            unitsStats.Add(currentUnitStats);
        }
        GameObject[] enemyUnits = GameObject.FindGameObjectsWithTag("EnemyUnit");
        foreach (GameObject enemyUnit in enemyUnits)
        {
            //update enemy stats before battle starts
            enemyUnit.GetComponent <UnitStatFunctions>().updateStats();
            UnitStatFunctions currentUnitStats = enemyUnit.GetComponent <UnitStatFunctions>();
            currentUnitStats.GetComponent <UnitStatFunctions>().calculateNextActTurn(0);
            unitsStats.Add(currentUnitStats);
        }

        //sets active scene to the currently overlayed level
        //   SceneManager.SetActiveScene(SceneManager.GetSceneByName("Battle1"));

        unitsStats.Sort();

        this.actionsMenu.SetActive(false);
        this.enemyUnitsMenu.SetActive(false);
        this.gameOverMenu.SetActive(false);

        this.nextTurn();
    }
Esempio n. 2
0
    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();
        }
    }