public bool CanSpawnNearby(IPlayer byPlayer, EntityProperties type, Vec3d spawnPosition, RuntimeSpawnConditions sc)
        {
            // Moved from EntitySpawner to here. Make drifters spawn at any light level if temporally unstable. A bit of an ugly hack, i know
            int lightLevel = api.World.BlockAccessor.GetLightLevel((int)spawnPosition.X, (int)spawnPosition.Y, (int)spawnPosition.Z, sc.LightLevelType);

            if (api.World.Config.GetBool("temporalStability", true) && type.Attributes?["spawnCloserDuringLowStability"].AsBool() == true)
            {
                // Below 25% begin reducing range
                double mod = Math.Min(1, 4 * byPlayer.Entity.WatchedAttributes.GetDouble("temporalStability", 1));

                mod = Math.Min(mod, Math.Max(0, 1 - 2 * data.stormGlitchStrength));

                int  surfaceY  = api.World.BlockAccessor.GetTerrainMapheightAt(spawnPosition.AsBlockPos);
                bool isSurface = spawnPosition.Y >= surfaceY - 5;

                float riftDist = NearestRiftDistance(spawnPosition);

                float minl = GameMath.Mix(0, sc.MinLightLevel, (float)mod);
                float maxl = GameMath.Mix(32, sc.MaxLightLevel, (float)mod);
                if (minl > lightLevel || maxl < lightLevel)
                {
                    if (!isSurface || riftDist >= 4 || api.World.Rand.NextDouble() > 0.02)
                    {
                        return(false);
                    }
                }

                double sqdist = byPlayer.Entity.ServerPos.SquareDistanceTo(spawnPosition);

                if (isSurface)
                {
                    return(riftDist < 24);
                }

                // Force a maximum distance
                if (mod < 0.5)
                {
                    return(sqdist < 10 * 10);
                }

                // Force a minimum distance
                return(sqdist > sc.MinDistanceToPlayer * sc.MinDistanceToPlayer * mod);
            }

            if (sc.MinLightLevel > lightLevel || sc.MaxLightLevel < lightLevel)
            {
                return(false);
            }

            return(byPlayer.Entity.ServerPos.SquareDistanceTo(spawnPosition) > sc.MinDistanceToPlayer * sc.MinDistanceToPlayer);
        }
Beispiel #2
0
        public virtual bool CanSpawnNearby(EntityProperties type, Vec3d spawnPosition, RuntimeSpawnConditions sc)
        {
            if (OnCanSpawnNearby != null)
            {
                return(OnCanSpawnNearby(type, spawnPosition, sc));
            }

            return(true);
        }