Ejemplo n.º 1
0
        public async Task Populate(IWorld world, int x, int z, GeneratorSettings settings)
        {
            var chunkColumnKey = world.MakeAddressByPartitionKey(new ChunkWorldPos {
                X = x, Z = z
            });
            ChunkColumnCompactStorage chunkColumn = await GrainFactory.GetGrain <IChunkColumn>(chunkColumnKey).GetStateUnsafe();

            Biome chunkBiome = Biome.GetBiome(chunkColumn.Biomes[7 * 16 + 7], settings);

            if (chunkBiome.GetBiomeId() == BiomeId.Plains)
            {
                var decorator = GrainFactory.GetGrain <IBiomePlainsDecorator>((long)BiomeId.Plains);
                await decorator.Decorate(world, new ChunkWorldPos(x, z), settings);

                // decorator.SpawnMob(world, chunk, new ChunkWorldPos(x, z), new BlockWorldPos { X = blockX, Z = blockZ });
            }
            else if (chunkBiome.GetBiomeId() == BiomeId.Forest)
            {
                var decorator = GrainFactory.GetGrain <IBiomeForestDecorator>((long)BiomeId.Forest);
                await decorator.Decorate(world, new ChunkWorldPos(x, z), settings);
            }
            else if (chunkBiome.GetBiomeId() == BiomeId.Taiga)
            {
                var decorator = GrainFactory.GetGrain <IBiomeTaigaDecorator>((long)BiomeId.Taiga);
                await decorator.Decorate(world, new ChunkWorldPos(x, z), settings);
            }
            else if (chunkBiome.GetBiomeId() == BiomeId.Savanna)
            {
                var decorator = GrainFactory.GetGrain <IBiomeSavannaDecorator>((long)BiomeId.Savanna);
                await decorator.Decorate(world, new ChunkWorldPos(x, z), settings);
            }
        }
Ejemplo n.º 2
0
        public void PopulateChunk(IWorld world, ChunkColumnStorage chunk, int x, int z, GeneratorSettings settings)
        {
            int   blockX     = x * 16;
            int   blockZ     = z * 16;
            Biome chunkBiome = Biome.GetBiome(chunk.Biomes[7 * 16 + 7], settings);

            chunkBiome.Decorate(world, GrainFactory, chunk, _random, new BlockWorldPos {
                X = blockX, Y = 0, Z = blockZ
            });
        }
Ejemplo n.º 3
0
        private void GenerateChunk(MapGenerationInfo info, ChunkColumnStorage chunk, int x, int z, GeneratorSettings settings)
        {
            // 生物群系生成
            // 获取生物群系
            int[,] biomeIds = _genlayer.GetInts(x * 16 - 8, z * 16 - 8, 32, 32);

            for (int i = 0; i < 10; ++i)
            {
                for (int j = 0; j < 10; ++j)
                {
                    _biomesForGeneration[j, i] = Biome.GetBiome(biomeIds[(int)(0.861111F * j * 4), (int)(0.861111F * i * 4)], settings);
                }
            }

            // 基本地形生成
            GenerateBasicTerrain(chunk, x, z, settings);

            // 获取生物群系
            biomeIds = _genlayer.GetInts(x * 16, z * 16, 16, 16);

            for (int i = 0; i < 16; ++i)
            {
                for (int j = 0; j < 16; ++j)
                {
                    _biomesForGeneration[j, i] = Biome.GetBiome(biomeIds[j, i], settings);
                }
            }

            // 设置生物群系
            for (int height = 0; height < 64; ++height)
            {
                for (int i = 0; i < 4; ++i)
                {
                    for (int j = 0; j < 4; ++j)
                    {
                        chunk.Biomes[(height * 4 + i) * 4 + j] = (int)_biomesForGeneration[j * 4, i * 4].GetBiomeId();
                    }
                }
            }

            // 添加生物群系特有方块
            ReplaceBiomeBlocks(settings, x, z, chunk, _biomesForGeneration);

            // Todo genrate structure
            // 生成洞穴
            if (settings.UseCaves)
            {
                CavesGenerator generator = new CavesGenerator(info);
                generator.Generate(info, x, z, chunk, _biomesForGeneration[8, 8]);
            }

            // 计算skylight
            GenerateSkylightMap(chunk);
        }
Ejemplo n.º 4
0
        private async Task OnGameTick(object sender, GameTickArgs e)
        {
            if (e.WorldAge % 512 == 0 && e.TimeOfDay > 12000 && e.TimeOfDay < 24000)
            {
                EntityWorldPos playerPosition = AttachedObject.GetValue(EntityWorldPositionComponent.EntityWorldPositionProperty);
                int            x = random.Next(9) - 4 + (int)playerPosition.X;
                int            z = random.Next(9) - 4 + (int)playerPosition.Z;
                BlockWorldPos  monsterBlockPos = new BlockWorldPos(x, 0, z);
                ChunkWorldPos  monsterChunkPos = monsterBlockPos.ToChunkWorldPos();
                var            chunkAccessor   = AttachedObject.GetComponent <ChunkAccessorComponent>();
                BiomeId        biomeId         = await chunkAccessor.GetBlockBiome(monsterBlockPos);

                IWorld            world   = AttachedObject.GetValue(WorldComponent.WorldProperty);
                GeneratorSettings setting = await world.GetGeneratorSettings();

                Biome        biome = Biome.GetBiome((int)biomeId, setting);
                IChunkColumn chunk = await chunkAccessor.GetChunk(monsterChunkPos);

                // TODO
                biome.SpawnMonster(world, GrainFactory, await chunk.GetState(), random, monsterBlockPos);
            }
        }
Ejemplo n.º 5
0
    //Valus to determine whear what biome is on the positions
    public TypeBlock SetUpBiome(int x, int y, int z, float sample, float sample2)
    {
        if ((int)sample2 == 0)
        {
            //sem nemhum
            TileBiome = BiomeType.ForestNormal;
        }
        else if ((int)sample2 == 1)
        {
            //Jungle
            TileBiome = BiomeType.Jungle;
        }
        else if ((int)sample2 == 2)
        {
            //Oceano Normal
            TileBiome = BiomeType.ForestNormal;
        }
        else if ((int)sample2 == 3)
        {
            //Deserto
            TileBiome = BiomeType.Montahas;
        }
        else if ((int)sample2 == 4)
        {
            //sem nemhum
            TileBiome = BiomeType.Plain;
        }
        else if ((int)sample2 == 5)
        {
            //sem nemhum
            TileBiome = BiomeType.Snow;
        }
        else if ((int)sample2 == 6)
        {
            //sem nemhum
            TileBiome = BiomeType.Jungle;
        }
        else if ((int)sample2 == 7)
        {
            //sem nemhum
            TileBiome = BiomeType.Desert;
        }
        else if ((int)sample2 == -4)
        {
            //sem nemhum
            TileBiome = BiomeType.ForestNormal_Dense;
        }
        else if ((int)sample2 == 8)
        {
            //sem nemhum
            TileBiome = BiomeType.ForestNormal_Dense;
        }
        else if ((int)sample2 == -8)
        {
            //sem nemhum
            TileBiome = BiomeType.ForestNormal_Dense;
        }
        else if ((int)sample2 == -2)
        {
            //sem nemhum
            TileBiome = BiomeType.ForestNormal_Dense;
        }
        else
        {
            //Debug.Log("BiomeNum : " + (int)sample2);
            TileBiome = BiomeType.ForestNormal;
        }

        return(Biome.GetBiome(x, y, z, this));
    }