Exemplo n.º 1
0
        public override void Initialize()
        {
            if (!CustomNetworkManager.IsServer)
            {
                return;
            }

            //We have bool to stop null checks on every pos
            var hasCustomMix = defaultRoomGasMixOverride != null;

            foreach (var gasSetter in GetComponentsInChildren <RoomGasSetter>())
            {
                gasSetter.SetUp();
            }

            BoundsInt bounds = metaTileMap.GetBounds();

            foreach (Vector3Int position in bounds.allPositionsWithin)
            {
                //Get top tile at pos to check if it should spawn with no air
                bool spawnWithNoAir = false;

                var topTile = metaTileMap.GetTile(position, LayerTypeSelection.Effects | LayerTypeSelection.Underfloor);
                if (topTile is BasicTile tile)
                {
                    spawnWithNoAir = tile.SpawnWithNoAir;
                }

                MetaDataNode node = metaDataLayer.Get(position, false);
                if ((node.IsRoom || node.IsOccupied) && !spawnWithNoAir)
                {
                    //Check to see if theres a special room mix
                    if (toSet.Count > 0 && toSet.TryGetValue(node.RoomNumber, out var gasSetter))
                    {
                        node.GasMix = GasMix.NewGasMix(gasSetter.GasMixToSpawn);
                    }
                    //See if the whole matrix has a custom mix
                    else if (hasCustomMix)
                    {
                        node.GasMix = GasMix.NewGasMix(defaultRoomGasMixOverride.BaseGasMix);
                    }
                    //Default to air mix otherwise
                    else
                    {
                        node.GasMix = GasMix.NewGasMix(GasMixes.BaseAirMix);
                    }
                }
                else
                {
                    node.GasMix = GasMix.NewGasMix(GasMixes.BaseSpaceMix);
                }
            }

            foreach (var gasSetter in toSet)
            {
                _ = Despawn.ServerSingle(gasSetter.Value.gameObject);
            }

            toSet.Clear();
        }
Exemplo n.º 2
0
        public override void Initialize()
        {
            if (!CustomNetworkManager.IsServer)
            {
                return;
            }

            BoundsInt bounds = metaTileMap.GetBounds();

            foreach (Vector3Int position in bounds.allPositionsWithin)
            {
                //get toptile at pos to check if it should spawn with no air
                bool spawnWithNoAir = false;
                var  topTile        = metaTileMap.GetTile(position, LayerTypeSelection.Effects | LayerTypeSelection.Underfloor);
                if (topTile is BasicTile tile)
                {
                    spawnWithNoAir = tile.SpawnWithNoAir;
                }
                MetaDataNode node = metaDataLayer.Get(position, false);
                if ((node.IsRoom || node.IsOccupied) && !spawnWithNoAir)
                {
                    node.GasMix = GasMix.NewGasMix(GasMixes.BaseAirMix);
                }
                else
                {
                    node.GasMix = GasMix.NewGasMix(GasMixes.BaseSpaceMix);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Use to set a rooms gas after the round has started, otherwise do it in the initialisation
        /// </summary>
        /// <param name="roomNumber">Room number to fill</param>
        /// <param name="gasMixToUse">GasMix to fill room with</param>
        public void SetRoomGas(int roomNumber, GasMix gasMixToUse)
        {
            BoundsInt bounds = metaTileMap.GetBounds();

            foreach (Vector3Int position in bounds.allPositionsWithin)
            {
                MetaDataNode node = metaDataLayer.Get(position, false);
                if (node.IsRoom && node.RoomNumber == roomNumber)
                {
                    node.GasMix = GasMix.NewGasMix(gasMixToUse);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Use to set a rooms gas after the round has started, otherwise do it in the initialisation
        /// </summary>
        /// <param name="roomNumber">Room number to fill</param>
        /// <param name="gasMixToUse">GasMix to fill room with</param>
        public void SetRoomGas(int roomNumber, GasMix gasMixToUse)
        {
            var bounds = metaTileMap.GetLocalBounds();

            foreach (Vector3Int position in bounds.allPositionsWithin())
            {
                MetaDataNode node = metaDataLayer.Get(position, false);
                if (node.IsRoom && node.RoomNumber == roomNumber)
                {
                    //Use ChangeGasMix to remove old gas overlays and add new overlays
                    node.ChangeGasMix(GasMix.NewGasMix(gasMixToUse));
                }
            }
        }
Exemplo n.º 5
0
        public void OnSpawnServer(SpawnInfo info)
        {
            if (CustomNetworkManager.IsServer == false)
            {
                return;
            }

            var metaDataNode = registerTile.Matrix.GetMetaDataNode(registerTile.LocalPositionServer, false);

            if (metaDataNode == null)
            {
                return;
            }

            if (GameManager.Instance.CurrentRoundState != RoundState.Started)
            {
                return;
            }

            if (gasMixToSpawn == null)
            {
                Logger.LogError($"Gas mix was null on {gameObject.ExpensiveName()}");
                return;
            }

            if (metaDataNode.RoomNumber != -1)
            {
                //This only happens after round has started, for spawned in room gas setters during the round
                registerTile.Matrix.OrNull()?.GetComponentInParent <AtmosSystem>().OrNull()?.SetRoomGas(metaDataNode.RoomNumber, GasMixToSpawn);
            }
            else if (metaDataNode.IsOccupied)
            {
                //Use ChangeGasMix to remove old gas overlays and add new overlays
                metaDataNode.ChangeGasMix(GasMix.NewGasMix(GasMixToSpawn));
            }

            _ = Despawn.ServerSingle(gameObject);
        }
Exemplo n.º 6
0
        public override void Initialize()
        {
            //We have bool to stop null checks on every pos
            var hasCustomMix = defaultRoomGasMixOverride != null;

            foreach (var gasSetter in GetComponentsInChildren <RoomGasSetter>())
            {
                gasSetter.SetUp();
            }

            var bounds = metaTileMap.GetLocalBounds();

            foreach (Vector3Int position in bounds.allPositionsWithin())
            {
                //Get top tile at pos to check if it should spawn with no air
                bool spawnWithNoAir = false;

                var topTile = metaTileMap.GetTile(position, LayerTypeSelection.Effects | LayerTypeSelection.Underfloor);
                if (topTile is BasicTile tile)
                {
                    spawnWithNoAir = tile.SpawnWithNoAir;
                }

                MetaDataNode node = metaDataLayer.Get(position, false);
                if ((node.IsRoom || node.IsOccupied) && !spawnWithNoAir)
                {
                    //Check to see if theres a special room mix
                    if (node.IsRoom && toSetRoom.Count > 0 && toSetRoom.TryGetValue(node.RoomNumber, out var roomGasSetter))
                    {
                        //We use ChangeGasMix here incase we need to add overlays, while the BaseAirMix and BaseSpaceMix can set directly since none of the gases in them do
                        //Does come with a performance penalty
                        //node.ChangeGasMix(GasMix.NewGasMix(gasSetter.GasMixToSpawn));

                        //TODO: above commented out due to performance on load for lavaland, remove line below if solution is found
                        node.GasMix = GasMix.NewGasMix(roomGasSetter.GasMixToSpawn);
                    }
                    //Check to see if theres a special occupied mix
                    else if (node.IsOccupied && toSetOccupied.Count > 0 && toSetOccupied.TryGetValue(position, out var occupiedGasSetter))
                    {
                        //We use ChangeGasMix here incase we need to add overlays, while the BaseAirMix and BaseSpaceMix can set directly since none of the gases in them do
                        //Does come with a performance penalty
                        //node.ChangeGasMix(GasMix.NewGasMix(gasSetter.GasMixToSpawn));

                        //TODO: above commented out due to performance on load for lavaland, remove line below if solution is found
                        node.GasMix = GasMix.NewGasMix(occupiedGasSetter.GasMixToSpawn);
                    }
                    //See if the whole matrix has a custom mix
                    else if (hasCustomMix)
                    {
                        //ChangeGasMix here too for the same reason as above
                        //node.ChangeGasMix(GasMix.NewGasMix(defaultRoomGasMixOverride.BaseGasMix));

                        //TODO: above commented out due to performance on load for lavaland, remove line below if solution is found
                        node.GasMix = GasMix.NewGasMix(defaultRoomGasMixOverride.BaseGasMix);
                    }
                    //Default to air mix otherwise
                    else
                    {
                        node.GasMix = GasMix.NewGasMix(GasMixes.BaseAirMix);
                    }
                }
                else
                {
                    node.GasMix = GasMix.NewGasMix(GasMixes.BaseSpaceMix);
                }
            }

            foreach (var gasSetter in toSetRoom)
            {
                _ = Despawn.ServerSingle(gasSetter.Value.gameObject);
            }

            foreach (var gasSetter in toSetOccupied)
            {
                _ = Despawn.ServerSingle(gasSetter.Value.gameObject);
            }

            toSetRoom.Clear();
            toSetOccupied.Clear();
        }