"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.levelHasRoomType = exports.levelHasBossID = exports.getLevelBossIDs = exports.fillLevelWithRedRooms = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const cachedEnumValues_1 = require("../arrays/cachedEnumValues");
const cachedClasses_1 = require("../core/cachedClasses");
const array_1 = require("./array");
const levelGrid_1 = require("./levelGrid");
const rooms_1 = require("./rooms");
/** Helper function to fill every possible level grid square with a red room. */
function fillLevelWithRedRooms() {
    const level = cachedClasses_1.game.GetLevel();
    let numRoomsInGrid;
    do {
        const roomsInGrid = (0, rooms_1.getRoomsInsideGrid)();
        numRoomsInGrid = roomsInGrid.length;
        for (const roomDescriptor of roomsInGrid) {
            for (const doorSlot of cachedEnumValues_1.DOOR_SLOT_VALUES) {
                if ((0, levelGrid_1.isDoorSlotValidAtGridIndexForRedRoom)(doorSlot, roomDescriptor.GridIndex)) {
                    level.MakeRedRoomDoor(roomDescriptor.GridIndex, doorSlot);
                }
            }
        }
    } while (numRoomsInGrid !== (0, rooms_1.getNumRooms)());
}
exports.fillLevelWithRedRooms = fillLevelWithRedRooms;
/**
 * Helper function to get the boss IDs of all of the Boss Rooms on this floor. (This is equivalent
 * to the sub-type of the room data.)
 *
 * Note that this will only look at Boss Rooms inside of the grid, so e.g. Reverse Emperor card
 * rooms will not count.
 */
function getLevelBossIDs() {
    const roomsInsideGrid = (0, rooms_1.getRoomsInsideGrid)();
    return (0, array_1.filterMap)(roomsInsideGrid, (roomDescriptor) => roomDescriptor.Data !== undefined &&
        roomDescriptor.Data.Type === isaac_typescript_definitions_1.RoomType.BOSS &&
        roomDescriptor.Data.StageID === isaac_typescript_definitions_1.StageID.SPECIAL_ROOMS
        ? roomDescriptor.Data.Subtype
        : undefined);
}
exports.getLevelBossIDs = getLevelBossIDs;
/**
 * Helper function to check if the current floor has a Boss Room that matches the boss ID provided.
 *
 * This function is variadic, meaning that you can pass as many boss IDs as you want to check for.
 * It will return true if one or more of the boss IDs are matched.
 */
function levelHasBossID(...bossIDs) {
    const levelBossIDs = getLevelBossIDs();
    const levelBossIDsSet = new Set(levelBossIDs);
    return bossIDs.some((bossID) => levelBossIDsSet.has(bossID));
}
exports.levelHasBossID = levelHasBossID;
/**
 * Helper function to check to see if the current floor has one or more of a specific room type in
 * it.
 *
 * This function is variadic, meaning that you can pass as many room types as you want to check for.
 * This function will return true if any of the room types are found.
 */
function levelHasRoomType(...roomTypes) {
    const roomDescriptors = (0, levelGrid_1.getRoomDescriptorsForType)(...roomTypes);
    return roomDescriptors.length > 0;
}
exports.levelHasRoomType = levelHasRoomType;
