"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useCardTemp = exports.isVanillaCardType = exports.isValidCardType = exports.isTarotCard = exports.isSuitCard = exports.isSpecialCard = exports.isRune = exports.isReverseTarotCard = exports.isPocketItemObject = exports.isModdedCardType = exports.isCardType = exports.isCard = exports.hasCard = exports.getItemConfigCardType = exports.getCardName = exports.getCardDescription = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const cachedEnumValues_1 = require("../cachedEnumValues");
const cachedClasses_1 = require("../core/cachedClasses");
const constantsFirstLast_1 = require("../core/constantsFirstLast");
const cardDescriptions_1 = require("../objects/cardDescriptions");
const cardNames_1 = require("../objects/cardNames");
const itemConfigCardTypesForCards_1 = require("../sets/itemConfigCardTypesForCards");
const flag_1 = require("./flag");
const types_1 = require("./types");
/**
 * Helper function to get a card description from a `CardType` value. Returns "Unknown" if the
 * provided card type is not valid.
 *
 * This function works for both vanilla and modded trinkets.
 *
 * For example, `getCardDescription(CardType.FOOL)` would return "Where journey begins".
 */
function getCardDescription(cardType) {
    // "ItemConfigCard.Description" is bugged with vanilla cards on patch v1.7.6, so we use a
    // hard-coded map as a workaround.
    const cardDescription = cardDescriptions_1.CARD_DESCRIPTIONS[cardType];
    // Handle modded cards.
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
    if (cardDescription !== undefined) {
        return cardDescription;
    }
    const itemConfigCard = cachedClasses_1.itemConfig.GetCard(cardType);
    if (itemConfigCard !== undefined) {
        return itemConfigCard.Description;
    }
    return cardDescriptions_1.DEFAULT_CARD_DESCRIPTION;
}
exports.getCardDescription = getCardDescription;
/**
 * Helper function to get the name of a card. Returns "Unknown" if the provided card type is not
 * valid.
 *
 * This function works for both vanilla and modded trinkets.
 *
 * For example, `getCardName(Card.FOOL)` would return "0 - The Fool".
 */
function getCardName(cardType) {
    // "ItemConfigCard.Name" is bugged with vanilla cards on patch v1.7.6, so we use a hard-coded map
    // as a workaround.
    const cardName = cardNames_1.CARD_NAMES[cardType];
    // Handle modded cards.
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
    if (cardName !== undefined) {
        return cardName;
    }
    const itemConfigCard = cachedClasses_1.itemConfig.GetCard(cardType);
    if (itemConfigCard !== undefined) {
        return itemConfigCard.Name;
    }
    return cardNames_1.DEFAULT_CARD_NAME;
}
exports.getCardName = getCardName;
/**
 * Helper function to get the item config card type of a particular card, rune, or object. For
 * example, the item config card type of `CardType.FOOL` is equal to `ItemConfigCardType.TAROT`.
 *
 * Returns undefined if the provided card type was not valid.
 */
function getItemConfigCardType(cardType) {
    const itemConfigCard = cachedClasses_1.itemConfig.GetCard(cardType);
    if (itemConfigCard === undefined) {
        return undefined;
    }
    return itemConfigCard.CardType;
}
exports.getItemConfigCardType = getItemConfigCardType;
/**
 * Helper function to check if a player is holding a specific card in one of their pocket item
 * slots.
 *
 * This function is variadic, meaning that you can pass as many cards as you want to check for. The
 * function will return true if the player has any of the cards.
 */
function hasCard(player, ...cardTypes) {
    const cardTypesSet = new Set(cardTypes);
    return cachedEnumValues_1.POCKET_ITEM_SLOT_VALUES.some((pocketItemSlot) => {
        const cardType = player.GetCard(pocketItemSlot);
        return cardTypesSet.has(cardType);
    });
}
exports.hasCard = hasCard;
/**
 * Returns true for card types that have the following item config card type:
 *
 * - `ItemConfigCardType.TAROT` (0)
 * - `ItemConfigCardType.SUIT` (1)
 * - `ItemConfigCardType.SPECIAL` (3)
 * - `ItemConfigCardType.TAROT_REVERSE` (5)
 */
function isCard(cardType) {
    const itemConfigCardType = getItemConfigCardType(cardType);
    if (itemConfigCardType === undefined) {
        return false;
    }
    return itemConfigCardTypesForCards_1.ITEM_CONFIG_CARD_TYPES_FOR_CARDS.has(itemConfigCardType);
}
exports.isCard = isCard;
/** Returns whether the given card type matches the specified item config card type. */
function isCardType(cardType, itemConfigCardType) {
    return itemConfigCardType === getItemConfigCardType(cardType);
}
exports.isCardType = isCardType;
/** Returns true for any card type added by a mod. */
function isModdedCardType(cardType) {
    return !isVanillaCardType(cardType);
}
exports.isModdedCardType = isModdedCardType;
/** Returns true for card types that have `ItemConfigCardType.SPECIAL_OBJECT`. */
function isPocketItemObject(cardType) {
    return isCardType(cardType, isaac_typescript_definitions_1.ItemConfigCardType.SPECIAL_OBJECT);
}
exports.isPocketItemObject = isPocketItemObject;
/** Returns true for card types that have `ItemConfigCardType.TAROT_REVERSE`. */
function isReverseTarotCard(cardType) {
    return isCardType(cardType, isaac_typescript_definitions_1.ItemConfigCardType.TAROT_REVERSE);
}
exports.isReverseTarotCard = isReverseTarotCard;
/** Returns true for card types that have `ItemConfigCardType.RUNE`. */
function isRune(cardType) {
    return isCardType(cardType, isaac_typescript_definitions_1.ItemConfigCardType.RUNE);
}
exports.isRune = isRune;
/** Returns true for card types that have `ItemConfigCardType.SPECIAL`. */
function isSpecialCard(cardType) {
    return isCardType(cardType, isaac_typescript_definitions_1.ItemConfigCardType.SPECIAL);
}
exports.isSpecialCard = isSpecialCard;
/** Returns true for card types that have `ItemConfigCardType.SUIT`. */
function isSuitCard(cardType) {
    return isCardType(cardType, isaac_typescript_definitions_1.ItemConfigCardType.SUIT);
}
exports.isSuitCard = isSuitCard;
/** Returns true for card types that have `ItemConfigCardType.TAROT`. */
function isTarotCard(cardType) {
    return isCardType(cardType, isaac_typescript_definitions_1.ItemConfigCardType.TAROT);
}
exports.isTarotCard = isTarotCard;
function isValidCardType(cardType) {
    const potentialCardType = (0, types_1.asCardType)(cardType);
    const itemConfigCard = cachedClasses_1.itemConfig.GetCard(potentialCardType);
    return itemConfigCard !== undefined;
}
exports.isValidCardType = isValidCardType;
function isVanillaCardType(cardType) {
    return cardType <= constantsFirstLast_1.LAST_VANILLA_CARD_TYPE;
}
exports.isVanillaCardType = isVanillaCardType;
/**
 * Helper function to use a card without showing an animation and without the announcer voice
 * playing.
 */
function useCardTemp(player, cardType) {
    const useFlags = (0, flag_1.addFlag)(isaac_typescript_definitions_1.UseFlag.NO_ANIMATION, isaac_typescript_definitions_1.UseFlag.NO_ANNOUNCER_VOICE);
    player.UseCard(cardType, useFlags);
}
exports.useCardTemp = useCardTemp;
