Esempio n. 1
0
    public static List <Vector2Int> GenerateDungeon(DungeonGenerationData dungeonData)
    {
        //Define list of dungeon crawlers
        List <DungeonCrawler> dungeonCrawlers = new List <DungeonCrawler>();

        for (int i = 0; i < dungeonData.numberOfCrawlers; i++)
        {
            //Add a dungeon crawler to the list starting at zero
            dungeonCrawlers.Add(new DungeonCrawler(Vector2Int.zero));
        }

        //Define the number of iterations
        int iterations = Random.Range(dungeonData.iterationMin, dungeonData.iterationMax);

        //Loop through based on the number of iterations
        for (int i = 0; i < iterations; i++)
        {
            //Loop through the dungeon crawlers in the scene
            foreach (DungeonCrawler dungeonCrawler in dungeonCrawlers)
            {
                //Define a new position for the map
                Vector2Int newPos = dungeonCrawler.Move(directionMovementMap);

                //Add the new position to the positions visited to avoid overlap
                positionsVisited.Add(newPos);
            }
        }

        return(positionsVisited);
    }
    //Main function to generate dungeon. Every dungeon crawler goes into a random direction. It adds to positions list. The number of positions depends on a random number between minimal and maximal number of iterations (rooms).
    public static List <Vector2Int> GenerateDungeon(DungeonGenerationData dungeonData)
    {
        List <DungeonCrawler> dungeonCrawlers = new List <DungeonCrawler>();

        for (int i = 0; i < dungeonData.numberOfCrawlers; ++i)
        {
            GameObject     tempGameObject = new GameObject();
            DungeonCrawler crawler        = tempGameObject.AddComponent <DungeonCrawler>();
            crawler.Position = Vector2Int.zero;
            dungeonCrawlers.Add(crawler);
        }
        int iterations = Random.Range(dungeonData.iterationMin, dungeonData.iterationMax);

        for (int i = 0; i < iterations; ++i)
        {
            foreach (DungeonCrawler dungeonCrawler in dungeonCrawlers)
            {
                Vector2Int newPosition = dungeonCrawler.Move(directionMovementMap);
                while (positionsVisited.Contains(newPosition))
                {
                    newPosition = dungeonCrawler.Move(directionMovementMap);
                }
                positionsVisited.Add(newPosition);
            }
        }
        return(positionsVisited);
    }
Esempio n. 3
0
    //Generate the Randomized Room Locations Based on the Variables Assigned in DungeonGenerationData
    public static List <Vector2Int> GenerateDungeon(DungeonGenerationData dungeonData)
    {
        positionsVisited     = new List <Vector2Int>();
        directionMovementMap = new Dictionary <Direction, Vector2Int>
        {
            { Direction.up, Vector2Int.up },
            { Direction.left, Vector2Int.left },
            { Direction.down, Vector2Int.down },
            { Direction.right, Vector2Int.right },
        };

        List <DungeonCrawler> dungeonCrawlers = new List <DungeonCrawler>();

        for (int i = 0; i < dungeonData.numberOfCrawlers; i++)
        {
            dungeonCrawlers.Add(new DungeonCrawler(Vector2Int.zero));
        }

        int iterations = Random.Range(dungeonData.iterationMin, dungeonData.iterationMax);

        for (int i = 0; i < iterations; i++)
        {
            foreach (DungeonCrawler dungeonCrawler in dungeonCrawlers)
            {
                Vector2Int newPos = dungeonCrawler.Move(directionMovementMap);
                positionsVisited.Add(newPos);
            }
        }

        return(positionsVisited);
    }
Esempio n. 4
0
    public List <Vector2Int> GenerateDungeon(DungeonGenerationData dungeonData, Vector2Int startpos)
    {
        positionsVisited = new List <Vector2Int>();
        List <DungeonCrawler> dungeonCrawlers = new List <DungeonCrawler>();

        for (int i = 0; i < dungeonData.numberOfCrawlers; i++)
        {
            dungeonCrawlers.Add(new DungeonCrawler(startpos));
        }

        int iterations = Random.Range(dungeonData.iterationMin, dungeonData.iterationMax);

        for (int i = 0; i < iterations; i++)
        {
            foreach (DungeonCrawler dungeonCrawler in dungeonCrawlers)
            {
                Vector2Int newPos = dungeonCrawler.Move(directionMovementMap);
                Debug.Log(" ho visitato " + newPos);
                if (newPos == startpos)
                {
                    Debug.Log(" ho visitato " + newPos + "ma non la aggiungo");
                }
                else
                {
                    positionsVisited.Add(newPos);
                }
            }
        }
        Debug.Log("fine visita ");
        return(positionsVisited);
    }
    public static List <Vector2Int> GenerateDungeon(
        DungeonGenerationData dungeonData
        )
    {
        List <DungeonCrawler> dungeonCrawlers = new List <DungeonCrawler>();

        for (int i = 0; i < dungeonData.numberOfCrawlers; i++)
        {
            dungeonCrawlers.Add(new DungeonCrawler(Vector2Int.zero));
        }
        int iterations = Random.Range(
            dungeonData.iterationMin,
            dungeonData.iterationMax
            );

        for (int i = 0; i < iterations; i++)
        {
            foreach (DungeonCrawler dungeonCrawler in dungeonCrawlers)
            {
                Vector2Int newPosition = dungeonCrawler.move(directionMovementMap);
                positionVisited.Add(newPosition);
            }
        }
        return(positionVisited);
    }
Esempio n. 6
0
    public void GenerateLevel()
    {
        if (mTestGenerationData != null)
        {
            mCurrentLevelData = mTestGenerationData;
        }
        else
        {
            DetermineCurrentLevelData();
        }

        if (GlobalData.NumHearts <= 0)
        {
            GlobalData.NumHearts = 1;
        }

        ClearProjectiles();
        ClearSpecialObjects();

        mDungeon.GenerateDungeon(mCurrentLevelData.mEnvironmentData);
        mStartPos = mDungeon.GetTilePosition(mDungeon.InitialRoomPosition.mX, mDungeon.InitialRoomPosition.mY);
        RespawnPlayer1();
        mGoal.mSignalType        = SignalType.LevelComplete;
        mGoal.transform.position = FindGoalSpawnPosition();
        mDungeon.SetCell(mGoal.transform.position, DungeonCell.TileType.Goal);

        // Generate room contents
        GenerateCollectables();
        GenerateEnemies();

        Signal.Dispatch(SignalType.LevelStart);
    }
Esempio n. 7
0
    static Dictionary <string, DungeonRoom> GetFinalRooms(List <GenRoom> rooms, DungeonGenerationData genData)
    {
        Dictionary <string, DungeonRoom> finalAreas = new Dictionary <string, DungeonRoom>();

        foreach (var genRoom in rooms)
        {
            DungeonRoom room = new DungeonRoom(genRoom.Id, 1 + (genRoom.gridX - 1) * 7, 1 + (genRoom.gridY - 1) * 7);

            if (genRoom.left != null && genRoom.left.Exists)
            {
                room.Doors.Add(new Door(genRoom.Id, genRoom.left.Id, Direction.Left));
            }

            if (genRoom.right != null && genRoom.right.Exists)
            {
                room.Doors.Add(new Door(genRoom.Id, genRoom.right.Id, Direction.Right));
            }

            if (genRoom.top != null && genRoom.top.Exists)
            {
                room.Doors.Add(new Door(genRoom.Id, genRoom.top.Id, Direction.Top));
            }

            if (genRoom.bot != null && genRoom.bot.Exists)
            {
                room.Doors.Add(new Door(genRoom.Id, genRoom.bot.Id, Direction.Bot));
            }

            finalAreas.Add(room.Id, room);
        }

        return(finalAreas);
    }
Esempio n. 8
0
    static void PopulateRooms(Dungeon dungeon, DungeonGenerationData genData)
    {
        List <DungeonRoom> rooms = Enumerable.ToList(dungeon.Rooms.Values).FindAll(item => item.Type == AreaType.Empty);

        dungeon.TotalRoomBattles = Random.Range(genData.TotalRoomBattleMin, genData.TotalRoomBattleMax + 1);
        int currentBattles = 0;
        int maxBattles     = dungeon.TotalRoomBattles;

        int guardedTresures = Random.Range(genData.RoomGuardedTresureMin, genData.RoomGuardedTresureMax + 1);

        dungeon.RoomGuardedTresure = Mathf.Clamp(guardedTresures, 0, maxBattles - currentBattles);
        currentBattles            += dungeon.RoomGuardedTresure;

        for (int i = 0; i < dungeon.RoomGuardedTresure; i++)
        {
            if (rooms.Count == 0)
            {
                return;
            }

            int index = Random.Range(0, rooms.Count);
            rooms[index].Type = AreaType.BattleTresure;
            rooms.RemoveAt(index);
        }

        int guardedCurios = Random.Range(genData.RoomGuardedCurioMin, genData.RoomGuardedCurioMax + 1);

        dungeon.RoomGuardedCurio = Mathf.Clamp(guardedCurios, 0, maxBattles - currentBattles);
        currentBattles          += dungeon.RoomGuardedCurio;

        for (int i = 0; i < dungeon.RoomGuardedCurio; i++)
        {
            if (rooms.Count == 0)
            {
                return;
            }

            int index = Random.Range(0, rooms.Count);
            rooms[index].Type = AreaType.BattleCurio;
            rooms.RemoveAt(index);
        }

        for (int i = currentBattles; i < dungeon.TotalRoomBattles; i++)
        {
            if (rooms.Count == 0)
            {
                return;
            }

            int index = Random.Range(0, rooms.Count);
            rooms[index].Type = AreaType.Battle;
            rooms.RemoveAt(index);
        }
    }
Esempio n. 9
0
    public static Dungeon GenerateDungeon(Quest quest, int seed = 0)
    {
        if (seed != 0)
        {
            Random.InitState(seed);
        }

        string[] lengthes = { "", "short", "medium", "long" };

        Dungeon dungeon = new Dungeon();
        DungeonGenerationData genData = DarkestDungeonManager.Data.DungeonGenerationData.Find(item =>
                                                                                              item.Dungeon == quest.Dungeon && item.Length == lengthes[quest.Length] && item.QuestType == quest.Type);
        DungeonEnviromentData envData = DarkestDungeonManager.Data.DungeonEnviromentData[quest.Dungeon];

        int roomsLeft = genData.BaseRoomNumber;
        int hallsLeft = genData.BaseCorridorNumber;
        int xSize     = genData.GridSizeX;
        int ySize     = genData.GridSizeY;

        dungeon.GridSizeX = xSize;
        dungeon.GridSizeY = ySize;

        List <GenRoom> areas = new List <GenRoom>();

        GenRoom[,] areaGrid = new GenRoom[xSize, ySize];

        GenerateRooms(areas, areaGrid, roomsLeft, xSize, ySize);
        GenRoom hub = FindMaxConnectivityRoom(areas);

        List <GenRoom> existingRooms = ForceBorderRooms(areas, hub, roomsLeft);
        List <GenHall> existingHalls = ForceHallConnection(existingRooms, hallsLeft);

        dungeon.Rooms    = CreateFinalRooms(existingRooms);
        dungeon.Hallways = CreateFinalHallways(dungeon, existingHalls, genData);

        MarkEntrance(dungeon);
        PopulateQuestGoals(dungeon, quest, existingRooms, envData);
        PopulateRooms(dungeon, genData);
        LoadRoomEnviroment(dungeon, envData, quest.Difficulty);
        PopulateHalls(dungeon, genData);
        LoadHallEnviroment(dungeon, envData, quest.Difficulty);

        dungeon.GridSizeX   = 1 + (xSize - 1) * 7;
        dungeon.GridSizeY   = 1 + (ySize - 1) * 7;
        dungeon.Name        = quest.Dungeon;
        dungeon.DungeonMash = envData.BattleMashes.Find(mash => mash.MashId == quest.Difficulty);
        dungeon.SharedMash  = DarkestDungeonManager.Data.DungeonEnviromentData["shared"].
                              BattleMashes.Find(mash => mash.MashId == quest.Difficulty);

        return(dungeon);
    }
Esempio n. 10
0
 protected void DetermineCurrentLevelData()
 {
     if (GlobalData.BossDefeated(GlobalData.BossId.Chocolate))
     {
         mCurrentLevelData = mHardDungeons[GlobalData.CurrentFloor % mHardDungeons.Length];
     }
     else if (GlobalData.BossDefeated(GlobalData.BossId.Flower))
     {
         mCurrentLevelData = mMediumDungeons[GlobalData.CurrentFloor % mMediumDungeons.Length];
     }
     else
     {
         mCurrentLevelData = mEasyDungeons[GlobalData.CurrentFloor % mEasyDungeons.Length];
     }
 }
Esempio n. 11
0
    public static List <Vector2Int> GenerateDungeon(DungeonGenerationData dungeonData)
    {
        List <DungeonCrawler> dungeonCrawlers = new List <DungeonCrawler>();

        for (int i = 0; i < dungeonData.numberOfCrawlers; i++)
        {
            dungeonCrawlers.Add(new DungeonCrawler(Vector2Int.zero));
        }

        int iterations = Random.Range(dungeonData.intertionsMin + PlayerController.currentLevel, dungeonData.interationsMax + PlayerController.currentLevel);

        for (int i = 0; i < iterations; i++)
        {
            foreach (DungeonCrawler dungeonCrawler in dungeonCrawlers)
            {
                Vector2Int newPos = dungeonCrawler.Move(directionMovementMap);
                positionVisited.Add(newPos);
            }
        }
        return(positionVisited);
    }
Esempio n. 12
0
    // Iterates through each crawler and fetches which positions each crawlers has visited.
    // Rooms can then be spawned at those positions
    public static List <Vector2Int> GenerateDungeon(DungeonGenerationData dungeonData)
    {
        List <DungeonCrawler> dungeonCrawlers = new List <DungeonCrawler>();

        for (int i = 0; i < dungeonData.numCrawlers; i++)
        {
            // Creates crawler at (0, 0) [starting room]
            dungeonCrawlers.Add(new DungeonCrawler(Vector2Int.zero));
        }

        int iterations = Random.Range(dungeonData.iterationMin, dungeonData.iterationMax);

        for (int i = 0; i < iterations; i++)
        {
            foreach (DungeonCrawler dungeonCrawler in dungeonCrawlers)
            {
                Vector2Int newPos = dungeonCrawler.Move(directionMovementMap);
                positionsVisited.Add(newPos);
            }
        }

        return(positionsVisited);
    }
Esempio n. 13
0
 protected void DetermineCurrentLevelData()
 {
     if(GlobalData.BossDefeated(GlobalData.BossId.Chocolate))
     {
         mCurrentLevelData = mHardDungeons[GlobalData.CurrentFloor%mHardDungeons.Length];
     }
     else if(GlobalData.BossDefeated(GlobalData.BossId.Flower))
     {
         mCurrentLevelData = mMediumDungeons[GlobalData.CurrentFloor % mMediumDungeons.Length];
     }
     else
     {
         mCurrentLevelData = mEasyDungeons[GlobalData.CurrentFloor % mEasyDungeons.Length];
     }
 }
Esempio n. 14
0
    public void GenerateLevel()
    {
        if(mTestGenerationData != null)
        {
            mCurrentLevelData = mTestGenerationData;
        }
        else
        {
            DetermineCurrentLevelData();
        }

        if(GlobalData.NumHearts <= 0)
        {
            GlobalData.NumHearts = 1;
        }

        ClearProjectiles();
        ClearSpecialObjects();

        mDungeon.GenerateDungeon(mCurrentLevelData.mEnvironmentData);
        mStartPos = mDungeon.GetTilePosition(mDungeon.InitialRoomPosition.mX, mDungeon.InitialRoomPosition.mY);
        RespawnPlayer1();
        mGoal.mSignalType = SignalType.LevelComplete;
        mGoal.transform.position = FindGoalSpawnPosition();
        mDungeon.SetCell(mGoal.transform.position, DungeonCell.TileType.Goal);

        // Generate room contents
        GenerateCollectables();
        GenerateEnemies();

        Signal.Dispatch(SignalType.LevelStart);
    }
Esempio n. 15
0
    public static Dungeon GenerateDungeon(Quest quest, int seed = 0)
    {
        if (seed != 0)
        {
            Random.InitState(seed);
        }

        string[] lengthes = new string[] { "", "short", "medium", "long" };

        Dungeon dungeon = new Dungeon();
        DungeonGenerationData genData = DarkestDungeonManager.Data.DungeonGenerationData.Find(item =>
                                                                                              item.Dungeon == quest.Dungeon &&
                                                                                              item.Length == lengthes[quest.Length] &&
                                                                                              item.QuestType == quest.Type);
        DungeonEnviromentData envData = DarkestDungeonManager.Data.DungeonEnviromentData[quest.Dungeon];

        int RoomsLeft = genData.BaseRoomNumber;
        int HallsLeft = genData.BaseCorridorNumber;
        int xSize     = genData.GridSizeX;
        int ySize     = genData.GridSizeY;

        dungeon.GridSizeX = xSize;
        dungeon.GridSizeY = ySize;

        List <GenRoom> Areas = new List <GenRoom>();

        GenRoom[,] areaGrid = new GenRoom[xSize, ySize];

        GenerateRooms(Areas, areaGrid, RoomsLeft, xSize, ySize);
        GenRoom hub = GetHub(Areas);

        List <GenRoom> ExistingRooms = ForceBorderRooms(Areas, hub, RoomsLeft);
        List <GenHall> ExistingHalls = ForceHallConnection(Areas, hub, ExistingRooms, HallsLeft);

        dungeon.Rooms    = GetFinalRooms(ExistingRooms, genData);
        dungeon.Hallways = GetFinalHallways(dungeon, ExistingHalls, genData);

        MarkEntrance(dungeon);
        switch (quest.Goal.Type)
        {
        case "kill_monster":
            if (quest.Goal.QuestData is QuestKillMonsterData)
            {
                var bossData = quest.Goal.QuestData as QuestKillMonsterData;
                envData.BattleMashes.Find(mash => mash.BossEncounters.Find(encounter =>
                                                                           encounter.MonsterSet.Contains(bossData.MonsterNameIds[0])) != null);
                var bossGenRoom = LongestPathRoom(ExistingRooms.Find(room => room.Id == dungeon.StartingRoomId), ExistingRooms);
                var bossRoom    = dungeon.Rooms[bossGenRoom.Id];
                bossRoom.Type = AreaType.Boss;
                var bossEncounter = envData.BattleMashes.Find(mash => mash.MashId == quest.Difficulty).
                                    BossEncounters.Find(encounter => encounter.MonsterSet.Contains(bossData.MonsterNameIds[0]));
                bossRoom.BattleEncounter = new BattleEncounter(bossEncounter.MonsterSet);
            }
            else
            {
                Debug.LogError("Missing boss data in dungeon!");
            }
            break;

        case "activate":
            if (quest.Goal.QuestData is QuestActivateData)
            {
                var activateData = quest.Goal.QuestData as QuestActivateData;
                var lastRoom     = LongestPathRoom(ExistingRooms.Find(room => room.Id == dungeon.StartingRoomId), ExistingRooms);
                for (int i = 0; i < activateData.Amount; i++)
                {
                    var availableRooms = ExistingRooms.FindAll(room =>
                                                               room.MinPath >= (float)i / activateData.Amount * lastRoom.MinPath &&
                                                               room.MinPath <= (float)(i + 1) / activateData.Amount * lastRoom.MinPath);
                    int randomRoom = Random.Range(0, availableRooms.Count - 1);
                    var questRoom  = dungeon.Rooms[availableRooms[randomRoom].Id];
                    if (questRoom.Type == AreaType.Empty)
                    {
                        var curio = new Curio(activateData.CurioName);
                        curio.IsQuestCurio = true;

                        if (quest.Goal.StartingItems.Count > 0)
                        {
                            curio.ItemInteractions.Add(new ItemInteraction()
                            {
                                Chance     = 1,
                                ItemId     = quest.Goal.StartingItems[0].Id,
                                ResultType = "loot",
                                Results    = new List <CurioResult>(),
                            });
                        }

                        questRoom.Type = AreaType.Curio;
                        questRoom.Prop = curio;
                    }
                    else
                    {
                        i--;
                    }
                }
            }
            break;

        case "gather":
            if (quest.Goal.QuestData is QuestGatherData)
            {
                var gatherData = quest.Goal.QuestData as QuestGatherData;
                var lastRoom   = LongestPathRoom(ExistingRooms.Find(room => room.Id == dungeon.StartingRoomId), ExistingRooms);
                for (int i = 0; i < gatherData.Item.Amount; i++)
                {
                    var availableRooms = ExistingRooms.FindAll(room =>
                                                               room.MinPath >= (float)i / gatherData.Item.Amount * lastRoom.MinPath &&
                                                               room.MinPath <= (float)(i + 1) / gatherData.Item.Amount * lastRoom.MinPath);
                    int randomRoom = Random.Range(0, availableRooms.Count - 1);
                    var questRoom  = dungeon.Rooms[availableRooms[randomRoom].Id];
                    if (questRoom.Type == AreaType.Empty)
                    {
                        var curio = new Curio(gatherData.CurioName);
                        curio.IsQuestCurio = true;

                        var curioInteraction = new CurioInteraction();
                        curioInteraction.Chance     = 1;
                        curioInteraction.ResultType = "loot";
                        curioInteraction.Results    = new List <CurioResult>();
                        curioInteraction.Results.Add(new CurioResult()
                        {
                            Chance = 1,
                            Draws  = 1,
                            Item   = gatherData.Item.Id,
                        });
                        curio.Results.Add(curioInteraction);
                        questRoom.Type = AreaType.Curio;
                        questRoom.Prop = curio;
                    }
                    else
                    {
                        i--;
                    }
                }
            }
            break;

        default:
            break;
        }
        PopulateRooms(dungeon, genData);
        LoadRoomEnviroment(dungeon, envData, quest.Difficulty);
        PopulateHalls(dungeon, genData);
        LoadHallEnviroment(dungeon, envData, quest.Difficulty);

        dungeon.GridSizeX   = 1 + (xSize - 1) * 7;
        dungeon.GridSizeY   = 1 + (ySize - 1) * 7;
        dungeon.Name        = quest.Dungeon;
        dungeon.DungeonMash = envData.BattleMashes.Find(mash => mash.MashId == quest.Difficulty);
        dungeon.SharedMash  = DarkestDungeonManager.Data.DungeonEnviromentData["shared"].
                              BattleMashes.Find(mash => mash.MashId == quest.Difficulty);
        return(dungeon);
    }
Esempio n. 16
0
    static void PopulateHalls(Dungeon dungeon, DungeonGenerationData genData)
    {
        List <HallSector> hallSectors = new List <HallSector>();

        foreach (var hallway in dungeon.Hallways.Values)
        {
            foreach (var hallSector in hallway.Halls)
            {
                if (hallSector.Type != AreaType.Door)
                {
                    hallSectors.Add(hallSector);
                }
            }
        }

        dungeon.HallwayBattles = Random.Range(genData.HallwayBattleMin, genData.HallwayBattleMax + 1);
        for (int i = 0; i < dungeon.HallwayBattles; i++)
        {
            if (hallSectors.Count == 0)
            {
                return;
            }

            int index = Random.Range(0, hallSectors.Count);
            hallSectors[index].Type = AreaType.Battle;
            hallSectors.RemoveAt(index);
        }

        dungeon.HallwayTraps = Random.Range(genData.HallwayTrapMin, genData.HallwayTrapMax + 1);
        for (int i = 0; i < dungeon.HallwayTraps; i++)
        {
            if (hallSectors.Count == 0)
            {
                return;
            }

            int index = Random.Range(0, hallSectors.Count);
            hallSectors[index].Type = AreaType.Trap;
            hallSectors.RemoveAt(index);
        }

        dungeon.HallwayObstacles = Random.Range(genData.HallwayObstacleMin, genData.HallwayObstacleMax + 1);

        for (int i = 0; i < dungeon.HallwayObstacles; i++)
        {
            if (hallSectors.Count == 0)
            {
                return;
            }

            int index = Random.Range(0, hallSectors.Count);
            hallSectors[index].Type = AreaType.Obstacle;
            hallSectors.RemoveAt(index);
        }

        dungeon.HallwayCurios = Random.Range(genData.HallwayCurioMin, genData.HallwayCurioMax + 1);

        for (int i = 0; i < dungeon.HallwayCurios; i++)
        {
            if (hallSectors.Count == 0)
            {
                return;
            }

            int index = Random.Range(0, hallSectors.Count);
            hallSectors[index].Type = AreaType.Curio;
            hallSectors.RemoveAt(index);
        }

        dungeon.HallwayHunger = Random.Range(genData.HallwayHungerMin, genData.HallwayHungerMax + 1);

        for (int i = 0; i < dungeon.HallwayHunger; i++)
        {
            if (hallSectors.Count == 0)
            {
                return;
            }

            int index = Random.Range(0, hallSectors.Count);
            hallSectors[index].Type = AreaType.Hunger;
            hallSectors.RemoveAt(index);
        }
    }
Esempio n. 17
0
    static Dictionary <string, Hallway> GetFinalHallways(Dungeon dungeon, List <GenHall> halls, DungeonGenerationData genData)
    {
        Dictionary <string, Hallway> finalHallways = new Dictionary <string, Hallway>();

        foreach (var genHall in halls)
        {
            Hallway hallway = new Hallway(genHall.Id);

            hallway.RoomA = dungeon.Rooms[genHall.roomA.Id];
            hallway.RoomB = dungeon.Rooms[genHall.roomB.Id];
            int hallIncrementX = 0, hallIncrementY = 0;
            int hallGridX = hallway.RoomA.GridX, hallGridY = hallway.RoomA.GridY;

            if (hallway.RoomA.GridX < hallway.RoomB.GridX)
            {
                hallIncrementX = 1;
            }
            else if (hallway.RoomA.GridX > hallway.RoomB.GridX)
            {
                hallIncrementX = -1;
            }

            if (hallway.RoomA.GridY < hallway.RoomB.GridY)
            {
                hallIncrementY = 1;
            }
            else if (hallway.RoomA.GridY > hallway.RoomB.GridY)
            {
                hallIncrementY = -1;
            }

            hallGridX += hallIncrementX;
            hallGridY += hallIncrementY;

            hallway.Halls.Add(new HallSector(hallway.Id + "_0", hallGridX, hallGridY, hallway,
                                             new Door(hallway.Id, genHall.roomA.Id, Direction.Left)));

            for (int i = 1; i <= genData.Spacing; i++)
            {
                hallGridX += hallIncrementX;
                hallGridY += hallIncrementY;
                hallway.Halls.Add(new HallSector(hallway.Id + "_" + i.ToString(), hallGridX, hallGridY, hallway));
            }

            hallGridX += hallIncrementX;
            hallGridY += hallIncrementY;
            hallway.Halls.Add(new HallSector(hallway.Id + "_" + (genData.Spacing + 1).ToString(), hallGridX, hallGridY,
                                             hallway, new Door(hallway.Id, genHall.roomB.Id, Direction.Right)));

            finalHallways.Add(hallway.Id, hallway);
        }

        return(finalHallways);
    }