public static WorldInstance GenerateDungeon(string name, int size, int levels, params string[] dungeonTypes) { DungeonInteriorGenerator interiorGenerator = new DungeonInteriorGenerator(); SpawnPointPlacer spawnPointPlacer = new SpawnPointPlacer(); List <string> entitiesToPlace = new List <string>(); if (dungeonTypes != null) { entitiesToPlace.AddRange(dungeonTypes); } WorldInstance root = null; WorldInstance current = null; for (int i = 1; i <= levels; i++) { WorldTile[,] tiles = interiorGenerator.GenerateWorldSpace(size); WorldInstance worldInstance = new WorldInstance(tiles, WorldType.Interior, name + " " + i); List <JoyObject> walls = interiorGenerator.GenerateWalls(tiles); foreach (JoyObject wall in walls) { worldInstance.AddObject(wall); } List <ItemInstance> items = DungeonItemPlacer.PlaceItems(worldInstance); foreach (ItemInstance item in items) { worldInstance.AddObject(item); } List <Entity> entities = DungeonEntityPlacer.PlaceEntities(worldInstance, entitiesToPlace); foreach (Entity entity in entities) { worldInstance.AddEntity(entity); } //Do the spawn points worldInstance.SpawnPoint = spawnPointPlacer.PlaceSpawnPoint(worldInstance); //Use this as our root if we don't have one if (root == null) { root = worldInstance; } //Link to the previous floor if (current != null) { current.AddArea(worldInstance.SpawnPoint, worldInstance); } current = worldInstance; } return(root); }
private void CreateWorld() { //Make a new overworld generator OverworldGenerator overworldGen = new OverworldGenerator(); //Generate the basic overworld m_World = new WorldInstance(overworldGen.GenerateWorldSpace(WORLD_SIZE), WorldType.Overworld, "Everse"); //Set the date and time for 1/1/1555, 12:00pm m_World.SetDateTime(new DateTime(1555, 1, 1, 12, 0, 0)); //Do the spawn point SpawnPointPlacer spawnPlacer = new SpawnPointPlacer(); Vector2Int spawnPoint = spawnPlacer.PlaceSpawnPoint(m_World); while ((spawnPoint.x == -1 && spawnPoint.y == -1)) { spawnPoint = spawnPlacer.PlaceSpawnPoint(m_World); } m_World.SpawnPoint = spawnPoint; //Set up the player m_Player.Move(m_World.SpawnPoint); m_Player.MyWorld = m_World; m_World.AddEntity(m_Player); //Begin the first floor of the Naga Pits List <string> dungeonTypes = new List <string>(); dungeonTypes.Add("Naga"); dungeonTypes.Add("Dungeon Slime"); WorldInstance dungeon = DungeonGenerator.GenerateDungeon("Naga Pits", WORLD_SIZE, 3, dungeonTypes.ToArray()); Vector2Int transitionPoint = spawnPlacer.PlaceTransitionPoint(m_World); m_World.AddArea(transitionPoint, dungeon); Done = true; m_Player.AddItem(new ItemInstance(ItemHandler.GetSpecificItem("Lantern"), new Vector2Int(-1, -1), true)); m_World.Tick(); }
private void CreateWorld() { //Make a new overworld generator OverworldGenerator overworldGen = new OverworldGenerator(this.m_WorldInfoHandler); //Generate the basic overworld this.m_World = new WorldInstance( overworldGen.GenerateWorldSpace(WORLD_SIZE, "plains"), new string[] { "overworld", "exterior" }, "Everse", GlobalConstants.GameManager.EntityHandler, GlobalConstants.GameManager.Roller); //Set the date and time for 1/1/1555, 12:00pm this.m_World.SetDateTime(new JoyDateTime(1555, 1, 1, 12)); //Do the spawn point SpawnPointPlacer spawnPlacer = new SpawnPointPlacer(GlobalConstants.GameManager.Roller); Vector2Int spawnPoint = spawnPlacer.PlaceSpawnPoint(this.m_World); while ((spawnPoint.x == -1 && spawnPoint.y == -1)) { spawnPoint = spawnPlacer.PlaceSpawnPoint(this.m_World); } this.m_World.SpawnPoint = spawnPoint; //Set up the player //m_Player.Move(m_World.SpawnPoint); //m_World.AddEntity(m_Player); //Begin the first floor of the Naga Pits WorldInfo worldInfo = this.m_WorldInfoHandler.GetRandom("interior"); DungeonGenerator dungeonGenerator = new DungeonGenerator(); WorldInstance dungeon = dungeonGenerator.GenerateDungeon( worldInfo, WORLD_SIZE, 3, GlobalConstants.GameManager, GlobalConstants.GameManager.Roller); Vector2Int transitionPoint = spawnPlacer.PlaceTransitionPoint(this.m_World); this.m_World.AddArea(transitionPoint, dungeon); this.Done = true; this.m_ActiveWorld = dungeon; this.m_Player.Move(dungeon.SpawnPoint); dungeon.AddEntity(this.m_Player); GlobalConstants.GameManager.EntityHandler.Add(this.m_Player); IItemInstance lightSource = GlobalConstants.GameManager.ItemFactory.CreateRandomItemOfType( new string[] { "light source" }, true); IItemInstance bag = GlobalConstants.GameManager.ItemFactory.CreateRandomItemOfType( new[] { "container" }, true); IJoyAction addItemAction = this.m_Player.FetchAction("additemaction"); addItemAction.Execute( new IJoyObject[] { this.m_Player, lightSource }, new[] { "pickup" }, new Dictionary <string, object> { { "newOwner", true } }); addItemAction.Execute( new IJoyObject[] { this.m_Player, bag }, new[] { "pickup" }, new Dictionary <string, object> { { "newOwner", true } }); for (int i = 0; i < 4; i++) { IItemInstance newItem = GlobalConstants.GameManager.ItemFactory.CreateRandomWeightedItem( true, false); addItemAction.Execute( new IJoyObject[] { this.m_Player, newItem }, new[] { "pickup" }, new Dictionary <string, object> { { "newOwner", true } }); } this.m_World.Tick(); GlobalConstants.GameManager.WorldHandler.Add(this.m_World); WorldSerialiser worldSerialiser = new WorldSerialiser(GlobalConstants.GameManager.ObjectIconHandler); worldSerialiser.Serialise(this.m_World); this.Done = true; }
public WorldInstance GenerateDungeon( WorldInfo.WorldInfo worldInfo, int size, int levels, IGameManager gameManager, RNG roller) { DungeonInteriorGenerator interiorGenerator = new DungeonInteriorGenerator( gameManager.GUIDManager, gameManager.ObjectIconHandler, gameManager.DerivedValueHandler, gameManager.WorldInfoHandler, roller); SpawnPointPlacer spawnPointPlacer = new SpawnPointPlacer(roller); DungeonItemPlacer itemPlacer = new DungeonItemPlacer( gameManager.ItemHandler, roller, gameManager.ItemFactory); DungeonEntityPlacer entityPlacer = new DungeonEntityPlacer( gameManager.EntityHandler, gameManager.CultureHandler, gameManager.EntityTemplateHandler, gameManager.PhysicsManager, gameManager.EntityFactory); List <string> entitiesToPlace = new List <string>(worldInfo.inhabitants); List <string> cultures = new List <string>(worldInfo.cultures); WorldInstance root = null; WorldInstance current = null; for (int i = 1; i <= levels; i++) { WorldTile[,] tiles = interiorGenerator.GenerateWorldSpace(size, worldInfo.name); HashSet <Vector2Int> walls = interiorGenerator.GenerateWalls(tiles); WorldInstance worldInstance = new WorldInstance( tiles, worldInfo.tags, worldInfo.name + " " + i, gameManager.EntityHandler, roller); foreach (Vector2Int wall in walls) { worldInstance.AddWall(wall); } List <IItemInstance> items = itemPlacer.PlaceItems(worldInstance); IEnumerable <IEntity> entities = entityPlacer.PlaceEntities( worldInstance, cultures, entitiesToPlace, roller); foreach (IEntity entity in entities) { worldInstance.AddEntity(entity); } //Do the spawn points worldInstance.SpawnPoint = spawnPointPlacer.PlaceSpawnPoint(worldInstance); //Use this as our root if we don't have one if (root == null) { root = worldInstance; } //Link to the previous floor if (current != null) { current.AddArea(spawnPointPlacer.PlaceTransitionPoint(current), worldInstance); } current = worldInstance; } return(root); }