public void SpawnRandomRoom(GameObject thisRoom, Vector3 doorPoint, DungeonDoor.DoorDirection requiredDirection, bool yes = false) { if (entireDungeon.Count < maxRooms) { GameObject roomToSpawn = null; switch (requiredDirection) { case DungeonDoor.DoorDirection.Up: roomToSpawn = upRooms[Random.Range(0, upRooms.Count)]; break; case DungeonDoor.DoorDirection.Down: roomToSpawn = downRooms[Random.Range(0, downRooms.Count)]; break; case DungeonDoor.DoorDirection.Left: roomToSpawn = leftRooms[Random.Range(0, leftRooms.Count)]; break; case DungeonDoor.DoorDirection.Right: roomToSpawn = rightRooms[Random.Range(0, rightRooms.Count)]; break; } GameObject spawnedRoom = Instantiate(roomToSpawn, Vector3.zero, Quaternion.identity); entireDungeon.Add(spawnedRoom); List <Transform> availableDoors = new List <Transform>(); for (int i = 0; i < spawnedRoom.GetComponent <DungeonRoom>().availableDoors.Count; i++) { GameObject thisDoor = spawnedRoom.GetComponent <DungeonRoom>().availableDoors[i]; if (thisDoor.GetComponent <DungeonDoor>().direction == requiredDirection) { availableDoors.Add(thisDoor.transform); } } Transform selectedDoor = availableDoors[Random.Range(0, availableDoors.Count)]; Vector3 selectedDoorPosition = selectedDoor.localPosition; selectedDoorPosition.y = 0; Vector3 requiredPosition = doorPoint - selectedDoorPosition; if (yes) { spawnedRoom.GetComponent <DungeonRoom>().previousReplaced = true; //spawnedRoom.GetComponent<MeshRenderer>().material = endRoomColor; } spawnedRoom.transform.position = requiredPosition; spawnedRoom.transform.SetParent(thisRoom.transform); spawnedRoom.GetComponent <DungeonRoom>().Initialize(this, selectedDoor.gameObject); print("WITH " + Physics.OverlapBox(spawnedRoom.transform.position, spawnedRoom.GetComponent <BoxCollider>().size / 2, spawnedRoom.transform.rotation).Length + " HITS AAA"); if (spawnedRoom.GetComponent <DungeonRoom>().HasCollision()) { print(spawnedRoom + " IS THE SPAWNED ROOM"); ReplaceRoom(spawnedRoom, selectedDoor.GetComponent <DungeonDoor>().direction); } else { print("WITH " + Physics.OverlapBox(spawnedRoom.transform.position, spawnedRoom.GetComponent <BoxCollider>().size / 2, spawnedRoom.transform.rotation).Length + " HITS"); StartCoroutine(spawnedRoom.GetComponent <DungeonRoom>().SpawnNextRoom()); } } }
public void ReplaceWithSmallEndRoom(GameObject roomToReplace, DungeonDoor.DoorDirection entranceDirection) { print("SPAWNED SMALL END ROOM"); Vector3 backupPosition = roomToReplace.GetComponent <DungeonRoom>().entranceDoor.transform.position; GameObject backupParent = roomToReplace.transform.parent.gameObject; entireDungeon.Remove(roomToReplace); if (endRooms.Contains(roomToReplace)) { endRooms.Remove(roomToReplace); } print("DESTROYED " + roomToReplace); DestroyImmediate(roomToReplace); List <GameObject> availableEndRooms = new List <GameObject>(); for (int i = 0; i < smallEndRooms.Count; i++) { GameObject thisRoom = smallEndRooms[i]; if (thisRoom.GetComponent <DungeonRoom>().availableDoors[0].GetComponent <DungeonDoor>().direction == entranceDirection) { availableEndRooms.Add(thisRoom); } } GameObject newRoom = Instantiate(availableEndRooms[Random.Range(0, availableEndRooms.Count)]); newRoom.GetComponent <DungeonRoom>().Initialize(this, newRoom.GetComponent <DungeonRoom>().availableDoors[0]); newRoom.transform.position = backupPosition - newRoom.GetComponent <DungeonRoom>().entranceDoor.transform.localPosition; newRoom.transform.SetParent(backupParent.transform); newRoom.GetComponent <DungeonRoom>().replaced = true; //newRoom.GetComponent<MeshRenderer>().material = endRoomColor; entireDungeon.Add(newRoom); }
public void CheckPartCollision(GameObject roomToCheck, DungeonDoor.DoorDirection entranceDirection) { if (roomToCheck.GetComponent <BaseRoom>().HasCollision(true)) { print("HAD COLL"); ReplaceRoom(roomToCheck, entranceDirection); } else { print("DID NOT COLL"); StartCoroutine(roomToCheck.GetComponent <BaseRoom>().SpawnNextRoom()); } }
public virtual IEnumerator SpawnNextRoom() { if (availableDoors.Count > 0) { creator.openProcesses += availableDoors.Count; } else { creator.openProcesses++; } yield return(null); int backupCount = availableDoors.Count; if (availableDoors.Count > 0) { for (int i = backupCount - 1; i >= 0; i--) { creator.openProcesses--; DungeonDoor.DoorDirection wantedDoorDirection = DungeonDoor.DoorDirection.Left; switch (availableDoors[i].GetComponent <DungeonDoor>().direction) { case DungeonDoor.DoorDirection.Up: wantedDoorDirection = DungeonDoor.DoorDirection.Down; break; case DungeonDoor.DoorDirection.Down: wantedDoorDirection = DungeonDoor.DoorDirection.Up; break; case DungeonDoor.DoorDirection.Left: wantedDoorDirection = DungeonDoor.DoorDirection.Right; break; case DungeonDoor.DoorDirection.Right: wantedDoorDirection = DungeonDoor.DoorDirection.Left; break; } SpawnRoom(wantedDoorDirection, availableDoors[i].transform); } } else { creator.openProcesses--; if (creator.openProcesses == 0) { creator.CheckRoomCount(); } } }
public void ProceedGeneration() { if (endRooms.Count > 0) { GameObject roomToReplace = endRooms[Random.Range(0, endRooms.Count)]; Transform backupTransform = roomToReplace.GetComponent <BaseRoom>().entranceDoor.GetComponent <DungeonDoor>().parentDoor.transform; GameObject backupParent = roomToReplace.GetComponent <BaseRoom>().parentRoom; DungeonDoor.DoorDirection backupDirection = roomToReplace.GetComponent <BaseRoom>().entranceDoor.GetComponent <DungeonDoor>().direction;; print("DESTROYED " + roomToReplace); print("PROCEEDGEN - REPLACING " + roomToReplace); roomToReplace.GetComponent <BaseRoom>().OnDestroyed(); DestroyImmediate(roomToReplace); SpawnRandomRoom(backupParent, backupTransform, backupDirection); } }
public IEnumerator SpawnNextRoom(bool yes = false) { print(" Spawned " + gameObject); creator.openProcesses++; yield return(null); creator.openProcesses--; if (availableDoors.Count > 0) { for (int i = 0; i < availableDoors.Count; i++) { DungeonDoor.DoorDirection wantedDoorDirection = DungeonDoor.DoorDirection.Left; switch (availableDoors[i].GetComponent <DungeonDoor>().direction) { case DungeonDoor.DoorDirection.Up: wantedDoorDirection = DungeonDoor.DoorDirection.Down; break; case DungeonDoor.DoorDirection.Down: wantedDoorDirection = DungeonDoor.DoorDirection.Up; break; case DungeonDoor.DoorDirection.Left: wantedDoorDirection = DungeonDoor.DoorDirection.Right; break; case DungeonDoor.DoorDirection.Right: wantedDoorDirection = DungeonDoor.DoorDirection.Left; break; } print("OGSPAWN"); creator.SpawnRandomRoom(gameObject, availableDoors[i].transform.position, wantedDoorDirection, yes); } } else { if (creator.openProcesses <= 0) { StartCoroutine(creator.CheckRoomCount()); } } }
public void ProceedGeneration() { if (endRooms.Count > 0) { GameObject roomToReplace = endRooms[Random.Range(0, endRooms.Count)]; Vector3 backupPos = roomToReplace.GetComponent <DungeonRoom>().entranceDoor.transform.position; GameObject backupParent = roomToReplace.transform.parent.gameObject; DungeonDoor.DoorDirection backupDirection = roomToReplace.GetComponent <DungeonRoom>().entranceDoor.GetComponent <DungeonDoor>().direction; endRooms.Remove(roomToReplace); entireDungeon.Remove(roomToReplace); print("DESTROYED " + roomToReplace); print("PROCEEDGEN - REPLACING " + roomToReplace); DestroyImmediate(roomToReplace); SpawnRandomRoom(backupParent, backupPos, backupDirection, true); } else { GenerateDungeon(); } }
public override void SpawnRoom(DungeonDoor.DoorDirection wantedDir, Transform doorPoint) { creator.SpawnDungeonPartAlt(creator.hallways, wantedDir, gameObject, doorPoint, RoomTypes.Hallway); }
public abstract void SpawnRoom(DungeonDoor.DoorDirection wantedDir, Transform doorPoint);
public override void SpawnRoom(DungeonDoor.DoorDirection wantedDir, Transform doorPoint) { throw new System.NotImplementedException(); }
public void ForcedReplaceRoom(List <GameObject> roomsToReplace, int requiredTimes, List <GameObject> staticOptions = null, int minDistanceFromStart = 0) { bool replaced = false; for (int counter = 0; counter < requiredTimes; counter++) { foreach (GameObject roomToReplace in roomsToReplace) { if (roomToReplace.GetComponent <BaseRoom>().roomDistanceFromStart >= minDistanceFromStart) { print("HIIII"); roomToReplace.SetActive(false); DungeonDoor.DoorDirection entranceDirection = roomToReplace.GetComponent <BaseRoom>().entranceDoor.GetComponent <DungeonDoor>().direction; List <GameObject> possibleAvailableOptions = new List <GameObject>(); if (staticOptions != null) { possibleAvailableOptions = staticOptions; } else { if (roomToReplace.GetComponent <BaseRoom>().type == BaseRoom.RoomTypes.Hallway) { possibleAvailableOptions = hallways; } else { possibleAvailableOptions = rooms; } } List <GameObject> availableOptions = new List <GameObject>(); foreach (GameObject option in possibleAvailableOptions) { foreach (GameObject door in option.GetComponent <BaseRoom>().availableDoors) { if (door.GetComponent <DungeonDoor>().direction == entranceDirection) { availableOptions.Add(option); break; } } } GameObject finalRoom = null; GameObject selectedDoor = null; int selectedDoorId = 0; print(availableOptions.Count); foreach (GameObject option in availableOptions) { List <GameObject> availableDoors = new List <GameObject>(); foreach (GameObject door in option.GetComponent <BaseRoom>().availableDoors) { if (door.GetComponent <DungeonDoor>().direction == entranceDirection) { availableDoors.Add(door); } } selectedDoor = availableDoors[Random.Range(0, availableDoors.Count)]; selectedDoorId = selectedDoor.GetComponent <DungeonDoor>().id; finalRoom = Instantiate(option, GetLocationData(option.transform, selectedDoor.transform, roomToReplace.GetComponent <BaseRoom>().entranceDoor.GetComponent <DungeonDoor>().parentDoor.transform), Quaternion.identity); for (int i = 0; i < finalRoom.GetComponent <BaseRoom>().availableDoors.Count; i++) { GameObject thisDoor = finalRoom.GetComponent <BaseRoom>().availableDoors[i]; if (thisDoor.GetComponent <DungeonDoor>().id == selectedDoorId) { selectedDoor = thisDoor; break; } } finalRoom.GetComponent <BaseRoom>().Initialize(this, roomToReplace.GetComponent <BaseRoom>().parentRoom, selectedDoor); finalRoom.GetComponent <BaseRoom>().entranceDoor.GetComponent <DungeonDoor>().parentDoor = roomToReplace.GetComponent <BaseRoom>().entranceDoor.GetComponent <DungeonDoor>().parentDoor; if (finalRoom.GetComponent <BaseRoom>().HasCollision(true)) { finalRoom.GetComponent <BaseRoom>().OnDestroyed(); DestroyImmediate(finalRoom); finalRoom = null; continue; } else { roomsToReplace.Remove(roomToReplace); roomToReplace.GetComponent <BaseRoom>().OnDestroyed(); DestroyImmediate(roomToReplace); //print("THIS ONE DID NOT COLLIDE C:"); break; } } if (finalRoom != null) { print("FOUND NEW ROOM"); finalRoom.GetComponent <BaseRoom>().replaced = true; //StartCoroutine(finalRoom.GetComponent<BaseRoom>().SpawnNextRoom()); replaced = true; break; } else { roomToReplace.SetActive(true); } } } if (!replaced) { return; } } }
public void ReplaceRoom(GameObject roomToReplace, DungeonDoor.DoorDirection entranceDirection, List <GameObject> staticOptions = null) { BaseRoom.RoomTypes backupType = roomToReplace.GetComponent <BaseRoom>().type; GameObject backupParentDoor = roomToReplace.GetComponent <BaseRoom>().entranceDoor.GetComponent <DungeonDoor>().parentDoor; GameObject backupParent = roomToReplace.GetComponent <BaseRoom>().parentRoom; print("DESTROYED " + roomToReplace); roomToReplace.GetComponent <BaseRoom>().OnDestroyed(); DestroyImmediate(roomToReplace); List <GameObject> possibleAvailableOptions = new List <GameObject>(); if (staticOptions != null) { possibleAvailableOptions = staticOptions; } else { if (backupType == BaseRoom.RoomTypes.Hallway) { possibleAvailableOptions = hallways; } else { possibleAvailableOptions = rooms; } } List <GameObject> availableOptions = new List <GameObject>(); foreach (GameObject option in possibleAvailableOptions) { foreach (GameObject door in option.GetComponent <BaseRoom>().availableDoors) { if (door.GetComponent <DungeonDoor>().direction == entranceDirection) { availableOptions.Add(option); break; } } } GameObject finalRoom = null; GameObject selectedDoor = null; int selectedDoorId = 0; foreach (GameObject option in availableOptions) { List <GameObject> availableDoors = new List <GameObject>(); foreach (GameObject door in option.GetComponent <BaseRoom>().availableDoors) { if (door.GetComponent <DungeonDoor>().direction == entranceDirection) { availableDoors.Add(door); } } selectedDoor = availableDoors[Random.Range(0, availableDoors.Count)]; selectedDoorId = selectedDoor.GetComponent <DungeonDoor>().id; finalRoom = Instantiate(option, GetLocationData(option.transform, selectedDoor.transform, backupParentDoor.transform), Quaternion.identity); for (int i = 0; i < finalRoom.GetComponent <BaseRoom>().availableDoors.Count; i++) { GameObject thisDoor = finalRoom.GetComponent <BaseRoom>().availableDoors[i]; if (thisDoor.GetComponent <DungeonDoor>().id == selectedDoorId) { selectedDoor = thisDoor; break; } } finalRoom.GetComponent <BaseRoom>().Initialize(this, backupParent, selectedDoor); finalRoom.GetComponent <BaseRoom>().entranceDoor.GetComponent <DungeonDoor>().parentDoor = backupParentDoor; if (finalRoom.GetComponent <BaseRoom>().HasCollision(true)) { finalRoom.GetComponent <BaseRoom>().OnDestroyed(); DestroyImmediate(finalRoom); finalRoom = null; continue; } else { //print("THIS ONE DID NOT COLLIDE C:"); break; } } if (finalRoom != null) { print("FOUND NEW ROOM"); finalRoom.GetComponent <BaseRoom>().replaced = true; StartCoroutine(finalRoom.GetComponent <BaseRoom>().SpawnNextRoom()); } else { RemoveDoor(backupParentDoor); if (openProcesses <= 0) { CheckRoomCount(); } } }
public void SpawnDungeonPartAlt(List <GameObject> allRooms, DungeonDoor.DoorDirection requiredDirection, GameObject parentRoom, Transform doorPoint, BaseRoom.RoomTypes roomType) { if (roomCount < maxRoomCount) { if (roomType == BaseRoom.RoomTypes.Normal) { List <GameObject> shouldReplace = ReplaceWithSpecialRoom(parentRoom); if (shouldReplace != null) { allRooms = shouldReplace; } } List <GameObject> possibleRooms = new List <GameObject>(); foreach (GameObject room in allRooms) { foreach (GameObject door in room.GetComponent <BaseRoom>().availableDoors) { if (door.GetComponent <DungeonDoor>().direction == requiredDirection) { possibleRooms.Add(room); break; } } } GameObject roomToSpawn = possibleRooms[Random.Range(0, possibleRooms.Count)]; List <Transform> availableDoors = new List <Transform>(); for (int i = 0; i < roomToSpawn.GetComponent <BaseRoom>().availableDoors.Count; i++) { GameObject thisDoor = roomToSpawn.GetComponent <BaseRoom>().availableDoors[i]; if (thisDoor.GetComponent <DungeonDoor>().direction == requiredDirection) { availableDoors.Add(thisDoor.transform); } } Transform selectedDoor = availableDoors[Random.Range(0, availableDoors.Count)]; int selectedDoorId = selectedDoor.GetComponent <DungeonDoor>().id; GameObject spawnedRoom = Instantiate(roomToSpawn, GetLocationData(roomToSpawn.transform, selectedDoor, doorPoint), Quaternion.identity); for (int i = 0; i < spawnedRoom.GetComponent <BaseRoom>().availableDoors.Count; i++) { Transform thisDoor = spawnedRoom.GetComponent <BaseRoom>().availableDoors[i].transform; if (thisDoor.GetComponent <DungeonDoor>().id == selectedDoorId) { selectedDoor = thisDoor; break; } } spawnedRoom.GetComponent <BaseRoom>().Initialize(this, parentRoom, selectedDoor.gameObject); spawnedRoom.GetComponent <BaseRoom>().entranceDoor.GetComponent <DungeonDoor>().parentDoor = doorPoint.gameObject; CheckPartCollision(spawnedRoom, selectedDoor.GetComponent <DungeonDoor>().direction); } else { RemoveDoor(doorPoint.gameObject); if (openProcesses == 0) { CheckRoomCount(); } } }
public void SpawnRandomRoom(GameObject thisRoom, Transform doorPoint, DungeonDoor.DoorDirection requiredDirection) { SpawnDungeonPartAlt(rooms, requiredDirection, thisRoom, doorPoint, BaseRoom.RoomTypes.Normal); }
public void SpawnRandomHallway(GameObject thisRoom, Transform doorPoint, DungeonDoor.DoorDirection requiredDirection) { SpawnDungeonPartAlt(hallways, requiredDirection, thisRoom, doorPoint, BaseRoom.RoomTypes.Hallway); }
public void ReplaceRoom(GameObject roomToReplace, DungeonDoor.DoorDirection entranceDirection) { Vector3 backupPos = roomToReplace.GetComponent <DungeonRoom>().entranceDoor.transform.position; GameObject backupParent = roomToReplace.transform.parent.gameObject; entireDungeon.Remove(roomToReplace); if (endRooms.Contains(roomToReplace)) { endRooms.Remove(roomToReplace); } print("DESTROYED " + roomToReplace); DestroyImmediate(roomToReplace); List <GameObject> availableOptions = new List <GameObject>(); switch (entranceDirection) { case DungeonDoor.DoorDirection.Up: availableOptions = upRooms; break; case DungeonDoor.DoorDirection.Down: availableOptions = downRooms; break; case DungeonDoor.DoorDirection.Left: availableOptions = leftRooms; break; case DungeonDoor.DoorDirection.Right: availableOptions = rightRooms; break; } GameObject finalRoom = null; GameObject entranceDoor = null; foreach (GameObject option in availableOptions) { finalRoom = Instantiate(option); List <GameObject> availableDoors = new List <GameObject>(); foreach (GameObject door in finalRoom.GetComponent <DungeonRoom>().availableDoors) { if (door.GetComponent <DungeonDoor>().direction == entranceDirection) { availableDoors.Add(door); } } entranceDoor = availableDoors[Random.Range(0, availableDoors.Count)]; finalRoom.transform.position = backupPos - entranceDoor.transform.localPosition; finalRoom.GetComponent <DungeonRoom>().Initialize(this, entranceDoor); if (finalRoom.GetComponent <DungeonRoom>().HasCollision()) { if (endRooms.Contains(finalRoom)) { endRooms.Remove(finalRoom); } DestroyImmediate(finalRoom); finalRoom = null; continue; } else { //print("THIS ONE DID NOT COLLIDE C:"); break; } } if (finalRoom != null) { print("FOUND NEW ROOM"); entireDungeon.Add(finalRoom); finalRoom.transform.SetParent(backupParent.transform); finalRoom.GetComponent <DungeonRoom>().replaced = true; StartCoroutine(finalRoom.GetComponent <DungeonRoom>().SpawnNextRoom()); } else { ReplaceWithSmallEndRoom(backupParent, backupParent.GetComponent <DungeonRoom>().entranceDoor.GetComponent <DungeonDoor>().direction); if (openProcesses <= 0) { StartCoroutine(CheckRoomCount()); } } }