"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setChallenge = exports.onChallenge = exports.onAnyChallenge = exports.getChallengeTrinketType = exports.getChallengeName = exports.getChallengeCollectibleTypes = exports.getChallengeCharacter = exports.getChallengeBoss = exports.clearChallenge = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const challengeBosses_1 = require("../objects/challengeBosses");
const challengeCharacters_1 = require("../objects/challengeCharacters");
const challengeCollectibleTypes_1 = require("../objects/challengeCollectibleTypes");
const challengeNames_1 = require("../objects/challengeNames");
const challengeTrinketType_1 = require("../objects/challengeTrinketType");
const log_1 = require("./log");
/**
 * Helper function to clear the current challenge, which will restart the run on a new random
 * non-challenge seed with the current character.
 *
 * If the player is not in a challenge already, this function will do nothing.
 *
 * Under the hood, this function executes the `challenge 0` console command.
 */
function clearChallenge() {
    if (onAnyChallenge()) {
        const command = `challenge ${isaac_typescript_definitions_1.Challenge.NULL}`;
        (0, log_1.log)(`Restarting the run to clear the current challenge with a console command of: ${command}`);
        Isaac.ExecuteCommand(command);
    }
}
exports.clearChallenge = clearChallenge;
/**
 * Get the final boss of a challenge. This will only work for vanilla challenges.
 *
 * For modded challenges, `BossID.MOM` (6) will be returned.
 *
 * Note that for `Challenge.BACKASSWARDS` (31), this function will return `BossID.MEGA_SATAN` (55),
 * but this is not actually the final boss. (There is no final boss for this challenge.)
 */
function getChallengeBoss(challenge) {
    const challengeBossID = challengeBosses_1.CHALLENGE_BOSSES[challenge];
    // Handle modded challenges.
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
    return challengeBossID ?? challengeBosses_1.DEFAULT_CHALLENGE_BOSS_ID;
}
exports.getChallengeBoss = getChallengeBoss;
/**
 * Get the starting character of a challenge. This will only work for vanilla challenges.
 *
 * For modded challenges, `PlayerType.ISAAC` (0) will be returned.
 */
function getChallengeCharacter(challenge) {
    const challengeCharacter = challengeCharacters_1.CHALLENGE_CHARACTERS[challenge];
    // Handle modded challenges.
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
    return challengeCharacter ?? challengeCharacters_1.DEFAULT_CHALLENGE_CHARACTER;
}
exports.getChallengeCharacter = getChallengeCharacter;
/**
 * Get the extra starting collectibles for a challenge. This will only work for vanilla challenges.
 *
 * For modded challenges, an empty array will be returned.
 */
function getChallengeCollectibleTypes(challenge) {
    return challengeCollectibleTypes_1.CHALLENGE_COLLECTIBLE_TYPES[challenge];
}
exports.getChallengeCollectibleTypes = getChallengeCollectibleTypes;
/**
 * Get the proper name for a `Challenge` enum. This will only work for vanilla challenges.
 *
 * For modded challenges, "Unknown" will be returned.
 */
function getChallengeName(challenge) {
    const challengeName = challengeNames_1.CHALLENGE_NAMES[challenge];
    // Handle modded challenges.
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
    return challengeName ?? challengeNames_1.DEFAULT_CHALLENGE_NAME;
}
exports.getChallengeName = getChallengeName;
/**
 * Get the extra starting trinket for a challenge. This will only work for vanilla challenges.
 *
 * If a challenge does not grant a starting trinket, `undefined` will be returned.
 *
 * For modded challenges, `undefined` will be returned.
 */
function getChallengeTrinketType(challenge) {
    return challengeTrinketType_1.CHALLENGE_TRINKET_TYPE[challenge];
}
exports.getChallengeTrinketType = getChallengeTrinketType;
/** Helper function to see if the player is playing any challenge. */
function onAnyChallenge() {
    const challenge = Isaac.GetChallenge();
    return challenge !== isaac_typescript_definitions_1.Challenge.NULL;
}
exports.onAnyChallenge = onAnyChallenge;
/**
 * Helper function to check to see if the player is playing a particular challenge.
 *
 * This function is variadic, meaning that you can specify as many challenges as you want to check
 * for.
 */
function onChallenge(...challenges) {
    const challenge = Isaac.GetChallenge();
    return challenges.includes(challenge);
}
exports.onChallenge = onChallenge;
/**
 * Helper function to restart the run on a particular challenge.
 *
 * If the player is already in the particular challenge, this function will do nothing.
 *
 * Under the hood, this function executes the `challenge 0` console command.
 */
function setChallenge(challenge) {
    if (!onChallenge(challenge)) {
        const command = `challenge ${challenge}`;
        (0, log_1.log)(`Restarting the run to set a challenge with a console command of: ${command}`);
        Isaac.ExecuteCommand(command);
    }
}
exports.setChallenge = setChallenge;
