예제 #1
0
        public void SpawnDarkrotNode(Vector3 position)
        {
            GameObject  newDarkrotNodeObject = GameObject.Instantiate(DarkrotNodePrefab, position, Quaternion.identity) as GameObject;
            DarkrotNode newDarkrotNode       = newDarkrotNodeObject.GetComponent <DarkrotNode> ();

            DarkrotNodes.Add(newDarkrotNode);
            newDarkrotNode.Form(mDarkrotSizes [UnityEngine.Random.Range(0, mDarkrotSizes.Count)]);
        }
예제 #2
0
        public void FixedUpdate()
        {
            mUpdateDarkrot++;
            if (mUpdateDarkrot > 4)
            {
                mUpdateDarkrot = 0;
                if (GameManager.Is(FGameState.InGame))
                {
                    //update exisiting darkrot nodes
                    for (int i = DarkrotNodes.LastIndex(); i >= 0; i--)
                    {
                        DarkrotNode node = DarkrotNodes [i];
                        if (node == null)
                        {
                            DarkrotNodes.RemoveAt(i);
                        }
                        else if (node.IsDispersed)
                        {
                            node.Destroy();
                            DarkrotNodes.RemoveAt(i);
                        }
                        else if (!node.Dispersing && node.IsTimeToMove)
                        {
                            //move the darkrot node towards the player
                            Vector3 newPosition = Vector3.MoveTowards(
                                node.mTr.position,
                                Player.Local.Position,
                                Mathf.Min(Vector3.Distance(node.mTr.position, Player.Local.Position), Globals.DarkrotMaxSpeed));

                            node.Move(newPosition);
                            //there's a random chance it'll emit a sound
                            MasterAudio.PlaySound(MasterAudio.SoundType.Darkrot, node.mTr, DarkrotAudioClips [UnityEngine.Random.Range(0, DarkrotAudioClips.Count)]);
                        }
                    }
                    //see if we're supposed to create new nodes

                    if (SpawnDarkrot && !GameWorld.Get.CurrentBiome.OuterSpace && (WorldClock.IsNight))
                    {
                        if ((!Player.Local.Surroundings.IsInCivilization || Player.Local.Surroundings.IsUnderground) && DarkrotNodes.Count < Globals.DarkrotMaxNodes)                          //darkrot only spawns in the wild regardless of difficulty
                        {
                            if (UnityEngine.Random.value < Globals.DarkrotBaseSpawnProbability)
                            {
                                mRandomPointAroundPlayer = Vector3.MoveTowards(Player.Local.Position, Player.Local.FocusVector.ToXZ(), Globals.DarkrotSpawnDistance);
                                //if we're underground we'll use different methods
                                //mTerrainType = GameWorld.Get.TerrainTypeAtInGamePosition(mRandomPointAroundPlayer, Player.Local.Surroundings.IsUnderground);
                                //is this civilized area? check the terrain type
                                bool spawnDarkrot = true;
                                if (Globals.DarkrotSpawnsOnlyInForests)
                                {
                                    mTerrainType = GameWorld.Get.TerrainTypeAtInGamePosition(mRandomPointAroundPlayer, Player.Local.Surroundings.IsUnderground);
                                    if (mTerrainType.g <= 0)
                                    {
                                        spawnDarkrot = false;
                                    }
                                }
                                if (spawnDarkrot)
                                {
                                    //if it's not civilized and we're in a forest / don't need to be in a forest
                                    mTerrainHit.feetPosition   = mRandomPointAroundPlayer;
                                    mTerrainHit.groundedHeight = 5f;
                                    mRandomPointAroundPlayer.y = GameWorld.Get.TerrainHeightAtInGamePosition(ref mTerrainHit);                                     //don't bother with terrain meshes
                                    //adjust the y position to the terrain
                                    //spawn the node
                                    SpawnDarkrotNode(mRandomPointAroundPlayer);
                                }
                            }
                        }
                    }
                    else
                    {
                        //if it's not nightime or underground
                        if (!Player.Local.Surroundings.IsUnderground)
                        {
                            //disperese all the darkrot, we're done here
                            for (int i = 0; i < DarkrotNodes.Count; i++)
                            {
                                DarkrotNodes [i].Disperse(Mathf.Infinity);
                            }
                            DarkrotNodes.Clear();
                        }
                    }
                }
            }
        }