Ejemplo n.º 1
0
 public void RemoveTile(Vector3Int position, LayerType layerType)
 {
     if (metaTileMap.HasTile(position, layerType))
     {
         RpcRemoveTile(position, layerType, false);
     }
 }
Ejemplo n.º 2
0
    private static Matrix4x4 FindObjectPosition(MetaTileMap metaTileMap, ref Vector3Int position, LayerTile tile)
    {
        bool onStructure = metaTileMap.HasTile(position, LayerType.Walls) ||
                           metaTileMap.HasTile(position, LayerType.Windows);

        Quaternion rotation = Quaternion.identity;

        for (int i = 0; i < 4; i++)
        {
            Vector3Int offset       = Vector3Int.RoundToInt(rotation * Vector3.up);
            bool       hasStructure = metaTileMap.HasTile(position + offset, LayerType.Walls) ||
                                      metaTileMap.HasTile(position, LayerType.Windows);
            bool isOccupied = metaTileMap.HasTile(position + offset, onStructure ? LayerType.Base : LayerType.Objects);

            if (onStructure != hasStructure && isOccupied == onStructure)
            {
                if (onStructure)
                {
                    position += offset;
                    rotation *= Quaternion.Euler(0f, 0f, 180);
                }
                break;
            }

            rotation *= Quaternion.Euler(0, 0, 90);
        }

        return(Matrix4x4.TRS(Vector3.zero, rotation, Vector3.one));
    }
Ejemplo n.º 3
0
    void Awake()
    {
        tileChangeManager = transform.GetComponentInParent <TileChangeManager>();
        metaDataLayer     = transform.GetComponentInParent <MetaDataLayer>();
        metaTileMap       = transform.GetComponentInParent <MetaTileMap>();

        Layer  = GetComponent <Layer>();
        matrix = GetComponentInParent <Matrix>();

        tileChangeManager.OnFloorOrPlatingRemoved.RemoveAllListeners();
        tileChangeManager.OnFloorOrPlatingRemoved.AddListener(cellPos =>
        {         //Poke items when both floor and plating are gone
            //As they might want to change matrix
            if (!metaTileMap.HasTile(cellPos, LayerType.Floors, true) &&
                !metaTileMap.HasTile(cellPos, LayerType.Base, true) &&
                metaTileMap.HasTile(cellPos, LayerType.Objects, true)
                )
            {
                foreach (var customNetTransform in matrix.Get <CustomNetTransform>(cellPos, true))
                {
                    customNetTransform.CheckMatrixSwitch();
                }
            }
        });
    }
Ejemplo n.º 4
0
    public void RemoveTile(Vector3Int cellPosition, LayerType layerType)
    {
        if (metaTileMap.HasTile(cellPosition, layerType, true))
        {
            RpcRemoveTile(cellPosition, layerType, false);

            AddToChangeList(cellPosition, layerType);
        }
    }
Ejemplo n.º 5
0
 //Poke items when both floor and plating are gone
 //As they might want to change matrix
 public void SwitchObjectsMatrixAt(Vector3Int cellPos)
 {
     if (!metaTileMap.HasTile(cellPos, LayerType.Floors) &&
         !metaTileMap.HasTile(cellPos, LayerType.Base) &&
         metaTileMap.HasObject(cellPos, CustomNetworkManager.Instance._isServer)
         )
     {
         foreach (var customNetTransform in matrix.Get <CustomNetTransform>(cellPos, true))
         {
             customNetTransform.CheckMatrixSwitch();
         }
     }
 }
    public void UpdateOverlay(Vector3Int cellPosition, OverlayTile overlayTile)
    {
        cellPosition.z = 0;
        if (!metaTileMap.HasTile(cellPosition, overlayTile.LayerType, true))
        {
            return;
        }
        cellPosition.z = -1;
        if (IsDifferent(cellPosition, overlayTile))
        {
            InternalUpdateTile(cellPosition, overlayTile);

            RpcUpdateTile(cellPosition, overlayTile.TileType, overlayTile.name);

            AddToChangeList(cellPosition, overlayTile);
        }
    }
Ejemplo n.º 7
0
    private void DoBulletDamage(BulletBehaviour bullet, Vector3 forceDir, Vector3 hitPos)
    {
        forceDir.z = 0;
        Vector3      bulletHitTarget = hitPos + (forceDir * 0.2f);
        Vector3Int   cellPos         = metaTileMap.WorldToCell(Vector3Int.RoundToInt(bulletHitTarget));
        MetaDataNode data            = metaDataLayer.Get(cellPos);

        if (Layer.LayerType == LayerType.Windows)
        {
            LayerTile getTile = metaTileMap.GetTile(cellPos, LayerType.Windows);
            if (getTile != null)
            {
                //TODO damage amt based off type of bullet
                AddWindowDamage(bullet.damage, data, cellPos, bulletHitTarget);
                return;
            }
        }

        if (Layer.LayerType == LayerType.Grills)
        {
            //Make sure a window is not protecting it first:
            if (!metaTileMap.HasTile(cellPos, LayerType.Windows, true))
            {
                if (metaTileMap.HasTile(cellPos, LayerType.Grills, true))
                {
                    //TODO damage amt based off type of bullet
                    AddGrillDamage(bullet.damage, data, cellPos, bulletHitTarget);
                }
            }
        }
    }
    public void UpdateOverlay(Vector3Int cellPosition, OverlayTile overlayTile, Matrix4x4?transformMatrix = null,
                              Color?color = null)
    {
        cellPosition.z = 0;
        if (!metaTileMap.HasTile(cellPosition, overlayTile.LayerType))
        {
            return;
        }
        cellPosition.z = -1;
        if (IsDifferent(cellPosition, overlayTile))
        {
            InternalUpdateTile(cellPosition, overlayTile, transformMatrix, color);

            AlertClients(cellPosition, overlayTile.TileType, overlayTile.name, transformMatrix, color);

            AddToChangeList(cellPosition, overlayTile, transformMatrix: transformMatrix, color: color);
        }
    }
Ejemplo n.º 9
0
        /// <summary>
        /// Checks if the grille's location has exposed floor plating,
        /// that a cable overlap exists there,
        /// and returns the highest voltage detected (for now).
        /// </summary>
        /// <returns>The voltage found on the cable</returns>
        private float ServerGetGrilleVoltage()
        {
            Vector3Int  targetCellPos = interaction.TargetCellPos;
            MetaTileMap metaTileMap   = interaction.TileChangeManager.MetaTileMap;
            Matrix      matrix        = metaTileMap.Layers[LayerType.Underfloor].matrix;

            // Check if the floor plating is exposed.
            if (metaTileMap.HasTile(targetCellPos, LayerType.Floors))
            {
                return(0);
            }

            // Check for cables underneath the grille.
            var eConns = matrix.GetElectricalConnections(targetCellPos);

            if (eConns == null)
            {
                return(0);
            }

            // Get the highest voltage and whether there is a connection overlap.
            // The current powernet implementation means the cable
            // will only report a voltage if there is current flow, it seems.
            // That's why we cannot simply the overlap connection's voltage,
            // and both ends of the cable need to be connected to the powernet.
            //
            // One possible workaround is to allow a Connection.Overlap to draw
            // a small amount of current, so that it registers a voltage.
            // Then, we don't need to check for the highest voltage and not worry
            // about whether the overlap is actually connected to a live cable.
            bool  overlapExists = false;
            float voltage       = 0;

            foreach (var conn in eConns)
            {
                if (conn.WireEndA == Connection.Overlap || conn.WireEndB == Connection.Overlap)
                {
                    overlapExists = true;
                }

                ElectricityFunctions.WorkOutActualNumbers(conn);
                if (conn.Data.ActualVoltage > voltage)
                {
                    voltage = conn.Data.ActualVoltage;
                }
            }

            // Check that there is a cable overlap.
            if (!overlapExists)
            {
                return(0);
            }

            // All checks passed, electrocute the performer!
            return(voltage);
        }
    public bool RemoveTile(Vector3Int cellPosition, LayerType layerType)
    {
        if (metaTileMap.HasTile(cellPosition, layerType, true))
        {
            InternalRemoveTile(cellPosition, layerType, false);

            RpcRemoveTile(cellPosition, layerType, false);

            AddToChangeList(cellPosition, layerType);

            if (layerType == LayerType.Floors || layerType == LayerType.Base)
            {
                OnFloorOrPlatingRemoved.Invoke(cellPosition);
            }
            return(true);
        }

        return(false);
    }
Ejemplo n.º 11
0
    public void RunOreGenerator()
    {
        metaTileMap       = GetComponentInChildren <MetaTileMap>();
        wallTilemap       = metaTileMap.Layers[LayerType.Walls].GetComponent <Tilemap>();
        tileChangeManager = GetComponent <TileChangeManager>();

        if (CustomNetworkManager.IsServer)
        {
            List <OreProbability> weightedList = new List <OreProbability>();
            foreach (var ores in config.OreProbabilities)
            {
                for (int i = 0; i < ores.SpawnChance; i++)
                {
                    weightedList.Add(ores);
                }
            }

            //TODO move BoundsInt bounds = wallTilemap.cellBounds to metaTileMap
            BoundsInt         bounds      = wallTilemap.cellBounds;
            List <Vector3Int> miningTiles = new List <Vector3Int>();

            for (int n = bounds.xMin; n < bounds.xMax; n++)
            {
                for (int p = bounds.yMin; p < bounds.yMax; p++)
                {
                    Vector3Int localPlace = (new Vector3Int(n, p, 0));

                    if (metaTileMap.HasTile(localPlace))
                    {
                        var tile = metaTileMap.GetTile(localPlace);
                        if (tile.name.Contains("rock_wall"))
                        {
                            miningTiles.Add(localPlace);
                        }
                    }
                }
            }

            int numberOfTiles = (int)((miningTiles.Count / 100f) * config.Density);
            for (int i = 0; i < numberOfTiles; i++)
            {
                var oreTile     = miningTiles[RANDOM.Next(miningTiles.Count)];
                var oreCategory = weightedList[RANDOM.Next(weightedList.Count)];
                tileChangeManager.UpdateTile(oreTile, oreCategory.WallTile);
                var intLocation = oreTile + Vector3Int.zero;
                intLocation.z = -1;
                tileChangeManager.AddOverlay(intLocation, oreCategory.OverlayTile as OverlayTile);

                NodeScatter(oreTile, oreCategory);
            }
        }
    }
Ejemplo n.º 12
0
 public bool IsClearUnderfloorConstruction(Vector3Int position, bool isServer)
 {
     if (MetaTileMap.HasTile(position, LayerType.Floors, isServer))
     {
         return(false);
     }
     else if (MetaTileMap.HasTile(position, LayerType.Walls, isServer))
     {
         return(false);
     }
     else if (MetaTileMap.HasTile(position, LayerType.Windows, isServer))
     {
         return(false);
     }
     else if (MetaTileMap.HasTile(position, LayerType.Grills, isServer))
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 13
0
    public LayerTile RemoveTile(Vector3Int cellPosition, LayerType layerType, bool removeAll = true)
    {
        var layerTile = metaTileMap.GetTile(cellPosition, layerType);

        if (metaTileMap.HasTile(cellPosition, layerType))
        {
            InternalRemoveTile(cellPosition, layerType, removeAll);

            RemoveTileMessage.Send(networkIdentity.netId, cellPosition, layerType, false);

            AddToChangeList(cellPosition, layerType);

            if (layerType == LayerType.Floors || layerType == LayerType.Base)
            {
                OnFloorOrPlatingRemoved.Invoke(cellPosition);
            }

            RemoveOverlaysOfType(cellPosition, LayerType.Effects, OverlayType.Damage);

            return(layerTile);
        }

        return(layerTile);
    }
Ejemplo n.º 14
0
    public LayerTile RemoveTile(Vector3Int cellPosition, LayerType layerType)
    {
        var layerTile = metaTileMap.GetTile(cellPosition, layerType);

        if (metaTileMap.HasTile(cellPosition, layerType))
        {
            InternalRemoveTile(cellPosition, layerType);

            SpawnSafeThread.RemoveTileMessageSend(networkMatrix.MatrixSync.netId, cellPosition, layerType);

            AddToChangeList(cellPosition, layerType);

            if (layerType == LayerType.Floors || layerType == LayerType.Base)
            {
                OnFloorOrPlatingRemoved.Invoke(cellPosition);
            }

            RemoveOverlaysOfType(cellPosition, LayerType.Effects, OverlayType.Damage);

            return(layerTile);
        }

        return(layerTile);
    }
Ejemplo n.º 15
0
        private static void DrawGizmo(MetaTileMap scr, GizmoType gizmoType)
        {
            if (!DrawGizmos)
            {
                return;
            }

            Vector3Int start = Vector3Int.RoundToInt(Camera.current.ScreenToWorldPoint(Vector3.one * -32) - scr.transform.position);             // bottom left
            Vector3Int end   =
                Vector3Int.RoundToInt(Camera.current.ScreenToWorldPoint(new Vector3(Camera.current.pixelWidth + 32, Camera.current.pixelHeight + 32)) -
                                      scr.transform.position);

            start.z = 0;
            end.z   = 1;


            if (end.y - start.y > 100)
            {
                // avoid being zoomed out too much (creates too many objects)
                return;
            }

            Gizmos.matrix = scr.transform.localToWorldMatrix;


            Color blue = Color.blue;

            blue.a = 0.5f;

            Color red = Color.red;

            red.a = 0.5f;

            Color green = Color.green;

            red.a = 0.5f;

            if (room)
            {
                DrawRoom(scr);
            }
            else
            {
                foreach (Vector3Int position in new BoundsInt(start, end - start).allPositionsWithin)
                {
                    if (space)
                    {
                        if (scr.IsSpaceAt(position))
                        {
                            Gizmos.color = red;
                            Gizmos.DrawCube(position + new Vector3(0.5f, 0.5f, 0), Vector3.one);
                        }
                    }
                    else
                    {
                        if (corners)
                        {
                            if (scr.HasTile(position, LayerType.Walls))
                            {
                                Gizmos.color = green;

                                int corner_count = 0;
                                foreach (Vector3Int pos in new[] { Vector3Int.up, Vector3Int.left, Vector3Int.down, Vector3Int.right, Vector3Int.up })
                                {
                                    if (!scr.HasTile(position + pos, LayerType.Walls))
                                    {
                                        corner_count++;
                                    }
                                    else
                                    {
                                        corner_count = 0;
                                    }

                                    if (corner_count > 1)
                                    {
                                        Gizmos.DrawCube(position + new Vector3(0.5f, 0.5f, 0), Vector3.one);
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            Gizmos.color = blue;
                            if (passable)
                            {
                                if (north)
                                {
                                    if (!scr.IsPassableAt(position + Vector3Int.up, position))
                                    {
                                        Gizmos.DrawCube(position + new Vector3(0.5f, 0.5f, 0), Vector3.one);
                                    }
                                }
                                else if (south)
                                {
                                    if (!scr.IsPassableAt(position + Vector3Int.down, position))
                                    {
                                        Gizmos.DrawCube(position + new Vector3(0.5f, 0.5f, 0), Vector3.one);
                                    }
                                }
                                else if (!scr.IsPassableAt(position))
                                {
                                    Gizmos.DrawCube(position + new Vector3(0.5f, 0.5f, 0), Vector3.one);
                                }
                            }
                            else
                            {
                                if (!scr.IsAtmosPassableAt(position))
                                {
                                    Gizmos.DrawCube(position + new Vector3(0.5f, 0.5f, 0), Vector3.one);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 16
0
 public bool HasTile(Vector3Int position, bool isServer)
 {
     return(MetaTileMap.HasTile(position, isServer));
 }
Ejemplo n.º 17
0
 public bool IsWallAt(Vector3Int position, bool isServer)
 {
     return(MetaTileMap.HasTile(position, LayerType.Walls, isServer));
 }
Ejemplo n.º 18
0
 public bool IsWindowAt(Vector3Int position, bool isServer)
 {
     return(MetaTileMap.HasTile(position, LayerType.Windows));
 }
Ejemplo n.º 19
0
    private void DoBulletDamage(BulletBehaviour bullet, Vector3 forceDir, Vector3 hitPos)
    {
        forceDir.z = 0;
        Vector3      bulletHitTarget = hitPos + (forceDir * 0.2f);
        Vector3Int   cellPos         = metaTileMap.WorldToCell(Vector3Int.RoundToInt(bulletHitTarget));
        MetaDataNode data            = metaDataLayer.Get(cellPos);

        if (Layer.LayerType == LayerType.Windows)
        {
            LayerTile getTile = metaTileMap.GetTile(cellPos, LayerType.Windows);
            if (getTile != null)
            {
                //TODO damage amt based off type of bullet
                AddWindowDamage(bullet.damage, data, cellPos, bulletHitTarget, AttackType.Bullet);
                return;
            }
        }

        if (Layer.LayerType == LayerType.Grills)
        {
            //Make sure a window is not protecting it first:
            if (!metaTileMap.HasTile(cellPos, LayerType.Windows, true))
            {
                if (metaTileMap.HasTile(cellPos, LayerType.Grills, true))
                {
                    //TODO damage amt based off type of bullet
                    AddGrillDamage(bullet.damage, data, cellPos, bulletHitTarget, AttackType.Bullet);
                }
            }
        }
        if (bullet.isMiningBullet)
        {
            if (Layer.LayerType == LayerType.Walls)
            {
                LayerTile getTile = metaTileMap.GetTile(cellPos, LayerType.Walls);
                if (getTile != null)
                {
                    if (Validations.IsMineableAt(bulletHitTarget, metaTileMap))
                    {
                        SoundManager.PlayNetworkedAtPos("BreakStone", bulletHitTarget);
                        var tile = getTile as BasicTile;
                        Spawn.ServerPrefab(tile.SpawnOnDeconstruct, bulletHitTarget, count: tile.SpawnAmountOnDeconstruct);
                        tileChangeManager.RemoveTile(cellPos, LayerType.Walls);
                    }
                }
            }
        }
    }
Ejemplo n.º 20
0
 public bool HasTile(Vector3Int position)
 {
     return(metaTileMap.HasTile(position));
 }