public override void OnEvent(Sleep evnt) { if (BoltNetwork.isClient && LocalPlayer.Inventory.CurrentView == PlayerInventory.PlayerViews.Sleep) { Debug.Log("Go to sleep"); TheForest.Utils.Scene.HudGui.MpSleepLabel.gameObject.SetActive(false); LocalPlayer.Inventory.CurrentView = PlayerInventory.PlayerViews.World; if (!evnt.Aborted) { LocalPlayer.Stats.GoToSleep(); if (Grabber.FocusedItemGO) { ShelterTrigger component = Grabber.FocusedItemGO.GetComponent <ShelterTrigger>(); if (component && component.BreakAfterSleep) { base.StartCoroutine(component.DelayedCollapse()); } component.SendMessage("OnSleep", SendMessageOptions.DontRequireReceiver); } EventRegistry.Player.Publish(TfEvent.Slept, null); } else { LocalPlayer.Stats.GoToSleepFake(); } TheForest.Utils.Scene.HudGui.Grid.repositionNow = true; } }
public override void OnEvent(Sleep evnt) { if (BoltNetwork.isClient && LocalPlayer.Inventory.CurrentView == PlayerInventory.PlayerViews.Sleep) { Scene.HudGui.MpSleepLabel.gameObject.SetActive(false); LocalPlayer.Inventory.CurrentView = PlayerInventory.PlayerViews.World; if (!evnt.Aborted) { LocalPlayer.Stats.GoToSleep(); if (Grabber.FocusedItemGO) { ShelterTrigger component = Grabber.FocusedItemGO.GetComponent <ShelterTrigger>(); if (component && component.BreakAfterSleep) { base.StartCoroutine(component.DelayedCollapse()); } } } else { LocalPlayer.Stats.GoToSleepFake(); } } }
private void Update() { if (this.playerDoingAction()) { this.SleepIcon.SetActive(false); Scene.HudGui.SleepDelayIcon.gameObject.SetActive(false); return; } if (LocalPlayer.Inventory.CurrentView == PlayerInventory.PlayerViews.World && !this.playerDoingAction()) { if (this.CanSleep) { if (this.SleepIcon) { if (!this.SleepIcon.activeSelf) { this.SleepIcon.SetActive(true); Scene.HudGui.SleepDelayIcon.gameObject.SetActive(false); } if (TheForest.Utils.Input.GetButtonAfterDelay("RestKey", 0.5f, false)) { if (!BoltNetwork.isRunning) { if (LocalPlayer.Stats.GoToSleep()) { ShelterTrigger.CheckRegrowTrees(); if (this.BreakAfterSleep) { base.StartCoroutine(this.DelayedCollapse()); } base.SendMessage("OnSleep", SendMessageOptions.DontRequireReceiver); } } else { this.ResetMpSleepDelay(); this._previousPlayersReady = -1; this.SleepIcon.SetActive(false); Scene.HudGui.SleepDelayIcon.gameObject.SetActive(false); Scene.HudGui.MpSleepLabel.gameObject.SetActive(true); LocalPlayer.Inventory.CurrentView = PlayerInventory.PlayerViews.Sleep; } } } } else if (this.SleepIcon.activeSelf || !Scene.HudGui.SleepDelayIcon.gameObject.activeSelf) { this.SleepIcon.SetActive(false); Scene.HudGui.SleepDelayIcon._target = this.SleepIcon.transform; Scene.HudGui.SleepDelayIcon.gameObject.SetActive(true); } } if (LocalPlayer.Inventory.CurrentView == PlayerInventory.PlayerViews.Sleep) { if (TheForest.Utils.Input.GetButtonDown("Esc")) { LocalPlayer.Inventory.CurrentView = PlayerInventory.PlayerViews.World; Scene.HudGui.MpSleepLabel.gameObject.SetActive(false); } else { int num = 0; for (int i = 0; i < Scene.SceneTracker.allPlayerEntities.Count; i++) { if (Scene.SceneTracker.allPlayerEntities[i].GetState <IPlayerState>().CurrentView == 9) { num++; } } if (this._previousPlayersReady != num) { this.ResetMpSleepDelay(); this._previousPlayersReady = num; Scene.HudGui.MpSleepLabel.text = num + 1 + "/" + (Scene.SceneTracker.allPlayerEntities.Count + 1); } if ((BoltNetwork.isServer || SteamClientDSConfig.isDSFirstClient) && num == Scene.SceneTracker.allPlayerEntities.Count) { if (this._mpSleepDelay > 0f) { this._mpSleepDelay -= Time.deltaTime; } else { base.SendMessage("OnSleep", SendMessageOptions.DontRequireReceiver); this.ResetMpSleepDelay(); Sleep sleep = Sleep.Create((!SteamClientDSConfig.isDSFirstClient) ? GlobalTargets.AllClients : GlobalTargets.OnlyServer); if (LocalPlayer.Stats.GoToSleep()) { if (!SteamClientDSConfig.isDSFirstClient) { ShelterTrigger.CheckRegrowTrees(); } if (this.BreakAfterSleep) { base.StartCoroutine(this.DelayedCollapse()); } } else { sleep.Aborted = true; } sleep.Send(); LocalPlayer.Inventory.CurrentView = PlayerInventory.PlayerViews.World; Scene.HudGui.MpSleepLabel.gameObject.SetActive(false); Scene.HudGui.Grid.repositionNow = true; } } } } if (this.PlayerCanSave() && TheForest.Utils.Input.GetButtonAfterDelay("Save", 0.5f, false)) { LocalPlayer.Stats.JustSave(); } }