Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public IEnumerator ConstructTK2DDungeonHook(Action <TK2DDungeonAssembler, Dungeon, tk2dTileMap> orig, TK2DDungeonAssembler self, Dungeon d, tk2dTileMap map)
        {
            for (int j = 0; j < d.data.Width; j++)
            {
                for (int k = 0; k < d.data.Height; k++)
                {
                    try {
                        self.BuildTileIndicesForCell(d, map, j, k);
                    } catch (Exception ex) {
                        if (ExpandStats.debugMode)
                        {
                            ETGModConsole.Log("[DEBUG] Exception caught in TK2DDungeonAssembler.ConstructTK2DDungeonHook at TK2DDungeonAssembler.BuildTileIndicesForCell!");
                        }
                        Debug.Log("Exception caught in TK2DDungeonAssembler.ConstructTK2DDungeonHook at TK2DDungeonAssembler.BuildTileIndicesForCell!");
                        Debug.LogException(ex);
                    }
                }
            }

            yield return(null);

            TileIndices tileIndices = ReflectionHelpers.ReflectGetField <TileIndices>(typeof(TK2DDungeonAssembler), "t", self);

            if (d.tileIndices.tilesetId == GlobalDungeonData.ValidTilesets.WESTGEON || d.tileIndices.tilesetId == GlobalDungeonData.ValidTilesets.FINALGEON)
            {
                for (int l = 0; l < d.data.Width; l++)
                {
                    for (int m = 0; m < d.data.Height; m++)
                    {
                        CellData cellData = d.data.cellData[l][m];
                        if (cellData != null)
                        {
                            if (cellData.type == CellType.FLOOR)
                            {
                                BuildShadowIndex(self, tileIndices, cellData, d, map, l, m);
                            }
                            else if (cellData.type == CellType.PIT)
                            {
                                BuildPitShadowIndex(self, tileIndices, cellData, d, map, l, m);
                            }
                        }
                    }
                }
            }
            TK2DInteriorDecorator decorator = new TK2DInteriorDecorator(self);

            decorator.PlaceLightDecoration(d, map);
            for (int i = 0; i < d.data.rooms.Count; i++)
            {
                if (d.data.rooms[i].area.prototypeRoom == null || d.data.rooms[i].area.prototypeRoom.usesProceduralDecoration)
                {
                    decorator.HandleRoomDecoration(d.data.rooms[i], d, map);
                }
                else
                {
                    decorator.HandleRoomDecorationMinimal(d.data.rooms[i], d, map);
                }
                if (i % 5 == 0)
                {
                    yield return(null);
                }
            }
            if ((d.data.rooms.Count - 1) % 5 != 0)
            {
                yield return(null);
            }
            map.Editor__SpriteCollection = tileIndices.dungeonCollection;
            if (d.ActuallyGenerateTilemap)
            {
                IEnumerator BuildTracker = map.DeferredBuild(tk2dTileMap.BuildFlags.Default);
                while (BuildTracker.MoveNext())
                {
                    yield return(null);
                }
            }
            yield break;
        }
Ejemplo n.º 3
0
        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);
        }