/// <summary>
    /// method, that handles current situation
    /// </summary>
    /// <param name="id">id of current situation</param>
    /// <param name="distanceToWalk">distance that needs to be walked</param>
    /// <param name="startBattle">true, if battle should start</param>
    /// <returns></returns>
    private IEnumerator WaitTillDistanceWalked(int id, double distanceToWalk,
                                               bool startBattle)
    {
        if (startBattle)
        {
            yield return(new WaitUntil(() => battleManager.BattleOver));
        }

        // do some "walking"
        if (!turnOffWalkingRequirement && distanceToWalk > 0)
        {
            textWhenWalking.gameObject.SetActive(true);
            decisionsPanel.gameObject.SetActive(false);
            currentSituation.gameObject.SetActive(false);

            if (!startSet)
            {
                textWhenWalking.SetStart(manager.profile.GetDistanceTraveled(), distanceToWalk);
                startSet = true;
            }

            yield return(new WaitUntil(() => distanceToWalk - textWhenWalking.Distance <= 0));

            startSet = false;

            textWhenWalking.gameObject.SetActive(false);
            decisionsPanel.gameObject.SetActive(true);
            currentSituation.gameObject.SetActive(true);
        }
        // flush current options
        decisionsPanel.Flush();
        // set new id for current situation
        currentSituationID = id;
        Situation current = chapters[currentChapterID].situations[currentSituationID];

        currentSituation.text = current.description;

        CharacterSelection charSel  = current as CharacterSelection;
        Navigation         navi     = current as Navigation;
        Dialogue           dialogue = current as Dialogue;
        GameOverSituation  gameOver = current as GameOverSituation;

        if (!characterChosen && !(current is CharacterSelection))
        {
            for (int i = 0; i < starterModels.Length; i++)
            {
                if (starterModels[i].isActiveAndEnabled)
                {
                    player  = starterClasses[i].Init(transform.parent, Vector3.zero, Quaternion.identity);
                    classID = i;
                }
            }
            Destroy(starterModels[0].transform.parent.gameObject);
            playerLifebar.SetFighter(player);
            player.SetLifebar(playerLifebar);
            player.gameObject.SetActive(false);
            characterChosen = true;
        }
        if (charSel == null && navi != null)
        {
            foreach (NextPoint info in (current as Navigation).options)
            {
                InstantiateDecision(info);
            }
        }
        if (dialogue != null)
        {
            foreach (DialogueOption info in dialogue.options)
            {
                InstantiateDecision(info);
            }

            for (int i = 0; i < dialogue.enemies.Length; i++)
            {
                Enemy enemy = Instantiate(dialogue.enemies[i], dialogue.enemyPosition[i],
                                          Quaternion.Euler(dialogue.enemyRotation[i]));
                battleManager.AddEnemy(enemy);
            }
        }
        if (charSel != null)
        {
            for (int i = 0; i < starterModels.Length; i++)
            {
                starterModels[i].gameObject.SetActive(i == charSel.classID);
            }
            foreach (NextPoint info in (current as Navigation).options)
            {
                InstantiateDecision(info);
            }
        }
        if (current.flushDeadEnemies)
        {
            foreach (GameObject gameObject in destroyOnSituationChange)
            {
                Destroy(gameObject);
            }
            destroyOnSituationChange = new List <GameObject>();
        }
        if (current.important)
        {
            PlotPoint plotPoint = new PlotPoint();
            plotPoint.chapter   = currentChapterID;
            plotPoint.situation = currentSituationID;
            pathPlayerTook.Add(plotPoint);
        }
        if (gameOver != null)
        {
            if (gameOver.vfx != null)
            {
                ParticleSystem gameOverVFX = Instantiate(gameOver.vfx, player.transform.position,
                                                         player.transform.rotation, transform);
                gameOverVFX.Play();
            }
            yield return(new WaitForSeconds(3f));

            SceneManager.LoadScene(4);
        }
        if (dialogue == null || dialogue.dialogueStart)
        {
            cam.UpdateCamPositionAndRotation(current.camPosition, Quaternion.Euler(current.camRotation));
            cam.SetSpotlight(current.spotlightRange);
        }
        try
        {
            foreach (int i in current.activateGameObject)
            {
                toggleableObjects[i].gameObject.SetActive(true);
            }
            foreach (int i in current.deactivateGameObject)
            {
                toggleableObjects[i].gameObject.SetActive(false);
            }
        }
        catch (NullReferenceException) { }
    }
Ejemplo n.º 2
0
 public void AddEnemyToBattle()
 {
     battleManager.AddEnemy(enemyIndexInBattleManager, Mathf.RoundToInt(eAgility), Mathf.RoundToInt(eStrength), Mathf.RoundToInt(eCritical), Mathf.RoundToInt(eSpeed), this, name);
 }