// Adds Teleporter to entrance room on first floor so that player can teleport back if teleported via Tentacle Teleporter.
 private void PlaceTeleporter(Dungeon dungeon)
 {
     for (int i = 0; i < dungeon.data.rooms.Count; i++)
     {
         RoomHandler CurrnetRoom = dungeon.data.rooms[i];
         if (CurrnetRoom.area.PrototypeRoomCategory == PrototypeDungeonRoom.RoomCategory.ENTRANCE)
         {
             CurrnetRoom.AddProceduralTeleporterToRoom();
             break;
         }
     }
     return;
 }
Beispiel #2
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);
        }