Esempio n. 1
0
 void DamageTiles()
 {
     for (int i = 0; i < m_tilesAround.Count; ++i)
     {
         if (Directions.Contains(m_tilesAround[i].Pos))
         {
             for (int dT = 0; dT < m_manager.DamagedTiles.DamagedTilesList.Count; ++dT)
             {
                 if (m_manager.DamagedTiles.DamagedTilesList[dT].Pos == m_tilesAround[i].Pos)
                 {
                     m_tilesAround[i].Health = m_manager.DamagedTiles.DamagedTilesList[dT].Health;
                 }
             }
             if (m_tilesAround[i].Health > 0)
             {
                 m_tilesAround[i].Health -= BombDamage;
                 m_manager.DamagedTiles.Add(m_tilesAround[i]);
                 if (m_tilesAround[i].BlockSound != null && WallGen.GetTilemap().GetTile(m_tilesAround[i].Pos) != null)
                 {
                     m_source.clip = m_tilesAround[i].BlockSound;
                     m_source.Play();
                 }
             }
             RemoveDeadTiles(i);
         }
     }
 }
Esempio n. 2
0
 public void PlaceTileClick(CustomTile _tile)
 {
     if (_tile != null)
     {
         DropBlock(_tile);
     }
     if (_tile != null && _tile.Item != null && _tile.Item.CanBePlaced || m_manager.Creative)
     {
         Vector2 worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         m_placePos = new Vector3Int((int)worldPosition.x, (int)worldPosition.y, 0);
         if (m_enemySpawner.Enemies.All(g => new Vector3Int((int)g.transform.position.x, (int)g.transform.position.y, (int)g.transform.position.z) != m_placePos))
         {
             float      distance = Vector3Int.Distance(m_placePos, new Vector3Int((int)transform.position.x, (int)transform.position.y, (int)transform.position.z));
             CustomTile newCopy  = Instantiate(_tile);
             if (distance <= MaxRange)
             {
                 if (Input.GetMouseButton(1))
                 {
                     if (newCopy.Type == TileType.Wall)
                     {
                         if (WallGen.GetTilemap().GetTile(m_placePos) == null)
                         {
                             if (new Vector3Int((int)transform.position.x, (int)transform.position.y, 0) != m_placePos)
                             {
                                 PTile(newCopy);
                                 if (!m_fileManager.PlacedOnTiles.ContainsKey(m_placePos))
                                 {
                                     m_fileManager.PlacedOnTiles.Add(m_placePos, TileManager.GetTileDictionaryFloor()[m_placePos].CustomTile);
                                 }
                                 if (TileManager.GetTileDictionaryFloor().ContainsKey(m_placePos))
                                 {
                                     int        id       = TileManager.GetTileDictionaryFloor()[m_placePos].CustomTile.ID;
                                     DataToSave tempData = new DataToSave
                                     {
                                         Position     = new Vector2Int(m_placePos.x, m_placePos.y),
                                         IsPlacedTile = true,
                                         ID           = id,
                                     };
                                     m_fileManager.Input(tempData);
                                 }
                             }
                         }
                     }
                     if (newCopy.Type == TileType.Floor || newCopy.Type == TileType.Path)
                     {
                         if (WallGen.GetTilemap().GetTile(m_placePos) == null)
                         {
                             if (TileManager.GetTileDictionaryFloor()[m_placePos].CustomTile.ID != _tile.ID)
                             {
                                 PTile(newCopy);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 3
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);
    }
Esempio n. 4
0
    void ShouldBlockDrop(CustomTile _tile)
    {
        Vector2    worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector3Int v             = new Vector3Int((int)worldPosition.x, (int)worldPosition.y, 0);

        if (Vector2.Distance(transform.position, worldPosition) > BackPack.PickupRange)
        {
            if (WallGen.GetTilemap().GetTile(v) == null)
            {
                GameObject c = Instantiate(BlockDrop, worldPosition, Quaternion.identity);
                c.GetComponent <BlockDrop>().SetUp(_tile);
                BackPack.RemoveItem(_tile.Item);
            }
        }
    }
Esempio n. 5
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);
                 }
             }
         }
     }
 }