"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isTransformationFlying = exports.hasFlyingTransformation = exports.getTransformationsForCollectibleType = exports.getTransformationName = exports.getPlayerTransformations = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const cachedEnumValues_1 = require("../cachedEnumValues");
const transformationNames_1 = require("../objects/transformationNames");
const ReadonlyMap_1 = require("../types/ReadonlyMap");
const ReadonlySet_1 = require("../types/ReadonlySet");
const collectibles_1 = require("./collectibles");
const flag_1 = require("./flag");
const TRANSFORMATION_TO_TAG_MAP = new ReadonlyMap_1.ReadonlyMap([
    [isaac_typescript_definitions_1.PlayerForm.GUPPY, isaac_typescript_definitions_1.ItemConfigTag.GUPPY],
    [isaac_typescript_definitions_1.PlayerForm.BEELZEBUB, isaac_typescript_definitions_1.ItemConfigTag.FLY],
    [isaac_typescript_definitions_1.PlayerForm.FUN_GUY, isaac_typescript_definitions_1.ItemConfigTag.MUSHROOM],
    [isaac_typescript_definitions_1.PlayerForm.SERAPHIM, isaac_typescript_definitions_1.ItemConfigTag.ANGEL],
    [isaac_typescript_definitions_1.PlayerForm.BOB, isaac_typescript_definitions_1.ItemConfigTag.BOB],
    [isaac_typescript_definitions_1.PlayerForm.SPUN, isaac_typescript_definitions_1.ItemConfigTag.SYRINGE],
    [isaac_typescript_definitions_1.PlayerForm.YES_MOTHER, isaac_typescript_definitions_1.ItemConfigTag.MOM],
    [isaac_typescript_definitions_1.PlayerForm.CONJOINED, isaac_typescript_definitions_1.ItemConfigTag.BABY],
    [isaac_typescript_definitions_1.PlayerForm.LEVIATHAN, isaac_typescript_definitions_1.ItemConfigTag.DEVIL],
    [isaac_typescript_definitions_1.PlayerForm.OH_CRAP, isaac_typescript_definitions_1.ItemConfigTag.POOP],
    [isaac_typescript_definitions_1.PlayerForm.BOOKWORM, isaac_typescript_definitions_1.ItemConfigTag.BOOK],
    // PlayerForm.ADULTHOOD (11) is based on pill usage.
    [isaac_typescript_definitions_1.PlayerForm.SPIDER_BABY, isaac_typescript_definitions_1.ItemConfigTag.SPIDER], // 12
    // PlayerForm.STOMPY (13) is based on size.
]);
const TRANSFORMATIONS_THAT_GRANT_FLYING = new ReadonlySet_1.ReadonlySet([
    isaac_typescript_definitions_1.PlayerForm.GUPPY,
    isaac_typescript_definitions_1.PlayerForm.BEELZEBUB,
    isaac_typescript_definitions_1.PlayerForm.SERAPHIM,
    isaac_typescript_definitions_1.PlayerForm.LEVIATHAN, // 8
]);
/** Returns a set of the player's current transformations. */
function getPlayerTransformations(player) {
    const transformations = new Set();
    for (const playerForm of cachedEnumValues_1.PLAYER_FORM_VALUES) {
        if (player.HasPlayerForm(playerForm)) {
            transformations.add(playerForm);
        }
    }
    return transformations;
}
exports.getPlayerTransformations = getPlayerTransformations;
/**
 * Helper function to get a transformation name from a PlayerForm enum.
 *
 * For example:
 *
 * ```ts
 * const transformationName = getTransformationName(PlayerForm.LORD_OF_THE_FLIES);
 * // transformationName is "Beelzebub"
 * ```
 */
function getTransformationName(playerForm) {
    return transformationNames_1.TRANSFORMATION_NAMES[playerForm];
}
exports.getTransformationName = getTransformationName;
/**
 * Returns a set containing all of the transformations that the given collectible types contribute
 * towards.
 */
function getTransformationsForCollectibleType(collectibleType) {
    const itemConfigTags = (0, collectibles_1.getCollectibleTags)(collectibleType);
    const transformationSet = new Set();
    for (const playerForm of cachedEnumValues_1.PLAYER_FORM_VALUES) {
        const itemConfigTag = TRANSFORMATION_TO_TAG_MAP.get(playerForm);
        if (itemConfigTag === undefined) {
            continue;
        }
        if ((0, flag_1.hasFlag)(itemConfigTags, itemConfigTag)) {
            transformationSet.add(playerForm);
        }
    }
    return transformationSet;
}
exports.getTransformationsForCollectibleType = getTransformationsForCollectibleType;
function hasFlyingTransformation(player) {
    for (const playerForm of TRANSFORMATIONS_THAT_GRANT_FLYING) {
        if (player.HasPlayerForm(playerForm)) {
            return true;
        }
    }
    return false;
}
exports.hasFlyingTransformation = hasFlyingTransformation;
function isTransformationFlying(playerForm) {
    return TRANSFORMATIONS_THAT_GRANT_FLYING.has(playerForm);
}
exports.isTransformationFlying = isTransformationFlying;
