Exemple #1
0
        public override bool Generate()
        {
            bool placed   = false;
            int  attempts = 0;

            while (!placed && attempts++ < 100000)
            {
                // Select a place in the first 4th of the world, avoiding the oceans
                int towerX = WorldGen.genRand.Next(300, Main.maxTilesX / 4);                 // from 50 since there's a unaccessible area at the world's borders
                // 50% of choosing the last 4th of the world
                // Choose which side of the world to be on randomly
                if (WorldGen.genRand.NextBool())
                {
                    towerX = Main.maxTilesX - towerX;
                }

                //Start at 200 tiles above the surface instead of 0, to exclude floating islands
                int towerY = (int)Main.worldSurface - 200;

                // We go down until we hit a solid tile or go under the world's surface
                while (!WorldGen.SolidTile(towerX, towerY) && towerY <= Main.worldSurface)
                {
                    towerY++;
                }

                // If we went under the world's surface, try again
                if (towerY > Main.worldSurface)
                {
                    continue;
                }
                Tile tile = Main.tile[towerX, towerY];
                // If the type of the tile we are placing the hideout on doesn't match what we want, try again
                if (!(tile.type == TileID.Dirt ||
                      tile.type == TileID.Grass ||
                      tile.type == TileID.Stone ||
                      tile.type == TileID.Mud ||
                      tile.type == TileID.FleshGrass ||
                      tile.type == TileID.CorruptGrass ||
                      tile.type == TileID.JungleGrass ||
                      tile.type == TileID.Sand ||
                      tile.type == TileID.Crimsand ||
                      tile.type == TileID.Ebonsand ||
                      tile.type == TileID.SnowBlock))
                {
                    continue;
                }

                // Don't place the hideout if the area isn't flat
                if (!MyWorld.CheckFlat(towerX, towerY, Tiles.GetLength(1), 3))
                {
                    continue;
                }

                Place(towerX, towerY);
                int num = NPC.NewNPC((towerX + 31) * 16, (towerY - 20) * 16, ModContent.NPCType <BoundRogue>());
                Main.npc[num].homeTileX = -1;
                Main.npc[num].homeTileY = -1;
                Main.npc[num].direction = 1;
                Main.npc[num].homeless  = true;

                placed = true;
            }
            if (!placed)
            {
                SpiritMod.instance.Logger.Error("Worldgen: FAILED to place Bandit Hideout, ground not flat enough?");
            }
            return(placed);
        }
        public override bool Generate()
        {
            shingleColor = WorldGen.genRand.NextBool() ? TileID.RedDynastyShingles : TileID.BlueDynastyShingles;
            bool placed   = false;
            int  attempts = 0;

            while (!placed && attempts++ < 100000)
            {
                // Select a place in the first 6th of the world, avoiding the oceans
                int towerX = WorldGen.genRand.Next(300, Main.maxTilesX / 6);                 // from 50 since there's a unaccessible area at the world's borders
                // 50% of choosing the last 6th of the world
                // Choose which side of the world to be on randomly
                if (WorldGen.genRand.NextBool())
                {
                    towerX = Main.maxTilesX - towerX;
                }

                //Start at 200 tiles above the surface instead of 0, to exclude floating islands
                int towerY = (int)Main.worldSurface - 200;

                // We go down until we hit a solid tile or go under the world's surface
                while (!WorldGen.SolidTile(towerX, towerY) && towerY <= Main.worldSurface)
                {
                    towerY++;
                }

                // If we went under the world's surface, try again
                if (towerY > Main.worldSurface)
                {
                    continue;
                }
                Tile tile = Main.tile[towerX, towerY];
                // If the type of the tile we are placing the tower on doesn't match what we want, try again
                if (!(tile.type == TileID.Dirt ||
                      tile.type == TileID.Grass ||
                      tile.type == TileID.Stone ||
                      tile.type == TileID.Mud ||
                      tile.type == TileID.FleshGrass ||
                      tile.type == TileID.CorruptGrass ||
                      tile.type == TileID.JungleGrass ||
                      tile.type == TileID.Sand ||
                      tile.type == TileID.Crimsand ||
                      tile.type == TileID.Ebonsand))
                {
                    continue;
                }

                // Don't place the tower if the area isn't flat
                if (!MyWorld.CheckFlat(towerX, towerY, Tiles.GetLength(1), 3))
                {
                    continue;
                }

                // place the tower
                Place(towerX, towerY);
                // extend the base a bit
                for (int i = towerX - 2; i < towerX + Tiles.GetLength(1) - 4; i++)
                {
                    for (int k = towerY + 3; k < towerY + 12; k++)
                    {
                        WorldGen.PlaceTile(i, k, TileID.StoneSlab, mute: true, forced: true);
                        WorldGen.SlopeTile(i, k);
                    }
                }
                // place the Rogue
                int num = NPC.NewNPC((towerX + 12) * 16, (towerY - 24) * 16, ModContent.NPCType <BoundGambler>(), 0, 0f, 0f, 0f, 0f, 255);
                Main.npc[num].homeTileX = -1;
                Main.npc[num].homeTileY = -1;
                Main.npc[num].direction = 1;
                Main.npc[num].homeless  = true;
                placed = true;
            }
            if (!placed)
            {
                SpiritMod.instance.Logger.Error("Worldgen: FAILED to place Goblin Tower, ground not flat enough?");
            }
            return(placed);
        }