Example #1
0
        private void PlaceRandomAlarmMushrooms(Dungeon dungeon, RoomHandler currentRoom, int RandomObjectsPlaced, int RandomObjectsSkipped)
        {
            PrototypeDungeonRoom.RoomCategory roomCategory = currentRoom.area.PrototypeRoomCategory;

            if (currentRoom == null | roomCategory == PrototypeDungeonRoom.RoomCategory.REWARD | string.IsNullOrEmpty(currentRoom.GetRoomName()) |
                currentRoom.GetRoomName().StartsWith("Boss Foyer") | currentRoom.IsMaintenanceRoom() |
                !currentRoom.HasActiveEnemies(RoomHandler.ActiveEnemyType.RoomClear))
            {
                return;
            }

            if (currentRoom != null && !string.IsNullOrEmpty(currentRoom.GetRoomName()) && !currentRoom.IsMaintenanceRoom() &&
                !currentRoom.GetRoomName().StartsWith("Boss Foyer") && currentRoom.RoomVisualSubtype == 0)
            {
                if (Random.value <= 0.6f)
                {
                    List <IntVector2> m_CachedPositions = new List <IntVector2>();
                    int MinMushroomCount = 2;
                    int MaxMushroomCount = 6;
                    if (Random.value <= 0.3f)
                    {
                        MinMushroomCount = 6;
                        MaxMushroomCount = 12;
                    }
                    else if (roomCategory == PrototypeDungeonRoom.RoomCategory.BOSS)
                    {
                        MaxMushroomCount = 10;
                    }

                    int X = currentRoom.area.dimensions.x;
                    int Y = currentRoom.area.dimensions.y;

                    if (X * Y < 100)
                    {
                        MinMushroomCount = 1;
                        MaxMushroomCount = 3;
                    }

                    int MushroomCount = Random.Range(MinMushroomCount, MaxMushroomCount);

                    for (int i = 0; i < MushroomCount; i++)
                    {
                        IntVector2?RandomVector = GetRandomAvailableCell(dungeon, currentRoom, m_CachedPositions, ExitClearence: 3, avoidExits: true, PositionRelativeToRoom: true);

                        if (RandomVector.HasValue)
                        {
                            GameObject alarmMushroomObject = ExpandPrefabs.EXAlarmMushroom.GetComponent <ExpandAlarmMushroomPlacable>().InstantiateObject(currentRoom, RandomVector.Value, true);
                            alarmMushroomObject.transform.parent = currentRoom.hierarchyParent;
                            ExpandAlarmMushroomPlacable m_AlarmMushRoomPlacable = ExpandPrefabs.EXAlarmMushroom.GetComponent <ExpandAlarmMushroomPlacable>();
                            m_AlarmMushRoomPlacable.ConfigureOnPlacement(currentRoom);
                            RandomObjectsPlaced++;
                            if (m_CachedPositions.Count <= 0)
                            {
                                break;
                            }
                        }
                        else
                        {
                            RandomObjectsSkipped++;
                        }
                    }
                }
            }
        }
        private static void PlaceRandomAlarmMushrooms(Dungeon dungeon, RoomHandler currentRoom)
        {
            PrototypeDungeonRoom.RoomCategory roomCategory = currentRoom.area.PrototypeRoomCategory;

            if (currentRoom == null | roomCategory == PrototypeDungeonRoom.RoomCategory.REWARD | string.IsNullOrEmpty(currentRoom.GetRoomName()) |
                currentRoom.GetRoomName().StartsWith("Boss Foyer") | currentRoom.IsMaintenanceRoom() |
                !currentRoom.HasActiveEnemies(RoomHandler.ActiveEnemyType.RoomClear) | roomCategory == PrototypeDungeonRoom.RoomCategory.BOSS)
            {
                return;
            }
            if (DebugMode)
            {
                Debug.Log("[ExpandTheGungeon] Checking room for valid Mushroom locations... ");
            }
            if (currentRoom != null && !string.IsNullOrEmpty(currentRoom.GetRoomName()) && !currentRoom.IsMaintenanceRoom() &&
                !currentRoom.GetRoomName().StartsWith("Boss Foyer"))
            {
                if (Random.value <= 0.6f)
                {
                    List <IntVector2> m_CachedPositions = new List <IntVector2>();
                    int MinMushroomCount = 2;
                    int MaxMushroomCount = 6;
                    if (Random.value <= 0.3f)
                    {
                        MinMushroomCount = 6;
                        MaxMushroomCount = 12;
                    }

                    int X = currentRoom.area.dimensions.x;
                    int Y = currentRoom.area.dimensions.y;

                    if (X * Y < 100)
                    {
                        MinMushroomCount = 1;
                        MaxMushroomCount = 3;
                    }

                    int MushroomCount = Random.Range(MinMushroomCount, MaxMushroomCount);

                    for (int i = 0; i < MushroomCount; i++)
                    {
                        if (DebugMode)
                        {
                            Debug.Log("[ExpandTheGungeon] Test Mushroom Iteration: " + i.ToString());
                        }
                        if (DebugMode)
                        {
                            if (!string.IsNullOrEmpty(currentRoom.GetRoomName()))
                            {
                                ETGModConsole.Log("[ExpandTheGungeon] On Room: " + currentRoom.GetRoomName());
                            }
                        }

                        IntVector2?RandomVector = GetRandomAvailableCell(dungeon, currentRoom, m_CachedPositions, 1, 4, avoidExits: true, PositionRelativeToRoom: true);

                        if (RandomVector.HasValue)
                        {
                            if (DebugMode)
                            {
                                ETGModConsole.Log("[ExpandTheGungeon] Valid Location found. Placing Mushroom...");
                            }
                            try {
                                GameObject alarmMushroomObject = ExpandPrefabs.EXAlarmMushroom.GetComponent <ExpandAlarmMushroomPlacable>().InstantiateObject(currentRoom, RandomVector.Value, true);
                                alarmMushroomObject.transform.parent = currentRoom.hierarchyParent;
                                ExpandAlarmMushroomPlacable m_AlarmMushRoomPlacable = ExpandPrefabs.EXAlarmMushroom.GetComponent <ExpandAlarmMushroomPlacable>();
                                m_AlarmMushRoomPlacable.ConfigureOnPlacement(currentRoom);
                            } catch (System.Exception ex) {
                                if (DebugMode)
                                {
                                    ETGModConsole.Log("[ExpandTheGungeon] Exception While placing/configuring mushroom!", DebugMode);
                                    Debug.LogException(ex);
                                }
                            }
                            RandomObjectsPlaced++;
                            if (DebugMode)
                            {
                                Debug.Log("[ExpandTheGungeon] Mushroom successfully placed!");
                            }
                            if (m_CachedPositions.Count <= 0)
                            {
                                break;
                            }
                        }
                        else
                        {
                            if (DebugMode)
                            {
                                Debug.Log("[ExpandTheGungeon] No valid cells found. Mushroom skipped!");
                            }
                            RandomObjectsSkipped++;
                        }
                    }
                }
            }
        }