private void Update() { if (!Scene.Cams.DeadCam.activeSelf) { if (!Scene.HudGui.MpRespawnLabel.gameObject.activeSelf && !this._vrRespawnActive && this._deathTime + this._minDownDuration < Time.time) { if (ForestVR.Enabled) { LocalPlayer.vrPlayerControl.ShowRespawnPrompt(true); this._vrRespawnActive = true; } else { Scene.HudGui.MpRespawnLabel.gameObject.SetActive(true); } } else if ((TheForest.Utils.Input.GetButtonDown("Take") && Scene.HudGui.MpRespawnMaxTimer.gameObject.activeSelf) || this._deathTime + this._maxDownDuration < Time.time) { Debug.Log("killed player"); PlayerRespawnMP.KillPlayer(); this._vrRespawnActive = false; } } else if (this._manualRespawnTime + this._respawnDuration < Time.time) { this.Respawn(); this._vrRespawnActive = false; } Scene.HudGui.MpRespawnMaxTimer.fillAmount = Mathf.Clamp01((Time.time - this._deathTime) / this._maxDownDuration); }
private void OnDestroy() { if (PlayerRespawnMP.Instance == this) { PlayerRespawnMP.Instance = null; } }
private void Update() { if (!Scene.Cams.DeadCam.activeSelf) { if (!Scene.HudGui.MpRespawnLabel.gameObject.activeSelf && this._deathTime + this._minDownDuration < Time.time) { Scene.HudGui.MpRespawnLabel.gameObject.SetActive(true); } else if ((TheForest.Utils.Input.GetButtonDown("Take") && Scene.HudGui.MpRespawnMaxTimer.gameObject.activeSelf) || this._deathTime + this._maxDownDuration < Time.time) { UnityEngine.Debug.Log("killed player"); PlayerRespawnMP.KillPlayer(); } } else if (this._manualRespawnTime + this._respawnDuration < Time.time) { this.Respawn(); } Scene.HudGui.MpRespawnMaxTimer.fillAmount = Mathf.Clamp01((Time.time - this._deathTime) / this._maxDownDuration); }
private void Respawn() { Debug.Log("LocalPlayer -> Respawn"); if (LocalPlayer.Stats.Dead) { if (LocalPlayer.IsInEndgame) { GameObject gameObject = GameObject.FindWithTag("EndgameLoader"); if (gameObject) { SceneLoadTrigger component = gameObject.GetComponent <SceneLoadTrigger>(); component.ForceUnload(); } } EventRegistry.Player.Publish(TfEvent.ExitOverlookArea, null); EventRegistry.Player.Publish(TfEvent.ExitEndgame, null); LocalPlayer.GameObject.SendMessage("NotInACave"); PlayerInventory inventory = LocalPlayer.Inventory; PlayerClothing clothing = LocalPlayer.Clothing; AchievementsManager achievements = LocalPlayer.Achievements; SurvivalBookTodo componentInChildren = LocalPlayer.SpecialItems.GetComponentInChildren <SurvivalBookTodo>(); string name = LocalPlayer.Entity.GetState <IPlayerState>().name; bool value = LocalPlayer.SavedData.ReachedLowSanityThreshold; bool value2 = LocalPlayer.SavedData.ExitedEndgame; LocalPlayer.Inventory.HideAllEquiped(false, false); LocalPlayer.Inventory.enabled = false; if (Scene.SceneTracker.allPlayers.Contains(LocalPlayer.GameObject)) { Scene.SceneTracker.allPlayers.Remove(LocalPlayer.GameObject); } if (Scene.SceneTracker.allPlayerEntities.Contains(LocalPlayer.Entity)) { Scene.SceneTracker.allPlayerEntities.Remove(LocalPlayer.Entity); } BoltNetwork.Detach(LocalPlayer.Entity); GameObject gameObject2 = LocalPlayer.GameObject; BoltEntity entity = LocalPlayer.Entity; gameObject2.name = "player Corpse - " + name; gameObject2.tag = "Untagged"; LocalPlayer.MainCamTr.parent = LocalPlayer.Transform; LocalPlayer.Inventory.CurrentView = PlayerInventory.PlayerViews.Loot; if (LocalPlayer.AnimControl.swimming) { LocalPlayer.Rigidbody.useGravity = true; } for (int i = gameObject2.transform.childCount - 1; i >= 0; i--) { Transform child = gameObject2.transform.GetChild(i); UnityEngine.Object.Destroy(child.gameObject); } Component[] components = gameObject2.GetComponents(typeof(MonoBehaviour)); foreach (Component component2 in components) { if (!(component2 is BoltEntity)) { UnityEngine.Object.DestroyImmediate(component2); } } Transform transform = base.transform; GameObject gameObject3 = UnityEngine.Object.Instantiate <GameObject>(Prefabs.Instance.PlayerPrefab, transform.position, transform.rotation); gameObject3.transform.localEulerAngles = new Vector3(0f, gameObject3.transform.localEulerAngles.y, 0f); gameObject3.name = Prefabs.Instance.PlayerPrefab.name; LocalPlayer.Inventory.SetQuickSelectItemIds(inventory.QuickSelectItemIds); LocalPlayer.Achievements.Clone(achievements); LocalPlayer.SpecialItems.GetComponentInChildren <SurvivalBookTodo>().Clone(componentInChildren); LocalPlayer.SavedData.ReachedLowSanityThreshold.SetValue(value); LocalPlayer.SavedData.ExitedEndgame.SetValue(value2); LocalPlayer.FpCharacter.UnLockView(); LocalPlayer.CamFollowHead.enableMouseControl(false); LocalPlayer.MainCamTr.localEulerAngles = Vector3.zero; LocalPlayer.MainRotator.enabled = true; LocalPlayer.CamRotator.enabled = true; LocalPlayer.Stats.Health = 28f; LocalPlayer.Stats.HealthTarget = 28f; LocalPlayer.Stats.Energy = 100f; LocalPlayer.Stats.Fullness = 0.35f; LocalPlayer.Stats.Thirst = 0.35f; LocalPlayer.Stats.Invoke("CheckArmsStart", 2f); LocalPlayer.Stats.Invoke("PlayWakeMusic", 0.5f); LocalPlayer.Tuts.CloseColdTut(); Scene.RainFollowGO.GetComponent <SmoothTransformConstraint>().target = LocalPlayer.Transform; gameObject3.SetActive(true); CoopUtils.AttachLocalPlayer(gameObject3, name); Scene.SceneTracker.allPlayers.Add(LocalPlayer.GameObject); LocalPlayer.GreebleRoot.SetActive(true); LocalPlayer.Inventory.enabled = true; LocalPlayer.Transform.SendMessage("enableMpRenderers"); LocalPlayer.Transform.SendMessage("playerLoadedFromRespawn"); this._addedItems = false; StealItemTrigger stealItemTrigger = UnityEngine.Object.Instantiate <StealItemTrigger>(Prefabs.Instance.DeadBackpackPrefab, gameObject2.transform.position, gameObject2.transform.rotation); stealItemTrigger._entity = entity; stealItemTrigger.transform.parent = gameObject2.transform; gameObject2.AddComponent <DeathMPTut>(); ItemStorage itemStorage = gameObject2.AddComponent <ItemStorage>(); itemStorage._acceptedTypes = ~Item.Types.Story; for (int k = inventory._possessedItems.Count - 1; k >= 0; k--) { InventoryItem inventoryItem = inventory._possessedItems[k]; if (!LocalPlayer.Inventory.Owns(inventoryItem._itemId, false)) { if (inventoryItem.MaxAmount == 1) { InventoryItemView inventoryItemView = inventory.InventoryItemViewsCache[inventoryItem._itemId][0]; this.AddItemToStorage(inventoryItem._itemId, inventoryItem._amount, itemStorage, inventoryItemView.Properties); } else if (inventoryItem.MaxAmount > 0 && inventoryItem.MaxAmount < 2147483647) { while (inventory.Owns(inventoryItem._itemId, false)) { InventoryItemView inventoryItemView2 = inventory.InventoryItemViewsCache[inventoryItem._itemId][0]; inventory.SortInventoryViewsByBonus(inventoryItemView2, inventoryItemView2.Properties.ActiveBonus, true); int amount = inventory.AmountOfItemWithBonus(inventoryItem._itemId, inventoryItemView2.Properties.ActiveBonus); inventory.RemoveItem(inventoryItem._itemId, amount, true, false); this.AddItemToStorage(inventoryItem._itemId, amount, itemStorage, inventoryItemView2.Properties); } } else { this.AddItemToStorage(inventoryItem._itemId, inventoryItem._amount, itemStorage, null); } } } for (int l = 0; l < inventory.EquipmentSlots.Length; l++) { InventoryItemView inventoryItemView3 = inventory.EquipmentSlots[l]; if (inventoryItemView3 && inventoryItemView3._itemId > 0) { this.AddItemToStorage(inventoryItemView3._itemId, 1, itemStorage, inventoryItemView3.Properties); } } clothing.DropAll(gameObject2.transform.position, true, true); if (!this._addedItems) { UnityEngine.Object.Destroy(gameObject2); } animalAI[] array2 = UnityEngine.Object.FindObjectsOfType <animalAI>(); foreach (animalAI animalAI in array2) { animalAI.SendMessage("updatePlayerTargets"); } mutantAI[] array4 = UnityEngine.Object.FindObjectsOfType <mutantAI>(); foreach (mutantAI mutantAI in array4) { mutantAI.SendMessage("updatePlayerTargets"); } Fish[] array6 = UnityEngine.Object.FindObjectsOfType <Fish>(); mutantScriptSetup[] array7 = UnityEngine.Object.FindObjectsOfType <mutantScriptSetup>(); foreach (mutantScriptSetup mutantScriptSetup in array7) { mutantScriptSetup.setupPlayer(); mutantScriptSetup.search.refreshCurrentTarget(); } LocalPlayer.Transform.SendMessage("enableMpRenderers"); Terrain.activeTerrain.GetComponent <Collider>().enabled = true; Scene.Clock.IsNotCave(); } PlayerRespawnMP.Cancel(); if (this._bringUpPauseMenu) { this._bringUpPauseMenu = false; LocalPlayer.Inventory.TogglePauseMenu(); } }
private void Awake() { PlayerRespawnMP.Instance = this; base.enabled = false; }
private void Respawn() { UnityEngine.Debug.Log("LocalPlayer -> Respawn"); if (LocalPlayer.Stats.Dead) { LocalPlayer.GameObject.SendMessage("NotInACave"); PlayerInventory inventory = LocalPlayer.Inventory; string name = LocalPlayer.Entity.GetState <IPlayerState>().name; LocalPlayer.Inventory.HideAllEquiped(false); LocalPlayer.Inventory.enabled = false; if (Scene.SceneTracker.allPlayers.Contains(LocalPlayer.GameObject)) { Scene.SceneTracker.allPlayers.Remove(LocalPlayer.GameObject); } if (Scene.SceneTracker.allPlayerEntities.Contains(LocalPlayer.Entity)) { Scene.SceneTracker.allPlayerEntities.Remove(LocalPlayer.Entity); } BoltNetwork.Detach(LocalPlayer.Entity); GameObject gameObject = LocalPlayer.GameObject; BoltEntity entity = LocalPlayer.Entity; gameObject.name = "player Corpse - " + name; gameObject.tag = "Untagged"; LocalPlayer.MainCamTr.parent = LocalPlayer.Transform; LocalPlayer.Inventory.CurrentView = PlayerInventory.PlayerViews.Loot; for (int i = gameObject.transform.childCount - 1; i >= 0; i--) { Transform child = gameObject.transform.GetChild(i); UnityEngine.Object.Destroy(child.gameObject); } Component[] components = gameObject.GetComponents(typeof(MonoBehaviour)); Component[] array = components; for (int j = 0; j < array.Length; j++) { Component component = array[j]; if (!(component is BoltEntity)) { UnityEngine.Object.DestroyImmediate(component); } } Transform transform = base.transform; GameObject gameObject2 = (GameObject)UnityEngine.Object.Instantiate(Prefabs.Instance.PlayerPrefab, transform.position, transform.rotation); gameObject2.transform.localEulerAngles = new Vector3(0f, gameObject2.transform.localEulerAngles.y, 0f); gameObject2.name = Prefabs.Instance.PlayerPrefab.name; LocalPlayer.FpCharacter.UnLockView(); LocalPlayer.CamFollowHead.enableMouseControl(false); LocalPlayer.MainCamTr.localEulerAngles = Vector3.zero; LocalPlayer.MainRotator.enabled = true; LocalPlayer.CamRotator.enabled = true; LocalPlayer.Stats.Health = 28f; LocalPlayer.Stats.Energy = 100f; LocalPlayer.Stats.Fullness = 0.35f; LocalPlayer.Stats.Thirst = 0.35f; LocalPlayer.Stats.Invoke("CheckArmsStart", 2f); LocalPlayer.Stats.Invoke("PlayWakeMusic", 0.5f); Scene.RainFollowGO.GetComponent <SmoothTransformConstraint>().target = LocalPlayer.Transform; gameObject2.SetActive(true); CoopUtils.AttachLocalPlayer(gameObject2, name); Scene.SceneTracker.allPlayers.Add(LocalPlayer.GameObject); LocalPlayer.GreebleRoot.SetActive(true); StealItemTrigger stealItemTrigger = (StealItemTrigger)UnityEngine.Object.Instantiate(Prefabs.Instance.DeadBackpackPrefab, gameObject.transform.position, gameObject.transform.rotation); stealItemTrigger._entity = entity; stealItemTrigger.transform.parent = gameObject.transform; gameObject.AddComponent <DeathMPTut>(); ItemStorage cis = gameObject.AddComponent <ItemStorage>(); for (int k = 0; k < inventory._possessedItems.Count; k++) { InventoryItem inventoryItem = inventory._possessedItems[k]; if (!LocalPlayer.Inventory.Owns(inventoryItem._itemId)) { this.AddItemToStorage(inventoryItem._itemId, inventoryItem._amount, inventoryItem._maxAmountBonus, cis); } } for (int l = 0; l < inventory.EquipmentSlots.Length; l++) { InventoryItemView inventoryItemView = inventory.EquipmentSlots[l]; if (inventoryItemView && inventoryItemView._itemId > 0) { this.AddItemToStorage(inventoryItemView._itemId, 1, 0, cis); } } animalAI[] array2 = UnityEngine.Object.FindObjectsOfType <animalAI>(); animalAI[] array3 = array2; for (int m = 0; m < array3.Length; m++) { animalAI animalAI = array3[m]; animalAI.SendMessage("updatePlayerTargets"); } mutantAI[] array4 = UnityEngine.Object.FindObjectsOfType <mutantAI>(); mutantAI[] array5 = array4; for (int n = 0; n < array5.Length; n++) { mutantAI mutantAI = array5[n]; mutantAI.SendMessage("updatePlayerTargets"); } Fish[] array6 = UnityEngine.Object.FindObjectsOfType <Fish>(); Fish[] array7 = array6; for (int num = 0; num < array7.Length; num++) { Fish fish = array7[num]; fish.SendMessage("updatePlayerTargets"); } mutantScriptSetup[] array8 = UnityEngine.Object.FindObjectsOfType <mutantScriptSetup>(); mutantScriptSetup[] array9 = array8; for (int num2 = 0; num2 < array9.Length; num2++) { mutantScriptSetup mutantScriptSetup = array9[num2]; mutantScriptSetup.setupPlayer(); mutantScriptSetup.search.refreshCurrentTarget(); } Terrain.activeTerrain.GetComponent <Collider>().enabled = true; Scene.Clock.IsNotCave(); } PlayerRespawnMP.Cancel(); }