/// <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) { } }
// Update is called once per frame void Update() { if (attackQueue == null) { attackQueue = new Queue <Fighter>(); } if (player == null) { player = manager.GetPlayerCharacter(); } if (player == null) { return; } if (pause) { player.IsFighting = false; if (enemies == null) { return; } foreach (Enemy enemy in enemies) { enemy.IsFighting = false; } } else { player.IsFighting = true; foreach (Enemy enemy in enemies) { enemy.IsFighting = true; } } if (AllEnemiesDead() && !someoneIsAttacking) { cam.ChangeToFirstPerson(); pause = true; } if (AllEnemiesDead() && !someoneIsAttacking && cam.PositionSet) { HandleBattleOver(); pause = true; } if (player != null && player.IsDead()) { StartCoroutine(DoDeathCam(1.5f)); } if (!someoneIsAttacking && attackQueue.Count > 0 && !BattleOver) { currentAttacker = attackQueue.Dequeue(); if (!currentAttacker.IsDead()) { SomeoneGotHit = false; someoneIsAttacking = true; foreach (Enemy enemy in enemies) { enemy.PauseInitiativeTimer(true); } player.PauseInitiativeTimer(true); if (currentAttacker == player) { attackOptionsPanel.Flush(); foreach (PlayerMove attack in player.GetAvailableMoves()) { Instantiate(attackOptionPrefab, attackOptionsPanel.transform). Init(attack, description, player); } player.Attack(); } else { currentAttacker.Attack(); } } } }