public RoomHandler AddRuntimeRoom() { IntVector2 dimensions = new IntVector2(15, 15); Dungeon d = GameManager.Instance.Dungeon; IntVector2 intVector = new IntVector2(d.data.Width + 10, 10); int newWidth = d.data.Width + 10 + dimensions.x; int newHeight = Mathf.Max(d.data.Height, dimensions.y + 10); CellData[][] array = BraveUtility.MultidimensionalArrayResize <CellData>(d.data.cellData, d.data.Width, d.data.Height, newWidth, newHeight); CellArea cellArea = new CellArea(intVector, dimensions, 0); cellArea.IsProceduralRoom = true; d.data.cellData = array; d.data.ClearCachedCellData(); RoomHandler roomHandler = new RoomHandler(cellArea); for (int x = 0; x < dimensions.x; x++) { for (int y = 0; y < dimensions.y; y++) { CellType cellType = (x >= 4 && x <= 9 && y >= 4 && y <= 9) ? CellType.FLOOR : CellType.PIT; IntVector2 p = new IntVector2(x, y) + intVector; CellData cellData = new CellData(p, cellType); cellData.parentArea = cellArea; cellData.parentRoom = roomHandler; cellData.nearestRoom = roomHandler; array[p.x][p.y] = cellData; roomHandler.RuntimeStampCellComplex(p.x, p.y, cellType, DiagonalWallType.NONE); } } d.data.rooms.Add(roomHandler); GameObject obj = Instantiate(PlatformOfDeath, new Vector3((float)intVector.x + 5, (float)intVector.y + 3, 0f), Quaternion.identity); obj.GetComponent <tk2dBaseSprite>().HeightOffGround = -30f; obj.GetComponent <tk2dBaseSprite>().UpdateZDepth(); GameObject obj2 = Instantiate(BigPlatformOfDeath, new Vector3((float)intVector.x, (float)intVector.y - 2f, 0f), Quaternion.identity); obj2.GetComponent <tk2dBaseSprite>().HeightOffGround = -30f; obj2.GetComponent <tk2dBaseSprite>().UpdateZDepth(); this.m_currentPlatform = obj; DeadlyDeadlyGoopManager.ReinitializeData(); roomHandler.PreventMinimapUpdates = true; return(roomHandler); }
public RoomHandler AddRuntimeRoom() { IntVector2 dimensions = new IntVector2(24, 24); Dungeon d = GameManager.Instance.Dungeon; IntVector2 intVector = new IntVector2(d.data.Width + 10, 10); int newWidth = d.data.Width + 10 + dimensions.x; int newHeight = Mathf.Max(d.data.Height, dimensions.y + 10); CellData[][] array = BraveUtility.MultidimensionalArrayResize <CellData>(d.data.cellData, d.data.Width, d.data.Height, newWidth, newHeight); CellArea cellArea = new CellArea(intVector, dimensions, 0); cellArea.IsProceduralRoom = true; d.data.cellData = array; d.data.ClearCachedCellData(); RoomHandler roomHandler = new RoomHandler(cellArea); for (int i = 0; i < dimensions.x; i++) { for (int j = 0; j < dimensions.y; j++) { IntVector2 p = new IntVector2(i, j) + intVector; CellData cellData = new CellData(p, CellType.FLOOR); cellData.parentArea = cellArea; cellData.parentRoom = roomHandler; cellData.nearestRoom = roomHandler; array[p.x][p.y] = cellData; roomHandler.RuntimeStampCellComplex(p.x, p.y, CellType.FLOOR, DiagonalWallType.NONE); } } d.data.rooms.Add(roomHandler); GameObject obj = Instantiate((GameObject)BraveResources.Load("Global Prefabs/CreepyEye_Room", ".prefab"), new Vector3((float)intVector.x, (float)intVector.y, 0f), Quaternion.identity); List <Component> children = obj.GetComponentsInChildren <Component>().ToList(); foreach (Component component in obj.GetComponents <Component>()) { if (children.Contains(component)) { children.Remove(component); } } foreach (Component child in children) { Destroy(child); } DeadlyDeadlyGoopManager.ReinitializeData(); roomHandler.Entered += delegate(PlayerController p) { AdvancedGameStatsManager.Instance.SetFlag(CustomDungeonFlags.ITEMSPECIFIC_GREEN_CHAMBER, true); for (int i = parentRoom.area.basePosition.x; i < parentRoom.area.basePosition.x + parentRoom.area.dimensions.x; i++) { for (int j = parentRoom.area.basePosition.y; j < parentRoom.area.basePosition.y + parentRoom.area.dimensions.y; j++) { CellData cellData = GameManager.Instance.Dungeon.data[i, j]; if (cellData != null && cellData.parentRoom == parentRoom && !cellData.isExitCell) { cellData.type = CellType.FLOOR; } } } enteredGeneratedRoom = true; parentRoom.AddProceduralTeleporterToRoom(); Destroy(eye); }; Transform parent = new GameObject("room's parent").transform; parent.position = new Vector3((float)intVector.x, (float)intVector.y, 0f); roomHandler.hierarchyParent = parent; Transform arrivalPoint = new GameObject("Arrival").transform; arrivalPoint.name = "Arrival"; arrivalPoint.position = new Vector3((float)intVector.x + (float)dimensions.x / 2, (float)intVector.y + (float)dimensions.x / 4, 0f); arrivalPoint.parent = parent; if (GreenChamberRewardPedestal != null) { RewardPedestal.Spawn(GreenChamberRewardPedestal.GetComponent <RewardPedestal>(), new IntVector2((intVector.x + dimensions.x / 2) - 1, (intVector.y + dimensions.x / 2) - 3)); } roomHandler.PreventMinimapUpdates = true; return(roomHandler); }
private RoomHandler[] GenerateCorruptedBossRoomCluster(Action <RoomHandler> postProcessCellData = null, DungeonData.LightGenerationStyle lightStyle = DungeonData.LightGenerationStyle.STANDARD) { Dungeon dungeon = GameManager.Instance.Dungeon; PrototypeDungeonRoom[] RoomArray = new PrototypeDungeonRoom[] { ExpandRoomPrefabs.CreepyGlitchRoom_Entrance, ExpandRoomPrefabs.CreepyGlitchRoom }; IntVector2[] basePositions = new IntVector2[] { IntVector2.Zero, new IntVector2(14, 0) }; GameObject tileMapObject = GameObject.Find("TileMap"); tk2dTileMap m_tilemap = tileMapObject.GetComponent <tk2dTileMap>(); if (m_tilemap == null) { if (ExpandStats.debugMode) { ETGModConsole.Log("ERROR: TileMap object is null! Something seriously went wrong!"); } return(null); } TK2DDungeonAssembler assembler = new TK2DDungeonAssembler(); assembler.Initialize(dungeon.tileIndices); if (RoomArray.Length != basePositions.Length) { Debug.LogError("Attempting to add a malformed room cluster at runtime!"); return(null); } RoomHandler[] RoomClusterArray = new RoomHandler[RoomArray.Length]; int num = 6; int num2 = 3; IntVector2 intVector = new IntVector2(int.MaxValue, int.MaxValue); IntVector2 intVector2 = new IntVector2(int.MinValue, int.MinValue); for (int i = 0; i < RoomArray.Length; i++) { intVector = IntVector2.Min(intVector, basePositions[i]); intVector2 = IntVector2.Max(intVector2, basePositions[i] + new IntVector2(RoomArray[i].Width, RoomArray[i].Height)); } IntVector2 a = intVector2 - intVector; IntVector2 b = IntVector2.Min(IntVector2.Zero, -1 * intVector); a += b; IntVector2 intVector3 = new IntVector2(dungeon.data.Width + num, num); int newWidth = dungeon.data.Width + num * 2 + a.x; int newHeight = Mathf.Max(dungeon.data.Height, a.y + num * 2); CellData[][] array = BraveUtility.MultidimensionalArrayResize(dungeon.data.cellData, dungeon.data.Width, dungeon.data.Height, newWidth, newHeight); dungeon.data.cellData = array; dungeon.data.ClearCachedCellData(); for (int j = 0; j < RoomArray.Length; j++) { IntVector2 d = new IntVector2(RoomArray[j].Width, RoomArray[j].Height); IntVector2 b2 = basePositions[j] + b; IntVector2 intVector4 = intVector3 + b2; CellArea cellArea = new CellArea(intVector4, d, 0); cellArea.prototypeRoom = RoomArray[j]; RoomHandler SelectedRoomInArray = new RoomHandler(cellArea); for (int k = -num; k < d.x + num; k++) { for (int l = -num; l < d.y + num; l++) { IntVector2 p = new IntVector2(k, l) + intVector4; if ((k >= 0 && l >= 0 && k < d.x && l < d.y) || array[p.x][p.y] == null) { CellData cellData = new CellData(p, CellType.WALL); cellData.positionInTilemap = cellData.positionInTilemap - intVector3 + new IntVector2(num2, num2); cellData.parentArea = cellArea; cellData.parentRoom = SelectedRoomInArray; cellData.nearestRoom = SelectedRoomInArray; cellData.distanceFromNearestRoom = 0f; array[p.x][p.y] = cellData; } } } dungeon.data.rooms.Add(SelectedRoomInArray); RoomClusterArray[j] = SelectedRoomInArray; } ConnectClusteredRooms(RoomClusterArray[1], RoomClusterArray[0], RoomArray[1], RoomArray[0], 0, 0, 3, 3); try { for (int n = 0; n < RoomClusterArray.Length; n++) { try { RoomClusterArray[n].WriteRoomData(dungeon.data); } catch (Exception) { if (ExpandStats.debugMode) { ETGModConsole.Log("WARNING: Exception caused during WriteRoomData step on room: " + RoomClusterArray[n].GetRoomName()); } } try { dungeon.data.GenerateLightsForRoom(dungeon.decoSettings, RoomClusterArray[n], GameObject.Find("_Lights").transform, lightStyle); } catch (Exception) { if (ExpandStats.debugMode) { ETGModConsole.Log("WARNING: Exception caused during GeernateLightsForRoom step on room: " + RoomClusterArray[n].GetRoomName()); } } postProcessCellData?.Invoke(RoomClusterArray[n]); if (RoomClusterArray[n].area.PrototypeRoomCategory == PrototypeDungeonRoom.RoomCategory.SECRET) { RoomClusterArray[n].BuildSecretRoomCover(); } } GameObject gameObject = (GameObject)Instantiate(BraveResources.Load("RuntimeTileMap", ".prefab")); tk2dTileMap component = gameObject.GetComponent <tk2dTileMap>(); string str = UnityEngine.Random.Range(10000, 99999).ToString(); gameObject.name = "Corrupted_" + "RuntimeTilemap_" + str; component.renderData.name = "Corrupted_" + "RuntimeTilemap_" + str + " Render Data"; component.Editor__SpriteCollection = dungeon.tileIndices.dungeonCollection; TK2DDungeonAssembler.RuntimeResizeTileMap(component, a.x + num2 * 2, a.y + num2 * 2, m_tilemap.partitionSizeX, m_tilemap.partitionSizeY); for (int num3 = 0; num3 < RoomArray.Length; num3++) { IntVector2 intVector5 = new IntVector2(RoomArray[num3].Width, RoomArray[num3].Height); IntVector2 b3 = basePositions[num3] + b; IntVector2 intVector6 = intVector3 + b3; for (int num4 = -num2; num4 < intVector5.x + num2; num4++) { for (int num5 = -num2; num5 < intVector5.y + num2 + 2; num5++) { try { assembler.BuildTileIndicesForCell(dungeon, component, intVector6.x + num4, intVector6.y + num5); } catch (Exception ex) { if (ExpandStats.debugMode) { ETGModConsole.Log("WARNING: Exception caused during BuildTileIndicesForCell step on room: " + RoomArray[num3].name); Debug.Log("WARNING: Exception caused during BuildTileIndicesForCell step on room: " + RoomArray[num3].name); Debug.LogException(ex); } } } } } RenderMeshBuilder.CurrentCellXOffset = intVector3.x - num2; RenderMeshBuilder.CurrentCellYOffset = intVector3.y - num2; component.ForceBuild(); RenderMeshBuilder.CurrentCellXOffset = 0; RenderMeshBuilder.CurrentCellYOffset = 0; component.renderData.transform.position = new Vector3(intVector3.x - num2, intVector3.y - num2, intVector3.y - num2); for (int num6 = 0; num6 < RoomClusterArray.Length; num6++) { RoomClusterArray[num6].OverrideTilemap = component; for (int num7 = 0; num7 < RoomClusterArray[num6].area.dimensions.x; num7++) { for (int num8 = 0; num8 < RoomClusterArray[num6].area.dimensions.y + 2; num8++) { IntVector2 intVector7 = RoomClusterArray[num6].area.basePosition + new IntVector2(num7, num8); if (dungeon.data.CheckInBoundsAndValid(intVector7)) { CellData currentCell = dungeon.data[intVector7]; TK2DInteriorDecorator.PlaceLightDecorationForCell(dungeon, component, currentCell, intVector7); } } } Pathfinder.Instance.InitializeRegion(dungeon.data, RoomClusterArray[num6].area.basePosition + new IntVector2(-3, -3), RoomClusterArray[num6].area.dimensions + new IntVector2(3, 3)); if (!RoomClusterArray[num6].IsSecretRoom) { RoomClusterArray[num6].RevealedOnMap = true; RoomClusterArray[num6].visibility = RoomHandler.VisibilityStatus.VISITED; StartCoroutine(Minimap.Instance.RevealMinimapRoomInternal(RoomClusterArray[num6], true, true, false)); } RoomClusterArray[num6].PostGenerationCleanup(); } if (RoomArray.Length == RoomClusterArray.Length) { for (int i = 0; i < RoomArray.Length; i++) { if (RoomArray[i].usesProceduralDecoration && RoomArray[i].allowFloorDecoration) { TK2DInteriorDecorator decorator = new TK2DInteriorDecorator(assembler); decorator.HandleRoomDecoration(RoomClusterArray[i], dungeon, m_tilemap); } } } } catch (Exception) { } DeadlyDeadlyGoopManager.ReinitializeData(); Minimap.Instance.InitializeMinimap(dungeon.data); return(RoomClusterArray); }
public static RoomHandler AddCustomRuntimeRoom(PrototypeDungeonRoom prototype, bool addRoomToMinimap = true, bool addTeleporter = true, bool isSecretRatExitRoom = false, Action <RoomHandler> postProcessCellData = null, DungeonData.LightGenerationStyle lightStyle = DungeonData.LightGenerationStyle.STANDARD) { Dungeon dungeon = GameManager.Instance.Dungeon; GameObject gameObject3 = (GameObject)UnityEngine.Object.Instantiate(BraveResources.Load("RuntimeTileMap", ".prefab")); tk2dTileMap component3 = gameObject3.GetComponent <tk2dTileMap>(); string str = UnityEngine.Random.Range(10000, 99999).ToString(); gameObject3.name = "Breach_RuntimeTilemap_" + str; component3.renderData.name = "Breach_RuntimeTilemap_" + str + " Render Data"; component3.Editor__SpriteCollection = dungeon.tileIndices.dungeonCollection; TK2DDungeonAssembler.RuntimeResizeTileMap(component3, 8, 8, component3.partitionSizeX, component3.partitionSizeY); GameObject gameObject2 = (GameObject)UnityEngine.Object.Instantiate(BraveResources.Load("RuntimeTileMap", ".prefab")); tk2dTileMap component2 = gameObject2.GetComponent <tk2dTileMap>(); //creepyRoom.OverrideTilemap = component; tk2dTileMap component4 = GameObject.Find("TileMap").GetComponent <tk2dTileMap>(); tk2dTileMap mainTilemap = component4; //tk2dTileMap mainTilemap = dungeon.MainTilemap; if (mainTilemap == null) { ETGModConsole.Log("ERROR: TileMap object is null! Something seriously went wrong!", false); Debug.Log("ERROR: TileMap object is null! Something seriously went wrong!"); return(null); } TK2DDungeonAssembler tk2DDungeonAssembler = new TK2DDungeonAssembler(); tk2DDungeonAssembler.Initialize(dungeon.tileIndices); IntVector2 zero = IntVector2.Zero; IntVector2 intVector = new IntVector2(50, 50); int x = intVector.x; int y = intVector.y; IntVector2 intVector2 = new IntVector2(int.MaxValue, int.MaxValue); IntVector2 lhs = new IntVector2(int.MinValue, int.MinValue); intVector2 = IntVector2.Min(intVector2, zero); IntVector2 intVector3 = IntVector2.Max(lhs, zero + new IntVector2(prototype.Width, prototype.Height)) - intVector2; IntVector2 b = IntVector2.Min(IntVector2.Zero, -1 * intVector2); intVector3 += b; IntVector2 intVector4 = new IntVector2(dungeon.data.Width + x, x); int newWidth = dungeon.data.Width + x * 2 + intVector3.x; int newHeight = Mathf.Max(dungeon.data.Height, intVector3.y + x * 2); CellData[][] array = BraveUtility.MultidimensionalArrayResize <CellData>(dungeon.data.cellData, dungeon.data.Width, dungeon.data.Height, newWidth, newHeight); dungeon.data.cellData = array; dungeon.data.ClearCachedCellData(); IntVector2 intVector5 = new IntVector2(prototype.Width, prototype.Height); IntVector2 b2 = zero + b; IntVector2 intVector6 = intVector4 + b2; CellArea cellArea = new CellArea(intVector6, intVector5, 0); cellArea.prototypeRoom = prototype; RoomHandler roomHandler = new RoomHandler(cellArea); for (int i = -x; i < intVector5.x + x; i++) { for (int j = -x; j < intVector5.y + x; j++) { IntVector2 intVector7 = new IntVector2(i, j) + intVector6; if ((i >= 0 && j >= 0 && i < intVector5.x && j < intVector5.y) || array[intVector7.x][intVector7.y] == null) { CellData cellData = new CellData(intVector7, CellType.WALL); cellData.positionInTilemap = cellData.positionInTilemap - intVector4 + new IntVector2(y, y); cellData.parentArea = cellArea; cellData.parentRoom = roomHandler; cellData.nearestRoom = roomHandler; cellData.distanceFromNearestRoom = 0f; array[intVector7.x][intVector7.y] = cellData; } } } dungeon.data.rooms.Add(roomHandler); try { roomHandler.WriteRoomData(dungeon.data); } catch (Exception) { ETGModConsole.Log("WARNING: Exception caused during WriteRoomData step on room: " + roomHandler.GetRoomName(), false); } try { dungeon.data.GenerateLightsForRoom(dungeon.decoSettings, roomHandler, GameObject.Find("_Lights").transform, lightStyle); } catch (Exception) { ETGModConsole.Log("WARNING: Exception caused during GeernateLightsForRoom step on room: " + roomHandler.GetRoomName(), false); } if (postProcessCellData != null) { postProcessCellData(roomHandler); } if (roomHandler.area.PrototypeRoomCategory == PrototypeDungeonRoom.RoomCategory.SECRET) { roomHandler.BuildSecretRoomCover(); } GameObject gameObject = (GameObject)UnityEngine.Object.Instantiate(BraveResources.Load("RuntimeTileMap", ".prefab")); tk2dTileMap component = gameObject.GetComponent <tk2dTileMap>(); string str2 = UnityEngine.Random.Range(10000, 99999).ToString(); gameObject.name = "Glitch_RuntimeTilemap_" + str; component.renderData.name = "Glitch_RuntimeTilemap_" + str + " Render Data"; component.Editor__SpriteCollection = dungeon.tileIndices.dungeonCollection; try { TK2DDungeonAssembler.RuntimeResizeTileMap(component, intVector3.x + y * 2, intVector3.y + y * 2, mainTilemap.partitionSizeX, mainTilemap.partitionSizeY); IntVector2 intVector8 = new IntVector2(prototype.Width, prototype.Height); IntVector2 b3 = zero + b; IntVector2 intVector9 = intVector4 + b3; for (int k = -y; k < intVector8.x + y; k++) { for (int l = -y; l < intVector8.y + y + 2; l++) { tk2DDungeonAssembler.BuildTileIndicesForCell(dungeon, component, intVector9.x + k, intVector9.y + l); } } RenderMeshBuilder.CurrentCellXOffset = intVector4.x - y; RenderMeshBuilder.CurrentCellYOffset = intVector4.y - y; component.ForceBuild(); RenderMeshBuilder.CurrentCellXOffset = 0; RenderMeshBuilder.CurrentCellYOffset = 0; component.renderData.transform.position = new Vector3((float)(intVector4.x - y), (float)(intVector4.y - y), (float)(intVector4.y - y)); } catch (Exception exception) { ETGModConsole.Log("WARNING: Exception occured during RuntimeResizeTileMap / RenderMeshBuilder steps!", false); Debug.Log("WARNING: Exception occured during RuntimeResizeTileMap/RenderMeshBuilder steps!"); Debug.LogException(exception); } roomHandler.OverrideTilemap = component; for (int m = 0; m < roomHandler.area.dimensions.x; m++) { for (int n = 0; n < roomHandler.area.dimensions.y + 2; n++) { IntVector2 intVector10 = roomHandler.area.basePosition + new IntVector2(m, n); if (dungeon.data.CheckInBoundsAndValid(intVector10)) { CellData currentCell = dungeon.data[intVector10]; TK2DInteriorDecorator.PlaceLightDecorationForCell(dungeon, component, currentCell, intVector10); } } } Pathfinder.Instance.InitializeRegion(dungeon.data, roomHandler.area.basePosition + new IntVector2(-3, -3), roomHandler.area.dimensions + new IntVector2(3, 3)); if (prototype.usesProceduralDecoration && prototype.allowFloorDecoration) { new TK2DInteriorDecorator(tk2DDungeonAssembler).HandleRoomDecoration(roomHandler, dungeon, mainTilemap); } roomHandler.PostGenerationCleanup(); if (addRoomToMinimap) { roomHandler.visibility = RoomHandler.VisibilityStatus.VISITED; MonoBehaviour mono = new MonoBehaviour(); mono.StartCoroutine(Minimap.Instance.RevealMinimapRoomInternal(roomHandler, true, true, false)); if (isSecretRatExitRoom) { roomHandler.visibility = RoomHandler.VisibilityStatus.OBSCURED; } } if (addTeleporter) { roomHandler.AddProceduralTeleporterToRoom(); } if (addRoomToMinimap) { Minimap.Instance.InitializeMinimap(dungeon.data); } DeadlyDeadlyGoopManager.ReinitializeData(); return(roomHandler); }