Пример #1
0
        protected IEnumerator WaitForUnload()
        {
            yield return(StartCoroutine(GUILoading.LoadStart(GUILoading.Mode.FullScreenBlack)));

            GUILoading.Lock(this);
            GUILoading.ActivityInfo = "Unloading World";
            string detailsInfo = "Unloading in game manager";

            GUILoading.DetailsInfo = "Waiting for managers to unload...";
            while (!Manager.FinishedUnloading)
            {
                while (GameWorld.Get.UnloadingGameWorld(out detailsInfo))                       //report GameWorld progress as it loads the game
                {
                    yield return(null);

                    GUILoading.DetailsInfo = detailsInfo;
                }
                Debug.Log("Waiting for manager to finish unloading...");
                yield return(null);
            }
            Application.LoadLevel("BlankLevel");            //this nukes anything but managers and worlditems
            GUILoading.Unlock(this);
            yield return(StartCoroutine(GUILoading.LoadFinish()));

            gState = FGameState.GameLoading;
        }
Пример #2
0
        protected IEnumerator StartupGame()
        {
            while (GUILoading.SplashScreen)                     //wait for splash screen
            {
                yield return(null);
            }
            yield return(StartCoroutine(GUILoading.LoadStart(GUILoading.Mode.FullScreenBlack)));

            GUILoading.Lock(this);
            GUILoading.DetailsInfo = "Starting up...";
            yield return(StartCoroutine(InitializeGameEnvironment()));

            GUILoading.Unlock(this);
            yield return(StartCoroutine(GUILoading.LoadFinish()));

            //initialization only happens once
            //after we're done, wait for the start menu to choose a game
            gState = FGameState.WaitingForGame;
            if (TestingEnvironment)
            {
                yield return(StartCoroutine(WaitForGameTestingEnvironment()));
            }
            else
            {
                yield return(StartCoroutine(WaitForGame()));
            }
            yield break;
        }
Пример #3
0
        protected IEnumerator FinishSequenceOverTime()
        {
            yield return(StartCoroutine(GUILoading.LoadStart(GUILoading.Mode.FullScreenBlack, true)));

            GUILoading.Lock(this);
            Player.Local.Despawn();
            yield return(null);

            yield return(StartCoroutine(SpawnManager.Get.SendPlayerToStartupPosition(State.StartupPositionName, State.Delay)));

            GUILoading.Unlock(this);
            yield return(null);

            yield return(StartCoroutine(GUILoading.LoadFinish()));
        }
Пример #4
0
        public IEnumerator SendPlayerToStartupPosition(PlayerStartupPosition startupPosition)
        {
            if (mSpawningPlayer)
            {
                //whoops
                yield break;
            }

            mSpawningPlayer = true;

            if (!GUILoading.IsLoading)
            {
                //let that go on its own, don't wait for it
                StartCoroutine(GUILoading.LoadStart(GUILoading.Mode.FullScreenBlack));
            }

            //if the startup position is null
            //use the character's state as a startup position
            if (startupPosition == null)
            {
                //the player state should be not-null by now
                Debug.Log("Using player startup position");
                startupPosition = Player.Local.GetStartupPosition();
            }

            if (Player.Local.HasSpawned)
            {
                Player.Local.Despawn();
            }
            //set the current spawn position
            CurrentStartupPosition = startupPosition;
            yield return(null);

            //set all existing world chunks to unclaimed
            mLoadingInfo = "Unloading chunks";
            //suspend chunk loading so the player's position doesn't get the world confused
            GameWorld.Get.SuspendChunkLoading = true;
            for (int i = 0; i < GameWorld.Get.WorldChunks.Count; i++)
            {
                if (GameWorld.Get.WorldChunks [i].State.ID != startupPosition.ChunkID)
                {
                    GameWorld.Get.WorldChunks [i].TargetMode = ChunkMode.Unloaded;
                }
            }
            //suspend worlditem loading so worlditems don't start spawning stuff till we're ready
            WorldItems.Get.SuspendWorldItemUpdates = true;
            //WorldItems.Get.SetAllWorldItemsToInvisible();
            //wait a moment to let that sink in
            yield return(null);

            //put the player in the middle of the chunk to be loaded first
            WorldChunk startChunk = null;

            if (GameWorld.Get.ChunkByID(startupPosition.ChunkID, out startChunk))
            {
                Player.Local.Position = startChunk.ChunkOffset + startupPosition.ChunkPosition.Position;
            }
            else
            {
                mLoadingInfo = "ERROR: Couldn't find startup chunk";
            }
            //we send the player to the chunk / location specified in the world settings
            mLoadingInfo = "Sending player to startup position";
            //re-enable chunk loading so everything can load
            GameWorld.Get.SuspendChunkLoading      = false;
            WorldItems.Get.SuspendWorldItemUpdates = false;
            //set the primary chunk and let it load
            //put the player in the middle of the chunk to be loaded first
            mLoadingInfo = "Waiting for chunks to load";
            while (!GameWorld.Get.ChunksLoaded)
            {
                yield return(null);
            }
            if (startupPosition.ForceUnloadAllNonPrimaryChunks)
            {
                Debug.Log("Force-unloading all primary chunks, structures, worlditems");
                //unload all chunks except the primary chunk
                var unloadChunks = GameWorld.Get.UnloadAllChunks(startupPosition.ChunkID);
                while (unloadChunks.MoveNext())
                {
                    mLoadingInfo = "Unloading all chunks...";
                    yield return(unloadChunks.Current);
                }
                var unloadStructures = Structures.Get.UnloadAllStructures();
                while (unloadStructures.MoveNext())
                {
                    mLoadingInfo = "Unloading all structures...";
                    yield return(unloadStructures.Current);
                }
                var unloadWorldItems = WorldItems.Get.UnloadAllWorldItems();
                while (unloadWorldItems.MoveNext())
                {
                    mLoadingInfo = "Unloading all worlditems...";
                    yield return(unloadWorldItems.Current);
                }
                Resources.UnloadUnusedAssets();
            }
            mLoadingInfo = "Chunks unloaded, setting primary chunk";
            //set all the non-distant chunks to load
            GameWorld.Get.SetDistantChunks(Player.Local.Position);
            if (!GameWorld.Get.SetPrimaryChunk(startupPosition.ChunkID))
            {
                mLoadingInfo = "Couldn't set primary chunk, halting load: " + startupPosition.ChunkID.ToString();
                yield break;
            }
            //set the startup position so managers know where the player will end up
            startupPosition.WorldPosition.Position = (GameWorld.Get.PrimaryChunk.ChunkOffset + startupPosition.ChunkPosition.Position);
            startupPosition.WorldPosition.Rotation = startupPosition.ChunkPosition.Rotation;
            //set all the non-distant chunks to load
            GameWorld.Get.SetDistantChunks(startupPosition.WorldPosition.Position);
            //wait for the rest of the chunk to load
            while (GameWorld.Get.PrimaryChunk.CurrentMode != ChunkMode.Primary)
            {
                //turn on the camera so it starts rendering grass meshes
                //this will fight with camera FX but that's ok
                CameraFX.Get.Default.cam.enabled     = true;
                CameraFX.Get.Default.cam.cullingMask = CameraFX.Get.Default.CullingMask;
                mLoadingInfo = "Waiting for primary chunk to load";
                //Debug.Log("waiting for primary chunk to load");
                yield return(null);
            }

            //initialize time
            if (startupPosition.RequiresStructure)
            {
                mLoadingInfo = "Loading structures";
                yield return(StartCoroutine(SendPlayerToStructure(
                                                startupPosition.ChunkID,
                                                startupPosition.LocationReference,
                                                startupPosition.StructureName,
                                                startupPosition.Interior,
                                                startupPosition.ChunkPosition,
                                                startChunk.ChunkOffset)));
            }
            else
            {
                mLoadingInfo = "Loading location";
                yield return(StartCoroutine(SendPlayerToLocation(
                                                startupPosition.ChunkID,
                                                startupPosition.LocationReference.GroupPath,
                                                startupPosition.LocationReference.FileName,
                                                startupPosition.ChunkPosition,
                                                startChunk.ChunkOffset,
                                                0.1f)));

                //since we're not inside a structure
                //we could be standing on something
                //either a minor structure or chunk prefab
                if (startupPosition.RequiresMeshTerrain)
                {
                    //wait for something to show up below the player before letting them go
                    GameWorld.TerrainHeightSearch terrainHit = new GameWorld.TerrainHeightSearch();
                    terrainHit.feetPosition   = startupPosition.WorldPosition.Position;
                    terrainHit.groundedHeight = Globals.DefaultCharacterGroundedHeight;
                    terrainHit.overhangHeight = Globals.DefaultCharacterHeight;
                    bool   foundSomethingBelowPlayer = false;
                    double timeOut = WorldClock.RealTime + 30f;
                    mLoadingInfo = "Waiting for mesh below player's feet";
                    while (WorldClock.RealTime < timeOut)
                    {
                        GameWorld.Get.TerrainHeightAtInGamePosition(ref terrainHit);
                        //see if we hit a mesh
                        if (terrainHit.hitTerrainMesh)
                        {
                            break;
                        }
                        yield return(null);
                    }
                }
            }

            //immediately add the game offset
            if (startupPosition.AbsoluteTime)
            {
                WorldClock.ResetAbsoluteTime();
                Profile.Get.CurrentGame.SetWorldTimeOffset(
                    startupPosition.TimeHours,
                    startupPosition.TimeDays,
                    startupPosition.TimeMonths,
                    startupPosition.TimeYears);
            }
            else
            {
                Profile.Get.CurrentGame.AddWorldTimeOffset(
                    startupPosition.TimeHours,
                    startupPosition.TimeDays,
                    startupPosition.TimeMonths,
                    startupPosition.TimeYears);
            }

            //unload anything we're not using
            //GC.Collect();
            //Resources.UnloadUnusedAssets();
            //yield return null;
            yield return(null);

            if (GUILoading.IsLoading)
            {
                StartCoroutine(GUILoading.LoadFinish());
            }

            Player.Local.SpawnAtPosition(startupPosition.WorldPosition);

            mSpawningPlayer = false;
            yield break;
        }
Пример #5
0
        //loads the current game and world
        //starts it up
        protected IEnumerator LoadOverTime()
        {
            Biomes.Get.UseTimeOfDayOverride = false;
            if (mStartupScenePrefab != null)
            {
                GameObject.Destroy(mStartupScenePrefab, 0.5f);
            }
            //Load all the things!
            yield return(StartCoroutine(GUILoading.LoadStart(GUILoading.Mode.FullScreenBlack)));

            GUILoading.Lock(this);
            string detailsInfo = string.Empty;

            //load all textures first
            //------------------
            Manager.TexturesLoadStart();
            //------------------
            yield return(null);

            GUILoading.ActivityInfo = "Loading Textures";
            GUILoading.DetailsInfo  = "Compiling mods";
            while (!Manager.FinishedLoadingTextures)
            {
                yield return(null);
            }
            GUILoading.ActivityInfo = "Generating World";
            GUILoading.DetailsInfo  = "Compiling mods";
            yield return(null);

            //------------------
            Manager.ModsLoadStart();
            //------------------
            //wait for the actual mods manager to finish loading mods
            while (!Mods.Get.ModsLoaded)
            {
                yield return(null);
            }
            //------------------
            Manager.ModsLoadFinish();
            //------------------
            yield return(null);

            //then jump straight ahead to the world loading
            GUILoading.ActivityInfo = "Loading World";
            GUILoading.DetailsInfo  = "Loading mods from generated world";
            //during this section we report on what the world manager is doing
            //it accomplishes nothing but looks nice on the loading screen
            GUILoading.ActivityInfo = "Creating World";
            while (GameWorld.Get.LoadingGameWorld(out detailsInfo))              //report GameWorld progress as it loads the game
            {
                yield return(null);

                GUILoading.DetailsInfo = detailsInfo;
            }
            //wait for other mods as normal
            //------------------
            while (!Manager.FinishedLoadingMods)
            {
                //Debug.Log ("Waiting for mods to finish loading");
                yield return(null);
            }
            //this only happens once per game
            if (!Profile.Get.CurrentGame.HasLoadedOnce)
            {
                GUILoading.ActivityInfo = "Creating World for First Time";
                //Debug.Log ("Creating world for first time");
                //------------------
                Manager.GameLoadStartFirstTime();
                //------------------
            }
            yield return(null);

            //------------------
            Manager.GameLoadStart();
            //------------------
            //give managers a tick to figure out what they're doing
            yield return(null);

            //------------------
            Manager.GameLoadFinish();
            //------------------
            while (!Manager.FinishedLoading)
            {
                //Debug.Log ("Waiting to finish loading...");
                yield return(null);
            }
            //during this section we report on what the spawn manager is up to
            while (SpawnManager.Get.SpawningPlayer(out detailsInfo))
            {
                yield return(null);

                GUILoading.DetailsInfo = detailsInfo;
            }
            //start the game!
            gState = FGameState.GameStarting;
            //wait a tick
            yield return(null);

            //this only happens once per game
            if (!Profile.Get.CurrentGame.HasStarted)
            {
                //------------------
                Manager.GameStartFirstTime();
                //------------------
                Profile.Get.CurrentGame.HasStarted = true;
                yield return(null);
            }
            //------------------
            Manager.GameStart();
            //------------------
            yield return(null);

            if (NetworkManager.Instance.IsHost)
            {
                //if we're the host, then the game can begin here
                //HostState = NHostState.Started;
            }
            //we pause the game immediately while we wait for the player to spawn
            //------------------
            Manager.GamePause();
            //------------------
            yield return(null);

            //save the game so we know that we've started once
            Profile.Get.SaveCurrent(ProfileComponents.Profile);
            //wait for the player to finish spawning then turn off the loading screen
            while (!Player.Local.HasSpawned)
            {
                //Debug.Log("Waiting for player to spawn");
                yield return(null);
            }
            //turn off the loading screen
            GUILoading.Unlock(this);
            yield return(StartCoroutine(GUILoading.LoadFinish()));

            //now that the player has spawned continue the game
            //------------------
            Manager.GameContinue();
            //------------------
            //this will set the state to InGame
            yield break;
        }
Пример #6
0
        protected IEnumerator MakeTradeoverTime()
        {
            Debug.Log("Starting to make trade");
            var loadStart = GUILoading.LoadStart(GUILoading.Mode.SmallInGame);

            while (loadStart.MoveNext())
            {
                yield return(null);
            }
            GUILoading.ActivityInfo = "Making Trade... " + CharacterGoods.Count.ToString() + " character goods going to player";
            //give stuff to player...
            foreach (BarterGoods good in CharacterGoods)
            {
                foreach (KeyValuePair <WIStack, int> goodPair in good)
                {
                    if (goodPair.Key.HasTopItem)
                    {
                        Debug.Log("Adding " + goodPair.Key.TopItem.FileName + " to player inventory...");
                    }
                    var addItem = PlayerInventory.AddItems(goodPair.Key, goodPair.Value);
                    while (addItem.MoveNext())
                    {
                        yield return(null);
                    }
                }
                yield return(null);
            }
            //wait a tick...
            yield return(null);

            //give stuff to character...
            foreach (BarterGoods good in PlayerGoods)
            {
                foreach (KeyValuePair <WIStack, int> goodPair in good)
                {
                    var enumerator = CharacterInventory.AddItems(goodPair.Key, goodPair.Value);
                    while (enumerator.MoveNext())
                    {
                        yield return(null);
                    }
                }
            }
            //TODO determine what counts as a 'successful use'
            BarterManager.Use(true);

            PlayerBank.Absorb(CharacterGoodsBank);
            CharacterBank.Absorb(PlayerGoodsBank);

            ClearGoodsAndCurrency();
            MadeTradeThisSession = true;
            Player.Get.AvatarActions.ReceiveAction(AvatarAction.BarterMakeTrade, WorldClock.AdjustedRealTime);
            var loadFinish = GUILoading.LoadFinish();

            while (loadFinish.MoveNext())
            {
                yield return(null);
            }
            Debug.Log("Finished making trade");
            mMakingTrade = false;
            yield break;
        }