diff --git a/DiceProbabilities/DiceProbabilitesPrinter/bin/Debug/net9.0/DiceProbabilitesPrinter.dll b/DiceProbabilities/DiceProbabilitesPrinter/bin/Debug/net9.0/DiceProbabilitesPrinter.dll index d0dd18b..ae448ee 100644 Binary files a/DiceProbabilities/DiceProbabilitesPrinter/bin/Debug/net9.0/DiceProbabilitesPrinter.dll and b/DiceProbabilities/DiceProbabilitesPrinter/bin/Debug/net9.0/DiceProbabilitesPrinter.dll differ diff --git a/DiceProbabilities/DiceProbabilitesPrinter/bin/Debug/net9.0/DiceProbabilitesPrinter.exe b/DiceProbabilities/DiceProbabilitesPrinter/bin/Debug/net9.0/DiceProbabilitesPrinter.exe index bd8a0d8..10927e8 100644 Binary files a/DiceProbabilities/DiceProbabilitesPrinter/bin/Debug/net9.0/DiceProbabilitesPrinter.exe and b/DiceProbabilities/DiceProbabilitesPrinter/bin/Debug/net9.0/DiceProbabilitesPrinter.exe differ diff --git a/DiceProbabilities/DiceProbabilitesPrinter/bin/Debug/net9.0/DiceProbabilities.dll b/DiceProbabilities/DiceProbabilitesPrinter/bin/Debug/net9.0/DiceProbabilities.dll index c67c4a1..b616e06 100644 Binary files a/DiceProbabilities/DiceProbabilitesPrinter/bin/Debug/net9.0/DiceProbabilities.dll and b/DiceProbabilities/DiceProbabilitesPrinter/bin/Debug/net9.0/DiceProbabilities.dll differ diff --git a/DiceProbabilities/DiceProbabilities/bin/Debug/netstandard2.0/DiceProbabilities.dll b/DiceProbabilities/DiceProbabilities/bin/Debug/netstandard2.0/DiceProbabilities.dll index d4d9f93..b616e06 100644 Binary files a/DiceProbabilities/DiceProbabilities/bin/Debug/netstandard2.0/DiceProbabilities.dll and b/DiceProbabilities/DiceProbabilities/bin/Debug/netstandard2.0/DiceProbabilities.dll differ diff --git a/DungeonMapGenerator/DungeonMapConsolePrinter/Program.cs b/DungeonMapGenerator/DungeonMapConsolePrinter/Program.cs index 779bee9..746e138 100644 --- a/DungeonMapGenerator/DungeonMapConsolePrinter/Program.cs +++ b/DungeonMapGenerator/DungeonMapConsolePrinter/Program.cs @@ -17,6 +17,8 @@ class Program int height = 20; DungeonMap map = generator.GenerateDungeon(width, height, 5); DungeonLockPopulator.PopulateLocksOfDungeon(map); + DungeonLockPopulator.AddExtraLocksToMonsterRooms(map.GetMonsterRooms()); + DungeonLockPopulator.AddExtraLocksToBossRoom(map.GetBossRoom()); List potentialLootRooms = new List(); potentialLootRooms.AddRange(map.GetNormalRooms()); potentialLootRooms.AddRange(map.GetMonsterRooms()); diff --git a/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DiceProbabilities.dll b/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DiceProbabilities.dll index d4d9f93..b616e06 100644 Binary files a/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DiceProbabilities.dll and b/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DiceProbabilities.dll differ diff --git a/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapConsolePrinter.dll b/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapConsolePrinter.dll index 1453861..c0bd6b7 100644 Binary files a/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapConsolePrinter.dll and b/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapConsolePrinter.dll differ diff --git a/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapConsolePrinter.exe b/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapConsolePrinter.exe index c2903dd..8e55002 100644 Binary files a/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapConsolePrinter.exe and b/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapConsolePrinter.exe differ diff --git a/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapGenerator.dll b/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapGenerator.dll index b675a0c..8cd40a0 100644 Binary files a/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapGenerator.dll and b/DungeonMapGenerator/DungeonMapConsolePrinter/bin/Debug/net9.0/DungeonMapGenerator.dll differ diff --git a/DungeonMapGenerator/DungeonMapGenerator/BossRoom.cs b/DungeonMapGenerator/DungeonMapGenerator/BossRoom.cs new file mode 100644 index 0000000..49a347a --- /dev/null +++ b/DungeonMapGenerator/DungeonMapGenerator/BossRoom.cs @@ -0,0 +1,11 @@ +namespace DungeonMapGenerator +{ + public class BossRoom : MonsterRoom + { + public BossRoom(int width, int height, Point positionOfTopLeft) + : base(width, height, positionOfTopLeft) // Calls MonsterRoom's constructor + { + TypeOfRoom = RoomType.Boss; + } + } +} \ No newline at end of file diff --git a/DungeonMapGenerator/DungeonMapGenerator/DungeonGenerator.cs b/DungeonMapGenerator/DungeonMapGenerator/DungeonGenerator.cs index 7b6e889..9d8b964 100644 --- a/DungeonMapGenerator/DungeonMapGenerator/DungeonGenerator.cs +++ b/DungeonMapGenerator/DungeonMapGenerator/DungeonGenerator.cs @@ -35,7 +35,7 @@ namespace DungeonMapGenerator dungeonMap.AddRoom(disperser.GenerateAndPlaceRoom( SIDE_LENGTH_OF_MONSTER, SIDE_LENGTH_OF_MONSTER, - RoomType.Monster)); + typeof(MonsterRoom))); } AddNormalRoomsAroundMonsterRooms(dungeonMap); @@ -49,13 +49,13 @@ namespace DungeonMapGenerator private void AddAdjacentRoomsToEntranceRooms(DungeonMap dungeon) { - List entranceRooms = dungeon.GetEntranceRooms(); + List entranceRooms = dungeon.GetEntranceRooms(); List roomsToAddRoomsTowards = dungeon.GetNodeRooms(); List obstructions = dungeon.GetRootRooms(); foreach (Room entranceRoom in entranceRooms) { - if (entranceRoom.GetAdjacentRooms().All(adjacent => adjacent.TypeOfRoom == RoomType.Entrance)) + if (entranceRoom.GetAdjacentRooms().All(adjacent => adjacent is EntranceRoom)) { Room closestRoom = null; foreach (RoomSide side in Enum.GetValues(typeof(RoomSide))) @@ -73,7 +73,7 @@ namespace DungeonMapGenerator dungeon.AddRooms(PlaceRoomsOrganicallyTowardRoom( entranceRoom, closestRoom, - RoomType.Normal, + typeof(Room), dungeon.GetOccupiedPoints(), dungeon.GetUnoccupiedPoints())); } @@ -122,7 +122,7 @@ namespace DungeonMapGenerator if (closestSeenRoom != null) { //Place rooms along the line until they are connected - dungeon.AddRooms(PlaceRoomsOrganicallyTowardRoom(room, closestSeenRoom, RoomType.Normal, + dungeon.AddRooms(PlaceRoomsOrganicallyTowardRoom(room, closestSeenRoom, typeof(Room), dungeon.GetOccupiedPoints(), dungeon.GetUnoccupiedPoints())); } } @@ -185,7 +185,7 @@ namespace DungeonMapGenerator } // Create room and add it if valid - Room newRoom = CreateAdjacentRoom(RoomType.Normal, unoccupiedPointsOnSide, side, dungeon.GetOccupiedPoints()); + Room newRoom = CreateAdjacentRoom(typeof(Room), unoccupiedPointsOnSide, side, dungeon.GetOccupiedPoints()); if (newRoom != null) { room.AddAdjacentRoomBySide(newRoom, side); @@ -254,9 +254,9 @@ namespace DungeonMapGenerator } } - private Room CreateAdjacentRoom(RoomType type, List unoccupiedPointsOnSide, RoomSide side, HashSet occupiedPoints) + private Room CreateAdjacentRoom(Type roomType, List unoccupiedPointsOnSide, RoomSide side, HashSet occupiedPoints) { - int sizeOfNewRoom = GetRoomSizeByType(type); + int sizeOfNewRoom = GetRoomSizeByType(roomType); Random random = new Random(); // Sort points by their coordinate based on the side of placement @@ -299,7 +299,7 @@ namespace DungeonMapGenerator break; } - Room testRoom = new Room(type, sizeOfNewRoom, sizeOfNewRoom, adjustedPoint); + Room testRoom = (Room)Activator.CreateInstance(roomType, sizeOfNewRoom, sizeOfNewRoom, adjustedPoint); if (!testRoom.GetPointsInRoom().Any(occupiedPoints.Contains)) { validRooms.Add(testRoom); // First point is the top-left point of the room @@ -343,20 +343,17 @@ namespace DungeonMapGenerator return true; } - private int GetRoomSizeByType(RoomType type) + private int GetRoomSizeByType(Type roomType) { - switch (type) + if (roomType == typeof(EntranceRoom)) { - case RoomType.Entrance: - return SIDE_LENGTH_OF_ENTRANCE; - case RoomType.Monster: - return - SIDE_LENGTH_OF_MONSTER; - case RoomType.Normal: - return SIDE_LENGTH_OF_NORMAL; - default: - return SIDE_LENGTH_OF_NORMAL; + return SIDE_LENGTH_OF_MONSTER; } + if (roomType == typeof(MonsterRoom)) + { + return SIDE_LENGTH_OF_MONSTER; + } + return SIDE_LENGTH_OF_NORMAL; } private Room GenerateOnlyBossRoom(int xLengthOfDungeon, int yLengthOfDungeon, int width, int heigth) @@ -367,7 +364,7 @@ namespace DungeonMapGenerator Random random = new Random(); int bossX = middleAreaX + random.Next(0, middleAreaX - width); int bossY = middleAreaY + random.Next(0, middleAreaY - heigth); - return new Room(RoomType.Boss, width, heigth, new Point(bossX, bossY)); + return new BossRoom(width, heigth, new Point(bossX, bossY)); } private enum Side @@ -421,20 +418,20 @@ namespace DungeonMapGenerator // Add half of points for this entrance line to the top left side for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL) { - entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(i,0))); + entranceRooms.Add(new EntranceRoom(SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(i,0))); } // Add the rest of the points for this entrance line to the top right side. for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL) { - entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(right - i,0))); + entranceRooms.Add(new EntranceRoom(SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(right - i,0))); } break; case 1: int startOfLine = GetStartOfCenteredLine(xLengthOfDungeon, roomsPerLine, SIDE_LENGTH_OF_NORMAL); for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL) { - entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL,new Point(startOfLine + i, 0))); + entranceRooms.Add(new EntranceRoom(SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL,new Point(startOfLine + i, 0))); } break; } @@ -445,20 +442,20 @@ namespace DungeonMapGenerator // Add points for this entrance line to the top right side for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL) { - entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(right, i + SIDE_LENGTH_OF_NORMAL))); + entranceRooms.Add(new EntranceRoom(SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(right, i + SIDE_LENGTH_OF_NORMAL))); } // Add the rest of the points for this entrance line to the bottom right side. for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL) { - entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(right, oneRoomFromBottom - i))); + entranceRooms.Add(new EntranceRoom(SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(right, oneRoomFromBottom - i))); } break; case 1: int startOfLine = GetStartOfCenteredLine(yLengthOfDungeon, roomsPerLine, SIDE_LENGTH_OF_NORMAL); for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL) { - entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(right, startOfLine + i))); + entranceRooms.Add(new EntranceRoom(SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(right, startOfLine + i))); } break; } @@ -469,20 +466,20 @@ namespace DungeonMapGenerator // Add half of points for this entrance line to the bottom left side for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL) { - entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(i, bottom))); + entranceRooms.Add(new EntranceRoom(SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(i, bottom))); } // Add the rest of the points for this entrance line to the bottom right side. for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL) { - entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point((xLengthOfDungeon - 1) - i, bottom))); + entranceRooms.Add(new EntranceRoom(SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point((xLengthOfDungeon - 1) - i, bottom))); } break; case 1: int startOfLine = GetStartOfCenteredLine(xLengthOfDungeon, roomsPerLine, SIDE_LENGTH_OF_NORMAL); for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL) { - entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(startOfLine + i, bottom))); + entranceRooms.Add(new EntranceRoom(SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(startOfLine + i, bottom))); } break; } @@ -493,20 +490,20 @@ namespace DungeonMapGenerator // Add half of points for this entrance line to the top left side for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL) { - entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(0, i + SIDE_LENGTH_OF_NORMAL))); + entranceRooms.Add(new EntranceRoom(SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(0, i + SIDE_LENGTH_OF_NORMAL))); } // Add the rest of the points for this entrance line to the bottom left side. for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL) { - entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(0, oneRoomFromBottom - i))); + entranceRooms.Add(new EntranceRoom(SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(0, oneRoomFromBottom - i))); } break; case 1: int startOfLine = GetStartOfCenteredLine(yLengthOfDungeon, roomsPerLine, SIDE_LENGTH_OF_NORMAL); for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL) { - entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(0, startOfLine + i))); + entranceRooms.Add(new EntranceRoom(SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(0, startOfLine + i))); } break; } @@ -613,7 +610,7 @@ namespace DungeonMapGenerator return points; } - private List PlaceRoomsOrganicallyTowardRoom(Room startingRoom, Room targetRoom, RoomType type, + private List PlaceRoomsOrganicallyTowardRoom(Room startingRoom, Room targetRoom, Type roomType, HashSet occupiedPoints, HashSet unoccupiedPoints) { List placedRooms = new List(); @@ -631,12 +628,12 @@ namespace DungeonMapGenerator GetSidesTowardsEndPoint(currentRoom.GetCenterOfRoom(), targetRoom.GetCenterOfRoom()); List availablePointsOnSide = GetUnoccupiedPointsOnSide(currentRoom, primary, unoccupiedPoints); - newRoom = CreateAdjacentRoom(type, availablePointsOnSide, primary, occupiedPoints); + newRoom = CreateAdjacentRoom(roomType, availablePointsOnSide, primary, occupiedPoints); // If the primary side doesn't have room for a new room the try secondary if (newRoom == null) { availablePointsOnSide = GetUnoccupiedPointsOnSide(currentRoom, secondary, unoccupiedPoints); - newRoom = CreateAdjacentRoom(type, availablePointsOnSide, secondary, occupiedPoints); + newRoom = CreateAdjacentRoom(roomType, availablePointsOnSide, secondary, occupiedPoints); } if (newRoom != null) diff --git a/DungeonMapGenerator/DungeonMapGenerator/DungeonLockPopulator.cs b/DungeonMapGenerator/DungeonMapGenerator/DungeonLockPopulator.cs index 17690ba..8a5a2df 100644 --- a/DungeonMapGenerator/DungeonMapGenerator/DungeonLockPopulator.cs +++ b/DungeonMapGenerator/DungeonMapGenerator/DungeonLockPopulator.cs @@ -13,8 +13,12 @@ namespace DungeonMapGenerator { Random random = new Random(); float desiredSuccessChance = .995f; - - List currentRooms = dungeon.GetEntranceRooms(); + + List currentRooms = new List(); + foreach (EntranceRoom entranceRoom in dungeon.GetEntranceRooms()) + { + currentRooms.Add(entranceRoom); + } HashSet seenRooms = new HashSet(currentRooms); // Set entrance room locks to 2 - 12 @@ -115,6 +119,43 @@ namespace DungeonMapGenerator } } + public static void AddExtraLocksToMonsterRooms(List monsterRooms) + { + int maxExtraMonsterRoomLocks = 2; + foreach (MonsterRoom monsterRoom in monsterRooms) + { + int extraLockCounter = 0; + foreach (Room adjacentRoom in monsterRoom.GetAdjacentRooms()) + { + if (Lock.VeryHardLocks.All(l => l.GetLock() != adjacentRoom.Lock.GetLock())) + { + if (extraLockCounter < maxExtraMonsterRoomLocks) + { + monsterRoom.ExtraLocks.Add(new Lock(adjacentRoom.Lock.GetLock())); + extraLockCounter++; + } + } + } + } + } + + public static void AddExtraLocksToBossRoom(BossRoom bossRoom) + { + int maxExtraBossRooms = 5; + int extraLockCounter = 0; + foreach (Room adjacentRoom in bossRoom.GetAdjacentRooms()) + { + if (Lock.VeryHardLocks.All(l => l.GetLock() != adjacentRoom.Lock.GetLock())) + { + if (extraLockCounter < maxExtraBossRooms) + { + bossRoom.ExtraLocks.Add(new Lock(adjacentRoom.Lock.GetLock())); + extraLockCounter++; + } + } + } + } + private static List GenerateLocks(List pregeneratedLocks, int numLocks, float successChance) { List locks = new List(); diff --git a/DungeonMapGenerator/DungeonMapGenerator/DungeonMap.cs b/DungeonMapGenerator/DungeonMapGenerator/DungeonMap.cs index 57d7355..e91d7dd 100644 --- a/DungeonMapGenerator/DungeonMapGenerator/DungeonMap.cs +++ b/DungeonMapGenerator/DungeonMapGenerator/DungeonMap.cs @@ -13,13 +13,13 @@ namespace DungeonMapGenerator [JsonProperty("Height")] public int Height; [JsonProperty("MonsterRooms")] - private List _monsterRooms = new List(); + private List _monsterRooms = new List(); [JsonProperty("EntranceRooms")] - private List _entranceRooms = new List(); + private List _entranceRooms = new List(); [JsonProperty("NormalRooms")] private List _normalRooms = new List(); [JsonProperty("BossRoom")] - private Room _bossRoom; + private BossRoom _bossRoom; private HashSet _unoccupiedPoints = new HashSet(); private HashSet _occupiedPoints = new HashSet(); public DungeonMap(){ } @@ -60,22 +60,24 @@ namespace DungeonMapGenerator public void AddRoom(Room room) { - switch (room.TypeOfRoom) + if (room is MonsterRoom) { - case RoomType.Monster: - _monsterRooms.Add(room); - break; - case RoomType.Entrance: - _entranceRooms.Add(room); - break; - case RoomType.Normal: - _normalRooms.Add(room); - break; - case RoomType.Boss: - _bossRoom = room; - break; - default: - return; + if (room is BossRoom) + { + _bossRoom = (BossRoom)room; + } + else + { + _monsterRooms.Add((MonsterRoom)room); + } + } + else if (room is EntranceRoom) + { + _entranceRooms.Add((EntranceRoom)room); + } + else + { + _normalRooms.Add(room); } AddPointsToOccupied(room.GetPointsInRoom()); @@ -83,37 +85,23 @@ namespace DungeonMapGenerator public void AddRooms(List rooms) { - if (rooms.Count == 0) return; - - switch (rooms[0].TypeOfRoom) + foreach (Room room in rooms) { - case RoomType.Monster: - _monsterRooms.AddRange(rooms); - break; - case RoomType.Entrance: - _entranceRooms.AddRange(rooms); - break; - case RoomType.Normal: - _normalRooms.AddRange(rooms); - break; - default: - return; + AddRoom(room); } - - AddPointsToOccupied(rooms.SelectMany(room => room.GetPointsInRoom()).ToList()); } - public List GetMonsterRooms() + public List GetMonsterRooms() { return _monsterRooms; } - public Room GetBossRoom() + public BossRoom GetBossRoom() { return _bossRoom; } - public List GetEntranceRooms() + public List GetEntranceRooms() { return _entranceRooms; } diff --git a/DungeonMapGenerator/DungeonMapGenerator/EntranceRoom.cs b/DungeonMapGenerator/DungeonMapGenerator/EntranceRoom.cs new file mode 100644 index 0000000..87f7ba9 --- /dev/null +++ b/DungeonMapGenerator/DungeonMapGenerator/EntranceRoom.cs @@ -0,0 +1,11 @@ +namespace DungeonMapGenerator +{ + public class EntranceRoom : Room + { + public EntranceRoom(int width, int height, Point positionOfTopLeft) + : base(width, height, positionOfTopLeft) // Calls Room's constructor + { + TypeOfRoom = RoomType.Entrance; + } + } +} \ No newline at end of file diff --git a/DungeonMapGenerator/DungeonMapGenerator/EvenDisperser.cs b/DungeonMapGenerator/DungeonMapGenerator/EvenDisperser.cs index ca27b23..f03ad01 100644 --- a/DungeonMapGenerator/DungeonMapGenerator/EvenDisperser.cs +++ b/DungeonMapGenerator/DungeonMapGenerator/EvenDisperser.cs @@ -8,7 +8,6 @@ namespace DungeonMapGenerator public class EvenDisperser { private List _samples = new List(){new Room( - RoomType.Normal, 1, 1, new Point(1000, 1000))}; @@ -36,16 +35,15 @@ namespace DungeonMapGenerator return availablePoints; } - public Room GenerateAndPlaceRoom(int xLength, int yLength, RoomType roomType) + public Room GenerateAndPlaceRoom(int xLength, int yLength, Type roomType) { int numCandidates = 100; // Increasing improves results but greatly effects performance. Random rnd = new Random(); - Room bestCandidate = new Room(roomType, xLength, yLength, new Point(Int32.MaxValue, Int32.MaxValue)); + Room bestCandidate = new Room(xLength, yLength, new Point(Int32.MaxValue, Int32.MaxValue)); int bestDistance = 0; for (var i = 0; i < numCandidates; i++) { - var candidate = new Room( - roomType, xLength, yLength, _availablePoints.ToList()[rnd.Next(0, _availablePoints.Count)]); + var candidate = (Room)Activator.CreateInstance(roomType, xLength, yLength, _availablePoints.ToList()[rnd.Next(0, _availablePoints.Count)]); var distance = candidate.GetDistanceToRoom(FindClosestRoom(_samples, candidate)); if (distance > bestDistance && candidate.GetPointsInRoom().All(room => _availablePoints.Contains(room))) diff --git a/DungeonMapGenerator/DungeonMapGenerator/MonsterRoom.cs b/DungeonMapGenerator/DungeonMapGenerator/MonsterRoom.cs new file mode 100644 index 0000000..8cdeef4 --- /dev/null +++ b/DungeonMapGenerator/DungeonMapGenerator/MonsterRoom.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; + +namespace DungeonMapGenerator +{ + public class MonsterRoom : Room + { + + public MonsterRoom(int width, int height, Point positionOfTopLeft) + : base(width, height, positionOfTopLeft) // Calls Room's constructor + { + TypeOfRoom = RoomType.Monster; + } + + public List ExtraLocks = new List(); + } +} \ No newline at end of file diff --git a/DungeonMapGenerator/DungeonMapGenerator/Room.cs b/DungeonMapGenerator/DungeonMapGenerator/Room.cs index 9031140..b782b77 100644 --- a/DungeonMapGenerator/DungeonMapGenerator/Room.cs +++ b/DungeonMapGenerator/DungeonMapGenerator/Room.cs @@ -32,8 +32,8 @@ namespace DungeonMapGenerator public class Room { private static int _nextId = 1; - - public RoomType TypeOfRoom { get; set; } + public RoomType TypeOfRoom { get; protected set; } + public Lock Lock { get; set; } public int Height { get; set; } public int Width { get; set; } @@ -51,15 +51,15 @@ namespace DungeonMapGenerator } - public Room(RoomType roomType, int width, int height, Point positionOfTopLeft) + public Room(int width, int height, Point positionOfTopLeft) { + TypeOfRoom = RoomType.Normal; Id = _nextId++; - TypeOfRoom = roomType; Width = width; Height = height; PositionOfTopLeft = positionOfTopLeft; } - + public void AddAdjacentRoom(Room room) { _adjacentRooms.Add(room); diff --git a/DungeonMapGenerator/DungeonMapGenerator/bin/Debug/netstandard2.0/DiceProbabilities.dll b/DungeonMapGenerator/DungeonMapGenerator/bin/Debug/netstandard2.0/DiceProbabilities.dll index d4d9f93..b616e06 100644 Binary files a/DungeonMapGenerator/DungeonMapGenerator/bin/Debug/netstandard2.0/DiceProbabilities.dll and b/DungeonMapGenerator/DungeonMapGenerator/bin/Debug/netstandard2.0/DiceProbabilities.dll differ diff --git a/DungeonMapGenerator/DungeonMapGenerator/bin/Debug/netstandard2.0/DungeonMapGenerator.dll b/DungeonMapGenerator/DungeonMapGenerator/bin/Debug/netstandard2.0/DungeonMapGenerator.dll index b675a0c..8cd40a0 100644 Binary files a/DungeonMapGenerator/DungeonMapGenerator/bin/Debug/netstandard2.0/DungeonMapGenerator.dll and b/DungeonMapGenerator/DungeonMapGenerator/bin/Debug/netstandard2.0/DungeonMapGenerator.dll differ diff --git a/PuzzleGameProject/Assets/Plugins/DiceProbabilities.dll b/PuzzleGameProject/Assets/Plugins/DiceProbabilities.dll index 919def5..b616e06 100644 Binary files a/PuzzleGameProject/Assets/Plugins/DiceProbabilities.dll and b/PuzzleGameProject/Assets/Plugins/DiceProbabilities.dll differ diff --git a/PuzzleGameProject/Assets/Plugins/DungeonMapGenerator.dll b/PuzzleGameProject/Assets/Plugins/DungeonMapGenerator.dll index cc09e97..b3c643e 100644 Binary files a/PuzzleGameProject/Assets/Plugins/DungeonMapGenerator.dll and b/PuzzleGameProject/Assets/Plugins/DungeonMapGenerator.dll differ diff --git a/PuzzleGameProject/Assets/Scripts/DungeonGenerator/DungeonMapLoader.cs b/PuzzleGameProject/Assets/Scripts/DungeonGenerator/DungeonMapLoader.cs index 535f2d5..c946098 100644 --- a/PuzzleGameProject/Assets/Scripts/DungeonGenerator/DungeonMapLoader.cs +++ b/PuzzleGameProject/Assets/Scripts/DungeonGenerator/DungeonMapLoader.cs @@ -29,6 +29,10 @@ namespace DungeonGenerator GameObject bossRoomGO = PrefabUtility.InstantiatePrefab(bossRoomPrefab, gameObject.transform) as GameObject; bossRoomGO.transform.position = ConvertToUnityPosition(map.GetBossRoom().GetCenterOfRoom(), map.Width, map.Height); AddLockToRoomObject(bossRoomGO, map.GetBossRoom().Lock.GetLock()); + foreach (DungeonMapGenerator.Lock extraLock in map.GetBossRoom().ExtraLocks) + { + AddLockToRoomObject(bossRoomGO, extraLock.GetLock()); + } _roomIdToGameObject[map.GetBossRoom().Id] = bossRoomGO; foreach (var monsterRoom in map.GetMonsterRooms()) @@ -36,6 +40,10 @@ namespace DungeonGenerator GameObject monsterRoomGO = PrefabUtility.InstantiatePrefab(monsterRoomPrefab, gameObject.transform) as GameObject; monsterRoomGO.transform.position = ConvertToUnityPosition(monsterRoom.GetCenterOfRoom(), map.Width, map.Height); AddLockToRoomObject(monsterRoomGO, monsterRoom.Lock.GetLock()); + foreach (DungeonMapGenerator.Lock extraLock in monsterRoom.ExtraLocks) + { + AddLockToRoomObject(monsterRoomGO, extraLock.GetLock()); + } _roomIdToGameObject[monsterRoom.Id] = monsterRoomGO; }