Exemplo n.º 1
0
    void PTile(CustomTile _copy)
    {
        Tilemap        toPlace  = null;
        Tilemap        toRemove = null;
        DictionaryType _type    = DictionaryType.Walls;

        switch (_copy.Type)
        {
        case TileType.Wall:
            toPlace  = WallGen.GetTilemap();
            toRemove = DungeonUtility.GetTilemap();
            _type    = DictionaryType.Walls;
            break;

        case TileType.Floor:
            toPlace  = DungeonUtility.GetTilemap();
            toRemove = DungeonUtility.GetTilemap();
            _type    = DictionaryType.Floor;
            break;

        case TileType.Path:
            toPlace  = DungeonUtility.GetTilemap();
            toRemove = DungeonUtility.GetTilemap();
            _type    = DictionaryType.Floor;
            break;
        }
        int id = 0;

        for (int a = 0; a < TileManager.GetTileHolder(_copy.Type).Tiles.Count; ++a)
        {
            if (TileManager.GetTileHolder(_copy.Type).Tiles[a].ID == _copy.ID)
            {
                _copy = TileManager.GetTileHolder(_copy.Type).Tiles[a];
                id    = TileManager.GetTileHolder(_copy.Type).Tiles[a].ID;
            }
        }
        TileManager.PlaceTile(m_placePos, m_index, toRemove, toPlace, _copy, _type);
        ApplySpriteVariation(_copy, toPlace, m_placePos);
        Instantiate(m_audioPlaceSource);
        if (!m_manager.Creative && BackPack.GetStorageTypeCount(_copy) > 0)
        {
            BackPack.RemoveItem(_copy.Item);
            if (BackPack.GetNewItem(_copy) != null)
            {
                _copy.Item = Instantiate(BackPack.GetNewItem(_copy));
            }
        }
        DataToSave tempData = new DataToSave
        {
            Position = new Vector2Int(m_placePos.x, m_placePos.y),
            ID       = id
        };

        m_fileManager.Input(tempData);
    }
Exemplo n.º 2
0
 void RemoveDeadTiles(int _index)
 {
     if (m_tilesAround[_index].Health <= 0)
     {
         DataToSave tempData = new DataToSave
         {
             Position     = new Vector2Int(m_tilesAround[_index].Pos.x, m_tilesAround[_index].Pos.y),
             ID           = m_tilesAround[_index].ID,
             IsNull       = true,
             IsPlacedTile = false
         };
         if (TileManager.GetTileDictionaryWalls().ContainsKey(m_tilesAround[_index].Pos))
         {
             if (WallGen.GetTilemap().GetTile(m_tilesAround[_index].Pos) != null)
             {
                 if (TileManager.GetTileDictionaryFloor().ContainsKey(m_tilesAround[_index].Pos))
                 {
                     TileManager.PlaceTile(m_tilesAround[_index].Pos, 0, WallGen.GetTilemap(), DungeonUtility.GetTilemap(), TileManager.GetTileDictionaryFloor()[m_tilesAround[_index].Pos].CustomTile, DictionaryType.Floor);
                     PlayBreakingEffect(_index);
                     AddToStorage(_index);
                     tempData.IsNull = true;
                     m_fileManager.Input(tempData);
                 }
                 else
                 {
                     TileManager.PlaceTile(m_tilesAround[_index].Pos, 0, WallGen.GetTilemap(), DungeonUtility.GetTilemap(), TileManager.GetTileHolder(TileType.Path).Tiles[0], DictionaryType.Floor);
                     PlayBreakingEffect(_index);
                     AddToStorage(_index);
                     tempData.ID           = TileManager.GetTileHolder(TileType.Path).Tiles[0].ID;
                     tempData.IsNull       = false;
                     tempData.IsPlacedTile = true;
                     m_fileManager.Input(tempData);
                 }
             }
         }
     }
 }
    public void Build()
    {
        m_fileManager = transform.parent.parent.GetComponent <FileManager>();
        if (!m_fileManager.Save.SeedSet)
        {
            m_fileManager.Save.Seed    = Seed;
            m_fileManager.Save.SeedSet = true;
        }
        Stopwatch SW = new Stopwatch();

        SW.Start();
        TileManager.LoadTileManager();
        m_dungeonDimensions = new Vector2Int(m_fileManager.XDimension, m_fileManager.YDimension);
        DungeonUtility.DungeonSetup(m_dungeonDimensions, m_tilemap);
        WallGen.SetWallSizes(m_wallDimensions);
        WallGen.SetWallsTileMap(m_walls);
        for (int i = 0; i < m_fileManager.SquareRoomAmount; ++i)
        {
            DungeonUtility.PickBuildPoint();
            WallGen.RandomiseWallSizes(m_wallSizesSquare[0], m_wallSizesSquare[1], m_wallSizesSquare[2], m_wallSizesSquare[3]);
            FloorGen.Square();
            if (UseMiniMapIcons)
            {
                Vector2 pos = new Vector2(DungeonUtility.GetBuildPoint().x + WallGen.GetWallDimensions().x / 2, DungeonUtility.GetBuildPoint().y + WallGen.GetWallDimensions().y / 2);
                Instantiate(SquareRoom, pos, Quaternion.identity);
            }
        }
        for (int i = 0; i < m_fileManager.LShapeRoomAmount; ++i)
        {
            DungeonUtility.PickBuildPoint();
            WallGen.RandomiseWallSizes(m_wallSizesSquare[0], m_wallSizesSquare[1], m_wallSizesSquare[2], m_wallSizesSquare[3]);
            int directionRandom = UnityEngine.Random.Range(0, 4);
            FloorGen.LShape(m_wallLengthLShape, m_wallHeightLShape, directionRandom);
        }
        for (int i = 0; i < m_fileManager.TShapeRoomAmount; ++i)
        {
            DungeonUtility.PickBuildPoint();
            int directionRandom = UnityEngine.Random.Range(0, 4);
            int stemWidth       = UnityEngine.Random.Range(2, m_wallSizesTShape[0]);
            int stemHeight      = UnityEngine.Random.Range(2, m_wallSizesTShape[1]);
            int roomLength      = UnityEngine.Random.Range(2, m_wallSizesTShape[2]);
            int roomHeight      = UnityEngine.Random.Range(2, m_wallSizesTShape[3]);
            FloorGen.TShape(stemWidth, stemHeight, roomLength, roomHeight, directionRandom);
        }
        for (int i = 0; i < m_fileManager.CircleRoomAmount; ++i)
        {
            int randomCircleSize = UnityEngine.Random.Range(1, m_circleStartSizeMax);
            DungeonUtility.PickBuildPoint();
            m_circleMiddleAmount = randomCircleSize;
            FloorGen.Circle(randomCircleSize, m_circleMiddleAmount);
            if (UseMiniMapIcons)
            {
                Vector2 pos = new Vector2(DungeonUtility.GetBuildPoint().x + m_circleMiddleAmount / 2, DungeonUtility.GetBuildPoint().y + m_circleMiddleAmount * 2);
                Instantiate(CircleRoom, pos, Quaternion.identity);
            }
        }
        for (int i = 0; i < m_fileManager.DiamondRoomAmount; ++i)
        {
            int RandomMaxRowAmount = UnityEngine.Random.Range(10, m_diamondMaxRowAmount);
            DungeonUtility.PickBuildPoint();
            FloorGen.Diamond(1, RandomMaxRowAmount);
            if (UseMiniMapIcons)
            {
                Vector2 pos = new Vector2(DungeonUtility.GetBuildPoint().x, DungeonUtility.GetBuildPoint().y + RandomMaxRowAmount / 2);
                Instantiate(DiamondRoom, pos, DiamondRoom.transform.rotation);
            }
        }
        for (int i = 0; i < FloorGen.GetFloorTilePositions().Count; ++i)
        {
            FloorGen.PlaceFloorTile(FloorGen.GetFloorTilePositions()[i]);
        }
        m_pathAmount += (m_fileManager.DiamondRoomAmount + m_fileManager.CircleRoomAmount + m_fileManager.SquareRoomAmount + m_fileManager.LShapeRoomAmount + m_fileManager.TShapeRoomAmount) / 4;
        for (int i = 0; i < m_pathAmount; ++i)
        {
            ConnectRoom.PlacePositions(i);
            ConnectRoom.FindOtherRoom();
        }
        WallGen.PlaceWalls();

        GameObject.Find("Player").GetComponent <PlaceTile>().FillTilesList();
        SW.Stop();
        TimeSpan ts = SW.Elapsed;

        UnityEngine.Debug.Log("Building Dungeon Took: " + ts.Milliseconds + " ms");
    }