示例#1
0
        public void Goto(Transform target)
        {
            bool flag = Terrain.activeTerrain.SampleHeight(target.position) - target.position.y > (float)((!LocalPlayer.IsInCaves) ? 6 : 3);
            Area componentInParent = target.GetComponentInParent <Area>();

            if (!flag && !LocalPlayer.IsInCaves)
            {
                RaycastHit raycastHit;
                if (Physics.SphereCast(target.transform.position + Vector3.up * 25f + Vector3.forward * 2f, 2f, Vector3.down, out raycastHit, 60f))
                {
                    this.GotoCave(flag);
                    this.GotoArea(componentInParent);
                    LocalPlayer.Rigidbody.velocity = Vector3.zero;
                    LocalPlayer.Transform.position = raycastHit.point + Vector3.up * 2.5f;
                    Debug.Log("$> going to " + target);
                }
                else
                {
                    Debug.Log("# didn't find a suitable landing spot raycasting down on '" + target + "', cancelling goto");
                }
            }
            else
            {
                this.GotoCave(flag);
                this.GotoArea(componentInParent);
                LocalPlayer.Rigidbody.velocity = Vector3.zero;
                LocalPlayer.Transform.position = target.transform.position + Vector3.up;
                GameObject gameObject = GameObject.FindWithTag("EndgameLoader");
                if (gameObject)
                {
                    SceneLoadTrigger component = gameObject.GetComponent <SceneLoadTrigger>();
                    Vector3          rhs       = LocalPlayer.Transform.position - component.transform.position;
                    if (Vector3.Dot(component.transform.forward, rhs) > 0f && rhs.magnitude < 150f)
                    {
                        component._onCrossingForwards.Invoke();
                    }
                }
                Debug.Log("# going to " + target);
            }
        }
示例#2
0
 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();
     }
 }
示例#3
0
    public IEnumerator Activation(bool activate)
    {
        if (ForestVR.Prototype)
        {
            base.enabled = false;
            yield break;
        }
        if (this.startedSequence)
        {
            yield break;
        }
        PerfTimerLogger timer = new PerfTimerLogger("[<color=#FFF>TIMER</color>] Activation", PerfTimerLogger.LogResultType.Milliseconds, null);

        this.startedSequence = true;
        if (!CoopPeerStarter.DedicatedHost)
        {
            while (!LocalPlayer.Rigidbody)
            {
                yield return(null);
            }
            LocalPlayer.Rigidbody.useGravity  = false;
            LocalPlayer.Rigidbody.isKinematic = true;
        }
        this.SetStartSequenceStep(0, 1f);
        Debug.Log("Game Activation Sequence step 0 (GameStartType=" + GameSetup.Init + ")");
        bool isLoadingSave = GameSetup.IsSavedGame;

        if (isLoadingSave && BoltNetwork.isRunning && BoltNetwork.isServer && Scene.PlaneCrash)
        {
            yield return(null);

            if (Scene.PlaneCrash.savePos)
            {
                CoopServerInfo.Instance.state.PlanePosition = Scene.PlaneCrash.savePos.position;
                CoopServerInfo.Instance.state.PlaneRotation = Scene.PlaneCrash.savePos.rotation;
                foreach (BoltConnection connection in BoltNetwork.clients)
                {
                    SetJoiningTimeOfDay setJoiningTimeOfDay = SetJoiningTimeOfDay.Create(connection);
                    setJoiningTimeOfDay.TimeOfDay = ((!Scene.Atmosphere) ? 302f : Scene.Atmosphere.TimeOfDay);
                    setJoiningTimeOfDay.Send();
                }
            }
            else
            {
                Debug.LogError("No plane crash position");
            }
        }
        else if (BoltNetwork.isServer && ((!isLoadingSave && !Scene.PlaneCrash.gameObject.activeSelf) || (isLoadingSave && !Scene.PlaneCrash.savePos)))
        {
            Debug.LogError("Setting fake plane coordinates for testing purposes. Please turn on plane crash when testing MP.");
            CoopServerInfo.Instance.state.PlanePosition = ((!LocalPlayer.Transform) ? new Vector3(400f, 50f, 300f) : LocalPlayer.Transform.position) + new Vector3(0f, 4f, 0f);
            CoopServerInfo.Instance.state.PlaneRotation = Quaternion.Euler(0f, 20f, 0f);
        }
        yield return(null);

        if (TheForest.Utils.Input.player != null)
        {
            TheForest.Utils.Input.SetMenuMapping(false);
        }
        this.SetStartSequenceStep(1, 1f);
        if (AstarPath.active)
        {
            Debug.Log("Game Activation Sequence step 1 : enable Astar");
            if (BoltNetwork.isClient)
            {
                GameObject gameObject  = GameObject.Find("Astar");
                GameObject gameObject2 = GameObject.Find("AstarGUOGo");
                if (gameObject2)
                {
                    UnityEngine.Object.Destroy(gameObject2);
                }
                if (gameObject)
                {
                    UnityEngine.Object.Destroy(gameObject);
                }
            }
            else
            {
                AstarPath.active.enabled = true;
            }
        }
        else
        {
            Debug.Log("Game Activation Sequence step 1 : AStar is missing, SKIPPING !!!");
        }
        yield return(null);

        int list = 1;

        foreach (LoadSave.GameObjectList frameActivationList in this._activateAfterLoading)
        {
            object arg = "Game Activation Sequence step 2 : Activating GameObject List #";
            int    num;
            list = (num = list) + 1;
            Debug.Log(arg + num);
            this.SetStartSequenceStep(2, (float)list / (float)this._activateAfterLoading.Count);
            foreach (GameObject gameObject3 in frameActivationList._frameJobs)
            {
                if (gameObject3)
                {
                    gameObject3.SetActive(activate);
                }
                else
                {
                    Debug.Log("Null GameObject in LoadSave's lists to activate. Please check something isn't missing or remove the entry.-");
                }
            }
            yield return(null);
        }
        if (!CoopPeerStarter.DedicatedHost)
        {
            while (!LocalPlayer.GameObject)
            {
                yield return(null);
            }
            GameObject endgameLoader = GameObject.FindWithTag("EndgameLoader");
            if (endgameLoader)
            {
                SceneLoadTrigger component = endgameLoader.GetComponent <SceneLoadTrigger>();
                if (LocalPlayer.ActiveAreaInfo.HasActiveEndgameArea)
                {
                    component.SetCanLoad(true);
                    component.ForceLoad();
                }
                else
                {
                    Vector3 rhs = LocalPlayer.Transform.position - component.transform.position;
                    if (Vector3.Dot(component.transform.forward, rhs) > 0f && rhs.magnitude < 150f)
                    {
                        component._onCrossingForwards.Invoke();
                    }
                }
            }
            this.SetStartSequenceStep(3, 1f);
            Debug.Log("Game Activation Sequence step 3 : Enabling GreebleLayers, workscheduler, rainfollow");
            LocalPlayer.GreebleRoot.SetActive(true);
            Scene.RainFollowGO.GetComponent <SmoothTransformConstraint>().target = LocalPlayer.Transform.Find("RainTargetGo");
        }
        else
        {
            this.SetStartSequenceStep(3, 1f);
            Debug.Log("Game Activation Sequence step 3* : Enabling workscheduler");
        }
        WorkScheduler.ShouldDoFullCycle = true;
        if (Scene.PlaneCrash.Crashed || !Scene.PlaneCrash.ShowCrash || !Scene.PlaneCrashAnimGO || !Scene.PlaneCrashAnimGO.activeSelf)
        {
            Scene.WorkScheduler.gameObject.SetActive(true);
        }
        yield return(null);

        yield return(null);

        this.SetStartSequenceStep(4, 1f);
        Debug.Log("Game Activation Sequence step 4 : Initalize Game Mode");
        if (!BoltNetwork.isClient && (Prefabs.Instance.GameModePrefabs[(int)GameSetup.Game] || GameModeStarter.Prefab))
        {
            if (GameModeStarter.Prefab)
            {
                UnityEngine.Object.Instantiate <GameObject>(GameModeStarter.Prefab);
            }
            else
            {
                UnityEngine.Object.Instantiate <GameObject>(Prefabs.Instance.GameModePrefabs[(int)GameSetup.Game]);
            }
        }
        else
        {
            yield return(YieldPresets.WaitPointFiveSeconds);
        }
        this.SetStartSequenceStep(5, 0.5f);
        Debug.Log("Game Activation Sequence step 5 : OnGameStart event");
        Time.timeScale = 1f;
        if (LoadSave.OnGameStart != null)
        {
            LoadSave.OnGameStart();
        }
        LoadSave.OnGameStart = null;
        if (BoltNetwork.isClient && isLoadingSave)
        {
            yield return(YieldPresets.WaitPointFiveSeconds);

            Vector3   playerPos = LocalPlayer.Transform.position;
            LayerMask layers    = LayerMask.GetMask(new string[]
            {
                "ReflectBig",
                "Terrain",
                "Prop",
                "Cave"
            });
            float      mpClientDelayStart = Time.realtimeSinceStartup;
            RaycastHit hit;
            while (Time.realtimeSinceStartup - mpClientDelayStart < 15f && !Physics.Raycast(playerPos, Vector3.down, out hit, 3f, layers))
            {
                this.SetStartSequenceStep(5, 0.5f + (Time.realtimeSinceStartup - mpClientDelayStart) / 15f * 0.5f);
                LocalPlayer.Transform.position = playerPos;
                yield return(null);
            }
        }
        this.SetStartSequenceStep(5, 1f);
        CaveTriggers.CheckPlayersInCave();
        MassDestructionSaveManager md = UnityEngine.Object.FindObjectOfType <MassDestructionSaveManager>();

        if (!md.GetComponent <GlobalDataSaver>())
        {
            md.gameObject.AddComponent <GlobalDataSaver>();
            StoreInformation component2 = md.GetComponent <StoreInformation>();
            if (!component2.Components.Contains("TheForest.Utils.GlobalDataSaver"))
            {
                component2.Components.Add("TheForest.Utils.GlobalDataSaver");
            }
        }
        if (!md.GetComponent <GreebleZonesManager>())
        {
            md.gameObject.AddComponent <GreebleZonesManager>();
            StoreInformation component3 = md.GetComponent <StoreInformation>();
            if (!component3.Components.Contains("GreebleZonesManager"))
            {
                component3.Components.Add("GreebleZonesManager");
            }
            UnityEngine.Object.FindObjectOfType <GreebleZonesManager>().RefreshGreebleZones();
        }
        if (!md.GetComponent <SpawnMutantsSerializerMessageProxy>())
        {
            md.gameObject.AddComponent <SpawnMutantsSerializerMessageProxy>();
        }
        foreach (Camera camera in UnityEngine.Object.FindObjectsOfType <Camera>())
        {
            camera.eventMask = 0;
        }
        Scene.LoadSave = null;
        Scene.Atmosphere.ForceSunRotationUpdate = true;
        Scene.SceneTracker.waitForLoadSequence  = true;
        this.SetStartSequenceStep(6, 0.25f);
        yield return(YieldPresets.WaitPointSixSeconds);

        if (!BoltNetwork.isClient)
        {
            while (Scene.SceneTracker.doingGlobalNavUpdate)
            {
                yield return(null);
            }
        }
        if (!CoopPeerStarter.DedicatedHost)
        {
            VirtualCursor.Instance.SetCursorType(VirtualCursor.CursorTypes.Reset);
            VirtualCursor.Instance.SetCursorType(VirtualCursor.CursorTypes.None);
        }
        this.SetStartSequenceStep(6, 0.5f);
        if (!CoopPeerStarter.DedicatedHost)
        {
            if (LocalPlayer.ActiveAreaInfo.HasActiveEndgameArea)
            {
                while (!LocalPlayer.IsInEndgame)
                {
                    yield return(null);
                }
                yield return(null);
            }
            LocalPlayer.Rigidbody.isKinematic = false;
            LocalPlayer.Rigidbody.useGravity  = true;
            this.SetStartSequenceStep(6, 1f);
            Debug.Log("Game Activation Sequence step 6 : BlackScreen off");
            if (LocalPlayer.Inventory.CurrentView == PlayerInventory.PlayerViews.Loading)
            {
                LocalPlayer.Inventory.CurrentView = PlayerInventory.PlayerViews.World;
            }
            Scene.HudGui.CheckHudState();
        }
        else
        {
            Scene.HudGui.gameObject.SetActive(false);
            this.SetStartSequenceStep(6, 1f);
            Debug.Log("Game Activation Sequence step 6* : BlackScreen off");
        }
        Scene.HudGui.Loading._cam.SetActive(false);
        Debug.Log("Game Activation Sequence step 7 : End of Sequence");
        if (LocalPlayer.Inventory)
        {
            if (LocalPlayer.Inventory.CurrentView != PlayerInventory.PlayerViews.PlaneCrash)
            {
                LocalPlayer.Inventory.enabled = true;
            }
            LocalPlayer.Transform.SendMessage("enableMpRenderers", SendMessageOptions.DontRequireReceiver);
            LocalPlayer.Transform.SendMessage("forceMecanimSync", SendMessageOptions.DontRequireReceiver);
        }
        if (BoltNetwork.isClient)
        {
            foreach (GameObject gameObject4 in Scene.MutantControler.activeNetCannibals)
            {
                if (gameObject4.activeSelf)
                {
                    gameObject4.SendMessage("forceSkinColor", SendMessageOptions.DontRequireReceiver);
                }
            }
        }
        if (LocalPlayer.MainRotator)
        {
            LocalPlayer.Transform.localEulerAngles        = new Vector3(0f, LocalPlayer.Transform.localEulerAngles.y, 0f);
            LocalPlayer.MainRotator.resetOriginalRotation = true;
        }
        if (LocalPlayer.IsInCaves && BoltNetwork.isClient)
        {
            playerInCave playerInCave = playerInCave.Create(GlobalTargets.OnlyServer);
            playerInCave.target = LocalPlayer.Transform.GetComponent <BoltEntity>();
            playerInCave.inCave = true;
            playerInCave.Send();
        }
        if (LocalPlayer.IsInCaves || LocalPlayer.IsInEndgame)
        {
            for (int j = 0; j < Scene.SceneTracker.caveEntrances.Count; j++)
            {
                Scene.SceneTracker.caveEntrances[j].disableCaveBlack();
            }
        }
        UnityEngine.Object.Destroy(this);
        BridgeAnchorHelper.Clear();
        if (BoltNetwork.isRunning && CoopHellDoors.Instance && CoopHellDoors.Instance.entity.isAttached)
        {
            CoopHellDoors.Instance.entity.Freeze(false);
        }
        if (SteamClientDSConfig.isDedicatedClient && LocalPlayer.Inventory.CurrentView == PlayerInventory.PlayerViews.World)
        {
            SteamClientDSConfig.IsClientAtWorld = true;
        }
        Scene.FinishGameLoad     = true;
        LoadingProgress.Progress = 0f;
        timer.Stop();
        yield break;
    }