private void PlaceSecretRatGrateInternal(Dungeon dungeon, DungeonPlaceableBehaviour prefabPlaceable, IntVector2 dimensions, Vector2 offset)
        {
            List <IntVector2> list = new List <IntVector2>();

            for (int i = 0; i < dungeon.data.rooms.Count; i++)
            {
                RoomHandler roomHandler = dungeon.data.rooms[i];
                if (!roomHandler.area.IsProceduralRoom && roomHandler.area.PrototypeRoomCategory == PrototypeDungeonRoom.RoomCategory.NORMAL && !roomHandler.OptionalDoorTopDecorable && !roomHandler.area.prototypeRoom.UseCustomMusic)
                {
                    for (int j = roomHandler.area.basePosition.x; j < roomHandler.area.basePosition.x + roomHandler.area.dimensions.x; j++)
                    {
                        for (int k = roomHandler.area.basePosition.y; k < roomHandler.area.basePosition.y + roomHandler.area.dimensions.y; k++)
                        {
                            if (ClearForRatGrate(dungeon, dimensions.x, dimensions.y, j, k))
                            {
                                list.Add(new IntVector2(j, k));
                            }
                        }
                    }
                }
            }
            if (list.Count > 0)
            {
                IntVector2  a            = list[BraveRandom.GenerationRandomRange(0, list.Count)];
                RoomHandler absoluteRoom = a.ToVector2().GetAbsoluteRoom();
                GameObject  gameObject   = prefabPlaceable.InstantiateObject(absoluteRoom, a - absoluteRoom.area.basePosition, true);
                gameObject.AddComponent <ChaosGlitchTrapDoor>();
                gameObject.transform.position = gameObject.transform.position + offset.ToVector3ZUp(0f);
                ChaosGlitchTrapDoor glitchTrapDoor = gameObject.GetComponent <ChaosGlitchTrapDoor>();
                glitchTrapDoor.ConfigureOnPlacement(absoluteRoom);
                for (int m = 0; m < dimensions.x; m++)
                {
                    for (int n = 0; n < dimensions.y; n++)
                    {
                        IntVector2 intVector = a + new IntVector2(m, n);
                        if (dungeon.data.CheckInBoundsAndValid(intVector))
                        {
                            dungeon.data[intVector].cellVisualData.floorTileOverridden = true;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void AddObjectToRoom(PrototypeDungeonRoom room, Vector2 position, DungeonPlaceable PlacableContents = null, DungeonPlaceableBehaviour NonEnemyBehaviour = null, string EnemyBehaviourGuid = null, float SpawnChance = 1f, int xOffset = 0, int yOffset = 0, int layer = 0)
        {
            if (room == null)
            {
                return;
            }
            if (room.placedObjects == null)
            {
                room.placedObjects = new List <PrototypePlacedObjectData>();
            }
            if (room.placedObjectPositions == null)
            {
                room.placedObjectPositions = new List <Vector2>();
            }

            PrototypePlacedObjectData m_NewObjectData = new PrototypePlacedObjectData()
            {
                placeableContents    = null,
                nonenemyBehaviour    = null,
                spawnChance          = SpawnChance,
                unspecifiedContents  = null,
                enemyBehaviourGuid   = string.Empty,
                contentsBasePosition = position,
                layer                 = layer,
                xMPxOffset            = xOffset,
                yMPxOffset            = yOffset,
                fieldData             = new List <PrototypePlacedObjectFieldData>(0),
                instancePrerequisites = new DungeonPrerequisite[0],
                linkedTriggerAreaIDs  = new List <int>(0),
                assignedPathIDx       = -1,
                assignedPathStartNode = 0
            };

            if (PlacableContents != null)
            {
                m_NewObjectData.placeableContents = PlacableContents;
            }
            else if (NonEnemyBehaviour != null)
            {
                m_NewObjectData.nonenemyBehaviour = NonEnemyBehaviour;
            }
            else if (EnemyBehaviourGuid != null)
            {
                m_NewObjectData.enemyBehaviourGuid = EnemyBehaviourGuid;
            }
            else
            {
                // All possible object fields were left null? Do nothing and return if this is the case.
                return;
            }

            room.placedObjects.Add(m_NewObjectData);
            room.placedObjectPositions.Add(position);
            return;
        }