protected override void OnSpawnerTick(float deltaTime)
        {
            if (ServerAPI.World.ElapsedMilliseconds - TimeSinceSpawn > NextShower)
            {
                if (ServerAPI.World.AllOnlinePlayers.Length > 0)
                {
                    MeteorCode        = GetRandomEntityCode();
                    ShowerTranslation = DetermineTranslation();

                    int numShowerMeteors = SpawnerRand.Next(0, ServerAPI.World.Config.GetInt("MaxMeteorsPerShower"));
                    int showerTime       = SpawnerRand.Next(ServerAPI.World.Config.GetInt("MinimumShowerDurationInMinutes"), ServerAPI.World.Config.GetInt("MaximumShowerDurationInMinutes"));

                    UnregisterShowerCallbacks();

                    ShowerCallbacks = new long[numShowerMeteors];

                    for (int i = 0; i < ShowerCallbacks.Length; i++)
                    {
                        double offsetTime = SpawnerRand.NextDouble();

                        ShowerCallbacks[i] = ServerAPI.Event.RegisterCallback(SpawnShowerMeteor, (int)(MeteoricExpansionHelpers.ConvertMinutesToMilliseconds(SpawnerRand.Next(0, showerTime)) + MeteoricExpansionHelpers.ConvertMinutesToMilliseconds(offsetTime)));
                    }

                    NextSpawn = SpawnerRand.Next(MinShowerSpawnTime, MaxShowerSpawnTime) + SpawnerRand.NextDouble();
                    NextSpawn = MeteoricExpansionHelpers.ConvertMinutesToMilliseconds(NextSpawn);

                    TimeSinceSpawn = ServerAPI.World.ElapsedMilliseconds + MeteoricExpansionHelpers.ConvertMinutesToMilliseconds(showerTime);
                }
            }
        }
Пример #2
0
        protected Vec3d DetermineTranslation()
        {
            double horiztontalTranslation, verticalTranslation;

            horiztontalTranslation = SpawnerRand.NextDouble();
            verticalTranslation    = SpawnerRand.NextDouble();

            bool isMovingEast  = Convert.ToBoolean(SpawnerRand.Next(0, 2));
            bool isMovingSouth = Convert.ToBoolean(SpawnerRand.Next(0, 2));

            Vec3d randomTranslation = new Vec3d
            {
                X = horiztontalTranslation,
                Y = verticalTranslation,
                Z = 1 - horiztontalTranslation
            };

            if (isMovingEast != false)
            {
                randomTranslation.X *= -1;
            }

            if (isMovingSouth != false)
            {
                randomTranslation.Y *= -1;
            }

            return(randomTranslation);
        }
Пример #3
0
        protected string GetRandomEntityCode()
        {
            string[] possibleCodes = GetEntityCodes();
            string   chosenCode    = possibleCodes[SpawnerRand.Next(0, possibleCodes.Length)];

            return(chosenCode);
        }
Пример #4
0
        /// <summary>
        /// Offsets meteor spawn position so that it does not spawn directly above the player. Be sure to set the MinSpawnDistance and MaxSpawnDistance before calling the base method.
        /// </summary>
        /// <returns></returns>
        protected virtual double GetSpawnOffset()
        {
            int    negativeRand = SpawnerRand.Next(0, 2);
            double spawnOffset  = SpawnerRand.Next(ServerAPI.WorldManager.ChunkSize * MinSpawnDistance, ServerAPI.WorldManager.ChunkSize * MaxSpawnDistance) + SpawnerRand.NextDouble();

            if (negativeRand == 0)
            {
                return(-spawnOffset);
            }

            return(spawnOffset);
        }
Пример #5
0
        //-- Spawn a meteor made with random rock and metals above the first online player every number of seconds as determined by tickIntervalInSeconds --//
        //-- Eventually spawns will happen between the minMeteorSpawnTime and maxMeteorSpawnTime --//
        protected override void OnSpawnerTick(float deltaTime)
        {
            if (ServerAPI.World.ElapsedMilliseconds - TimeSinceSpawn > NextSpawn)
            {
                if (ServerAPI.World.AllOnlinePlayers.Length > 0)
                {
                    ServerAPI.World.SpawnEntity(GenerateEntity());
                }

                NextSpawn = SpawnerRand.Next(MinSpawnTime, MaxSpawnTime) + SpawnerRand.NextDouble();
                NextSpawn = MeteoricExpansionHelpers.ConvertMinutesToMilliseconds(NextSpawn);

                TimeSinceSpawn = this.ServerAPI.World.ElapsedMilliseconds;
            }
        }
        protected override void Initialize(ICoreServerAPI sApi)
        {
            ConfigDisableShowers = sApi.World.Config.GetBool("DisableShowers");

            if (ConfigDisableShowers == false)
            {
                base.Initialize(sApi);

                EntityTypeToSpawn = typeof(EntityShowerMeteor);

                SpawnTickListener = ServerAPI.Event.RegisterGameTickListener(OnSpawnerTick, SPAWNER_TICK_INTERVAL);

                MinShowerSpawnTime = ServerAPI.World.Config.GetInt("MinimumMinutesBetweenShowers");
                MaxShowerSpawnTime = ServerAPI.World.Config.GetInt("MaximumMinutesBetweenShowers");

                MinSpawnDistance = ServerAPI.World.Config.GetInt("MinimumShowerSpawnDistanceInChunks");
                MaxSpawnDistance = ServerAPI.World.Config.GetInt("MaximumShowerSpawnDistanceInChunks");

                NextShower = SpawnerRand.Next(MinShowerSpawnTime, MaxShowerSpawnTime) + SpawnerRand.NextDouble();
                NextShower = MeteoricExpansionHelpers.ConvertMinutesToMilliseconds(NextShower);
            }
        }
Пример #7
0
        protected int SpawnNearPlayer()
        {
            int totalPlayersOnline = ServerAPI.World.AllOnlinePlayers.Length;

            return(SpawnerRand.Next(0, totalPlayersOnline));
        }