예제 #1
0
            new public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
            {
                Storm.InitializeStatics(chunks.World.ParticleManager);
                BoundingBox box = chunks.Bounds;

                box.Expand(10.0f);

                if (GlobalTransform.Translation.X < box.Min.X ||
                    GlobalTransform.Translation.X > box.Max.X ||
                    GlobalTransform.Translation.Z < box.Min.Z ||
                    GlobalTransform.Translation.Z > box.Max.Z)
                {
                    Die();
                }


                bool generateRainDrop = MathFunctions.RandEvent(Raininess);

                if (generateRainDrop)
                {
                    for (int i = 0; i < MaxRainDrops; i++)
                    {
                        if (!RainDrops[i].IsAlive)
                        {
                            RainDrops[i].IsAlive = true;
                            RainDrops[i].Pos     = MathFunctions.RandVector3Box(BoundingBox);
                            RainDrops[i].Pos     = new Vector3(RainDrops[i].Pos.X, BoundingBox.Min.Y - 1, RainDrops[i].Pos.Z);
                            RainDrops[i].Vel     = Vector3.Down * Storm.Properties[TypeofStorm].RainSpeed + Velocity;
                            break;
                        }
                    }
                }

                Voxel test = new Voxel();

                Storm.StormProperties stormProperties = Storm.Properties[TypeofStorm];
                for (int i = 0; i < MaxRainDrops; i++)
                {
                    if (!RainDrops[i].IsAlive)
                    {
                        continue;
                    }

                    RainDrops[i].Pos += RainDrops[i].Vel * DwarfTime.Dt;

                    if (stormProperties.RainRandom > 0)
                    {
                        RainDrops[i].Vel.X += MathFunctions.Rand(-1, 1) * stormProperties.RainRandom * DwarfTime.Dt;
                        RainDrops[i].Vel.Z += MathFunctions.Rand(-1, 1) * stormProperties.RainRandom * DwarfTime.Dt;
                    }

                    if (RainDrops[i].Pos.Y < 0)
                    {
                        RainDrops[i].IsAlive = false;
                    }

                    if (!RainDrops[i].IsAlive && RainDrops[i].Particle != null)
                    {
                        RainDrops[i].Particle.LifeRemaining = -1;
                        RainDrops[i].Particle = null;
                    }
                    else if (RainDrops[i].IsAlive && RainDrops[i].Particle == null)
                    {
                        RainDrops[i].Particle = stormProperties.RainEffect.Emitters[0].CreateParticle(RainDrops[i].Pos,
                                                                                                      RainDrops[i].Vel, Color.White);
                    }
                    else if (RainDrops[i].IsAlive && RainDrops[i].Particle != null)
                    {
                        RainDrops[i].Particle.Position = RainDrops[i].Pos;
                        RainDrops[i].Particle.Velocity = RainDrops[i].Vel;
                    }

                    if (!chunks.ChunkData.GetVoxel(RainDrops[i].Pos, ref test))
                    {
                        continue;
                    }
                    if (test == null || test.IsEmpty || test.WaterLevel > 0)
                    {
                        continue;
                    }

                    RainDrops[i].IsAlive = false;
                    stormProperties.HitEffect.Trigger(1, RainDrops[i].Pos + Vector3.UnitY * 0.5f, Color.White);

                    if (!MathFunctions.RandEvent(0.1f))
                    {
                        continue;
                    }

                    Voxel above = test.IsEmpty ? test : test.GetVoxelAbove();

                    if (above == null)
                    {
                        continue;
                    }
                    if (stormProperties.CreatesLiquid &&
                        (above.WaterLevel < WaterManager.maxWaterLevel && (above.Water.Type == LiquidType.Water || above.Water.Type == LiquidType.None)))
                    {
                        WaterCell water = above.Water;
                        water.WaterLevel = (byte)Math.Min(WaterManager.maxWaterLevel, water.WaterLevel + WaterManager.rainFallAmount);
                        water.Type       = stormProperties.LiquidToCreate;

                        above.Water = water;
                        above.Chunk.ShouldRebuildWater = true;
                    }
                    else if (stormProperties.CreatesVoxel && above.IsEmpty && above.WaterLevel == 0)
                    {
                        above.Type   = stormProperties.VoxelToCreate;
                        above.Water  = new WaterCell();
                        above.Health = above.Type.StartingHealth;
                        above.Chunk.NotifyTotalRebuild(!above.IsInterior);
                    }
                }



                Matrix tf = LocalTransform;

                tf.Translation += Velocity * DwarfTime.Dt;
                LocalTransform  = tf;
                base.Update(gameTime, chunks, camera);
            }