using Fie.Camera; using Fie.Core; using Fie.Object; using Fie.Scene; using Fie.User; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Fie.Manager { [FieManagerExists(FieManagerExistSceneFlag.ANYTIME_DESTROY)] public class FieInGameStateManager : FieManagerBehaviour { public enum FieInGameState { STATE_IS_INITIALIZING, STATE_IS_RETRYING, STATE_NOW_ON_GAME, STATE_CUTSCENE, STATE_GAMEOVER, STATE_ON_QUIT } public delegate void FieInGameStateChangedCallback(); public FieInGameState _gameState; public Coroutine _checkingGameOverCoroutine; private bool _isBooted; private int _gameOverCount; public bool isBootComplete => _isBooted; public event FieInGameStateChangedCallback GameOverEvent; public event FieInGameStateChangedCallback RetryEvent; public event FieInGameStateChangedCallback RetryFinishedEvent; private IEnumerator InGameBootTask() { _isBooted = false; FiePlayerSpawnPoint[] array = UnityEngine.Object.FindObjectsOfType(); Dictionary dictionary = new Dictionary(); if (array != null && array.Length > 0) { for (int i = 0; i < array.Length; i++) { dictionary[array[i].spawnPointNumber] = array[i].transform.position; } } if (!FieBootstrap.isBootedFromBootStrap) { FieManagerBehaviour.I.StartUp(); FieManagerBehaviour.I.StartUp(); FieManagerBehaviour.I.StartUp(); FieManagerBehaviour.I.StartUp(); int num = 0; FieUser[] allUserData = FieManagerBehaviour.I.getAllUserData(); foreach (FieUser fieUser in allUserData) { FieGameCharacter fieGameCharacter = null; if (fieUser != null) { Vector3 position = (!dictionary.ContainsKey(num)) ? Vector3.zero : dictionary[num]; if (fieUser.usersCharacter != null) { fieGameCharacter = fieUser.usersCharacter; fieGameCharacter.transform.position = position; fieGameCharacter.transform.rotation = Quaternion.LookRotation(Vector3.forward); } else { if (FieBootstrap.isBootedFromBootStrap) { Debug.LogError("An users character prefab was missed! please check the class : " + fieUser.usersCharacterPrefab.GetType()); continue; } if (fieUser.usersCharacter == null && fieUser.usersCharacterPrefab != null) { string empty = string.Empty; FiePrefabInfo fiePrefabInfo = (FiePrefabInfo)Attribute.GetCustomAttribute(fieUser.usersCharacterPrefab.GetType(), typeof(FiePrefabInfo)); if (fiePrefabInfo == null) { Debug.LogError("The debug character prefab dose not have FiePrefabInfo attribute! Please check the class : " + fieUser.usersCharacterPrefab.GetType()); continue; } string path = fiePrefabInfo.path; if (path == string.Empty) { Debug.LogError("A prefab path was not found! Please check the class : " + fieUser.usersCharacterPrefab.GetType()); continue; } GameObject gameObject = PhotonNetwork.Instantiate(path, position, Quaternion.LookRotation(Vector3.forward), 0); fieGameCharacter = (fieUser.usersCharacter = gameObject.GetComponent()); } } if (fieGameCharacter != null) { if (!FieBootstrap.isBootedFromBootStrap) { fieGameCharacter.InitializeIntelligenceSystem(); } if (PhotonNetwork.offlineMode && fieUser.usersCharacter.intelligenceType == FieGameCharacter.IntelligenceType.Controllable) { fieGameCharacter.SetOwnerUser(fieUser); } else if (fieGameCharacter.photonView.ownerId == PhotonNetwork.player.ID) { fieGameCharacter.SetOwnerUser(fieUser); } FieManagerBehaviour.I.AssignCharacter(FieInGameCharacterStatusManager.ForcesTag.PLAYER, fieGameCharacter); } num++; } } } else { int num2 = 0; List allPlayerCharacters = FieManagerBehaviour.I.GetAllPlayerCharacters(); foreach (FieGameCharacter item in allPlayerCharacters) { if (item.forces == FieEmittableObjectBase.EmitObjectTag.PLAYER) { Vector3 vector2 = item.position = ((!dictionary.ContainsKey(num2)) ? Vector3.zero : dictionary[num2]); FieManagerBehaviour.I.AssignCharacter(FieInGameCharacterStatusManager.ForcesTag.PLAYER, item); num2++; } } } FieManagerBehaviour.I.StartUp(); FieManagerBehaviour.I.gameCamera.SetCameraTask(); FieManagerBehaviour.I.StartUp(); _isBooted = true; _gameState = FieInGameState.STATE_NOW_ON_GAME; yield break; } private IEnumerator RetryTask() { yield return (object)new WaitForSeconds(0.1f); /*Error: Unable to find new state assignment for yield return*/; } private void GameOverCallback() { FieManagerBehaviour.I.isEnableControll = false; } protected override void StartUpEntity() { _gameState = FieInGameState.STATE_IS_INITIALIZING; StartCoroutine(InGameBootTask()); if (_checkingGameOverCoroutine != null) { StopCoroutine(_checkingGameOverCoroutine); } _checkingGameOverCoroutine = StartCoroutine(CheckingGameOverTask()); } private IEnumerator CheckingGameOverTask() { if (_gameState == FieInGameState.STATE_NOW_ON_GAME) { if (FieManagerBehaviour.I.isAllPlayerDied()) { _gameOverCount = Mathf.Clamp(_gameOverCount + 1, 1, 5); } if (_gameOverCount > 3) { SetGameState(FieInGameState.STATE_GAMEOVER); } yield return (object)new WaitForSeconds(1f); /*Error: Unable to find new state assignment for yield return*/; } yield return (object)null; /*Error: Unable to find new state assignment for yield return*/; } public void SetGameState(FieInGameState state) { if (state != _gameState) { switch (state) { case FieInGameState.STATE_GAMEOVER: FieManagerBehaviour.I.SendGameOverEvent(); if (_checkingGameOverCoroutine != null) { StopCoroutine(_checkingGameOverCoroutine); } if (this.GameOverEvent != null) { this.GameOverEvent(); } break; case FieInGameState.STATE_IS_RETRYING: FieManagerBehaviour.I.SendRetryEvent(); StartCoroutine(RetryTask()); break; case FieInGameState.STATE_ON_QUIT: FieManagerBehaviour.I.SendGameQuitEvent(); QuitGame(); break; } _gameState = state; } } private void QuitGame() { FieManagerBehaviour.I.LoadScene(new FieSceneResult(), allowSceneActivation: true, FieFaderManager.FadeType.OUT_TO_WHITE, 1f); FieManagerBehaviour.I.ChangeMixerVolume(0f, 0.5f, FieAudioManager.FieAudioMixerType.BGM, FieAudioManager.FieAudioMixerType.Voice, FieAudioManager.FieAudioMixerType.SE); if (_checkingGameOverCoroutine != null) { StopCoroutine(_checkingGameOverCoroutine); } } public void SetGameOver() { if (this.GameOverEvent != null) { this.GameOverEvent(); } } internal void SetRetry() { if (_checkingGameOverCoroutine != null) { StopCoroutine(_checkingGameOverCoroutine); } StartCoroutine(RetryTask()); } internal void SetQuit() { QuitGame(); } private void OnDestroy() { if (_checkingGameOverCoroutine != null) { StopCoroutine(_checkingGameOverCoroutine); } } } }