"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PreBerserkDeath = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const ModCallbackCustom_1 = require("../../enums/ModCallbackCustom");
const playerIndex_1 = require("../../functions/playerIndex");
const players_1 = require("../../functions/players");
const revive_1 = require("../../functions/revive");
const shouldFire_1 = require("../../shouldFire");
const CustomCallback_1 = require("../private/CustomCallback");
class PreBerserkDeath extends CustomCallback_1.CustomCallback {
    constructor() {
        super();
        this.customCallbacksUsed = [
            [
                ModCallbackCustom_1.ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED,
                this.postPEffectUpdateReordered,
            ],
        ];
    }
    shouldFire = shouldFire_1.shouldFirePlayer;
    // ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED
    postPEffectUpdateReordered = (player) => {
        // This callback should not trigger for the Strawman Keeper and other players that are "child"
        // players.
        if ((0, playerIndex_1.isChildPlayer)(player)) {
            return;
        }
        const effects = player.GetEffects();
        const berserkEffect = effects.GetCollectibleEffect(isaac_typescript_definitions_1.CollectibleType.BERSERK);
        const numHitsRemaining = (0, players_1.getPlayerNumHitsRemaining)(player);
        // If the Berserk effect will end on the next frame and we have no hearts left.
        if (berserkEffect !== undefined &&
            berserkEffect.Cooldown === 1 &&
            numHitsRemaining === 0 &&
            !(0, revive_1.willPlayerRevive)(player)) {
            this.fire(player);
        }
    };
}
exports.PreBerserkDeath = PreBerserkDeath;
