Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using Steamworks;
- using TMPro;
- using UnityEngine;
- using UnityEngine.Analytics;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class GameManager : MonoBehaviour
- {
- public List<Rigidbody> SpawnedWeapons
- {
- get
- {
- return this.mSpawnedWeapons;
- }
- }
- public static GameManager Instance
- {
- get
- {
- return GameManager._instance;
- }
- }
- public Controller LastWinner { get; private set; }
- public virtual void Awake()
- {
- Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None);
- Application.SetStackTraceLogType(LogType.Warning, StackTraceLogType.None);
- Debug.Log("StickVer " + StickFightConstants.VERSION_VALUE);
- this.numberOfMaps = Application.levelCount - 2;
- this.levelSelector = base.GetComponent<LevelSelection>();
- this.onlineRoom = base.GetComponent<OnlineRoom>();
- this.vicotory = base.GetComponent<Vicotory>();
- this.mCountDownHandler = UnityEngine.Object.FindObjectOfType<CountDown>();
- if (GameManager._instance != null && GameManager._instance != this)
- {
- UnityEngine.Object.Destroy(base.gameObject);
- }
- else
- {
- GameManager._instance = this;
- }
- this.m_WeaponSelectionHandler = UnityEngine.Object.FindObjectOfType<WeaponSelectionHandler>();
- this.mNetworkManager = UnityEngine.Object.FindObjectOfType<MultiplayerManager>();
- this.lastMapNumber = new MapWrapper
- {
- MapType = 0,
- MapData = BitConverter.GetBytes(0)
- };
- }
- public virtual void Start()
- {
- GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(GameObject.Find("Show Wins"));
- gameObject.transform.SetParent(GameObject.Find("GameSettingsMask").transform.GetChild(0).GetChild(1), false);
- gameObject.transform.SetSiblingIndex(10);
- gameObject.name = "Combine Maps";
- gameObject.GetComponentInChildren<TextMeshProUGUI>().text = "COMBINE MAPS";
- Navigation navigation = gameObject.transform.GetChild(1).GetComponent<Button>().navigation;
- navigation.mode = Navigation.Mode.Explicit;
- navigation.selectOnUp = GameObject.Find("Show Wins").transform.GetChild(1).GetComponent<Button>();
- gameObject.transform.GetChild(1).GetComponent<Button>().navigation = navigation;
- Navigation navigation2 = GameObject.Find("Show Wins").transform.GetChild(1).GetComponent<Button>().navigation;
- navigation2.mode = Navigation.Mode.Explicit;
- navigation2.selectOnDown = gameObject.transform.GetChild(1).GetComponent<Button>();
- GameObject.Find("Show Wins").transform.GetChild(1).GetComponent<Button>().navigation = navigation2;
- Navigation navigation3 = gameObject.transform.parent.FindChild("Back").GetChild(0).GetComponent<Button>().navigation;
- navigation3.mode = Navigation.Mode.Explicit;
- navigation3.selectOnUp = gameObject.transform.GetChild(1).GetComponent<Button>();
- gameObject.transform.parent.FindChild("Back").GetChild(0).GetComponent<Button>().navigation = navigation3;
- this.controllerHandler = base.GetComponent<ControllerHandler>();
- this.winText = base.GetComponentInChildren<WinText>(true).GetComponent<TextMeshProUGUI>();
- this.au = base.GetComponentInChildren<AudioSource>();
- this.hoardHandler = UnityEngine.Object.FindObjectOfType<HoardHandler>();
- this.crown = UnityEngine.Object.FindObjectOfType<Crown>();
- this.InitAnalytics();
- }
- public virtual void InitAnalytics()
- {
- ulong steamID = SteamUser.GetSteamID().m_SteamID;
- Analytics.SetUserId(steamID.ToString());
- GameManager.m_AnalyticsTrigger = AnalytcisTrigger.Instance;
- }
- public virtual void OnGUI()
- {
- }
- public virtual void Update()
- {
- if (GameManager.inFight && !GameManager.stillInMenu)
- {
- GameObject.Find("GameSettingsMask").transform.GetChild(0).GetChild(1).GetChild(10).gameObject.SetActive(false);
- Navigation navigation = GameObject.Find("Show Wins").transform.GetChild(1).GetComponent<Button>().navigation;
- navigation.mode = Navigation.Mode.Explicit;
- navigation.selectOnDown = GameObject.Find("GameSettingsMask").transform.GetChild(0).GetChild(1).FindChild("Back").GetChild(0).GetComponent<Button>();
- GameObject.Find("Show Wins").transform.GetChild(1).GetComponent<Button>().navigation = navigation;
- Navigation navigation2 = GameObject.Find("GameSettingsMask").transform.GetChild(0).GetChild(1).FindChild("Back").GetChild(0).GetComponent<Button>().navigation;
- navigation2.mode = Navigation.Mode.Explicit;
- navigation2.selectOnUp = GameObject.Find("Show Wins").transform.GetChild(1).GetComponent<Button>();
- GameObject.Find("GameSettingsMask").transform.GetChild(0).GetChild(1).FindChild("Back").GetChild(0).GetComponent<Button>().navigation = navigation2;
- }
- if (Input.GetKeyDown(KeyCode.R))
- {
- this.StartMatch(this.levelSelector.GetNextLevel(), true);
- }
- Cursor.lockState = CursorLockMode.Confined;
- if (GameManager.inFight)
- {
- this.randomWeaponCounter -= Time.deltaTime;
- }
- if (this.randomWeaponCounter < 0f)
- {
- this.SpawnRandomWeapon();
- }
- if (GameManager.inFight && !GameManager.stillInMenu)
- {
- this.matchTime += Time.deltaTime;
- }
- else
- {
- this.matchTime = 0f;
- }
- this.hoardHandler.specificNumber = (int)Mathf.Clamp((this.matchTime - this.secondsBeforeSuddendeath) / 10f, 0f, (float)OptionsHolder.bots);
- }
- public virtual MapWrapper GetCurrentMap()
- {
- return this.lastMapNumber;
- }
- public virtual void RestartGame()
- {
- if (MatchmakingHandler.IsNetworkMatch)
- {
- MatchmakingHandler.Instance.Disconnect(false);
- }
- Application.LoadLevel(Application.loadedLevel);
- GameManager.stillInMenu = true;
- PauseManager.isPaused = false;
- GameManager.inFight = false;
- GameManager.playersBeingMoved = 0;
- Time.timeScale = 1f;
- TimeHandler.managerTime = 1f;
- TimeHandler.pauseTime = 1f;
- DisableIfPlayed.hasPlayed = true;
- }
- public virtual void SpawnRandomWeapon()
- {
- if (this.dontSpawnItems)
- {
- return;
- }
- if (OptionsHolder.weaponsSpawn == 2)
- {
- return;
- }
- if (MatchmakingHandler.IsNetworkMatch && !MultiplayerManager.IsServer)
- {
- return;
- }
- if (OptionsHolder.weaponsSpawn == 1)
- {
- this.randomWeaponCounter = UnityEngine.Random.Range(3f, 5f);
- }
- if (OptionsHolder.weaponsSpawn == 0)
- {
- this.randomWeaponCounter = UnityEngine.Random.Range(5f, 8f);
- }
- if (OptionsHolder.weaponsSpawn == 3)
- {
- this.randomWeaponCounter = UnityEngine.Random.Range(8f, 12f);
- }
- this.randomWeaponCounter += this.extraSpawnWeaponTime;
- float num = UnityEngine.Random.Range(0f, 8f);
- if (this.spawnedLastWeaponOnLeftSide)
- {
- num *= -1f;
- }
- this.spawnedLastWeaponOnLeftSide = !this.spawnedLastWeaponOnLeftSide;
- float num2 = 11f;
- if (GameManager.Instance)
- {
- num2 *= GameManager.Instance.LastAppliedScale;
- }
- Vector3 vector = Vector3.up * num2 + Vector3.forward * num;
- GameObject original;
- int randomWeaponIndex = this.m_WeaponSelectionHandler.GetRandomWeaponIndex(true, out original);
- if (randomWeaponIndex < 0)
- {
- return;
- }
- bool flag = false;
- if (this.lastMapNumber.MapType == 0)
- {
- int num3 = BitConverter.ToInt32(this.lastMapNumber.MapData, 0);
- flag = (num3 >= 104 && num3 <= 124);
- }
- if (MatchmakingHandler.IsNetworkMatch)
- {
- this.mNetworkManager.SpawnWeapon(randomWeaponIndex, vector, flag);
- }
- else
- {
- GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(original, vector, Quaternion.identity);
- if (flag)
- {
- gameObject.GetComponent<WeaponPickUp>().ChangeToPresent();
- }
- this.mSpawnedWeapons.Add(gameObject.GetComponent<Rigidbody>());
- }
- if ((double)UnityEngine.Random.value > 0.9)
- {
- this.SpawnRandomWeapon();
- }
- }
- public virtual void DissarmPlayers()
- {
- foreach (Controller controller in this.controllerHandler.players)
- {
- if (!(controller == null))
- {
- controller.GetComponent<Fighting>().Dissarm();
- DragHandler[] componentsInChildren = controller.GetComponentsInChildren<DragHandler>();
- for (int i = 0; i < componentsInChildren.Length; i++)
- {
- componentsInChildren[i].extraDrag = 0f;
- }
- }
- }
- }
- public virtual void RevivePlayer(Controller playerToRevive, bool newMap = true)
- {
- if (playerToRevive == null)
- {
- Debug.LogWarning("Trying to revive null player");
- return;
- }
- int count = this.playersAlive.Count;
- bool flag = false;
- for (int i = 0; i < count; i++)
- {
- if (this.playersAlive[i] == null)
- {
- this.playersAlive[i] = playerToRevive;
- flag = true;
- break;
- }
- }
- if (!flag)
- {
- this.playersAlive.Add(playerToRevive);
- }
- bool flag2 = false;
- HealthHandler component = playerToRevive.GetComponent<HealthHandler>();
- if (component == null)
- {
- Debug.LogWarning("Trying to revive player without HealthHandler");
- return;
- }
- component.health = 100f;
- component.sinceSpawn = 0f;
- if (component.FirstDeathFlag)
- {
- flag2 = true;
- if (newMap)
- {
- if (component.DiedWithinSeconds(1f))
- {
- playerToRevive.GetComponent<CharacterInformation>().isDead = true;
- }
- else
- {
- component.FirstDeathFlag = false;
- }
- }
- }
- else
- {
- playerToRevive.GetComponent<CharacterInformation>().isDead = false;
- playerToRevive.gameObject.SetActive(true);
- }
- playerToRevive.GetComponent<CharacterInformation>().sinceFallen = 2f;
- playerToRevive.GetComponent<GrabHandler>().EndGrab();
- playerToRevive.damager = null;
- if (MatchmakingHandler.IsNetworkMatch)
- {
- playerToRevive.GetComponent<global::NetworkPlayer>().SetActive(true);
- }
- if (flag2)
- {
- this.playersAlive.Remove(playerToRevive);
- }
- WinCounterUI winCounterUI = UnityEngine.Object.FindObjectOfType<WinCounterUI>();
- if (winCounterUI != null)
- {
- winCounterUI.RefreshWinTexts();
- }
- }
- public virtual void ReviveAllPlayers(bool newMap = true)
- {
- this.playersAlive.Clear();
- foreach (Controller playerToRevive in this.controllerHandler.players)
- {
- this.RevivePlayer(playerToRevive, newMap);
- }
- }
- public virtual void RemovePlayer(Controller player)
- {
- this.playersAlive.Remove(player);
- }
- public virtual void KillPlayer(Controller playerToKill)
- {
- if (this.playersAlive.Contains(playerToKill))
- {
- this.playersAlive.Remove(playerToKill);
- }
- if (playerToKill.damager != null && !playerToKill.damager.isAI)
- {
- if (this.crown.crownBarrer == playerToKill)
- {
- this.crown.SetNewKing(playerToKill.damager, false);
- playerToKill.damager.GetComponent<CharacterStats>().crownSteals++;
- }
- playerToKill.damager.OnKilledEnemy(playerToKill);
- playerToKill.damager.GetComponent<CharacterStats>().kills++;
- }
- else
- {
- playerToKill.GetComponent<CharacterStats>().suicides++;
- }
- int num = 0;
- Controller controller = null;
- foreach (Controller controller2 in this.playersAlive)
- {
- if (controller2 != null && !controller2.GetComponent<CharacterInformation>().isDead)
- {
- controller = controller2;
- num++;
- }
- }
- if (num <= 1)
- {
- if (MatchmakingHandler.IsNetworkMatch)
- {
- if (MultiplayerManager.IsServer)
- {
- if (GameManager.stillInMenu && this.mNetworkManager.GetPlayersInLobby(false) < 2)
- {
- return;
- }
- MapWrapper nextLevel = this.levelSelector.GetNextLevel();
- byte indexOfWinner = (num != 0) ? ((byte)controller.GetComponent<global::NetworkPlayer>().NetworkSpawnID) : byte.MaxValue;
- this.LastWinner = controller;
- this.mNetworkManager.ChangeMap(nextLevel, indexOfWinner);
- bool customMap = this.lastMapNumber.MapType == 2;
- GameManager.m_AnalyticsTrigger.OnMatchEnd(true, customMap);
- }
- }
- else
- {
- this.AllButOnePlayersDied();
- }
- }
- playerToKill.OnDeath();
- playerToKill.GetComponent<CharacterStats>().deaths++;
- }
- public virtual GameObject FindWeaponByIndex(int weaponIndex)
- {
- int num = (this.weapons == null) ? 0 : this.weapons.Length;
- for (int i = 0; i < num; i++)
- {
- GameObject gameObject = this.weapons[i];
- if (gameObject)
- {
- string text = gameObject.name.Split(new char[]
- {
- '('
- })[0].Replace("Gun", string.Empty);
- int num2;
- if (int.TryParse(text, out num2))
- {
- if (weaponIndex == num2)
- {
- return this.weapons[i];
- }
- }
- else
- {
- Debug.LogError(string.Concat(new object[]
- {
- "Could not parse weaponNumber: ",
- text,
- " Index: ",
- weaponIndex
- }));
- }
- }
- }
- num = ((this.weaponsT2 == null) ? 0 : this.weaponsT2.Length);
- for (int j = 0; j < num; j++)
- {
- GameObject gameObject2 = this.weaponsT2[j];
- if (gameObject2)
- {
- string text2 = gameObject2.name.Split(new char[]
- {
- '('
- })[0].Replace("Gun", string.Empty);
- int num3;
- if (int.TryParse(text2, out num3))
- {
- if (weaponIndex == num3)
- {
- return this.weaponsT2[j];
- }
- }
- else
- {
- Debug.LogError(string.Concat(new object[]
- {
- "Could not parse weaponNumber: ",
- text2,
- " Index: ",
- weaponIndex
- }));
- }
- }
- }
- num = ((this.weaponsT3 == null) ? 0 : this.weaponsT3.Length);
- for (int k = 0; k < num; k++)
- {
- GameObject gameObject3 = this.weaponsT3[k];
- if (gameObject3)
- {
- string text3 = gameObject3.name.Split(new char[]
- {
- '('
- })[0].Replace("Gun", string.Empty);
- int num4;
- if (int.TryParse(text3, out num4))
- {
- if (weaponIndex == num4)
- {
- return this.weaponsT3[k];
- }
- }
- else
- {
- Debug.LogError(string.Concat(new object[]
- {
- "Could not parse weaponNumber: ",
- text3,
- " Index: ",
- weaponIndex
- }));
- }
- }
- }
- num = ((this.weaponSpeciaTier == null) ? 0 : this.weaponSpeciaTier.Length);
- for (int l = 0; l < num; l++)
- {
- GameObject gameObject4 = this.weaponSpeciaTier[l];
- if (gameObject4)
- {
- string text4 = gameObject4.name.Split(new char[]
- {
- '('
- })[0].Replace("Gun", string.Empty);
- int num5;
- if (int.TryParse(text4, out num5))
- {
- if (weaponIndex == num5)
- {
- return this.weaponSpeciaTier[l];
- }
- }
- else
- {
- Debug.LogError(string.Concat(new object[]
- {
- "Could not parse weaponNumber: ",
- text4,
- " Index: ",
- weaponIndex
- }));
- }
- }
- }
- throw new Exception("Could not find weapon with index: " + weaponIndex);
- }
- public virtual int GetPlayersAlive()
- {
- return this.playersAlive.Count;
- }
- public List<CharacterActions> SavedDevicesForNetwork
- {
- get
- {
- return this.mSavedDevicesForNetwork;
- }
- }
- public virtual int KillAllPlayers(bool network)
- {
- int num = 0;
- if (this.mSavedDevicesForNetwork.Count == 0)
- {
- foreach (Controller controller in this.playersAlive)
- {
- if (controller.HasControl)
- {
- this.mSavedDevicesForNetwork.Add(controller.PlayerActions);
- }
- UnityEngine.Object.Destroy(controller.gameObject);
- num++;
- }
- }
- this.playersAlive.Clear();
- return num;
- }
- // Token: 0x06000198 RID: 408 RVA: 0x000191AC File Offset: 0x000173AC
- public virtual void KillAllPlayers(List<Controller> playersToCheck)
- {
- this.playersAlive.Clear();
- if (playersToCheck == null)
- {
- return;
- }
- foreach (Controller controller in playersToCheck)
- {
- if (!(controller == null) && controller.HasControl)
- {
- this.playersAlive.Add(controller);
- }
- }
- }
- // Token: 0x06000199 RID: 409 RVA: 0x00019220 File Offset: 0x00017420
- public virtual void AllButOnePlayersDied()
- {
- this.mSpawnedWeapons.Clear();
- this.onlineRoom.hasStarted = true;
- Controller controller = null;
- foreach (Controller controller2 in this.playersAlive)
- {
- if (controller2 != null)
- {
- controller = controller2;
- break;
- }
- }
- if (controller == null)
- {
- Debug.LogWarning("Ending match with no player alive");
- }
- if (controller != null)
- {
- this.winText.color = controller.gameObject.GetComponentInChildren<SpriteRenderer>().GetComponent<SetColorWhenDamaged>().startColor;
- }
- this.winText.text = this.vicotory.GetRandomWinText();
- this.winText.gameObject.SetActive(true);
- this.au.PlayOneShot(this.winClips[UnityEngine.Random.Range(0, this.winClips.Length)]);
- if (GameManager.stillInMenu)
- {
- this.EnableObjects();
- }
- if (controller != null)
- {
- this.LastWinner = controller;
- }
- this.StartMatch(this.levelSelector.GetNextLevel(), true);
- if (controller != null)
- {
- this.crown.SetNewKing(controller, true);
- }
- bool customMap = this.lastMapNumber.MapType == 2 || this.lastMapNumber.MapType == 1;
- GameManager.m_AnalyticsTrigger.OnMatchEnd(false, customMap);
- }
- public virtual void EnableObjects()
- {
- foreach (GameObject gameObject in this.enableOnStart)
- {
- if (gameObject)
- {
- gameObject.SetActive(true);
- }
- }
- foreach (GameObject gameObject2 in this.disableOnStart)
- {
- if (gameObject2)
- {
- gameObject2.SetActive(false);
- }
- }
- }
- public virtual void StartMatch(MapWrapper mapIndex, bool MovePlayers = true)
- {
- if (GameManager.inFight && this.OnMatchEnded != null)
- {
- this.OnMatchEnded();
- }
- if (this.LastWinner != null && this.LastWinner.HasControl)
- {
- if (SteamStatsAndAchievements.Instance.TransientMemory.Copy<int>("DeathsByFalling").GetValue(0) >= ControllerHandler.Instance.ActivePlayers.Count - 1 && ControllerHandler.Instance.ActivePlayers.Count > 1)
- {
- SteamStatsAndAchievements.Instance.UnlockAchievement(SteamStatsAndAchievements.EAchievement.Walkover);
- }
- if (this.currentMapInfo != null && this.currentMapInfo.metaData.Contains("IceWorld"))
- {
- DestructiblePiece[] array = UnityEngine.Object.FindObjectsOfType<DestructiblePiece>();
- if (array.Length != 0)
- {
- bool flag = true;
- DestructiblePiece[] array2 = array;
- for (int i = 0; i < array2.Length; i++)
- {
- Rigidbody component = array2[i].GetComponent<Rigidbody>();
- if (component && component.isKinematic)
- {
- flag = false;
- break;
- }
- }
- if (flag)
- {
- SteamStatsAndAchievements.Instance.UnlockAchievement(SteamStatsAndAchievements.EAchievement.IceAge);
- }
- }
- }
- }
- if (this.LastWinner != null)
- {
- this.LastWinner.GetComponent<CharacterStats>().wins++;
- UnityEngine.Object.FindObjectOfType<WinCounterUI>().IncrementWinCounter(this.LastWinner);
- }
- this.EnableObjects();
- GameManager.inFight = false;
- if (OptionsHolder.weaponsSpawn == 1)
- {
- this.randomWeaponCounter = UnityEngine.Random.Range(0.5f, 1f);
- }
- if (OptionsHolder.weaponsSpawn == 0)
- {
- this.randomWeaponCounter = UnityEngine.Random.Range(2f, 4f);
- }
- if (OptionsHolder.weaponsSpawn == 3)
- {
- this.randomWeaponCounter = UnityEngine.Random.Range(4f, 8f);
- }
- this.randomWeaponCounter += this.extraSpawnWeaponTime;
- this.secondsBeforeSuddendeath = 25f;
- base.StartCoroutine(this.StartMapSequence(mapIndex, MovePlayers));
- if (MatchmakingHandler.IsNetworkMatch)
- {
- this.m_CustomMapInfoHandler.ShowSubscribe();
- }
- }
- public virtual void LoadMapCourotine(MapWrapper map)
- {
- base.StartCoroutine(this.LoadMap(map));
- }
- public virtual IEnumerator StartMapSequence(MapWrapper mapIndex, bool MovePlayers = true)
- {
- Debug.Log("StartMapSequence0");
- while (TimeHandler.managerTime > 0.01f)
- {
- TimeHandler.managerTime = Mathf.Lerp(TimeHandler.managerTime, 0f, Time.unscaledDeltaTime * 3f);
- yield return null;
- }
- SteamStatsAndAchievements.Instance.CleanUpAndStoreStats();
- foreach (Rigidbody rigidbody in UnityEngine.Object.FindObjectsOfType<Rigidbody>())
- {
- if (rigidbody.gameObject.scene.name != "MainScene")
- {
- rigidbody.isKinematic = true;
- }
- }
- foreach (Controller controller in this.controllerHandler.players)
- {
- if (!(controller == null))
- {
- controller.OnUnloadMap();
- Rigidbody[] componentsInChildren = controller.transform.root.GetComponentsInChildren<Rigidbody>(true);
- for (int j = 0; j < componentsInChildren.Length; j++)
- {
- componentsInChildren[j].isKinematic = true;
- }
- }
- }
- TimeHandler.managerTime = 1f;
- RemoveOnLevelChange[] array2 = UnityEngine.Object.FindObjectsOfType<RemoveOnLevelChange>();
- for (int k = 0; k < array2.Length; k++)
- {
- array2[k].gameObject.AddComponent<ShrinkOverTime>();
- }
- Collider[] componentsInChildren2 = base.GetComponentsInChildren<Collider>();
- for (int l = 0; l < componentsInChildren2.Length; l++)
- {
- componentsInChildren2[l].enabled = false;
- }
- this.isLoading = true;
- if (!this.levelSelector.IsDownloadingMaps() && !this.levelSelector.LastMapNeededDownloading())
- {
- this.LoadMapCourotine(mapIndex);
- }
- Debug.Log("isLoading0");
- yield return new WaitWhile(() => this.isLoading);
- yield return null;
- Debug.Log("isLoading1");
- if (!this.loadSuccessful)
- {
- Debug.LogWarning("StartMapSequence load failed");
- yield break;
- }
- if (MatchmakingHandler.IsNetworkMatch)
- {
- MultiplayerManager multiplayerManager = UnityEngine.Object.FindObjectOfType<MultiplayerManager>();
- multiplayerManager.CheckForGroundWeapons();
- multiplayerManager.UpdateUI();
- }
- byte b = 0;
- while ((int)b < this.controllerHandler.players.Count)
- {
- Controller controller2 = this.controllerHandler.players[(int)b];
- if (!(controller2 == null))
- {
- Vector3 targetPosition = new Vector3(0f, 12f, 0f);
- if (MatchmakingHandler.IsNetworkMatch && controller2.HasControl && !MovePlayers)
- {
- targetPosition = ((!controller2.GetComponent<HealthHandler>().FirstDeathFlag) ? new Vector3(0f, 12f, 0f) : new Vector3(0f, -100f, 0f));
- }
- else
- {
- int num = (int)b;
- if (b < 0 || (int)b >= this.currentMapInfo.spawnPoints.Length)
- {
- Debug.LogWarning("Trying to use invalid spawnpoint");
- num = 0;
- }
- targetPosition = this.currentMapInfo.spawnPoints[num].localPosition;
- }
- base.StartCoroutine(this.MovePlayer(controller2.GetComponentInChildren<Hip>().GetComponent<Rigidbody>(), targetPosition));
- }
- b += 1;
- }
- if (GameManager.stillInMenu)
- {
- GameManager.stillInMenu = false;
- UnityEngine.Object.Destroy(base.transform.Find("Map").gameObject);
- foreach (Rigidbody rigidbody2 in base.GetComponentsInChildren<Rigidbody>())
- {
- rigidbody2.gameObject.AddComponent<ConstantForce>().force = Vector3.forward * 1000000f;
- rigidbody2.gameObject.AddComponent<RemoveAfterSeconds>();
- }
- }
- else
- {
- base.StartCoroutine(this.RemoveMap(this.lastMapNumber));
- }
- this.m_CustomMapInfoHandler.HideSubscribe();
- this.m_CustomMapInfoHandler.AssignNewMap(mapIndex);
- yield return new WaitForSecondsRealtime(1.1f);
- this.mapAnimation.state1 = false;
- if (this.currentMapInfo != null)
- {
- this.currentMapInfo.dontFollowTheSwoosher = false;
- base.StartCoroutine(this.PrepareMapForTravel(this.currentMapInfo.gameObject, true));
- this.currentMapInfo.gameObject.SetActive(true);
- }
- else
- {
- Debug.LogError("Missing currentMapInfo");
- }
- this.lastMapNumber = mapIndex;
- Debug.Log("StartMapSequence1");
- yield break;
- }
- public virtual void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
- {
- Debug.Log("OnLevelFinishedLoading");
- this.isLoadingInternal = false;
- }
- public virtual void OnMapSizeChanged(float newSize)
- {
- this.m_CameraAspectFix.SetMapSize(newSize);
- float num = newSize / 10f;
- foreach (BoxCollider boxCollider in UnityEngine.Object.FindObjectsOfType<BoxCollider>())
- {
- if (boxCollider.name == "Death")
- {
- boxCollider.transform.root.localScale = new Vector3(1f, num, num);
- break;
- }
- }
- BarsHandler[] array2 = UnityEngine.Object.FindObjectsOfType<BarsHandler>();
- for (int j = 0; j < array2.Length; j++)
- {
- array2[j].transform.localScale = new Vector3(1f, num, num);
- }
- foreach (BackGround backGround in UnityEngine.Object.FindObjectsOfType<BackGround>())
- {
- backGround.transform.localScale = backGround.StartScale * num;
- }
- this.winText.gameObject.SetActive(false);
- Vector3 localScale = this.GameCanvas.transform.localScale;
- Vector3 localScale2 = new Vector3(localScale.x / this.LastAppliedScale * num, localScale.y / this.LastAppliedScale * num, localScale.z);
- this.GameCanvas.transform.localScale = localScale2;
- this.LastAppliedScale = num;
- }
- public virtual IEnumerator LoadMap(MapWrapper mapIndex)
- {
- if (this.oldMap != null && PlayerPrefs.GetInt("Combine Maps") == 1)
- {
- UnityEngine.Object.Destroy(this.oldMap.gameObject);
- }
- this.loadSuccessful = true;
- this.isLoadingInternal = true;
- if (mapIndex.MapType > 0)
- {
- bool flag = this.levelSelector.LoadCustomLevel(mapIndex, new Action<float>(this.OnMapSizeChanged));
- this.isLoadingInternal = false;
- if (!flag)
- {
- this.loadSuccessful = false;
- UnityEngine.Object.FindObjectOfType<LoadingScreenManager>().LoadThenFail(ConnectionErrorType.DownloadFailure, string.Empty);
- yield break;
- }
- Debug.Log("Loaded custom map: " + mapIndex);
- }
- else
- {
- int num;
- using (MemoryStream memoryStream = new MemoryStream(mapIndex.MapData))
- {
- using (BinaryReader binaryReader = new BinaryReader(memoryStream))
- {
- num = binaryReader.ReadInt32();
- }
- }
- Debug.Log("Loading Scene: " + SceneManager.GetSceneByBuildIndex(num).name);
- SceneManager.sceneLoaded += this.OnLevelFinishedLoading;
- SceneManager.LoadScene(num, LoadSceneMode.Additive);
- this.OnMapSizeChanged(10f);
- }
- if (this.currentMapInfo)
- {
- this.oldMap = this.currentMapInfo;
- }
- Debug.Log("LoadMapWait0");
- yield return new WaitWhile(() => this.isLoadingInternal);
- yield return null;
- Debug.Log("LoadMapWait1");
- foreach (MapInfo mapInfo in UnityEngine.Object.FindObjectsOfType<MapInfo>())
- {
- if (!this.oldMap || mapInfo != this.oldMap)
- {
- this.currentMapInfo = mapInfo;
- BackGround componentInChildren = mapInfo.GetComponentInChildren<BackGround>();
- if (componentInChildren)
- {
- componentInChildren.enabled = true;
- }
- mapInfo.gameObject.SetActive(false);
- }
- }
- if (this.currentMapInfo != null)
- {
- this.dontSpawnItems = this.currentMapInfo.dontSpawnItems;
- this.extraSpawnWeaponTime = this.currentMapInfo.extraWeaponSpawnTime;
- }
- this.isLoading = false;
- yield break;
- }
- public virtual IEnumerator RemoveMap(MapWrapper mapIndex)
- {
- this.mapAnimation.state1 = true;
- base.StartCoroutine(this.PrepareMapForTravel(this.oldMap.gameObject, false));
- BackGround componentInChildren = this.oldMap.GetComponentInChildren<BackGround>();
- if (componentInChildren)
- {
- componentInChildren.FadeOut();
- }
- yield return new WaitForSecondsRealtime(1f);
- Debug.Log("Trying to unload scene nr: " + mapIndex);
- if (mapIndex.MapType == 0 && PlayerPrefs.GetInt("Combine Maps") == 0)
- {
- SceneManager.UnloadScene(BitConverter.ToInt32(mapIndex.MapData, 0));
- }
- else if (mapIndex.MapType == 0 && PlayerPrefs.GetInt("Combine Maps") == 1)
- {
- Debug.Log("Finally?");
- }
- else if (PlayerPrefs.GetInt("Combine Maps") == 1)
- {
- Debug.Log("Finally?");
- }
- else
- {
- UnityEngine.Object.Destroy(this.oldMap.gameObject);
- }
- yield break;
- }
- public virtual IEnumerator PrepareMapForTravel(GameObject map, bool comingIn)
- {
- Rigidbody[] componentsInChildren = map.gameObject.GetComponentsInChildren<Rigidbody>();
- for (int i = 0; i < componentsInChildren.Length; i++)
- {
- componentsInChildren[i].isKinematic = true;
- }
- foreach (ConfigurableJoint configurableJoint in map.gameObject.GetComponentsInChildren<ConfigurableJoint>(true))
- {
- GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(configurableJoint.gameObject, configurableJoint.transform.position, configurableJoint.transform.rotation);
- gameObject.AddComponent<JointDummy>();
- gameObject.transform.parent = configurableJoint.transform.parent;
- ConfigurableJoint[] components = gameObject.GetComponents<ConfigurableJoint>();
- for (int k = 0; k < components.Length; k++)
- {
- UnityEngine.Object.Destroy(components[k]);
- }
- ConstantForce[] components2 = gameObject.GetComponents<ConstantForce>();
- for (int l = 0; l < components2.Length; l++)
- {
- UnityEngine.Object.Destroy(components2[l]);
- }
- UnityEngine.Object.Destroy(gameObject.GetComponent<Rigidbody>());
- configurableJoint.gameObject.SetActive(false);
- }
- yield return new WaitForSecondsRealtime(1f);
- while (this.mapAnimation.isAnimating)
- {
- yield return null;
- }
- JointDummy[] array = UnityEngine.Object.FindObjectsOfType<JointDummy>();
- for (int m = 0; m < array.Length; m++)
- {
- UnityEngine.Object.Destroy(array[m].gameObject);
- }
- if (map)
- {
- ConfigurableJoint[] componentsInChildren3 = map.gameObject.GetComponentsInChildren<ConfigurableJoint>(true);
- for (int n = 0; n < componentsInChildren3.Length; n++)
- {
- componentsInChildren3[n].gameObject.SetActive(true);
- }
- }
- if (map)
- {
- foreach (Rigidbody rigidbody in map.gameObject.GetComponentsInChildren<Rigidbody>())
- {
- DestructiblePiece component = rigidbody.GetComponent<DestructiblePiece>();
- if ((!component || component.simpleDestruction || component.eventDestruction) && !rigidbody.GetComponent<DontEnableRig>())
- {
- rigidbody.isKinematic = false;
- }
- }
- }
- if (MatchmakingHandler.IsNetworkMatch)
- {
- P2PStatistics.StartRecording();
- }
- if (comingIn)
- {
- if (MatchmakingHandler.IsNetworkMatch)
- {
- this.mMultiplayerManager.InitMapDataObjects();
- TimeHandler.managerTime = 0f;
- this.mMultiplayerManager.ReadyUp();
- yield return new WaitForSecondsRealtime(0.5f);
- this.mMultiplayerManager.InitSyncedObjects();
- base.StartCoroutine(this.StartCountdownAfterSeconds(MultiplayerManager.k_MAX_SECONDS_UNTIL_AUTO_START));
- using (List<Controller>.Enumerator enumerator = this.controllerHandler.players.GetEnumerator())
- {
- while (enumerator.MoveNext())
- {
- Controller controller = enumerator.Current;
- if (!(controller == null))
- {
- componentsInChildren = controller.transform.root.GetComponentsInChildren<Rigidbody>(true);
- for (int num = 0; num < componentsInChildren.Length; num++)
- {
- componentsInChildren[num].isKinematic = false;
- }
- }
- }
- yield break;
- }
- }
- yield return new WaitForSecondsRealtime(1f);
- this.m_CustomMapInfoHandler.HideMapInfo();
- }
- yield break;
- }
- public virtual IEnumerator StartCountdownAfterSeconds(float seconds)
- {
- float timer = 0f;
- bool play = true;
- while (timer < seconds)
- {
- timer += Time.unscaledDeltaTime;
- if (GameManager.inFight)
- {
- play = false;
- this.mWaitTextAnimator.state1 = false;
- break;
- }
- if (timer >= 1f && !this.mPlayingCountdown)
- {
- this.mWaitTextAnimator.state1 = true;
- }
- yield return 0;
- }
- if (play)
- {
- this.StartCountDown();
- }
- yield break;
- }
- public virtual void StartCountDown()
- {
- this.mWaitTextAnimator.state1 = false;
- base.StartCoroutine(this.CountDownCoroutine());
- }
- public virtual IEnumerator CountDownCoroutine()
- {
- if (this.mPlayingCountdown)
- {
- yield break;
- }
- this.m_CustomMapInfoHandler.HideMapInfo();
- this.mPlayingCountdown = true;
- TimeHandler.managerTime = 0f;
- this.mCountDownHandler.Countdown();
- yield return new WaitForSecondsRealtime(1f);
- GameManager.inFight = true;
- TimeHandler.managerTime = 1f;
- this.mPlayingCountdown = false;
- yield break;
- }
- public virtual IEnumerator MovePlayer(Rigidbody player, Vector3 targetPosition)
- {
- if (!player)
- {
- yield break;
- }
- GameManager.playersBeingMoved++;
- Rigidbody[] componentsInChildren = player.transform.root.GetComponentsInChildren<Rigidbody>();
- for (int i = 0; i < componentsInChildren.Length; i++)
- {
- componentsInChildren[i].isKinematic = true;
- }
- player.transform.root.GetComponent<SetMovementAbility>().Reset();
- this.DissarmPlayers();
- player.transform.root.GetComponent<Controller>().SetCollision(false);
- Vector3 movementDirection = targetPosition + Vector3.up * 1f - player.position;
- float t = 0f;
- float lastStep = 0f;
- while (t < this.movePlayerTime)
- {
- if (!player)
- {
- yield break;
- }
- t += Time.deltaTime;
- float num = this.movePlayerCurve.Evaluate(t / this.movePlayerTime);
- float num2 = this.movePlayerCurve.Evaluate(lastStep / this.movePlayerTime);
- float d = num - num2;
- componentsInChildren = player.transform.root.GetComponentsInChildren<Rigidbody>();
- for (int j = 0; j < componentsInChildren.Length; j++)
- {
- componentsInChildren[j].transform.position += d * movementDirection;
- }
- lastStep = t;
- yield return null;
- }
- while (this.mapAnimation.isAnimating)
- {
- if (!player)
- {
- yield break;
- }
- Vector3 b = targetPosition + Vector3.up * 1f - player.transform.position;
- foreach (Rigidbody rigidbody in player.transform.root.GetComponentsInChildren<Rigidbody>())
- {
- if (rigidbody)
- {
- rigidbody.transform.position += b;
- }
- }
- yield return null;
- }
- if (player)
- {
- if (!MatchmakingHandler.IsNetworkMatch)
- {
- componentsInChildren = player.transform.root.GetComponentsInChildren<Rigidbody>(true);
- for (int l = 0; l < componentsInChildren.Length; l++)
- {
- componentsInChildren[l].isKinematic = false;
- }
- }
- player.transform.root.GetComponent<Controller>().SetCollision(true);
- }
- this.ReviveAllPlayers(true);
- if (!MatchmakingHandler.IsNetworkMatch)
- {
- GameManager.inFight = true;
- }
- yield break;
- }
- public virtual void NetworkAllPlayersDiedButOne(MapWrapper newlevel, byte winner)
- {
- this.onlineRoom.hasStarted = true;
- P2PStatistics.StopRecording();
- List<Controller> playerControllers = this.mNetworkManager.PlayerControllers;
- if (winner != 255)
- {
- Controller controller = null;
- if ((int)winner < playerControllers.Count)
- {
- controller = playerControllers[(int)winner];
- }
- if (controller != null)
- {
- this.crown.SetNewKing(controller, true);
- this.LastWinner = controller;
- this.winText.text = this.vicotory.GetRandomWinText();
- this.winText.color = controller.GetComponentInChildren<SpriteRenderer>().GetComponent<SetColorWhenDamaged>().startColor;
- this.winText.gameObject.SetActive(true);
- }
- }
- if (this.au)
- {
- this.au.PlayOneShot(this.winClips[UnityEngine.Random.Range(0, this.winClips.Length)]);
- }
- foreach (Controller controller2 in playerControllers)
- {
- if (!(controller2 == null))
- {
- controller2.GetComponent<global::NetworkPlayer>().SetActive(false);
- }
- }
- this.StartMatch(newlevel, true);
- }
- public virtual byte FindWeaponIdByName(string weaponName)
- {
- int num = this.weapons.Length;
- byte b = 0;
- while ((int)b < num)
- {
- string name = this.weapons[(int)b].name;
- if (weaponName.Split(new char[]
- {
- '('
- })[0].ToLower() == name.ToLower())
- {
- return b;
- }
- b += 1;
- }
- num = this.weaponsT2.Length;
- byte b2 = 0;
- while ((int)b2 < num)
- {
- string name2 = this.weaponsT2[(int)b2].name;
- if (weaponName.Split(new char[]
- {
- '('
- })[0].ToLower() == name2.ToLower())
- {
- return (byte)((int)b2 + this.weapons.Length);
- }
- b2 += 1;
- }
- num = this.weaponsT3.Length;
- byte b3 = 0;
- while ((int)b3 < num)
- {
- string name3 = this.weaponsT3[(int)b3].name;
- if (weaponName.Split(new char[]
- {
- '('
- })[0].ToLower() == name3.ToLower())
- {
- return (byte)((int)b3 + this.weaponsT2.Length);
- }
- b3 += 1;
- }
- Debug.LogError("Could not find weapon named: " + weaponName);
- return byte.MaxValue;
- }
- public virtual GameObject GetWeaponWithIndexAndOverFlow(byte weaponID)
- {
- Debug.Log("Trying to find weapon with overflow: " + weaponID);
- int num = this.weapons.Length;
- int num2 = this.weapons.Length + this.weaponsT2.Length;
- int num3 = num2 + this.weaponsT3.Length;
- GameObject[] array = this.weapons;
- if ((int)weaponID < num)
- {
- Debug.Log("Found Weapon In Tier 1! Real ID" + (int)weaponID);
- return array[(int)weaponID];
- }
- array = this.weaponsT2;
- int num4;
- if ((int)weaponID < num2)
- {
- num4 = (int)weaponID - num;
- Debug.Log("Found Weapon In Tier 2! Real ID" + num4);
- return array[num4];
- }
- array = this.weaponsT3;
- if ((int)weaponID >= num3)
- {
- array = this.weaponSpeciaTier;
- num4 = (int)weaponID - num3;
- Debug.Log("Found Weapon In Special Tier! Real ID" + num4);
- return array[num4];
- }
- num4 = (int)weaponID - num2;
- Debug.Log("Found Weapon In Tier 3! Real ID" + num4);
- return array[num4];
- }
- public virtual CharacterActions GetNextSavedDeviceForNetwork()
- {
- if (this.mSavedDevicesForNetwork == null || this.mSavedDevicesForNetwork.Count <= 1)
- {
- return this.GetDefaultBindings();
- }
- CharacterActions characterActions = this.mSavedDevicesForNetwork[0];
- this.mSavedDevicesForNetwork[0] = null;
- if (characterActions == null)
- {
- for (int i = 1; i < this.mSavedDevicesForNetwork.Count; i++)
- {
- characterActions = this.mSavedDevicesForNetwork[i];
- if (characterActions != null)
- {
- this.mSavedDevicesForNetwork[i] = null;
- break;
- }
- }
- }
- if (characterActions == null)
- {
- return this.GetDefaultBindings();
- }
- return characterActions;
- }
- public virtual CharacterActions GetDefaultBindings()
- {
- return CharacterActions.CreateWithAnyBindings();
- }
- public virtual void DisableAllPlayers()
- {
- foreach (Controller controller in this.playersAlive)
- {
- if (controller != null)
- {
- controller.gameObject.SetActive(false);
- }
- }
- }
- public virtual void SaveDevicesForNextGame(List<Controller> players)
- {
- this.mSavedDevicesForNetwork.Clear();
- if (players == null)
- {
- return;
- }
- foreach (Controller controller in players)
- {
- if (!(controller == null) && controller.HasControl)
- {
- this.mSavedDevicesForNetwork.Add(controller.PlayerActions);
- }
- }
- }
- public virtual bool IsInLobby()
- {
- bool flag = this.lastMapNumber.MapType > 0;
- byte[] mapData = this.lastMapNumber.MapData;
- return !flag && BitConverter.ToInt32(mapData, 0) == 0;
- }
- public static int playersBeingMoved;
- public static bool inFight;
- public static bool stillInMenu = true;
- public static bool spawnWeaponsAsPresents = true;
- public CodeStateAnimation mapAnimation;
- public AnimationCurve movePlayerCurve;
- public float movePlayerTime = 1f;
- protected ControllerHandler controllerHandler;
- protected List<Rigidbody> mSpawnedWeapons = new List<Rigidbody>();
- public List<Controller> playersAlive = new List<Controller>();
- public MultiplayerManager mMultiplayerManager;
- public P2PPackageHandler P2PPackageHandler;
- protected MapInfo[] maps;
- public MapInfo currentMapInfo;
- public MapInfo oldMap;
- public GameObject mapHolder;
- public MapWrapper lastMapNumber;
- public GameObject[] weapons;
- public GameObject[] weaponsT2;
- public GameObject[] weaponsT3;
- public GameObject[] weaponSpeciaTier;
- public GameObject[] GodWeapons;
- public GameObject[] poolRanged;
- public GameObject[] poolMeele;
- public GameObject[] poolSniper;
- public GameObject[] poolHandguns;
- public GameObject[] poolExplosive;
- public GameObject[] poolSnakes;
- public GameObject[] poolLava;
- public TextMeshProUGUI winText;
- protected float randomWeaponCounter = 99f;
- protected AudioSource au;
- public AudioClip[] winClips;
- public bool isLoading;
- protected bool isLoadingInternal;
- protected bool dontSpawnItems;
- protected float secondsBeforeSuddendeath;
- public float matchTime;
- protected HoardHandler hoardHandler;
- protected Crown crown;
- protected Vicotory vicotory;
- public bool testing;
- protected bool loadSuccessful = true;
- protected static GameManager _instance;
- public int numberOfMaps;
- protected CountDown mCountDownHandler;
- [SerializeField]
- protected CodeStateAnimation mWaitTextAnimator;
- protected LevelSelection levelSelector;
- protected OnlineRoom onlineRoom;
- protected WeaponSelectionHandler m_WeaponSelectionHandler;
- protected MultiplayerManager mNetworkManager;
- public TMP_InputField chatInputField;
- public GameObject[] enableOnStart;
- public GameObject[] disableOnStart;
- [SerializeField]
- protected CustomMapInfoSubscriberHandler m_CustomMapInfoHandler;
- protected bool spawnedLastWeaponOnLeftSide;
- protected float extraSpawnWeaponTime;
- public Action OnMatchEnded;
- public GameObject GameCanvas;
- protected static AnalytcisTrigger m_AnalyticsTrigger;
- protected List<CharacterActions> mSavedDevicesForNetwork = new List<CharacterActions>();
- [SerializeField]
- protected AspectFix m_CameraAspectFix;
- [SerializeField]
- protected Transform m_Bars;
- public float LastAppliedScale = 1f;
- protected bool mPlayingCountdown;
- public bool ForCombine;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement