private void onCmdLineTestServer(IServerPlayer player, int groupId, CmdArgs args)
        {
            if (args.PeekWord() == "clear")
            {
                foreach (var val in lightningFlashes)
                {
                    val.Dispose();
                }
                lightningFlashes.Clear();
                return;
            }

            var pos = player.Entity.Pos.AheadCopy((int)args.PopInt(10)).XYZ;

            weatherSys.SpawnLightningFlash(pos);
        }
Exemplo n.º 2
0
        public void TickEvery25ms(float dt)
        {
            if (ws.api.Side == EnumAppSide.Client)
            {
                clientUpdate(dt);
            }
            else
            {
                double nowTotalHours = ws.api.World.Calendar.TotalHours;
                int    i             = 0;
                while (nowTotalHours - LastUpdateTotalHours > 1 && i++ < 1000)
                {
                    TickEveryInGameHourServer(LastUpdateTotalHours);
                    LastUpdateTotalHours++;
                }

                var   rnd = ws.api.World.Rand;
                float targetLightninMinTemp = CurWeatherEvent.State.LightningMinTemp;
                if (rnd.NextDouble() < CurWeatherEvent.State.LightningRate)
                {
                    ClimateCondition nowcond = ws.api.World.BlockAccessor.GetClimateAt(regionCenterPos, EnumGetClimateMode.ForSuppliedDateValues, ws.api.World.Calendar.TotalDays);
                    if (nowcond.Temperature >= targetLightninMinTemp && nowcond.RainCloudOverlay > 0.15)
                    {
                        Vec3d pos = regionCenterPos.ToVec3d().Add(-200 + rnd.NextDouble() * 400, ws.api.World.SeaLevel, -200 + rnd.NextDouble() * 400);
                        ws.SpawnLightningFlash(pos);
                    }
                }
            }

            if (Transitioning)
            {
                float speed = ws.api.World.Calendar.SpeedOfTime / 60f;
                Weight += dt / TransitionDelay * speed;

                if (Weight > 1)
                {
                    Transitioning = false;
                    Weight        = 1;
                }
            }
            else
            {
                if (ws.autoChangePatterns && ws.api.Side == EnumAppSide.Server && ws.api.World.Calendar.TotalHours > NewWePattern.State.ActiveUntilTotalHours)
                {
                    TriggerTransition();
                }
            }

            if (ws.autoChangePatterns && ws.api.Side == EnumAppSide.Server)
            {
                bool sendPacket = false;

                if (ws.api.World.Calendar.TotalHours > CurWindPattern.State.ActiveUntilTotalHours)
                {
                    CurWindPattern = WindPatterns[Rand.NextInt(WindPatterns.Length)];
                    CurWindPattern.OnBeginUse();
                    sendPacket = true;
                }

                if (ws.api.World.Calendar.TotalHours > CurWeatherEvent.State.ActiveUntilTotalHours || CurWeatherEvent.ShouldStop(weatherData.climateCond.Rainfall, weatherData.climateCond.Temperature))
                {
                    CurWeatherEvent = RandomWeatherEvent();
                    CurWeatherEvent.OnBeginUse();
                    sendPacket = true;
                }

                if (sendPacket)
                {
                    wsServer.SendWeatherStateUpdate(new WeatherState()
                    {
                        RegionX         = regionX,
                        RegionZ         = regionZ,
                        NewPattern      = NewWePattern.State,
                        OldPattern      = OldWePattern.State,
                        WindPattern     = CurWindPattern.State,
                        WeatherEvent    = CurWeatherEvent?.State,
                        TransitionDelay = TransitionDelay,
                        Transitioning   = Transitioning,
                        Weight          = Weight,
                        LcgCurrentSeed  = Rand.currentSeed,
                        LcgMapGenSeed   = Rand.mapGenSeed,
                        LcgWorldSeed    = Rand.worldSeed
                    });
                }
            }


            NewWePattern.Update(dt);
            OldWePattern.Update(dt);

            CurWindPattern.Update(dt);
            CurWeatherEvent.Update(dt);

            float curWindSpeed    = weatherData.curWindSpeed.X;
            float targetWindSpeed = (float)GetWindSpeed(ws.api.World.SeaLevel);

            curWindSpeed += GameMath.Clamp((targetWindSpeed - curWindSpeed) * dt, -0.001f, 0.001f);
            weatherData.curWindSpeed.X = curWindSpeed;

            quarterSecAccum += dt;
            if (quarterSecAccum > 0.25f)
            {
                regionCenterPos.Y = ws.api.World.BlockAccessor.GetRainMapHeightAt(regionCenterPos);
                if (regionCenterPos.Y == 0)
                {
                    regionCenterPos.Y = ws.api.World.SeaLevel;                         // Map chunk might not be loaded. In that case y will be 0.
                }
                ClimateCondition nowcond = ws.api.World.BlockAccessor.GetClimateAt(regionCenterPos);
                if (nowcond != null)
                {
                    weatherData.climateCond = nowcond;
                }

                quarterSecAccum = 0;
            }

            weatherData.BlendedPrecType = CurWeatherEvent.State.PrecType;
        }